diff options
author | 2017-06-14 19:08:01 -0400 | |
---|---|---|
committer | 2017-06-14 23:32:05 +0000 | |
commit | a0485d94529905e76320b7aa941a0d94b5578ac2 (patch) | |
tree | c851472453a20c78f2c3669ba9021ab0e9b02586 /src/gpu/GrRenderTargetContext.cpp | |
parent | 699b8732bf7b1ea3fbcce0b77a60f96fc4f8446c (diff) |
Revert "Converts remaining rect ops from GrLegacyMeshDrawOp to GrMeshDrawOp subclasses."
This reverts commit 1ec03f33cf493352174c748662d4a3cca29f78fd.
Revert "Fix logic reversal in NonAAFillRectOp test factory"
This reverts commit 89c1c2552ec5b9ad8949988f7c9532a298b55987.
Reason: Unexpected GM changes.
Bug: skia:
Change-Id: I9edf5f0e4a54b5cad86bd438a505aaaef38563de
Reviewed-on: https://skia-review.googlesource.com/19960
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrRenderTargetContext.cpp')
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 125 |
1 files changed, 83 insertions, 42 deletions
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 7d752b43c7..0f436f0300 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -34,6 +34,7 @@ #include "ops/GrDrawOp.h" #include "ops/GrDrawVerticesOp.h" #include "ops/GrLatticeOp.h" +#include "ops/GrNonAAFillRectOp.h" #include "ops/GrOp.h" #include "ops/GrOvalOpFactory.h" #include "ops/GrRectOpFactory.h" @@ -284,9 +285,10 @@ void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor // We don't call drawRect() here to avoid the cropping to the, possibly smaller, // RenderTargetProxy bounds - std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFill( - std::move(paint), SkMatrix::I(), SkRect::Make(rtRect), GrAAType::kNone); - fRenderTargetContext->addDrawOp(GrNoClip(), std::move(op)); + fRenderTargetContext->drawNonAAFilledRect(GrNoClip(), std::move(paint), SkMatrix::I(), + SkRect::Make(rtRect), nullptr, nullptr, nullptr, + GrAAType::kNone); + } else { // This path doesn't handle coalescing of full screen clears b.c. it // has to clear the entire render target - not just the content area. @@ -396,9 +398,8 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip, AutoCheckFlush acf(this->drawingManager()); - std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( - std::move(paint), SkMatrix::I(), localMatrix, r, GrAAType::kNone); - this->addDrawOp(clip, std::move(op)); + this->drawNonAAFilledRect(clip, std::move(paint), SkMatrix::I(), r, nullptr, &localMatrix, + nullptr, GrAAType::kNone); } } @@ -407,6 +408,10 @@ static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po point.fY >= rect.fTop && point.fY <= rect.fBottom; } +static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { + return viewMatrix.preservesRightAngles(); +} + // 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, @@ -474,17 +479,29 @@ bool GrRenderTargetContext::drawFilledRect(const GrClip& clip, } } GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); - std::unique_ptr<GrDrawOp> op; if (GrAAType::kCoverage == aaType) { - op = GrRectOpFactory::MakeAAFill(std::move(paint), viewMatrix, rect, ss); + // The fill path can handle rotation but not skew. + if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { + SkRect devBoundRect; + viewMatrix.mapRect(&devBoundRect, croppedRect); + std::unique_ptr<GrLegacyMeshDrawOp> op = + GrRectOpFactory::MakeAAFill(paint, viewMatrix, rect, croppedRect, devBoundRect); + if (op) { + GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); + if (ss) { + pipelineBuilder.setUserStencil(ss); + } + this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); + return true; + } + } } else { - op = GrRectOpFactory::MakeNonAAFill(std::move(paint), viewMatrix, croppedRect, aaType, ss); - } - if (!op) { - return false; + this->drawNonAAFilledRect(clip, std::move(paint), viewMatrix, croppedRect, nullptr, nullptr, + ss, aaType); + return true; } - this->addDrawOp(clip, std::move(op)); - return true; + + return false; } void GrRenderTargetContext::drawRect(const GrClip& clip, @@ -574,21 +591,30 @@ void GrRenderTargetContext::drawRect(const GrClip& clip, } } - std::unique_ptr<GrDrawOp> op; + bool snapToPixelCenters = false; + std::unique_ptr<GrLegacyMeshDrawOp> op; + GrColor color = paint.getColor(); GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); if (GrAAType::kCoverage == aaType) { // The stroke path needs the rect to remain axis aligned (no rotation or skew). if (viewMatrix.rectStaysRect()) { - op = GrRectOpFactory::MakeAAStroke(std::move(paint), viewMatrix, rect, stroke); + op = GrRectOpFactory::MakeAAStroke(color, viewMatrix, rect, stroke); } } else { - op = GrRectOpFactory::MakeNonAAStroke(std::move(paint), viewMatrix, rect, stroke, - aaType); + // 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. + snapToPixelCenters = stroke.getStyle() == SkStrokeRec::kHairline_Style && + GrFSAAType::kUnifiedMSAA != fRenderTargetProxy->fsaaType(); + op = GrRectOpFactory::MakeNonAAStroke(color, viewMatrix, rect, stroke, + snapToPixelCenters); } if (op) { - this->addDrawOp(clip, std::move(op)); + GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); + pipelineBuilder.setSnapVerticesToPixelCenters(snapToPixelCenters); + this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); return; } } @@ -694,9 +720,9 @@ void GrRenderTargetContextPriv::stencilRect(const GrClip& clip, GrPaint paint; paint.setXPFactory(GrDisableColorXPFactory::Get()); - std::unique_ptr<GrDrawOp> op = - GrRectOpFactory::MakeNonAAFill(std::move(paint), viewMatrix, rect, aaType, ss); - fRenderTargetContext->addDrawOp(clip, std::move(op)); + + fRenderTargetContext->drawNonAAFilledRect(clip, std::move(paint), viewMatrix, rect, nullptr, + nullptr, ss, aaType); } bool GrRenderTargetContextPriv::drawAndStencilRect(const GrClip& clip, @@ -758,16 +784,16 @@ void GrRenderTargetContext::fillRectToRect(const GrClip& clip, GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); if (GrAAType::kCoverage != aaType) { - std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalRect( - std::move(paint), viewMatrix, croppedRect, croppedLocalRect, aaType); - this->addDrawOp(clip, std::move(op)); + this->drawNonAAFilledRect(clip, std::move(paint), viewMatrix, croppedRect, + &croppedLocalRect, nullptr, nullptr, aaType); return; } - std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalRect( - std::move(paint), viewMatrix, croppedRect, croppedLocalRect); - if (op) { - this->addDrawOp(clip, std::move(op)); + if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { + std::unique_ptr<GrLegacyMeshDrawOp> op = GrAAFillRectOp::MakeWithLocalRect( + paint.getColor(), viewMatrix, croppedRect, croppedLocalRect); + GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); + this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); return; } @@ -814,16 +840,16 @@ void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip, GrAAType aaType = this->chooseAAType(aa, GrAllowMixedSamples::kNo); if (GrAAType::kCoverage != aaType) { - std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFillWithLocalMatrix( - std::move(paint), viewMatrix, localMatrix, croppedRect, aaType); - this->addDrawOp(clip, std::move(op)); + this->drawNonAAFilledRect(clip, std::move(paint), viewMatrix, croppedRect, nullptr, + &localMatrix, nullptr, aaType); return; } - std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeAAFillWithLocalMatrix( - std::move(paint), viewMatrix, localMatrix, croppedRect); - if (op) { - this->addDrawOp(clip, std::move(op)); + if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { + std::unique_ptr<GrLegacyMeshDrawOp> op = + GrAAFillRectOp::Make(paint.getColor(), viewMatrix, localMatrix, croppedRect); + GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); + this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); return; } @@ -1438,6 +1464,21 @@ void GrRenderTargetContext::prepareForExternalIO() { this->drawingManager()->prepareSurfaceForExternalIO(fRenderTargetProxy.get()); } +void GrRenderTargetContext::drawNonAAFilledRect(const GrClip& clip, + GrPaint&& paint, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkRect* localRect, + const SkMatrix* localMatrix, + const GrUserStencilSettings* ss, + GrAAType hwOrNoneAAType) { + SkASSERT(GrAAType::kCoverage != hwOrNoneAAType); + SkASSERT(GrAAType::kNone == hwOrNoneAAType || GrFSAAType::kNone != this->fsaaType()); + std::unique_ptr<GrDrawOp> op = GrNonAAFillRectOp::Make( + std::move(paint), viewMatrix, rect, localRect, localMatrix, hwOrNoneAAType, ss); + this->addDrawOp(clip, std::move(op)); +} + // Can 'path' be drawn as a pair of filled nested rectangles? static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path, SkRect rects[2]) { @@ -1511,13 +1552,13 @@ void GrRenderTargetContext::drawPath(const GrClip& clip, SkRect rects[2]; if (fills_as_nested_rects(viewMatrix, path, rects)) { - std::unique_ptr<GrDrawOp> op = - GrRectOpFactory::MakeAAFillNestedRects(std::move(paint), viewMatrix, rects); - if (!op) { - // A null return indicates that there is nothing to draw in this case. - return; + std::unique_ptr<GrLegacyMeshDrawOp> op = + GrRectOpFactory::MakeAAFillNestedRects(paint.getColor(), viewMatrix, rects); + if (op) { + GrPipelineBuilder pipelineBuilder(std::move(paint), aaType); + this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); } - this->addDrawOp(clip, std::move(op)); + return; } } SkRect ovalRect; |