Line data Source code
1 : /*
2 : * Copyright 2016 Google Inc.
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 :
8 : #ifndef SKSL_PROGRAM
9 : #define SKSL_PROGRAM
10 :
11 : #include <vector>
12 : #include <memory>
13 :
14 : #include "SkSLContext.h"
15 : #include "SkSLModifiers.h"
16 : #include "SkSLProgramElement.h"
17 : #include "SkSLSymbolTable.h"
18 :
19 : // name of the render target height uniform
20 : #define SKSL_RTHEIGHT_NAME "u_skRTHeight"
21 :
22 : namespace SkSL {
23 :
24 : /**
25 : * Represents a fully-digested program, ready for code generation.
26 : */
27 0 : struct Program {
28 : struct Settings {
29 : #ifdef SKSL_STANDALONE
30 : const StandaloneShaderCaps* fCaps = &standaloneCaps;
31 : #else
32 : const GrShaderCaps* fCaps = nullptr;
33 : #endif
34 : // if false, sk_FragCoord is exactly the same as gl_FragCoord. If true, the y coordinate
35 : // must be flipped.
36 : bool fFlipY = false;
37 : };
38 :
39 : struct Inputs {
40 : // if true, this program requires the render target height uniform to be defined
41 : bool fRTHeight;
42 :
43 : // if true, this program must be recompiled if the flipY setting changes. If false, the
44 : // program will compile to the same code regardless of the flipY setting.
45 : bool fFlipY;
46 :
47 0 : void reset() {
48 0 : fRTHeight = false;
49 0 : fFlipY = false;
50 0 : }
51 :
52 0 : bool isEmpty() {
53 0 : return !fRTHeight && !fFlipY;
54 : }
55 : };
56 :
57 : enum Kind {
58 : kFragment_Kind,
59 : kVertex_Kind,
60 : kGeometry_Kind
61 : };
62 :
63 0 : Program(Kind kind,
64 : Settings settings,
65 : Modifiers::Flag defaultPrecision,
66 : Context* context,
67 : std::vector<std::unique_ptr<ProgramElement>> elements,
68 : std::shared_ptr<SymbolTable> symbols,
69 : Inputs inputs)
70 0 : : fKind(kind)
71 : , fSettings(settings)
72 : , fDefaultPrecision(defaultPrecision)
73 : , fContext(context)
74 : , fSymbols(symbols)
75 0 : , fElements(std::move(elements))
76 0 : , fInputs(inputs) {}
77 :
78 : Kind fKind;
79 : Settings fSettings;
80 : // FIXME handle different types; currently it assumes this is for floats
81 : Modifiers::Flag fDefaultPrecision;
82 : Context* fContext;
83 : // it's important to keep fElements defined after (and thus destroyed before) fSymbols,
84 : // because destroying elements can modify reference counts in symbols
85 : std::shared_ptr<SymbolTable> fSymbols;
86 : std::vector<std::unique_ptr<ProgramElement>> fElements;
87 : Inputs fInputs;
88 : };
89 :
90 : } // namespace
91 :
92 : #endif
|