| Index: src/gpu/gl/GrGLProgramEffects.cpp
|
| diff --git a/src/gpu/gl/GrGLProgramEffects.cpp b/src/gpu/gl/GrGLProgramEffects.cpp
|
| index d69cbbb4529eac7a648193f136bdf4a78430d56b..369ec1076030f25e8abccf694006692abb1fbf3a 100644
|
| --- a/src/gpu/gl/GrGLProgramEffects.cpp
|
| +++ b/src/gpu/gl/GrGLProgramEffects.cpp
|
| @@ -7,6 +7,7 @@
|
|
|
| #include "gl/builders/GrGLProgramBuilder.h"
|
| #include "GrGLProgramEffects.h"
|
| +#include "GrDrawEffect.h"
|
| #include "gl/GrGLEffect.h"
|
| #include "gl/GrGLPathRendering.h"
|
| #include "gl/builders/GrGLProgramBuilder.h"
|
| @@ -88,17 +89,15 @@
|
| /**
|
| * Retrieves the final matrix that a transform needs to apply to its source coords.
|
| */
|
| -SkMatrix get_transform_matrix(const GrEffectStage& effectStage,
|
| - bool useExplicitLocalCoords,
|
| - int transformIdx) {
|
| - const GrCoordTransform& coordTransform = effectStage.getEffect()->coordTransform(transformIdx);
|
| +SkMatrix get_transform_matrix(const GrDrawEffect& drawEffect, int transformIdx) {
|
| + const GrCoordTransform& coordTransform = drawEffect.effect()->coordTransform(transformIdx);
|
| SkMatrix combined;
|
|
|
| if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
|
| // If we have explicit local coords then we shouldn't need a coord change.
|
| - const SkMatrix& ccm =
|
| - useExplicitLocalCoords ? SkMatrix::I() : effectStage.getCoordChangeMatrix();
|
| - combined.setConcat(coordTransform.getMatrix(), ccm);
|
| + SkASSERT(!drawEffect.programHasExplicitLocalCoords() ||
|
| + drawEffect.getCoordChangeMatrix().isIdentity());
|
| + combined.setConcat(coordTransform.getMatrix(), drawEffect.getCoordChangeMatrix());
|
| } else {
|
| combined = coordTransform.getMatrix();
|
| }
|
| @@ -114,19 +113,18 @@
|
| }
|
| return combined;
|
| }
|
| +
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| -bool GrGLProgramEffects::GenEffectMetaKey(const GrEffectStage& effectStage,
|
| - bool useExplicitLocalCoords,
|
| - const GrGLCaps& caps,
|
| +bool GrGLProgramEffects::GenEffectMetaKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps,
|
| GrEffectKeyBuilder* b) {
|
|
|
| - uint32_t textureKey = GrGLProgramEffects::GenTextureKey(effectStage.getEffect(), caps);
|
| - uint32_t transformKey = GrGLProgramEffects::GenTransformKey(effectStage,useExplicitLocalCoords);
|
| - uint32_t attribKey = GrGLProgramEffects::GenAttribKey(effectStage.getEffect());
|
| - uint32_t classID = effectStage.getEffect()->getFactory().effectClassID();
|
| + uint32_t textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps);
|
| + uint32_t transformKey = GrGLProgramEffects::GenTransformKey(drawEffect);
|
| + uint32_t attribKey = GrGLProgramEffects::GenAttribKey(drawEffect.castEffect<GrEffect>());
|
| + uint32_t classID = drawEffect.effect()->getFactory().effectClassID();
|
|
|
| // Currently we allow 16 bits for each of the above portions of the meta-key. Fail if they
|
| // don't fit.
|
| @@ -141,10 +139,10 @@
|
| return true;
|
| }
|
|
|
| -uint32_t GrGLProgramEffects::GenAttribKey(const GrEffect* effect) {
|
| +uint32_t GrGLProgramEffects::GenAttribKey(const GrEffect& effect) {
|
| uint32_t key = 0;
|
|
|
| - const GrEffect::VertexAttribArray& vars = effect->getVertexAttribs();
|
| + const GrEffect::VertexAttribArray& vars = effect.getVertexAttribs();
|
| int numAttributes = vars.count();
|
| SkASSERT(numAttributes <= 2);
|
| for (int a = 0; a < numAttributes; ++a) {
|
| @@ -154,22 +152,24 @@
|
| return key;
|
| }
|
|
|
| -uint32_t GrGLProgramEffects::GenTransformKey(const GrEffectStage& effectStage,
|
| - bool useExplicitLocalCoords) {
|
| +uint32_t GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) {
|
| uint32_t totalKey = 0;
|
| - int numTransforms = effectStage.getEffect()->numTransforms();
|
| + int numTransforms = drawEffect.effect()->numTransforms();
|
| for (int t = 0; t < numTransforms; ++t) {
|
| uint32_t key = 0;
|
| - const GrCoordTransform& coordTransform = effectStage.getEffect()->coordTransform(t);
|
| + const GrCoordTransform& coordTransform = drawEffect.effect()->coordTransform(t);
|
| SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType();
|
| - SkMatrix::TypeMask type1 = SkMatrix::kIdentity_Mask;
|
| - if (kLocal_GrCoordSet == coordTransform.sourceCoords() && !useExplicitLocalCoords) {
|
| - type1 = effectStage.getCoordChangeMatrix().getType();
|
| - } else if (kPosition_GrCoordSet == coordTransform.sourceCoords() && useExplicitLocalCoords) {
|
| - // We only make the key indicate that device coords are referenced when the local coords
|
| - // are not actually determined by positions. Otherwise the local coords var and position
|
| - // var are identical.
|
| - key |= kPositionCoords_Flag;
|
| + SkMatrix::TypeMask type1;
|
| + if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
|
| + type1 = drawEffect.getCoordChangeMatrix().getType();
|
| + } else {
|
| + if (drawEffect.programHasExplicitLocalCoords()) {
|
| + // We only make the key indicate that device coords are referenced when the local coords
|
| + // are not actually determined by positions. Otherwise the local coords var and position
|
| + // var are identical.
|
| + key |= kPositionCoords_Flag;
|
| + }
|
| + type1 = SkMatrix::kIdentity_Mask;
|
| }
|
|
|
| int combinedTypes = type0 | type1;
|
| @@ -186,11 +186,11 @@
|
| return totalKey;
|
| }
|
|
|
| -uint32_t GrGLProgramEffects::GenTextureKey(const GrEffect* effect, const GrGLCaps& caps) {
|
| +uint32_t GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps) {
|
| uint32_t key = 0;
|
| - int numTextures = effect->numTextures();
|
| + int numTextures = drawEffect.effect()->numTextures();
|
| for (int t = 0; t < numTextures; ++t) {
|
| - const GrTextureAccess& access = effect->textureAccess(t);
|
| + const GrTextureAccess& access = drawEffect.effect()->textureAccess(t);
|
| uint32_t configComponentMask = GrPixelConfigComponentMask(access.getTexture()->config());
|
| if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.swizzleMask())) {
|
| key |= 1 << t;
|
| @@ -207,10 +207,10 @@
|
| }
|
|
|
| void GrGLProgramEffects::emitSamplers(GrGLProgramBuilder* builder,
|
| - const GrEffect& effect,
|
| + const GrEffect* effect,
|
| TextureSamplerArray* outSamplers) {
|
| SkTArray<Sampler, true>& samplers = fSamplers.push_back();
|
| - int numTextures = effect.numTextures();
|
| + int numTextures = effect->numTextures();
|
| samplers.push_back_n(numTextures);
|
| SkString name;
|
| for (int t = 0; t < numTextures; ++t) {
|
| @@ -219,7 +219,7 @@
|
| kSampler2D_GrSLType,
|
| name.c_str());
|
| SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler,
|
| - (samplers[t].fUniform, effect.textureAccess(t)));
|
| + (samplers[t].fUniform, effect->textureAccess(t)));
|
| }
|
| }
|
|
|
| @@ -237,13 +237,13 @@
|
| }
|
| }
|
|
|
| -void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect& effect, int effectIdx) {
|
| +void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect* effect, int effectIdx) {
|
| const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx];
|
| int numSamplers = samplers.count();
|
| - SkASSERT(numSamplers == effect.numTextures());
|
| + SkASSERT(numSamplers == effect->numTextures());
|
| for (int s = 0; s < numSamplers; ++s) {
|
| SkASSERT(samplers[s].fTextureUnit >= 0);
|
| - const GrTextureAccess& textureAccess = effect.textureAccess(s);
|
| + const GrTextureAccess& textureAccess = effect->textureAccess(s);
|
| gpu->bindTexture(samplers[s].fTextureUnit,
|
| textureAccess.getParams(),
|
| static_cast<GrGLTexture*>(textureAccess.getTexture()));
|
| @@ -258,17 +258,18 @@
|
| const char* outColor,
|
| const char* inColor,
|
| int stageIndex) {
|
| - const GrEffect& effect = *stage.getEffect();
|
| - SkSTArray<2, TransformedCoords> coords(effect.numTransforms());
|
| - SkSTArray<4, TextureSampler> samplers(effect.numTextures());
|
| + GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords);
|
| + const GrEffect* effect = stage.getEffect();
|
| + SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
|
| + SkSTArray<4, TextureSampler> samplers(effect->numTextures());
|
|
|
| GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
|
| GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
|
| vsBuilder->emitAttributes(stage);
|
| - this->emitTransforms(builder, stage, &coords);
|
| + this->emitTransforms(builder, drawEffect, &coords);
|
| this->emitSamplers(builder, effect, &samplers);
|
|
|
| - GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect);
|
| + GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
|
| fGLEffects.push_back(glEffect);
|
|
|
| // Enclose custom code in a block to avoid namespace conflicts
|
| @@ -279,9 +280,9 @@
|
|
|
| if (glEffect->isVertexEffect()) {
|
| GrGLGeometryProcessor* vertexEffect = static_cast<GrGLGeometryProcessor*>(glEffect);
|
| - vertexEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers);
|
| + vertexEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samplers);
|
| } else {
|
| - glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers);
|
| + glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samplers);
|
| }
|
|
|
| vsBuilder->codeAppend("\t}\n");
|
| @@ -289,11 +290,11 @@
|
| }
|
|
|
| void GrGLVertexProgramEffects::emitTransforms(GrGLFullProgramBuilder* builder,
|
| - const GrEffectStage& effectStage,
|
| + const GrDrawEffect& drawEffect,
|
| TransformedCoordsArray* outCoords) {
|
| SkTArray<Transform, true>& transforms = fTransforms.push_back();
|
| - uint32_t totalKey = GenTransformKey(effectStage, fHasExplicitLocalCoords);
|
| - int numTransforms = effectStage.getEffect()->numTransforms();
|
| + uint32_t totalKey = GenTransformKey(drawEffect);
|
| + int numTransforms = drawEffect.effect()->numTransforms();
|
| transforms.push_back_n(numTransforms);
|
|
|
| SkTArray<PathTransform, true>* pathTransforms = NULL;
|
| @@ -374,16 +375,15 @@
|
| SkASSERT(numEffects == fTransforms.count());
|
| SkASSERT(numEffects == fSamplers.count());
|
| for (int e = 0; e < numEffects; ++e) {
|
| - const GrEffectStage& effectStage = *effectStages[e];
|
| - const GrEffect& effect = *effectStage.getEffect();
|
| - fGLEffects[e]->setData(programDataManager, effect);
|
| + GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords);
|
| + fGLEffects[e]->setData(programDataManager, drawEffect);
|
| if (GrGpu::IsPathRenderingDrawType(drawType)) {
|
| - this->setPathTransformData(gpu, programDataManager, effectStage, e);
|
| + this->setPathTransformData(gpu, programDataManager, drawEffect, e);
|
| } else {
|
| - this->setTransformData(gpu, programDataManager, effectStage, e);
|
| - }
|
| -
|
| - this->bindTextures(gpu, effect, e);
|
| + this->setTransformData(gpu, programDataManager, drawEffect, e);
|
| + }
|
| +
|
| + this->bindTextures(gpu, drawEffect.effect(), e);
|
| }
|
| }
|
|
|
| @@ -394,27 +394,27 @@
|
| SkASSERT(1 == fTransforms.count());
|
| SkASSERT(1 == fSamplers.count());
|
| SkASSERT(1 == fGLEffects.count());
|
| - const GrEffect& effect = *effectStage->getEffect();
|
| - fGLEffects[0]->setData(programDataManager, effect);
|
| + GrDrawEffect drawEffect(*effectStage, fHasExplicitLocalCoords);
|
| + fGLEffects[0]->setData(programDataManager, drawEffect);
|
| if (GrGpu::IsPathRenderingDrawType(drawType)) {
|
| - this->setPathTransformData(gpu, programDataManager, *effectStage, 0);
|
| + this->setPathTransformData(gpu, programDataManager, drawEffect, 0);
|
| } else {
|
| - this->setTransformData(gpu, programDataManager, *effectStage, 0);
|
| - }
|
| -
|
| - this->bindTextures(gpu, effect, 0);
|
| + this->setTransformData(gpu, programDataManager, drawEffect, 0);
|
| + }
|
| +
|
| + this->bindTextures(gpu, drawEffect.effect(), 0);
|
| }
|
|
|
| void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu,
|
| const GrGLProgramDataManager& pdman,
|
| - const GrEffectStage& effectStage,
|
| + const GrDrawEffect& drawEffect,
|
| int effectIdx) {
|
| SkTArray<Transform, true>& transforms = fTransforms[effectIdx];
|
| int numTransforms = transforms.count();
|
| - SkASSERT(numTransforms == effectStage.getEffect()->numTransforms());
|
| + SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
|
| for (int t = 0; t < numTransforms; ++t) {
|
| SkASSERT(transforms[t].fHandle.isValid());
|
| - const SkMatrix& matrix = get_transform_matrix(effectStage, fHasExplicitLocalCoords, t);
|
| + const SkMatrix& matrix = get_transform_matrix(drawEffect, t);
|
| if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
|
| pdman.setSkMatrix(transforms[t].fHandle, matrix);
|
| transforms[t].fCurrentValue = matrix;
|
| @@ -424,14 +424,14 @@
|
|
|
| void GrGLVertexProgramEffects::setPathTransformData(GrGpuGL* gpu,
|
| const GrGLProgramDataManager& pdman,
|
| - const GrEffectStage& effectStage,
|
| + const GrDrawEffect& drawEffect,
|
| int effectIdx) {
|
| SkTArray<PathTransform, true>& transforms = fPathTransforms[effectIdx];
|
| int numTransforms = transforms.count();
|
| - SkASSERT(numTransforms == effectStage.getEffect()->numTransforms());
|
| + SkASSERT(numTransforms == drawEffect.effect()->numTransforms());
|
| for (int t = 0; t < numTransforms; ++t) {
|
| SkASSERT(transforms[t].fHandle.isValid());
|
| - const SkMatrix& transform = get_transform_matrix(effectStage, fHasExplicitLocalCoords, t);
|
| + const SkMatrix& transform = get_transform_matrix(drawEffect, t);
|
| if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
|
| continue;
|
| }
|
| @@ -473,15 +473,16 @@
|
| const char* outColor,
|
| const char* inColor,
|
| int stageIndex) {
|
| - const GrEffect& effect = *stage.getEffect();
|
| - SkSTArray<2, TransformedCoords> coords(effect.numTransforms());
|
| - SkSTArray<4, TextureSampler> samplers(effect.numTextures());
|
| -
|
| - SkASSERT(0 == effect.getVertexAttribs().count());
|
| - this->setupPathTexGen(builder, stage, &coords);
|
| + GrDrawEffect drawEffect(stage, false);
|
| + const GrEffect* effect = stage.getEffect();
|
| + SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
|
| + SkSTArray<4, TextureSampler> samplers(effect->numTextures());
|
| +
|
| + SkASSERT(0 == effect->getVertexAttribs().count());
|
| + this->setupPathTexGen(builder, drawEffect, &coords);
|
| this->emitSamplers(builder, effect, &samplers);
|
|
|
| - GrGLEffect* glEffect = effect.getFactory().createGLInstance(effect);
|
| + GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
|
| fGLEffects.push_back(glEffect);
|
|
|
| GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
|
| @@ -491,16 +492,16 @@
|
| fsBuilder->codeAppend(openBrace.c_str());
|
|
|
| SkASSERT(!glEffect->isVertexEffect());
|
| - glEffect->emitCode(builder, effect, key, outColor, inColor, coords, samplers);
|
| + glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samplers);
|
|
|
| fsBuilder->codeAppend("\t}\n");
|
| }
|
|
|
| void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyProgramBuilder* builder,
|
| - const GrEffectStage& effectStage,
|
| + const GrDrawEffect& drawEffect,
|
| TransformedCoordsArray* outCoords) {
|
| - int numTransforms = effectStage.getEffect()->numTransforms();
|
| - uint32_t totalKey = GenTransformKey(effectStage, false);
|
| + int numTransforms = drawEffect.effect()->numTransforms();
|
| + uint32_t totalKey = GenTransformKey(drawEffect);
|
| int texCoordIndex = builder->addTexCoordSets(numTransforms);
|
| SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex));
|
| SkString name;
|
| @@ -521,24 +522,23 @@
|
| SkASSERT(numEffects == fTransforms.count());
|
| SkASSERT(numEffects == fSamplers.count());
|
| for (int e = 0; e < numEffects; ++e) {
|
| - const GrEffectStage& effectStage = *effectStages[e];
|
| - const GrEffect& effect = *effectStage.getEffect();
|
| - fGLEffects[e]->setData(pdman, effect);
|
| - this->setPathTexGenState(gpu, effectStage, e);
|
| - this->bindTextures(gpu, effect, e);
|
| + GrDrawEffect drawEffect(*effectStages[e], false);
|
| + fGLEffects[e]->setData(pdman, drawEffect);
|
| + this->setPathTexGenState(gpu, drawEffect, e);
|
| + this->bindTextures(gpu, drawEffect.effect(), e);
|
| }
|
| }
|
|
|
| void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu,
|
| - const GrEffectStage& effectStage,
|
| + const GrDrawEffect& drawEffect,
|
| int effectIdx) {
|
| uint32_t totalKey = fTransforms[effectIdx].fTransformKey;
|
| int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex;
|
| - int numTransforms = effectStage.getEffect()->numTransforms();
|
| + int numTransforms = drawEffect.effect()->numTransforms();
|
| for (int t = 0; t < numTransforms; ++t) {
|
| switch (get_matrix_type(totalKey, t)) {
|
| case kNoPersp_MatrixType: {
|
| - const SkMatrix& transform = get_transform_matrix(effectStage, false, t);
|
| + const SkMatrix& transform = get_transform_matrix(drawEffect, t);
|
| gpu->glPathRendering()->enablePathTexGen(
|
| texCoordIndex++,
|
| GrGLPathRendering::kST_PathTexGenComponents,
|
| @@ -546,7 +546,7 @@
|
| break;
|
| }
|
| case kGeneral_MatrixType: {
|
| - const SkMatrix& transform = get_transform_matrix(effectStage, false, t);
|
| + const SkMatrix& transform = get_transform_matrix(drawEffect, t);
|
| gpu->glPathRendering()->enablePathTexGen(
|
| texCoordIndex++,
|
| GrGLPathRendering::kSTR_PathTexGenComponents,
|
|
|