diff options
author | 2016-12-09 15:10:07 -0500 | |
---|---|---|
committer | 2016-12-09 20:43:41 +0000 | |
commit | 0e8fc8b9e6a138cf4a66b421fb824679df717329 (patch) | |
tree | 9db412fc2ea22314336f3680249e905c4984902c /src/gpu/GrRenderTargetContext.cpp | |
parent | 385836d3d764303cc37c4d1bcc0ab890d209374e (diff) |
Relandx2 "Remove antialiasing control from GrPaint."
Fixes a bad merge.
This reverts commit 073285c0595d46205d1482cc19af2d7d891bfeae.
Change-Id: I5e92339d9b33d3a6dc58b9fcd2a1b3a5684e8f8a
Reviewed-on: https://skia-review.googlesource.com/5774
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrRenderTargetContext.cpp')
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 394 |
1 files changed, 190 insertions, 204 deletions
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index ebdf810c8f..5eec103fdd 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -266,7 +266,7 @@ void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor // RenderTargetProxy bounds fRenderTargetContext->drawNonAAFilledRect(GrNoClip(), paint, SkMatrix::I(), SkRect::Make(rtRect), - nullptr,nullptr, nullptr, false); + nullptr, nullptr, nullptr, GrAAType::kNone); } else { if (!fRenderTargetContext->accessRenderTarget()) { @@ -324,7 +324,7 @@ void GrRenderTargetContext::internalClear(const GrFixedClip& clip, paint.setColor4f(GrColor4f::FromGrColor(color)); paint.setXPFactory(GrPorterDuffXPFactory::Make(SkBlendMode::kSrc)); - this->drawRect(clip, paint, SkMatrix::I(), SkRect::Make(clearRect)); + this->drawRect(clip, paint, GrAA::kNo, SkMatrix::I(), SkRect::Make(clearRect)); } else if (isFull) { if (this->accessRenderTarget()) { this->getOpList()->fullClear(this->accessRenderTarget(), color); @@ -342,7 +342,7 @@ void GrRenderTargetContext::internalClear(const GrFixedClip& clip, } void GrRenderTargetContext::drawPaint(const GrClip& clip, - const GrPaint& origPaint, + const GrPaint& paint, const SkMatrix& viewMatrix) { ASSERT_SINGLE_OWNER RETURN_IF_ABANDONED @@ -353,26 +353,19 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip, // don't overflow fixed-point implementations SkRect r = fRenderTargetProxy->getBoundsRect(); - SkTCopyOnFirstWrite<GrPaint> paint(origPaint); SkRRect rrect; - bool aaRRect; + GrAA aa; // Check if we can replace a clipRRect()/drawPaint() with a drawRRect(). We only do the // transformation for non-rect rrects. Rects caused a performance regression on an Android // test that needs investigation. We also skip cases where there are fragment processors // because they may depend on having correct local coords and this path draws in device space // without a local matrix. - if (!paint->numTotalFragmentProcessors() && - clip.isRRect(r, &rrect, &aaRRect) && !rrect.isRect()) { - paint.writable()->setAntiAlias(aaRRect); - this->drawRRect(GrNoClip(), *paint, SkMatrix::I(), rrect, GrStyle::SimpleFill()); + if (!paint.numTotalFragmentProcessors() && clip.isRRect(r, &rrect, &aa) && !rrect.isRect()) { + this->drawRRect(GrNoClip(), paint, aa, SkMatrix::I(), rrect, GrStyle::SimpleFill()); return; } - // by definition this fills the entire clip, no need for AA - if (paint->isAntiAlias()) { - paint.writable()->setAntiAlias(false); - } bool isPerspective = viewMatrix.hasPerspective(); @@ -384,7 +377,7 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip, SkDebugf("Could not invert matrix\n"); return; } - this->drawRect(clip, *paint, viewMatrix, r); + this->drawRect(clip, paint, GrAA::kNo, viewMatrix, r); } else { SkMatrix localMatrix; if (!viewMatrix.invert(&localMatrix)) { @@ -394,8 +387,8 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - this->drawNonAAFilledRect(clip, *paint, SkMatrix::I(), r, nullptr, &localMatrix, nullptr, - false /* useHWAA */); + this->drawNonAAFilledRect(clip, paint, SkMatrix::I(), r, nullptr, &localMatrix, + nullptr, GrAAType::kNone); } } @@ -408,21 +401,6 @@ static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { return viewMatrix.preservesRightAngles(); } -static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTargetProxy* rtp, - bool* useHWAA = nullptr) { - if (!paint.isAntiAlias()) { - if (useHWAA) { - *useHWAA = false; - } - return false; - } else { - if (useHWAA) { - *useHWAA = rtp->isUnifiedMultisampled(); - } - return !rtp->isUnifiedMultisampled(); - } -} - // Attempts to crop a rect and optional local rect to the clip boundaries. // Returns false if the draw can be skipped entirely. static bool crop_filled_rect(int width, int height, const GrClip& clip, @@ -470,6 +448,7 @@ static bool crop_filled_rect(int width, int height, const GrClip& clip, bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRect& rect, const GrUserStencilSettings* ss) { @@ -479,14 +458,14 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, } sk_sp<GrDrawOp> op; - bool useHWAA; + GrAAType aaType; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); - op.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), paint.isAntiAlias(), - fInstancedPipelineInfo, &useHWAA)); + op.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), aa, + fInstancedPipelineInfo, &aaType)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); if (ss) { pipelineBuilder.setUserStencil(ss); } @@ -494,8 +473,8 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, return true; } } - - if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { + aaType = this->decideAAType(aa); + if (GrAAType::kCoverage == aaType) { // The fill path can handle rotation but not skew. if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { SkRect devBoundRect; @@ -504,7 +483,7 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, op.reset(GrRectBatchFactory::CreateAAFill(paint, viewMatrix, rect, croppedRect, devBoundRect)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); if (ss) { pipelineBuilder.setUserStencil(ss); } @@ -514,7 +493,7 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, } } else { this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, nullptr, ss, - useHWAA); + aaType); return true; } @@ -523,6 +502,7 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, void GrRenderTargetContext::drawRect(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRect& rect, const GrStyle* style) { @@ -569,7 +549,7 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, } } - if (this->drawFilledRect(clip, paint, viewMatrix, rect, nullptr)) { + if (this->drawFilledRect(clip, paint, aa, viewMatrix, rect, nullptr)) { return; } } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || @@ -580,7 +560,7 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, // TODO: Move these stroke->fill fallbacks to GrShape? switch (stroke.getJoin()) { case SkPaint::kMiter_Join: - this->drawRect(clip, paint, viewMatrix, + this->drawRect(clip, paint, aa, viewMatrix, {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, &GrStyle::SimpleFill()); @@ -589,16 +569,16 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, // Raster draws nothing when both dimensions are empty. if (rect.width() || rect.height()){ SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r); - this->drawRRect(clip, paint, viewMatrix, rrect, GrStyle::SimpleFill()); + this->drawRRect(clip, paint, aa, viewMatrix, rrect, GrStyle::SimpleFill()); return; } case SkPaint::kBevel_Join: if (!rect.width()) { - this->drawRect(clip, paint, viewMatrix, + this->drawRect(clip, paint, aa, viewMatrix, {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, &GrStyle::SimpleFill()); } else { - this->drawRect(clip, paint, viewMatrix, + this->drawRect(clip, paint, aa, viewMatrix, {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, &GrStyle::SimpleFill()); } @@ -606,12 +586,12 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, } } - bool useHWAA; bool snapToPixelCenters = false; sk_sp<GrDrawOp> op; GrColor color = paint.getColor(); - if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { + GrAAType aaType = this->decideAAType(aa); + if (GrAAType::kCoverage == aaType) { // The stroke path needs the rect to remain axis aligned (no rotation or skew). if (viewMatrix.rectStaysRect()) { op.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect, stroke)); @@ -627,7 +607,7 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, } if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); if (snapToPixelCenters) { pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, @@ -642,7 +622,7 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addRect(rect); - this->internalDrawPath(clip, paint, viewMatrix, path, *style); + this->internalDrawPath(clip, paint, aa, viewMatrix, path, *style); } int GrRenderTargetContextPriv::maxWindowRectangles() const { @@ -666,16 +646,17 @@ void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool i } void GrRenderTargetContextPriv::stencilPath(const GrClip& clip, - bool useHWAA, + GrAAType aaType, const SkMatrix& viewMatrix, const GrPath* path) { - fRenderTargetContext->getOpList()->stencilPath(fRenderTargetContext, clip, useHWAA, viewMatrix, + SkASSERT(aaType != GrAAType::kCoverage); + fRenderTargetContext->getOpList()->stencilPath(fRenderTargetContext, clip, aaType, viewMatrix, path); } void GrRenderTargetContextPriv::stencilRect(const GrClip& clip, const GrUserStencilSettings* ss, - bool useHWAA, + GrAAType aaType, const SkMatrix& viewMatrix, const SkRect& rect) { ASSERT_SINGLE_OWNER_PRIV @@ -683,22 +664,21 @@ void GrRenderTargetContextPriv::stencilRect(const GrClip& clip, SkDEBUGCODE(fRenderTargetContext->validate();) GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, "GrRenderTargetContext::stencilRect"); - + SkASSERT(GrAAType::kCoverage != aaType); AutoCheckFlush acf(fRenderTargetContext->fDrawingManager); GrPaint paint; - paint.setAntiAlias(useHWAA); paint.setXPFactory(GrDisableColorXPFactory::Make()); fRenderTargetContext->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nullptr, ss, - useHWAA); + aaType); } bool GrRenderTargetContextPriv::drawAndStencilRect(const GrClip& clip, const GrUserStencilSettings* ss, SkRegion::Op op, bool invert, - bool doAA, + GrAA aa, const SkMatrix& viewMatrix, const SkRect& rect) { ASSERT_SINGLE_OWNER_PRIV @@ -710,21 +690,20 @@ bool GrRenderTargetContextPriv::drawAndStencilRect(const GrClip& clip, AutoCheckFlush acf(fRenderTargetContext->fDrawingManager); GrPaint paint; - paint.setAntiAlias(doAA); paint.setCoverageSetOpXPFactory(op, invert); - if (fRenderTargetContext->drawFilledRect(clip, paint, viewMatrix, rect, ss)) { + if (fRenderTargetContext->drawFilledRect(clip, paint, aa, viewMatrix, rect, ss)) { return true; } - SkPath path; path.setIsVolatile(true); path.addRect(rect); - return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path); + return this->drawAndStencilPath(clip, ss, op, invert, aa, viewMatrix, path); } void GrRenderTargetContext::fillRectToRect(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRect& rectToDraw, const SkRect& localRect) { @@ -741,30 +720,30 @@ void GrRenderTargetContext::fillRectToRect(const GrClip& clip, } AutoCheckFlush acf(fDrawingManager); - bool useHWAA; + GrAAType aaType; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); sk_sp<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), - croppedLocalRect, paint.isAntiAlias(), - fInstancedPipelineInfo, &useHWAA)); + croppedLocalRect, aa, fInstancedPipelineInfo, &aaType)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } } - if (!should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { - this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, &croppedLocalRect, - nullptr, nullptr, useHWAA); + aaType = this->decideAAType(aa); + if (GrAAType::kCoverage != aaType) { + this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, &croppedLocalRect, nullptr, + nullptr, aaType); return; } if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { sk_sp<GrDrawOp> op(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, croppedRect, croppedLocalRect)); - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->addDrawOp(pipelineBuilder, clip, op.get()); return; } @@ -779,11 +758,12 @@ void GrRenderTargetContext::fillRectToRect(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addRect(localRect); - this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); + this->internalDrawPath(clip, paint, aa, viewAndUnLocalMatrix, path, GrStyle()); } void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRect& rectToDraw, const SkMatrix& localMatrix) { @@ -798,29 +778,30 @@ void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, } AutoCheckFlush acf(fDrawingManager); - bool useHWAA; + GrAAType aaType; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); sk_sp<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), localMatrix, - paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); + aa, fInstancedPipelineInfo, &aaType)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } } - if (!should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { - this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, - &localMatrix, nullptr, useHWAA); + aaType = this->decideAAType(aa); + if (GrAAType::kCoverage != aaType) { + this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, &localMatrix, + nullptr, aaType); return; } if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { sk_sp<GrDrawOp> op(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix, croppedRect)); - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -836,7 +817,7 @@ void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, path.setIsVolatile(true); path.addRect(rectToDraw); path.transform(localMatrix); - this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); + this->internalDrawPath(clip, paint, aa, viewAndUnLocalMatrix, path, GrStyle()); } void GrRenderTargetContext::drawVertices(const GrClip& clip, @@ -869,7 +850,7 @@ void GrRenderTargetContext::drawVertices(const GrClip& clip, positions, vertexCount, indices, indexCount, colors, texCoords, bounds)); - GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); + GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } @@ -892,7 +873,7 @@ void GrRenderTargetContext::drawAtlas(const GrClip& clip, sk_sp<GrDrawOp> op(new GrDrawAtlasBatch(paint.getColor(), viewMatrix, spriteCount, xform, texRect, colors)); - GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); + GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } @@ -900,6 +881,7 @@ void GrRenderTargetContext::drawAtlas(const GrClip& clip, void GrRenderTargetContext::drawRRect(const GrClip& origClip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRRect& rrect, const GrStyle& style) { @@ -928,21 +910,22 @@ void GrRenderTargetContext::drawRRect(const GrClip& origClip, AutoCheckFlush acf(fDrawingManager); const SkStrokeRec stroke = style.strokeRec(); - bool useHWAA; + GrAAType aaType; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && stroke.isFillStyle()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); - sk_sp<GrDrawOp> op(ir->recordRRect(rrect, viewMatrix, paint.getColor(), paint.isAntiAlias(), - fInstancedPipelineInfo, &useHWAA)); + sk_sp<GrDrawOp> op(ir->recordRRect(rrect, viewMatrix, paint.getColor(), aa, + fInstancedPipelineInfo, &aaType)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, *clip, op.get()); return; } } - if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { + aaType = this->decideAAType(aa); + if (GrAAType::kCoverage == aaType) { const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); sk_sp<GrDrawOp> op(GrOvalRenderer::CreateRRectBatch(paint.getColor(), paint.usesDistanceVectorField(), @@ -951,7 +934,7 @@ void GrRenderTargetContext::drawRRect(const GrClip& origClip, stroke, shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, *clip, op.get()); return; } @@ -960,7 +943,7 @@ void GrRenderTargetContext::drawRRect(const GrClip& origClip, SkPath path; path.setIsVolatile(true); path.addRRect(rrect); - this->internalDrawPath(*clip, paint, viewMatrix, path, style); + this->internalDrawPath(*clip, paint, aa, viewMatrix, path, style); } /////////////////////////////////////////////////////////////////////////////// @@ -983,72 +966,55 @@ void GrRenderTargetContext::drawShadowRRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); const SkStrokeRec stroke = style.strokeRec(); - bool useHWAA; - - // TODO: add instancing support - //if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && - // stroke.isFillStyle()) { - // InstancedRendering* ir = this->getOpList()->instancedRendering(); - // SkAutoTUnref<GrDrawOp> op(ir->recordRRect(rrect, viewMatrix, paint.getColor(), - // paint.isAntiAlias(), fInstancedPipelineInfo, - // &useHWAA)); - // if (op) { - // GrPipelineBuilder pipelineBuilder(paint, useHWAA); - // this->getOpList()->addDrawOp(pipelineBuilder, this, *clip, op); - // return; - // } - //} - - if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { - const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); - sk_sp<GrDrawOp> op(CreateShadowRRectBatch(paint.getColor(), - viewMatrix, - rrect, - blurRadius, - stroke, - shaderCaps)); - if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); - this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); - return; - } + // TODO: add instancing support? + + const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); + sk_sp<GrDrawOp> op(CreateShadowRRectBatch(paint.getColor(), + viewMatrix, + rrect, + blurRadius, + stroke, + shaderCaps)); + if (op) { + GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); + this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); + return; } - - SkPath path; - path.setIsVolatile(true); - path.addRRect(rrect); - this->internalDrawPath(clip, paint, viewMatrix, path, style); } /////////////////////////////////////////////////////////////////////////////// bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, const GrPaint& paintIn, + GrAA aa, const SkMatrix& viewMatrix, const SkRRect& origOuter, const SkRRect& origInner) { SkASSERT(!origInner.isEmpty()); SkASSERT(!origOuter.isEmpty()); + GrAAType aaType; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { - bool useHWAA; InstancedRendering* ir = this->getOpList()->instancedRendering(); sk_sp<GrDrawOp> op(ir->recordDRRect(origOuter, origInner, viewMatrix, paintIn.getColor(), - paintIn.isAntiAlias(), fInstancedPipelineInfo, - &useHWAA)); + aa, fInstancedPipelineInfo, &aaType)); if (op) { - GrPipelineBuilder pipelineBuilder(paintIn, useHWAA); + GrPipelineBuilder pipelineBuilder(paintIn, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return true; } } - bool applyAA = paintIn.isAntiAlias() && !fRenderTargetProxy->isUnifiedMultisampled(); + aaType = this->decideAAType(aa); - GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdgeType : - kInverseFillBW_GrProcessorEdgeType; - GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : - kFillBW_GrProcessorEdgeType; + GrPrimitiveEdgeType innerEdgeType, outerEdgeType; + if (GrAAType::kCoverage == aaType) { + innerEdgeType = kInverseFillAA_GrProcessorEdgeType; + outerEdgeType = kFillAA_GrProcessorEdgeType; + } else { + innerEdgeType = kInverseFillBW_GrProcessorEdgeType; + outerEdgeType = kFillBW_GrProcessorEdgeType; + } SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); SkMatrix inverseVM; @@ -1067,7 +1033,6 @@ bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, } GrPaint grPaint(paintIn); - grPaint.setAntiAlias(false); // TODO these need to be a geometry processors sk_sp<GrFragmentProcessor> innerEffect(GrRRectEffect::Make(innerEdgeType, *inner)); @@ -1084,16 +1049,17 @@ bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, grPaint.addCoverageFragmentProcessor(std::move(outerEffect)); SkRect bounds = outer->getBounds(); - if (applyAA) { + if (GrAAType::kCoverage == aaType) { bounds.outset(SK_ScalarHalf, SK_ScalarHalf); } - this->fillRectWithLocalMatrix(clip, grPaint, SkMatrix::I(), bounds, inverseVM); + this->fillRectWithLocalMatrix(clip, grPaint, GrAA::kNo, SkMatrix::I(), bounds, inverseVM); return true; } void GrRenderTargetContext::drawDRRect(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRRect& outer, const SkRRect& inner) { @@ -1107,7 +1073,7 @@ void GrRenderTargetContext::drawDRRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - if (this->drawFilledDRRect(clip, paint, viewMatrix, outer, inner)) { + if (this->drawFilledDRRect(clip, paint, aa, viewMatrix, outer, inner)) { return; } @@ -1117,7 +1083,7 @@ void GrRenderTargetContext::drawDRRect(const GrClip& clip, path.addRRect(outer); path.setFillType(SkPath::kEvenOdd_FillType); - this->internalDrawPath(clip, paint, viewMatrix, path, GrStyle::SimpleFill()); + this->internalDrawPath(clip, paint, aa, viewMatrix, path, GrStyle::SimpleFill()); } /////////////////////////////////////////////////////////////////////////////// @@ -1128,6 +1094,7 @@ static inline bool is_int(float x) { void GrRenderTargetContext::drawRegion(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRegion& region, const GrStyle& style) { @@ -1136,28 +1103,30 @@ void GrRenderTargetContext::drawRegion(const GrClip& clip, SkDEBUGCODE(this->validate();) GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRegion"); - bool needsAA = false; - if (paint.isAntiAlias()) { + if (GrAA::kYes == aa) { // GrRegionBatch performs no antialiasing but is much faster, so here we check the matrix // to see whether aa is really required. - needsAA = SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) || - !is_int(viewMatrix.getTranslateX()) || - !is_int(viewMatrix.getTranslateY()); + if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && + is_int(viewMatrix.getTranslateX()) && + is_int(viewMatrix.getTranslateY())) { + aa = GrAA::kNo; + } } bool complexStyle = !style.isSimpleFill(); - if (complexStyle || needsAA) { + if (complexStyle || GrAA::kYes == aa) { SkPath path; region.getBoundaryPath(&path); - return this->drawPath(clip, paint, viewMatrix, path, style); + return this->drawPath(clip, paint, aa, viewMatrix, path, style); } sk_sp<GrDrawOp> op(GrRegionBatch::Create(paint.getColor(), viewMatrix, region)); - GrPipelineBuilder pipelineBuilder(paint, false); + GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } void GrRenderTargetContext::drawOval(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRect& oval, const GrStyle& style) { @@ -1174,21 +1143,22 @@ void GrRenderTargetContext::drawOval(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); const SkStrokeRec& stroke = style.strokeRec(); - bool useHWAA; + GrAAType aaType; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && stroke.isFillStyle()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); - sk_sp<GrDrawOp> op(ir->recordOval(oval, viewMatrix, paint.getColor(), paint.isAntiAlias(), - fInstancedPipelineInfo, &useHWAA)); + sk_sp<GrDrawOp> op(ir->recordOval(oval, viewMatrix, paint.getColor(), aa, + fInstancedPipelineInfo, &aaType)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } } - if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { + aaType = this->decideAAType(aa); + if (GrAAType::kCoverage == aaType) { const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); sk_sp<GrDrawOp> op(GrOvalRenderer::CreateOvalBatch(paint.getColor(), viewMatrix, @@ -1196,7 +1166,7 @@ void GrRenderTargetContext::drawOval(const GrClip& clip, stroke, shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -1205,19 +1175,20 @@ void GrRenderTargetContext::drawOval(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addOval(oval); - this->internalDrawPath(clip, paint, viewMatrix, path, style); + this->internalDrawPath(clip, paint, aa, viewMatrix, path, style); } void GrRenderTargetContext::drawArc(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const GrStyle& style) { - bool useHWAA; - if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { + GrAAType aaType = this->decideAAType(aa); + if (GrAAType::kCoverage == aaType) { const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); sk_sp<GrDrawOp> op(GrOvalRenderer::CreateArcBatch(paint.getColor(), viewMatrix, @@ -1228,7 +1199,7 @@ void GrRenderTargetContext::drawArc(const GrClip& clip, style, shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -1236,8 +1207,7 @@ void GrRenderTargetContext::drawArc(const GrClip& clip, SkPath path; SkPathPriv::CreateDrawArcPath(&path, oval, startAngle, sweepAngle, useCenter, style.isSimpleFill()); - this->internalDrawPath(clip, paint, viewMatrix, path, style); - return; + this->internalDrawPath(clip, paint, aa, viewMatrix, path, style); } void GrRenderTargetContext::drawImageLattice(const GrClip& clip, @@ -1257,7 +1227,7 @@ void GrRenderTargetContext::drawImageLattice(const GrClip& clip, sk_sp<GrDrawOp> op(GrNinePatch::CreateNonAA(paint.getColor(), viewMatrix, imageWidth, imageHeight, std::move(iter), dst)); - GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); + GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } @@ -1286,11 +1256,12 @@ void GrRenderTargetContext::drawNonAAFilledRect(const GrClip& clip, const SkRect* localRect, const SkMatrix* localMatrix, const GrUserStencilSettings* ss, - bool useHWAA) { - SkASSERT(!useHWAA || this->isStencilBufferMultisampled()); + GrAAType hwOrNoneAAType) { + SkASSERT(GrAAType::kCoverage != hwOrNoneAAType); + SkASSERT(hwOrNoneAAType == GrAAType::kNone || this->isStencilBufferMultisampled()); sk_sp<GrDrawOp> op( GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, localRect, localMatrix)); - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, hwOrNoneAAType); if (ss) { pipelineBuilder.setUserStencil(ss); } @@ -1392,6 +1363,7 @@ static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path void GrRenderTargetContext::drawPath(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkPath& path, const GrStyle& style) { @@ -1409,9 +1381,8 @@ void GrRenderTargetContext::drawPath(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - bool useHWAA; - if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA) && - !style.pathEffect()) { + GrAAType aaType = this->decideAAType(aa); + if (GrAAType::kCoverage == aaType && !style.pathEffect()) { if (style.isSimpleFill() && !path.isConvex()) { // Concave AA paths are expensive - try to avoid them for special cases SkRect rects[2]; @@ -1419,8 +1390,8 @@ void GrRenderTargetContext::drawPath(const GrClip& clip, if (fills_as_nested_rects(viewMatrix, path, rects)) { sk_sp<GrDrawOp> op(GrRectBatchFactory::CreateAAFillNestedRects( paint.getColor(), viewMatrix, rects)); - if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + if (op) { + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } return; @@ -1437,7 +1408,7 @@ void GrRenderTargetContext::drawPath(const GrClip& clip, style.strokeRec(), shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); + GrPipelineBuilder pipelineBuilder(paint, aaType); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -1449,23 +1420,24 @@ void GrRenderTargetContext::drawPath(const GrClip& clip, // cache. This presents a potential hazard for buffered drawing. However, // the writePixels that uploads to the scratch will perform a flush so we're // OK. - this->internalDrawPath(clip, paint, viewMatrix, path, style); + this->internalDrawPath(clip, paint, aa, viewMatrix, path, style); } bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, const GrUserStencilSettings* ss, SkRegion::Op op, bool invert, - bool doAA, + GrAA aa, const SkMatrix& viewMatrix, const SkPath& path) { ASSERT_SINGLE_OWNER_PRIV RETURN_FALSE_IF_ABANDONED_PRIV SkDEBUGCODE(fRenderTargetContext->validate();) - GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, "GrRenderTargetContext::drawPath"); + GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, + "GrRenderTargetContextPriv::drawAndStencilPath"); if (path.isEmpty() && path.isInverseFillType()) { - this->drawAndStencilRect(clip, ss, op, invert, false, SkMatrix::I(), + this->drawAndStencilRect(clip, ss, op, invert, GrAA::kNo, SkMatrix::I(), SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height())); return true; @@ -1477,13 +1449,12 @@ bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, // the src color (either the input alpha or in the frag shader) to implement // aa. If we have some future driver-mojo path AA that can do the right // thing WRT to the blend then we'll need some query on the PR. - bool useCoverageAA = doAA && !fRenderTargetContext->isUnifiedMultisampled(); + GrAAType aaType = fRenderTargetContext->decideAAType(aa); bool hasUserStencilSettings = !ss->isUnused(); - bool isStencilBufferMSAA = fRenderTargetContext->isStencilBufferMultisampled(); - const GrPathRendererChain::DrawType type = - useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType - : GrPathRendererChain::kColor_DrawType; + const GrPathRendererChain::DrawType type = (GrAAType::kCoverage == aaType) + ? GrPathRendererChain::kColorAntiAlias_DrawType + : GrPathRendererChain::kColor_DrawType; GrShape shape(path, GrStyle::SimpleFill()); GrPathRenderer::CanDrawPathArgs canDrawArgs; @@ -1491,9 +1462,8 @@ bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, fRenderTargetContext->fDrawingManager->getContext()->caps()->shaderCaps(); canDrawArgs.fViewMatrix = &viewMatrix; canDrawArgs.fShape = &shape; - canDrawArgs.fAntiAlias = useCoverageAA; + canDrawArgs.fAAType = aaType; canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; - canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; // Don't allow the SW renderer GrPathRenderer* pr = fRenderTargetContext->fDrawingManager->getPathRenderer(canDrawArgs, false, @@ -1514,7 +1484,7 @@ bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, args.fClip = &clip; args.fViewMatrix = &viewMatrix; args.fShape = &shape; - args.fAntiAlias = useCoverageAA; + args.fAAType = aaType; args.fGammaCorrect = fRenderTargetContext->isGammaCorrect(); pr->drawPath(args); return true; @@ -1534,55 +1504,71 @@ SkBudgeted GrRenderTargetContextPriv::isBudgeted() const { void GrRenderTargetContext::internalDrawPath(const GrClip& clip, const GrPaint& paint, + GrAA aa, const SkMatrix& viewMatrix, const SkPath& path, const GrStyle& style) { ASSERT_SINGLE_OWNER RETURN_IF_ABANDONED SkASSERT(!path.isEmpty()); + GrShape shape; - bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTargetProxy.get()); - constexpr bool kHasUserStencilSettings = false; - bool isStencilBufferMSAA = this->isStencilBufferMultisampled(); - - const GrPathRendererChain::DrawType type = - useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType - : GrPathRendererChain::kColor_DrawType; - - GrShape shape(path, style); - if (shape.isEmpty()) { - return; + GrAAType aaType = this->decideAAType(aa, /*allowMixedSamples*/ true); + if (style.isSimpleHairline() && aaType == GrAAType::kMixedSamples) { + // NVPR cannot handle hairlines, so this will would get picked up by a different stencil and + // cover path renderer (i.e. default path renderer). The hairline renderer produces much + // smoother hairlines than MSAA. + aaType = GrAAType::kCoverage; } GrPathRenderer::CanDrawPathArgs canDrawArgs; canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps(); canDrawArgs.fViewMatrix = &viewMatrix; canDrawArgs.fShape = &shape; - canDrawArgs.fAntiAlias = useCoverageAA; - canDrawArgs.fHasUserStencilSettings = kHasUserStencilSettings; - canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; + canDrawArgs.fHasUserStencilSettings = false; - // Try a 1st time without applying any of the style to the geometry (and barring sw) - GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); - SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); + GrPathRenderer* pr; + do { + const GrPathRendererChain::DrawType type = GrAAType::kCoverage == aaType + ? GrPathRendererChain::kColorAntiAlias_DrawType + : GrPathRendererChain::kColor_DrawType; - if (!pr && shape.style().pathEffect()) { - // It didn't work above, so try again with the path effect applied. - shape = shape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); + shape = GrShape(path, style); if (shape.isEmpty()) { return; } + + canDrawArgs.fAAType = aaType; + + // Try a 1st time without applying any of the style to the geometry (and barring sw) pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); - } - if (!pr) { - if (shape.style().applies()) { - shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale); + SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); + + if (!pr && shape.style().pathEffect()) { + // It didn't work above, so try again with the path effect applied. + shape = shape.applyStyle(GrStyle::Apply::kPathEffectOnly, styleScale); if (shape.isEmpty()) { return; } + pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); } - // This time, allow SW renderer - pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); - } + if (!pr) { + if (shape.style().applies()) { + shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale); + if (shape.isEmpty()) { + return; + } + } + // This time, allow SW renderer + pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); + } + if (!pr && (aaType == GrAAType::kMixedSamples || aaType == GrAAType::kMSAA)) { + // There are exceptional cases where we may wind up falling back to coverage based AA + // when the target is MSAA (e.g. through disabling path renderers via GrContextOptions). + aaType = GrAAType::kCoverage; + } else { + break; + } + } while(true); if (!pr) { #ifdef SK_DEBUG @@ -1598,8 +1584,8 @@ void GrRenderTargetContext::internalDrawPath(const GrClip& clip, args.fRenderTargetContext = this; args.fClip = &clip; args.fViewMatrix = &viewMatrix; - args.fShape = canDrawArgs.fShape; - args.fAntiAlias = useCoverageAA; + args.fShape = &shape; + args.fAAType = aaType; args.fGammaCorrect = this->isGammaCorrect(); pr->drawPath(args); } |