Remove drawPathsFromRange from GrDrawContext
Replaces drawPathsFromRange with a more general drawPathBatch method. While this still isn't perfect, it's a step in the right direction that removes the need for path range draws to fit in a public API. BUG=skia: Review URL: https://codereview.chromium.org/1506823004
This commit is contained in:
parent
77665b8a07
commit
8ff8d24c83
@ -16,12 +16,11 @@
|
||||
class GrClip;
|
||||
class GrContext;
|
||||
class GrDrawBatch;
|
||||
class GrDrawPathBatchBase;
|
||||
class GrDrawingManager;
|
||||
class GrDrawTarget;
|
||||
class GrPaint;
|
||||
class GrPathProcessor;
|
||||
class GrPathRange;
|
||||
class GrPathRangeDraw;
|
||||
class GrPipelineBuilder;
|
||||
class GrRenderTarget;
|
||||
class GrStrokeInfo;
|
||||
@ -63,17 +62,6 @@ public:
|
||||
SkScalar x, SkScalar y,
|
||||
SkDrawFilter*, const SkIRect& clipBounds);
|
||||
|
||||
// drawPathsFromRange is thanks to GrStencilAndCoverTextContext
|
||||
// TODO: remove once path batches can be created external to GrDrawTarget.
|
||||
void drawPathsFromRange(const GrPipelineBuilder*,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkMatrix& localMatrix,
|
||||
GrColor color,
|
||||
GrPathRange* range,
|
||||
GrPathRangeDraw* draw,
|
||||
int /*GrPathRendering::FillType*/ fill,
|
||||
const SkRect& bounds);
|
||||
|
||||
/**
|
||||
* Provides a perfomance hint that the render target's contents are allowed
|
||||
* to become undefined.
|
||||
@ -274,6 +262,14 @@ public:
|
||||
*/
|
||||
void drawBatch(const GrClip&, const GrPaint&, GrDrawBatch*);
|
||||
|
||||
/**
|
||||
* Draws a path batch. This needs to be separate from drawBatch because we install path stencil
|
||||
* settings late.
|
||||
*
|
||||
* TODO: Figure out a better model that allows us to roll this method into drawBatch.
|
||||
*/
|
||||
void drawPathBatch(const GrPipelineBuilder&, GrDrawPathBatchBase*);
|
||||
|
||||
int width() const { return fRenderTarget->width(); }
|
||||
int height() const { return fRenderTarget->height(); }
|
||||
int numColorSamples() const { return fRenderTarget->numColorSamples(); }
|
||||
|
@ -136,22 +136,6 @@ void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
|
||||
fTextContext->drawTextBlob(this, clip, skPaint, viewMatrix, blob, x, y, filter, clipBounds);
|
||||
}
|
||||
|
||||
void GrDrawContext::drawPathsFromRange(const GrPipelineBuilder* pipelineBuilder,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkMatrix& localMatrix,
|
||||
GrColor color,
|
||||
GrPathRange* range,
|
||||
GrPathRangeDraw* draw,
|
||||
int /*GrPathRendering::FillType*/ fill,
|
||||
const SkRect& bounds) {
|
||||
RETURN_IF_ABANDONED
|
||||
SkDEBUGCODE(this->validate();)
|
||||
|
||||
this->getDrawTarget()->drawPathsFromRange(*pipelineBuilder, viewMatrix, localMatrix, color,
|
||||
range, draw, (GrPathRendering::FillType) fill,
|
||||
bounds);
|
||||
}
|
||||
|
||||
void GrDrawContext::discard() {
|
||||
RETURN_IF_ABANDONED
|
||||
SkDEBUGCODE(this->validate();)
|
||||
@ -638,6 +622,16 @@ void GrDrawContext::drawBatch(const GrClip& clip,
|
||||
this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
|
||||
}
|
||||
|
||||
void GrDrawContext::drawPathBatch(const GrPipelineBuilder& pipelineBuilder,
|
||||
GrDrawPathBatchBase* batch) {
|
||||
RETURN_IF_ABANDONED
|
||||
SkDEBUGCODE(this->validate();)
|
||||
|
||||
AutoCheckFlush acf(fDrawingManager);
|
||||
|
||||
this->getDrawTarget()->drawPathBatch(pipelineBuilder, batch);
|
||||
}
|
||||
|
||||
void GrDrawContext::drawPath(const GrClip& clip,
|
||||
const GrPaint& paint,
|
||||
const SkMatrix& viewMatrix,
|
||||
|
@ -316,40 +316,13 @@ void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder,
|
||||
batch->unref();
|
||||
}
|
||||
|
||||
void GrDrawTarget::drawPath(const GrPipelineBuilder& pipelineBuilder,
|
||||
const SkMatrix& viewMatrix,
|
||||
GrColor color,
|
||||
const GrPath* path,
|
||||
GrPathRendering::FillType fill) {
|
||||
SkASSERT(path);
|
||||
SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
|
||||
|
||||
GrDrawPathBatchBase* batch = GrDrawPathBatch::Create(viewMatrix, color, path);
|
||||
this->drawPathBatch(pipelineBuilder, batch, fill);
|
||||
batch->unref();
|
||||
}
|
||||
|
||||
void GrDrawTarget::drawPathsFromRange(const GrPipelineBuilder& pipelineBuilder,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkMatrix& localMatrix,
|
||||
GrColor color,
|
||||
GrPathRange* range,
|
||||
GrPathRangeDraw* draw,
|
||||
GrPathRendering::FillType fill,
|
||||
const SkRect& bounds) {
|
||||
GrDrawPathBatchBase* batch = GrDrawPathRangeBatch::Create(viewMatrix, localMatrix, color,
|
||||
range, draw, bounds);
|
||||
this->drawPathBatch(pipelineBuilder, batch, fill);
|
||||
batch->unref();
|
||||
}
|
||||
|
||||
void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder,
|
||||
GrDrawPathBatchBase* batch,
|
||||
GrPathRendering::FillType fill) {
|
||||
GrDrawPathBatchBase* batch) {
|
||||
// This looks like drawBatch() but there is an added wrinkle that stencil settings get inserted
|
||||
// after setting up clipping but before onDrawBatch(). TODO: Figure out a better model for
|
||||
// handling stencil settings WRT interactions between pipeline(builder), clipmaskmanager, and
|
||||
// batches.
|
||||
SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
|
||||
|
||||
GrPipelineBuilder::AutoRestoreStencil ars;
|
||||
GrAppliedClip clip;
|
||||
@ -367,7 +340,7 @@ void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder,
|
||||
GrStencilSettings stencilSettings;
|
||||
GrRenderTarget* rt = pipelineBuilder.getRenderTarget();
|
||||
GrStencilAttachment* sb = fResourceProvider->attachStencilAttachment(rt);
|
||||
this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
|
||||
this->getPathStencilSettingsForFilltype(batch->fillType(), sb, &stencilSettings);
|
||||
batch->setStencilSettings(stencilSettings);
|
||||
|
||||
GrPipeline::CreateArgs args;
|
||||
|
@ -39,7 +39,6 @@ class GrClip;
|
||||
class GrCaps;
|
||||
class GrPath;
|
||||
class GrDrawPathBatchBase;
|
||||
class GrPathRangeDraw;
|
||||
|
||||
class GrDrawTarget final : public SkRefCnt {
|
||||
public:
|
||||
@ -112,34 +111,13 @@ public:
|
||||
GrPathRendering::FillType);
|
||||
|
||||
/**
|
||||
* Draws a path. Fill must not be a hairline. It will respect the HW
|
||||
* antialias flag on the GrPipelineBuilder (if possible in the 3D API).
|
||||
* Draws a path batch. Fill must not be a hairline. It will respect the HW antialias flag on
|
||||
* the GrPipelineBuilder (if possible in the 3D API). This needs to be separate from drawBatch
|
||||
* because we install path stencil settings late.
|
||||
*
|
||||
* TODO: Remove this function and construct the batch outside GrDrawTarget.
|
||||
* TODO: Figure out a better model that allows us to roll this method into drawBatch.
|
||||
*/
|
||||
void drawPath(const GrPipelineBuilder&, const SkMatrix& viewMatrix, GrColor color,
|
||||
const GrPath*, GrPathRendering::FillType);
|
||||
|
||||
/**
|
||||
* Draws the aggregate path from combining multiple. Note that this will not
|
||||
* always be equivalent to back-to-back calls to drawPath(). It will respect
|
||||
* the HW antialias flag on the GrPipelineBuilder (if possible in the 3D API).
|
||||
*
|
||||
* TODO: Remove this function and construct the batch outside GrDrawTarget.
|
||||
*
|
||||
* @param draw The transforms and indices for the draw.
|
||||
* This object must only be drawn once. The draw
|
||||
* may modify its contents.
|
||||
* @param fill Fill type for drawing all the paths
|
||||
*/
|
||||
void drawPathsFromRange(const GrPipelineBuilder&,
|
||||
const SkMatrix& viewMatrix,
|
||||
const SkMatrix& localMatrix,
|
||||
GrColor color,
|
||||
GrPathRange* range,
|
||||
GrPathRangeDraw* draw,
|
||||
GrPathRendering::FillType fill,
|
||||
const SkRect& bounds);
|
||||
void drawPathBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawPathBatchBase* batch);
|
||||
|
||||
/**
|
||||
* Helper function for drawing rects.
|
||||
@ -288,8 +266,6 @@ private:
|
||||
GrXferProcessor::DstTexture*,
|
||||
const SkRect& batchBounds);
|
||||
|
||||
void drawPathBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawPathBatchBase* batch,
|
||||
GrPathRendering::FillType fill);
|
||||
// Check to see if this set of draw commands has been sent out
|
||||
void getPathStencilSettingsForFilltype(GrPathRendering::FillType,
|
||||
const GrStencilAttachment*,
|
||||
|
@ -523,8 +523,12 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
|
||||
SkRect bounds = SkRect::MakeIWH(pipelineBuilder->getRenderTarget()->width(),
|
||||
pipelineBuilder->getRenderTarget()->height());
|
||||
|
||||
dc->drawPathsFromRange(pipelineBuilder, drawMatrix, localMatrix, color, glyphs, fDraw,
|
||||
GrPathRendering::kWinding_FillType, bounds);
|
||||
SkAutoTUnref<GrDrawPathBatchBase> batch(
|
||||
GrDrawPathRangeBatch::Create(drawMatrix, localMatrix, color,
|
||||
GrPathRendering::kWinding_FillType, glyphs, fDraw,
|
||||
bounds));
|
||||
|
||||
dc->drawPathBatch(*pipelineBuilder, batch);
|
||||
}
|
||||
|
||||
if (fFallbackTextBlob) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
class GrTextStrike;
|
||||
class GrPath;
|
||||
class SkSurfaceProps;
|
||||
class GrPathRangeDraw;
|
||||
|
||||
/*
|
||||
* This class implements text rendering using stencil and cover path rendering
|
||||
|
@ -42,23 +42,11 @@ SkString GrDrawPathRangeBatch::dumpInfo() const {
|
||||
return string;
|
||||
}
|
||||
|
||||
bool GrDrawPathRangeBatch::isWinding() const {
|
||||
static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Face;
|
||||
bool isWinding = kInvert_StencilOp != this->stencilSettings().passOp(pathFace);
|
||||
if (isWinding) {
|
||||
// Double check that it is in fact winding.
|
||||
SkASSERT(kIncClamp_StencilOp == this->stencilSettings().passOp(pathFace));
|
||||
SkASSERT(kIncClamp_StencilOp == this->stencilSettings().failOp(pathFace));
|
||||
SkASSERT(0x1 != this->stencilSettings().writeMask(pathFace));
|
||||
SkASSERT(!this->stencilSettings().isTwoSided());
|
||||
}
|
||||
return isWinding;
|
||||
}
|
||||
|
||||
GrDrawPathRangeBatch::GrDrawPathRangeBatch(const SkMatrix& viewMatrix, const SkMatrix& localMatrix,
|
||||
GrColor color, GrPathRange* range, GrPathRangeDraw* draw,
|
||||
GrColor color, GrPathRendering::FillType fill,
|
||||
GrPathRange* range, GrPathRangeDraw* draw,
|
||||
const SkRect& bounds)
|
||||
: INHERITED(ClassID(), viewMatrix, color)
|
||||
: INHERITED(ClassID(), viewMatrix, color, fill)
|
||||
, fPathRange(range)
|
||||
, fLocalMatrix(localMatrix) {
|
||||
SkDEBUGCODE(draw->fUsedInBatch = true;)
|
||||
@ -90,7 +78,7 @@ bool GrDrawPathRangeBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) {
|
||||
// work). Note that it's also possible for overlapping paths to cancel each other's winding
|
||||
// numbers, and we only partially account for this by not allowing even/odd paths to be
|
||||
// combined. (Glyphs in the same font tend to wind the same direction so it works out OK.)
|
||||
if (!this->isWinding() ||
|
||||
if (GrPathRendering::kWinding_FillType != this->fillType() ||
|
||||
this->stencilSettings() != that->stencilSettings() ||
|
||||
this->overrides().willColorBlendWithDst()) {
|
||||
return false;
|
||||
|
@ -27,13 +27,17 @@ public:
|
||||
overrides->fUsePLSDstRead = false;
|
||||
}
|
||||
|
||||
GrPathRendering::FillType fillType() const { return fFillType; }
|
||||
|
||||
void setStencilSettings(const GrStencilSettings& stencil) { fStencilSettings = stencil; }
|
||||
|
||||
protected:
|
||||
GrDrawPathBatchBase(uint32_t classID, const SkMatrix& viewMatrix, GrColor initialColor)
|
||||
GrDrawPathBatchBase(uint32_t classID, const SkMatrix& viewMatrix, GrColor initialColor,
|
||||
GrPathRendering::FillType fill)
|
||||
: INHERITED(classID)
|
||||
, fViewMatrix(viewMatrix)
|
||||
, fColor(initialColor) {}
|
||||
, fColor(initialColor)
|
||||
, fFillType(fill) {}
|
||||
|
||||
const GrStencilSettings& stencilSettings() const { return fStencilSettings; }
|
||||
const GrXPOverridesForBatch& overrides() const { return fOverrides; }
|
||||
@ -48,6 +52,7 @@ private:
|
||||
|
||||
SkMatrix fViewMatrix;
|
||||
GrColor fColor;
|
||||
GrPathRendering::FillType fFillType;
|
||||
GrStencilSettings fStencilSettings;
|
||||
GrXPOverridesForBatch fOverrides;
|
||||
|
||||
@ -60,8 +65,8 @@ public:
|
||||
|
||||
// This can't return a more abstract type because we install the stencil settings late :(
|
||||
static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, GrColor color,
|
||||
const GrPath* path) {
|
||||
return new GrDrawPathBatch(viewMatrix, color, path);
|
||||
GrPathRendering::FillType fill, const GrPath* path) {
|
||||
return new GrDrawPathBatch(viewMatrix, color, fill, path);
|
||||
}
|
||||
|
||||
const char* name() const override { return "DrawPath"; }
|
||||
@ -69,8 +74,9 @@ public:
|
||||
SkString dumpInfo() const override;
|
||||
|
||||
private:
|
||||
GrDrawPathBatch(const SkMatrix& viewMatrix, GrColor color, const GrPath* path)
|
||||
: INHERITED(ClassID(), viewMatrix, color)
|
||||
GrDrawPathBatch(const SkMatrix& viewMatrix, GrColor color, GrPathRendering::FillType fill,
|
||||
const GrPath* path)
|
||||
: INHERITED(ClassID(), viewMatrix, color, fill)
|
||||
, fPath(path) {
|
||||
fBounds = path->getBounds();
|
||||
viewMatrix.mapRect(&fBounds);
|
||||
@ -148,9 +154,11 @@ public:
|
||||
|
||||
// This can't return a more abstract type because we install the stencil settings late :(
|
||||
static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, const SkMatrix& localMatrix,
|
||||
GrColor color, GrPathRange* range, GrPathRangeDraw* draw,
|
||||
GrColor color, GrPathRendering::FillType fill,
|
||||
GrPathRange* range, GrPathRangeDraw* draw,
|
||||
const SkRect& bounds) {
|
||||
return new GrDrawPathRangeBatch(viewMatrix, localMatrix, color, range, draw, bounds);
|
||||
return new GrDrawPathRangeBatch(viewMatrix, localMatrix, color, fill, range, draw,
|
||||
bounds);
|
||||
}
|
||||
|
||||
~GrDrawPathRangeBatch() override;
|
||||
@ -160,10 +168,9 @@ public:
|
||||
SkString dumpInfo() const override;
|
||||
|
||||
private:
|
||||
inline bool isWinding() const;
|
||||
|
||||
GrDrawPathRangeBatch(const SkMatrix& viewMatrix, const SkMatrix& localMatrix, GrColor color,
|
||||
GrPathRange* range, GrPathRangeDraw* draw, const SkRect& bounds);
|
||||
GrPathRendering::FillType fill, GrPathRange* range,
|
||||
GrPathRangeDraw* draw, const SkRect& bounds);
|
||||
|
||||
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override;
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "GrStencilAndCoverPathRenderer.h"
|
||||
#include "GrCaps.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrDrawPathBatch.h"
|
||||
#include "GrGpu.h"
|
||||
#include "GrPath.h"
|
||||
#include "GrRenderTarget.h"
|
||||
@ -131,7 +132,9 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) {
|
||||
0xffff);
|
||||
|
||||
pipelineBuilder->setStencil(kStencilPass);
|
||||
args.fTarget->drawPath(*pipelineBuilder, viewMatrix, args.fColor, p, p->getFillType());
|
||||
SkAutoTUnref<GrDrawPathBatchBase> batch(
|
||||
GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(), p));
|
||||
args.fTarget->drawPathBatch(*pipelineBuilder, batch);
|
||||
}
|
||||
|
||||
pipelineBuilder->stencil()->setDisabled();
|
||||
|
Loading…
Reference in New Issue
Block a user