From fc49d56feb2d890ccb3827ed087ab32e18a9da12 Mon Sep 17 00:00:00 2001 From: csmartdalton Date: Tue, 26 Jul 2016 17:05:47 -0700 Subject: Implement coverage AA for skewed rects with local coords Adds a path fallback for rects with local coords that can't be drawn with an analytic shader. This is accomplished by modifying the view matrix and then drawing the local rect/quad. BUG=skia:5500, 7508 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2183223002 Review-Url: https://codereview.chromium.org/2183223002 --- src/gpu/GrDrawContext.cpp | 74 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 23 deletions(-) (limited to 'src/gpu/GrDrawContext.cpp') diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index e6bc55b619..266c50d70c 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -616,12 +616,12 @@ void GrDrawContext::fillRectToRect(const GrClip& clip, } AutoCheckFlush acf(fDrawingManager); - SkAutoTUnref batch; bool useHWAA; if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { - batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), croppedLocalRect, - paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); + SkAutoTUnref batch(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), + croppedLocalRect, paint.isAntiAlias(), + fInstancedPipelineInfo, &useHWAA)); if (batch) { GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); @@ -629,20 +629,33 @@ void GrDrawContext::fillRectToRect(const GrClip& clip, } } - if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && - view_matrix_ok_for_aa_fill_rect(viewMatrix)) { - batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, - croppedRect, croppedLocalRect)); - if (batch) { - GrPipelineBuilder pipelineBuilder(paint, useHWAA); - this->drawBatch(pipelineBuilder, clip, batch); - return; - } - } else { + if (!should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, &croppedLocalRect, nullptr, nullptr); + return; + } + + if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { + SkAutoTUnref batch(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), + viewMatrix, + croppedRect, + croppedLocalRect)); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); + this->drawBatch(pipelineBuilder, clip, batch); + return; + } + + SkMatrix viewAndUnLocalMatrix; + if (!viewAndUnLocalMatrix.setRectToRect(localRect, rectToDraw, SkMatrix::kFill_ScaleToFit)) { + SkDebugf("fillRectToRect called with empty local matrix.\n"); + return; } + viewAndUnLocalMatrix.postConcat(viewMatrix); + SkPath path; + path.setIsVolatile(true); + path.addRect(localRect); + this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); } void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, @@ -661,12 +674,12 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, } AutoCheckFlush acf(fDrawingManager); - SkAutoTUnref batch; bool useHWAA; if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { - batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), localMatrix, - paint.isAntiAlias(), fInstancedPipelineInfo, &useHWAA)); + SkAutoTUnref batch(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), + localMatrix, paint.isAntiAlias(), + fInstancedPipelineInfo, &useHWAA)); if (batch) { GrPipelineBuilder pipelineBuilder(paint, useHWAA); this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); @@ -674,17 +687,32 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, } } - if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && - view_matrix_ok_for_aa_fill_rect(viewMatrix)) { - batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix, - croppedRect)); - GrPipelineBuilder pipelineBuilder(paint, useHWAA); - this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); - } else { + if (!should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { this->drawNonAAFilledRect(clip, paint, viewMatrix, croppedRect, nullptr, &localMatrix, nullptr); + return; } + if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { + SkAutoTUnref batch(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, + localMatrix, croppedRect)); + GrPipelineBuilder pipelineBuilder(paint, useHWAA); + this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); + return; + } + + SkMatrix viewAndUnLocalMatrix; + if (!localMatrix.invert(&viewAndUnLocalMatrix)) { + SkDebugf("fillRectWithLocalMatrix called with degenerate local matrix.\n"); + return; + } + viewAndUnLocalMatrix.postConcat(viewMatrix); + + SkPath path; + path.setIsVolatile(true); + path.addRect(rectToDraw); + path.transform(localMatrix); + this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); } void GrDrawContext::drawVertices(const GrClip& clip, -- cgit v1.2.3