Flutter Engine
The Flutter Engine
SkSLProgram.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9#include "src/sksl/SkSLPool.h"
16#include "src/sksl/ir/SkSLSymbolTable.h" // IWYU pragma: keep
17
18#include <utility>
19
20namespace SkSL {
21
22Program::Program(std::unique_ptr<std::string> source,
23 std::unique_ptr<ProgramConfig> config,
24 std::shared_ptr<Context> context,
25 std::vector<std::unique_ptr<ProgramElement>> elements,
26 std::unique_ptr<SymbolTable> symbols,
27 std::unique_ptr<Pool> pool)
28 : fSource(std::move(source))
29 , fConfig(std::move(config))
30 , fContext(context)
31 , fSymbols(std::move(symbols))
32 , fPool(std::move(pool))
33 , fOwnedElements(std::move(elements)) {
35}
36
38 // Some or all of the program elements are in the pool. To free them safely, we must attach
39 // the pool before destroying any program elements. (Otherwise, we may accidentally call
40 // delete on a pooled node.)
41 AutoAttachPoolToThread attach(fPool.get());
42
43 fOwnedElements.clear();
44 fContext.reset();
45 fSymbols.reset();
46}
47
48std::string Program::description() const {
49 std::string result = fConfig->versionDescription();
50 for (const ProgramElement* e : this->elements()) {
51 result += e->description();
52 }
53 return result;
54}
55
56const FunctionDeclaration* Program::getFunction(const char* functionName) const {
57 const Symbol* symbol = fSymbols->find(functionName);
58 bool valid = symbol && symbol->is<FunctionDeclaration>() &&
60 return valid ? &symbol->as<FunctionDeclaration>() : nullptr;
61}
62
63} // namespace SkSL
AutoreleasePool pool
const Context & fContext
const SymbolTable & fSymbols
const FunctionDefinition * definition() const
bool is() const
Definition: SkSLIRNode.h:124
const T & as() const
Definition: SkSLIRNode.h:133
SkBitmap source
Definition: examples.cpp:28
GAsyncResult * result
std::unique_ptr< ProgramUsage > GetUsage(const Program &program)
Definition: ref_ptr.h:256
std::vector< std::unique_ptr< ProgramElement > > fOwnedElements
Definition: SkSLProgram.h:161
Program(std::unique_ptr< std::string > source, std::unique_ptr< ProgramConfig > config, std::shared_ptr< Context > context, std::vector< std::unique_ptr< ProgramElement > > elements, std::unique_ptr< SymbolTable > symbols, std::unique_ptr< Pool > pool)
Definition: SkSLProgram.cpp:22
ElementsCollection elements() const
Definition: SkSLProgram.h:140
std::shared_ptr< Context > fContext
Definition: SkSLProgram.h:154
std::unique_ptr< ProgramUsage > fUsage
Definition: SkSLProgram.h:155
std::unique_ptr< Pool > fPool
Definition: SkSLProgram.h:159
std::unique_ptr< SymbolTable > fSymbols
Definition: SkSLProgram.h:158
const FunctionDeclaration * getFunction(const char *functionName) const
Definition: SkSLProgram.cpp:56
std::unique_ptr< ProgramConfig > fConfig
Definition: SkSLProgram.h:153
std::string description() const
Definition: SkSLProgram.cpp:48