diff options
author | robertphillips <robertphillips@google.com> | 2016-02-29 13:50:40 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-29 13:50:40 -0800 |
commit | 000958973f4b514cddbfdcc01ec167437b66de2c (patch) | |
tree | 040d4b6a690fa54a2f28e0babc7203515833569b /src | |
parent | eef980270d3385fee340eb1633962fe3ba8b7132 (diff) |
Move drawDRRect back to GrDrawContext
This still leaves GrDrawContext fiddling around with specialized fragment processors but it does allow for different handling of the DRRects (e.g., for instanced drawing).
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1750533003
Review URL: https://codereview.chromium.org/1750533003
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrDrawContext.cpp | 89 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 66 |
2 files changed, 94 insertions, 61 deletions
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index b5c28190f2..e5064f0454 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -23,6 +23,8 @@ #include "batches/GrRectBatchFactory.h" #include "batches/GrNinePatch.h" // TODO Factory +#include "effects/GrRRectEffect.h" + #include "text/GrAtlasTextContext.h" #include "text/GrStencilAndCoverTextContext.h" @@ -515,6 +517,93 @@ void GrDrawContext::drawRRect(const GrClip& clip, paint.isAntiAlias(), path, strokeInfo); } +bool GrDrawContext::drawFilledDRRect(const GrClip& clip, + const GrPaint& paintIn, + const SkMatrix& viewMatrix, + const SkRRect& origOuter, + const SkRRect& origInner) { + SkASSERT(!origInner.isEmpty()); + SkASSERT(!origOuter.isEmpty()); + + bool applyAA = paintIn.isAntiAlias() && !fRenderTarget->isUnifiedMultisampled(); + + GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdgeType : + kInverseFillBW_GrProcessorEdgeType; + GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : + kFillBW_GrProcessorEdgeType; + + SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); + SkMatrix inverseVM; + if (!viewMatrix.isIdentity()) { + if (!origInner.transform(viewMatrix, inner.writable())) { + return false; + } + if (!origOuter.transform(viewMatrix, outer.writable())) { + return false; + } + if (!viewMatrix.invert(&inverseVM)) { + return false; + } + } else { + inverseVM.reset(); + } + + GrPaint grPaint(paintIn); + grPaint.setAntiAlias(false); + + // TODO these need to be a geometry processors + SkAutoTUnref<GrFragmentProcessor> innerEffect(GrRRectEffect::Create(innerEdgeType, *inner)); + if (!innerEffect) { + return false; + } + + SkAutoTUnref<GrFragmentProcessor> outerEffect(GrRRectEffect::Create(outerEdgeType, *outer)); + if (!outerEffect) { + return false; + } + + grPaint.addCoverageFragmentProcessor(innerEffect); + grPaint.addCoverageFragmentProcessor(outerEffect); + + SkRect bounds = outer->getBounds(); + if (applyAA) { + bounds.outset(SK_ScalarHalf, SK_ScalarHalf); + } + + this->fillRectWithLocalMatrix(clip, grPaint, SkMatrix::I(), bounds, inverseVM); + return true; +} + +void GrDrawContext::drawDRRect(const GrClip& clip, + const GrPaint& paint, + const SkMatrix& viewMatrix, + const SkRRect& outer, + const SkRRect& inner) { + ASSERT_SINGLE_OWNER + RETURN_IF_ABANDONED + SkDEBUGCODE(this->validate();) + GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawDRRect"); + + SkASSERT(!outer.isEmpty()); + SkASSERT(!inner.isEmpty()); + + AutoCheckFlush acf(fDrawingManager); + + if (this->drawFilledDRRect(clip, paint, viewMatrix, outer, inner)) { + return; + } + + SkPath path; + path.setIsVolatile(true); + path.addRRect(inner); + path.addRRect(outer); + path.setFillType(SkPath::kEvenOdd_FillType); + + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + this->internalDrawPath(&pipelineBuilder, viewMatrix, paint.getColor(), + paint.isAntiAlias(), path, GrStrokeInfo::FillInfo()); +} + /////////////////////////////////////////////////////////////////////////////// void GrDrawContext::drawOval(const GrClip& clip, diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index e97f275e7a..04bc14e563 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -44,7 +44,6 @@ #include "batches/GrRectBatchFactory.h" #include "effects/GrBicubicEffect.h" #include "effects/GrDashingEffect.h" -#include "effects/GrRRectEffect.h" #include "effects/GrSimpleTextureEffect.h" #include "effects/GrTextureDomain.h" #include "text/GrTextUtils.h" @@ -561,65 +560,6 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); } -bool SkGpuDevice::drawFilledDRRect(const SkMatrix& viewMatrix, const SkRRect& origOuter, - const SkRRect& origInner, const SkPaint& paint) { - SkASSERT(!origInner.isEmpty()); - SkASSERT(!origOuter.isEmpty()); - - bool applyAA = paint.isAntiAlias() && !fRenderTarget->isUnifiedMultisampled(); - - GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdgeType : - kInverseFillBW_GrProcessorEdgeType; - GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : - kFillBW_GrProcessorEdgeType; - - SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); - SkMatrix inverseVM; - if (!viewMatrix.isIdentity()) { - if (!origInner.transform(viewMatrix, inner.writable())) { - return false; - } - if (!origOuter.transform(viewMatrix, outer.writable())) { - return false; - } - if (!viewMatrix.invert(&inverseVM)) { - return false; - } - } else { - inverseVM.reset(); - } - - GrPaint grPaint; - - if (!SkPaintToGrPaint(this->context(), paint, viewMatrix, &grPaint)) { - return false; - } - - grPaint.setAntiAlias(false); - - // TODO these need to be a geometry processors - SkAutoTUnref<GrFragmentProcessor> innerEffect(GrRRectEffect::Create(innerEdgeType, *inner)); - if (!innerEffect) { - return false; - } - - SkAutoTUnref<GrFragmentProcessor> outerEffect(GrRRectEffect::Create(outerEdgeType, *outer)); - if (!outerEffect) { - return false; - } - - grPaint.addCoverageFragmentProcessor(innerEffect); - grPaint.addCoverageFragmentProcessor(outerEffect); - - SkRect bounds = outer->getBounds(); - if (applyAA) { - bounds.outset(SK_ScalarHalf, SK_ScalarHalf); - } - - fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, SkMatrix::I(), bounds, inverseVM); - return true; -} - void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { @@ -639,9 +579,13 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, SkStrokeRec stroke(paint); if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) { - if (this->drawFilledDRRect(*draw.fMatrix, outer, inner, paint)) { + GrPaint grPaint; + if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { return; } + + fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner); + return; } SkPath path; |