diff options
author | Brian Salomon <bsalomon@google.com> | 2017-12-01 16:01:47 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-01 21:25:39 +0000 |
commit | 6574921253197338f879130ed99fb9ce483976de (patch) | |
tree | 786f7d99ecdd4efeab5c2ea68e02fd24b189d5a0 /src | |
parent | 80654c16bd47ec800cacc9845c9129e203427914 (diff) |
Revert "Revert "Fix rendering of drrects with small circular inner rrects.""
This reverts commit ec727c981dd7ed83e98c7713c2828c6ab144937b.
Change-Id: Id3164619016d58b2bcc0b8af606215653f553fce
Reviewed-on: https://skia-review.googlesource.com/79422
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 23 | ||||
-rw-r--r-- | src/gpu/effects/GrCircleEffect.cpp | 5 | ||||
-rw-r--r-- | src/gpu/effects/GrCircleEffect.fp | 16 | ||||
-rw-r--r-- | src/gpu/effects/GrCircleEffect.h | 6 |
4 files changed, 47 insertions, 3 deletions
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 2310ebda94..aba2e1db29 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -1224,6 +1224,28 @@ bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, } } + SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); + + if (aa == GrAA::kYes && inner->isCircle() && outer->isCircle()) { + auto outerR = outer->width() / 2.f; + auto innerR = inner->width() / 2.f; + auto cx = outer->getBounds().fLeft + outerR; + auto cy = outer->getBounds().fTop + outerR; + if (SkScalarNearlyEqual(cx, inner->getBounds().fLeft + innerR) && + SkScalarNearlyEqual(cy, inner->getBounds().fTop + innerR)) { + auto avgR = (innerR + outerR) / 2.f; + auto circleBounds = SkRect::MakeLTRB(cx - avgR, cy - avgR, cx + avgR, cy + avgR); + SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); + stroke.setStrokeStyle(outerR - innerR); + auto op = GrOvalOpFactory::MakeOvalOp(std::move(paint), viewMatrix, circleBounds, + stroke, this->caps()->shaderCaps()); + if (op) { + this->addDrawOp(clip, std::move(op)); + return true; + } + } + } + GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); GrClipEdgeType innerEdgeType, outerEdgeType; @@ -1235,7 +1257,6 @@ bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, outerEdgeType = GrClipEdgeType::kFillBW; } - SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); SkMatrix inverseVM; if (!viewMatrix.isIdentity()) { if (!origInner.transform(viewMatrix, inner.writable())) { diff --git a/src/gpu/effects/GrCircleEffect.cpp b/src/gpu/effects/GrCircleEffect.cpp index 3bd2138e94..a5adf1cc88 100644 --- a/src/gpu/effects/GrCircleEffect.cpp +++ b/src/gpu/effects/GrCircleEffect.cpp @@ -66,6 +66,9 @@ private: SkScalar effectiveRadius = radius; if (GrProcessorEdgeTypeIsInverseFill((GrClipEdgeType)edgeType)) { effectiveRadius -= 0.5f; + // When the radius is 0.5 effectiveRadius is 0 which causes an inf * 0 in the + // shader. + effectiveRadius = SkTMax(0.001f, effectiveRadius); } else { effectiveRadius += 0.5f; } @@ -108,7 +111,7 @@ std::unique_ptr<GrFragmentProcessor> GrCircleEffect::TestCreate(GrProcessorTestD SkPoint center; center.fX = testData->fRandom->nextRangeScalar(0.f, 1000.f); center.fY = testData->fRandom->nextRangeScalar(0.f, 1000.f); - SkScalar radius = testData->fRandom->nextRangeF(0.f, 1000.f); + SkScalar radius = testData->fRandom->nextRangeF(1.f, 1000.f); GrClipEdgeType et; do { et = (GrClipEdgeType)testData->fRandom->nextULessThan(kGrClipEdgeTypeCnt); diff --git a/src/gpu/effects/GrCircleEffect.fp b/src/gpu/effects/GrCircleEffect.fp index fe959f8bc8..352e824b54 100644 --- a/src/gpu/effects/GrCircleEffect.fp +++ b/src/gpu/effects/GrCircleEffect.fp @@ -15,6 +15,18 @@ half prevRadius = -1; // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills. uniform half4 circle; +@make { + static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType, SkPoint center, + float radius) { + // A radius below half causes the implicit insetting done by this processor to become + // inverted. We could handle this case by making the processor code more complicated. + if (radius < .5f) { + return nullptr; + } + return std::unique_ptr<GrFragmentProcessor>(new GrCircleEffect(edgeType, center, radius)); + } +} + @optimizationFlags { kCompatibleWithCoverageAsAlpha_OptimizationFlag } @setData(pdman) { @@ -22,6 +34,8 @@ uniform half4 circle; SkScalar effectiveRadius = radius; if (GrProcessorEdgeTypeIsInverseFill((GrClipEdgeType) edgeType)) { effectiveRadius -= 0.5f; + // When the radius is 0.5 effectiveRadius is 0 which causes an inf * 0 in the shader. + effectiveRadius = SkTMax(0.001f, effectiveRadius); } else { effectiveRadius += 0.5f; } @@ -58,7 +72,7 @@ void main() { SkPoint center; center.fX = testData->fRandom->nextRangeScalar(0.f, 1000.f); center.fY = testData->fRandom->nextRangeScalar(0.f, 1000.f); - SkScalar radius = testData->fRandom->nextRangeF(0.f, 1000.f); + SkScalar radius = testData->fRandom->nextRangeF(1.f, 1000.f); GrClipEdgeType et; do { et = (GrClipEdgeType) testData->fRandom->nextULessThan(kGrClipEdgeTypeCnt); diff --git a/src/gpu/effects/GrCircleEffect.h b/src/gpu/effects/GrCircleEffect.h index bf6bd0e8e6..d721a78241 100644 --- a/src/gpu/effects/GrCircleEffect.h +++ b/src/gpu/effects/GrCircleEffect.h @@ -19,8 +19,14 @@ public: GrClipEdgeType edgeType() const { return fEdgeType; } SkPoint center() const { return fCenter; } float radius() const { return fRadius; } + static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType, SkPoint center, float radius) { + // A radius below half causes the implicit insetting done by this processor to become + // inverted. We could handle this case by making the processor code more complicated. + if (radius < .5f) { + return nullptr; + } return std::unique_ptr<GrFragmentProcessor>(new GrCircleEffect(edgeType, center, radius)); } GrCircleEffect(const GrCircleEffect& src); |