Index: src/gpu/GrDrawContext.cpp |
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp |
index 430ae886f39c603eceb0645d57c73f844c23dcdf..aa7057510ce9d88508ac45ab3a15abca06e588a7 100644 |
--- a/src/gpu/GrDrawContext.cpp |
+++ b/src/gpu/GrDrawContext.cpp |
@@ -242,11 +242,7 @@ void GrDrawContext::drawPaint(const GrClip& clip, |
AutoCheckFlush acf(fDrawingManager); |
- SkAutoTUnref<GrDrawBatch> batch( |
- GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix::I(), r, nullptr, |
- &localMatrix)); |
- GrPipelineBuilder pipelineBuilder(*paint); // Create a pipeline builder without hwaa. |
- this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
+ this->drawNonAAFilledRect(clip, *paint, SkMatrix::I(), r, nullptr, &localMatrix, nullptr); |
} |
} |
@@ -274,33 +270,52 @@ static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt, |
} |
} |
-GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint, |
- const SkMatrix& viewMatrix, |
- const SkRect& rect, |
- bool* useHWAA) { |
+bool GrDrawContext::drawFilledRect(const GrClip& clip, |
+ const GrPaint& paint, |
+ const SkMatrix& viewMatrix, |
+ const SkRect& rect, |
+ const GrUserStencilSettings* ss) { |
+ |
+ SkAutoTUnref<GrDrawBatch> batch; |
+ bool useHWAA; |
+ |
if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) { |
- if (GrDrawBatch* batch = ir->recordRect(rect, viewMatrix, paint.getColor(), |
- paint.isAntiAlias(), fInstancedPipelineInfo, |
- useHWAA)) { |
- return batch; |
+ batch.reset(ir->recordRect(rect, viewMatrix, paint.getColor(), |
+ paint.isAntiAlias(), fInstancedPipelineInfo, |
+ &useHWAA)); |
+ if (batch) { |
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
+ if (ss) { |
+ pipelineBuilder.setUserStencil(ss); |
+ } |
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
+ return true; |
} |
} |
- if (should_apply_coverage_aa(paint, fRenderTarget.get(), useHWAA)) { |
+ if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
// The fill path can handle rotation but not skew. |
if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
SkRect devBoundRect; |
viewMatrix.mapRect(&devBoundRect, rect); |
- return GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix, |
- rect, devBoundRect); |
+ |
+ batch.reset(GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix, |
+ rect, devBoundRect)); |
+ if (batch) { |
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
+ if (ss) { |
+ pipelineBuilder.setUserStencil(ss); |
+ } |
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
+ return true; |
+ } |
} |
} else { |
- // filled BW rect |
- return GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, |
- nullptr, nullptr); |
+ this->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nullptr, ss); |
+ return true; |
} |
- return nullptr; |
+ return false; |
} |
void GrDrawContext::drawRect(const GrClip& clip, |
@@ -322,10 +337,8 @@ void GrDrawContext::drawRect(const GrClip& clip, |
AutoCheckFlush acf(fDrawingManager); |
const SkStrokeRec& stroke = style->strokeRec(); |
- bool useHWAA; |
- bool snapToPixelCenters = false; |
- SkAutoTUnref<GrDrawBatch> batch; |
- if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
+ if (stroke.getStyle() == SkStrokeRec::kFill_Style && |
+ !fContext->caps()->useDrawInsteadOfClear()) { |
// 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. |
SkRect rtRect; |
@@ -351,7 +364,10 @@ void GrDrawContext::drawRect(const GrClip& clip, |
} |
} |
} |
- batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); |
+ |
+ if (this->drawFilledRect(clip, paint, viewMatrix, rect, nullptr)) { |
+ return; |
+ } |
} else if (stroke.getStyle() == SkStrokeRec::kStroke_Style || |
stroke.getStyle() == SkStrokeRec::kHairline_Style) { |
if ((!rect.width() || !rect.height()) && |
@@ -385,6 +401,11 @@ void GrDrawContext::drawRect(const GrClip& clip, |
return; |
} |
} |
+ |
+ bool useHWAA; |
+ bool snapToPixelCenters = false; |
+ SkAutoTUnref<GrDrawBatch> batch; |
+ |
GrColor color = paint.getColor(); |
if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
// The stroke path needs the rect to remain axis aligned (no rotation or skew). |
@@ -400,18 +421,18 @@ void GrDrawContext::drawRect(const GrClip& clip, |
batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect, |
stroke, snapToPixelCenters)); |
} |
- } |
- if (batch) { |
- GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
+ if (batch) { |
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
- if (snapToPixelCenters) { |
- pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, |
- snapToPixelCenters); |
- } |
+ if (snapToPixelCenters) { |
+ pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, |
+ snapToPixelCenters); |
+ } |
- this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
- return; |
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
+ return; |
+ } |
} |
SkPath path; |
@@ -458,13 +479,7 @@ void GrDrawContextPriv::stencilRect(const GrFixedClip& clip, |
SkASSERT(!useHWAA || fDrawContext->isStencilBufferMultisampled()); |
- GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
- pipelineBuilder.setUserStencil(ss); |
- |
- SkAutoTUnref<GrDrawBatch> batch( |
- GrRectBatchFactory::CreateNonAAFill(SK_ColorWHITE, viewMatrix, rect, nullptr, nullptr)); |
- |
- fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext, clip, batch); |
+ fDrawContext->drawFilledRect(clip, paint, viewMatrix, rect, ss); |
} |
bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip, |
@@ -485,14 +500,7 @@ bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip, |
paint.setAntiAlias(doAA); |
paint.setCoverageSetOpXPFactory(op, invert); |
- bool useHWAA; |
- SkAutoTUnref<GrDrawBatch> batch( |
- fDrawContext->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); |
- if (batch) { |
- GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
- pipelineBuilder.setUserStencil(ss); |
- |
- fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext, clip, batch); |
+ if (fDrawContext->drawFilledRect(clip, paint, viewMatrix, rect, ss)) { |
return true; |
} |
@@ -530,15 +538,16 @@ void GrDrawContext::fillRectToRect(const GrClip& clip, |
view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, rectToDraw, |
localRect)); |
+ if (batch) { |
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
+ this->drawBatch(pipelineBuilder, clip, batch); |
+ return; |
+ } |
} else { |
- batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rectToDraw, |
- &localRect, nullptr)); |
+ this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, &localRect, |
+ nullptr, nullptr); |
} |
- if (batch) { |
- GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
- this->drawBatch(pipelineBuilder, clip, batch); |
- } |
} |
void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
@@ -569,13 +578,13 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix, |
rectToDraw)); |
+ GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
} else { |
- batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rectToDraw, |
- nullptr, &localMatrix)); |
+ this->drawNonAAFilledRect(clip, paint, viewMatrix, rectToDraw, nullptr, |
+ &localMatrix, nullptr); |
} |
- GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
- this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
} |
void GrDrawContext::drawVertices(const GrClip& clip, |
@@ -872,6 +881,23 @@ void GrDrawContext::drawImageNine(const GrClip& clip, |
} |
+void GrDrawContext::drawNonAAFilledRect(const GrClip& clip, |
+ const GrPaint& paint, |
+ const SkMatrix& viewMatrix, |
+ const SkRect& rect, |
+ const SkRect* localRect, |
+ const SkMatrix* localMatrix, |
+ const GrUserStencilSettings* ss) { |
+ SkAutoTUnref<GrDrawBatch> batch( |
+ GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, localRect, |
+ localMatrix)); |
+ GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
+ if (ss) { |
+ pipelineBuilder.setUserStencil(ss); |
+ } |
+ this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
+} |
+ |
// 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]) { |