commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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/SkString.h" |
| 9 | #include "include/gpu/GrBackendSurface.h" |
| 10 | #include "include/gpu/GrContextOptions.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 11 | #include "include/gpu/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/private/SkTo.h" |
| 13 | #include "src/core/SkMathPriv.h" |
| 14 | #include "src/gpu/GrClip.h" |
| 15 | #include "src/gpu/GrContextPriv.h" |
| 16 | #include "src/gpu/GrDrawOpAtlas.h" |
| 17 | #include "src/gpu/GrDrawingManager.h" |
| 18 | #include "src/gpu/GrGpu.h" |
| 19 | #include "src/gpu/GrGpuResourceCacheAccess.h" |
| 20 | #include "src/gpu/GrMemoryPool.h" |
| 21 | #include "src/gpu/GrRecordingContextPriv.h" |
| 22 | #include "src/gpu/GrRenderTargetContext.h" |
| 23 | #include "src/gpu/GrRenderTargetContextPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 24 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrResourceCache.h" |
| 26 | #include "src/gpu/GrSemaphore.h" |
| 27 | #include "src/gpu/GrSurfaceContextPriv.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 28 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "src/gpu/SkGr.h" |
| 30 | #include "src/gpu/ccpr/GrCCPathCache.h" |
| 31 | #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h" |
| 32 | #include "src/gpu/ops/GrMeshDrawOp.h" |
| 33 | #include "src/gpu/text/GrStrikeCache.h" |
| 34 | #include "src/gpu/text/GrTextBlobCache.h" |
| 35 | #include "src/image/SkImage_Gpu.h" |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 36 | |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 37 | #include <algorithm> |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 38 | |
bsalomon | ddf30e6 | 2015-02-19 11:38:44 -0800 | [diff] [blame] | 39 | /////////////////////////////////////////////////////////////////////////////// |
| 40 | |
| 41 | void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 42 | |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 43 | #ifdef SK_DEBUG |
| 44 | int GrResourceCache::countUniqueKeysWithTag(const char* tag) const { |
| 45 | int count = 0; |
Mike Klein | cff6396 | 2020-03-14 16:22:45 -0500 | [diff] [blame] | 46 | fUniqueHash.foreach([&](const GrGpuResource& resource){ |
| 47 | if (0 == strcmp(tag, resource.getUniqueKey().tag())) { |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 48 | ++count; |
| 49 | } |
Mike Klein | cff6396 | 2020-03-14 16:22:45 -0500 | [diff] [blame] | 50 | }); |
Brian Salomon | 1090da6 | 2017-01-06 12:04:19 -0500 | [diff] [blame] | 51 | return count; |
| 52 | } |
| 53 | #endif |
| 54 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 55 | /////////////////////////////////////////////////////////////////////////////// |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 56 | |
Adlai Holler | 33dbd65 | 2020-06-01 12:35:42 -0400 | [diff] [blame] | 57 | #define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(fRenderTargetContext->singleOwner()) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 58 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 59 | uint32_t GrRenderTargetContextPriv::testingOnly_getOpsTaskID() { |
| 60 | return fRenderTargetContext->getOpsTask()->uniqueID(); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 63 | void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) { |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 64 | this->testingOnly_addDrawOp(nullptr, std::move(op), {}); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 67 | void GrRenderTargetContextPriv::testingOnly_addDrawOp( |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 68 | const GrClip* clip, |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 69 | std::unique_ptr<GrDrawOp> op, |
| 70 | const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) { |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 71 | ASSERT_SINGLE_OWNER |
Robert Phillips | 9eb0002 | 2020-06-30 15:30:12 -0400 | [diff] [blame] | 72 | if (fRenderTargetContext->fContext->abandoned()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 73 | fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op)); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 74 | return; |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 75 | } |
| 76 | SkDEBUGCODE(fRenderTargetContext->validate()); |
Robert Phillips | 0d075de | 2019-03-04 11:08:13 -0500 | [diff] [blame] | 77 | GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->auditTrail(), |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 78 | "GrRenderTargetContext::testingOnly_addDrawOp"); |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 79 | fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 80 | } |
| 81 | |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 82 | #undef ASSERT_SINGLE_OWNER |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 83 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 84 | ////////////////////////////////////////////////////////////////////////////// |
| 85 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 86 | void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) { |
| 87 | // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for |
| 88 | // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true. |
| 89 | // The test is responsible to not draw any paths that CCPR is not actually capable of. |
| 90 | this->onDrawPath(args); |
| 91 | } |
| 92 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 93 | const GrCCPerFlushResources* |
| 94 | GrCoverageCountingPathRenderer::testingOnly_getCurrentFlushResources() { |
| 95 | SkASSERT(fFlushing); |
| 96 | if (fFlushingPaths.empty()) { |
| 97 | return nullptr; |
| 98 | } |
| 99 | // All pending paths should share the same resources. |
| 100 | const GrCCPerFlushResources* resources = fFlushingPaths.front()->fFlushResources.get(); |
| 101 | #ifdef SK_DEBUG |
| 102 | for (const auto& flushingPaths : fFlushingPaths) { |
| 103 | SkASSERT(flushingPaths->fFlushResources.get() == resources); |
| 104 | } |
| 105 | #endif |
| 106 | return resources; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 107 | } |
| 108 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 109 | const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const { |
| 110 | return fPathCache.get(); |
| 111 | } |
| 112 | |
| 113 | const GrTexture* GrCCPerFlushResources::testingOnly_frontCopyAtlasTexture() const { |
| 114 | if (fCopyAtlasStack.empty()) { |
| 115 | return nullptr; |
| 116 | } |
| 117 | const GrTextureProxy* proxy = fCopyAtlasStack.front().textureProxy(); |
| 118 | return (proxy) ? proxy->peekTexture() : nullptr; |
| 119 | } |
| 120 | |
| 121 | const GrTexture* GrCCPerFlushResources::testingOnly_frontRenderedAtlasTexture() const { |
| 122 | if (fRenderedAtlasStack.empty()) { |
| 123 | return nullptr; |
| 124 | } |
| 125 | const GrTextureProxy* proxy = fRenderedAtlasStack.front().textureProxy(); |
| 126 | return (proxy) ? proxy->peekTexture() : nullptr; |
| 127 | } |
| 128 | |
| 129 | const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>& |
| 130 | GrCCPathCache::testingOnly_getHashTable() const { |
| 131 | return fHashTable; |
| 132 | } |
| 133 | |
| 134 | const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const { |
| 135 | return fLRU; |
| 136 | } |
| 137 | |
| 138 | int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; } |
| 139 | |
| 140 | int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; } |
| 141 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 142 | ////////////////////////////////////////////////////////////////////////////// |
| 143 | |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 144 | #define DRAW_OP_TEST_EXTERN(Op) \ |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 145 | extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, \ |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 146 | GrRecordingContext*, int numSamples) |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 147 | #define DRAW_OP_TEST_ENTRY(Op) Op##__Test |
| 148 | |
Brian Salomon | 10978a6 | 2017-06-15 16:21:49 -0400 | [diff] [blame] | 149 | DRAW_OP_TEST_EXTERN(AAConvexPathOp); |
Brian Salomon | b295573 | 2017-07-13 16:42:55 -0400 | [diff] [blame] | 150 | DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp); |
Brian Salomon | a531f25 | 2017-07-07 13:29:28 -0400 | [diff] [blame] | 151 | DRAW_OP_TEST_EXTERN(AAHairlineOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 152 | DRAW_OP_TEST_EXTERN(AAStrokeRectOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 153 | DRAW_OP_TEST_EXTERN(CircleOp); |
Brian Salomon | 98222ac | 2017-07-12 15:27:54 -0400 | [diff] [blame] | 154 | DRAW_OP_TEST_EXTERN(DashOp); |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 155 | DRAW_OP_TEST_EXTERN(DefaultPathOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 156 | DRAW_OP_TEST_EXTERN(DIEllipseOp); |
| 157 | DRAW_OP_TEST_EXTERN(EllipseOp); |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 158 | DRAW_OP_TEST_EXTERN(FillRectOp); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 159 | DRAW_OP_TEST_EXTERN(GrAtlasTextOp); |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 160 | DRAW_OP_TEST_EXTERN(DrawAtlasOp); |
Robert Phillips | b6e9d3c | 2019-02-11 14:29:34 -0500 | [diff] [blame] | 161 | DRAW_OP_TEST_EXTERN(DrawVerticesOp); |
Brian Salomon | 815486c | 2017-07-11 08:52:13 -0400 | [diff] [blame] | 162 | DRAW_OP_TEST_EXTERN(NonAALatticeOp); |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 163 | DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); |
Brian Salomon | 0596909 | 2017-07-13 11:20:51 -0400 | [diff] [blame] | 164 | DRAW_OP_TEST_EXTERN(ShadowRRectOp); |
Brian Salomon | febbd23 | 2017-07-11 15:52:02 -0400 | [diff] [blame] | 165 | DRAW_OP_TEST_EXTERN(SmallPathOp); |
Brian Salomon | f036632 | 2017-07-11 15:53:05 -0400 | [diff] [blame] | 166 | DRAW_OP_TEST_EXTERN(RegionOp); |
Brian Salomon | 05441c4 | 2017-05-15 16:45:49 -0400 | [diff] [blame] | 167 | DRAW_OP_TEST_EXTERN(RRectOp); |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 168 | DRAW_OP_TEST_EXTERN(TriangulatingPathOp); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 169 | DRAW_OP_TEST_EXTERN(TextureOp); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 170 | |
| 171 | void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) { |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 172 | auto context = renderTargetContext->surfPriv().getContext(); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 173 | using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 174 | GrRecordingContext*, int numSamples); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 175 | static constexpr MakeDrawOpFn* gFactories[] = { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 176 | DRAW_OP_TEST_ENTRY(AAConvexPathOp), |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 177 | DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp), |
| 178 | DRAW_OP_TEST_ENTRY(AAHairlineOp), |
| 179 | DRAW_OP_TEST_ENTRY(AAStrokeRectOp), |
| 180 | DRAW_OP_TEST_ENTRY(CircleOp), |
| 181 | DRAW_OP_TEST_ENTRY(DashOp), |
| 182 | DRAW_OP_TEST_ENTRY(DefaultPathOp), |
| 183 | DRAW_OP_TEST_ENTRY(DIEllipseOp), |
| 184 | DRAW_OP_TEST_ENTRY(EllipseOp), |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 185 | DRAW_OP_TEST_ENTRY(FillRectOp), |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 186 | DRAW_OP_TEST_ENTRY(GrAtlasTextOp), |
Brian Osman | 4d92b89 | 2019-03-24 00:53:23 +0000 | [diff] [blame] | 187 | DRAW_OP_TEST_ENTRY(DrawAtlasOp), |
Robert Phillips | b6e9d3c | 2019-02-11 14:29:34 -0500 | [diff] [blame] | 188 | DRAW_OP_TEST_ENTRY(DrawVerticesOp), |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 189 | DRAW_OP_TEST_ENTRY(NonAALatticeOp), |
| 190 | DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp), |
| 191 | DRAW_OP_TEST_ENTRY(ShadowRRectOp), |
| 192 | DRAW_OP_TEST_ENTRY(SmallPathOp), |
| 193 | DRAW_OP_TEST_ENTRY(RegionOp), |
| 194 | DRAW_OP_TEST_ENTRY(RRectOp), |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 195 | DRAW_OP_TEST_ENTRY(TriangulatingPathOp), |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 196 | DRAW_OP_TEST_ENTRY(TextureOp), |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 197 | }; |
| 198 | |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 199 | static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories); |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 200 | uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal)); |
Brian Salomon | fc26f3c | 2017-07-14 15:27:56 -0400 | [diff] [blame] | 201 | auto op = gFactories[index]( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 202 | std::move(paint), random, context, renderTargetContext->numSamples()); |
Herb Derby | 411e7aa | 2020-07-09 16:02:08 -0400 | [diff] [blame^] | 203 | |
| 204 | // Creating a GrAtlasTextOp my not produce an op if for example, it is totally outside the |
| 205 | // render target context. |
Ben Wagner | 525e876 | 2020-07-09 16:19:35 -0400 | [diff] [blame] | 206 | if (op) { |
| 207 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 208 | } |
Brian Salomon | 1772663 | 2017-05-12 14:09:46 -0400 | [diff] [blame] | 209 | } |