blob: 88a3a8c3c252e90778ab6b457f43a583544e733e [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"
13#include "include/private/GrRenderTargetProxy.h"
14#include "include/private/SkTo.h"
15#include "src/core/SkMathPriv.h"
16#include "src/gpu/GrClip.h"
17#include "src/gpu/GrContextPriv.h"
18#include "src/gpu/GrDrawOpAtlas.h"
19#include "src/gpu/GrDrawingManager.h"
20#include "src/gpu/GrGpu.h"
21#include "src/gpu/GrGpuResourceCacheAccess.h"
22#include "src/gpu/GrMemoryPool.h"
23#include "src/gpu/GrRecordingContextPriv.h"
24#include "src/gpu/GrRenderTargetContext.h"
25#include "src/gpu/GrRenderTargetContextPriv.h"
26#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
Robert Phillipseaa86252016-11-08 13:49:39 +000039bool GrSurfaceProxy::isWrapped_ForTesting() const {
40 return SkToBool(fTarget);
41}
42
43bool GrRenderTargetContext::isWrapped_ForTesting() const {
44 return fRenderTargetProxy->isWrapped_ForTesting();
45}
46
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000047///////////////////////////////////////////////////////////////////////////////
48
mtkleinb9eb4ac2015-02-02 18:26:03 -080049
bsalomonddf30e62015-02-19 11:38:44 -080050///////////////////////////////////////////////////////////////////////////////
51
52void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -080053
Brian Salomon1090da62017-01-06 12:04:19 -050054#ifdef SK_DEBUG
55int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
56 int count = 0;
57 UniqueHash::ConstIter iter(&fUniqueHash);
58 while (!iter.done()) {
59 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
60 ++count;
61 }
62 ++iter;
63 }
64 return count;
65}
66#endif
67
bsalomon33435572014-11-05 14:47:41 -080068///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -080069
70#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040071 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -080072
Chris Dalton706a6ff2017-11-29 22:01:06 -070073
Chris Daltona32a3c32017-12-05 10:05:21 -070074uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
75 return fRenderTargetContext->getOpList()->uniqueID();
76}
77
Brian Salomon348a0372018-10-31 10:42:18 -040078void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
79 this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
Chris Dalton706a6ff2017-11-29 22:01:06 -070080}
81
Brian Salomon348a0372018-10-31 10:42:18 -040082void GrRenderTargetContextPriv::testingOnly_addDrawOp(
83 const GrClip& clip,
84 std::unique_ptr<GrDrawOp> op,
85 const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
Brian Salomonac70f842017-05-08 10:43:33 -040086 ASSERT_SINGLE_OWNER
Robert Phillips6a6de562019-02-15 15:19:15 -050087 if (fRenderTargetContext->fContext->priv().abandoned()) {
Robert Phillips9da87e02019-02-04 13:26:26 -050088 fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
Brian Salomon348a0372018-10-31 10:42:18 -040089 return;
Brian Salomonac70f842017-05-08 10:43:33 -040090 }
91 SkDEBUGCODE(fRenderTargetContext->validate());
Robert Phillips0d075de2019-03-04 11:08:13 -050092 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->auditTrail(),
Brian Salomonac70f842017-05-08 10:43:33 -040093 "GrRenderTargetContext::testingOnly_addDrawOp");
Brian Salomon348a0372018-10-31 10:42:18 -040094 fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
Brian Salomonac70f842017-05-08 10:43:33 -040095}
96
joshualittf5883a62016-01-13 07:47:38 -080097#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -080098
99///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700100
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400101GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const {
102 return fSurfaceFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700103}
104
Brian Salomon17726632017-05-12 14:09:46 -0400105//////////////////////////////////////////////////////////////////////////////
106
Chris Daltona2b5b642018-06-24 13:08:57 -0600107void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) {
108 // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for
109 // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true.
110 // The test is responsible to not draw any paths that CCPR is not actually capable of.
111 this->onDrawPath(args);
112}
113
Chris Dalton351e80c2019-01-06 22:51:00 -0700114const GrCCPerFlushResources*
115GrCoverageCountingPathRenderer::testingOnly_getCurrentFlushResources() {
116 SkASSERT(fFlushing);
117 if (fFlushingPaths.empty()) {
118 return nullptr;
119 }
120 // All pending paths should share the same resources.
121 const GrCCPerFlushResources* resources = fFlushingPaths.front()->fFlushResources.get();
122#ifdef SK_DEBUG
123 for (const auto& flushingPaths : fFlushingPaths) {
124 SkASSERT(flushingPaths->fFlushResources.get() == resources);
125 }
126#endif
127 return resources;
Chris Dalton4da70192018-06-18 09:51:36 -0600128}
129
Chris Dalton351e80c2019-01-06 22:51:00 -0700130const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const {
131 return fPathCache.get();
132}
133
134const GrTexture* GrCCPerFlushResources::testingOnly_frontCopyAtlasTexture() const {
135 if (fCopyAtlasStack.empty()) {
136 return nullptr;
137 }
138 const GrTextureProxy* proxy = fCopyAtlasStack.front().textureProxy();
139 return (proxy) ? proxy->peekTexture() : nullptr;
140}
141
142const GrTexture* GrCCPerFlushResources::testingOnly_frontRenderedAtlasTexture() const {
143 if (fRenderedAtlasStack.empty()) {
144 return nullptr;
145 }
146 const GrTextureProxy* proxy = fRenderedAtlasStack.front().textureProxy();
147 return (proxy) ? proxy->peekTexture() : nullptr;
148}
149
150const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>&
151GrCCPathCache::testingOnly_getHashTable() const {
152 return fHashTable;
153}
154
155const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const {
156 return fLRU;
157}
158
159int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
160
161int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
162
Chris Dalton4da70192018-06-18 09:51:36 -0600163//////////////////////////////////////////////////////////////////////////////
164
Brian Salomon17726632017-05-12 14:09:46 -0400165#define DRAW_OP_TEST_EXTERN(Op) \
Robert Phillipsb97da532019-02-12 15:24:12 -0500166 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, \
167 GrRecordingContext*, GrFSAAType)
Brian Salomon17726632017-05-12 14:09:46 -0400168#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
169
Brian Salomon10978a62017-06-15 16:21:49 -0400170DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400171DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400172DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400173DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400174DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400175DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400176DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400177DRAW_OP_TEST_EXTERN(DIEllipseOp);
178DRAW_OP_TEST_EXTERN(EllipseOp);
Michael Ludwig69858532018-11-28 15:34:34 -0500179DRAW_OP_TEST_EXTERN(FillRectOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400180DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Osman4d92b892019-03-24 00:53:23 +0000181DRAW_OP_TEST_EXTERN(DrawAtlasOp);
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -0500182DRAW_OP_TEST_EXTERN(DrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400183DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400184DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400185DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400186DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400187DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400188DRAW_OP_TEST_EXTERN(RRectOp);
Brian Salomon9530f7e2017-07-11 09:03:10 -0400189DRAW_OP_TEST_EXTERN(TesselatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400190DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400191
192void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
Robert Phillips69893702019-02-22 11:16:30 -0500193 auto context = renderTargetContext->surfPriv().getContext();
Robert Phillipsb97da532019-02-12 15:24:12 -0500194 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*,
195 GrRecordingContext*, GrFSAAType);
Brian Salomon17726632017-05-12 14:09:46 -0400196 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400197 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400198 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
199 DRAW_OP_TEST_ENTRY(AAHairlineOp),
200 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
201 DRAW_OP_TEST_ENTRY(CircleOp),
202 DRAW_OP_TEST_ENTRY(DashOp),
203 DRAW_OP_TEST_ENTRY(DefaultPathOp),
204 DRAW_OP_TEST_ENTRY(DIEllipseOp),
205 DRAW_OP_TEST_ENTRY(EllipseOp),
Michael Ludwig69858532018-11-28 15:34:34 -0500206 DRAW_OP_TEST_ENTRY(FillRectOp),
Brian Salomon34169692017-08-28 15:32:01 -0400207 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
Brian Osman4d92b892019-03-24 00:53:23 +0000208 DRAW_OP_TEST_ENTRY(DrawAtlasOp),
Robert Phillipsb6e9d3c2019-02-11 14:29:34 -0500209 DRAW_OP_TEST_ENTRY(DrawVerticesOp),
Brian Salomon34169692017-08-28 15:32:01 -0400210 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
211 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
212 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
213 DRAW_OP_TEST_ENTRY(SmallPathOp),
214 DRAW_OP_TEST_ENTRY(RegionOp),
215 DRAW_OP_TEST_ENTRY(RRectOp),
216 DRAW_OP_TEST_ENTRY(TesselatingPathOp),
217 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400218 };
219
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400220 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400221 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400222 auto op = gFactories[index](
223 std::move(paint), random, context, renderTargetContext->fsaaType());
224 SkASSERT(op);
225 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
Brian Salomon17726632017-05-12 14:09:46 -0400226}