blob: 1f85ac5469cfcb2a487530655bdc614db72f71f6 [file] [log] [blame]
commit-bot@chromium.org78a10782013-08-21 19:27:48 +00001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkString.h"
9#include "include/gpu/GrBackendSurface.h"
10#include "include/gpu/GrContextOptions.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040011#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#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 Danielf91aeb22019-06-18 09:58:02 -040024#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/GrResourceCache.h"
26#include "src/gpu/GrSemaphore.h"
27#include "src/gpu/GrSurfaceContextPriv.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000028#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029#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 Canary8a001442018-09-19 11:31:27 -040036
Hal Canaryc640d0d2018-06-13 09:59:02 -040037#include <algorithm>
joshualitte8042922015-12-11 06:11:21 -080038
bsalomonddf30e62015-02-19 11:38:44 -080039///////////////////////////////////////////////////////////////////////////////
40
41void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -080042
Brian Salomon1090da62017-01-06 12:04:19 -050043#ifdef SK_DEBUG
44int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
45 int count = 0;
Mike Kleincff63962020-03-14 16:22:45 -050046 fUniqueHash.foreach([&](const GrGpuResource& resource){
47 if (0 == strcmp(tag, resource.getUniqueKey().tag())) {
Brian Salomon1090da62017-01-06 12:04:19 -050048 ++count;
49 }
Mike Kleincff63962020-03-14 16:22:45 -050050 });
Brian Salomon1090da62017-01-06 12:04:19 -050051 return count;
52}
53#endif
54
bsalomon33435572014-11-05 14:47:41 -080055///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -080056
Adlai Holler33dbd652020-06-01 12:35:42 -040057#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(fRenderTargetContext->singleOwner())
Chris Dalton706a6ff2017-11-29 22:01:06 -070058
Greg Danielf41b2bd2019-08-22 16:19:24 -040059uint32_t GrRenderTargetContextPriv::testingOnly_getOpsTaskID() {
60 return fRenderTargetContext->getOpsTask()->uniqueID();
Chris Daltona32a3c32017-12-05 10:05:21 -070061}
62
Brian Salomon348a0372018-10-31 10:42:18 -040063void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
Michael Ludwig7c12e282020-05-29 09:54:07 -040064 this->testingOnly_addDrawOp(nullptr, std::move(op), {});
Chris Dalton706a6ff2017-11-29 22:01:06 -070065}
66
Brian Salomon348a0372018-10-31 10:42:18 -040067void GrRenderTargetContextPriv::testingOnly_addDrawOp(
Michael Ludwig7c12e282020-05-29 09:54:07 -040068 const GrClip* clip,
Brian Salomon348a0372018-10-31 10:42:18 -040069 std::unique_ptr<GrDrawOp> op,
70 const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
Brian Salomonac70f842017-05-08 10:43:33 -040071 ASSERT_SINGLE_OWNER
Robert Phillips9eb00022020-06-30 15:30:12 -040072 if (fRenderTargetContext->fContext->abandoned()) {
Robert Phillips9da87e02019-02-04 13:26:26 -050073 fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
Brian Salomon348a0372018-10-31 10:42:18 -040074 return;
Brian Salomonac70f842017-05-08 10:43:33 -040075 }
76 SkDEBUGCODE(fRenderTargetContext->validate());
Robert Phillips0d075de2019-03-04 11:08:13 -050077 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->auditTrail(),
Brian Salomonac70f842017-05-08 10:43:33 -040078 "GrRenderTargetContext::testingOnly_addDrawOp");
Brian Salomon348a0372018-10-31 10:42:18 -040079 fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
Brian Salomonac70f842017-05-08 10:43:33 -040080}
81
joshualittf5883a62016-01-13 07:47:38 -080082#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -080083
Brian Salomon17726632017-05-12 14:09:46 -040084//////////////////////////////////////////////////////////////////////////////
85
Chris Daltona2b5b642018-06-24 13:08:57 -060086void 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 Dalton351e80c2019-01-06 22:51:00 -070093const GrCCPerFlushResources*
94GrCoverageCountingPathRenderer::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 Dalton4da70192018-06-18 09:51:36 -0600107}
108
Chris Dalton351e80c2019-01-06 22:51:00 -0700109const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const {
110 return fPathCache.get();
111}
112
113const 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
121const 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
129const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>&
130GrCCPathCache::testingOnly_getHashTable() const {
131 return fHashTable;
132}
133
134const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const {
135 return fLRU;
136}
137
138int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
139
140int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
141
Chris Dalton4da70192018-06-18 09:51:36 -0600142//////////////////////////////////////////////////////////////////////////////
143
Brian Salomon17726632017-05-12 14:09:46 -0400144#define DRAW_OP_TEST_EXTERN(Op) \
Robert Phillipsb97da532019-02-12 15:24:12 -0500145 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, \
Chris Dalton6ce447a2019-06-23 18:07:38 -0600146 GrRecordingContext*, int numSamples)
Brian Salomon17726632017-05-12 14:09:46 -0400147#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
148
Brian Salomon10978a62017-06-15 16:21:49 -0400149DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400150DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400151DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400152DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400153DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400154DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400155DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400156DRAW_OP_TEST_EXTERN(DIEllipseOp);
157DRAW_OP_TEST_EXTERN(EllipseOp);
Michael Ludwig69858532018-11-28 15:34:34 -0500158DRAW_OP_TEST_EXTERN(FillRectOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400159DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Osman4d92b892019-03-24 00:53:23 +0000160DRAW_OP_TEST_EXTERN(DrawAtlasOp);
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -0500161DRAW_OP_TEST_EXTERN(DrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400162DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400163DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400164DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400165DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400166DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400167DRAW_OP_TEST_EXTERN(RRectOp);
Chris Dalton17dc4182020-03-25 16:18:16 -0600168DRAW_OP_TEST_EXTERN(TriangulatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400169DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400170
171void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
Robert Phillips69893702019-02-22 11:16:30 -0500172 auto context = renderTargetContext->surfPriv().getContext();
Robert Phillipsb97da532019-02-12 15:24:12 -0500173 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*,
Chris Dalton6ce447a2019-06-23 18:07:38 -0600174 GrRecordingContext*, int numSamples);
Brian Salomon17726632017-05-12 14:09:46 -0400175 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400176 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400177 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 Ludwig69858532018-11-28 15:34:34 -0500185 DRAW_OP_TEST_ENTRY(FillRectOp),
Brian Salomon34169692017-08-28 15:32:01 -0400186 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
Brian Osman4d92b892019-03-24 00:53:23 +0000187 DRAW_OP_TEST_ENTRY(DrawAtlasOp),
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -0500188 DRAW_OP_TEST_ENTRY(DrawVerticesOp),
Brian Salomon34169692017-08-28 15:32:01 -0400189 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 Dalton17dc4182020-03-25 16:18:16 -0600195 DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400196 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400197 };
198
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400199 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400200 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400201 auto op = gFactories[index](
Chris Dalton6ce447a2019-06-23 18:07:38 -0600202 std::move(paint), random, context, renderTargetContext->numSamples());
Ben Wagner525e8762020-07-09 16:19:35 -0400203 if (op) {
204 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
205 }
Brian Salomon17726632017-05-12 14:09:46 -0400206}