diff options
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrOpFlushState.h | 4 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 34 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.h | 4 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 12 | ||||
-rw-r--r-- | src/gpu/effects/GrShadowGeoProc.cpp | 24 | ||||
-rw-r--r-- | src/gpu/effects/GrShadowGeoProc.h | 12 | ||||
-rw-r--r-- | src/gpu/ops/GrShadowRRectOp.cpp | 90 | ||||
-rw-r--r-- | src/gpu/ops/GrShadowRRectOp.h | 10 |
8 files changed, 72 insertions, 118 deletions
diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h index 42daab3960..a701965d4d 100644 --- a/src/gpu/GrOpFlushState.h +++ b/src/gpu/GrOpFlushState.h @@ -245,6 +245,10 @@ public: return this->state()->allocPipeline(std::forward<Args>(args)...); } + /** + * Helper that makes a pipeline targeting the op's render target that incorporates the op's + * GrAppliedClip. + * */ GrPipeline* makePipeline(uint32_t pipelineFlags, const GrProcessorSet* processorSet) { GrPipeline::InitArgs pipelineArgs; pipelineArgs.fFlags = pipelineFlags; diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index e274a3bd86..7baf512bad 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -956,7 +956,7 @@ static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) { } bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, - GrPaint&& paint, + GrColor color4ub, const SkMatrix& viewMatrix, const SkPath& path, const SkDrawShadowRec& rec) { @@ -1011,7 +1011,7 @@ bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, viewMatrix[SkMatrix::kMSkewX] * viewMatrix[SkMatrix::kMSkewX]); SkScalar occluderHeight = rec.fZPlaneParams.fZ; - GrColor4f color = paint.getColor4f(); + GrColor4f color = GrColor4f::FromGrColor(color4ub); bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag); bool tonalColor = SkToBool(rec.fFlags & SkShadowFlags::kTonalColor_ShadowFlag); @@ -1051,15 +1051,13 @@ bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, // which is just 1/umbraAlpha. SkScalar blurClamp = SkScalarInvert(umbraAlpha); - std::unique_ptr<GrLegacyMeshDrawOp> op = GrShadowRRectOp::Make(ambientColor, viewMatrix, - ambientRRect, - devSpaceAmbientBlur, - devSpaceInsetWidth, - blurClamp); - if (op) { - GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone); - this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); - } + std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(ambientColor, viewMatrix, + ambientRRect, + devSpaceAmbientBlur, + devSpaceInsetWidth, + blurClamp); + SkASSERT(op); + this->addDrawOp(clip, std::move(op)); } if (rec.fSpotAlpha > 0) { @@ -1163,14 +1161,12 @@ bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, spotColor = color.mulByScalar(rec.fSpotAlpha).toGrColor(); } - std::unique_ptr<GrLegacyMeshDrawOp> op = GrShadowRRectOp::Make(spotColor, viewMatrix, - spotShadowRRect, - devSpaceSpotBlur, - insetWidth); - if (op) { - GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone); - this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); - } + std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(spotColor, viewMatrix, + spotShadowRRect, + devSpaceSpotBlur, + insetWidth); + SkASSERT(op); + this->addDrawOp(clip, std::move(op)); } return true; diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index f470a8642b..4485d6333c 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -154,13 +154,13 @@ public: * Use a fast method to render the ambient and spot shadows for a path. * Will return false if not possible for the given path. * - * @param paint describes how to color pixels. + * @param color shadow color. * @param viewMatrix transformation matrix * @param path the path to shadow * @param rec parameters for shadow rendering */ bool drawFastShadow(const GrClip&, - GrPaint&&, + GrColor color, const SkMatrix& viewMatrix, const SkPath& path, const SkDrawShadowRec& rec); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index caa960d6fa..5f2130b87c 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1643,16 +1643,8 @@ void SkGpuDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) { CHECK_SHOULD_DRAW(); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawShadow", fContext.get()); - SkPaint p; - p.setColor(rec.fColor); - GrPaint grPaint; - if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), p, this->ctm(), - &grPaint)) { - return; - } - - if (!fRenderTargetContext->drawFastShadow(this->clip(), std::move(grPaint), - this->ctm(), path, rec)) { + GrColor color = SkColorToPremulGrColor(rec.fColor); + if (!fRenderTargetContext->drawFastShadow(this->clip(), color, this->ctm(), path, rec)) { // failed to find an accelerated case this->INHERITED::drawShadow(path, rec); } diff --git a/src/gpu/effects/GrShadowGeoProc.cpp b/src/gpu/effects/GrShadowGeoProc.cpp index 5ff7ec1caf..6ab993a857 100644 --- a/src/gpu/effects/GrShadowGeoProc.cpp +++ b/src/gpu/effects/GrShadowGeoProc.cpp @@ -41,7 +41,6 @@ public: uniformHandler, gpArgs->fPositionVar, rsgp.inPosition()->fName, - rsgp.localMatrix(), args.fFPCoordTransformHandler); fragBuilder->codeAppend("float d = length(shadowParams.xy);"); @@ -55,17 +54,7 @@ public: void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& proc, FPCoordTransformIter&& transformIter) override { - this->setTransformDataHelper(proc.cast<GrRRectShadowGeoProc>().localMatrix(), - pdman, &transformIter); - } - - static inline void GenKey(const GrGeometryProcessor& gp, - const GrShaderCaps&, - GrProcessorKeyBuilder* b) { - const GrRRectShadowGeoProc& rsgp = gp.cast<GrRRectShadowGeoProc>(); - uint16_t key; - key = rsgp.localMatrix().hasPerspective() ? 0x1 : 0x0; - b->add32(key); + this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); } private: @@ -74,9 +63,7 @@ private: /////////////////////////////////////////////////////////////////////////////// -GrRRectShadowGeoProc::GrRRectShadowGeoProc(const SkMatrix& localMatrix) - : fLocalMatrix(localMatrix) { - +GrRRectShadowGeoProc::GrRRectShadowGeoProc() { this->initClassID<GrRRectShadowGeoProc>(); fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType, kHigh_GrSLPrecision); @@ -84,11 +71,6 @@ GrRRectShadowGeoProc::GrRRectShadowGeoProc(const SkMatrix& localMatrix) fInShadowParams = &this->addVertexAttrib("inShadowParams", kVec4f_GrVertexAttribType); } -void GrRRectShadowGeoProc::getGLSLProcessorKey(const GrShaderCaps& caps, - GrProcessorKeyBuilder* b) const { - GrGLSLRRectShadowGeoProc::GenKey(*this, caps, b); -} - GrGLSLPrimitiveProcessor* GrRRectShadowGeoProc::createGLSLInstance(const GrShaderCaps&) const { return new GrGLSLRRectShadowGeoProc(); } @@ -99,6 +81,6 @@ GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrRRectShadowGeoProc); #if GR_TEST_UTILS sk_sp<GrGeometryProcessor> GrRRectShadowGeoProc::TestCreate(GrProcessorTestData* d) { - return GrRRectShadowGeoProc::Make(GrTest::TestMatrix(d->fRandom)); + return GrRRectShadowGeoProc::Make(); } #endif diff --git a/src/gpu/effects/GrShadowGeoProc.h b/src/gpu/effects/GrShadowGeoProc.h index d9a1eaf981..0b4baf49b8 100644 --- a/src/gpu/effects/GrShadowGeoProc.h +++ b/src/gpu/effects/GrShadowGeoProc.h @@ -19,29 +19,25 @@ class GrGLRRectShadowGeoProc; */ class GrRRectShadowGeoProc : public GrGeometryProcessor { public: - static sk_sp<GrGeometryProcessor> Make(const SkMatrix& localMatrix) { - return sk_sp<GrGeometryProcessor>(new GrRRectShadowGeoProc(localMatrix)); + static sk_sp<GrGeometryProcessor> Make() { + return sk_sp<GrGeometryProcessor>(new GrRRectShadowGeoProc()); } - ~GrRRectShadowGeoProc() override {} - const char* name() const override { return "RRectShadow"; } const Attribute* inPosition() const { return fInPosition; } const Attribute* inColor() const { return fInColor; } const Attribute* inShadowParams() const { return fInShadowParams; } GrColor color() const { return fColor; } - const SkMatrix& localMatrix() const { return fLocalMatrix; } - void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; + void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {} GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override; private: - GrRRectShadowGeoProc(const SkMatrix& localMatrix); + GrRRectShadowGeoProc(); GrColor fColor; - SkMatrix fLocalMatrix; const Attribute* fInPosition; const Attribute* fInColor; const Attribute* fInShadowParams; diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp index a8e459a484..07281f2389 100644 --- a/src/gpu/ops/GrShadowRRectOp.cpp +++ b/src/gpu/ops/GrShadowRRectOp.cpp @@ -6,11 +6,9 @@ */ #include "GrShadowRRectOp.h" - #include "GrDrawOpTest.h" #include "GrOpFlushState.h" -#include "GrStyle.h" - +#include "SkRRect.h" #include "effects/GrShadowGeoProc.h" /////////////////////////////////////////////////////////////////////////////// @@ -182,16 +180,17 @@ static const uint16_t* rrect_type_to_indices(RRectType type) { } /////////////////////////////////////////////////////////////////////////////// +namespace { -class ShadowCircularRRectOp final : public GrLegacyMeshDrawOp { +class ShadowCircularRRectOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID // An insetWidth > 1/2 rect width or height indicates a simple fill. - ShadowCircularRRectOp(GrColor color, const SkMatrix& viewMatrix, const SkRect& devRect, + ShadowCircularRRectOp(GrColor color, const SkRect& devRect, float devRadius, bool isCircle, float blurRadius, float insetWidth, float blurClamp) - : INHERITED(ClassID()), fViewMatrixIfUsingLocalCoords(viewMatrix) { + : INHERITED(ClassID()) { SkRect bounds = devRect; SkASSERT(insetWidth > 0); SkScalar innerRadius = 0.0f; @@ -249,25 +248,17 @@ public: fGeoData[i].fOuterRadius, fGeoData[i].fUmbraInset, fGeoData[i].fInnerRadius, fGeoData[i].fBlurRadius); } - string.append(DumpPipelineInfo(*this->pipeline())); string.append(INHERITED::dumpInfo()); return string; } -private: - void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color, - GrProcessorAnalysisCoverage* coverage) const override { - color->setToConstant(fGeoData[0].fColor); - *coverage = GrProcessorAnalysisCoverage::kSingleChannel; - } + FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } - void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override { - optimizations.getOverrideColorIfSet(&fGeoData[0].fColor); - if (!optimizations.readsLocalCoords()) { - fViewMatrixIfUsingLocalCoords.reset(); - } + RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override { + return RequiresDstTexture::kNo; } +private: struct Geometry { GrColor fColor; SkScalar fOuterRadius; @@ -568,14 +559,8 @@ private: } void onPrepareDraws(Target* target) const override { - // Invert the view matrix as a local matrix (if any other processors require coords). - SkMatrix localMatrix; - if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { - return; - } - // Setup geometry processor - sk_sp<GrGeometryProcessor> gp(GrRRectShadowGeoProc::Make(localMatrix)); + sk_sp<GrGeometryProcessor> gp = GrRRectShadowGeoProc::Make(); int instanceCount = fGeoData.count(); size_t vertexStride = gp->getVertexStride(); @@ -627,23 +612,18 @@ private: } } + static const uint32_t kPipelineFlags = 0; + const GrPipeline* pipeline = + target->makePipeline(kPipelineFlags, &GrProcessorSet::EmptySet()); + GrMesh mesh(GrPrimitiveType::kTriangles); mesh.setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1); mesh.setVertexData(vertexBuffer, firstVertex); - target->draw(gp.get(), this->pipeline(), mesh); + target->draw(gp.get(), pipeline, mesh); } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { ShadowCircularRRectOp* that = t->cast<ShadowCircularRRectOp>(); - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), - that->bounds(), caps)) { - return false; - } - - if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsingLocalCoords)) { - return false; - } - fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); this->joinBounds(*that); fVertCount += that->fVertCount; @@ -652,22 +632,23 @@ private: } SkSTArray<1, Geometry, true> fGeoData; - SkMatrix fViewMatrixIfUsingLocalCoords; int fVertCount; int fIndexCount; - typedef GrLegacyMeshDrawOp INHERITED; + typedef GrMeshDrawOp INHERITED; }; +} // anonymous namespace + /////////////////////////////////////////////////////////////////////////////// namespace GrShadowRRectOp { -std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, - const SkMatrix& viewMatrix, - const SkRRect& rrect, - SkScalar blurWidth, - SkScalar insetWidth, - SkScalar blurClamp) { +std::unique_ptr<GrDrawOp> Make(GrColor color, + const SkMatrix& viewMatrix, + const SkRRect& rrect, + SkScalar blurWidth, + SkScalar insetWidth, + SkScalar blurClamp) { // Shadow rrect ops only handle simple circular rrects. SkASSERT(viewMatrix.isSimilarity() && (rrect.isSimpleCircular() || rrect.isRect() || rrect.isCircle())); @@ -683,12 +664,12 @@ std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, SkScalar scaledRadius = SkScalarAbs(radius*matrixFactor); SkScalar scaledInsetWidth = SkScalarAbs(insetWidth*matrixFactor); - return std::unique_ptr<GrLegacyMeshDrawOp>(new ShadowCircularRRectOp(color, viewMatrix, bounds, - scaledRadius, - rrect.isOval(), - blurWidth, - scaledInsetWidth, - blurClamp)); + return std::unique_ptr<GrDrawOp>(new ShadowCircularRRectOp(color, bounds, + scaledRadius, + rrect.isOval(), + blurWidth, + scaledInsetWidth, + blurClamp)); } } @@ -696,7 +677,7 @@ std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, #if GR_TEST_UTILS -GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(ShadowRRectOp) { +GR_DRAW_OP_TEST_DEFINE(ShadowRRectOp) { // create a similarity matrix SkScalar rotate = random->nextSScalar1() * 360.f; SkScalar translateX = random->nextSScalar1() * 1000.f; @@ -706,17 +687,22 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(ShadowRRectOp) { viewMatrix.setRotate(rotate); viewMatrix.postTranslate(translateX, translateY); viewMatrix.postScale(scale, scale); - GrColor color = GrRandomColor(random); SkScalar insetWidth = random->nextSScalar1() * 72.f; SkScalar blurWidth = random->nextSScalar1() * 72.f; SkScalar blurClamp = random->nextSScalar1(); bool isCircle = random->nextBool(); + // This op doesn't use a full GrPaint, just a color. + GrColor color = paint.getColor(); if (isCircle) { SkRect circle = GrTest::TestSquare(random); SkRRect rrect = SkRRect::MakeOval(circle); return GrShadowRRectOp::Make(color, viewMatrix, rrect, blurWidth, insetWidth, blurClamp); } else { - const SkRRect& rrect = GrTest::TestRRectSimple(random); + SkRRect rrect; + do { + // This may return a rrect with elliptical corners, which we don't support. + rrect = GrTest::TestRRectSimple(random); + } while (!rrect.isSimpleCircular()); return GrShadowRRectOp::Make(color, viewMatrix, rrect, blurWidth, insetWidth, blurClamp); } } diff --git a/src/gpu/ops/GrShadowRRectOp.h b/src/gpu/ops/GrShadowRRectOp.h index 126009558e..3d8e92af00 100644 --- a/src/gpu/ops/GrShadowRRectOp.h +++ b/src/gpu/ops/GrShadowRRectOp.h @@ -8,20 +8,18 @@ #ifndef GrShadowRRectOp_DEFINED #define GrShadowRRectOp_DEFINED +#include <memory> #include "GrColor.h" -#include "SkRefCnt.h" -class GrLegacyMeshDrawOp; -class GrShaderCaps; +class GrDrawOp; class SkMatrix; class SkRRect; class SkStrokeRec; namespace GrShadowRRectOp { -std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor, const SkMatrix& viewMatrix, const SkRRect& rrect, - SkScalar blurWidth, SkScalar insetWidth, - SkScalar blurClamp = 1); +std::unique_ptr<GrDrawOp> Make(GrColor, const SkMatrix& viewMatrix, const SkRRect& rrect, + SkScalar blurWidth, SkScalar insetWidth, SkScalar blurClamp = 1); } #endif |