diff options
Diffstat (limited to 'src/gpu/effects/GrDashingEffect.cpp')
-rw-r--r-- | src/gpu/effects/GrDashingEffect.cpp | 136 |
1 files changed, 65 insertions, 71 deletions
diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index 1d873de749..8e942a1dfd 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -241,7 +241,8 @@ static void setup_dashed_rect_pos(const SkRect& rect, int idx, const SkMatrix& m static GrGeometryProcessor* create_dash_gp(GrColor, DashAAMode aaMode, DashCap cap, - const SkMatrix& localMatrix); + const SkMatrix& localMatrix, + bool usesLocalCoords); class DashBatch : public GrBatch { public: @@ -315,25 +316,20 @@ public: bool isRoundCap = SkPaint::kRound_Cap == cap; DashCap capType = isRoundCap ? kRound_DashCap : kNonRound_DashCap; if (this->fullDash()) { - gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, invert)); + gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, invert, + this->usesLocalCoords())); } else { // Set up the vertex data for the line and start/end dashes gp.reset(GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, this->color(), + this->usesLocalCoords(), + this->coverageIgnored(), SkMatrix::I(), invert)); } batchTarget->initDraw(gp, pipeline); - // TODO remove this when batch is everywhere - GrPipelineInfo init; - init.fColorIgnored = fBatch.fColorIgnored; - init.fOverrideColor = GrColor_ILLEGAL; - init.fCoverageIgnored = fBatch.fCoverageIgnored; - init.fUsesLocalCoords = this->usesLocalCoords(); - gp->initBatchTracker(batchTarget->currentBatchTracker(), init); - // useAA here means Edge AA or MSAA bool useAA = this->aaMode() != kBW_DashAAMode; bool fullDash = this->fullDash(); @@ -661,6 +657,7 @@ private: DashAAMode aaMode() const { return fBatch.fAAMode; } bool fullDash() const { return fBatch.fFullDash; } SkPaint::Cap cap() const { return fBatch.fCap; } + bool coverageIgnored() const { return fBatch.fCoverageIgnored; } struct BatchTracker { GrColor fColor; @@ -750,12 +747,6 @@ bool GrDashingEffect::DrawDashLine(GrDrawTarget* target, class GLDashingCircleEffect; -struct DashingCircleBatchTracker { - GrGPInput fInputColorType; - GrColor fColor; - bool fUsesLocalCoords; -}; - /* * This effect will draw a dotted line (defined as a dashed lined with round caps and no on * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo. @@ -771,7 +762,8 @@ public: static GrGeometryProcessor* Create(GrColor, DashAAMode aaMode, - const SkMatrix& localMatrix); + const SkMatrix& localMatrix, + bool usesLocalCoords); const char* name() const override { return "DashingCircleEffect"; } @@ -785,8 +777,12 @@ public: GrColor color() const { return fColor; } + bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } + const SkMatrix& localMatrix() const { return fLocalMatrix; } + bool usesLocalCoords() const { return fUsesLocalCoords; } + virtual void getGLProcessorKey(const GrBatchTracker&, const GrGLSLCaps&, GrProcessorKeyBuilder* b) const override; @@ -794,13 +790,13 @@ public: virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker&, const GrGLSLCaps&) const override; - void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override; - private: - DashingCircleEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix); + DashingCircleEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix, + bool usesLocalCoords); GrColor fColor; SkMatrix fLocalMatrix; + bool fUsesLocalCoords; DashAAMode fAAMode; const Attribute* fInPosition; const Attribute* fInDashParams; @@ -855,7 +851,6 @@ GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&, void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); - const DashingCircleBatchTracker local = args.fBT.cast<DashingCircleBatchTracker>(); GrGLGPBuilder* pb = args.fPB; GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); @@ -873,7 +868,9 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams()->fName); // Setup pass through color - this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, &fColorUniform); + if (!dce.colorIgnored()) { + this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); + } // Setup position this->setupPosition(pb, gpArgs, dce.inPosition()->fName); @@ -904,12 +901,12 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& processor, const GrBatchTracker& bt) { - const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>(); - if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { + const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); + if (dce.color() != fColor) { GrGLfloat c[4]; - GrColorToRGBAFloat(local.fColor, c); + GrColorToRGBAFloat(dce.color(), c); pdman.set4fv(fColorUniform, 1, c); - fColor = local.fColor; + fColor = dce.color(); } } @@ -917,20 +914,21 @@ void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, const GrBatchTracker& bt, const GrGLSLCaps&, GrProcessorKeyBuilder* b) { - const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>(); const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); uint32_t key = 0; - key |= local.fUsesLocalCoords && dce.localMatrix().hasPerspective() ? 0x1 : 0x0; + key |= dce.usesLocalCoords() && dce.localMatrix().hasPerspective() ? 0x1 : 0x0; + key |= dce.colorIgnored() ? 0x2 : 0x0; key |= dce.aaMode() << 8; - b->add32(key << 16 | local.fInputColorType); + b->add32(key); } ////////////////////////////////////////////////////////////////////////////// GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, DashAAMode aaMode, - const SkMatrix& localMatrix) { - return SkNEW_ARGS(DashingCircleEffect, (color, aaMode, localMatrix)); + const SkMatrix& localMatrix, + bool usesLocalCoords) { + return SkNEW_ARGS(DashingCircleEffect, (color, aaMode, localMatrix, usesLocalCoords)); } void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, @@ -946,9 +944,11 @@ GrGLPrimitiveProcessor* DashingCircleEffect::createGLInstance(const GrBatchTrack DashingCircleEffect::DashingCircleEffect(GrColor color, DashAAMode aaMode, - const SkMatrix& localMatrix) + const SkMatrix& localMatrix, + bool usesLocalCoords) : fColor(color) , fLocalMatrix(localMatrix) + , fUsesLocalCoords(usesLocalCoords) , fAAMode(aaMode) { this->initClassID<DashingCircleEffect>(); fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); @@ -957,12 +957,6 @@ DashingCircleEffect::DashingCircleEffect(GrColor color, kVec2f_GrVertexAttribType)); } -void DashingCircleEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { - DashingCircleBatchTracker* local = bt->cast<DashingCircleBatchTracker>(); - local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); - local->fUsesLocalCoords = init.fUsesLocalCoords; -} - GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, @@ -971,19 +965,14 @@ GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, GrTexture*[]) { DashAAMode aaMode = static_cast<DashAAMode>(random->nextULessThan(kDashAAModeCount)); return DashingCircleEffect::Create(GrRandomColor(random), - aaMode, GrTest::TestMatrix(random)); + aaMode, GrTest::TestMatrix(random), + random->nextBool()); } ////////////////////////////////////////////////////////////////////////////// class GLDashingLineEffect; -struct DashingLineBatchTracker { - GrGPInput fInputColorType; - GrColor fColor; - bool fUsesLocalCoords; -}; - /* * This effect will draw a dashed line. The width of the dash is given by the strokeWidth and the * length and spacing by the DashInfo. Both of the previous two parameters are in device space. @@ -999,7 +988,8 @@ public: static GrGeometryProcessor* Create(GrColor, DashAAMode aaMode, - const SkMatrix& localMatrix); + const SkMatrix& localMatrix, + bool usesLocalCoords); const char* name() const override { return "DashingEffect"; } @@ -1013,8 +1003,12 @@ public: GrColor color() const { return fColor; } + bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } + const SkMatrix& localMatrix() const { return fLocalMatrix; } + bool usesLocalCoords() const { return fUsesLocalCoords; } + virtual void getGLProcessorKey(const GrBatchTracker& bt, const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; @@ -1022,13 +1016,13 @@ public: virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, const GrGLSLCaps&) const override; - void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override; - private: - DashingLineEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix); + DashingLineEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix, + bool usesLocalCoords); GrColor fColor; SkMatrix fLocalMatrix; + bool fUsesLocalCoords; DashAAMode fAAMode; const Attribute* fInPosition; const Attribute* fInDashParams; @@ -1076,7 +1070,6 @@ GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&, void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); - const DashingLineBatchTracker& local = args.fBT.cast<DashingLineBatchTracker>(); GrGLGPBuilder* pb = args.fPB; GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); @@ -1096,7 +1089,10 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->fName); // Setup pass through color - this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, &fColorUniform); + if (!de.colorIgnored()) { + this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); + } + // Setup position this->setupPosition(pb, gpArgs, de.inPosition()->fName); @@ -1144,12 +1140,12 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& processor, const GrBatchTracker& bt) { - const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); - if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { + const DashingLineEffect& de = processor.cast<DashingLineEffect>(); + if (de.color() != fColor) { GrGLfloat c[4]; - GrColorToRGBAFloat(local.fColor, c); + GrColorToRGBAFloat(de.color(), c); pdman.set4fv(fColorUniform, 1, c); - fColor = local.fColor; + fColor = de.color(); } } @@ -1157,20 +1153,21 @@ void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, const GrBatchTracker& bt, const GrGLSLCaps&, GrProcessorKeyBuilder* b) { - const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); const DashingLineEffect& de = gp.cast<DashingLineEffect>(); uint32_t key = 0; - key |= local.fUsesLocalCoords && de.localMatrix().hasPerspective() ? 0x1 : 0x0; + key |= de.usesLocalCoords() && de.localMatrix().hasPerspective() ? 0x1 : 0x0; + key |= de.colorIgnored() ? 0x2 : 0x0; key |= de.aaMode() << 8; - b->add32(key << 16 | local.fInputColorType); + b->add32(key); } ////////////////////////////////////////////////////////////////////////////// GrGeometryProcessor* DashingLineEffect::Create(GrColor color, DashAAMode aaMode, - const SkMatrix& localMatrix) { - return SkNEW_ARGS(DashingLineEffect, (color, aaMode, localMatrix)); + const SkMatrix& localMatrix, + bool usesLocalCoords) { + return SkNEW_ARGS(DashingLineEffect, (color, aaMode, localMatrix, usesLocalCoords)); } void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, @@ -1186,9 +1183,11 @@ GrGLPrimitiveProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker DashingLineEffect::DashingLineEffect(GrColor color, DashAAMode aaMode, - const SkMatrix& localMatrix) + const SkMatrix& localMatrix, + bool usesLocalCoords) : fColor(color) , fLocalMatrix(localMatrix) + , fUsesLocalCoords(usesLocalCoords) , fAAMode(aaMode) { this->initClassID<DashingLineEffect>(); fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); @@ -1196,12 +1195,6 @@ DashingLineEffect::DashingLineEffect(GrColor color, fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAttribType)); } -void DashingLineEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { - DashingLineBatchTracker* local = bt->cast<DashingLineBatchTracker>(); - local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); - local->fUsesLocalCoords = init.fUsesLocalCoords; -} - GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, @@ -1210,7 +1203,7 @@ GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, GrTexture*[]) { DashAAMode aaMode = static_cast<DashAAMode>(random->nextULessThan(kDashAAModeCount)); return DashingLineEffect::Create(GrRandomColor(random), - aaMode, GrTest::TestMatrix(random)); + aaMode, GrTest::TestMatrix(random), random->nextBool()); } ////////////////////////////////////////////////////////////////////////////// @@ -1218,12 +1211,13 @@ GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, static GrGeometryProcessor* create_dash_gp(GrColor color, DashAAMode dashAAMode, DashCap cap, - const SkMatrix& localMatrix) { + const SkMatrix& localMatrix, + bool usesLocalCoords) { switch (cap) { case kRound_DashCap: - return DashingCircleEffect::Create(color, dashAAMode, localMatrix); + return DashingCircleEffect::Create(color, dashAAMode, localMatrix, usesLocalCoords); case kNonRound_DashCap: - return DashingLineEffect::Create(color, dashAAMode, localMatrix); + return DashingLineEffect::Create(color, dashAAMode, localMatrix, usesLocalCoords); default: SkFAIL("Unexpected dashed cap."); } |