2019-06-05 17:54:39 +00:00
|
|
|
/*
|
|
|
|
* 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/GrContextOptions.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-06-05 17:54:39 +00:00
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
2020-06-29 19:36:12 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-06-05 17:54:39 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2020-10-14 15:46:51 +00:00
|
|
|
DrawResult onDraw(GrRecordingContext* rContext, GrRenderTargetContext* rtc, SkCanvas* canvas,
|
2019-06-05 17:54:39 +00:00
|
|
|
SkString* errorMsg) override {
|
|
|
|
using CoverageType = GrCCAtlas::CoverageType;
|
|
|
|
|
2019-07-19 20:20:53 +00:00
|
|
|
if (rtc->numSamples() > 1) {
|
|
|
|
errorMsg->set("ccpr is currently only used for coverage AA");
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2020-10-14 15:46:51 +00:00
|
|
|
auto* ccpr = rContext->priv().drawingManager()->getCoverageCountingPathRenderer();
|
2019-06-05 17:54:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-14 15:46:51 +00:00
|
|
|
auto dContext = GrAsDirectContext(rContext);
|
|
|
|
|
2019-06-05 17:54:39 +00:00
|
|
|
auto starRect = SkRect::MakeWH(fStarSize, fStarSize);
|
|
|
|
SkPath star7_winding = ToolUtils::make_star(starRect, 7);
|
2019-11-26 17:17:17 +00:00
|
|
|
star7_winding.setFillType(SkPathFillType::kWinding);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
SkPath star7_evenOdd = star7_winding;
|
2020-05-21 16:11:27 +00:00
|
|
|
star7_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
|
2019-11-26 17:17:17 +00:00
|
|
|
star7_evenOdd.setFillType(SkPathFillType::kEvenOdd);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
SkPath star5_winding = ToolUtils::make_star(starRect, 5);
|
2020-05-21 16:11:27 +00:00
|
|
|
star5_winding.transform(SkMatrix::Translate(fStarSize, 0));
|
2019-11-26 17:17:17 +00:00
|
|
|
star5_winding.setFillType(SkPathFillType::kWinding);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
SkPath star5_evenOdd = star5_winding;
|
2020-05-21 16:11:27 +00:00
|
|
|
star5_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
|
2019-11-26 17:17:17 +00:00
|
|
|
star5_evenOdd.setFillType(SkPathFillType::kEvenOdd);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
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);
|
2020-06-11 15:51:06 +00:00
|
|
|
rtc->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
// 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.
|
2019-07-19 20:20:53 +00:00
|
|
|
ERR_MSG_ASSERT(ccpr->coverageType() == atlasCoverageType);
|
2019-06-05 17:54:39 +00:00
|
|
|
} 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.
|
2019-07-19 20:20:53 +00:00
|
|
|
ERR_MSG_ASSERT(ccpr->coverageType() == atlasCoverageType);
|
2019-06-05 17:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++numCachedPaths;
|
|
|
|
}
|
2020-10-14 15:46:51 +00:00
|
|
|
|
|
|
|
if (dContext) {
|
|
|
|
// Verify all 4 paths are tracked by the path cache.
|
|
|
|
ERR_MSG_ASSERT(4 == numCachedPaths);
|
|
|
|
}
|
2019-06-05 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const bool fLiteralCoverageAtlas;
|
|
|
|
const int fStarSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return new PreserveFillRuleGM(true); )
|
|
|
|
DEF_GM( return new PreserveFillRuleGM(false); )
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|