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

Side by Side Diff: src/gpu/gl/GrGLProgramEffects.cpp

Issue 577593003: Revert of removing GrDrawEffect (Closed) Base URL: https://skia.googlesource.com/skia.git@gp3
Patch Set: Created 6 years, 3 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 | « src/gpu/gl/GrGLProgramEffects.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.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 2013 Google Inc. 2 * Copyright 2013 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 #include "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrGLProgramEffects.h" 9 #include "GrGLProgramEffects.h"
10 #include "GrDrawEffect.h"
10 #include "gl/GrGLEffect.h" 11 #include "gl/GrGLEffect.h"
11 #include "gl/GrGLPathRendering.h" 12 #include "gl/GrGLPathRendering.h"
12 #include "gl/builders/GrGLProgramBuilder.h" 13 #include "gl/builders/GrGLProgramBuilder.h"
13 #include "gl/GrGLGeometryProcessor.h" 14 #include "gl/GrGLGeometryProcessor.h"
14 #include "gl/GrGpuGL.h" 15 #include "gl/GrGpuGL.h"
15 16
16 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; 17 typedef GrGLProgramEffects::TransformedCoords TransformedCoords;
17 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; 18 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
18 typedef GrGLProgramEffects::TextureSampler TextureSampler; 19 typedef GrGLProgramEffects::TextureSampler TextureSampler;
19 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; 20 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 */ 82 */
82 GrCoordSet get_source_coords(uint32_t transformKey, int transformIdx) { 83 GrCoordSet get_source_coords(uint32_t transformKey, int transformIdx) {
83 return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoord s_Flag ? 84 return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoord s_Flag ?
84 kPosition_GrCoordSet : 85 kPosition_GrCoordSet :
85 kLocal_GrCoordSet; 86 kLocal_GrCoordSet;
86 } 87 }
87 88
88 /** 89 /**
89 * Retrieves the final matrix that a transform needs to apply to its source coor ds. 90 * Retrieves the final matrix that a transform needs to apply to its source coor ds.
90 */ 91 */
91 SkMatrix get_transform_matrix(const GrEffectStage& effectStage, 92 SkMatrix get_transform_matrix(const GrDrawEffect& drawEffect, int transformIdx) {
92 bool useExplicitLocalCoords, 93 const GrCoordTransform& coordTransform = drawEffect.effect()->coordTransform (transformIdx);
93 int transformIdx) {
94 const GrCoordTransform& coordTransform = effectStage.getEffect()->coordTrans form(transformIdx);
95 SkMatrix combined; 94 SkMatrix combined;
96 95
97 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { 96 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
98 // If we have explicit local coords then we shouldn't need a coord chang e. 97 // If we have explicit local coords then we shouldn't need a coord chang e.
99 const SkMatrix& ccm = 98 SkASSERT(!drawEffect.programHasExplicitLocalCoords() ||
100 useExplicitLocalCoords ? SkMatrix::I() : effectStage.getCoordCha ngeMatrix(); 99 drawEffect.getCoordChangeMatrix().isIdentity());
101 combined.setConcat(coordTransform.getMatrix(), ccm); 100 combined.setConcat(coordTransform.getMatrix(), drawEffect.getCoordChange Matrix());
102 } else { 101 } else {
103 combined = coordTransform.getMatrix(); 102 combined = coordTransform.getMatrix();
104 } 103 }
105 if (coordTransform.reverseY()) { 104 if (coordTransform.reverseY()) {
106 // combined.postScale(1,-1); 105 // combined.postScale(1,-1);
107 // combined.postTranslate(0,1); 106 // combined.postTranslate(0,1);
108 combined.set(SkMatrix::kMSkewY, 107 combined.set(SkMatrix::kMSkewY,
109 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); 108 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
110 combined.set(SkMatrix::kMScaleY, 109 combined.set(SkMatrix::kMScaleY,
111 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); 110 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
112 combined.set(SkMatrix::kMTransY, 111 combined.set(SkMatrix::kMTransY,
113 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); 112 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
114 } 113 }
115 return combined; 114 return combined;
116 } 115 }
116
117 } 117 }
118 118
119 //////////////////////////////////////////////////////////////////////////////// 119 ////////////////////////////////////////////////////////////////////////////////
120 120
121 bool GrGLProgramEffects::GenEffectMetaKey(const GrEffectStage& effectStage, 121 bool GrGLProgramEffects::GenEffectMetaKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps,
122 bool useExplicitLocalCoords,
123 const GrGLCaps& caps,
124 GrEffectKeyBuilder* b) { 122 GrEffectKeyBuilder* b) {
125 123
126 uint32_t textureKey = GrGLProgramEffects::GenTextureKey(effectStage.getEffec t(), caps); 124 uint32_t textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps);
127 uint32_t transformKey = GrGLProgramEffects::GenTransformKey(effectStage,useE xplicitLocalCoords); 125 uint32_t transformKey = GrGLProgramEffects::GenTransformKey(drawEffect);
128 uint32_t attribKey = GrGLProgramEffects::GenAttribKey(effectStage.getEffect( )); 126 uint32_t attribKey = GrGLProgramEffects::GenAttribKey(drawEffect.castEffect< GrEffect>());
129 uint32_t classID = effectStage.getEffect()->getFactory().effectClassID(); 127 uint32_t classID = drawEffect.effect()->getFactory().effectClassID();
130 128
131 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they 129 // Currently we allow 16 bits for each of the above portions of the meta-key . Fail if they
132 // don't fit. 130 // don't fit.
133 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); 131 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
134 if ((textureKey | transformKey | attribKey | classID) & kMetaKeyInvalidMask) { 132 if ((textureKey | transformKey | attribKey | classID) & kMetaKeyInvalidMask) {
135 return false; 133 return false;
136 } 134 }
137 135
138 uint32_t* key = b->add32n(2); 136 uint32_t* key = b->add32n(2);
139 key[0] = (textureKey << 16 | transformKey); 137 key[0] = (textureKey << 16 | transformKey);
140 key[1] = (classID << 16 | attribKey); 138 key[1] = (classID << 16 | attribKey);
141 return true; 139 return true;
142 } 140 }
143 141
144 uint32_t GrGLProgramEffects::GenAttribKey(const GrEffect* effect) { 142 uint32_t GrGLProgramEffects::GenAttribKey(const GrEffect& effect) {
145 uint32_t key = 0; 143 uint32_t key = 0;
146 144
147 const GrEffect::VertexAttribArray& vars = effect->getVertexAttribs(); 145 const GrEffect::VertexAttribArray& vars = effect.getVertexAttribs();
148 int numAttributes = vars.count(); 146 int numAttributes = vars.count();
149 SkASSERT(numAttributes <= 2); 147 SkASSERT(numAttributes <= 2);
150 for (int a = 0; a < numAttributes; ++a) { 148 for (int a = 0; a < numAttributes; ++a) {
151 uint32_t value = 1 << a; 149 uint32_t value = 1 << a;
152 key |= value; 150 key |= value;
153 } 151 }
154 return key; 152 return key;
155 } 153 }
156 154
157 uint32_t GrGLProgramEffects::GenTransformKey(const GrEffectStage& effectStage, 155 uint32_t GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) {
158 bool useExplicitLocalCoords) {
159 uint32_t totalKey = 0; 156 uint32_t totalKey = 0;
160 int numTransforms = effectStage.getEffect()->numTransforms(); 157 int numTransforms = drawEffect.effect()->numTransforms();
161 for (int t = 0; t < numTransforms; ++t) { 158 for (int t = 0; t < numTransforms; ++t) {
162 uint32_t key = 0; 159 uint32_t key = 0;
163 const GrCoordTransform& coordTransform = effectStage.getEffect()->coordT ransform(t); 160 const GrCoordTransform& coordTransform = drawEffect.effect()->coordTrans form(t);
164 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); 161 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType();
165 SkMatrix::TypeMask type1 = SkMatrix::kIdentity_Mask; 162 SkMatrix::TypeMask type1;
166 if (kLocal_GrCoordSet == coordTransform.sourceCoords() && !useExplicitLo calCoords) { 163 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
167 type1 = effectStage.getCoordChangeMatrix().getType(); 164 type1 = drawEffect.getCoordChangeMatrix().getType();
168 } else if (kPosition_GrCoordSet == coordTransform.sourceCoords() && useE xplicitLocalCoords) { 165 } else {
169 // We only make the key indicate that device coords are referenced w hen the local coords 166 if (drawEffect.programHasExplicitLocalCoords()) {
170 // are not actually determined by positions. Otherwise the local coo rds var and position 167 // We only make the key indicate that device coords are referenc ed when the local coords
171 // var are identical. 168 // are not actually determined by positions. Otherwise the local coords var and position
172 key |= kPositionCoords_Flag; 169 // var are identical.
170 key |= kPositionCoords_Flag;
171 }
172 type1 = SkMatrix::kIdentity_Mask;
173 } 173 }
174 174
175 int combinedTypes = type0 | type1; 175 int combinedTypes = type0 | type1;
176 176
177 if (SkMatrix::kPerspective_Mask & combinedTypes) { 177 if (SkMatrix::kPerspective_Mask & combinedTypes) {
178 key |= kGeneral_MatrixType; 178 key |= kGeneral_MatrixType;
179 } else { 179 } else {
180 key |= kNoPersp_MatrixType; 180 key |= kNoPersp_MatrixType;
181 } 181 }
182 key <<= kTransformKeyBits * t; 182 key <<= kTransformKeyBits * t;
183 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap 183 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap
184 totalKey |= key; 184 totalKey |= key;
185 } 185 }
186 return totalKey; 186 return totalKey;
187 } 187 }
188 188
189 uint32_t GrGLProgramEffects::GenTextureKey(const GrEffect* effect, const GrGLCap s& caps) { 189 uint32_t GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps) {
190 uint32_t key = 0; 190 uint32_t key = 0;
191 int numTextures = effect->numTextures(); 191 int numTextures = drawEffect.effect()->numTextures();
192 for (int t = 0; t < numTextures; ++t) { 192 for (int t = 0; t < numTextures; ++t) {
193 const GrTextureAccess& access = effect->textureAccess(t); 193 const GrTextureAccess& access = drawEffect.effect()->textureAccess(t);
194 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText ure()->config()); 194 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText ure()->config());
195 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s wizzleMask())) { 195 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s wizzleMask())) {
196 key |= 1 << t; 196 key |= 1 << t;
197 } 197 }
198 } 198 }
199 return key; 199 return key;
200 } 200 }
201 201
202 GrGLProgramEffects::~GrGLProgramEffects() { 202 GrGLProgramEffects::~GrGLProgramEffects() {
203 int numEffects = fGLEffects.count(); 203 int numEffects = fGLEffects.count();
204 for (int e = 0; e < numEffects; ++e) { 204 for (int e = 0; e < numEffects; ++e) {
205 SkDELETE(fGLEffects[e]); 205 SkDELETE(fGLEffects[e]);
206 } 206 }
207 } 207 }
208 208
209 void GrGLProgramEffects::emitSamplers(GrGLProgramBuilder* builder, 209 void GrGLProgramEffects::emitSamplers(GrGLProgramBuilder* builder,
210 const GrEffect& effect, 210 const GrEffect* effect,
211 TextureSamplerArray* outSamplers) { 211 TextureSamplerArray* outSamplers) {
212 SkTArray<Sampler, true>& samplers = fSamplers.push_back(); 212 SkTArray<Sampler, true>& samplers = fSamplers.push_back();
213 int numTextures = effect.numTextures(); 213 int numTextures = effect->numTextures();
214 samplers.push_back_n(numTextures); 214 samplers.push_back_n(numTextures);
215 SkString name; 215 SkString name;
216 for (int t = 0; t < numTextures; ++t) { 216 for (int t = 0; t < numTextures; ++t) {
217 name.printf("Sampler%d", t); 217 name.printf("Sampler%d", t);
218 samplers[t].fUniform = builder->addUniform(GrGLProgramBuilder::kFragment _Visibility, 218 samplers[t].fUniform = builder->addUniform(GrGLProgramBuilder::kFragment _Visibility,
219 kSampler2D_GrSLType, 219 kSampler2D_GrSLType,
220 name.c_str()); 220 name.c_str());
221 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, 221 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler,
222 (samplers[t].fUniform, effect.textureAccess(t))); 222 (samplers[t].fUniform, effect->textureAccess(t))) ;
223 } 223 }
224 } 224 }
225 225
226 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou rceManager, int* texUnitIdx) { 226 void GrGLProgramEffects::initSamplers(const GrGLProgramDataManager& programResou rceManager, int* texUnitIdx) {
227 int numEffects = fGLEffects.count(); 227 int numEffects = fGLEffects.count();
228 SkASSERT(numEffects == fSamplers.count()); 228 SkASSERT(numEffects == fSamplers.count());
229 for (int e = 0; e < numEffects; ++e) { 229 for (int e = 0; e < numEffects; ++e) {
230 SkTArray<Sampler, true>& samplers = fSamplers[e]; 230 SkTArray<Sampler, true>& samplers = fSamplers[e];
231 int numSamplers = samplers.count(); 231 int numSamplers = samplers.count();
232 for (int s = 0; s < numSamplers; ++s) { 232 for (int s = 0; s < numSamplers; ++s) {
233 SkASSERT(samplers[s].fUniform.isValid()); 233 SkASSERT(samplers[s].fUniform.isValid());
234 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx) ; 234 programResourceManager.setSampler(samplers[s].fUniform, *texUnitIdx) ;
235 samplers[s].fTextureUnit = (*texUnitIdx)++; 235 samplers[s].fTextureUnit = (*texUnitIdx)++;
236 } 236 }
237 } 237 }
238 } 238 }
239 239
240 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect& effect, int effectIdx) { 240 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect* effect, int effectIdx) {
241 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; 241 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx];
242 int numSamplers = samplers.count(); 242 int numSamplers = samplers.count();
243 SkASSERT(numSamplers == effect.numTextures()); 243 SkASSERT(numSamplers == effect->numTextures());
244 for (int s = 0; s < numSamplers; ++s) { 244 for (int s = 0; s < numSamplers; ++s) {
245 SkASSERT(samplers[s].fTextureUnit >= 0); 245 SkASSERT(samplers[s].fTextureUnit >= 0);
246 const GrTextureAccess& textureAccess = effect.textureAccess(s); 246 const GrTextureAccess& textureAccess = effect->textureAccess(s);
247 gpu->bindTexture(samplers[s].fTextureUnit, 247 gpu->bindTexture(samplers[s].fTextureUnit,
248 textureAccess.getParams(), 248 textureAccess.getParams(),
249 static_cast<GrGLTexture*>(textureAccess.getTexture())); 249 static_cast<GrGLTexture*>(textureAccess.getTexture()));
250 } 250 }
251 } 251 }
252 252
253 //////////////////////////////////////////////////////////////////////////////// 253 ////////////////////////////////////////////////////////////////////////////////
254 254
255 void GrGLVertexProgramEffects::emitEffect(GrGLFullProgramBuilder* builder, 255 void GrGLVertexProgramEffects::emitEffect(GrGLFullProgramBuilder* builder,
256 const GrEffectStage& stage, 256 const GrEffectStage& stage,
257 const GrEffectKey& key, 257 const GrEffectKey& key,
258 const char* outColor, 258 const char* outColor,
259 const char* inColor, 259 const char* inColor,
260 int stageIndex) { 260 int stageIndex) {
261 const GrEffect& effect = *stage.getEffect(); 261 GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords);
262 SkSTArray<2, TransformedCoords> coords(effect.numTransforms()); 262 const GrEffect* effect = stage.getEffect();
263 SkSTArray<4, TextureSampler> samplers(effect.numTextures()); 263 SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
264 SkSTArray<4, TextureSampler> samplers(effect->numTextures());
264 265
265 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); 266 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
266 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 267 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
267 vsBuilder->emitAttributes(stage); 268 vsBuilder->emitAttributes(stage);
268 this->emitTransforms(builder, stage, &coords); 269 this->emitTransforms(builder, drawEffect, &coords);
269 this->emitSamplers(builder, effect, &samplers); 270 this->emitSamplers(builder, effect, &samplers);
270 271
271 GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect); 272 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
272 fGLEffects.push_back(glEffect); 273 fGLEffects.push_back(glEffect);
273 274
274 // Enclose custom code in a block to avoid namespace conflicts 275 // Enclose custom code in a block to avoid namespace conflicts
275 SkString openBrace; 276 SkString openBrace;
276 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); 277 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name());
277 fsBuilder->codeAppend(openBrace.c_str()); 278 fsBuilder->codeAppend(openBrace.c_str());
278 vsBuilder->codeAppend(openBrace.c_str()); 279 vsBuilder->codeAppend(openBrace.c_str());
279 280
280 if (glEffect->isVertexEffect()) { 281 if (glEffect->isVertexEffect()) {
281 GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor* >(glEffect); 282 GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor* >(glEffect);
282 vertexEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers); 283 vertexEffect->emitCode(builder, drawEffect, key, outColor, inColor, coor ds, samplers);
283 } else { 284 } else {
284 glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samp lers); 285 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samplers);
285 } 286 }
286 287
287 vsBuilder->codeAppend("\t}\n"); 288 vsBuilder->codeAppend("\t}\n");
288 fsBuilder->codeAppend("\t}\n"); 289 fsBuilder->codeAppend("\t}\n");
289 } 290 }
290 291
291 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, 292 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder,
292 const GrEffectStage& effectStage, 293 const GrDrawEffect& drawEffect,
293 TransformedCoordsArray* outCoords) { 294 TransformedCoordsArray* outCoords) {
294 SkTArray<Transform, true>& transforms = fTransforms.push_back(); 295 SkTArray<Transform, true>& transforms = fTransforms.push_back();
295 uint32_t totalKey = GenTransformKey(effectStage, fHasExplicitLocalCoords); 296 uint32_t totalKey = GenTransformKey(drawEffect);
296 int numTransforms = effectStage.getEffect()->numTransforms(); 297 int numTransforms = drawEffect.effect()->numTransforms();
297 transforms.push_back_n(numTransforms); 298 transforms.push_back_n(numTransforms);
298 299
299 SkTArray<PathTransform, true>* pathTransforms = NULL; 300 SkTArray<PathTransform, true>* pathTransforms = NULL;
300 const GrGLCaps* glCaps = builder->ctxInfo().caps(); 301 const GrGLCaps* glCaps = builder->ctxInfo().caps();
301 if (glCaps->pathRenderingSupport() && 302 if (glCaps->pathRenderingSupport() &&
302 builder->gpu()->glPathRendering()->texturingMode() == 303 builder->gpu()->glPathRendering()->texturingMode() ==
303 GrGLPathRendering::SeparableShaders_TexturingMode) { 304 GrGLPathRendering::SeparableShaders_TexturingMode) {
304 pathTransforms = &fPathTransforms.push_back(); 305 pathTransforms = &fPathTransforms.push_back();
305 pathTransforms->push_back_n(numTransforms); 306 pathTransforms->push_back_n(numTransforms);
306 } 307 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 368 }
368 369
369 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, 370 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu,
370 GrGpu::DrawType drawType, 371 GrGpu::DrawType drawType,
371 const GrGLProgramDataManager& programData Manager, 372 const GrGLProgramDataManager& programData Manager,
372 const GrEffectStage* effectStages[]) { 373 const GrEffectStage* effectStages[]) {
373 int numEffects = fGLEffects.count(); 374 int numEffects = fGLEffects.count();
374 SkASSERT(numEffects == fTransforms.count()); 375 SkASSERT(numEffects == fTransforms.count());
375 SkASSERT(numEffects == fSamplers.count()); 376 SkASSERT(numEffects == fSamplers.count());
376 for (int e = 0; e < numEffects; ++e) { 377 for (int e = 0; e < numEffects; ++e) {
377 const GrEffectStage& effectStage = *effectStages[e]; 378 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords);
378 const GrEffect& effect = *effectStage.getEffect(); 379 fGLEffects[e]->setData(programDataManager, drawEffect);
379 fGLEffects[e]->setData(programDataManager, effect);
380 if (GrGpu::IsPathRenderingDrawType(drawType)) { 380 if (GrGpu::IsPathRenderingDrawType(drawType)) {
381 this->setPathTransformData(gpu, programDataManager, effectStage, e); 381 this->setPathTransformData(gpu, programDataManager, drawEffect, e);
382 } else { 382 } else {
383 this->setTransformData(gpu, programDataManager, effectStage, e); 383 this->setTransformData(gpu, programDataManager, drawEffect, e);
384 } 384 }
385 385
386 this->bindTextures(gpu, effect, e); 386 this->bindTextures(gpu, drawEffect.effect(), e);
387 } 387 }
388 } 388 }
389 389
390 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, 390 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu,
391 GrGpu::DrawType drawType, 391 GrGpu::DrawType drawType,
392 const GrGLProgramDataManager& programData Manager, 392 const GrGLProgramDataManager& programData Manager,
393 const GrEffectStage* effectStage) { 393 const GrEffectStage* effectStage) {
394 SkASSERT(1 == fTransforms.count()); 394 SkASSERT(1 == fTransforms.count());
395 SkASSERT(1 == fSamplers.count()); 395 SkASSERT(1 == fSamplers.count());
396 SkASSERT(1 == fGLEffects.count()); 396 SkASSERT(1 == fGLEffects.count());
397 const GrEffect& effect = *effectStage->getEffect(); 397 GrDrawEffect drawEffect(*effectStage, fHasExplicitLocalCoords);
398 fGLEffects[0]->setData(programDataManager, effect); 398 fGLEffects[0]->setData(programDataManager, drawEffect);
399 if (GrGpu::IsPathRenderingDrawType(drawType)) { 399 if (GrGpu::IsPathRenderingDrawType(drawType)) {
400 this->setPathTransformData(gpu, programDataManager, *effectStage, 0); 400 this->setPathTransformData(gpu, programDataManager, drawEffect, 0);
401 } else { 401 } else {
402 this->setTransformData(gpu, programDataManager, *effectStage, 0); 402 this->setTransformData(gpu, programDataManager, drawEffect, 0);
403 } 403 }
404 404
405 this->bindTextures(gpu, effect, 0); 405 this->bindTextures(gpu, drawEffect.effect(), 0);
406 } 406 }
407 407
408 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, 408 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu,
409 const GrGLProgramDataManager& pd man, 409 const GrGLProgramDataManager& pd man,
410 const GrEffectStage& effectStage , 410 const GrDrawEffect& drawEffect,
411 int effectIdx) { 411 int effectIdx) {
412 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; 412 SkTArray<Transform, true>& transforms = fTransforms[effectIdx];
413 int numTransforms = transforms.count(); 413 int numTransforms = transforms.count();
414 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); 414 SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
415 for (int t = 0; t < numTransforms; ++t) { 415 for (int t = 0; t < numTransforms; ++t) {
416 SkASSERT(transforms[t].fHandle.isValid()); 416 SkASSERT(transforms[t].fHandle.isValid());
417 const SkMatrix& matrix = get_transform_matrix(effectStage, fHasExplicitL ocalCoords, t); 417 const SkMatrix& matrix = get_transform_matrix(drawEffect, t);
418 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { 418 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
419 pdman.setSkMatrix(transforms[t].fHandle, matrix); 419 pdman.setSkMatrix(transforms[t].fHandle, matrix);
420 transforms[t].fCurrentValue = matrix; 420 transforms[t].fCurrentValue = matrix;
421 } 421 }
422 } 422 }
423 } 423 }
424 424
425 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu, 425 void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu,
426 const GrGLProgramDataManager & pdman, 426 const GrGLProgramDataManager & pdman,
427 const GrEffectStage& effectS tage, 427 const GrDrawEffect& drawEffe ct,
428 int effectIdx) { 428 int effectIdx) {
429 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx]; 429 SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx];
430 int numTransforms = transforms.count(); 430 int numTransforms = transforms.count();
431 SkASSERT(numTransforms == effectStage.getEffect()->numTransforms()); 431 SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
432 for (int t = 0; t < numTransforms; ++t) { 432 for (int t = 0; t < numTransforms; ++t) {
433 SkASSERT(transforms[t].fHandle.isValid()); 433 SkASSERT(transforms[t].fHandle.isValid());
434 const SkMatrix& transform = get_transform_matrix(effectStage, fHasExplic itLocalCoords, t); 434 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
435 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { 435 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
436 continue; 436 continue;
437 } 437 }
438 transforms[t].fCurrentValue = transform; 438 transforms[t].fCurrentValue = transform;
439 switch (transforms[t].fType) { 439 switch (transforms[t].fType) {
440 case kVec2f_GrSLType: 440 case kVec2f_GrSLType:
441 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform); 441 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 2, transform);
442 break; 442 break;
443 case kVec3f_GrSLType: 443 case kVec3f_GrSLType:
444 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform); 444 pdman.setProgramPathFragmentInputTransform(transforms[t].fHandle , 3, transform);
(...skipping 21 matching lines...) Expand all
466 } 466 }
467 467
468 //////////////////////////////////////////////////////////////////////////////// 468 ////////////////////////////////////////////////////////////////////////////////
469 469
470 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyProgramBuilder* bu ilder, 470 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyProgramBuilder* bu ilder,
471 const GrEffectStage& stage, 471 const GrEffectStage& stage,
472 const GrEffectKey& key, 472 const GrEffectKey& key,
473 const char* outColor, 473 const char* outColor,
474 const char* inColor, 474 const char* inColor,
475 int stageIndex) { 475 int stageIndex) {
476 const GrEffect& effect = *stage.getEffect(); 476 GrDrawEffect drawEffect(stage, false);
477 SkSTArray<2, TransformedCoords> coords(effect.numTransforms()); 477 const GrEffect* effect = stage.getEffect();
478 SkSTArray<4, TextureSampler> samplers(effect.numTextures()); 478 SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
479 SkSTArray<4, TextureSampler> samplers(effect->numTextures());
479 480
480 SkASSERT(0 == effect.getVertexAttribs().count()); 481 SkASSERT(0 == effect->getVertexAttribs().count());
481 this->setupPathTexGen(builder, stage, &coords); 482 this->setupPathTexGen(builder, drawEffect, &coords);
482 this->emitSamplers(builder, effect, &samplers); 483 this->emitSamplers(builder, effect, &samplers);
483 484
484 GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect); 485 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
485 fGLEffects.push_back(glEffect); 486 fGLEffects.push_back(glEffect);
486 487
487 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 488 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
488 // Enclose custom code in a block to avoid namespace conflicts 489 // Enclose custom code in a block to avoid namespace conflicts
489 SkString openBrace; 490 SkString openBrace;
490 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); 491 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name());
491 fsBuilder->codeAppend(openBrace.c_str()); 492 fsBuilder->codeAppend(openBrace.c_str());
492 493
493 SkASSERT(!glEffect->isVertexEffect()); 494 SkASSERT(!glEffect->isVertexEffect());
494 glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers ); 495 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp lers);
495 496
496 fsBuilder->codeAppend("\t}\n"); 497 fsBuilder->codeAppend("\t}\n");
497 } 498 }
498 499
499 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyProgramBuilde r* builder, 500 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyProgramBuilde r* builder,
500 const GrEffectStage& effectStage, 501 const GrDrawEffect& drawEffect,
501 TransformedCoordsArray* outCoords) { 502 TransformedCoordsArray* outCoords) {
502 int numTransforms = effectStage.getEffect()->numTransforms(); 503 int numTransforms = drawEffect.effect()->numTransforms();
503 uint32_t totalKey = GenTransformKey(effectStage, false); 504 uint32_t totalKey = GenTransformKey(drawEffect);
504 int texCoordIndex = builder->addTexCoordSets(numTransforms); 505 int texCoordIndex = builder->addTexCoordSets(numTransforms);
505 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); 506 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex));
506 SkString name; 507 SkString name;
507 for (int t = 0; t < numTransforms; ++t) { 508 for (int t = 0; t < numTransforms; ++t) {
508 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? 509 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ?
509 kVec3f_GrSLType : 510 kVec3f_GrSLType :
510 kVec2f_GrSLType; 511 kVec2f_GrSLType;
511 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); 512 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++);
512 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); 513 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type));
513 } 514 }
514 } 515 }
515 516
516 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, 517 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu,
517 GrGpu::DrawType, 518 GrGpu::DrawType,
518 const GrGLProgramDataManager& pdman, 519 const GrGLProgramDataManager& pdman,
519 const GrEffectStage* effectStages[]) { 520 const GrEffectStage* effectStages[]) {
520 int numEffects = fGLEffects.count(); 521 int numEffects = fGLEffects.count();
521 SkASSERT(numEffects == fTransforms.count()); 522 SkASSERT(numEffects == fTransforms.count());
522 SkASSERT(numEffects == fSamplers.count()); 523 SkASSERT(numEffects == fSamplers.count());
523 for (int e = 0; e < numEffects; ++e) { 524 for (int e = 0; e < numEffects; ++e) {
524 const GrEffectStage& effectStage = *effectStages[e]; 525 GrDrawEffect drawEffect(*effectStages[e], false);
525 const GrEffect& effect = *effectStage.getEffect(); 526 fGLEffects[e]->setData(pdman, drawEffect);
526 fGLEffects[e]->setData(pdman, effect); 527 this->setPathTexGenState(gpu, drawEffect, e);
527 this->setPathTexGenState(gpu, effectStage, e); 528 this->bindTextures(gpu, drawEffect.effect(), e);
528 this->bindTextures(gpu, effect, e);
529 } 529 }
530 } 530 }
531 531
532 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, 532 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu,
533 const GrEffectStage& effectStage, 533 const GrDrawEffect& drawEffect,
534 int effectIdx) { 534 int effectIdx) {
535 uint32_t totalKey = fTransforms[effectIdx].fTransformKey; 535 uint32_t totalKey = fTransforms[effectIdx].fTransformKey;
536 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; 536 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex;
537 int numTransforms = effectStage.getEffect()->numTransforms(); 537 int numTransforms = drawEffect.effect()->numTransforms();
538 for (int t = 0; t < numTransforms; ++t) { 538 for (int t = 0; t < numTransforms; ++t) {
539 switch (get_matrix_type(totalKey, t)) { 539 switch (get_matrix_type(totalKey, t)) {
540 case kNoPersp_MatrixType: { 540 case kNoPersp_MatrixType: {
541 const SkMatrix& transform = get_transform_matrix(effectStage, fa lse, t); 541 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
542 gpu->glPathRendering()->enablePathTexGen( 542 gpu->glPathRendering()->enablePathTexGen(
543 texCoordIndex++, 543 texCoordIndex++,
544 GrGLPathRendering::kST_PathTexGenComponents, 544 GrGLPathRendering::kST_PathTexGenComponents,
545 transform); 545 transform);
546 break; 546 break;
547 } 547 }
548 case kGeneral_MatrixType: { 548 case kGeneral_MatrixType: {
549 const SkMatrix& transform = get_transform_matrix(effectStage, fa lse, t); 549 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
550 gpu->glPathRendering()->enablePathTexGen( 550 gpu->glPathRendering()->enablePathTexGen(
551 texCoordIndex++, 551 texCoordIndex++,
552 GrGLPathRendering::kSTR_PathTexGenComponents, 552 GrGLPathRendering::kSTR_PathTexGenComponents,
553 transform); 553 transform);
554 break; 554 break;
555 } 555 }
556 default: 556 default:
557 SkFAIL("Unexpected matrixs type."); 557 SkFAIL("Unexpected matrixs type.");
558 } 558 }
559 } 559 }
560 } 560 }
561 561
562 GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder( 562 GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder(
563 GrGLFragmentOnlyProgramBuilder* builder, 563 GrGLFragmentOnlyProgramBuilder* builder,
564 int reserveCount) 564 int reserveCount)
565 : fBuilder(builder) 565 : fBuilder(builder)
566 , fProgramEffects(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (reserveCount))) { 566 , fProgramEffects(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (reserveCount))) {
567 } 567 }
568 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, 568 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
569 const GrEffectKey& key, 569 const GrEffectKey& key,
570 const char* outColor, 570 const char* outColor,
571 const char* inColor, 571 const char* inColor,
572 int stageIndex) { 572 int stageIndex) {
573 SkASSERT(fProgramEffects.get()); 573 SkASSERT(fProgramEffects.get());
574 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); 574 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex);
575 } 575 }
576 576
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramEffects.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698