Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTypes.h" |
| 9 | #include "tests/Test.h" |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkMatrix.h" |
| 12 | #include "include/core/SkRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/gpu/mock/GrMockTypes.h" |
| 14 | #include "include/private/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/core/SkPathPriv.h" |
| 16 | #include "src/gpu/GrClip.h" |
| 17 | #include "src/gpu/GrContextPriv.h" |
| 18 | #include "src/gpu/GrDrawingManager.h" |
| 19 | #include "src/gpu/GrPaint.h" |
| 20 | #include "src/gpu/GrPathRenderer.h" |
| 21 | #include "src/gpu/GrRecordingContextPriv.h" |
| 22 | #include "src/gpu/GrRenderTargetContext.h" |
| 23 | #include "src/gpu/GrRenderTargetContextPriv.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 24 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/ccpr/GrCCPathCache.h" |
| 26 | #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 27 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "tools/ToolUtils.h" |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 29 | |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 30 | #include <cmath> |
| 31 | |
| 32 | static constexpr int kCanvasSize = 100; |
| 33 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 34 | enum class DoCoverageCount { kNo = false, kYes }; |
| 35 | enum class DoStroke { kNo = false, kYes }; |
| 36 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 37 | class CCPRClip : public GrClip { |
| 38 | public: |
| 39 | CCPRClip(GrCoverageCountingPathRenderer* ccpr, const SkPath& path) : fCCPR(ccpr), fPath(path) {} |
| 40 | |
| 41 | private: |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 42 | bool apply(GrRecordingContext* context, GrRenderTargetContext* rtc, bool useHWAA, |
| 43 | bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const override { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 44 | out->addCoverageFP(fCCPR->makeClipProcessor(rtc->priv().testingOnly_getOpsTaskID(), fPath, |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 45 | SkIRect::MakeWH(rtc->width(), rtc->height()), |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 46 | *context->priv().caps())); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 47 | return true; |
| 48 | } |
| 49 | bool quickContains(const SkRect&) const final { return false; } |
| 50 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; } |
Michael Ludwig | c002d56 | 2020-05-13 14:17:57 -0400 | [diff] [blame] | 51 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 52 | GrCoverageCountingPathRenderer* const fCCPR; |
| 53 | const SkPath fPath; |
| 54 | }; |
| 55 | |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 56 | class CCPRPathDrawer { |
| 57 | public: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 58 | CCPRPathDrawer(sk_sp<GrContext> ctx, skiatest::Reporter* reporter, DoStroke doStroke) |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 59 | : fCtx(ctx) |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 60 | , fCCPR(fCtx->priv().drawingManager()->getCoverageCountingPathRenderer()) |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 61 | , fRTC(GrRenderTargetContext::Make( |
| 62 | fCtx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, |
| 63 | {kCanvasSize, kCanvasSize})) |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 64 | , fDoStroke(DoStroke::kYes == doStroke) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 65 | if (!fCCPR) { |
| 66 | ERRORF(reporter, "ccpr not enabled in GrContext for ccpr tests"); |
| 67 | } |
| 68 | if (!fRTC) { |
| 69 | ERRORF(reporter, "failed to create GrRenderTargetContext for ccpr tests"); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 73 | GrContext* ctx() const { return fCtx.get(); } |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 74 | GrCoverageCountingPathRenderer* ccpr() const { return fCCPR; } |
| 75 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 76 | bool valid() const { return fCCPR && fRTC; } |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 77 | void clear() const { fRTC->clear(SK_PMColor4fTRANSPARENT); } |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 78 | void destroyGrContext() { |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 79 | SkASSERT(fCtx->unique()); |
| 80 | fRTC.reset(); |
| 81 | fCCPR = nullptr; |
| 82 | fCtx.reset(); |
| 83 | } |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 84 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 85 | void drawPath(const SkPath& path, const SkMatrix& matrix = SkMatrix::I()) const { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 86 | SkASSERT(this->valid()); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 87 | |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 88 | GrPaint paint; |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 89 | paint.setColor4f({ 0, 1, 0, 1 }); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 90 | |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 91 | GrNoClip noClip; |
| 92 | SkIRect clipBounds = SkIRect::MakeWH(kCanvasSize, kCanvasSize); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 93 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 94 | GrStyledShape shape; |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 95 | if (!fDoStroke) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 96 | shape = GrStyledShape(path); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 97 | } else { |
| 98 | // Use hairlines for now, since they are the only stroke type that doesn't require a |
| 99 | // rigid-body transform. The CCPR stroke code makes no distinction between hairlines |
| 100 | // and regular strokes other than how it decides the device-space stroke width. |
| 101 | SkStrokeRec stroke(SkStrokeRec::kHairline_InitStyle); |
| 102 | stroke.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kMiter_Join, 4); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 103 | shape = GrStyledShape(path, GrStyle(stroke, nullptr)); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 104 | } |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 105 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 106 | fCCPR->testingOnly_drawPathDirectly({ |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 107 | fCtx.get(), std::move(paint), &GrUserStencilSettings::kUnused, fRTC.get(), &noClip, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 108 | &clipBounds, &matrix, &shape, GrAAType::kCoverage, false}); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 109 | } |
| 110 | |
Brian Osman | cb3d087 | 2018-10-16 15:19:28 -0400 | [diff] [blame] | 111 | void clipFullscreenRect(SkPath clipPath, SkPMColor4f color = { 0, 1, 0, 1 }) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 112 | SkASSERT(this->valid()); |
| 113 | |
| 114 | GrPaint paint; |
| 115 | paint.setColor4f(color); |
| 116 | |
| 117 | fRTC->drawRect(CCPRClip(fCCPR, clipPath), std::move(paint), GrAA::kYes, SkMatrix::I(), |
| 118 | SkRect::MakeIWH(kCanvasSize, kCanvasSize)); |
| 119 | } |
| 120 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 121 | void flush() const { |
| 122 | SkASSERT(this->valid()); |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 123 | fCtx->flushAndSubmit(); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | private: |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 127 | sk_sp<GrContext> fCtx; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 128 | GrCoverageCountingPathRenderer* fCCPR; |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 129 | std::unique_ptr<GrRenderTargetContext> fRTC; |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 130 | const bool fDoStroke; |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 131 | }; |
| 132 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 133 | class CCPRTest { |
| 134 | public: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 135 | void run(skiatest::Reporter* reporter, DoCoverageCount doCoverageCount, DoStroke doStroke) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 136 | GrMockOptions mockOptions; |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 137 | mockOptions.fDrawInstancedSupport = true; |
Brian Osman | c6444d2 | 2019-01-09 16:30:12 -0500 | [diff] [blame] | 138 | mockOptions.fHalfFloatVertexAttributeSupport = true; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 139 | mockOptions.fMapBufferFlags = GrCaps::kCanMap_MapFlag; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 140 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability = |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 141 | GrMockOptions::ConfigOptions::Renderability::kNonMSAA; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 142 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true; |
| 143 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fRenderability = |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 144 | GrMockOptions::ConfigOptions::Renderability::kMSAA; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 145 | mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 146 | mockOptions.fGeometryShaderSupport = true; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 147 | mockOptions.fIntegerSupport = true; |
| 148 | mockOptions.fFlatInterpolationSupport = true; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 149 | |
| 150 | GrContextOptions ctxOptions; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 151 | ctxOptions.fDisableCoverageCountingPaths = (DoCoverageCount::kNo == doCoverageCount); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 152 | ctxOptions.fAllowPathMaskCaching = false; |
| 153 | ctxOptions.fGpuPathRenderers = GpuPathRenderers::kCoverageCounting; |
| 154 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 155 | this->customizeOptions(&mockOptions, &ctxOptions); |
| 156 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 157 | sk_sp<GrContext> mockContext = GrContext::MakeMock(&mockOptions, ctxOptions); |
| 158 | if (!mockContext) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 159 | ERRORF(reporter, "could not create mock context"); |
| 160 | return; |
| 161 | } |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 162 | if (!mockContext->unique()) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 163 | ERRORF(reporter, "mock context is not unique"); |
| 164 | return; |
| 165 | } |
| 166 | |
Adlai Holler | 5ba50af | 2020-04-29 21:11:14 -0400 | [diff] [blame] | 167 | CCPRPathDrawer ccpr(std::exchange(mockContext, nullptr), reporter, doStroke); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 168 | if (!ccpr.valid()) { |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | fPath.moveTo(0, 0); |
| 173 | fPath.cubicTo(50, 50, 0, 50, 50, 0); |
| 174 | this->onRun(reporter, ccpr); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 175 | } |
| 176 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 177 | virtual ~CCPRTest() {} |
| 178 | |
| 179 | protected: |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 180 | virtual void customizeOptions(GrMockOptions*, GrContextOptions*) {} |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 181 | virtual void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) = 0; |
| 182 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 183 | SkPath fPath; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 184 | }; |
| 185 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 186 | #define DEF_CCPR_TEST(name) \ |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 187 | DEF_GPUTEST(name, reporter, /* options */) { \ |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 188 | name test; \ |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 189 | test.run(reporter, DoCoverageCount::kYes, DoStroke::kNo); \ |
| 190 | test.run(reporter, DoCoverageCount::kYes, DoStroke::kYes); \ |
| 191 | test.run(reporter, DoCoverageCount::kNo, DoStroke::kNo); \ |
| 192 | /* FIXME: test.run(reporter, (DoCoverageCount::kNo, DoStroke::kYes) once supported. */ \ |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 193 | } |
| 194 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 195 | class CCPR_cleanup : public CCPRTest { |
Chris Dalton | 5a5fe79 | 2020-02-15 11:41:30 -0700 | [diff] [blame] | 196 | protected: |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 197 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override { |
| 198 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 199 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 200 | // Ensure paths get unreffed. |
| 201 | for (int i = 0; i < 10; ++i) { |
| 202 | ccpr.drawPath(fPath); |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 203 | } |
| 204 | REPORTER_ASSERT(reporter, !SkPathPriv::TestingOnly_unique(fPath)); |
| 205 | ccpr.flush(); |
| 206 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 207 | |
| 208 | // Ensure clip paths get unreffed. |
| 209 | for (int i = 0; i < 10; ++i) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 210 | ccpr.clipFullscreenRect(fPath); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 211 | } |
| 212 | REPORTER_ASSERT(reporter, !SkPathPriv::TestingOnly_unique(fPath)); |
| 213 | ccpr.flush(); |
| 214 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 215 | |
| 216 | // Ensure paths get unreffed when we delete the context without flushing. |
| 217 | for (int i = 0; i < 10; ++i) { |
| 218 | ccpr.drawPath(fPath); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 219 | ccpr.clipFullscreenRect(fPath); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 220 | } |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 221 | REPORTER_ASSERT(reporter, !SkPathPriv::TestingOnly_unique(fPath)); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 222 | |
| 223 | ccpr.destroyGrContext(); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 224 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 225 | } |
| 226 | }; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 227 | DEF_CCPR_TEST(CCPR_cleanup) |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 228 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 229 | class CCPR_cleanupWithTexAllocFail : public CCPR_cleanup { |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 230 | void customizeOptions(GrMockOptions* mockOptions, GrContextOptions*) override { |
| 231 | mockOptions->fFailTextureAllocations = true; |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 232 | } |
Chris Dalton | 5a5fe79 | 2020-02-15 11:41:30 -0700 | [diff] [blame] | 233 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override { |
| 234 | ((GrRecordingContext*)ccpr.ctx())->priv().incrSuppressWarningMessages(); |
| 235 | this->CCPR_cleanup::onRun(reporter, ccpr); |
| 236 | } |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 237 | }; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 238 | DEF_CCPR_TEST(CCPR_cleanupWithTexAllocFail) |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 239 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 240 | class CCPR_unregisterCulledOps : public CCPRTest { |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 241 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override { |
| 242 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 243 | |
| 244 | // Ensure Ops get unregistered from CCPR when culled early. |
| 245 | ccpr.drawPath(fPath); |
| 246 | REPORTER_ASSERT(reporter, !SkPathPriv::TestingOnly_unique(fPath)); |
| 247 | ccpr.clear(); // Clear should delete the CCPR Op. |
| 248 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 249 | ccpr.flush(); // Should not crash (DrawPathsOp should have unregistered itself). |
| 250 | |
| 251 | // Ensure Op unregisters work when we delete the context without flushing. |
| 252 | ccpr.drawPath(fPath); |
| 253 | REPORTER_ASSERT(reporter, !SkPathPriv::TestingOnly_unique(fPath)); |
| 254 | ccpr.clear(); // Clear should delete the CCPR DrawPathsOp. |
| 255 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 256 | ccpr.destroyGrContext(); // Should not crash (DrawPathsOp should have unregistered itself). |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 257 | } |
| 258 | }; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 259 | DEF_CCPR_TEST(CCPR_unregisterCulledOps) |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 260 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 261 | class CCPR_parseEmptyPath : public CCPRTest { |
Chris Dalton | c9c97b7 | 2017-11-27 15:34:26 -0700 | [diff] [blame] | 262 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override { |
| 263 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 264 | |
| 265 | // Make a path large enough that ccpr chooses to crop it by the RT bounds, and ends up with |
| 266 | // an empty path. |
| 267 | SkPath largeOutsidePath; |
| 268 | largeOutsidePath.moveTo(-1e30f, -1e30f); |
| 269 | largeOutsidePath.lineTo(-1e30f, +1e30f); |
| 270 | largeOutsidePath.lineTo(-1e10f, +1e30f); |
| 271 | ccpr.drawPath(largeOutsidePath); |
| 272 | |
| 273 | // Normally an empty path is culled before reaching ccpr, however we use a back door for |
| 274 | // testing so this path will make it. |
| 275 | SkPath emptyPath; |
| 276 | SkASSERT(emptyPath.isEmpty()); |
| 277 | ccpr.drawPath(emptyPath); |
| 278 | |
| 279 | // This is the test. It will exercise various internal asserts and verify we do not crash. |
| 280 | ccpr.flush(); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 281 | |
| 282 | // Now try again with clips. |
| 283 | ccpr.clipFullscreenRect(largeOutsidePath); |
| 284 | ccpr.clipFullscreenRect(emptyPath); |
| 285 | ccpr.flush(); |
| 286 | |
| 287 | // ... and both. |
| 288 | ccpr.drawPath(largeOutsidePath); |
| 289 | ccpr.clipFullscreenRect(largeOutsidePath); |
| 290 | ccpr.drawPath(emptyPath); |
| 291 | ccpr.clipFullscreenRect(emptyPath); |
| 292 | ccpr.flush(); |
Chris Dalton | c9c97b7 | 2017-11-27 15:34:26 -0700 | [diff] [blame] | 293 | } |
| 294 | }; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 295 | DEF_CCPR_TEST(CCPR_parseEmptyPath) |
Chris Dalton | d6fa454 | 2019-01-04 13:23:51 -0700 | [diff] [blame] | 296 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 297 | static int get_mock_texture_id(const GrTexture* texture) { |
| 298 | const GrBackendTexture& backingTexture = texture->getBackendTexture(); |
| 299 | SkASSERT(GrBackendApi::kMock == backingTexture.backend()); |
| 300 | |
| 301 | if (!backingTexture.isValid()) { |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | GrMockTextureInfo info; |
| 306 | backingTexture.getMockTextureInfo(&info); |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 307 | return info.id(); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | // Base class for cache path unit tests. |
| 311 | class CCPRCacheTest : public CCPRTest { |
| 312 | protected: |
| 313 | // Registers as an onFlush callback in order to snag the CCPR per-flush resources and note the |
| 314 | // texture IDs. |
| 315 | class RecordLastMockAtlasIDs : public GrOnFlushCallbackObject { |
| 316 | public: |
| 317 | RecordLastMockAtlasIDs(sk_sp<GrCoverageCountingPathRenderer> ccpr) : fCCPR(ccpr) {} |
| 318 | |
| 319 | int lastCopyAtlasID() const { return fLastCopyAtlasID; } |
| 320 | int lastRenderedAtlasID() const { return fLastRenderedAtlasID; } |
| 321 | |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 322 | void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs, |
| 323 | int numOpsTaskIDs) override { |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 324 | fLastRenderedAtlasID = fLastCopyAtlasID = 0; |
| 325 | |
| 326 | const GrCCPerFlushResources* resources = fCCPR->testingOnly_getCurrentFlushResources(); |
| 327 | if (!resources) { |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | if (const GrTexture* tex = resources->testingOnly_frontCopyAtlasTexture()) { |
| 332 | fLastCopyAtlasID = get_mock_texture_id(tex); |
| 333 | } |
| 334 | if (const GrTexture* tex = resources->testingOnly_frontRenderedAtlasTexture()) { |
| 335 | fLastRenderedAtlasID = get_mock_texture_id(tex); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | void postFlush(GrDeferredUploadToken, const uint32_t*, int) override {} |
| 340 | |
| 341 | private: |
| 342 | sk_sp<GrCoverageCountingPathRenderer> fCCPR; |
| 343 | int fLastCopyAtlasID = 0; |
| 344 | int fLastRenderedAtlasID = 0; |
| 345 | }; |
| 346 | |
| 347 | CCPRCacheTest() { |
| 348 | static constexpr int primes[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; |
| 349 | |
| 350 | SkRandom rand; |
| 351 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPaths); ++i) { |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 352 | int numPts = rand.nextRangeU(GrStyledShape::kMaxKeyFromDataVerbCnt + 1, |
| 353 | GrStyledShape::kMaxKeyFromDataVerbCnt * 2); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 354 | int step; |
| 355 | do { |
| 356 | step = primes[rand.nextU() % SK_ARRAY_COUNT(primes)]; |
| 357 | } while (step == numPts); |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 358 | fPaths[i] = ToolUtils::make_star(SkRect::MakeLTRB(0, 0, 1, 1), numPts, step); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | void drawPathsAndFlush(CCPRPathDrawer& ccpr, const SkMatrix& m) { |
| 363 | this->drawPathsAndFlush(ccpr, &m, 1); |
| 364 | } |
| 365 | void drawPathsAndFlush(CCPRPathDrawer& ccpr, const SkMatrix* matrices, int numMatrices) { |
| 366 | // Draw all the paths. |
| 367 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPaths); ++i) { |
| 368 | ccpr.drawPath(fPaths[i], matrices[i % numMatrices]); |
| 369 | } |
| 370 | // Re-draw a few paths, to test the case where a cache entry is hit more than once in a |
| 371 | // single flush. |
| 372 | SkRandom rand; |
| 373 | int duplicateIndices[10]; |
| 374 | for (size_t i = 0; i < SK_ARRAY_COUNT(duplicateIndices); ++i) { |
| 375 | duplicateIndices[i] = rand.nextULessThan(SK_ARRAY_COUNT(fPaths)); |
| 376 | } |
| 377 | for (size_t i = 0; i < SK_ARRAY_COUNT(duplicateIndices); ++i) { |
| 378 | for (size_t j = 0; j <= i; ++j) { |
| 379 | int idx = duplicateIndices[j]; |
| 380 | ccpr.drawPath(fPaths[idx], matrices[idx % numMatrices]); |
| 381 | } |
| 382 | } |
| 383 | ccpr.flush(); |
| 384 | } |
| 385 | |
| 386 | private: |
Chris Dalton | d6fa454 | 2019-01-04 13:23:51 -0700 | [diff] [blame] | 387 | void customizeOptions(GrMockOptions*, GrContextOptions* ctxOptions) override { |
| 388 | ctxOptions->fAllowPathMaskCaching = true; |
| 389 | } |
| 390 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 391 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) final { |
| 392 | RecordLastMockAtlasIDs atlasIDRecorder(sk_ref_sp(ccpr.ccpr())); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 393 | ccpr.ctx()->priv().addOnFlushCallbackObject(&atlasIDRecorder); |
Chris Dalton | d6fa454 | 2019-01-04 13:23:51 -0700 | [diff] [blame] | 394 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 395 | this->onRun(reporter, ccpr, atlasIDRecorder); |
| 396 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 397 | ccpr.ctx()->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&atlasIDRecorder); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | virtual void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 401 | const RecordLastMockAtlasIDs&) = 0; |
| 402 | |
| 403 | protected: |
| 404 | SkPath fPaths[350]; |
| 405 | }; |
| 406 | |
| 407 | // Ensures ccpr always reuses the same atlas texture in the animation use case. |
| 408 | class CCPR_cache_animationAtlasReuse : public CCPRCacheTest { |
| 409 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 410 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 411 | SkMatrix m = SkMatrix::Translate(kCanvasSize/2, kCanvasSize/2); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 412 | m.preScale(80, 80); |
| 413 | m.preTranslate(-.5,-.5); |
| 414 | this->drawPathsAndFlush(ccpr, m); |
| 415 | |
| 416 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 417 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 418 | const int atlasID = atlasIDRecorder.lastRenderedAtlasID(); |
| 419 | |
| 420 | // Ensures we always reuse the same atlas texture in the animation use case. |
| 421 | for (int i = 0; i < 12; ++i) { |
| 422 | // 59 is prime, so we will hit every integer modulo 360 before repeating. |
| 423 | m.preRotate(59, .5, .5); |
| 424 | |
| 425 | // Go twice. Paths have to get drawn twice with the same matrix before we cache their |
| 426 | // atlas. This makes sure that on the subsequent draw, after an atlas has been cached |
| 427 | // and is then invalidated since the matrix will change, that the same underlying |
| 428 | // texture object is still reused for the next atlas. |
| 429 | for (int j = 0; j < 2; ++j) { |
| 430 | this->drawPathsAndFlush(ccpr, m); |
| 431 | // Nothing should be copied to an 8-bit atlas after just two draws. |
| 432 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 433 | REPORTER_ASSERT(reporter, atlasIDRecorder.lastRenderedAtlasID() == atlasID); |
| 434 | } |
Chris Dalton | 2e825a3 | 2019-01-04 22:14:27 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 437 | // Do the last draw again. (On draw 3 they should get copied to an 8-bit atlas.) |
| 438 | this->drawPathsAndFlush(ccpr, m); |
| 439 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 440 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 441 | |
| 442 | // Now double-check that everything continues to hit the cache as expected when the matrix |
| 443 | // doesn't change. |
| 444 | for (int i = 0; i < 10; ++i) { |
| 445 | this->drawPathsAndFlush(ccpr, m); |
| 446 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 447 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 448 | } |
| 449 | } |
| 450 | }; |
| 451 | DEF_CCPR_TEST(CCPR_cache_animationAtlasReuse) |
| 452 | |
| 453 | class CCPR_cache_recycleEntries : public CCPRCacheTest { |
| 454 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 455 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 456 | SkMatrix m = SkMatrix::Translate(kCanvasSize/2, kCanvasSize/2); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 457 | m.preScale(80, 80); |
| 458 | m.preTranslate(-.5,-.5); |
| 459 | |
| 460 | auto cache = ccpr.ccpr()->testingOnly_getPathCache(); |
| 461 | REPORTER_ASSERT(reporter, cache); |
| 462 | |
| 463 | const auto& lru = cache->testingOnly_getLRU(); |
| 464 | |
| 465 | SkTArray<const void*> expectedPtrs; |
| 466 | |
| 467 | // Ensures we always reuse the same atlas texture in the animation use case. |
| 468 | for (int i = 0; i < 5; ++i) { |
| 469 | // 59 is prime, so we will hit every integer modulo 360 before repeating. |
| 470 | m.preRotate(59, .5, .5); |
| 471 | |
| 472 | // Go twice. Paths have to get drawn twice with the same matrix before we cache their |
| 473 | // atlas. |
| 474 | for (int j = 0; j < 2; ++j) { |
| 475 | this->drawPathsAndFlush(ccpr, m); |
| 476 | // Nothing should be copied to an 8-bit atlas after just two draws. |
| 477 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 478 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 479 | } |
| 480 | |
| 481 | int idx = 0; |
| 482 | for (const GrCCPathCacheEntry* entry : lru) { |
| 483 | if (0 == i) { |
| 484 | expectedPtrs.push_back(entry); |
| 485 | } else { |
| 486 | // The same pointer should have been recycled for the new matrix. |
| 487 | REPORTER_ASSERT(reporter, entry == expectedPtrs[idx]); |
| 488 | } |
| 489 | ++idx; |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | }; |
| 494 | DEF_CCPR_TEST(CCPR_cache_recycleEntries) |
| 495 | |
| 496 | // Ensures mostly-visible paths get their full mask cached. |
| 497 | class CCPR_cache_mostlyVisible : public CCPRCacheTest { |
| 498 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 499 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
| 500 | SkMatrix matrices[3] = { |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 501 | SkMatrix::Scale(kCanvasSize/2, kCanvasSize/2), // Fully visible. |
| 502 | SkMatrix::Scale(kCanvasSize * 1.25, kCanvasSize * 1.25), // Mostly visible. |
| 503 | SkMatrix::Scale(kCanvasSize * 1.5, kCanvasSize * 1.5), // Mostly NOT visible. |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | for (int i = 0; i < 10; ++i) { |
| 507 | this->drawPathsAndFlush(ccpr, matrices, 3); |
| 508 | if (2 == i) { |
| 509 | // The mostly-visible paths should still get cached. |
| 510 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 511 | } else { |
| 512 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 513 | } |
| 514 | // Ensure mostly NOT-visible paths never get cached. |
| 515 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 516 | } |
| 517 | |
| 518 | // Clear the path cache. |
| 519 | this->drawPathsAndFlush(ccpr, SkMatrix::I()); |
| 520 | |
| 521 | // Now only draw the fully/mostly visible ones. |
| 522 | for (int i = 0; i < 2; ++i) { |
| 523 | this->drawPathsAndFlush(ccpr, matrices, 2); |
| 524 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 525 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 526 | } |
| 527 | |
| 528 | // On draw 3 they should get copied to an 8-bit atlas. |
| 529 | this->drawPathsAndFlush(ccpr, matrices, 2); |
| 530 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 531 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 532 | |
| 533 | for (int i = 0; i < 10; ++i) { |
| 534 | this->drawPathsAndFlush(ccpr, matrices, 2); |
| 535 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 536 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 537 | } |
| 538 | |
| 539 | // Draw a different part of the path to ensure the full mask was cached. |
| 540 | matrices[1].postTranslate(SkScalarFloorToInt(kCanvasSize * -.25f), |
| 541 | SkScalarFloorToInt(kCanvasSize * -.25f)); |
| 542 | for (int i = 0; i < 10; ++i) { |
| 543 | this->drawPathsAndFlush(ccpr, matrices, 2); |
| 544 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 545 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 546 | } |
| 547 | } |
| 548 | }; |
| 549 | DEF_CCPR_TEST(CCPR_cache_mostlyVisible) |
| 550 | |
| 551 | // Ensures GrContext::performDeferredCleanup works. |
| 552 | class CCPR_cache_deferredCleanup : public CCPRCacheTest { |
| 553 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 554 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 555 | SkMatrix m = SkMatrix::Scale(20, 20); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 556 | int lastRenderedAtlasID = 0; |
| 557 | |
| 558 | for (int i = 0; i < 5; ++i) { |
| 559 | this->drawPathsAndFlush(ccpr, m); |
| 560 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 561 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 562 | int renderedAtlasID = atlasIDRecorder.lastRenderedAtlasID(); |
| 563 | REPORTER_ASSERT(reporter, renderedAtlasID != lastRenderedAtlasID); |
| 564 | lastRenderedAtlasID = renderedAtlasID; |
| 565 | |
| 566 | this->drawPathsAndFlush(ccpr, m); |
| 567 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 568 | REPORTER_ASSERT(reporter, lastRenderedAtlasID == atlasIDRecorder.lastRenderedAtlasID()); |
| 569 | |
| 570 | // On draw 3 they should get copied to an 8-bit atlas. |
| 571 | this->drawPathsAndFlush(ccpr, m); |
| 572 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 573 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 574 | |
| 575 | for (int i = 0; i < 10; ++i) { |
| 576 | this->drawPathsAndFlush(ccpr, m); |
| 577 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 578 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 579 | } |
| 580 | |
| 581 | ccpr.ctx()->performDeferredCleanup(std::chrono::milliseconds(0)); |
| 582 | } |
| 583 | } |
| 584 | }; |
| 585 | DEF_CCPR_TEST(CCPR_cache_deferredCleanup) |
| 586 | |
| 587 | // Verifies the cache/hash table internals. |
| 588 | class CCPR_cache_hashTable : public CCPRCacheTest { |
| 589 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 590 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
| 591 | using CoverageType = GrCCAtlas::CoverageType; |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 592 | SkMatrix m = SkMatrix::Scale(20, 20); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 593 | |
| 594 | for (int i = 0; i < 5; ++i) { |
| 595 | this->drawPathsAndFlush(ccpr, m); |
| 596 | if (2 == i) { |
| 597 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 598 | } else { |
| 599 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 600 | } |
| 601 | if (i < 2) { |
| 602 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 603 | } else { |
| 604 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 605 | } |
| 606 | |
| 607 | auto cache = ccpr.ccpr()->testingOnly_getPathCache(); |
| 608 | REPORTER_ASSERT(reporter, cache); |
| 609 | |
| 610 | const auto& hash = cache->testingOnly_getHashTable(); |
| 611 | const auto& lru = cache->testingOnly_getLRU(); |
| 612 | int count = 0; |
| 613 | for (GrCCPathCacheEntry* entry : lru) { |
| 614 | auto* node = hash.find(entry->cacheKey()); |
| 615 | REPORTER_ASSERT(reporter, node); |
| 616 | REPORTER_ASSERT(reporter, node->entry() == entry); |
| 617 | REPORTER_ASSERT(reporter, 0 == entry->testingOnly_peekOnFlushRefCnt()); |
| 618 | REPORTER_ASSERT(reporter, entry->unique()); |
| 619 | if (0 == i) { |
| 620 | REPORTER_ASSERT(reporter, !entry->cachedAtlas()); |
| 621 | } else { |
| 622 | const GrCCCachedAtlas* cachedAtlas = entry->cachedAtlas(); |
| 623 | REPORTER_ASSERT(reporter, cachedAtlas); |
| 624 | if (1 == i) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 625 | REPORTER_ASSERT(reporter, ccpr.ccpr()->coverageType() |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 626 | == cachedAtlas->coverageType()); |
| 627 | } else { |
| 628 | REPORTER_ASSERT(reporter, CoverageType::kA8_LiteralCoverage |
| 629 | == cachedAtlas->coverageType()); |
| 630 | } |
| 631 | REPORTER_ASSERT(reporter, cachedAtlas->textureKey().isValid()); |
| 632 | // The actual proxy should not be held past the end of a flush. |
| 633 | REPORTER_ASSERT(reporter, !cachedAtlas->getOnFlushProxy()); |
| 634 | REPORTER_ASSERT(reporter, 0 == cachedAtlas->testingOnly_peekOnFlushRefCnt()); |
| 635 | } |
| 636 | ++count; |
| 637 | } |
| 638 | REPORTER_ASSERT(reporter, hash.count() == count); |
| 639 | } |
| 640 | } |
| 641 | }; |
| 642 | DEF_CCPR_TEST(CCPR_cache_hashTable) |
| 643 | |
| 644 | // Ensures paths get cached even when using a sporadic flushing pattern and drawing out of order |
| 645 | // (a la Chrome tiles). |
| 646 | class CCPR_cache_multiFlush : public CCPRCacheTest { |
| 647 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 648 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
| 649 | static constexpr int kNumPaths = SK_ARRAY_COUNT(fPaths); |
| 650 | static constexpr int kBigPrimes[] = { |
| 651 | 9323, 11059, 22993, 38749, 45127, 53147, 64853, 77969, 83269, 99989}; |
| 652 | |
| 653 | SkRandom rand; |
| 654 | SkMatrix m = SkMatrix::I(); |
| 655 | |
| 656 | for (size_t i = 0; i < SK_ARRAY_COUNT(kBigPrimes); ++i) { |
| 657 | int prime = kBigPrimes[i]; |
| 658 | int endPathIdx = (int)rand.nextULessThan(kNumPaths); |
| 659 | int pathIdx = endPathIdx; |
| 660 | int nextFlush = rand.nextRangeU(1, 47); |
| 661 | for (int j = 0; j < kNumPaths; ++j) { |
| 662 | pathIdx = (pathIdx + prime) % kNumPaths; |
| 663 | int repeat = rand.nextRangeU(1, 3); |
| 664 | for (int k = 0; k < repeat; ++k) { |
| 665 | ccpr.drawPath(fPaths[pathIdx], m); |
| 666 | } |
| 667 | if (nextFlush == j) { |
| 668 | ccpr.flush(); |
| 669 | // The paths are small enough that we should never copy to an A8 atlas. |
| 670 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 671 | if (i < 2) { |
| 672 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 673 | } else { |
| 674 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 675 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 676 | nextFlush = std::min(j + (int)rand.nextRangeU(1, 29), kNumPaths - 1); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | SkASSERT(endPathIdx == pathIdx % kNumPaths); |
| 680 | } |
| 681 | } |
| 682 | }; |
| 683 | DEF_CCPR_TEST(CCPR_cache_multiFlush) |
| 684 | |
Chris Dalton | aaa77c1 | 2019-01-07 17:45:36 -0700 | [diff] [blame] | 685 | // Ensures a path drawn over mutiple tiles gets cached. |
| 686 | class CCPR_cache_multiTileCache : public CCPRCacheTest { |
| 687 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 688 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
| 689 | // Make sure a path drawn over 9 tiles gets cached (1 tile out of 9 is >10% visibility). |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 690 | const SkMatrix m0 = SkMatrix::Scale(kCanvasSize*3, kCanvasSize*3); |
Chris Dalton | aaa77c1 | 2019-01-07 17:45:36 -0700 | [diff] [blame] | 691 | const SkPath p0 = fPaths[0]; |
| 692 | for (int i = 0; i < 9; ++i) { |
| 693 | static constexpr int kRowOrder[9] = {0,1,1,0,2,2,2,1,0}; |
| 694 | static constexpr int kColumnOrder[9] = {0,0,1,1,0,1,2,2,2}; |
| 695 | |
| 696 | SkMatrix tileM = m0; |
| 697 | tileM.postTranslate(-kCanvasSize * kColumnOrder[i], -kCanvasSize * kRowOrder[i]); |
| 698 | ccpr.drawPath(p0, tileM); |
| 699 | ccpr.flush(); |
| 700 | if (i < 5) { |
| 701 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 702 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 703 | } else if (5 == i) { |
| 704 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 705 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 706 | } else { |
| 707 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 708 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | // Now make sure paths don't get cached when visibility is <10% for every draw (12 tiles). |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 713 | const SkMatrix m1 = SkMatrix::Scale(kCanvasSize*4, kCanvasSize*3); |
Chris Dalton | aaa77c1 | 2019-01-07 17:45:36 -0700 | [diff] [blame] | 714 | const SkPath p1 = fPaths[1]; |
| 715 | for (int row = 0; row < 3; ++row) { |
| 716 | for (int col = 0; col < 4; ++col) { |
| 717 | SkMatrix tileM = m1; |
| 718 | tileM.postTranslate(-kCanvasSize * col, -kCanvasSize * row); |
| 719 | ccpr.drawPath(p1, tileM); |
| 720 | ccpr.flush(); |
| 721 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 722 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // Double-check the cache is still intact. |
| 727 | ccpr.drawPath(p0, m0); |
| 728 | ccpr.flush(); |
| 729 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 730 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 731 | |
| 732 | ccpr.drawPath(p1, m1); |
| 733 | ccpr.flush(); |
| 734 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 735 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastRenderedAtlasID()); |
| 736 | } |
| 737 | }; |
| 738 | DEF_CCPR_TEST(CCPR_cache_multiTileCache) |
| 739 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 740 | // This test exercises CCPR's cache capabilities by drawing many paths with two different |
| 741 | // transformation matrices. We then vary the matrices independently by whole and partial pixels, |
| 742 | // and verify the caching behaved as expected. |
| 743 | class CCPR_cache_partialInvalidate : public CCPRCacheTest { |
| 744 | void customizeOptions(GrMockOptions*, GrContextOptions* ctxOptions) override { |
| 745 | ctxOptions->fAllowPathMaskCaching = true; |
| 746 | } |
| 747 | |
| 748 | static constexpr int kPathSize = 4; |
| 749 | |
| 750 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr, |
| 751 | const RecordLastMockAtlasIDs& atlasIDRecorder) override { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 752 | SkMatrix matrices[2] = { |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 753 | SkMatrix::Translate(5, 5), |
| 754 | SkMatrix::Translate(kCanvasSize - kPathSize - 5, kCanvasSize - kPathSize - 5) |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 755 | }; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 756 | matrices[0].preScale(kPathSize, kPathSize); |
| 757 | matrices[1].preScale(kPathSize, kPathSize); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 758 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 759 | int firstAtlasID = 0; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 760 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 761 | for (int iterIdx = 0; iterIdx < 4*3*2; ++iterIdx) { |
| 762 | this->drawPathsAndFlush(ccpr, matrices, 2); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 763 | |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 764 | if (0 == iterIdx) { |
| 765 | // First iteration: just note the ID of the stashed atlas and continue. |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 766 | firstAtlasID = atlasIDRecorder.lastRenderedAtlasID(); |
| 767 | REPORTER_ASSERT(reporter, 0 != firstAtlasID); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 768 | continue; |
| 769 | } |
| 770 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 771 | int testIdx = (iterIdx/2) % 3; |
| 772 | int repetitionIdx = iterIdx % 2; |
| 773 | switch (testIdx) { |
| 774 | case 0: |
| 775 | if (0 == repetitionIdx) { |
| 776 | // This is the big test. New paths were drawn twice last round. On hit 2 |
| 777 | // (last time), 'firstAtlasID' was cached as a 16-bit atlas. Now, on hit 3, |
| 778 | // these paths should be copied out of 'firstAtlasID', and into an A8 atlas. |
| 779 | // THEN: we should recycle 'firstAtlasID' and reuse that same texture to |
| 780 | // render the new masks. |
| 781 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 782 | REPORTER_ASSERT(reporter, |
| 783 | atlasIDRecorder.lastRenderedAtlasID() == firstAtlasID); |
| 784 | } else { |
| 785 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 786 | // This is hit 2 for the new masks. Next time they will be copied to an A8 |
| 787 | // atlas. |
| 788 | REPORTER_ASSERT(reporter, |
| 789 | atlasIDRecorder.lastRenderedAtlasID() == firstAtlasID); |
| 790 | } |
Chris Dalton | d6fa454 | 2019-01-04 13:23:51 -0700 | [diff] [blame] | 791 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 792 | if (1 == repetitionIdx) { |
| 793 | // Integer translates: all path masks stay valid. |
| 794 | matrices[0].preTranslate(-1, -1); |
| 795 | matrices[1].preTranslate(1, 1); |
| 796 | } |
| 797 | break; |
| 798 | |
| 799 | case 1: |
| 800 | if (0 == repetitionIdx) { |
| 801 | // New paths were drawn twice last round. The third hit (now) they should be |
| 802 | // copied to an A8 atlas. |
| 803 | REPORTER_ASSERT(reporter, 0 != atlasIDRecorder.lastCopyAtlasID()); |
| 804 | } else { |
| 805 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
| 806 | } |
| 807 | |
| 808 | // This draw should have gotten 100% cache hits; we only did integer translates |
| 809 | // last time (or none if it was the first flush). Therefore, everything should |
| 810 | // have been cached. |
| 811 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastRenderedAtlasID()); |
| 812 | |
| 813 | if (1 == repetitionIdx) { |
| 814 | // Invalidate even path masks. |
| 815 | matrices[0].preTranslate(1.6f, 1.4f); |
| 816 | } |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 817 | break; |
| 818 | |
| 819 | case 2: |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 820 | // No new masks to copy from last time; it had 100% cache hits. |
| 821 | REPORTER_ASSERT(reporter, 0 == atlasIDRecorder.lastCopyAtlasID()); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 822 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 823 | // Even path masks were invalidated last iteration by a subpixel translate. |
| 824 | // They should have been re-rendered this time in the original 'firstAtlasID' |
| 825 | // texture. |
| 826 | REPORTER_ASSERT(reporter, |
| 827 | atlasIDRecorder.lastRenderedAtlasID() == firstAtlasID); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 828 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 829 | if (1 == repetitionIdx) { |
| 830 | // Invalidate odd path masks. |
| 831 | matrices[1].preTranslate(-1.4f, -1.6f); |
| 832 | } |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 833 | break; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | }; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 838 | DEF_CCPR_TEST(CCPR_cache_partialInvalidate) |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 839 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 840 | class CCPR_unrefPerOpsTaskPathsBeforeOps : public CCPRTest { |
Chris Dalton | dedf8f2 | 2018-09-24 20:23:47 -0600 | [diff] [blame] | 841 | void onRun(skiatest::Reporter* reporter, CCPRPathDrawer& ccpr) override { |
| 842 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 843 | for (int i = 0; i < 10000; ++i) { |
| 844 | // Draw enough paths to make the arena allocator hit the heap. |
| 845 | ccpr.drawPath(fPath); |
| 846 | } |
| 847 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 848 | // Unref the GrCCPerOpsTaskPaths object. |
| 849 | auto perOpsTaskPathsMap = ccpr.ccpr()->detachPendingPaths(); |
| 850 | perOpsTaskPathsMap.clear(); |
Chris Dalton | dedf8f2 | 2018-09-24 20:23:47 -0600 | [diff] [blame] | 851 | |
| 852 | // Now delete the Op and all its draws. |
| 853 | REPORTER_ASSERT(reporter, !SkPathPriv::TestingOnly_unique(fPath)); |
| 854 | ccpr.flush(); |
| 855 | REPORTER_ASSERT(reporter, SkPathPriv::TestingOnly_unique(fPath)); |
| 856 | } |
| 857 | }; |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 858 | DEF_CCPR_TEST(CCPR_unrefPerOpsTaskPathsBeforeOps) |
Chris Dalton | dedf8f2 | 2018-09-24 20:23:47 -0600 | [diff] [blame] | 859 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 860 | class CCPRRenderingTest { |
| 861 | public: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 862 | void run(skiatest::Reporter* reporter, GrContext* ctx, DoStroke doStroke) const { |
| 863 | if (auto ccpr = ctx->priv().drawingManager()->getCoverageCountingPathRenderer()) { |
| 864 | if (DoStroke::kYes == doStroke && |
| 865 | GrCCAtlas::CoverageType::kA8_Multisample == ccpr->coverageType()) { |
| 866 | return; // Stroking is not yet supported for multisample. |
| 867 | } |
| 868 | CCPRPathDrawer drawer(sk_ref_sp(ctx), reporter, doStroke); |
| 869 | if (!drawer.valid()) { |
| 870 | return; |
| 871 | } |
| 872 | this->onRun(reporter, drawer); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 873 | } |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | virtual ~CCPRRenderingTest() {} |
| 877 | |
| 878 | protected: |
| 879 | virtual void onRun(skiatest::Reporter* reporter, const CCPRPathDrawer& ccpr) const = 0; |
| 880 | }; |
| 881 | |
| 882 | #define DEF_CCPR_RENDERING_TEST(name) \ |
| 883 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(name, reporter, ctxInfo) { \ |
| 884 | name test; \ |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 885 | test.run(reporter, ctxInfo.grContext(), DoStroke::kNo); \ |
| 886 | test.run(reporter, ctxInfo.grContext(), DoStroke::kYes); \ |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 887 | } |
| 888 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 889 | class CCPR_busyPath : public CCPRRenderingTest { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 890 | void onRun(skiatest::Reporter* reporter, const CCPRPathDrawer& ccpr) const override { |
| 891 | static constexpr int kNumBusyVerbs = 1 << 17; |
| 892 | ccpr.clear(); |
| 893 | SkPath busyPath; |
| 894 | busyPath.moveTo(0, 0); // top left |
| 895 | busyPath.lineTo(kCanvasSize, kCanvasSize); // bottom right |
| 896 | for (int i = 2; i < kNumBusyVerbs; ++i) { |
| 897 | float offset = i * ((float)kCanvasSize / kNumBusyVerbs); |
| 898 | busyPath.lineTo(kCanvasSize - offset, kCanvasSize + offset); // offscreen |
| 899 | } |
| 900 | ccpr.drawPath(busyPath); |
| 901 | |
| 902 | ccpr.flush(); // If this doesn't crash, the test passed. |
| 903 | // If it does, maybe fiddle with fMaxInstancesPerDrawArraysWithoutCrashing in |
| 904 | // your platform's GrGLCaps. |
| 905 | } |
| 906 | }; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 907 | DEF_CCPR_RENDERING_TEST(CCPR_busyPath) |