diff options
author | Brian Salomon <bsalomon@google.com> | 2017-08-10 12:46:01 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-10 17:56:45 +0000 |
commit | b74ef035a42af8acf028abd129cb59862cb15c46 (patch) | |
tree | 97fb33acaf4a60747675a8084ab027dd61bf8f05 /src | |
parent | 92e6cc6b2d42f3826b36bd24da7dd3fe8443b114 (diff) |
Hide GrPaint copy constructor and add GrPaint::Clone and remove MoveOrNew and MoveOrCopy.
Also makes paint clones use cloned fragment processors.
Change-Id: I60efcfc6a46a4f8430a72f4d1ec79c7d99fbe593
Reviewed-on: https://skia-review.googlesource.com/33084
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrPaint.cpp | 18 | ||||
-rw-r--r-- | src/gpu/GrPaint.h | 49 | ||||
-rw-r--r-- | src/gpu/GrSoftwarePathRenderer.cpp | 14 | ||||
-rw-r--r-- | src/gpu/ops/GrDefaultPathRenderer.cpp | 13 | ||||
-rw-r--r-- | src/gpu/ops/GrMSAAPathRenderer.cpp | 11 |
5 files changed, 45 insertions, 60 deletions
diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp index d9182d2704..139a2cc89a 100644 --- a/src/gpu/GrPaint.cpp +++ b/src/gpu/GrPaint.cpp @@ -11,6 +11,24 @@ #include "effects/GrPorterDuffXferProcessor.h" #include "effects/GrSimpleTextureEffect.h" +GrPaint::GrPaint(const GrPaint& that) + : fXPFactory(that.fXPFactory) + , fColorFragmentProcessors(that.fColorFragmentProcessors.count()) + , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count()) + , fDisableOutputConversionToSRGB(that.fDisableOutputConversionToSRGB) + , fAllowSRGBInputs(that.fAllowSRGBInputs) + , fTrivial(that.fTrivial) + , fColor(that.fColor) { + for (int i = 0; i < that.fColorFragmentProcessors.count(); ++i) { + fColorFragmentProcessors.push_back(that.fColorFragmentProcessors[i]->clone()); + SkASSERT(fColorFragmentProcessors[i]); + } + for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) { + fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone()); + SkASSERT(fCoverageFragmentProcessors[i]); + } +} + void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) { this->setXPFactory(GrPorterDuffXPFactory::Get(mode)); } diff --git a/src/gpu/GrPaint.h b/src/gpu/GrPaint.h index 0d8beb4bff..1ab01f3ce4 100644 --- a/src/gpu/GrPaint.h +++ b/src/gpu/GrPaint.h @@ -41,9 +41,10 @@ class GrXPFactory; class GrPaint { public: GrPaint() = default; - explicit GrPaint(const GrPaint&) = default; ~GrPaint() = default; + static GrPaint Clone(const GrPaint& src) { return GrPaint(src); } + /** * The initial color of the drawn primitive. Defaults to solid white. */ @@ -148,24 +149,9 @@ public: bool isTrivial() const { return fTrivial; } private: - template <bool> class MoveOrImpl; - -public: - /** - * A temporary instance of this class can be used to select between moving an existing paint or - * a temporary copy of an existing paint into a call site. MoveOrClone(paint, false) is a rvalue - * reference to paint while MoveOrClone(paint, true) is a rvalue reference to a copy of paint. - */ - using MoveOrClone = MoveOrImpl<true>; - - /** - * A temporary instance of this class can be used to select between moving an existing or a - * newly default constructed paint into a call site. MoveOrNew(paint, false) is a rvalue - * reference to paint while MoveOrNew(paint, true) is a rvalue reference to a default paint. - */ - using MoveOrNew = MoveOrImpl<false>; - -private: + // Since paint copying is expensive if there are fragment processors, we require going through + // the Clone() method. + GrPaint(const GrPaint&); GrPaint& operator=(const GrPaint&) = delete; friend class GrProcessorSet; @@ -179,29 +165,4 @@ private: GrColor4f fColor = GrColor4f::OpaqueWhite(); }; -/** This is the implementation of MoveOrCopy and MoveOrNew. */ -template <bool COPY_IF_NEW> -class GrPaint::MoveOrImpl { -public: - MoveOrImpl(GrPaint& paint, bool newPaint) { - if (newPaint) { - if (COPY_IF_NEW) { - fStorage.init(paint); - } else { - fStorage.init(); - }; - fPaint = fStorage.get(); - } else { - fPaint = &paint; - } - } - - operator GrPaint&&() && { return std::move(*fPaint); } - GrPaint& paint() { return *fPaint; } - -private: - SkTLazy<GrPaint> fStorage; - GrPaint* fPaint; -}; - #endif diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index f479a483fe..8858bf90a2 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -98,20 +98,20 @@ void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTarg if (devClipBounds.fTop < devPathBounds.fTop) { rect.iset(devClipBounds.fLeft, devClipBounds.fTop, devClipBounds.fRight, devPathBounds.fTop); - DrawNonAARect(renderTargetContext, GrPaint(paint), userStencilSettings, clip, SkMatrix::I(), - rect, invert); + DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip, + SkMatrix::I(), rect, invert); } if (devClipBounds.fLeft < devPathBounds.fLeft) { rect.iset(devClipBounds.fLeft, devPathBounds.fTop, devPathBounds.fLeft, devPathBounds.fBottom); - DrawNonAARect(renderTargetContext, GrPaint(paint), userStencilSettings, clip, SkMatrix::I(), - rect, invert); + DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip, + SkMatrix::I(), rect, invert); } if (devClipBounds.fRight > devPathBounds.fRight) { rect.iset(devPathBounds.fRight, devPathBounds.fTop, devClipBounds.fRight, devPathBounds.fBottom); - DrawNonAARect(renderTargetContext, GrPaint(paint), userStencilSettings, clip, SkMatrix::I(), - rect, invert); + DrawNonAARect(renderTargetContext, GrPaint::Clone(paint), userStencilSettings, clip, + SkMatrix::I(), rect, invert); } if (devClipBounds.fBottom > devPathBounds.fBottom) { rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, @@ -222,7 +222,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { } } if (inverseFilled) { - DrawAroundInvPath(args.fRenderTargetContext, GrPaint(args.fPaint), + DrawAroundInvPath(args.fRenderTargetContext, GrPaint::Clone(args.fPaint), *args.fUserStencilSettings, *args.fClip, *args.fViewMatrix, devClipBounds, unclippedDevShapeBounds); } diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp index fb720850c0..4a436aa04b 100644 --- a/src/gpu/ops/GrDefaultPathRenderer.cpp +++ b/src/gpu/ops/GrDefaultPathRenderer.cpp @@ -593,13 +593,16 @@ bool GrDefaultPathRenderer::internalDrawPath(GrRenderTargetContext* renderTarget std::move(paint), viewM, localMatrix, bounds, aaType, passes[p])); } else { bool stencilPass = stencilOnly || passCount > 1; - GrPaint::MoveOrNew passPaint(paint, stencilPass); + std::unique_ptr<GrDrawOp> op; if (stencilPass) { - passPaint.paint().setXPFactory(GrDisableColorXPFactory::Get()); + GrPaint stencilPaint; + stencilPaint.setXPFactory(GrDisableColorXPFactory::Get()); + op = DefaultPathOp::Make(std::move(stencilPaint), path, srcSpaceTol, newCoverage, + viewMatrix, isHairline, aaType, devBounds, passes[p]); + } else { + op = DefaultPathOp::Make(std::move(paint), path, srcSpaceTol, newCoverage, + viewMatrix, isHairline, aaType, devBounds, passes[p]); } - std::unique_ptr<GrDrawOp> op = - DefaultPathOp::Make(std::move(passPaint), path, srcSpaceTol, newCoverage, - viewMatrix, isHairline, aaType, devBounds, passes[p]); renderTargetContext->addDrawOp(clip, std::move(op)); } } diff --git a/src/gpu/ops/GrMSAAPathRenderer.cpp b/src/gpu/ops/GrMSAAPathRenderer.cpp index 425e675e89..072692aa93 100644 --- a/src/gpu/ops/GrMSAAPathRenderer.cpp +++ b/src/gpu/ops/GrMSAAPathRenderer.cpp @@ -639,12 +639,15 @@ bool GrMSAAPathRenderer::internalDrawPath(GrRenderTargetContext* renderTargetCon bool firstPassIsStencil = stencilOnly || passes[1]; // If we have a cover pass then we ignore the paint in the first pass and apply it in the // second. - GrPaint::MoveOrNew firstPassPaint(paint, firstPassIsStencil); + std::unique_ptr<GrDrawOp> op; if (firstPassIsStencil) { - firstPassPaint.paint().setXPFactory(GrDisableColorXPFactory::Get()); + GrPaint stencilPaint; + stencilPaint.setXPFactory(GrDisableColorXPFactory::Get()); + op = MSAAPathOp::Make(std::move(stencilPaint), path, aaType, viewMatrix, devBounds, + passes[0]); + } else { + op = MSAAPathOp::Make(std::move(paint), path, aaType, viewMatrix, devBounds, passes[0]); } - std::unique_ptr<GrDrawOp> op = MSAAPathOp::Make(std::move(firstPassPaint), path, aaType, - viewMatrix, devBounds, passes[0]); if (!op) { return false; } |