blob: 7a0cbfe103f8c80b13fe1d10595b2d03387d5893 [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
Greg Daniel7ef28f32017-04-20 16:41:55 +00008#include "GrBackendSurface.h"
Robert Phillips646f6372018-09-25 09:31:10 -04009#include "GrClip.h"
bsalomon682c2692015-05-22 14:01:46 -070010#include "GrContextOptions.h"
Chris Daltonfe199b72017-05-05 11:26:15 -040011#include "GrContextPriv.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050012#include "GrDrawOpAtlas.h"
robertphillips77a2e522015-10-17 07:43:27 -070013#include "GrDrawingManager.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040014#include "GrGpu.h"
bsalomon3582d3e2015-02-13 14:20:05 -080015#include "GrGpuResourceCacheAccess.h"
Robert Phillipsc994a932018-06-19 13:09:54 -040016#include "GrMemoryPool.h"
Brian Salomon17726632017-05-12 14:09:46 -040017#include "GrRenderTargetContext.h"
Brian Salomon2ee084e2016-12-16 18:59:19 -050018#include "GrRenderTargetContextPriv.h"
csmartdaltonf9635992016-08-10 11:09:07 -070019#include "GrRenderTargetProxy.h"
bsalomon0ea80f42015-02-11 10:49:59 -080020#include "GrResourceCache.h"
Greg Daniel6be35232017-03-01 17:01:09 -050021#include "GrSemaphore.h"
Brian Salomon17726632017-05-12 14:09:46 -040022#include "GrSurfaceContextPriv.h"
Robert Phillips646e4292017-06-13 12:44:56 -040023#include "GrTexture.h"
Brian Osman3b655982017-03-07 16:58:08 -050024#include "SkGr.h"
Robert Phillips22f4a1f2016-12-20 08:57:26 -050025#include "SkImage_Gpu.h"
halcanary4dbbd042016-06-07 17:21:10 -070026#include "SkMathPriv.h"
mtkleinb9eb4ac2015-02-02 18:26:03 -080027#include "SkString.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040028#include "SkTo.h"
Chris Dalton4da70192018-06-18 09:51:36 -060029#include "ccpr/GrCoverageCountingPathRenderer.h"
Chris Dalton351e80c2019-01-06 22:51:00 -070030#include "ccpr/GrCCPathCache.h"
Brian Salomon17726632017-05-12 14:09:46 -040031#include "ops/GrMeshDrawOp.h"
Herb Derby081e6f32019-01-16 13:46:02 -050032#include "text/GrStrikeCache.h"
joshualitte8042922015-12-11 06:11:21 -080033#include "text/GrTextBlobCache.h"
Hal Canary8a001442018-09-19 11:31:27 -040034
Hal Canaryc640d0d2018-06-13 09:59:02 -040035#include <algorithm>
joshualitte8042922015-12-11 06:11:21 -080036
Robert Phillipseaa86252016-11-08 13:49:39 +000037bool GrSurfaceProxy::isWrapped_ForTesting() const {
38 return SkToBool(fTarget);
39}
40
41bool GrRenderTargetContext::isWrapped_ForTesting() const {
42 return fRenderTargetProxy->isWrapped_ForTesting();
43}
44
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000045///////////////////////////////////////////////////////////////////////////////
46
mtkleinb9eb4ac2015-02-02 18:26:03 -080047
bsalomonddf30e62015-02-19 11:38:44 -080048///////////////////////////////////////////////////////////////////////////////
49
50void GrResourceCache::changeTimestamp(uint32_t newTimestamp) { fTimestamp = newTimestamp; }
mtkleinb9eb4ac2015-02-02 18:26:03 -080051
Brian Salomon1090da62017-01-06 12:04:19 -050052#ifdef SK_DEBUG
53int GrResourceCache::countUniqueKeysWithTag(const char* tag) const {
54 int count = 0;
55 UniqueHash::ConstIter iter(&fUniqueHash);
56 while (!iter.done()) {
57 if (0 == strcmp(tag, (*iter).getUniqueKey().tag())) {
58 ++count;
59 }
60 ++iter;
61 }
62 return count;
63}
64#endif
65
bsalomon33435572014-11-05 14:47:41 -080066///////////////////////////////////////////////////////////////////////////////
joshualittf5883a62016-01-13 07:47:38 -080067
Chris Daltond004e0b2018-09-27 09:28:03 -060068sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createInstantiatedProxy(
69 const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit, SkBudgeted budgeted) {
70 sk_sp<GrTexture> tex;
71
72 if (SkBackingFit::kApprox == fit) {
73 tex = fResourceProvider->createApproxTexture(desc, GrResourceProvider::Flags::kNone);
74 } else {
75 tex = fResourceProvider->createTexture(desc, budgeted, GrResourceProvider::Flags::kNone);
76 }
77 if (!tex) {
78 return nullptr;
79 }
80
81 return this->createWrapped(std::move(tex), origin);
82}
83
Brian Salomon9bc76d92019-01-24 12:18:33 -050084sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createWrapped(sk_sp<GrTexture> tex,
85 GrSurfaceOrigin origin) {
86 return this->createWrapped(std::move(tex), origin);
87}
88
Chris Daltond004e0b2018-09-27 09:28:03 -060089///////////////////////////////////////////////////////////////////////////////
90
joshualittf5883a62016-01-13 07:47:38 -080091#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040092 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -080093
Chris Dalton706a6ff2017-11-29 22:01:06 -070094
Chris Daltona32a3c32017-12-05 10:05:21 -070095uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
96 return fRenderTargetContext->getOpList()->uniqueID();
97}
98
Brian Salomon348a0372018-10-31 10:42:18 -040099void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
100 this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
Chris Dalton706a6ff2017-11-29 22:01:06 -0700101}
102
Brian Salomon348a0372018-10-31 10:42:18 -0400103void GrRenderTargetContextPriv::testingOnly_addDrawOp(
104 const GrClip& clip,
105 std::unique_ptr<GrDrawOp> op,
106 const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
Brian Salomonac70f842017-05-08 10:43:33 -0400107 ASSERT_SINGLE_OWNER
108 if (fRenderTargetContext->drawingManager()->wasAbandoned()) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500109 fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
Brian Salomon348a0372018-10-31 10:42:18 -0400110 return;
Brian Salomonac70f842017-05-08 10:43:33 -0400111 }
112 SkDEBUGCODE(fRenderTargetContext->validate());
113 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
114 "GrRenderTargetContext::testingOnly_addDrawOp");
Brian Salomon348a0372018-10-31 10:42:18 -0400115 fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
Brian Salomonac70f842017-05-08 10:43:33 -0400116}
117
joshualittf5883a62016-01-13 07:47:38 -0800118#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -0800119
120///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -0700121
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400122GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const {
123 return fSurfaceFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700124}
125
Brian Salomon17726632017-05-12 14:09:46 -0400126//////////////////////////////////////////////////////////////////////////////
127
Chris Daltona2b5b642018-06-24 13:08:57 -0600128void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) {
129 // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for
130 // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true.
131 // The test is responsible to not draw any paths that CCPR is not actually capable of.
132 this->onDrawPath(args);
133}
134
Chris Dalton351e80c2019-01-06 22:51:00 -0700135const GrCCPerFlushResources*
136GrCoverageCountingPathRenderer::testingOnly_getCurrentFlushResources() {
137 SkASSERT(fFlushing);
138 if (fFlushingPaths.empty()) {
139 return nullptr;
140 }
141 // All pending paths should share the same resources.
142 const GrCCPerFlushResources* resources = fFlushingPaths.front()->fFlushResources.get();
143#ifdef SK_DEBUG
144 for (const auto& flushingPaths : fFlushingPaths) {
145 SkASSERT(flushingPaths->fFlushResources.get() == resources);
146 }
147#endif
148 return resources;
Chris Dalton4da70192018-06-18 09:51:36 -0600149}
150
Chris Dalton351e80c2019-01-06 22:51:00 -0700151const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const {
152 return fPathCache.get();
153}
154
155const GrTexture* GrCCPerFlushResources::testingOnly_frontCopyAtlasTexture() const {
156 if (fCopyAtlasStack.empty()) {
157 return nullptr;
158 }
159 const GrTextureProxy* proxy = fCopyAtlasStack.front().textureProxy();
160 return (proxy) ? proxy->peekTexture() : nullptr;
161}
162
163const GrTexture* GrCCPerFlushResources::testingOnly_frontRenderedAtlasTexture() const {
164 if (fRenderedAtlasStack.empty()) {
165 return nullptr;
166 }
167 const GrTextureProxy* proxy = fRenderedAtlasStack.front().textureProxy();
168 return (proxy) ? proxy->peekTexture() : nullptr;
169}
170
171const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>&
172GrCCPathCache::testingOnly_getHashTable() const {
173 return fHashTable;
174}
175
176const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const {
177 return fLRU;
178}
179
180int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
181
182int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
183
Chris Dalton4da70192018-06-18 09:51:36 -0600184//////////////////////////////////////////////////////////////////////////////
185
Brian Salomon17726632017-05-12 14:09:46 -0400186#define DRAW_OP_TEST_EXTERN(Op) \
Brian Salomon815486c2017-07-11 08:52:13 -0400187 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType)
Brian Salomon17726632017-05-12 14:09:46 -0400188#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
189
Brian Salomon10978a62017-06-15 16:21:49 -0400190DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400191DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400192DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400193DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400194DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400195DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400196DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400197DRAW_OP_TEST_EXTERN(DIEllipseOp);
198DRAW_OP_TEST_EXTERN(EllipseOp);
Michael Ludwig69858532018-11-28 15:34:34 -0500199DRAW_OP_TEST_EXTERN(FillRectOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400200DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Salomon0088f942017-07-12 11:51:27 -0400201DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
Brian Salomonc2f42542017-07-12 14:11:22 -0400202DRAW_OP_TEST_EXTERN(GrDrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400203DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400204DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400205DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400206DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400207DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400208DRAW_OP_TEST_EXTERN(RRectOp);
Brian Salomon9530f7e2017-07-11 09:03:10 -0400209DRAW_OP_TEST_EXTERN(TesselatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400210DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400211
212void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
213 GrContext* context = renderTargetContext->surfPriv().getContext();
Brian Salomon17726632017-05-12 14:09:46 -0400214 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType);
215 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400216 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400217 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
218 DRAW_OP_TEST_ENTRY(AAHairlineOp),
219 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
220 DRAW_OP_TEST_ENTRY(CircleOp),
221 DRAW_OP_TEST_ENTRY(DashOp),
222 DRAW_OP_TEST_ENTRY(DefaultPathOp),
223 DRAW_OP_TEST_ENTRY(DIEllipseOp),
224 DRAW_OP_TEST_ENTRY(EllipseOp),
Michael Ludwig69858532018-11-28 15:34:34 -0500225 DRAW_OP_TEST_ENTRY(FillRectOp),
Brian Salomon34169692017-08-28 15:32:01 -0400226 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
227 DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
228 DRAW_OP_TEST_ENTRY(GrDrawVerticesOp),
Brian Salomon34169692017-08-28 15:32:01 -0400229 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
230 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
231 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
232 DRAW_OP_TEST_ENTRY(SmallPathOp),
233 DRAW_OP_TEST_ENTRY(RegionOp),
234 DRAW_OP_TEST_ENTRY(RRectOp),
235 DRAW_OP_TEST_ENTRY(TesselatingPathOp),
236 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400237 };
238
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400239 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400240 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400241 auto op = gFactories[index](
242 std::move(paint), random, context, renderTargetContext->fsaaType());
243 SkASSERT(op);
244 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
Brian Salomon17726632017-05-12 14:09:46 -0400245}