Add choke point for modifying non-AA rect draws (e.g., applying clipping)

NOTREECHECKS=true
NOPRESUBMIT=true

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2125333002

Review-Url: https://codereview.chromium.org/2125333002
This commit is contained in:
robertphillips 2016-07-08 12:00:07 -07:00 committed by Commit bot
parent 6cc9006a90
commit e5e3a7a520
6 changed files with 105 additions and 77 deletions

View File

@ -32,6 +32,7 @@ class GrPipelineBuilder;
class GrRenderTarget;
class GrStyle;
class GrSurface;
struct GrUserStencilSettings;
class SkDrawFilter;
struct SkIPoint;
struct SkIRect;
@ -322,10 +323,19 @@ private:
const SkRRect& origOuter,
const SkRRect& origInner);
GrDrawBatch* getFillRectBatch(const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rect,
bool* useHWAA);
bool drawFilledRect(const GrClip& clip,
const GrPaint& paint,
const SkMatrix& viewMatrix,
const SkRect& rect,
const GrUserStencilSettings* ss);
void drawNonAAFilledRect(const GrClip&,
const GrPaint&,
const SkMatrix& viewMatrix,
const SkRect& rect,
const SkRect* localRect,
const SkMatrix* localMatrix,
const GrUserStencilSettings* ss);
void internalDrawPath(const GrClip& clip,
const GrPaint& paint,

View File

@ -47,13 +47,6 @@ public:
const GrClipStackClip&, const SkRect* devBounds, GrAppliedClip*);
private:
static void DrawNonAARect(GrDrawContext* drawContext,
const GrFixedClip& clip,
const SkMatrix& viewMatrix,
const SkRect& rect,
bool isAA,
const GrUserStencilSettings* stencilSettings);
static bool PathNeedsSWRenderer(GrContext* context,
bool hasUserStencilSettings,
const GrDrawContext*,

View File

@ -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,9 +337,6 @@ 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) {
// 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.
@ -351,7 +363,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 +400,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 +420,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 +478,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 +499,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 +537,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 +577,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 +880,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]) {

View File

@ -469,15 +469,13 @@ void GrDrawTarget::clear(const SkIRect* rect,
drawContext->discard();
}
// TODO: flip this into real draw!
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode));
SkRect scalarRect = SkRect::Make(*rect);
SkAutoTUnref<GrDrawBatch> batch(
GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalarRect,
nullptr, nullptr));
this->drawBatch(pipelineBuilder, drawContext, GrNoClip(), batch);
GrPaint paint;
paint.setColor4f(GrColor4f::FromGrColor(color));
paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode));
drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), scalarRect);
} else {
GrBatch* batch = new GrClearBatch(*rect, color, drawContext->accessRenderTarget());
this->recordBatch(batch, batch->bounds());

View File

@ -554,6 +554,7 @@ bool GrDefaultPathRenderer::internalDrawPath(GrDrawContext* drawContext,
GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds, nullptr,
&localMatrix));
SkASSERT(GrPipelineBuilder::kBoth_DrawFace == drawFace[p]);
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint));
pipelineBuilder.setDrawFace(drawFace[p]);
if (passes[p]) {

View File

@ -658,6 +658,7 @@ bool GrMSAAPathRenderer::internalDrawPath(GrDrawContext* drawContext,
GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds, nullptr,
&localMatrix));
SkASSERT(GrPipelineBuilder::kBoth_DrawFace == drawFace[p]);
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint));
pipelineBuilder.setDrawFace(drawFace[p]);
if (passes[p]) {