diff options
Diffstat (limited to 'src/gpu/GrRenderTargetContext.cpp')
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 392 |
1 files changed, 203 insertions, 189 deletions
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 6ef34d22bb..ebdf810c8f 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -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, GrAA::kNo, SkMatrix::I(), SkRect::Make(clearRect)); + this->drawRect(clip, paint, 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& paint, + const GrPaint& origPaint, const SkMatrix& viewMatrix) { ASSERT_SINGLE_OWNER RETURN_IF_ABANDONED @@ -353,19 +353,26 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip, // don't overflow fixed-point implementations SkRect r = fRenderTargetProxy->getBoundsRect(); + SkTCopyOnFirstWrite<GrPaint> paint(origPaint); SkRRect rrect; - GrAA aa; + bool aaRRect; // 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, &aa) && !rrect.isRect()) { - this->drawRRect(GrNoClip(), paint, aa, SkMatrix::I(), rrect, GrStyle::SimpleFill()); + if (!paint->numTotalFragmentProcessors() && + clip.isRRect(r, &rrect, &aaRRect) && !rrect.isRect()) { + paint.writable()->setAntiAlias(aaRRect); + this->drawRRect(GrNoClip(), *paint, 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(); @@ -377,7 +384,7 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip, SkDebugf("Could not invert matrix\n"); return; } - this->drawRect(clip, paint, GrAA::kNo, viewMatrix, r); + this->drawRect(clip, *paint, viewMatrix, r); } else { SkMatrix localMatrix; if (!viewMatrix.invert(&localMatrix)) { @@ -387,8 +394,8 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - this->drawNonAAFilledRect(clip, paint, SkMatrix::I(), r, nullptr, &localMatrix, - nullptr, GrAAType::kNone); + this->drawNonAAFilledRect(clip, *paint, SkMatrix::I(), r, nullptr, &localMatrix, nullptr, + false /* useHWAA */); } } @@ -401,6 +408,21 @@ 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, @@ -448,7 +470,6 @@ 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) { @@ -458,14 +479,14 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, } sk_sp<GrDrawOp> op; - GrAAType aaType; + bool useHWAA; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); - op.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), aa, - fInstancedPipelineInfo, &aaType)); + op.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), paint.isAntiAlias(), + fInstancedPipelineInfo, &useHWAA)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); if (ss) { pipelineBuilder.setUserStencil(ss); } @@ -473,8 +494,8 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, return true; } } - aaType = this->decideAAType(aa); - if (GrAAType::kCoverage == aaType) { + + if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { // The fill path can handle rotation but not skew. if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { SkRect devBoundRect; @@ -483,7 +504,7 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, op.reset(GrRectBatchFactory::CreateAAFill(paint, viewMatrix, rect, croppedRect, devBoundRect)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); if (ss) { pipelineBuilder.setUserStencil(ss); } @@ -493,7 +514,7 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, } } else { this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, nullptr, ss, - aaType); + useHWAA); return true; } @@ -502,7 +523,6 @@ 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) { @@ -549,7 +569,7 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, } } - if (this->drawFilledRect(clip, paint, aa, viewMatrix, rect, nullptr)) { + if (this->drawFilledRect(clip, paint, viewMatrix, rect, nullptr)) { return; } } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || @@ -560,7 +580,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, aa, viewMatrix, + this->drawRect(clip, paint, viewMatrix, {rect.fLeft - r, rect.fTop - r, rect.fRight + r, rect.fBottom + r}, &GrStyle::SimpleFill()); @@ -569,16 +589,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, aa, viewMatrix, rrect, GrStyle::SimpleFill()); + this->drawRRect(clip, paint, viewMatrix, rrect, GrStyle::SimpleFill()); return; } case SkPaint::kBevel_Join: if (!rect.width()) { - this->drawRect(clip, paint, aa, viewMatrix, + this->drawRect(clip, paint, viewMatrix, {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom}, &GrStyle::SimpleFill()); } else { - this->drawRect(clip, paint, aa, viewMatrix, + this->drawRect(clip, paint, viewMatrix, {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r}, &GrStyle::SimpleFill()); } @@ -586,12 +606,12 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, } } + bool useHWAA; bool snapToPixelCenters = false; sk_sp<GrDrawOp> op; GrColor color = paint.getColor(); - GrAAType aaType = this->decideAAType(aa); - if (GrAAType::kCoverage == aaType) { + if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { // 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)); @@ -607,7 +627,7 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, } if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); if (snapToPixelCenters) { pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, @@ -622,7 +642,7 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addRect(rect); - this->internalDrawPath(clip, paint, aa, viewMatrix, path, *style); + this->internalDrawPath(clip, paint, viewMatrix, path, *style); } int GrRenderTargetContextPriv::maxWindowRectangles() const { @@ -646,17 +666,16 @@ void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool i } void GrRenderTargetContextPriv::stencilPath(const GrClip& clip, - GrAAType aaType, + bool useHWAA, const SkMatrix& viewMatrix, const GrPath* path) { - SkASSERT(aaType != GrAAType::kCoverage); - fRenderTargetContext->getOpList()->stencilPath(fRenderTargetContext, clip, aaType, viewMatrix, + fRenderTargetContext->getOpList()->stencilPath(fRenderTargetContext, clip, useHWAA, viewMatrix, path); } void GrRenderTargetContextPriv::stencilRect(const GrClip& clip, const GrUserStencilSettings* ss, - GrAAType aaType, + bool useHWAA, const SkMatrix& viewMatrix, const SkRect& rect) { ASSERT_SINGLE_OWNER_PRIV @@ -664,21 +683,22 @@ 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, - aaType); + useHWAA); } bool GrRenderTargetContextPriv::drawAndStencilRect(const GrClip& clip, const GrUserStencilSettings* ss, SkRegion::Op op, bool invert, - GrAA aa, + bool doAA, const SkMatrix& viewMatrix, const SkRect& rect) { ASSERT_SINGLE_OWNER_PRIV @@ -690,20 +710,21 @@ bool GrRenderTargetContextPriv::drawAndStencilRect(const GrClip& clip, AutoCheckFlush acf(fRenderTargetContext->fDrawingManager); GrPaint paint; + paint.setAntiAlias(doAA); paint.setCoverageSetOpXPFactory(op, invert); - if (fRenderTargetContext->drawFilledRect(clip, paint, aa, viewMatrix, rect, ss)) { + if (fRenderTargetContext->drawFilledRect(clip, paint, viewMatrix, rect, ss)) { return true; } + SkPath path; path.setIsVolatile(true); path.addRect(rect); - return this->drawAndStencilPath(clip, ss, op, invert, aa, viewMatrix, path); + return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path); } void GrRenderTargetContext::fillRectToRect(const GrClip& clip, const GrPaint& paint, - GrAA aa, const SkMatrix& viewMatrix, const SkRect& rectToDraw, const SkRect& localRect) { @@ -720,30 +741,30 @@ void GrRenderTargetContext::fillRectToRect(const GrClip& clip, } AutoCheckFlush acf(fDrawingManager); - GrAAType aaType; + bool useHWAA; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); sk_sp<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), - croppedLocalRect, aa, fInstancedPipelineInfo, &aaType)); + croppedLocalRect, paint.isAntiAlias(), + fInstancedPipelineInfo, &useHWAA)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } } - aaType = this->decideAAType(aa); - if (GrAAType::kCoverage != aaType) { - this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, &croppedLocalRect, nullptr, - nullptr, aaType); + if (!should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { + this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, &croppedLocalRect, + nullptr, nullptr, useHWAA); return; } if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { sk_sp<GrDrawOp> op(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, croppedRect, croppedLocalRect)); - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->addDrawOp(pipelineBuilder, clip, op.get()); return; } @@ -758,12 +779,11 @@ void GrRenderTargetContext::fillRectToRect(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addRect(localRect); - this->internalDrawPath(clip, paint, aa, viewAndUnLocalMatrix, path, GrStyle()); + this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); } void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, const GrPaint& paint, - GrAA aa, const SkMatrix& viewMatrix, const SkRect& rectToDraw, const SkMatrix& localMatrix) { @@ -778,30 +798,29 @@ void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, } AutoCheckFlush acf(fDrawingManager); - GrAAType aaType; + bool useHWAA; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); sk_sp<GrDrawOp> op(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), localMatrix, - aa, fInstancedPipelineInfo, &aaType)); + paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } } - aaType = this->decideAAType(aa); - if (GrAAType::kCoverage != aaType) { - this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, &localMatrix, - nullptr, aaType); + if (!should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { + this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, + &localMatrix, nullptr, useHWAA); return; } if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { sk_sp<GrDrawOp> op(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix, croppedRect)); - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -817,7 +836,7 @@ void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, path.setIsVolatile(true); path.addRect(rectToDraw); path.transform(localMatrix); - this->internalDrawPath(clip, paint, aa, viewAndUnLocalMatrix, path, GrStyle()); + this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); } void GrRenderTargetContext::drawVertices(const GrClip& clip, @@ -850,7 +869,7 @@ void GrRenderTargetContext::drawVertices(const GrClip& clip, positions, vertexCount, indices, indexCount, colors, texCoords, bounds)); - GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); + GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } @@ -873,7 +892,7 @@ void GrRenderTargetContext::drawAtlas(const GrClip& clip, sk_sp<GrDrawOp> op(new GrDrawAtlasBatch(paint.getColor(), viewMatrix, spriteCount, xform, texRect, colors)); - GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); + GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } @@ -881,7 +900,6 @@ 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) { @@ -910,22 +928,21 @@ void GrRenderTargetContext::drawRRect(const GrClip& origClip, AutoCheckFlush acf(fDrawingManager); const SkStrokeRec stroke = style.strokeRec(); - GrAAType aaType; + bool useHWAA; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && stroke.isFillStyle()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); - sk_sp<GrDrawOp> op(ir->recordRRect(rrect, viewMatrix, paint.getColor(), aa, - fInstancedPipelineInfo, &aaType)); + sk_sp<GrDrawOp> op(ir->recordRRect(rrect, viewMatrix, paint.getColor(), paint.isAntiAlias(), + fInstancedPipelineInfo, &useHWAA)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, *clip, op.get()); return; } } - aaType = this->decideAAType(aa); - if (GrAAType::kCoverage == aaType) { + if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); sk_sp<GrDrawOp> op(GrOvalRenderer::CreateRRectBatch(paint.getColor(), paint.usesDistanceVectorField(), @@ -934,7 +951,7 @@ void GrRenderTargetContext::drawRRect(const GrClip& origClip, stroke, shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, *clip, op.get()); return; } @@ -943,7 +960,7 @@ void GrRenderTargetContext::drawRRect(const GrClip& origClip, SkPath path; path.setIsVolatile(true); path.addRRect(rrect); - this->internalDrawPath(*clip, paint, aa, viewMatrix, path, style); + this->internalDrawPath(*clip, paint, viewMatrix, path, style); } /////////////////////////////////////////////////////////////////////////////// @@ -966,55 +983,72 @@ void GrRenderTargetContext::drawShadowRRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); const SkStrokeRec stroke = style.strokeRec(); - // 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; + 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; + } } + + 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(), - aa, fInstancedPipelineInfo, &aaType)); + paintIn.isAntiAlias(), fInstancedPipelineInfo, + &useHWAA)); if (op) { - GrPipelineBuilder pipelineBuilder(paintIn, aaType); + GrPipelineBuilder pipelineBuilder(paintIn, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return true; } } - aaType = this->decideAAType(aa); + bool applyAA = paintIn.isAntiAlias() && !fRenderTargetProxy->isUnifiedMultisampled(); - GrPrimitiveEdgeType innerEdgeType, outerEdgeType; - if (GrAAType::kCoverage == aaType) { - innerEdgeType = kInverseFillAA_GrProcessorEdgeType; - outerEdgeType = kFillAA_GrProcessorEdgeType; - } else { - innerEdgeType = kInverseFillBW_GrProcessorEdgeType; - outerEdgeType = kFillBW_GrProcessorEdgeType; - } + GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdgeType : + kInverseFillBW_GrProcessorEdgeType; + GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : + kFillBW_GrProcessorEdgeType; SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); SkMatrix inverseVM; @@ -1033,6 +1067,7 @@ 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)); @@ -1049,17 +1084,16 @@ bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip, grPaint.addCoverageFragmentProcessor(std::move(outerEffect)); SkRect bounds = outer->getBounds(); - if (GrAAType::kCoverage == aaType) { + if (applyAA) { bounds.outset(SK_ScalarHalf, SK_ScalarHalf); } - this->fillRectWithLocalMatrix(clip, grPaint, GrAA::kNo, SkMatrix::I(), bounds, inverseVM); + this->fillRectWithLocalMatrix(clip, grPaint, 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) { @@ -1073,7 +1107,7 @@ void GrRenderTargetContext::drawDRRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - if (this->drawFilledDRRect(clip, paint, aa, viewMatrix, outer, inner)) { + if (this->drawFilledDRRect(clip, paint, viewMatrix, outer, inner)) { return; } @@ -1083,7 +1117,7 @@ void GrRenderTargetContext::drawDRRect(const GrClip& clip, path.addRRect(outer); path.setFillType(SkPath::kEvenOdd_FillType); - this->internalDrawPath(clip, paint, aa, viewMatrix, path, GrStyle::SimpleFill()); + this->internalDrawPath(clip, paint, viewMatrix, path, GrStyle::SimpleFill()); } /////////////////////////////////////////////////////////////////////////////// @@ -1094,7 +1128,6 @@ 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) { @@ -1103,30 +1136,28 @@ void GrRenderTargetContext::drawRegion(const GrClip& clip, SkDEBUGCODE(this->validate();) GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRegion"); - if (GrAA::kYes == aa) { + bool needsAA = false; + if (paint.isAntiAlias()) { // GrRegionBatch performs no antialiasing but is much faster, so here we check the matrix // to see whether aa is really required. - if (!SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) && - is_int(viewMatrix.getTranslateX()) && - is_int(viewMatrix.getTranslateY())) { - aa = GrAA::kNo; - } + needsAA = SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)) || + !is_int(viewMatrix.getTranslateX()) || + !is_int(viewMatrix.getTranslateY()); } bool complexStyle = !style.isSimpleFill(); - if (complexStyle || GrAA::kYes == aa) { + if (complexStyle || needsAA) { SkPath path; region.getBoundaryPath(&path); - return this->drawPath(clip, paint, aa, viewMatrix, path, style); + return this->drawPath(clip, paint, viewMatrix, path, style); } sk_sp<GrDrawOp> op(GrRegionBatch::Create(paint.getColor(), viewMatrix, region)); - GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone); + GrPipelineBuilder pipelineBuilder(paint, false); 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) { @@ -1143,22 +1174,21 @@ void GrRenderTargetContext::drawOval(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); const SkStrokeRec& stroke = style.strokeRec(); - GrAAType aaType; + bool useHWAA; if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() && stroke.isFillStyle()) { InstancedRendering* ir = this->getOpList()->instancedRendering(); - sk_sp<GrDrawOp> op(ir->recordOval(oval, viewMatrix, paint.getColor(), aa, - fInstancedPipelineInfo, &aaType)); + sk_sp<GrDrawOp> op(ir->recordOval(oval, viewMatrix, paint.getColor(), paint.isAntiAlias(), + fInstancedPipelineInfo, &useHWAA)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } } - aaType = this->decideAAType(aa); - if (GrAAType::kCoverage == aaType) { + if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); sk_sp<GrDrawOp> op(GrOvalRenderer::CreateOvalBatch(paint.getColor(), viewMatrix, @@ -1166,7 +1196,7 @@ void GrRenderTargetContext::drawOval(const GrClip& clip, stroke, shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -1175,20 +1205,19 @@ void GrRenderTargetContext::drawOval(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addOval(oval); - this->internalDrawPath(clip, paint, aa, viewMatrix, path, style); + this->internalDrawPath(clip, paint, 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) { - GrAAType aaType = this->decideAAType(aa); - if (GrAAType::kCoverage == aaType) { + bool useHWAA; + if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA)) { const GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); sk_sp<GrDrawOp> op(GrOvalRenderer::CreateArcBatch(paint.getColor(), viewMatrix, @@ -1199,7 +1228,7 @@ void GrRenderTargetContext::drawArc(const GrClip& clip, style, shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -1207,7 +1236,8 @@ void GrRenderTargetContext::drawArc(const GrClip& clip, SkPath path; SkPathPriv::CreateDrawArcPath(&path, oval, startAngle, sweepAngle, useCenter, style.isSimpleFill()); - this->internalDrawPath(clip, paint, aa, viewMatrix, path, style); + this->internalDrawPath(clip, paint, viewMatrix, path, style); + return; } void GrRenderTargetContext::drawImageLattice(const GrClip& clip, @@ -1227,7 +1257,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, GrAAType::kNone); + GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } @@ -1256,12 +1286,11 @@ void GrRenderTargetContext::drawNonAAFilledRect(const GrClip& clip, const SkRect* localRect, const SkMatrix* localMatrix, const GrUserStencilSettings* ss, - GrAAType hwOrNoneAAType) { - SkASSERT(GrAAType::kCoverage != hwOrNoneAAType); - SkASSERT(hwOrNoneAAType == GrAAType::kNone || this->isStencilBufferMultisampled()); + bool useHWAA) { + SkASSERT(!useHWAA || this->isStencilBufferMultisampled()); sk_sp<GrDrawOp> op( GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, localRect, localMatrix)); - GrPipelineBuilder pipelineBuilder(paint, hwOrNoneAAType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); if (ss) { pipelineBuilder.setUserStencil(ss); } @@ -1363,7 +1392,6 @@ 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) { @@ -1381,8 +1409,9 @@ void GrRenderTargetContext::drawPath(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrAAType aaType = this->decideAAType(aa); - if (GrAAType::kCoverage == aaType && !style.pathEffect()) { + bool useHWAA; + if (should_apply_coverage_aa(paint, fRenderTargetProxy.get(), &useHWAA) && + !style.pathEffect()) { if (style.isSimpleFill() && !path.isConvex()) { // Concave AA paths are expensive - try to avoid them for special cases SkRect rects[2]; @@ -1390,8 +1419,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, aaType); + if (op) { + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); } return; @@ -1408,7 +1437,7 @@ void GrRenderTargetContext::drawPath(const GrClip& clip, style.strokeRec(), shaderCaps)); if (op) { - GrPipelineBuilder pipelineBuilder(paint, aaType); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getOpList()->addDrawOp(pipelineBuilder, this, clip, op.get()); return; } @@ -1420,24 +1449,23 @@ 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, aa, viewMatrix, path, style); + this->internalDrawPath(clip, paint, viewMatrix, path, style); } bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, const GrUserStencilSettings* ss, SkRegion::Op op, bool invert, - GrAA aa, + bool doAA, 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, - "GrRenderTargetContextPriv::drawAndStencilPath"); + GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, "GrRenderTargetContext::drawPath"); if (path.isEmpty() && path.isInverseFillType()) { - this->drawAndStencilRect(clip, ss, op, invert, GrAA::kNo, SkMatrix::I(), + this->drawAndStencilRect(clip, ss, op, invert, false, SkMatrix::I(), SkRect::MakeIWH(fRenderTargetContext->width(), fRenderTargetContext->height())); return true; @@ -1449,12 +1477,13 @@ 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. - GrAAType aaType = fRenderTargetContext->decideAAType(aa); + bool useCoverageAA = doAA && !fRenderTargetContext->isUnifiedMultisampled(); bool hasUserStencilSettings = !ss->isUnused(); + bool isStencilBufferMSAA = fRenderTargetContext->isStencilBufferMultisampled(); - const GrPathRendererChain::DrawType type = (GrAAType::kCoverage == aaType) - ? GrPathRendererChain::kColorAntiAlias_DrawType - : GrPathRendererChain::kColor_DrawType; + const GrPathRendererChain::DrawType type = + useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType + : GrPathRendererChain::kColor_DrawType; GrShape shape(path, GrStyle::SimpleFill()); GrPathRenderer::CanDrawPathArgs canDrawArgs; @@ -1462,8 +1491,9 @@ bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, fRenderTargetContext->fDrawingManager->getContext()->caps()->shaderCaps(); canDrawArgs.fViewMatrix = &viewMatrix; canDrawArgs.fShape = &shape; - canDrawArgs.fAAType = aaType; + canDrawArgs.fAntiAlias = useCoverageAA; canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; + canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; // Don't allow the SW renderer GrPathRenderer* pr = fRenderTargetContext->fDrawingManager->getPathRenderer(canDrawArgs, false, @@ -1484,7 +1514,7 @@ bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip, args.fClip = &clip; args.fViewMatrix = &viewMatrix; args.fShape = &shape; - args.fAAType = aaType; + args.fAntiAlias = useCoverageAA; args.fGammaCorrect = fRenderTargetContext->isGammaCorrect(); pr->drawPath(args); return true; @@ -1504,71 +1534,55 @@ 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; - 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; + 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; } GrPathRenderer::CanDrawPathArgs canDrawArgs; canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps(); canDrawArgs.fViewMatrix = &viewMatrix; canDrawArgs.fShape = &shape; - canDrawArgs.fHasUserStencilSettings = false; + canDrawArgs.fAntiAlias = useCoverageAA; + canDrawArgs.fHasUserStencilSettings = kHasUserStencilSettings; + canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; - GrPathRenderer* pr; - do { - const GrPathRendererChain::DrawType type = GrAAType::kCoverage == aaType - ? GrPathRendererChain::kColorAntiAlias_DrawType - : GrPathRendererChain::kColor_DrawType; + // 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); - shape = GrShape(path, style); + 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; } - - 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); - 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 (!pr) { + if (shape.style().applies()) { + shape = shape.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale); if (shape.isEmpty()) { return; } - pr = fDrawingManager->getPathRenderer(canDrawArgs, false, 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); + // This time, allow SW renderer + pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); + } if (!pr) { #ifdef SK_DEBUG @@ -1584,8 +1598,8 @@ void GrRenderTargetContext::internalDrawPath(const GrClip& clip, args.fRenderTargetContext = this; args.fClip = &clip; args.fViewMatrix = &viewMatrix; - args.fShape = &shape; - args.fAAType = aaType; + args.fShape = canDrawArgs.fShape; + args.fAntiAlias = useCoverageAA; args.fGammaCorrect = this->isGammaCorrect(); pr->drawPath(args); } |