Reland "Don't simplify strokes that could have been tessellated"

This is a reland of 3f95357c4c

Original change's description:
> Don't simplify strokes that could have been tessellated
>
> Bug: chromium:1172543
> Change-Id: I3be0d822ca0a338118059c7aa37b2fd7822869b8
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/362936
> Commit-Queue: Chris Dalton <csmartdalton@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>

Bug: chromium:1172543
Change-Id: I514211c3d46e62d3bacb0beb8fc9ea6959144e4e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367022
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2021-02-05 14:56:21 -07:00 committed by Skia Commit-Bot
parent 447f33105a
commit e6ae4761c1
5 changed files with 60 additions and 24 deletions

View File

@ -959,6 +959,14 @@ GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRendere
return fPathRendererChain->getCoverageCountingPathRenderer();
}
GrPathRenderer* GrDrawingManager::getTessellationPathRenderer() {
if (!fPathRendererChain) {
fPathRendererChain = std::make_unique<GrPathRendererChain>(fContext,
fOptionsForPathRendererChain);
}
return fPathRendererChain->getTessellationPathRenderer();
}
void GrDrawingManager::flushIfNecessary() {
auto direct = fContext->asDirectContext();
if (!direct) {

View File

@ -108,6 +108,10 @@ public:
// supported and turned on.
GrCoverageCountingPathRenderer* getCoverageCountingPathRenderer();
// Returns a direct pointer to the tessellation path renderer, or null if it is not supported
// and turned on.
GrPathRenderer* getTessellationPathRenderer();
void flushIfNecessary();
static bool ProgramUnitTest(GrDirectContext*, int maxStages, int maxLevels);

View File

@ -72,6 +72,7 @@ GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Opti
if (options.fGpuPathRenderers & GpuPathRenderers::kTessellation) {
if (GrTessellationPathRenderer::IsSupported(caps)) {
auto tess = sk_make_sp<GrTessellationPathRenderer>(context);
fTessellationPathRenderer = tess.get();
context->priv().addOnFlushCallbackObject(tess.get());
fChain.push_back(std::move(tess));
}

View File

@ -53,12 +53,19 @@ public:
return fCoverageCountingPathRenderer;
}
/** Returns a direct pointer to the tessellation path renderer, or null if it is not in the
chain. */
GrPathRenderer* getTessellationPathRenderer() {
return fTessellationPathRenderer;
}
private:
enum {
kPreAllocCount = 8,
};
SkSTArray<kPreAllocCount, sk_sp<GrPathRenderer>> fChain;
GrCoverageCountingPathRenderer* fCoverageCountingPathRenderer = nullptr;
GrPathRenderer* fTessellationPathRenderer = nullptr;
};
#endif

View File

@ -1787,19 +1787,6 @@ void GrSurfaceDrawContext::drawShapeUsingPathRenderer(const GrClip* clip,
return;
}
// Always simplify the stroke for now. In the future we will give the tessellator a chance to
// claim strokes before trying to simplify them.
shape.simplifyStroke();
if (attemptDrawSimple || shape.simplified()) {
// Usually we enter drawShapeUsingPathRenderer() because the shape+style was too
// complex for dedicated draw ops. However, if GrStyledShape was able to reduce something
// we ought to try again instead of going right to path rendering.
if (this->drawSimpleShape(clip, &paint, aa, viewMatrix, shape)) {
return;
}
}
SkIRect clipConservativeBounds = get_clip_bounds(this, clip);
GrAAType aaType = this->chooseAAType(aa);
@ -1813,17 +1800,44 @@ void GrSurfaceDrawContext::drawShapeUsingPathRenderer(const GrClip* clip,
canDrawArgs.fClipConservativeBounds = &clipConservativeBounds;
canDrawArgs.fTargetIsWrappedVkSecondaryCB = this->wrapsVkSecondaryCB();
canDrawArgs.fHasUserStencilSettings = false;
GrPathRenderer* pr;
static constexpr GrPathRendererChain::DrawType kType = GrPathRendererChain::DrawType::kColor;
if (shape.isEmpty() && !shape.inverseFilled()) {
return;
}
canDrawArgs.fAAType = aaType;
// Try a 1st time without applying any of the style to the geometry (and barring sw)
pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType);
constexpr static bool kDisallowSWPathRenderer = false;
constexpr static bool kAllowSWPathRenderer = true;
using DrawType = GrPathRendererChain::DrawType;
GrPathRenderer* pr = nullptr;
if (!shape.style().strokeRec().isFillStyle() && !shape.isEmpty()) {
// Give the tessellation path renderer a chance to claim this stroke before we simplify it.
GrPathRenderer* tess = this->drawingManager()->getTessellationPathRenderer();
if (tess && tess->canDrawPath(canDrawArgs) == GrPathRenderer::CanDrawPath::kYes) {
pr = tess;
}
}
if (!pr) {
// The shape isn't a stroke that can be drawn directly. Simplify if possible.
shape.simplifyStroke();
if (shape.isEmpty() && !shape.inverseFilled()) {
return;
}
if (attemptDrawSimple || shape.simplified()) {
// Usually we enter drawShapeUsingPathRenderer() because the shape+style was too complex
// for dedicated draw ops. However, if GrStyledShape was able to reduce something we
// ought to try again instead of going right to path rendering.
if (this->drawSimpleShape(clip, &paint, aa, viewMatrix, shape)) {
return;
}
}
// Try a 1st time without applying any of the style to the geometry (and barring sw)
pr = this->drawingManager()->getPathRenderer(canDrawArgs, kDisallowSWPathRenderer,
DrawType::kColor);
}
SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix);
if (!pr && shape.style().pathEffect()) {
@ -1832,7 +1846,8 @@ void GrSurfaceDrawContext::drawShapeUsingPathRenderer(const GrClip* clip,
if (shape.isEmpty()) {
return;
}
pr = this->drawingManager()->getPathRenderer(canDrawArgs, false, kType);
pr = this->drawingManager()->getPathRenderer(canDrawArgs, kDisallowSWPathRenderer,
DrawType::kColor);
}
if (!pr) {
if (shape.style().applies()) {
@ -1841,7 +1856,8 @@ void GrSurfaceDrawContext::drawShapeUsingPathRenderer(const GrClip* clip,
return;
}
// This time, allow SW renderer
pr = this->drawingManager()->getPathRenderer(canDrawArgs, true, kType);
pr = this->drawingManager()->getPathRenderer(canDrawArgs, kAllowSWPathRenderer,
DrawType::kColor);
} else {
pr = this->drawingManager()->getSoftwarePathRenderer();
#if GR_PATH_RENDERER_SPEW