From 4bc31815ba1aa42ea13c5637c6b52262422b7bdb Mon Sep 17 00:00:00 2001 From: robertphillips Date: Tue, 1 Mar 2016 12:22:49 -0800 Subject: [PATCH] Make GrDrawContext::internalDrawPath cons up its own GrPipelineBuilder Hopefully, this better defines (and reduces) the lifetime and reuse of GrPipelineBuilder objects in GrDrawContext. TBR=bsalomon@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1730903007 Committed: https://skia.googlesource.com/skia/+/00fddebe56fabea67dcc08762805c1294eebf5bf Review URL: https://codereview.chromium.org/1730903007 --- include/gpu/GrDrawContext.h | 11 ++-- src/gpu/GrDrawContext.cpp | 131 ++++++++++++++++++++++---------------------- 2 files changed, 69 insertions(+), 73 deletions(-) diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index 8cd5ee6..bde2f4a 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -100,7 +100,7 @@ public: const GrPaint& paint, const SkMatrix& viewMatrix, const SkRect&, - const GrStrokeInfo* strokeInfo = NULL); + const GrStrokeInfo* strokeInfo = nullptr); /** * Maps a rectangle of shader coordinates to a rectangle and fills that rectangle. @@ -302,12 +302,11 @@ private: const SkRRect& origOuter, const SkRRect& origInner); - void internalDrawPath(GrPipelineBuilder*, + void internalDrawPath(const GrClip& clip, + const GrPaint& paint, const SkMatrix& viewMatrix, - GrColor, - bool useAA, - const SkPath&, - const GrStrokeInfo&); + const SkPath& path, + const GrStrokeInfo& strokeInfo); // This entry point allows the GrTextContext-derived classes to add their batches to // the drawTarget. diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index e5064f0..628b4b2 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -229,10 +229,10 @@ void GrDrawContext::drawPaint(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); SkAutoTUnref batch( GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix::I(), r, nullptr, &localMatrix)); + GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } } @@ -265,7 +265,7 @@ void GrDrawContext::drawRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - SkScalar width = nullptr == strokeInfo ? -1 : strokeInfo->getWidth(); + SkScalar width = !strokeInfo ? -1 : strokeInfo->getWidth(); // Check if this is a full RT draw and can be replaced with a clear. We don't bother checking // cases where the RT is fully inside a stroke. @@ -301,15 +301,13 @@ void GrDrawContext::drawRect(const GrClip& clip, } } - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); - GrColor color = paint.getColor(); - + bool snapToPixelCenters = false; SkAutoTUnref batch; if (should_apply_coverage_aa(paint, fRenderTarget)) { if (width >= 0) { // The stroke path needs the rect to remain axis aligned (no rotation or skew). if (viewMatrix.rectStaysRect()) { - batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect, + batch.reset(GrRectBatchFactory::CreateAAStroke(paint.getColor(), viewMatrix, rect, *strokeInfo)); } } else { @@ -317,34 +315,42 @@ void GrDrawContext::drawRect(const GrClip& clip, if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { SkRect devBoundRect; viewMatrix.mapRect(&devBoundRect, rect); - batch.reset(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect, + batch.reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix, rect, devBoundRect)); } } - if (!batch) { - SkPath path; - path.setIsVolatile(true); - path.addRect(rect); - this->internalDrawPath(&pipelineBuilder, viewMatrix, color, true, path, *strokeInfo); - SkASSERT(paint.isAntiAlias()); - return; - } } else if (width >= 0) { // Non-AA hairlines are snapped to pixel centers to make which pixels are hit deterministic - bool snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisampled()); - batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect, width, - snapToPixelCenters)); + snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisampled()); + batch.reset(GrRectBatchFactory::CreateNonAAStroke(paint.getColor(), viewMatrix, rect, + width, snapToPixelCenters)); // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of - // hairline rects. We jam all the vertices to pixel centers to avoid this, but not when MSAA - // is enabled because it can cause ugly artifacts. - pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, - snapToPixelCenters); + // hairline rects. We jam all the vertices to pixel centers to avoid this, but not when + // MSAA is enabled because it can cause ugly artifacts. } else { // filled BW rect - batch.reset(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, nullptr, nullptr)); + batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, + nullptr, nullptr)); } - this->getDrawTarget()->drawBatch(pipelineBuilder, batch); + + if (batch) { + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + + if (snapToPixelCenters) { + pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, + snapToPixelCenters); + } + + this->getDrawTarget()->drawBatch(pipelineBuilder, batch); + return; + } + + SkPath path; + path.setIsVolatile(true); + path.addRect(rect); + this->internalDrawPath(clip, paint, viewMatrix, path, + strokeInfo ? *strokeInfo : GrStrokeInfo::FillInfo()); } void GrDrawContext::fillRectToRect(const GrClip& clip, @@ -359,7 +365,6 @@ void GrDrawContext::fillRectToRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); SkAutoTUnref batch; if (should_apply_coverage_aa(paint, fRenderTarget) && view_matrix_ok_for_aa_fill_rect(viewMatrix)) { @@ -371,6 +376,7 @@ void GrDrawContext::fillRectToRect(const GrClip& clip, } if (batch) { + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->drawBatch(&pipelineBuilder, batch); } } @@ -387,8 +393,6 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); - SkAutoTUnref batch; if (should_apply_coverage_aa(paint, fRenderTarget) && view_matrix_ok_for_aa_fill_rect(viewMatrix)) { @@ -398,6 +402,8 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rectToDraw, nullptr, &localMatrix)); } + + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -418,8 +424,6 @@ void GrDrawContext::drawVertices(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); - // TODO clients should give us bounds SkRect bounds; if (!bounds.setBoundsCheck(positions, vertexCount)) { @@ -444,6 +448,7 @@ void GrDrawContext::drawVertices(const GrClip& clip, indexCount, colors, texCoords, bounds)); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -462,14 +467,13 @@ void GrDrawContext::drawAtlas(const GrClip& clip, GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas"); AutoCheckFlush acf(fDrawingManager); - - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); - + GrDrawAtlasBatch::Geometry geometry; geometry.fColor = paint.getColor(); SkAutoTUnref batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xform, texRect, colors)); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -493,18 +497,16 @@ void GrDrawContext::drawRRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); - GrColor color = paint.getColor(); - if (should_apply_coverage_aa(paint, fRenderTarget)) { GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); - SkAutoTUnref batch(GrOvalRenderer::CreateRRectBatch(color, + SkAutoTUnref batch(GrOvalRenderer::CreateRRectBatch(paint.getColor(), viewMatrix, rrect, strokeInfo, shaderCaps)); if (batch) { + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } @@ -513,8 +515,7 @@ void GrDrawContext::drawRRect(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addRRect(rrect); - this->internalDrawPath(&pipelineBuilder, viewMatrix, color, - paint.isAntiAlias(), path, strokeInfo); + this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); } bool GrDrawContext::drawFilledDRRect(const GrClip& clip, @@ -600,8 +601,7 @@ void GrDrawContext::drawDRRect(const GrClip& clip, path.setFillType(SkPath::kEvenOdd_FillType); GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); - this->internalDrawPath(&pipelineBuilder, viewMatrix, paint.getColor(), - paint.isAntiAlias(), path, GrStrokeInfo::FillInfo()); + this->internalDrawPath(clip, paint, viewMatrix, path, GrStrokeInfo::FillInfo()); } /////////////////////////////////////////////////////////////////////////////// @@ -624,17 +624,15 @@ void GrDrawContext::drawOval(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); - GrColor color = paint.getColor(); - if (should_apply_coverage_aa(paint, fRenderTarget)) { GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); - SkAutoTUnref batch(GrOvalRenderer::CreateOvalBatch(color, + SkAutoTUnref batch(GrOvalRenderer::CreateOvalBatch(paint.getColor(), viewMatrix, oval, strokeInfo, shaderCaps)); if (batch) { + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } @@ -643,8 +641,7 @@ void GrDrawContext::drawOval(const GrClip& clip, SkPath path; path.setIsVolatile(true); path.addOval(oval); - this->internalDrawPath(&pipelineBuilder, viewMatrix, color, - paint.isAntiAlias(), path, strokeInfo); + this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); } void GrDrawContext::drawImageNine(const GrClip& clip, @@ -762,16 +759,8 @@ void GrDrawContext::drawPath(const GrClip& clip, return; } - GrColor color = paint.getColor(); - - // Note that internalDrawPath may sw-rasterize the path into a scratch texture. - // Scratch textures can be recycled after they are returned to the texture - // 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. AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); if (should_apply_coverage_aa(paint, fRenderTarget) && !strokeInfo.isDashed()) { if (strokeInfo.getWidth() < 0 && !path.isConvex()) { // Concave AA paths are expensive - try to avoid them for special cases @@ -779,7 +768,9 @@ void GrDrawContext::drawPath(const GrClip& clip, if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { SkAutoTUnref batch(GrRectBatchFactory::CreateAAFillNestedRects( - color, viewMatrix, rects)); + paint.getColor(), viewMatrix, rects)); + + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } @@ -789,25 +780,30 @@ void GrDrawContext::drawPath(const GrClip& clip, if (isOval && !path.isInverseFillType()) { GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); - SkAutoTUnref batch(GrOvalRenderer::CreateOvalBatch(color, + SkAutoTUnref batch(GrOvalRenderer::CreateOvalBatch(paint.getColor(), viewMatrix, ovalRect, strokeInfo, shaderCaps)); if (batch) { + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } } } - this->internalDrawPath(&pipelineBuilder, viewMatrix, color, - paint.isAntiAlias(), path, strokeInfo); + + // Note that internalDrawPath may sw-rasterize the path into a scratch texture. + // Scratch textures can be recycled after they are returned to the texture + // 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, strokeInfo); } -void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder, +void GrDrawContext::internalDrawPath(const GrClip& clip, + const GrPaint& paint, const SkMatrix& viewMatrix, - GrColor color, - bool useAA, const SkPath& path, const GrStrokeInfo& strokeInfo) { ASSERT_SINGLE_OWNER @@ -818,10 +814,9 @@ void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder, // 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 = useAA && - !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled(); - bool isStencilDisabled = pipelineBuilder->getStencil().isDisabled(); - bool isStencilBufferMSAA = pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled(); + bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget); + const bool isStencilDisabled = true; + bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); const GrPathRendererChain::DrawType type = useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType @@ -894,11 +889,13 @@ void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder, return; } + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPathRenderer::DrawPathArgs args; args.fTarget = this->getDrawTarget(); args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); - args.fPipelineBuilder = pipelineBuilder; - args.fColor = color; + args.fPipelineBuilder = &pipelineBuilder; + args.fColor = paint.getColor(); args.fViewMatrix = &viewMatrix; args.fPath = pathPtr; args.fStroke = strokeInfoPtr; -- 2.7.4