| Index: src/gpu/GrOvalRenderer.cpp
|
| diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
|
| index f694678e9dbb2c1d3601af3f4d576f9ec993a7a1..0b198662333c62d61e2d91f913f33a4acf211c4c 100644
|
| --- a/src/gpu/GrOvalRenderer.cpp
|
| +++ b/src/gpu/GrOvalRenderer.cpp
|
| @@ -11,7 +11,7 @@
|
| #include "GrEffect.h"
|
| #include "gl/GrGLEffect.h"
|
| #include "gl/GrGLSL.h"
|
| -#include "gl/GrGLVertexEffect.h"
|
| +#include "gl/GrGLGeometryProcessor.h"
|
| #include "GrTBackendEffectFactory.h"
|
|
|
| #include "GrDrawState.h"
|
| @@ -22,7 +22,7 @@
|
| #include "SkStrokeRec.h"
|
| #include "SkTLazy.h"
|
|
|
| -#include "effects/GrVertexEffect.h"
|
| +#include "effects/GrGeometryProcessor.h"
|
| #include "effects/GrRRectEffect.h"
|
|
|
| namespace {
|
| @@ -60,7 +60,7 @@ inline bool circle_stays_circle(const SkMatrix& m) {
|
| * specified as offset_x, offset_y (both from center point), outer radius and inner radius.
|
| */
|
|
|
| -class CircleEdgeEffect : public GrVertexEffect {
|
| +class CircleEdgeEffect : public GrGeometryProcessor {
|
| public:
|
| static GrEffect* Create(bool stroke) {
|
| GR_CREATE_STATIC_EFFECT(gCircleStrokeEdge, CircleEdgeEffect, (true));
|
| @@ -80,6 +80,8 @@ public:
|
| *validFlags = 0;
|
| }
|
|
|
| + const GrShaderVar& aCircleEdge() const { return fAttrCircleEdge; }
|
| +
|
| virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
|
| return GrTBackendEffectFactory<CircleEdgeEffect>::getInstance();
|
| }
|
| @@ -90,7 +92,7 @@ public:
|
|
|
| inline bool isStroked() const { return fStroke; }
|
|
|
| - class GLEffect : public GrGLVertexEffect {
|
| + class GLEffect : public GrGLGeometryProcessor {
|
| public:
|
| GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
| : INHERITED (factory) {}
|
| @@ -106,10 +108,8 @@ public:
|
| const char *vsName, *fsName;
|
| builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName);
|
|
|
| - GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
|
| - const SkString* attr0Name =
|
| - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
|
| - vsBuilder->codeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str());
|
| + GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();;
|
| + vsBuilder->codeAppendf("\t%s = %s;\n", vsName, circleEffect.aCircleEdge().c_str());
|
|
|
| GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
|
| fsBuilder->codeAppendf("\tfloat d = length(%s.xy);\n", fsName);
|
| @@ -132,13 +132,17 @@ public:
|
| virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_OVERRIDE {}
|
|
|
| private:
|
| - typedef GrGLVertexEffect INHERITED;
|
| + typedef GrGLGeometryProcessor INHERITED;
|
| };
|
|
|
|
|
| private:
|
| - CircleEdgeEffect(bool stroke) : GrVertexEffect() {
|
| - this->addVertexAttrib(kVec4f_GrSLType);
|
| + CircleEdgeEffect(bool stroke)
|
| + : GrGeometryProcessor()
|
| + , fAttrCircleEdge(this->addVertexAttrib(
|
| + GrShaderVar("aCircleEdge",
|
| + kVec4f_GrSLType,
|
| + GrShaderVar::kAttribute_TypeModifier))) {
|
| fStroke = stroke;
|
| }
|
|
|
| @@ -147,11 +151,12 @@ private:
|
| return cee.fStroke == fStroke;
|
| }
|
|
|
| + const GrShaderVar& fAttrCircleEdge;
|
| bool fStroke;
|
|
|
| GR_DECLARE_EFFECT_TEST;
|
|
|
| - typedef GrVertexEffect INHERITED;
|
| + typedef GrGeometryProcessor INHERITED;
|
| };
|
|
|
| GR_DEFINE_EFFECT_TEST(CircleEdgeEffect);
|
| @@ -173,7 +178,7 @@ GrEffect* CircleEdgeEffect::TestCreate(SkRandom* random,
|
| * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0.
|
| */
|
|
|
| -class EllipseEdgeEffect : public GrVertexEffect {
|
| +class EllipseEdgeEffect : public GrGeometryProcessor {
|
| public:
|
| static GrEffect* Create(bool stroke) {
|
| GR_CREATE_STATIC_EFFECT(gEllipseStrokeEdge, EllipseEdgeEffect, (true));
|
| @@ -201,9 +206,12 @@ public:
|
|
|
| static const char* Name() { return "EllipseEdge"; }
|
|
|
| + const GrShaderVar& aEllipseOffset() const { return fAttrEllipseOffset; }
|
| + const GrShaderVar& aEllipseRadii() const { return fAttrEllipseRadii; }
|
| +
|
| inline bool isStroked() const { return fStroke; }
|
|
|
| - class GLEffect : public GrGLVertexEffect {
|
| + class GLEffect : public GrGLGeometryProcessor {
|
| public:
|
| GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
| : INHERITED (factory) {}
|
| @@ -223,14 +231,11 @@ public:
|
| builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName, &fsOffsetName);
|
|
|
| GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
|
| - const SkString* attr0Name =
|
| - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
|
| - vsBuilder->codeAppendf("\t%s = %s;\n", vsOffsetName, attr0Name->c_str());
|
| + vsBuilder->codeAppendf("%s = %s;", vsOffsetName,
|
| + ellipseEffect.aEllipseOffset().c_str());
|
|
|
| builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, &fsRadiiName);
|
| - const SkString* attr1Name =
|
| - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[1]);
|
| - vsBuilder->codeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name->c_str());
|
| + vsBuilder->codeAppendf("%s = %s;", vsRadiiName, ellipseEffect.aEllipseRadii().c_str());
|
|
|
| // for outer curve
|
| GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
|
| @@ -266,13 +271,20 @@ public:
|
| }
|
|
|
| private:
|
| - typedef GrGLVertexEffect INHERITED;
|
| + typedef GrGLGeometryProcessor INHERITED;
|
| };
|
|
|
| private:
|
| - EllipseEdgeEffect(bool stroke) : GrVertexEffect() {
|
| - this->addVertexAttrib(kVec2f_GrSLType);
|
| - this->addVertexAttrib(kVec4f_GrSLType);
|
| + EllipseEdgeEffect(bool stroke)
|
| + : GrGeometryProcessor()
|
| + , fAttrEllipseOffset(this->addVertexAttrib(
|
| + GrShaderVar("aEllipseOffset",
|
| + kVec2f_GrSLType,
|
| + GrShaderVar::kAttribute_TypeModifier)))
|
| + , fAttrEllipseRadii(this->addVertexAttrib(
|
| + GrShaderVar("aEllipseRadii",
|
| + kVec4f_GrSLType,
|
| + GrShaderVar::kAttribute_TypeModifier))) {
|
| fStroke = stroke;
|
| }
|
|
|
| @@ -281,11 +293,13 @@ private:
|
| return eee.fStroke == fStroke;
|
| }
|
|
|
| + const GrShaderVar& fAttrEllipseOffset;
|
| + const GrShaderVar& fAttrEllipseRadii;
|
| bool fStroke;
|
|
|
| GR_DECLARE_EFFECT_TEST;
|
|
|
| - typedef GrVertexEffect INHERITED;
|
| + typedef GrGeometryProcessor INHERITED;
|
| };
|
|
|
| GR_DEFINE_EFFECT_TEST(EllipseEdgeEffect);
|
| @@ -308,7 +322,7 @@ GrEffect* EllipseEdgeEffect::TestCreate(SkRandom* random,
|
| * The result is device-independent and can be used with any affine matrix.
|
| */
|
|
|
| -class DIEllipseEdgeEffect : public GrVertexEffect {
|
| +class DIEllipseEdgeEffect : public GrGeometryProcessor {
|
| public:
|
| enum Mode { kStroke = 0, kHairline, kFill };
|
|
|
| @@ -342,9 +356,12 @@ public:
|
|
|
| static const char* Name() { return "DIEllipseEdge"; }
|
|
|
| + const GrShaderVar& aEllipseOffsets0() const { return fAttrEllipseOffsets0; }
|
| + const GrShaderVar& aEllipseOffsets1() const { return fAttrEllipseOffsets1; }
|
| +
|
| inline Mode getMode() const { return fMode; }
|
|
|
| - class GLEffect : public GrGLVertexEffect {
|
| + class GLEffect : public GrGLGeometryProcessor {
|
| public:
|
| GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
| : INHERITED (factory) {}
|
| @@ -363,15 +380,13 @@ public:
|
| &vsOffsetName0, &fsOffsetName0);
|
|
|
| GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder();
|
| - const SkString* attr0Name =
|
| - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
|
| - vsBuilder->codeAppendf("\t%s = %s;\n", vsOffsetName0, attr0Name->c_str());
|
| + vsBuilder->codeAppendf("%s = %s;", vsOffsetName0,
|
| + ellipseEffect.aEllipseOffsets0().c_str());
|
| const char *vsOffsetName1, *fsOffsetName1;
|
| builder->addVarying(kVec2f_GrSLType, "EllipseOffsets1",
|
| &vsOffsetName1, &fsOffsetName1);
|
| - const SkString* attr1Name =
|
| - vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[1]);
|
| - vsBuilder->codeAppendf("\t%s = %s;\n", vsOffsetName1, attr1Name->c_str());
|
| + vsBuilder->codeAppendf("\t%s = %s;\n", vsOffsetName1,
|
| + ellipseEffect.aEllipseOffsets1().c_str());
|
|
|
| GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
|
| SkAssertResult(fsBuilder->enableFeature(
|
| @@ -426,13 +441,20 @@ public:
|
| }
|
|
|
| private:
|
| - typedef GrGLVertexEffect INHERITED;
|
| + typedef GrGLGeometryProcessor INHERITED;
|
| };
|
|
|
| private:
|
| - DIEllipseEdgeEffect(Mode mode) : GrVertexEffect() {
|
| - this->addVertexAttrib(kVec2f_GrSLType);
|
| - this->addVertexAttrib(kVec2f_GrSLType);
|
| + DIEllipseEdgeEffect(Mode mode)
|
| + : GrGeometryProcessor()
|
| + , fAttrEllipseOffsets0(this->addVertexAttrib(
|
| + GrShaderVar("aEllipseOffsets0",
|
| + kVec2f_GrSLType,
|
| + GrShaderVar::kAttribute_TypeModifier)))
|
| + , fAttrEllipseOffsets1(this->addVertexAttrib(
|
| + GrShaderVar("aEllipseOffsets1",
|
| + kVec2f_GrSLType,
|
| + GrShaderVar::kAttribute_TypeModifier))) {
|
| fMode = mode;
|
| }
|
|
|
| @@ -441,11 +463,13 @@ private:
|
| return eee.fMode == fMode;
|
| }
|
|
|
| + const GrShaderVar& fAttrEllipseOffsets0;
|
| + const GrShaderVar& fAttrEllipseOffsets1;
|
| Mode fMode;
|
|
|
| GR_DECLARE_EFFECT_TEST;
|
|
|
| - typedef GrVertexEffect INHERITED;
|
| + typedef GrGeometryProcessor INHERITED;
|
| };
|
|
|
| GR_DEFINE_EFFECT_TEST(DIEllipseEdgeEffect);
|
| @@ -552,8 +576,7 @@ void GrOvalRenderer::drawCircle(GrDrawTarget* target,
|
| }
|
|
|
| GrEffect* effect = CircleEdgeEffect::Create(isStrokeOnly && innerRadius > 0);
|
| - static const int kCircleEdgeAttrIndex = 1;
|
| - drawState->setGeometryProcessor(effect, kCircleEdgeAttrIndex)->unref();
|
| + drawState->setGeometryProcessor(effect)->unref();
|
|
|
| // The radii are outset for two reasons. First, it allows the shader to simply perform
|
| // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the
|
| @@ -694,9 +717,7 @@ bool GrOvalRenderer::drawEllipse(GrDrawTarget* target,
|
| GrEffect* effect = EllipseEdgeEffect::Create(isStrokeOnly &&
|
| innerXRadius > 0 && innerYRadius > 0);
|
|
|
| - static const int kEllipseCenterAttrIndex = 1;
|
| - static const int kEllipseEdgeAttrIndex = 2;
|
| - drawState->setGeometryProcessor(effect, kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref();
|
| + drawState->setGeometryProcessor(effect)->unref();
|
|
|
| // Compute the reciprocals of the radii here to save time in the shader
|
| SkScalar xRadRecip = SkScalarInvert(xRadius);
|
| @@ -812,10 +833,7 @@ bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target,
|
|
|
| GrEffect* effect = DIEllipseEdgeEffect::Create(mode);
|
|
|
| - static const int kEllipseOuterOffsetAttrIndex = 1;
|
| - static const int kEllipseInnerOffsetAttrIndex = 2;
|
| - drawState->setGeometryProcessor(effect, kEllipseOuterOffsetAttrIndex,
|
| - kEllipseInnerOffsetAttrIndex)->unref();
|
| + drawState->setGeometryProcessor(effect)->unref();
|
|
|
| // This expands the outer rect so that after CTM we end up with a half-pixel border
|
| SkScalar a = vm[SkMatrix::kMScaleX];
|
| @@ -1062,8 +1080,7 @@ bool GrOvalRenderer::drawRRect(GrDrawTarget* target, GrContext* context, bool us
|
| isStrokeOnly = (isStrokeOnly && innerRadius >= 0);
|
|
|
| GrEffect* effect = CircleEdgeEffect::Create(isStrokeOnly);
|
| - static const int kCircleEdgeAttrIndex = 1;
|
| - drawState->setGeometryProcessor(effect, kCircleEdgeAttrIndex)->unref();
|
| + drawState->setGeometryProcessor(effect)->unref();
|
|
|
| // The radii are outset for two reasons. First, it allows the shader to simply perform
|
| // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the
|
| @@ -1166,11 +1183,7 @@ bool GrOvalRenderer::drawRRect(GrDrawTarget* target, GrContext* context, bool us
|
| EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices());
|
|
|
| GrEffect* effect = EllipseEdgeEffect::Create(isStrokeOnly);
|
| - static const int kEllipseOffsetAttrIndex = 1;
|
| - static const int kEllipseRadiiAttrIndex = 2;
|
| - drawState->setGeometryProcessor(effect,
|
| - kEllipseOffsetAttrIndex,
|
| - kEllipseRadiiAttrIndex)->unref();
|
| + drawState->setGeometryProcessor(effect)->unref();
|
|
|
| // Compute the reciprocals of the radii here to save time in the shader
|
| SkScalar xRadRecip = SkScalarInvert(xRadius);
|
|
|