blob: 465acf141ccb3537baf1e94115404fc6c2efaf5c [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"
11#include "include/gpu/GrTexture.h"
12#include "include/private/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/private/SkTo.h"
14#include "src/core/SkMathPriv.h"
15#include "src/gpu/GrClip.h"
16#include "src/gpu/GrContextPriv.h"
17#include "src/gpu/GrDrawOpAtlas.h"
18#include "src/gpu/GrDrawingManager.h"
19#include "src/gpu/GrGpu.h"
20#include "src/gpu/GrGpuResourceCacheAccess.h"
21#include "src/gpu/GrMemoryPool.h"
22#include "src/gpu/GrRecordingContextPriv.h"
23#include "src/gpu/GrRenderTargetContext.h"
24#include "src/gpu/GrRenderTargetContextPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040025#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050026#include "src/gpu/GrResourceCache.h"
27#include "src/gpu/GrSemaphore.h"
28#include "src/gpu/GrSurfaceContextPriv.h"
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 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;
46 UniqueHash::ConstIter iter(&fUniqueHash);
47 while (!iter.done()) {
48 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
49 ++count;
50 }
51 ++iter;
52 }
53 return count;
54}
55#endif
56
bsalomon33435572014-11-05 14:47:41 -080057///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -080058
59#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040060 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -080061
Chris Dalton706a6ff2017-11-29 22:01:06 -070062
Chris Daltona32a3c32017-12-05 10:05:21 -070063uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
64 return fRenderTargetContext->getOpList()->uniqueID();
65}
66
Brian Salomon348a0372018-10-31 10:42:18 -040067void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
68 this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
Chris Dalton706a6ff2017-11-29 22:01:06 -070069}
70
Brian Salomon348a0372018-10-31 10:42:18 -040071void GrRenderTargetContextPriv::testingOnly_addDrawOp(
72 const GrClip& clip,
73 std::unique_ptr<GrDrawOp> op,
74 const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
Brian Salomonac70f842017-05-08 10:43:33 -040075 ASSERT_SINGLE_OWNER
Robert Phillips6a6de562019-02-15 15:19:15 -050076 if (fRenderTargetContext->fContext->priv().abandoned()) {
Robert Phillips9da87e02019-02-04 13:26:26 -050077 fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
Brian Salomon348a0372018-10-31 10:42:18 -040078 return;
Brian Salomonac70f842017-05-08 10:43:33 -040079 }
80 SkDEBUGCODE(fRenderTargetContext->validate());
Robert Phillips0d075de2019-03-04 11:08:13 -050081 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->auditTrail(),
Brian Salomonac70f842017-05-08 10:43:33 -040082 "GrRenderTargetContext::testingOnly_addDrawOp");
Brian Salomon348a0372018-10-31 10:42:18 -040083 fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
Brian Salomonac70f842017-05-08 10:43:33 -040084}
85
joshualittf5883a62016-01-13 07:47:38 -080086#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -080087
Brian Salomon17726632017-05-12 14:09:46 -040088//////////////////////////////////////////////////////////////////////////////
89
Chris Daltona2b5b642018-06-24 13:08:57 -060090void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) {
91 // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for
92 // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true.
93 // The test is responsible to not draw any paths that CCPR is not actually capable of.
94 this->onDrawPath(args);
95}
96
Chris Dalton351e80c2019-01-06 22:51:00 -070097const GrCCPerFlushResources*
98GrCoverageCountingPathRenderer::testingOnly_getCurrentFlushResources() {
99 SkASSERT(fFlushing);
100 if (fFlushingPaths.empty()) {
101 return nullptr;
102 }
103 // All pending paths should share the same resources.
104 const GrCCPerFlushResources* resources = fFlushingPaths.front()->fFlushResources.get();
105#ifdef SK_DEBUG
106 for (const auto& flushingPaths : fFlushingPaths) {
107 SkASSERT(flushingPaths->fFlushResources.get() == resources);
108 }
109#endif
110 return resources;
Chris Dalton4da70192018-06-18 09:51:36 -0600111}
112
Chris Dalton351e80c2019-01-06 22:51:00 -0700113const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const {
114 return fPathCache.get();
115}
116
117const GrTexture* GrCCPerFlushResources::testingOnly_frontCopyAtlasTexture() const {
118 if (fCopyAtlasStack.empty()) {
119 return nullptr;
120 }
121 const GrTextureProxy* proxy = fCopyAtlasStack.front().textureProxy();
122 return (proxy) ? proxy->peekTexture() : nullptr;
123}
124
125const GrTexture* GrCCPerFlushResources::testingOnly_frontRenderedAtlasTexture() const {
126 if (fRenderedAtlasStack.empty()) {
127 return nullptr;
128 }
129 const GrTextureProxy* proxy = fRenderedAtlasStack.front().textureProxy();
130 return (proxy) ? proxy->peekTexture() : nullptr;
131}
132
133const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>&
134GrCCPathCache::testingOnly_getHashTable() const {
135 return fHashTable;
136}
137
138const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const {
139 return fLRU;
140}
141
142int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
143
144int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
145
Chris Dalton4da70192018-06-18 09:51:36 -0600146//////////////////////////////////////////////////////////////////////////////
147
Brian Salomon17726632017-05-12 14:09:46 -0400148#define DRAW_OP_TEST_EXTERN(Op) \
Robert Phillipsb97da532019-02-12 15:24:12 -0500149 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, \
Chris Dalton6ce447a2019-06-23 18:07:38 -0600150 GrRecordingContext*, int numSamples)
Brian Salomon17726632017-05-12 14:09:46 -0400151#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
152
Brian Salomon10978a62017-06-15 16:21:49 -0400153DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400154DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400155DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400156DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400157DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400158DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400159DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400160DRAW_OP_TEST_EXTERN(DIEllipseOp);
161DRAW_OP_TEST_EXTERN(EllipseOp);
Michael Ludwig69858532018-11-28 15:34:34 -0500162DRAW_OP_TEST_EXTERN(FillRectOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400163DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Osman4d92b892019-03-24 00:53:23 +0000164DRAW_OP_TEST_EXTERN(DrawAtlasOp);
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -0500165DRAW_OP_TEST_EXTERN(DrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400166DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400167DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400168DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400169DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400170DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400171DRAW_OP_TEST_EXTERN(RRectOp);
Brian Salomon9530f7e2017-07-11 09:03:10 -0400172DRAW_OP_TEST_EXTERN(TesselatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400173DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400174
175void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
Robert Phillips69893702019-02-22 11:16:30 -0500176 auto context = renderTargetContext->surfPriv().getContext();
Robert Phillipsb97da532019-02-12 15:24:12 -0500177 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*,
Chris Dalton6ce447a2019-06-23 18:07:38 -0600178 GrRecordingContext*, int numSamples);
Brian Salomon17726632017-05-12 14:09:46 -0400179 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400180 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400181 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
182 DRAW_OP_TEST_ENTRY(AAHairlineOp),
183 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
184 DRAW_OP_TEST_ENTRY(CircleOp),
185 DRAW_OP_TEST_ENTRY(DashOp),
186 DRAW_OP_TEST_ENTRY(DefaultPathOp),
187 DRAW_OP_TEST_ENTRY(DIEllipseOp),
188 DRAW_OP_TEST_ENTRY(EllipseOp),
Michael Ludwig69858532018-11-28 15:34:34 -0500189 DRAW_OP_TEST_ENTRY(FillRectOp),
Brian Salomon34169692017-08-28 15:32:01 -0400190 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
Brian Osman4d92b892019-03-24 00:53:23 +0000191 DRAW_OP_TEST_ENTRY(DrawAtlasOp),
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -0500192 DRAW_OP_TEST_ENTRY(DrawVerticesOp),
Brian Salomon34169692017-08-28 15:32:01 -0400193 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
194 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
195 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
196 DRAW_OP_TEST_ENTRY(SmallPathOp),
197 DRAW_OP_TEST_ENTRY(RegionOp),
198 DRAW_OP_TEST_ENTRY(RRectOp),
199 DRAW_OP_TEST_ENTRY(TesselatingPathOp),
200 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400201 };
202
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400203 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400204 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400205 auto op = gFactories[index](
Chris Dalton6ce447a2019-06-23 18:07:38 -0600206 std::move(paint), random, context, renderTargetContext->numSamples());
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400207 SkASSERT(op);
208 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
Brian Salomon17726632017-05-12 14:09:46 -0400209}