| OLD | NEW |
| 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 "GrDrawEffect.h" |
| 11 #include "gl/GrGLEffect.h" | 11 #include "gl/GrGLEffect.h" |
| 12 #include "gl/GrGLPathRendering.h" | 12 #include "gl/GrGLPathRendering.h" |
| 13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
| 14 #include "gl/GrGLVertexEffect.h" | 14 #include "gl/GrGLGeometryProcessor.h" |
| 15 #include "gl/GrGpuGL.h" | 15 #include "gl/GrGpuGL.h" |
| 16 | 16 |
| 17 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; | 17 typedef GrGLProgramEffects::TransformedCoords TransformedCoords; |
| 18 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; | 18 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; |
| 19 typedef GrGLProgramEffects::TextureSampler TextureSampler; | 19 typedef GrGLProgramEffects::TextureSampler TextureSampler; |
| 20 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; | 20 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * We specialize the vertex code for each of these matrix types. | 23 * We specialize the vertex code for each of these matrix types. |
| 24 */ | 24 */ |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 } | 117 } |
| 118 | 118 |
| 119 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 120 | 120 |
| 121 bool GrGLProgramEffects::GenEffectMetaKey(const GrDrawEffect& drawEffect, const
GrGLCaps& caps, | 121 bool GrGLProgramEffects::GenEffectMetaKey(const GrDrawEffect& drawEffect, const
GrGLCaps& caps, |
| 122 GrEffectKeyBuilder* b) { | 122 GrEffectKeyBuilder* b) { |
| 123 | 123 |
| 124 uint32_t textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps); | 124 uint32_t textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps); |
| 125 uint32_t transformKey = GrGLProgramEffects::GenTransformKey(drawEffect); | 125 uint32_t transformKey = GrGLProgramEffects::GenTransformKey(drawEffect); |
| 126 uint32_t attribKey = GrGLProgramEffects::GenAttribKey(drawEffect); | 126 uint32_t attribKey = GrGLProgramEffects::GenAttribKey(drawEffect.castEffect<
GrEffect>()); |
| 127 uint32_t classID = drawEffect.effect()->getFactory().effectClassID(); | 127 uint32_t classID = drawEffect.effect()->getFactory().effectClassID(); |
| 128 | 128 |
| 129 // 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 |
| 130 // don't fit. | 130 // don't fit. |
| 131 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); | 131 static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); |
| 132 if ((textureKey | transformKey | attribKey | classID) & kMetaKeyInvalidMask)
{ | 132 if ((textureKey | transformKey | attribKey | classID) & kMetaKeyInvalidMask)
{ |
| 133 return false; | 133 return false; |
| 134 } | 134 } |
| 135 | 135 |
| 136 uint32_t* key = b->add32n(2); | 136 uint32_t* key = b->add32n(2); |
| 137 key[0] = (textureKey << 16 | transformKey); | 137 key[0] = (textureKey << 16 | transformKey); |
| 138 key[1] = (classID << 16 | attribKey); | 138 key[1] = (classID << 16 | attribKey); |
| 139 return true; | 139 return true; |
| 140 } | 140 } |
| 141 | 141 |
| 142 uint32_t GrGLProgramEffects::GenAttribKey(const GrDrawEffect& drawEffect) { | 142 uint32_t GrGLProgramEffects::GenAttribKey(const GrEffect& effect) { |
| 143 uint32_t key = 0; | 143 uint32_t key = 0; |
| 144 int numAttributes = drawEffect.getVertexAttribIndexCount(); | 144 |
| 145 const GrEffect::VertexAttribArray& vars = effect.getVertexAttribs(); |
| 146 int numAttributes = vars.count(); |
| 145 SkASSERT(numAttributes <= 2); | 147 SkASSERT(numAttributes <= 2); |
| 146 const int* attributeIndices = drawEffect.getVertexAttribIndices(); | |
| 147 for (int a = 0; a < numAttributes; ++a) { | 148 for (int a = 0; a < numAttributes; ++a) { |
| 148 uint32_t value = attributeIndices[a] << 3 * a; | 149 uint32_t value = 1 << a; |
| 149 SkASSERT(0 == (value & key)); // keys for each attribute ought not to ov
erlap | |
| 150 key |= value; | 150 key |= value; |
| 151 } | 151 } |
| 152 return key; | 152 return key; |
| 153 } | 153 } |
| 154 | 154 |
| 155 uint32_t GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) { | 155 uint32_t GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) { |
| 156 uint32_t totalKey = 0; | 156 uint32_t totalKey = 0; |
| 157 int numTransforms = drawEffect.effect()->numTransforms(); | 157 int numTransforms = drawEffect.effect()->numTransforms(); |
| 158 for (int t = 0; t < numTransforms; ++t) { | 158 for (int t = 0; t < numTransforms; ++t) { |
| 159 uint32_t key = 0; | 159 uint32_t key = 0; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 272 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); |
| 273 fGLEffects.push_back(glEffect); | 273 fGLEffects.push_back(glEffect); |
| 274 | 274 |
| 275 // Enclose custom code in a block to avoid namespace conflicts | 275 // Enclose custom code in a block to avoid namespace conflicts |
| 276 SkString openBrace; | 276 SkString openBrace; |
| 277 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | 277 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); |
| 278 fsBuilder->codeAppend(openBrace.c_str()); | 278 fsBuilder->codeAppend(openBrace.c_str()); |
| 279 vsBuilder->codeAppend(openBrace.c_str()); | 279 vsBuilder->codeAppend(openBrace.c_str()); |
| 280 | 280 |
| 281 if (glEffect->isVertexEffect()) { | 281 if (glEffect->isVertexEffect()) { |
| 282 GrGLVertexEffect* vertexEffect = static_cast<GrGLVertexEffect*>(glEffect
); | 282 GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor*
>(glEffect); |
| 283 vertexEffect->emitCode(builder, drawEffect, key, outColor, inColor, coor
ds, samplers); | 283 vertexEffect->emitCode(builder, drawEffect, key, outColor, inColor, coor
ds, samplers); |
| 284 } else { | 284 } else { |
| 285 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords,
samplers); | 285 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords,
samplers); |
| 286 } | 286 } |
| 287 | 287 |
| 288 vsBuilder->codeAppend("\t}\n"); | 288 vsBuilder->codeAppend("\t}\n"); |
| 289 fsBuilder->codeAppend("\t}\n"); | 289 fsBuilder->codeAppend("\t}\n"); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, | 292 void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 GrDrawEffect drawEffect(stage, false); | 476 GrDrawEffect drawEffect(stage, false); |
| 477 const GrEffect* effect = stage.getEffect(); | 477 const GrEffect* effect = stage.getEffect(); |
| 478 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); | 478 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); |
| 479 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); | 479 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); |
| 480 | 480 |
| 481 SkASSERT(0 == stage.getVertexAttribIndexCount()); | 481 SkASSERT(0 == effect->getVertexAttribs().count()); |
| 482 this->setupPathTexGen(builder, drawEffect, &coords); | 482 this->setupPathTexGen(builder, drawEffect, &coords); |
| 483 this->emitSamplers(builder, effect, &samplers); | 483 this->emitSamplers(builder, effect, &samplers); |
| 484 | 484 |
| 485 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 485 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); |
| 486 fGLEffects.push_back(glEffect); | 486 fGLEffects.push_back(glEffect); |
| 487 | 487 |
| 488 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 488 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 489 // Enclose custom code in a block to avoid namespace conflicts | 489 // Enclose custom code in a block to avoid namespace conflicts |
| 490 SkString openBrace; | 490 SkString openBrace; |
| 491 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | 491 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |