Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/gpu/gl/builders/GrGLFragmentShaderBuilder.h

Issue 1290773002: BUILDS! Added mangleString, onBefore, and onAfterChildProcEmitCode() to GrGLFragmentShaderBuilder.c… Base URL: https://skia.googlesource.com/skia@cs3_flatten
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkString.h ('k') | src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGLFragmentShaderBuilder_DEFINED 8 #ifndef GrGLFragmentShaderBuilder_DEFINED
9 #define GrGLFragmentShaderBuilder_DEFINED 9 #define GrGLFragmentShaderBuilder_DEFINED
10 10
11 #include "GrGLShaderBuilder.h" 11 #include "GrGLShaderBuilder.h"
12 12
13 class GrGLVarying; 13 class GrGLVarying;
14 14
15 /* 15 /*
16 * This base class encapsulates the functionality which the GP uses to build fra gment shaders 16 * This base class encapsulates the functionality which the GP uses to build fra gment shaders
17 */ 17 */
18 class GrGLFragmentBuilder : public GrGLShaderBuilder { 18 class GrGLFragmentBuilder : public GrGLShaderBuilder {
19 public: 19 public:
20 GrGLFragmentBuilder(GrGLProgramBuilder* program) : INHERITED(program) {} 20 GrGLFragmentBuilder(GrGLProgramBuilder* program)
21 : INHERITED(program) {
22 fSubstageIndices.push_back(0);
23 }
21 virtual ~GrGLFragmentBuilder() {} 24 virtual ~GrGLFragmentBuilder() {}
22 /** 25 /**
23 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile 26 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile
24 * if code is added that uses one of these features without calling enableFe ature() 27 * if code is added that uses one of these features without calling enableFe ature()
25 */ 28 */
26 enum GLSLFeature { 29 enum GLSLFeature {
27 kStandardDerivatives_GLSLFeature = 0, 30 kStandardDerivatives_GLSLFeature = 0,
28 kLastGLSLFeature = kStandardDerivatives_GLSLFeature 31 kLastGLSLFeature = kStandardDerivatives_GLSLFeature
29 }; 32 };
30 33
31 /** 34 /**
32 * If the feature is supported then true is returned and any necessary #exte nsion declarations 35 * If the feature is supported then true is returned and any necessary #exte nsion declarations
33 * are added to the shaders. If the feature is not supported then false will be returned. 36 * are added to the shaders. If the feature is not supported then false will be returned.
34 */ 37 */
35 virtual bool enableFeature(GLSLFeature) = 0; 38 virtual bool enableFeature(GLSLFeature) = 0;
36 39
37 /** 40 /**
38 * This returns a variable name to access the 2D, perspective correct versio n of the coords in 41 * This returns a variable name to access the 2D, perspective correct versio n of the coords in
39 * the fragment shader. If the coordinates at index are 3-dimensional, it im mediately emits a 42 * the fragment shader. If the coordinates at index are 3-dimensional, it im mediately emits a
40 * perspective divide into the fragment shader (xy / z) to convert them to 2 D. 43 * perspective divide into the fragment shader (xy / z) to convert them to 2 D.
41 */ 44 */
42 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra y& coords, 45 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra y& coords,
43 int index) = 0; 46 int index) = 0;
44 47
45 48
46 /** Returns a variable name that represents the position of the fragment in the FS. The position 49 /** Returns a variable name that represents the position of the fragment in the FS. The position
47 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */ 50 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */
48 virtual const char* fragmentPosition() = 0; 51 virtual const char* fragmentPosition() = 0;
49 52
53 /**
54 * Fragment procs with child procs should call these functions before/after calling emitCode
55 * on a child proc.
56 */
57 void onBeforeChildProcEmitCode();
58 void onAfterChildProcEmitCode();
59
60 int getChildNumberThisLevel() const {
61 if (fSubstageIndices.count() > 1)
62 return fSubstageIndices[fSubstageIndices.count() - 2];
63 return -1;
64 }
65
66 const SkString& getMangleString() const { return fMangleString; }
67
68 SkString getMangleStringThisLevel() const {
69 SkString ret;
70 int childNumber = getChildNumberThisLevel();
71 if (childNumber >= 0)
72 ret.printf("_c%d", childNumber);
73 return ret;
74 }
75
50 private: 76 private:
77 /*
78 * State that tracks which child proc in the proc tree is currently emitting code. This is
79 * used to update the manglestring, which is used to mangle the names of uni forms and functions
80 * emitted by the proc. fSubstageIndices is a stack: its count indicates ho w many levels deep
81 * we are in the tree, and its second-to-last value is the index of the chil d proc at that
82 * level which is currently emitting code.
83 */
84 SkTArray<int> fSubstageIndices;
85 SkString fMangleString;
86
51 friend class GrGLPathProcessor; 87 friend class GrGLPathProcessor;
52 88
53 typedef GrGLShaderBuilder INHERITED; 89 typedef GrGLShaderBuilder INHERITED;
54 }; 90 };
55 91
56 /* 92 /*
57 * Fragment processor's, in addition to all of the above, may need to use dst co lor so they use 93 * Fragment processor's, in addition to all of the above, may need to use dst co lor so they use
58 * this builder to create their shader. Because this is the only shader builder the FP sees, we 94 * this builder to create their shader. Because this is the only shader builder the FP sees, we
59 * just call it FPShaderBuilder 95 * just call it FPShaderBuilder
60 */ 96 */
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // the program creator 198 // the program creator
163 bool fHasReadDstColor; 199 bool fHasReadDstColor;
164 bool fHasReadFragmentPosition; 200 bool fHasReadFragmentPosition;
165 201
166 friend class GrGLProgramBuilder; 202 friend class GrGLProgramBuilder;
167 203
168 typedef GrGLXPFragmentBuilder INHERITED; 204 typedef GrGLXPFragmentBuilder INHERITED;
169 }; 205 };
170 206
171 #endif 207 #endif
OLDNEW
« no previous file with comments | « include/core/SkString.h ('k') | src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698