From 249af15fb82833d2274850c589812b6e69df0033 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Mon, 15 Sep 2014 11:41:13 -0700 Subject: BUG=skia: R=bsalomon@google.com, egdaniel@google.com, jvanverth@google.com, robertphillips@google.com Author: joshualitt@chromium.org Review URL: https://codereview.chromium.org/543623004 --- src/gpu/effects/GrBezierEffect.cpp | 53 ++++++++++--------- src/gpu/effects/GrBezierEffect.h | 26 ++++++---- src/gpu/effects/GrCustomCoordsTextureEffect.cpp | 21 ++++---- src/gpu/effects/GrCustomCoordsTextureEffect.h | 11 ++-- src/gpu/effects/GrDashingEffect.cpp | 66 ++++++++++++++---------- src/gpu/effects/GrDistanceFieldTextureEffect.cpp | 39 +++++++------- src/gpu/effects/GrDistanceFieldTextureEffect.h | 27 ++++++---- src/gpu/effects/GrGeometryProcessor.h | 41 +++++++++++++++ src/gpu/effects/GrVertexEffect.h | 37 ------------- 9 files changed, 178 insertions(+), 143 deletions(-) create mode 100644 src/gpu/effects/GrGeometryProcessor.h delete mode 100644 src/gpu/effects/GrVertexEffect.h (limited to 'src/gpu/effects') diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp index 488af1585f..8c85809078 100644 --- a/src/gpu/effects/GrBezierEffect.cpp +++ b/src/gpu/effects/GrBezierEffect.cpp @@ -10,10 +10,10 @@ #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" -#include "gl/GrGLVertexEffect.h" +#include "gl/GrGLGeometryProcessor.h" #include "GrTBackendEffectFactory.h" -class GrGLConicEffect : public GrGLVertexEffect { +class GrGLConicEffect : public GrGLGeometryProcessor { public: GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); @@ -32,7 +32,7 @@ public: private: GrEffectEdgeType fEdgeType; - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; GrGLConicEffect::GrGLConicEffect(const GrBackendEffectFactory& factory, @@ -54,10 +54,9 @@ void GrGLConicEffect::emitCode(GrGLFullProgramBuilder* builder, builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", &vsName, &fsName); + const GrShaderVar& inConicCoeffs = drawEffect.castEffect().inConicCoeffs(); GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attr0Name = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("%s = %s;", vsName, attr0Name->c_str()); + vsBuilder->codeAppendf("%s = %s;", vsName, inConicCoeffs.c_str()); GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); fsBuilder->codeAppend("float edgeAlpha;"); @@ -135,9 +134,11 @@ const GrBackendEffectFactory& GrConicEffect::getFactory() const { return GrTBackendEffectFactory::getInstance(); } -GrConicEffect::GrConicEffect(GrEffectEdgeType edgeType) : GrVertexEffect() { - this->addVertexAttrib(kVec4f_GrSLType); - fEdgeType = edgeType; +GrConicEffect::GrConicEffect(GrEffectEdgeType edgeType) + : fEdgeType(edgeType) + , fInConicCoeffs(this->addVertexAttrib(GrShaderVar("inConicCoeffs", + kVec4f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { } bool GrConicEffect::onIsEqual(const GrEffect& other) const { @@ -166,7 +167,7 @@ GrEffect* GrConicEffect::TestCreate(SkRandom* random, // Quad ////////////////////////////////////////////////////////////////////////////// -class GrGLQuadEffect : public GrGLVertexEffect { +class GrGLQuadEffect : public GrGLGeometryProcessor { public: GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&); @@ -185,7 +186,7 @@ public: private: GrEffectEdgeType fEdgeType; - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; GrGLQuadEffect::GrGLQuadEffect(const GrBackendEffectFactory& factory, @@ -206,9 +207,8 @@ void GrGLQuadEffect::emitCode(GrGLFullProgramBuilder* builder, builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName); GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attrName = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("%s = %s;", vsName, attrName->c_str()); + const GrShaderVar& inHairQuadEdge = drawEffect.castEffect().inHairQuadEdge(); + vsBuilder->codeAppendf("%s = %s;", vsName, inHairQuadEdge.c_str()); GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); fsBuilder->codeAppendf("float edgeAlpha;"); @@ -272,9 +272,11 @@ const GrBackendEffectFactory& GrQuadEffect::getFactory() const { return GrTBackendEffectFactory::getInstance(); } -GrQuadEffect::GrQuadEffect(GrEffectEdgeType edgeType) : GrVertexEffect() { - this->addVertexAttrib(kVec4f_GrSLType); - fEdgeType = edgeType; +GrQuadEffect::GrQuadEffect(GrEffectEdgeType edgeType) + : fEdgeType(edgeType) + , fInHairQuadEdge(this->addVertexAttrib(GrShaderVar("inCubicCoeffs", + kVec4f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { } bool GrQuadEffect::onIsEqual(const GrEffect& other) const { @@ -303,7 +305,7 @@ GrEffect* GrQuadEffect::TestCreate(SkRandom* random, // Cubic ////////////////////////////////////////////////////////////////////////////// -class GrGLCubicEffect : public GrGLVertexEffect { +class GrGLCubicEffect : public GrGLGeometryProcessor { public: GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); @@ -322,7 +324,7 @@ public: private: GrEffectEdgeType fEdgeType; - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; GrGLCubicEffect::GrGLCubicEffect(const GrBackendEffectFactory& factory, @@ -345,9 +347,8 @@ void GrGLCubicEffect::emitCode(GrGLFullProgramBuilder* builder, &vsName, &fsName, GrGLShaderVar::kHigh_Precision); GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attr0Name = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("%s = %s;", vsName, attr0Name->c_str()); + const GrShaderVar& inCubicCoeffs = drawEffect.castEffect().inCubicCoeffs(); + vsBuilder->codeAppendf("%s = %s;", vsName, inCubicCoeffs.c_str()); GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); @@ -451,9 +452,11 @@ const GrBackendEffectFactory& GrCubicEffect::getFactory() const { return GrTBackendEffectFactory::getInstance(); } -GrCubicEffect::GrCubicEffect(GrEffectEdgeType edgeType) : GrVertexEffect() { - this->addVertexAttrib(kVec4f_GrSLType); - fEdgeType = edgeType; +GrCubicEffect::GrCubicEffect(GrEffectEdgeType edgeType) + : fEdgeType(edgeType) + , fInCubicCoeffs(this->addVertexAttrib(GrShaderVar("inCubicCoeffs", + kVec4f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { } bool GrCubicEffect::onIsEqual(const GrEffect& other) const { diff --git a/src/gpu/effects/GrBezierEffect.h b/src/gpu/effects/GrBezierEffect.h index b8d8f7b2e4..4da16fe88b 100644 --- a/src/gpu/effects/GrBezierEffect.h +++ b/src/gpu/effects/GrBezierEffect.h @@ -10,7 +10,7 @@ #include "GrDrawTargetCaps.h" #include "GrEffect.h" -#include "GrVertexEffect.h" +#include "GrGeometryProcessor.h" #include "GrTypesPriv.h" /** @@ -55,7 +55,7 @@ */ class GrGLConicEffect; -class GrConicEffect : public GrVertexEffect { +class GrConicEffect : public GrGeometryProcessor { public: static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetCaps& caps) { GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrEffectEdgeType)); @@ -86,6 +86,7 @@ public: static const char* Name() { return "Conic"; } + inline const GrShaderVar& inConicCoeffs() const { return fInConicCoeffs; } inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); } inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } @@ -104,11 +105,12 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; - GrEffectEdgeType fEdgeType; + GrEffectEdgeType fEdgeType; + const GrShaderVar& fInConicCoeffs; GR_DECLARE_EFFECT_TEST; - typedef GrVertexEffect INHERITED; + typedef GrGeometryProcessor INHERITED; }; /////////////////////////////////////////////////////////////////////////////// @@ -122,7 +124,7 @@ private: */ class GrGLQuadEffect; -class GrQuadEffect : public GrVertexEffect { +class GrQuadEffect : public GrGeometryProcessor { public: static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetCaps& caps) { GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrEffectEdgeType)); @@ -153,6 +155,7 @@ public: static const char* Name() { return "Quad"; } + inline const GrShaderVar& inHairQuadEdge() const { return fInHairQuadEdge; } inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); } inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } @@ -171,11 +174,12 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; - GrEffectEdgeType fEdgeType; + GrEffectEdgeType fEdgeType; + const GrShaderVar& fInHairQuadEdge; GR_DECLARE_EFFECT_TEST; - typedef GrVertexEffect INHERITED; + typedef GrGeometryProcessor INHERITED; }; ////////////////////////////////////////////////////////////////////////////// @@ -191,7 +195,7 @@ private: */ class GrGLCubicEffect; -class GrCubicEffect : public GrVertexEffect { +class GrCubicEffect : public GrGeometryProcessor { public: static GrEffect* Create(const GrEffectEdgeType edgeType, const GrDrawTargetCaps& caps) { GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrEffectEdgeType)); @@ -222,6 +226,7 @@ public: static const char* Name() { return "Cubic"; } + inline const GrShaderVar& inCubicCoeffs() const { return fInCubicCoeffs; } inline bool isAntiAliased() const { return GrEffectEdgeTypeIsAA(fEdgeType); } inline bool isFilled() const { return GrEffectEdgeTypeIsFill(fEdgeType); } inline GrEffectEdgeType getEdgeType() const { return fEdgeType; } @@ -240,11 +245,12 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; - GrEffectEdgeType fEdgeType; + GrEffectEdgeType fEdgeType; + const GrShaderVar& fInCubicCoeffs; GR_DECLARE_EFFECT_TEST; - typedef GrVertexEffect INHERITED; + typedef GrGeometryProcessor INHERITED; }; #endif diff --git a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp index 0401c6c7ef..206c5245be 100644 --- a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp +++ b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp @@ -10,11 +10,11 @@ #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" -#include "gl/GrGLVertexEffect.h" +#include "gl/GrGLGeometryProcessor.h" #include "GrTBackendEffectFactory.h" #include "GrTexture.h" -class GrGLCustomCoordsTextureEffect : public GrGLVertexEffect { +class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { public: GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect) : INHERITED (factory) {} @@ -26,7 +26,9 @@ public: const char* inputColor, const TransformedCoordsArray&, const TextureSamplerArray& samplers) SK_OVERRIDE { - SkASSERT(1 == drawEffect.castEffect().numVertexAttribs()); + const GrCustomCoordsTextureEffect& customCoordsTextureEffect = + drawEffect.castEffect(); + SkASSERT(1 == customCoordsTextureEffect.getVertexAttribs().count()); SkString fsCoordName; const char* vsVaryingName; @@ -35,9 +37,8 @@ public: fsCoordName = fsVaryingNamePtr; GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attr0Name = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, attr0Name->c_str()); + const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTextureCoords(); + vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, inTextureCoords.c_str()); GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); fsBuilder->codeAppendf("\t%s = ", outputColor); @@ -52,16 +53,18 @@ public: const GrDrawEffect& drawEffect) SK_OVERRIDE {} private: - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; /////////////////////////////////////////////////////////////////////////////// GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, const GrTextureParams& params) - : fTextureAccess(texture, params) { + : fTextureAccess(texture, params) + , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", + kVec2f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { this->addTextureAccess(&fTextureAccess); - this->addVertexAttrib(kVec2f_GrSLType); } bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const { diff --git a/src/gpu/effects/GrCustomCoordsTextureEffect.h b/src/gpu/effects/GrCustomCoordsTextureEffect.h index 95e0fbba14..02e7c44013 100644 --- a/src/gpu/effects/GrCustomCoordsTextureEffect.h +++ b/src/gpu/effects/GrCustomCoordsTextureEffect.h @@ -9,7 +9,7 @@ #define GrCustomCoordsTextureEffect_DEFINED #include "GrEffect.h" -#include "GrVertexEffect.h" +#include "GrGeometryProcessor.h" class GrGLCustomCoordsTextureEffect; @@ -18,7 +18,7 @@ class GrGLCustomCoordsTextureEffect; * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input * coords are a custom attribute. */ -class GrCustomCoordsTextureEffect : public GrVertexEffect { +class GrCustomCoordsTextureEffect : public GrGeometryProcessor { public: static GrEffect* Create(GrTexture* tex, const GrTextureParams& p) { return SkNEW_ARGS(GrCustomCoordsTextureEffect, (tex, p)); @@ -30,6 +30,8 @@ public: virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; + const GrShaderVar& inTextureCoords() const { return fInTextureCoords; } + typedef GrGLCustomCoordsTextureEffect GLEffect; virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; @@ -39,11 +41,12 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; - GrTextureAccess fTextureAccess; + GrTextureAccess fTextureAccess; + const GrShaderVar& fInTextureCoords; GR_DECLARE_EFFECT_TEST; - typedef GrVertexEffect INHERITED; + typedef GrGeometryProcessor INHERITED; }; #endif diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index f4298eb4a0..398b0dd673 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -10,9 +10,9 @@ #include "../GrAARectRenderer.h" -#include "effects/GrVertexEffect.h" +#include "effects/GrGeometryProcessor.h" #include "gl/GrGLEffect.h" -#include "gl/GrGLVertexEffect.h" +#include "gl/GrGLGeometryProcessor.h" #include "gl/GrGLSL.h" #include "GrContext.h" #include "GrCoordTransform.h" @@ -69,6 +69,10 @@ struct DashLineVertex { SkPoint fDashPos; }; +extern const GrVertexAttrib gDashLineNoAAVertexAttribs[] = { + { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding } +}; + extern const GrVertexAttrib gDashLineVertexAttribs[] = { { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, { kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBinding }, @@ -346,12 +350,16 @@ bool GrDashingEffect::DrawDashLine(const SkPoint pts[2], const GrPaint& paint, GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_DashCap : GrDashingEffect::kNonRound_DashCap; drawState->setGeometryProcessor( - GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType), 1)->unref(); - } + GrDashingEffect::Create(edgeType, devInfo, strokeWidth, capType))->unref(); - // Set up the vertex data for the line and start/end dashes - drawState->setVertexAttribs(SK_ARRAY_COUNT(gDashLineVertexAttribs), - sizeof(DashLineVertex)); + // Set up the vertex data for the line and start/end dashes + drawState->setVertexAttribs(SK_ARRAY_COUNT(gDashLineVertexAttribs), + sizeof(DashLineVertex)); + } else { + // Set up the vertex data for the line and start/end dashes + drawState->setVertexAttribs( + SK_ARRAY_COUNT(gDashLineNoAAVertexAttribs), sizeof(DashLineVertex)); + } int totalRectCnt = 0; @@ -424,7 +432,7 @@ class GLDashingCircleEffect; * transform the line to be horizontal, with the start of line at the origin then shifted to the * right by half the off interval. The line then goes in the positive x direction. */ -class DashingCircleEffect : public GrVertexEffect { +class DashingCircleEffect : public GrGeometryProcessor { public: typedef SkPathEffect::DashInfo DashInfo; @@ -434,6 +442,8 @@ public: static const char* Name() { return "DashingCircleEffect"; } + const GrShaderVar& inCoord() const { return fInCoord; } + GrEffectEdgeType getEdgeType() const { return fEdgeType; } SkScalar getRadius() const { return fRadius; } @@ -454,18 +464,19 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; GrEffectEdgeType fEdgeType; + const GrShaderVar& fInCoord; SkScalar fIntervalLength; SkScalar fRadius; SkScalar fCenterX; GR_DECLARE_EFFECT_TEST; - typedef GrVertexEffect INHERITED; + typedef GrGeometryProcessor INHERITED; }; ////////////////////////////////////////////////////////////////////////////// -class GLDashingCircleEffect : public GrGLVertexEffect { +class GLDashingCircleEffect : public GrGLGeometryProcessor { public: GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); @@ -486,7 +497,7 @@ private: SkScalar fPrevRadius; SkScalar fPrevCenterX; SkScalar fPrevIntervalLength; - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& factory, @@ -517,9 +528,7 @@ void GLDashingCircleEffect::emitCode(GrGLFullProgramBuilder* builder, builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attr0Name = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str()); + vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dce.inCoord().c_str()); // transforms all points so that we can compare them to our test circle GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); @@ -582,14 +591,15 @@ const GrBackendEffectFactory& DashingCircleEffect::getFactory() const { DashingCircleEffect::DashingCircleEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar radius) - : fEdgeType(edgeType) { + : fEdgeType(edgeType) + , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord", + kVec2f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { SkScalar onLen = info.fIntervals[0]; SkScalar offLen = info.fIntervals[1]; fIntervalLength = onLen + offLen; fRadius = radius; fCenterX = SkScalarHalf(offLen); - - this->addVertexAttrib(kVec2f_GrSLType); } bool DashingCircleEffect::onIsEqual(const GrEffect& other) const { @@ -635,7 +645,7 @@ class GLDashingLineEffect; * line at the origin then shifted to the right by half the off interval. The line then goes in the * positive x direction. */ -class DashingLineEffect : public GrVertexEffect { +class DashingLineEffect : public GrGeometryProcessor { public: typedef SkPathEffect::DashInfo DashInfo; @@ -645,6 +655,8 @@ public: static const char* Name() { return "DashingEffect"; } + const GrShaderVar& inCoord() const { return fInCoord; } + GrEffectEdgeType getEdgeType() const { return fEdgeType; } const SkRect& getRect() const { return fRect; } @@ -663,17 +675,18 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; GrEffectEdgeType fEdgeType; + const GrShaderVar& fInCoord; SkRect fRect; SkScalar fIntervalLength; GR_DECLARE_EFFECT_TEST; - typedef GrVertexEffect INHERITED; + typedef GrGeometryProcessor INHERITED; }; ////////////////////////////////////////////////////////////////////////////// -class GLDashingLineEffect : public GrGLVertexEffect { +class GLDashingLineEffect : public GrGLGeometryProcessor { public: GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&); @@ -694,7 +707,7 @@ private: GrGLProgramDataManager::UniformHandle fIntervalUniform; SkRect fPrevRect; SkScalar fPrevIntervalLength; - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, @@ -729,9 +742,7 @@ void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder, const char *vsCoordName, *fsCoordName; builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attr0Name = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str()); + vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, de.inCoord().c_str()); // transforms all points so that we can compare them to our test rect GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); @@ -801,15 +812,16 @@ const GrBackendEffectFactory& DashingLineEffect::getFactory() const { DashingLineEffect::DashingLineEffect(GrEffectEdgeType edgeType, const DashInfo& info, SkScalar strokeWidth) - : fEdgeType(edgeType) { + : fEdgeType(edgeType) + , fInCoord(this->addVertexAttrib(GrShaderVar("inCoord", + kVec2f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { SkScalar onLen = info.fIntervals[0]; SkScalar offLen = info.fIntervals[1]; SkScalar halfOffLen = SkScalarHalf(offLen); SkScalar halfStroke = SkScalarHalf(strokeWidth); fIntervalLength = onLen + offLen; fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); - - this->addVertexAttrib(kVec2f_GrSLType); } bool DashingLineEffect::onIsEqual(const GrEffect& other) const { diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp index eaaefebc54..ee7dd61387 100755 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp @@ -10,7 +10,7 @@ #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" -#include "gl/GrGLVertexEffect.h" +#include "gl/GrGLGeometryProcessor.h" #include "GrTBackendEffectFactory.h" #include "GrTexture.h" @@ -29,7 +29,7 @@ // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/2 #define SK_DistanceFieldAAFactor "0.7071" -class GrGLDistanceFieldTextureEffect : public GrGLVertexEffect { +class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { public: GrGLDistanceFieldTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect) @@ -43,13 +43,13 @@ public: const char* inputColor, const TransformedCoordsArray&, const TextureSamplerArray& samplers) SK_OVERRIDE { - SkASSERT(1 == drawEffect.castEffect().numVertexAttribs()); + const GrDistanceFieldTextureEffect& dfTexEffect = + drawEffect.castEffect(); + SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); SkAssertResult(fsBuilder->enableFeature( GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); - const GrDistanceFieldTextureEffect& dfTexEffect = - drawEffect.castEffect(); SkString fsCoordName; const char* vsCoordName; @@ -58,9 +58,7 @@ public: fsCoordName = fsCoordNamePtr; GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attr0Name = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str()); + vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextureCoords().c_str()); const char* textureSizeUniName = NULL; fTextureSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, @@ -165,7 +163,7 @@ private: GrGLProgramDataManager::UniformHandle fLuminanceUni; float fLuminance; - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; /////////////////////////////////////////////////////////////////////////////// @@ -183,13 +181,15 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrTexture* texture, , fGammaTextureAccess(gamma, gammaParams) , fLuminance(luminance) #endif - , fFlags(flags & kNonLCD_DistanceFieldEffectMask) { + , fFlags(flags & kNonLCD_DistanceFieldEffectMask) + , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", + kVec2f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); this->addTextureAccess(&fTextureAccess); #ifdef SK_GAMMA_APPLY_TO_A8 this->addTextureAccess(&fGammaTextureAccess); #endif - this->addVertexAttrib(kVec2f_GrSLType); } bool GrDistanceFieldTextureEffect::onIsEqual(const GrEffect& other) const { @@ -257,7 +257,7 @@ GrEffect* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, /////////////////////////////////////////////////////////////////////////////// -class GrGLDistanceFieldLCDTextureEffect : public GrGLVertexEffect { +class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { public: GrGLDistanceFieldLCDTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect) @@ -271,10 +271,9 @@ public: const char* inputColor, const TransformedCoordsArray&, const TextureSamplerArray& samplers) SK_OVERRIDE { - SkASSERT(1 == drawEffect.castEffect().numVertexAttribs()); - const GrDistanceFieldLCDTextureEffect& dfTexEffect = drawEffect.castEffect(); + SkASSERT(1 == dfTexEffect.getVertexAttribs().count()); SkString fsCoordName; const char* vsCoordName; @@ -283,9 +282,7 @@ public: fsCoordName = fsCoordNamePtr; GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); - const SkString* attr0Name = - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); - vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, attr0Name->c_str()); + vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dfTexEffect.inTextureCoords().c_str()); const char* textureSizeUniName = NULL; // width, height, 1/(3*width) @@ -443,7 +440,7 @@ private: GrGLProgramDataManager::UniformHandle fTextColorUni; SkColor fTextColor; - typedef GrGLVertexEffect INHERITED; + typedef GrGLGeometryProcessor INHERITED; }; /////////////////////////////////////////////////////////////////////////////// @@ -456,12 +453,14 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( : fTextureAccess(texture, params) , fGammaTextureAccess(gamma, gParams) , fTextColor(textColor) - , fFlags(flags & kLCD_DistanceFieldEffectMask) { + , fFlags(flags & kLCD_DistanceFieldEffectMask) + , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", + kVec2f_GrSLType, + GrShaderVar::kAttribute_TypeModifier))) { SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_DistanceFieldEffectFlag)); this->addTextureAccess(&fTextureAccess); this->addTextureAccess(&fGammaTextureAccess); - this->addVertexAttrib(kVec2f_GrSLType); } bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrEffect& other) const { diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.h b/src/gpu/effects/GrDistanceFieldTextureEffect.h index dca1949c50..5f08edaa79 100644 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.h +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.h @@ -9,7 +9,7 @@ #define GrDistanceFieldTextureEffect_DEFINED #include "GrEffect.h" -#include "GrVertexEffect.h" +#include "GrGeometryProcessor.h" class GrGLDistanceFieldTextureEffect; class GrGLDistanceFieldLCDTextureEffect; @@ -38,7 +38,7 @@ enum GrDistanceFieldEffectFlags { * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input * coords are a custom attribute. Gamma correction is handled via a texture LUT. */ -class GrDistanceFieldTextureEffect : public GrVertexEffect { +class GrDistanceFieldTextureEffect : public GrGeometryProcessor { public: #ifdef SK_GAMMA_APPLY_TO_A8 static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, @@ -59,6 +59,8 @@ public: static const char* Name() { return "DistanceFieldTexture"; } virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; + + const GrShaderVar& inTextureCoords() const { return fInTextureCoords; } #ifdef SK_GAMMA_APPLY_TO_A8 float getLuminance() const { return fLuminance; } #endif @@ -77,12 +79,13 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; - GrTextureAccess fTextureAccess; + GrTextureAccess fTextureAccess; #ifdef SK_GAMMA_APPLY_TO_A8 - GrTextureAccess fGammaTextureAccess; - float fLuminance; + GrTextureAccess fGammaTextureAccess; + float fLuminance; #endif - uint32_t fFlags; + uint32_t fFlags; + const GrShaderVar& fInTextureCoords; GR_DECLARE_EFFECT_TEST; @@ -95,7 +98,7 @@ private: * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input * coords are a custom attribute. Gamma correction is handled via a texture LUT. */ -class GrDistanceFieldLCDTextureEffect : public GrVertexEffect { +class GrDistanceFieldLCDTextureEffect : public GrGeometryProcessor { public: static GrEffect* Create(GrTexture* tex, const GrTextureParams& params, GrTexture* gamma, const GrTextureParams& gammaParams, @@ -108,6 +111,7 @@ public: static const char* Name() { return "DistanceFieldLCDTexture"; } + const GrShaderVar& inTextureCoords() const { return fInTextureCoords; } virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; GrColor getTextColor() const { return fTextColor; } uint32_t getFlags() const { return fFlags; } @@ -124,10 +128,11 @@ private: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; - GrTextureAccess fTextureAccess; - GrTextureAccess fGammaTextureAccess; - GrColor fTextColor; - uint32_t fFlags; + GrTextureAccess fTextureAccess; + GrTextureAccess fGammaTextureAccess; + GrColor fTextColor; + uint32_t fFlags; + const GrShaderVar& fInTextureCoords; GR_DECLARE_EFFECT_TEST; diff --git a/src/gpu/effects/GrGeometryProcessor.h b/src/gpu/effects/GrGeometryProcessor.h new file mode 100644 index 0000000000..0e1c80c150 --- /dev/null +++ b/src/gpu/effects/GrGeometryProcessor.h @@ -0,0 +1,41 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGeometryProcessor_DEFINED +#define GrGeometryProcessor_DEFINED + +#include "GrEffect.h" + +/** + * If an effect needs specialized vertex shader code, then it must inherit from this class. + * Otherwise it won't be able to add vertex attribs, and it will be given a vertexless shader + * program in emitCode. + */ +class GrGeometryProcessor : public GrEffect { +public: + GrGeometryProcessor() { fRequiresVertexShader = true; } + +protected: + /** + * Subclasses call this from their constructor to register vertex attributes (at most + * kMaxVertexAttribs). This must only be called from the constructor because GrEffects are + * immutable. + * + * We return a reference to the added var so that derived classes can name it nicely and use it + * in shader code. + */ + const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { + SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier()); + SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); + return fVertexAttribs.push_back(var); + } + +private: + typedef GrEffect INHERITED; +}; + +#endif diff --git a/src/gpu/effects/GrVertexEffect.h b/src/gpu/effects/GrVertexEffect.h deleted file mode 100644 index 323c85e34e..0000000000 --- a/src/gpu/effects/GrVertexEffect.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrVertexEffect_DEFINED -#define GrVertexEffect_DEFINED - -#include "GrEffect.h" - -/** - * If an effect needs specialized vertex shader code, then it must inherit from this class. - * Otherwise it won't be able to add vertex attribs, and it might be given a vertexless shader - * program in emitCode. - */ -class GrVertexEffect : public GrEffect { -public: - GrVertexEffect() { fRequiresVertexShader = true; } - -protected: - /** - * Subclasses call this from their constructor to register vertex attributes (at most - * kMaxVertexAttribs). This must only be called from the constructor because GrEffects are - * immutable. - */ - void addVertexAttrib(GrSLType type) { - SkASSERT(fVertexAttribTypes.count() < kMaxVertexAttribs); - fVertexAttribTypes.push_back(type); - } - -private: - typedef GrEffect INHERITED; -}; - -#endif -- cgit v1.2.3