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

Side by Side Diff: src/gpu/gl/GrGLProgram.h

Issue 12942014: Move GrGLProgram::Desc out of GrGLProgram. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Move #include below dbl include check Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 8
9 #ifndef GrGLProgram_DEFINED 9 #ifndef GrGLProgram_DEFINED
10 #define GrGLProgram_DEFINED 10 #define GrGLProgram_DEFINED
11 11
12 #include "GrDrawState.h" 12 #include "GrDrawState.h"
13 #include "GrGLEffect.h"
14 #include "GrGLContext.h" 13 #include "GrGLContext.h"
14 #include "GrGLProgramDesc.h"
15 #include "GrGLSL.h" 15 #include "GrGLSL.h"
16 #include "GrGLTexture.h" 16 #include "GrGLTexture.h"
17 #include "GrGLUniformManager.h" 17 #include "GrGLUniformManager.h"
18 18
19 #include "SkString.h" 19 #include "SkString.h"
20 #include "SkXfermode.h" 20 #include "SkXfermode.h"
21 21
22 class GrBinHashKeyBuilder; 22 class GrBinHashKeyBuilder;
23 class GrGLEffect; 23 class GrGLEffect;
24 class GrGLShaderBuilder; 24 class GrGLShaderBuilder;
25 class SkMWCRandom; 25 class SkMWCRandom;
26 26
27 // optionally compile the experimental GS code. Set to GR_DEBUG
28 // so that debug build bots will execute the code.
29 #define GR_GL_EXPERIMENTAL_GS GR_DEBUG
30
31 /** 27 /**
32 * This class manages a GPU program and records per-program information. 28 * This class manages a GPU program and records per-program information.
33 * We can specify the attribute locations so that they are constant 29 * We can specify the attribute locations so that they are constant
34 * across our shaders. But the driver determines the uniform locations 30 * across our shaders. But the driver determines the uniform locations
35 * at link time. We don't need to remember the sampler uniform location 31 * at link time. We don't need to remember the sampler uniform location
36 * because we will bind a texture slot to it and never change it 32 * because we will bind a texture slot to it and never change it
37 * Uniforms are program-local so we can't rely on fHWState to hold the 33 * Uniforms are program-local so we can't rely on fHWState to hold the
38 * previous uniform state after a program change. 34 * previous uniform state after a program change.
39 */ 35 */
40 class GrGLProgram : public GrRefCnt { 36 class GrGLProgram : public GrRefCnt {
41 public: 37 public:
42 SK_DECLARE_INST_COUNT(GrGLProgram) 38 SK_DECLARE_INST_COUNT(GrGLProgram)
43 39
44 class Desc;
45
46 /**
47 * Builds a program descriptor from a GrDrawState. Whether the primitive typ e is points, the
48 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs.
49 */
50 static void BuildDesc(const GrDrawState&,
51 bool isPoints,
52 GrDrawState::BlendOptFlags,
53 GrBlendCoeff srcCoeff,
54 GrBlendCoeff dstCoeff,
55 const GrGpuGL* gpu,
56 Desc* outDesc);
57
58 static GrGLProgram* Create(const GrGLContext& gl, 40 static GrGLProgram* Create(const GrGLContext& gl,
59 const Desc& desc, 41 const GrGLProgramDesc& desc,
60 const GrEffectStage* stages[]); 42 const GrEffectStage* stages[]);
61 43
62 virtual ~GrGLProgram(); 44 virtual ~GrGLProgram();
63 45
64 /** 46 /**
65 * Call to abandon GL objects owned by this program. 47 * Call to abandon GL objects owned by this program.
66 */ 48 */
67 void abandon(); 49 void abandon();
68 50
69 /** 51 /**
70 * The shader may modify the blend coefficients. Params are in/out 52 * The shader may modify the blend coefficients. Params are in/out
71 */ 53 */
72 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const; 54 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const;
73 55
74 const Desc& getDesc() { return fDesc; } 56 const GrGLProgramDesc& getDesc() { return fDesc; }
75 57
76 /** 58 /**
77 * Gets the GL program ID for this program. 59 * Gets the GL program ID for this program.
78 */ 60 */
79 GrGLuint programID() const { return fProgramID; } 61 GrGLuint programID() const { return fProgramID; }
80 62
81 /** 63 /**
82 * Some GL state that is relevant to programs is not stored per-program. In particular vertex 64 * Some GL state that is relevant to programs is not stored per-program. In particular vertex
83 * attributes are global state. This struct is read and updated by GrGLProgr am::setData to 65 * attributes are global state. This struct is read and updated by GrGLProgr am::setData to
84 * allow us to avoid setting this state redundantly. 66 * allow us to avoid setting this state redundantly.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 98
117 /** 99 /**
118 * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a 100 * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a
119 * draw occurs using the program after the program has already been bound. I t also uses the 101 * draw occurs using the program after the program has already been bound. I t also uses the
120 * GrGpuGL object to bind the textures required by the GrGLEffects. 102 * GrGpuGL object to bind the textures required by the GrGLEffects.
121 * 103 *
122 * The color and coverage params override the GrDrawState's getColor() and g etCoverage() values. 104 * The color and coverage params override the GrDrawState's getColor() and g etCoverage() values.
123 */ 105 */
124 void setData(GrGpuGL*, GrColor color, GrColor coverage, SharedGLState*); 106 void setData(GrGpuGL*, GrColor color, GrColor coverage, SharedGLState*);
125 107
126 // Parameters that affect code generation
127 // This structs should be kept compact; it is input to an expensive hash key generator.
128 class Desc {
129 public:
130 Desc() {
131 // since we use this as part of a key we can't have any uninitialize d
132 // padding
133 memset(this, 0, sizeof(Desc));
134 }
135
136 // returns this as a uint32_t array to be used as a key in the program c ache
137 const uint32_t* asKey() const {
138 return reinterpret_cast<const uint32_t*>(this);
139 }
140
141 // For unit testing.
142 void setRandom(SkMWCRandom*,
143 const GrGpuGL* gpu,
144 const GrEffectStage stages[GrDrawState::kNumStages]);
145
146 private:
147 // Specifies where the initial color comes from before the stages are ap plied.
148 enum ColorInput {
149 kSolidWhite_ColorInput,
150 kTransBlack_ColorInput,
151 kAttribute_ColorInput,
152 kUniform_ColorInput,
153
154 kColorInputCnt
155 };
156 // Dual-src blending makes use of a secondary output color that can be
157 // used as a per-pixel blend coefficient. This controls whether a
158 // secondary source is output and what value it holds.
159 enum DualSrcOutput {
160 kNone_DualSrcOutput,
161 kCoverage_DualSrcOutput,
162 kCoverageISA_DualSrcOutput,
163 kCoverageISC_DualSrcOutput,
164
165 kDualSrcOutputCnt
166 };
167
168 // should the FS discard if the coverage is zero (to avoid stencil manip ulation)
169 bool fDiscardIfZeroCoverage;
170
171 // stripped of bits that don't affect program generation
172 GrAttribBindings fAttribBindings;
173
174 /** Non-zero if this stage has an effect */
175 GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages];
176
177 // To enable experimental geometry shader code (not for use in
178 // production)
179 #if GR_GL_EXPERIMENTAL_GS
180 bool fExperimentalGS;
181 #endif
182 uint8_t fColorInput; // casts to enum Col orInput
183 uint8_t fCoverageInput; // casts to enum Col orInput
184 uint8_t fDualSrcOutput; // casts to enum Dua lSrcOutput
185 int8_t fFirstCoverageStage;
186 SkBool8 fEmitsPointSize;
187 uint8_t fColorFilterXfermode; // casts to enum SkX fermode::Mode
188
189 int8_t fPositionAttributeIndex;
190 int8_t fColorAttributeIndex;
191 int8_t fCoverageAttributeIndex;
192 int8_t fLocalCoordsAttributeIndex;
193
194 friend class GrGLProgram;
195 };
196
197 // Layout information for OpenGL vertex attributes
198 struct AttribLayout {
199 GrGLint fCount;
200 GrGLenum fType;
201 GrGLboolean fNormalized;
202 };
203 static const AttribLayout kAttribLayouts[kGrVertexAttribTypeCount];
204
205 private: 108 private:
206 GrGLProgram(const GrGLContext& gl, 109 GrGLProgram(const GrGLContext& gl,
207 const Desc& desc, 110 const GrGLProgramDesc& desc,
208 const GrEffectStage* stages[]); 111 const GrEffectStage* stages[]);
209 112
210 bool succeeded() const { return 0 != fProgramID; } 113 bool succeeded() const { return 0 != fProgramID; }
211 114
212 /** 115 /**
213 * This is the heavy initialization routine for building a GLProgram. 116 * This is the heavy initialization routine for building a GLProgram.
214 */ 117 */
215 bool genProgram(const GrEffectStage* stages[]); 118 bool genProgram(const GrEffectStage* stages[]);
216 119
217 void genInputColor(GrGLShaderBuilder* builder, SkString* inColor); 120 void genInputColor(GrGLShaderBuilder* builder, SkString* inColor);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 GrGLuint fProgramID; 177 GrGLuint fProgramID;
275 178
276 // these reflect the current values of uniforms (GL uniform values travel wi th program) 179 // these reflect the current values of uniforms (GL uniform values travel wi th program)
277 MatrixState fMatrixState; 180 MatrixState fMatrixState;
278 GrColor fColor; 181 GrColor fColor;
279 GrColor fCoverage; 182 GrColor fCoverage;
280 GrColor fColorFilterColor; 183 GrColor fColorFilterColor;
281 184
282 GrGLEffect* fEffects[GrDrawState::kNumStages]; 185 GrGLEffect* fEffects[GrDrawState::kNumStages];
283 186
284 Desc fDesc; 187 GrGLProgramDesc fDesc;
285 const GrGLContext& fContext; 188 const GrGLContext& fContext;
286 189
287 GrGLUniformManager fUniformManager; 190 GrGLUniformManager fUniformManager;
288 UniformHandles fUniformHandles; 191 UniformHandles fUniformHandles;
289 192
290 typedef GrRefCnt INHERITED; 193 typedef GrRefCnt INHERITED;
291 }; 194 };
292 195
293 #endif 196 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/gl/GrGLProgram.cpp » ('j') | src/gpu/gl/GrGLProgramDesc.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698