skia2/tests/GrCCPRTest.cpp

310 lines
11 KiB
C++
Raw Normal View History

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkTypes.h"
#include "tests/Test.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkRect.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/mock/GrMockTypes.h"
#include "src/core/SkPathPriv.h"
#include "src/gpu/GrClip.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrPaint.h"
#include "src/gpu/GrPathRenderer.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrSurfaceDrawContext.h"
Reland "Move GrGpuResource GrSurface and GrTexture into src." This reverts commit f6ed96d1c23b79130ca7344c984b07ef9d94fb7b. Reason for revert: google3 change landed Original change's description: > Revert "Move GrGpuResource GrSurface and GrTexture into src." > > This reverts commit e5a06ce678aad7640411f99f70f220f82ad49908. > > Reason for revert: Need to make change in google3 first > > Original change's description: > > Move GrGpuResource GrSurface and GrTexture into src. > > > > Must land https://chromium-review.googlesource.com/c/chromium/src/+/2087980 > > before this can land. > > > > Bug: skia:7966 > > Change-Id: I60bbb1765bfbb2c96b2bc0c9826b6b9d57eb2a03 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275077 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com > > Change-Id: Id39e0a351e49a87209de88a6ad9fadb0219db72c > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:7966 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275216 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: I746ce739cb084cefc46f9dab24ef773e7c3cc621 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:7966 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275436 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-03-05 19:14:18 +00:00
#include "src/gpu/GrTexture.h"
#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
Reland "Rename GrShape to GrStyledShape" This reverts commit 73b86c1ade1c002cfa4da66c33c25514737e2416. Reason for revert: wasn't the problem, relanding Original change's description: > Revert "Rename GrShape to GrStyledShape" > > This reverts commit f3f08af010eebdb9c1501bdf1b3d8e715298b05f. > > Reason for revert: maybe this is breaking the ios perf bot; it is the first CL that caused the bot to fail, but I can't really say why this would break them. > > Original change's description: > > Rename GrShape to GrStyledShape > > > > Change-Id: Ic457e634b4b95356f5615cff3fce1ca7d7677c26 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/284036 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Commit-Queue: Michael Ludwig <michaelludwig@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,michaelludwig@google.com > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Change-Id: I2e5adbfc820811fbbde9cb57af28f86a7ba40bd9 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/284231 > Reviewed-by: Michael Ludwig <michaelludwig@google.com> > Commit-Queue: Michael Ludwig <michaelludwig@google.com> TBR=bsalomon@google.com,robertphillips@google.com,michaelludwig@google.com Change-Id: Ifdd52f8bacb5d66a7bf58efd328675c4c443ac8a No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/284376 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-04-17 20:21:37 +00:00
#include "src/gpu/geometry/GrStyledShape.h"
#include "tools/ToolUtils.h"
#include <cmath>
static constexpr int kCanvasSize = 100;
class CCPRClip : public GrClip {
public:
CCPRClip(GrCoverageCountingPathRenderer* ccpr, const SkPath& path) : fCCPR(ccpr), fPath(path) {}
private:
SkIRect getConservativeBounds() const final { return fPath.getBounds().roundOut(); }
Effect apply(GrRecordingContext* context, GrSurfaceDrawContext* rtc, GrAAType,
GrAppliedClip* out, SkRect* bounds) const override {
auto [success, fp] = fCCPR->makeClipProcessor(/*inputFP=*/nullptr,
rtc->getOpsTask()->uniqueID(), fPath,
SkIRect::MakeWH(rtc->width(), rtc->height()),
*context->priv().caps());
if (success) {
out->addCoverageFP(std::move(fp));
return Effect::kClipped;
} else {
return Effect::kClippedOut;
}
}
GrCoverageCountingPathRenderer* const fCCPR;
const SkPath fPath;
};
class CCPRPathDrawer {
public:
CCPRPathDrawer(sk_sp<GrDirectContext> dContext, skiatest::Reporter* reporter)
: fDContext(dContext)
, fCCPR(fDContext->priv().drawingManager()->getCoverageCountingPathRenderer())
, fRTC(GrSurfaceDrawContext::Make(
fDContext.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact,
{kCanvasSize, kCanvasSize}, SkSurfaceProps())) {
if (!fCCPR) {
ERRORF(reporter, "ccpr not enabled in GrDirectContext for ccpr tests");
}
if (!fRTC) {
ERRORF(reporter, "failed to create GrSurfaceDrawContext for ccpr tests");
}
}
GrDirectContext* dContext() const { return fDContext.get(); }
GrCoverageCountingPathRenderer* ccpr() const { return fCCPR; }
bool valid() const { return fCCPR && fRTC; }
Reland "Simplify GrRTC::clean APIs" This reverts commit 4730f29993783fc9e96e45098d7e708fe08f1f26. Reason for revert: Fix WIP Original change's description: > Revert "Simplify GrRTC::clean APIs" > > This reverts commit 6cbd7c2e57af9c499f7e99feb215b890fdd3a10a. > > Reason for revert: mac/generated files failures > > Original change's description: > > Simplify GrRTC::clean APIs > > > > The CanClearFullscreen enum type is removed. Most usages of clear() had > > kYes because a null scissor rect was provided, or had kNo because the > > scissor was really critical to the behavior. A few places did provide a > > scissor and kYes (e.g. for initializing the target). > > > > To simplify this, the public GrRTC has two variants of clear(). One with > > only a color (for fullscreen clears), and one with a rect for partial > > clears. The private API also adds a clearAtLeast() function that replaces > > the several cases where we'd have a scissor but could expand to fullscreen. > > > > I find the current control flow in internalClear() to be hard to > > follow (albeit I was the one to make it that way...), but later CLs > > will improve it. > > > > Bug: skia:10205 > > Change-Id: I87cf8d688c58fbe58ee854fbc4ffe22482d969c6 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290256 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Michael Ludwig <michaelludwig@google.com> > > TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com > > Change-Id: I7131df6f5323f4f9c120cbcfd9bc57e627e2eb65 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10205 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291842 > Reviewed-by: Michael Ludwig <michaelludwig@google.com> > Commit-Queue: Michael Ludwig <michaelludwig@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:10205 Change-Id: Id5db153d7c2500279cca8478818b66f67a53e143 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291844 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-05-26 20:57:38 +00:00
void clear() const { fRTC->clear(SK_PMColor4fTRANSPARENT); }
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
void destroyGrContext() {
SkASSERT(fDContext->unique());
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
fRTC.reset();
fCCPR = nullptr;
fDContext.reset();
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
}
void clipFullscreenRect(SkPath clipPath, const SkMatrix& matrix = SkMatrix::I()) const {
SkASSERT(this->valid());
GrPaint paint;
paint.setColor4f({0, 1, 0, 1});
CCPRClip clip(fCCPR, clipPath);
Reland "GrClips provided as pointers to GrRTC" This reverts commit 074414fed53efcab7f33b06454958707419e37d8. Reason for revert: updated to guard against nullptr before calling quickContains(rrect). Original change's description: > Revert "GrClips provided as pointers to GrRTC" > > This reverts commit 226b689471a0fbb7400bc166032458278957541b. > > Reason for revert: Breaks Android roller > > Original change's description: > > GrClips provided as pointers to GrRTC > > > > A null clip represents no high-level clipping is necessary (the implicit > > clip to the render target's logical dimensions is fine). > > > > This also removes GrNoClip and GrFixedClip::Disabled() since they are > > replaced with just nullptr. > > > > By allowing nullptr to represent no intended clipping, it makes it easier > > to require GrClip and GrAppliedClip objects to know about the dimensions > > of the device. If we required a non-null clip object to represent no > > clipping, we'd have to have an instance for each device based on its > > size and that just became cumbersome. > > > > Bug: skia:10205 > > Change-Id: Ie30cc71820b92d99356d393a4c98c8677082e761 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290539 > > Commit-Queue: Michael Ludwig <michaelludwig@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com > > Change-Id: I42c4828bcf016ee3d30d5c20b771be96e125817b > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10205 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292856 > Reviewed-by: Weston Tracey <westont@google.com> > Commit-Queue: Weston Tracey <westont@google.com> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com,westont@google.com # Not skipping CQ checks because this is a reland. Bug: skia:10205 Change-Id: I5715a4de3b7c8847b73020dc4937d3816d879803 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292876 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-05-29 13:54:07 +00:00
fRTC->drawRect(&clip, std::move(paint), GrAA::kYes, SkMatrix::I(),
SkRect::MakeIWH(kCanvasSize, kCanvasSize));
}
void flush() const {
SkASSERT(this->valid());
fDContext->flushAndSubmit();
}
private:
sk_sp<GrDirectContext> fDContext;
GrCoverageCountingPathRenderer* fCCPR;
std::unique_ptr<GrSurfaceDrawContext> fRTC;
};
class CCPRTest {
public:
void run(skiatest::Reporter* reporter) {
GrMockOptions mockOptions;
mockOptions.fDrawInstancedSupport = true;
mockOptions.fHalfFloatVertexAttributeSupport = true;
mockOptions.fMapBufferFlags = GrCaps::kCanMap_MapFlag;
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability =
GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true;
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fRenderability =
GrMockOptions::ConfigOptions::Renderability::kMSAA;
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true;
mockOptions.fGeometryShaderSupport = true;
mockOptions.fIntegerSupport = true;
mockOptions.fFlatInterpolationSupport = true;
GrContextOptions ctxOptions;
ctxOptions.fAllowPathMaskCaching = false;
ctxOptions.fGpuPathRenderers = GpuPathRenderers::kCoverageCounting;
this->customizeOptions(&mockOptions, &ctxOptions);
sk_sp<GrDirectContext> mockContext = GrDirectContext::MakeMock(&mockOptions, ctxOptions);
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
if (!mockContext) {
ERRORF(reporter, "could not create mock context");
return;
}
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
if (!mockContext->unique()) {
ERRORF(reporter, "mock context is not unique");
return;
}
CCPRPathDrawer ccpr(std::exchange(mockContext, nullptr), reporter);
if (!ccpr.valid()) {
return;
}
fPath.moveTo(0, 0);
fPath.cubicTo(50, 50, 0, 50, 50, 0);
this->onRun(reporter, ccpr);
}
virtual ~CCPRTest() {}
protected:
virtual void customizeOptions(GrMockOptions*, GrContextOptions*) {}
virtual void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) = 0;
SkPath fPath;
};
#define DEF_CCPR_TEST(name) \
DEF_GPUTEST(name, reporter, /* options */) { \
name test; \
test.run(reporter); \
}
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
class CCPR_cleanup : public CCPRTest {
protected:
void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override {
REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath));
// Ensure paths get unreffed when we delete the context without flushing.
for (int i = 0; i < 10; ++i) {
ccpr.clipFullscreenRect(fPath);
ccpr.clipFullscreenRect(fPath);
}
REPORTER_ASSERT(reporter, !SkPathPriv::TestingOnly_unique(fPath));
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
ccpr.destroyGrContext();
REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath));
}
};
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
DEF_CCPR_TEST(CCPR_cleanup)
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
class CCPR_cleanupWithTexAllocFail : public CCPR_cleanup {
void customizeOptions(GrMockOptions* mockOptions, GrContextOptions*) override {
mockOptions->fFailTextureAllocations = true;
}
void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override {
((GrRecordingContext*)ccpr.dContext())->priv().incrSuppressWarningMessages();
this->CCPR_cleanup::onRun(reporter, ccpr);
}
};
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
DEF_CCPR_TEST(CCPR_cleanupWithTexAllocFail)
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
class CCPR_parseEmptyPath : public CCPRTest {
void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override {
REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath));
// Make a path large enough that ccpr chooses to crop it by the RT bounds, and ends up with
// an empty path.
SkPath largeOutsidePath = SkPath::Polygon({
{-1e30f, -1e30f},
{-1e30f, +1e30f},
{-1e10f, +1e30f},
}, false);
ccpr.clipFullscreenRect(largeOutsidePath);
// Normally an empty path is culled before reaching ccpr, however we use a back door for
// testing so this path will make it.
SkPath emptyPath;
SkASSERT(emptyPath.isEmpty());
ccpr.clipFullscreenRect(emptyPath);
// This is the test. It will exercise various internal asserts and verify we do not crash.
ccpr.flush();
// Now try again with clips.
ccpr.clipFullscreenRect(largeOutsidePath);
ccpr.clipFullscreenRect(emptyPath);
ccpr.flush();
// ... and both.
ccpr.clipFullscreenRect(largeOutsidePath);
ccpr.clipFullscreenRect(largeOutsidePath);
ccpr.clipFullscreenRect(emptyPath);
ccpr.clipFullscreenRect(emptyPath);
ccpr.flush();
}
};
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
DEF_CCPR_TEST(CCPR_parseEmptyPath)
class CCPRRenderingTest {
public:
void run(skiatest::Reporter* reporter, GrDirectContext* dContext) const {
if (dContext->priv().drawingManager()->getCoverageCountingPathRenderer()) {
CCPRPathDrawer drawer(sk_ref_sp(dContext), reporter);
if (!drawer.valid()) {
return;
}
this->onRun(reporter, drawer);
}
}
virtual ~CCPRRenderingTest() {}
protected:
virtual void onRun(skiatest::Reporter* reporter, const CCPRPathDrawer& ccpr) const = 0;
};
#define DEF_CCPR_RENDERING_TEST(name) \
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(name, reporter, ctxInfo) { \
name test; \
test.run(reporter, ctxInfo.directContext()); \
}
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
class CCPR_busyPath : public CCPRRenderingTest {
void onRun(skiatest::Reporter* reporter, const CCPRPathDrawer& ccpr) const override {
static constexpr int kNumBusyVerbs = 1 << 17;
ccpr.clear();
SkPathBuilder busyPath;
busyPath.moveTo(0, 0); // top left
busyPath.lineTo(kCanvasSize, kCanvasSize); // bottom right
for (int i = 2; i < kNumBusyVerbs; ++i) {
float offset = i * ((float)kCanvasSize / kNumBusyVerbs);
busyPath.lineTo(kCanvasSize - offset, kCanvasSize + offset); // offscreen
}
ccpr.clipFullscreenRect(busyPath.detach());
ccpr.flush(); // If this doesn't crash, the test passed.
// If it does, maybe fiddle with fMaxInstancesPerDrawArraysWithoutCrashing in
// your platform's GrGLCaps.
}
};
Reland "ccpr: Rework the path cache to support sporadic flushing" This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b Original change's description: > ccpr: Rework the path cache to support sporadic flushing > > Removes the notion of a stashed atlas that we store from the previous > flush. Now we just cache every atlas we ever render. Cached atlases > can either be 16-bit or 8-bit. > > The "reuse" and "animation" cases should both behave exactly the same > as before: Where before we would copy from the stashed atlas to 8-bit > atlases, we now copy from a cached 16-bit atlas and then invalidate > it. Where before we would recycle the stashed atlas's backing texture > object, we now recycle this same texture object from an invalidated > 16-bit cached atlas. > > The main difference is that cases like tiled rendering now work. If > you draw your whole scene in one flush, you still get one big 16-bit > cached atlas, just like the "stashed atlas" implementation. But if you > draw your scene in tiles, you now get lots of little cached 16-bit > atlases, which can be reused and eventually copied to 8-bit atlases. > > Bug: skia:8462 > Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18 > Reviewed-on: https://skia-review.googlesource.com/c/179991 > Commit-Queue: Chris Dalton <csmartdalton@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8462 Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391 Reviewed-on: https://skia-review.googlesource.com/c/181450 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
2019-01-07 05:51:00 +00:00
DEF_CCPR_RENDERING_TEST(CCPR_busyPath)
// https://bugs.chromium.org/p/chromium/issues/detail?id=1102117
class CCPR_evictCacheEntryForPendingDrawOp : public CCPRRenderingTest {
void onRun(skiatest::Reporter* reporter, const CCPRPathDrawer& ccpr) const override {
static constexpr SkRect kRect = SkRect::MakeWH(50, 50);
ccpr.clear();
// make sure path is cached.
for (int i = 0; i < 2; i++) {
SkPath path;
path.addRect(kRect);
ccpr.clipFullscreenRect(path);
ccpr.flush();
}
// make enough cached draws to make DoCopies happen.
for (int i = 0; i <= GrCoverageCountingPathRenderer::kDoCopiesThreshold; i++) {
SkPath path;
path.addRect(kRect);
ccpr.clipFullscreenRect(path);
}
// now draw the path in an incompatible matrix. Previous draw's cached atlas should
// not be invalidated. otherwise, this flush would render more paths than allocated for.
auto m = SkMatrix::Translate(0.1f, 0.1f);
SkPath path;
path.addRect(kRect);
ccpr.clipFullscreenRect(path, m);
ccpr.flush();
// if this test does not crash, it is passed.
}
};
DEF_CCPR_RENDERING_TEST(CCPR_evictCacheEntryForPendingDrawOp)