Index: src/gpu/GrClipMaskManager.cpp |
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp |
index 7418e76449a3a2b4da775fda97e3b729aa824967..cd2dfe809ce6f07b09dd4335505989eddb8b316b 100644 |
--- a/src/gpu/GrClipMaskManager.cpp |
+++ b/src/gpu/GrClipMaskManager.cpp |
@@ -16,6 +16,7 @@ |
#include "GrRenderTarget.h" |
#include "GrRenderTargetPriv.h" |
#include "GrResourceProvider.h" |
+#include "GrInstancedRendering.h" |
#include "GrStencilAttachment.h" |
#include "GrSWMaskHelper.h" |
#include "SkRasterClip.h" |
@@ -48,16 +49,6 @@ static const GrFragmentProcessor* create_fp_for_mask(GrTexture* result, const Sk |
kDevice_GrCoordSet); |
} |
-static void draw_non_aa_rect(GrDrawTarget* drawTarget, |
- const GrPipelineBuilder& pipelineBuilder, |
- GrColor color, |
- const SkMatrix& viewMatrix, |
- const SkRect& rect) { |
- SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, |
- nullptr, nullptr)); |
- drawTarget->drawBatch(pipelineBuilder, batch); |
-} |
- |
// Does the path in 'element' require SW rendering? If so, return true (and, |
// optionally, set 'prOut' to NULL. If not, return false (and, optionally, set |
// 'prOut' to the non-SW path renderer that will do the job). |
@@ -754,6 +745,16 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt, |
fDrawTarget->cmmAccess().clearStencilClip(stencilSpaceIBounds, |
GrReducedClip::kAllIn_InitialState == initialState, rt); |
+ GrInstancedRendering* instRendering = fDrawTarget->instancedRendering(); |
+ uint32_t instRenderingFlags; |
+ if (instRendering) { |
+ instRenderingFlags = GrInstancedRendering::kStencilWrite_Flag | |
+ GrInstancedRendering::kUseDiscard_Flag; |
+ if (rt->isStencilBufferMultisampled()) { |
+ instRenderingFlags |= GrInstancedRendering::kStencilBufferMSAA_Flag; |
+ } |
+ } |
+ |
// walk through each clip element and perform its set op |
// with the existing clip. |
for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get(); iter.next()) { |
@@ -781,9 +782,27 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt, |
GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
SkRegion::Op op = element->getOp(); |
+ SkAutoTUnref<GrDrawBatch> fastBatch; |
+ if (Element::kPath_Type != element->getType()) { |
+ if (instRendering) { |
+ bool useHWAA; |
+ fastBatch.reset(instRendering->recordRRect(element->asRRect(), viewMatrix, |
+ GrColor_WHITE, |
+ pipelineBuilder.isHWAntialias(), |
+ instRenderingFlags, &useHWAA)); |
+ SkASSERT(!fastBatch || pipelineBuilder.isHWAntialias() == useHWAA); |
+ } |
+ |
+ if (!fastBatch && Element::kRect_Type == element->getType()) { |
+ fastBatch.reset(GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, viewMatrix, |
+ element->getRect(), nullptr, |
+ nullptr)); |
+ } |
+ } |
+ |
GrPathRenderer* pr = nullptr; |
SkPath clipPath; |
- if (Element::kRect_Type == element->getType()) { |
+ if (fastBatch) { |
stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
fillInverted = false; |
} else { |
@@ -837,11 +856,9 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt, |
0xffff, |
0x0000, |
0xffff); |
- if (Element::kRect_Type == element->getType()) { |
+ if (fastBatch) { |
*pipelineBuilder.stencil() = gDrawToStencil; |
- |
- draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_WHITE, viewMatrix, |
- element->getRect()); |
+ fDrawTarget->drawBatch(pipelineBuilder, fastBatch); |
} else { |
if (!clipPath.isEmpty()) { |
if (canRenderDirectToStencil) { |
@@ -879,9 +896,8 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt, |
*pipelineBuilder.stencil() = stencilSettings[p]; |
if (canDrawDirectToClip) { |
- if (Element::kRect_Type == element->getType()) { |
- draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_WHITE, viewMatrix, |
- element->getRect()); |
+ if (fastBatch) { |
+ fDrawTarget->drawBatch(pipelineBuilder, fastBatch); |
} else { |
GrPathRenderer::DrawPathArgs args; |
args.fTarget = fDrawTarget; |
@@ -898,8 +914,23 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt, |
} else { |
// The view matrix is setup to do clip space -> stencil space translation, so |
// draw rect in clip space. |
- draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_WHITE, viewMatrix, |
- SkRect::Make(clipSpaceIBounds)); |
+ const SkRect& clipSpaceRect = SkRect::Make(clipSpaceIBounds); |
+ SkAutoTUnref<GrDrawBatch> coverBatch; |
+ if (instRendering) { |
+ bool useHWAA; |
+ coverBatch.reset(instRendering->recordRect(clipSpaceRect, viewMatrix, |
+ GrColor_WHITE, |
+ pipelineBuilder.isHWAntialias(), |
+ instRenderingFlags, &useHWAA)); |
+ SkASSERT(!fastBatch || pipelineBuilder.isHWAntialias() == useHWAA); |
+ } |
+ if (!coverBatch) { |
+ coverBatch.reset(GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, |
+ viewMatrix, |
+ clipSpaceRect, |
+ nullptr, nullptr)); |
+ } |
+ fDrawTarget->drawBatch(pipelineBuilder, coverBatch); |
} |
} |
} |