blob: f697d95f959c7a0d1025e0bb8c1bdda6220b537b [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
68#define ASSERT_SINGLE_OWNER \
Robert Phillipsa90aa2b2017-04-10 08:19:26 -040069 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->singleOwner());)
joshualittf5883a62016-01-13 07:47:38 -080070
Chris Dalton706a6ff2017-11-29 22:01:06 -070071
Chris Daltona32a3c32017-12-05 10:05:21 -070072uint32_t GrRenderTargetContextPriv::testingOnly_getOpListID() {
73 return fRenderTargetContext->getOpList()->uniqueID();
74}
75
Brian Salomon348a0372018-10-31 10:42:18 -040076void GrRenderTargetContextPriv::testingOnly_addDrawOp(std::unique_ptr<GrDrawOp> op) {
77 this->testingOnly_addDrawOp(GrNoClip(), std::move(op));
Chris Dalton706a6ff2017-11-29 22:01:06 -070078}
79
Brian Salomon348a0372018-10-31 10:42:18 -040080void GrRenderTargetContextPriv::testingOnly_addDrawOp(
81 const GrClip& clip,
82 std::unique_ptr<GrDrawOp> op,
83 const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
Brian Salomonac70f842017-05-08 10:43:33 -040084 ASSERT_SINGLE_OWNER
Robert Phillipsa9162df2019-02-11 14:12:03 -050085 if (fRenderTargetContext->fContext->abandoned()) {
Robert Phillips9da87e02019-02-04 13:26:26 -050086 fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
Brian Salomon348a0372018-10-31 10:42:18 -040087 return;
Brian Salomonac70f842017-05-08 10:43:33 -040088 }
89 SkDEBUGCODE(fRenderTargetContext->validate());
90 GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
91 "GrRenderTargetContext::testingOnly_addDrawOp");
Brian Salomon348a0372018-10-31 10:42:18 -040092 fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn);
Brian Salomonac70f842017-05-08 10:43:33 -040093}
94
joshualittf5883a62016-01-13 07:47:38 -080095#undef ASSERT_SINGLE_OWNER
joshualittf5883a62016-01-13 07:47:38 -080096
97///////////////////////////////////////////////////////////////////////////////
csmartdaltonf9635992016-08-10 11:09:07 -070098
Robert Phillipsfe0253f2018-03-16 16:47:25 -040099GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const {
100 return fSurfaceFlags;
csmartdaltonf9635992016-08-10 11:09:07 -0700101}
102
Brian Salomon17726632017-05-12 14:09:46 -0400103//////////////////////////////////////////////////////////////////////////////
104
Chris Daltona2b5b642018-06-24 13:08:57 -0600105void GrCoverageCountingPathRenderer::testingOnly_drawPathDirectly(const DrawPathArgs& args) {
106 // Call onDrawPath() directly: We want to test paths that might fail onCanDrawPath() simply for
107 // performance reasons, and GrPathRenderer::drawPath() assert that this call returns true.
108 // The test is responsible to not draw any paths that CCPR is not actually capable of.
109 this->onDrawPath(args);
110}
111
Chris Dalton351e80c2019-01-06 22:51:00 -0700112const GrCCPerFlushResources*
113GrCoverageCountingPathRenderer::testingOnly_getCurrentFlushResources() {
114 SkASSERT(fFlushing);
115 if (fFlushingPaths.empty()) {
116 return nullptr;
117 }
118 // All pending paths should share the same resources.
119 const GrCCPerFlushResources* resources = fFlushingPaths.front()->fFlushResources.get();
120#ifdef SK_DEBUG
121 for (const auto& flushingPaths : fFlushingPaths) {
122 SkASSERT(flushingPaths->fFlushResources.get() == resources);
123 }
124#endif
125 return resources;
Chris Dalton4da70192018-06-18 09:51:36 -0600126}
127
Chris Dalton351e80c2019-01-06 22:51:00 -0700128const GrCCPathCache* GrCoverageCountingPathRenderer::testingOnly_getPathCache() const {
129 return fPathCache.get();
130}
131
132const GrTexture* GrCCPerFlushResources::testingOnly_frontCopyAtlasTexture() const {
133 if (fCopyAtlasStack.empty()) {
134 return nullptr;
135 }
136 const GrTextureProxy* proxy = fCopyAtlasStack.front().textureProxy();
137 return (proxy) ? proxy->peekTexture() : nullptr;
138}
139
140const GrTexture* GrCCPerFlushResources::testingOnly_frontRenderedAtlasTexture() const {
141 if (fRenderedAtlasStack.empty()) {
142 return nullptr;
143 }
144 const GrTextureProxy* proxy = fRenderedAtlasStack.front().textureProxy();
145 return (proxy) ? proxy->peekTexture() : nullptr;
146}
147
148const SkTHashTable<GrCCPathCache::HashNode, const GrCCPathCache::Key&>&
149GrCCPathCache::testingOnly_getHashTable() const {
150 return fHashTable;
151}
152
153const SkTInternalLList<GrCCPathCacheEntry>& GrCCPathCache::testingOnly_getLRU() const {
154 return fLRU;
155}
156
157int GrCCPathCacheEntry::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
158
159int GrCCCachedAtlas::testingOnly_peekOnFlushRefCnt() const { return fOnFlushRefCnt; }
160
Chris Dalton4da70192018-06-18 09:51:36 -0600161//////////////////////////////////////////////////////////////////////////////
162
Brian Salomon17726632017-05-12 14:09:46 -0400163#define DRAW_OP_TEST_EXTERN(Op) \
Brian Salomon815486c2017-07-11 08:52:13 -0400164 extern std::unique_ptr<GrDrawOp> Op##__Test(GrPaint&&, SkRandom*, GrContext*, GrFSAAType)
Brian Salomon17726632017-05-12 14:09:46 -0400165#define DRAW_OP_TEST_ENTRY(Op) Op##__Test
166
Brian Salomon10978a62017-06-15 16:21:49 -0400167DRAW_OP_TEST_EXTERN(AAConvexPathOp);
Brian Salomonb2955732017-07-13 16:42:55 -0400168DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
Brian Salomona531f252017-07-07 13:29:28 -0400169DRAW_OP_TEST_EXTERN(AAHairlineOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400170DRAW_OP_TEST_EXTERN(AAStrokeRectOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400171DRAW_OP_TEST_EXTERN(CircleOp);
Brian Salomon98222ac2017-07-12 15:27:54 -0400172DRAW_OP_TEST_EXTERN(DashOp);
Brian Salomonee3e0ba2017-07-13 16:40:46 -0400173DRAW_OP_TEST_EXTERN(DefaultPathOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400174DRAW_OP_TEST_EXTERN(DIEllipseOp);
175DRAW_OP_TEST_EXTERN(EllipseOp);
Michael Ludwig69858532018-11-28 15:34:34 -0500176DRAW_OP_TEST_EXTERN(FillRectOp);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400177DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
Brian Salomon0088f942017-07-12 11:51:27 -0400178DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
Brian Salomonc2f42542017-07-12 14:11:22 -0400179DRAW_OP_TEST_EXTERN(GrDrawVerticesOp);
Brian Salomon815486c2017-07-11 08:52:13 -0400180DRAW_OP_TEST_EXTERN(NonAALatticeOp);
Brian Salomonbaaf4392017-06-15 09:59:23 -0400181DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
Brian Salomon05969092017-07-13 11:20:51 -0400182DRAW_OP_TEST_EXTERN(ShadowRRectOp);
Brian Salomonfebbd232017-07-11 15:52:02 -0400183DRAW_OP_TEST_EXTERN(SmallPathOp);
Brian Salomonf0366322017-07-11 15:53:05 -0400184DRAW_OP_TEST_EXTERN(RegionOp);
Brian Salomon05441c42017-05-15 16:45:49 -0400185DRAW_OP_TEST_EXTERN(RRectOp);
Brian Salomon9530f7e2017-07-11 09:03:10 -0400186DRAW_OP_TEST_EXTERN(TesselatingPathOp);
Brian Salomon34169692017-08-28 15:32:01 -0400187DRAW_OP_TEST_EXTERN(TextureOp);
Brian Salomon17726632017-05-12 14:09:46 -0400188
189void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
190 GrContext* context = renderTargetContext->surfPriv().getContext();
Brian Salomon17726632017-05-12 14:09:46 -0400191 using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType);
192 static constexpr MakeDrawOpFn* gFactories[] = {
Brian Salomon34169692017-08-28 15:32:01 -0400193 DRAW_OP_TEST_ENTRY(AAConvexPathOp),
Brian Salomon34169692017-08-28 15:32:01 -0400194 DRAW_OP_TEST_ENTRY(AAFlatteningConvexPathOp),
195 DRAW_OP_TEST_ENTRY(AAHairlineOp),
196 DRAW_OP_TEST_ENTRY(AAStrokeRectOp),
197 DRAW_OP_TEST_ENTRY(CircleOp),
198 DRAW_OP_TEST_ENTRY(DashOp),
199 DRAW_OP_TEST_ENTRY(DefaultPathOp),
200 DRAW_OP_TEST_ENTRY(DIEllipseOp),
201 DRAW_OP_TEST_ENTRY(EllipseOp),
Michael Ludwig69858532018-11-28 15:34:34 -0500202 DRAW_OP_TEST_ENTRY(FillRectOp),
Brian Salomon34169692017-08-28 15:32:01 -0400203 DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
204 DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
205 DRAW_OP_TEST_ENTRY(GrDrawVerticesOp),
Brian Salomon34169692017-08-28 15:32:01 -0400206 DRAW_OP_TEST_ENTRY(NonAALatticeOp),
207 DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
208 DRAW_OP_TEST_ENTRY(ShadowRRectOp),
209 DRAW_OP_TEST_ENTRY(SmallPathOp),
210 DRAW_OP_TEST_ENTRY(RegionOp),
211 DRAW_OP_TEST_ENTRY(RRectOp),
212 DRAW_OP_TEST_ENTRY(TesselatingPathOp),
213 DRAW_OP_TEST_ENTRY(TextureOp),
Brian Salomon17726632017-05-12 14:09:46 -0400214 };
215
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400216 static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
Brian Salomon17726632017-05-12 14:09:46 -0400217 uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
Brian Salomonfc26f3c2017-07-14 15:27:56 -0400218 auto op = gFactories[index](
219 std::move(paint), random, context, renderTargetContext->fsaaType());
220 SkASSERT(op);
221 renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
Brian Salomon17726632017-05-12 14:09:46 -0400222}