ccpr: Preserve fill rules for cached paths

Fixes a bug where even-odd fill rule was not being preserved on paths
that were reused from a stashed fp16 coverage count atlas.

Bug: skia:8782
Change-Id: I6698498a6f4c8df8eff10b19beb80e49663a577c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218047
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2019-06-05 11:54:39 -06:00 committed by Skia Commit-Bot
parent 928b2997b3
commit 5b5403e75b
6 changed files with 156 additions and 9 deletions

View File

@ -152,7 +152,7 @@ namespace skiagm {
bool getControls(SkMetaData* controls) { return this->onGetControls(controls); }
void setControls(const SkMetaData& controls) { this->onSetControls(controls); }
virtual void modifyGrContextOptions(GrContextOptions* options);
virtual void modifyGrContextOptions(GrContextOptions*);
protected:
virtual void onOnceBeforeDraw();

148
gm/preservefillrule.cpp Normal file
View File

@ -0,0 +1,148 @@
/*
* Copyright 2019 Google LLC.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkPath.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrContextOptions.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/ccpr/GrCCPathCache.h"
#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
#include "tools/ToolUtils.h"
namespace skiagm {
#define ERR_MSG_ASSERT(COND) \
do { \
if (!(COND)) { \
errorMsg->printf("preservefillrule.cpp(%i): assert(%s)", \
__LINE__, #COND); \
return DrawResult::kFail; \
} \
} while (false)
/**
* This test ensures that the ccpr path cache preserves fill rules properly, both in the case where
* we copy paths into a8 literal coverage atlases, as well as in the case where we just reuse a
* stashed fp16 coverage count atlas.
*/
class PreserveFillRuleGM : public GpuGM {
public:
// fStarSize affects whether ccpr copies the paths to an a8 literal coverage atlas, or just
// leaves them stashed in an fp16 coverage count atlas. The threshold for copying to a8 is
// currently 256x256 total pixels copied. If this ever changes, there is code in onDraw that
// will detect the unexpected behavior and draw a failure message.
PreserveFillRuleGM(bool literalCoverageAtlas)
: fLiteralCoverageAtlas(literalCoverageAtlas)
, fStarSize((fLiteralCoverageAtlas) ? 200 : 20) {
}
private:
SkString onShortName() override {
SkString name("preservefillrule");
name += (fLiteralCoverageAtlas) ? "_big" : "_little";
return name;
}
SkISize onISize() override { return SkISize::Make(fStarSize * 2, fStarSize * 2); }
void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
ctxOptions->fGpuPathRenderers = GpuPathRenderers::kCoverageCounting;
ctxOptions->fAllowPathMaskCaching = true;
}
DrawResult onDraw(GrContext* ctx, GrRenderTargetContext* rtc, SkCanvas* canvas,
SkString* errorMsg) override {
using CoverageType = GrCCAtlas::CoverageType;
auto* ccpr = ctx->priv().drawingManager()->getCoverageCountingPathRenderer();
if (!ccpr) {
errorMsg->set("ccpr only");
return DrawResult::kSkip;
}
auto pathCache = ccpr->testingOnly_getPathCache();
if (!pathCache) {
errorMsg->set("ccpr is not in caching mode. "
"Are you using viewer? Launch with \"--cachePathMasks true\".");
return DrawResult::kFail;
}
auto starRect = SkRect::MakeWH(fStarSize, fStarSize);
SkPath star7_winding = ToolUtils::make_star(starRect, 7);
star7_winding.setFillType(SkPath::kWinding_FillType);
SkPath star7_evenOdd = star7_winding;
star7_evenOdd.transform(SkMatrix::MakeTrans(0, fStarSize));
star7_evenOdd.setFillType(SkPath::kEvenOdd_FillType);
SkPath star5_winding = ToolUtils::make_star(starRect, 5);
star5_winding.transform(SkMatrix::MakeTrans(fStarSize, 0));
star5_winding.setFillType(SkPath::kWinding_FillType);
SkPath star5_evenOdd = star5_winding;
star5_evenOdd.transform(SkMatrix::MakeTrans(0, fStarSize));
star5_evenOdd.setFillType(SkPath::kEvenOdd_FillType);
SkPaint paint;
paint.setColor(SK_ColorGREEN);
paint.setAntiAlias(true);
for (int i = 0; i < 3; ++i) {
canvas->clear(SK_ColorWHITE);
canvas->drawPath(star7_winding, paint);
canvas->drawPath(star7_evenOdd, paint);
canvas->drawPath(star5_winding, paint);
canvas->drawPath(star5_evenOdd, paint);
rtc->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
// Ensure the path cache is behaving in such a way that we are actually testing what we
// think we are.
int numCachedPaths = 0;
for (GrCCPathCacheEntry* entry : pathCache->testingOnly_getLRU()) {
if (0 == i) {
// We don't cache an atlas on the first hit.
ERR_MSG_ASSERT(!entry->cachedAtlas());
} else {
// The stars should be cached in an atlas now.
ERR_MSG_ASSERT(entry->cachedAtlas());
CoverageType atlasCoverageType = entry->cachedAtlas()->coverageType();
if (i < 2) {
// We never copy to an a8 atlas before the second hit.
ERR_MSG_ASSERT(CoverageType::kFP16_CoverageCount == atlasCoverageType);
} else if (fLiteralCoverageAtlas) {
// Verify fStarSize is large enough that the paths got copied to an a8
// atlas.
ERR_MSG_ASSERT(CoverageType::kA8_LiteralCoverage == atlasCoverageType);
} else {
// Verify fStarSize is small enough that the paths did *NOT* get copied to
// an a8 atlas.
ERR_MSG_ASSERT(CoverageType::kFP16_CoverageCount == atlasCoverageType);
}
}
++numCachedPaths;
}
// Verify all 4 paths are tracked by the path cache.
ERR_MSG_ASSERT(4 == numCachedPaths);
}
return DrawResult::kOk;
}
private:
const bool fLiteralCoverageAtlas;
const int fStarSize;
};
DEF_GM( return new PreserveFillRuleGM(true); )
DEF_GM( return new PreserveFillRuleGM(false); )
}

View File

@ -279,6 +279,7 @@ gm_sources = [
"$_gm/poly2poly.cpp",
"$_gm/polygonoffset.cpp",
"$_gm/polygons.cpp",
"$_gm/preservefillrule.cpp",
"$_gm/postercircle.cpp",
"$_gm/quadpaths.cpp",
"$_gm/radial_gradient_precision.cpp",

View File

@ -358,8 +358,8 @@ void GrCCDrawPathsOp::SingleDraw::setupResources(
#endif
op->recordInstance(fCacheEntry->cachedAtlas()->getOnFlushProxy(),
resources->nextPathInstanceIdx());
resources->appendDrawPathInstance().set(*fCacheEntry, fCachedMaskShift,
SkPMColor4f_toFP16(fColor));
resources->appendDrawPathInstance().set(
*fCacheEntry, fCachedMaskShift, SkPMColor4f_toFP16(fColor), doEvenOddFill);
return;
}
}

View File

@ -166,8 +166,8 @@ void GrCCPathProcessor::Impl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// find an octagon that circumscribes the (bloated) path.
GrGLSLVertexBuilder* v = args.fVertBuilder;
// Are we clockwise (positive wind, nonzero fill), or counter-clockwise (negative wind,
// even/odd fill)?
// Are we clockwise? (Positive wind => nonzero fill rule.)
// Or counter-clockwise? (negative wind => even/odd fill rule.)
v->codeAppendf("float wind = sign(devbounds.z - devbounds.x);");
// Find our reference corner from the device-space bounding box.

View File

@ -44,10 +44,8 @@ public:
SkIVector fDevToAtlasOffset; // Translation from device space to location in atlas.
uint64_t fColor; // Color always stored as 4 x fp16
void set(const GrOctoBounds&, const SkIVector& devToAtlasOffset, uint64_t,
DoEvenOddFill = DoEvenOddFill::kNo);
void set(const GrCCPathCacheEntry&, const SkIVector& shift, uint64_t,
DoEvenOddFill = DoEvenOddFill::kNo);
void set(const GrOctoBounds&, const SkIVector& devToAtlasOffset, uint64_t, DoEvenOddFill);
void set(const GrCCPathCacheEntry&, const SkIVector& shift, uint64_t, DoEvenOddFill);
};
GR_STATIC_ASSERT(4 * 12 == sizeof(Instance));