blob: c5d17977d3758d0ed9e98bf341445fb881fb57c5 [file] [log] [blame]
Robert Phillips5af44de2017-07-18 14:49:38 -04001/*
2 * Copyright 2017 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 "src/gpu/GrResourceAllocator.h"
Robert Phillips5af44de2017-07-18 14:49:38 -04009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrGpuResourcePriv.h"
Greg Danielf41b2bd2019-08-22 16:19:24 -040011#include "src/gpu/GrOpsTask.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrResourceProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040014#include "src/gpu/GrSurfaceProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrSurfaceProxyPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040016#include "src/gpu/GrTextureProxy.h"
Robert Phillips5af44de2017-07-18 14:49:38 -040017
Robert Phillipsda1be462018-07-27 07:18:06 -040018#if GR_TRACK_INTERVAL_CREATION
Mike Klein0ec1c572018-12-04 11:52:51 -050019 #include <atomic>
20
21 uint32_t GrResourceAllocator::Interval::CreateUniqueID() {
22 static std::atomic<uint32_t> nextID{1};
23 uint32_t id;
24 do {
Adlai Holler4888cda2020-11-06 16:37:37 -050025 id = nextID.fetch_add(1, std::memory_order_relaxed);
Mike Klein0ec1c572018-12-04 11:52:51 -050026 } while (id == SK_InvalidUniqueID);
27 return id;
28 }
Robert Phillipsda1be462018-07-27 07:18:06 -040029#endif
30
Robert Phillips5b65a842017-11-13 15:48:12 -050031void GrResourceAllocator::Interval::assign(sk_sp<GrSurface> s) {
32 SkASSERT(!fAssignedSurface);
33 fAssignedSurface = s;
34 fProxy->priv().assign(std::move(s));
35}
36
Robert Phillipsc73666f2019-04-24 08:49:48 -040037void GrResourceAllocator::determineRecyclability() {
38 for (Interval* cur = fIntvlList.peekHead(); cur; cur = cur->next()) {
39 if (cur->proxy()->canSkipResourceAllocator()) {
40 // These types of proxies can slip in here if they require a stencil buffer
41 continue;
42 }
43
Brian Salomon557e8122019-10-24 10:37:08 -040044 if (!cur->proxy()->refCntGreaterThan(cur->uses())) {
Robert Phillipsc73666f2019-04-24 08:49:48 -040045 // All the refs on the proxy are known to the resource allocator thus no one
46 // should be holding onto it outside of Ganesh.
Robert Phillipsc73666f2019-04-24 08:49:48 -040047 cur->markAsRecyclable();
48 }
49 }
50}
51
Robert Phillips5b65a842017-11-13 15:48:12 -050052GrResourceAllocator::~GrResourceAllocator() {
Robert Phillips5b65a842017-11-13 15:48:12 -050053 SkASSERT(fIntvlList.empty());
54 SkASSERT(fActiveIntvls.empty());
55 SkASSERT(!fIntvlHash.count());
Robert Phillips5b65a842017-11-13 15:48:12 -050056}
57
Adlai Holler7f7a5df2021-02-09 17:41:10 +000058void GrResourceAllocator::addInterval(GrSurfaceProxy* proxy, unsigned int start, unsigned int end,
59 ActualUse actualUse
Chris Dalton8816b932017-11-29 16:48:25 -070060 SkDEBUGCODE(, bool isDirectDstRead)) {
Brian Salomonbeb7f522019-08-30 16:19:42 -040061 SkASSERT(start <= end);
62 SkASSERT(!fAssigned); // We shouldn't be adding any intervals after (or during) assignment
Robert Phillips5f78adf2019-04-22 12:41:39 -040063
Chris Dalton97155592019-06-13 13:40:20 -060064 if (proxy->canSkipResourceAllocator()) {
Robert Phillips5f78adf2019-04-22 12:41:39 -040065 return;
66 }
67
Brian Salomon9cadc312018-12-05 15:09:19 -050068 // If a proxy is read only it must refer to a texture with specific content that cannot be
69 // recycled. We don't need to assign a texture to it and no other proxy can be instantiated
70 // with the same texture.
71 if (proxy->readOnly()) {
Brian Salomonbeb7f522019-08-30 16:19:42 -040072 if (proxy->isLazy() && !proxy->priv().doLazyInstantiation(fResourceProvider)) {
Adlai Holler19fd5142021-03-08 10:19:30 -070073 fFailedInstantiation = true;
Brian Salomon9cadc312018-12-05 15:09:19 -050074 } else {
Brian Salomonbeb7f522019-08-30 16:19:42 -040075 // Since we aren't going to add an interval we won't revisit this proxy in assign(). So
76 // must already be instantiated or it must be a lazy proxy that we instantiated above.
77 SkASSERT(proxy->isInstantiated());
Brian Salomon9cadc312018-12-05 15:09:19 -050078 }
Brian Salomonbeb7f522019-08-30 16:19:42 -040079 return;
80 }
81 if (Interval* intvl = fIntvlHash.find(proxy->uniqueID().asUInt())) {
82 // Revise the interval for an existing use
83#ifdef SK_DEBUG
Adlai Holler9e2c50e2021-02-09 14:41:52 -050084 if (0 == start && 0 == end) {
85 // This interval is for the initial upload to a deferred proxy. Due to the vagaries
86 // of how deferred proxies are collected they can appear as uploads multiple times
87 // in a single opsTasks' list and as uploads in several opsTasks.
88 SkASSERT(0 == intvl->start());
89 } else if (isDirectDstRead) {
Brian Salomonbeb7f522019-08-30 16:19:42 -040090 // Direct reads from the render target itself should occur w/in the existing
91 // interval
92 SkASSERT(intvl->start() <= start && intvl->end() >= end);
93 } else {
94 SkASSERT(intvl->end() <= start && intvl->end() <= end);
95 }
96#endif
Adlai Holler7f7a5df2021-02-09 17:41:10 +000097 if (ActualUse::kYes == actualUse) {
98 intvl->addUse();
99 }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400100 intvl->extendEnd(end);
101 return;
102 }
Adlai Hollerda163672021-03-15 11:03:37 -0400103 Interval* newIntvl = fIntervalAllocator.make<Interval>(proxy, start, end);
Brian Salomonc6093532018-12-05 21:34:36 +0000104
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000105 if (ActualUse::kYes == actualUse) {
106 newIntvl->addUse();
107 }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400108 fIntvlList.insertByIncreasingStart(newIntvl);
109 fIntvlHash.add(newIntvl);
Robert Phillips5af44de2017-07-18 14:49:38 -0400110}
111
112GrResourceAllocator::Interval* GrResourceAllocator::IntervalList::popHead() {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400113 SkDEBUGCODE(this->validate());
114
Robert Phillips5af44de2017-07-18 14:49:38 -0400115 Interval* temp = fHead;
116 if (temp) {
Robert Phillipsf8e25022017-11-08 15:24:31 -0500117 fHead = temp->next();
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400118 if (!fHead) {
119 fTail = nullptr;
120 }
121 temp->setNext(nullptr);
Robert Phillips5af44de2017-07-18 14:49:38 -0400122 }
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400123
124 SkDEBUGCODE(this->validate());
Robert Phillips5af44de2017-07-18 14:49:38 -0400125 return temp;
126}
127
128// TODO: fuse this with insertByIncreasingEnd
129void GrResourceAllocator::IntervalList::insertByIncreasingStart(Interval* intvl) {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400130 SkDEBUGCODE(this->validate());
131 SkASSERT(!intvl->next());
132
Robert Phillips5af44de2017-07-18 14:49:38 -0400133 if (!fHead) {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400134 // 14%
135 fHead = fTail = intvl;
Robert Phillipsf8e25022017-11-08 15:24:31 -0500136 } else if (intvl->start() <= fHead->start()) {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400137 // 3%
Robert Phillipsf8e25022017-11-08 15:24:31 -0500138 intvl->setNext(fHead);
Robert Phillips5af44de2017-07-18 14:49:38 -0400139 fHead = intvl;
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400140 } else if (fTail->start() <= intvl->start()) {
141 // 83%
142 fTail->setNext(intvl);
143 fTail = intvl;
Robert Phillips5af44de2017-07-18 14:49:38 -0400144 } else {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400145 // almost never
Robert Phillips5af44de2017-07-18 14:49:38 -0400146 Interval* prev = fHead;
Robert Phillipsf8e25022017-11-08 15:24:31 -0500147 Interval* next = prev->next();
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400148 for (; intvl->start() > next->start(); prev = next, next = next->next()) {
Robert Phillips5af44de2017-07-18 14:49:38 -0400149 }
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400150
151 SkASSERT(next);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500152 intvl->setNext(next);
153 prev->setNext(intvl);
Robert Phillips5af44de2017-07-18 14:49:38 -0400154 }
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400155
156 SkDEBUGCODE(this->validate());
Robert Phillips5af44de2017-07-18 14:49:38 -0400157}
158
159// TODO: fuse this with insertByIncreasingStart
160void GrResourceAllocator::IntervalList::insertByIncreasingEnd(Interval* intvl) {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400161 SkDEBUGCODE(this->validate());
162 SkASSERT(!intvl->next());
163
Robert Phillips5af44de2017-07-18 14:49:38 -0400164 if (!fHead) {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400165 // 14%
166 fHead = fTail = intvl;
Robert Phillipsf8e25022017-11-08 15:24:31 -0500167 } else if (intvl->end() <= fHead->end()) {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400168 // 64%
Robert Phillipsf8e25022017-11-08 15:24:31 -0500169 intvl->setNext(fHead);
Robert Phillips5af44de2017-07-18 14:49:38 -0400170 fHead = intvl;
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400171 } else if (fTail->end() <= intvl->end()) {
172 // 3%
173 fTail->setNext(intvl);
174 fTail = intvl;
Robert Phillips5af44de2017-07-18 14:49:38 -0400175 } else {
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400176 // 19% but 81% of those land right after the list's head
Robert Phillips5af44de2017-07-18 14:49:38 -0400177 Interval* prev = fHead;
Robert Phillipsf8e25022017-11-08 15:24:31 -0500178 Interval* next = prev->next();
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400179 for (; intvl->end() > next->end(); prev = next, next = next->next()) {
Robert Phillips5af44de2017-07-18 14:49:38 -0400180 }
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400181
182 SkASSERT(next);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500183 intvl->setNext(next);
184 prev->setNext(intvl);
Robert Phillips5af44de2017-07-18 14:49:38 -0400185 }
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400186
187 SkDEBUGCODE(this->validate());
Robert Phillips5af44de2017-07-18 14:49:38 -0400188}
189
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400190#ifdef SK_DEBUG
191void GrResourceAllocator::IntervalList::validate() const {
192 SkASSERT(SkToBool(fHead) == SkToBool(fTail));
193
194 Interval* prev = nullptr;
195 for (Interval* cur = fHead; cur; prev = cur, cur = cur->next()) {
196 }
197
198 SkASSERT(fTail == prev);
199}
200#endif
Robert Phillips4150eea2018-02-07 17:08:21 -0500201
202 GrResourceAllocator::Interval* GrResourceAllocator::IntervalList::detachAll() {
203 Interval* tmp = fHead;
204 fHead = nullptr;
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400205 fTail = nullptr;
Robert Phillips4150eea2018-02-07 17:08:21 -0500206 return tmp;
207}
208
Robert Phillips5af44de2017-07-18 14:49:38 -0400209// 'surface' can be reused. Add it back to the free pool.
Robert Phillips715d08c2018-07-18 13:56:48 -0400210void GrResourceAllocator::recycleSurface(sk_sp<GrSurface> surface) {
Robert Phillips57aa3672017-07-21 11:38:13 -0400211 const GrScratchKey &key = surface->resourcePriv().getScratchKey();
212
213 if (!key.isValid()) {
214 return; // can't do it w/o a valid scratch key
215 }
216
Robert Phillipsf8e25022017-11-08 15:24:31 -0500217 if (surface->getUniqueKey().isValid()) {
218 // If the surface has a unique key we throw it back into the resource cache.
219 // If things get really tight 'findSurfaceFor' may pull it back out but there is
220 // no need to have it in tight rotation.
221 return;
222 }
223
Robert Phillips715d08c2018-07-18 13:56:48 -0400224#if GR_ALLOCATION_SPEW
225 SkDebugf("putting surface %d back into pool\n", surface->uniqueID().asUInt());
226#endif
Robert Phillips57aa3672017-07-21 11:38:13 -0400227 // TODO: fix this insertion so we get a more LRU-ish behavior
Robert Phillips5b65a842017-11-13 15:48:12 -0500228 fFreePool.insert(key, surface.release());
Robert Phillips5af44de2017-07-18 14:49:38 -0400229}
230
231// First try to reuse one of the recently allocated/used GrSurfaces in the free pool.
232// If we can't find a useable one, create a new one.
Chris Dalton0b68dda2019-11-07 21:08:03 -0700233sk_sp<GrSurface> GrResourceAllocator::findSurfaceFor(const GrSurfaceProxy* proxy) {
Robert Phillips0790f8a2018-09-18 13:11:03 -0400234 if (proxy->asTextureProxy() && proxy->asTextureProxy()->getUniqueKey().isValid()) {
235 // First try to reattach to a cached version if the proxy is uniquely keyed
Chris Dalton0b68dda2019-11-07 21:08:03 -0700236 if (sk_sp<GrSurface> surface = fResourceProvider->findByUniqueKey<GrSurface>(
237 proxy->asTextureProxy()->getUniqueKey())) {
Robert Phillips0790f8a2018-09-18 13:11:03 -0400238 return surface;
239 }
240 }
241
Robert Phillips57aa3672017-07-21 11:38:13 -0400242 // First look in the free pool
243 GrScratchKey key;
Robert Phillips5af44de2017-07-18 14:49:38 -0400244
Greg Danield51fa2f2020-01-22 16:53:38 -0500245 proxy->priv().computeScratchKey(*fResourceProvider->caps(), &key);
Robert Phillips57aa3672017-07-21 11:38:13 -0400246
Robert Phillips10d17212019-04-24 14:09:10 -0400247 auto filter = [] (const GrSurface* s) {
248 return true;
Robert Phillipsf8e25022017-11-08 15:24:31 -0500249 };
250 sk_sp<GrSurface> surface(fFreePool.findAndRemove(key, filter));
Robert Phillips57aa3672017-07-21 11:38:13 -0400251 if (surface) {
Robert Phillipsf8e25022017-11-08 15:24:31 -0500252 if (SkBudgeted::kYes == proxy->isBudgeted() &&
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500253 GrBudgetedType::kBudgeted != surface->resourcePriv().budgetedType()) {
Robert Phillipsf8e25022017-11-08 15:24:31 -0500254 // This gets the job done but isn't quite correct. It would be better to try to
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500255 // match budgeted proxies w/ budgeted surfaces and unbudgeted w/ unbudgeted.
Robert Phillipsf8e25022017-11-08 15:24:31 -0500256 surface->resourcePriv().makeBudgeted();
257 }
Robert Phillips0790f8a2018-09-18 13:11:03 -0400258 SkASSERT(!surface->getUniqueKey().isValid());
Robert Phillipsf8e25022017-11-08 15:24:31 -0500259 return surface;
Robert Phillips57aa3672017-07-21 11:38:13 -0400260 }
261
262 // Failing that, try to grab a new one from the resource cache
Robert Phillips5af44de2017-07-18 14:49:38 -0400263 return proxy->priv().createSurface(fResourceProvider);
264}
265
266// Remove any intervals that end before the current index. Return their GrSurfaces
Robert Phillips39667382019-04-17 16:03:30 -0400267// to the free pool if possible.
Robert Phillips5af44de2017-07-18 14:49:38 -0400268void GrResourceAllocator::expire(unsigned int curIndex) {
Robert Phillipsf8e25022017-11-08 15:24:31 -0500269 while (!fActiveIntvls.empty() && fActiveIntvls.peekHead()->end() < curIndex) {
Robert Phillips5af44de2017-07-18 14:49:38 -0400270 Interval* temp = fActiveIntvls.popHead();
Robert Phillipsdf25e3a2018-08-08 12:48:40 -0400271 SkASSERT(!temp->next());
Robert Phillips5b65a842017-11-13 15:48:12 -0500272
273 if (temp->wasAssignedSurface()) {
Robert Phillips715d08c2018-07-18 13:56:48 -0400274 sk_sp<GrSurface> surface = temp->detachSurface();
275
Robert Phillipsc73666f2019-04-24 08:49:48 -0400276 if (temp->isRecyclable()) {
Robert Phillips715d08c2018-07-18 13:56:48 -0400277 this->recycleSurface(std::move(surface));
278 }
Robert Phillips5b65a842017-11-13 15:48:12 -0500279 }
Robert Phillips5af44de2017-07-18 14:49:38 -0400280 }
281}
282
Adlai Holler19fd5142021-03-08 10:19:30 -0700283bool GrResourceAllocator::assign() {
Robert Phillips5f78adf2019-04-22 12:41:39 -0400284 fIntvlHash.reset(); // we don't need the interval hash anymore
285
Robert Phillips5af44de2017-07-18 14:49:38 -0400286 SkDEBUGCODE(fAssigned = true;)
287
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500288 if (fIntvlList.empty()) {
Adlai Holler19fd5142021-03-08 10:19:30 -0700289 return !fFailedInstantiation; // no resources to assign
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500290 }
291
Robert Phillips715d08c2018-07-18 13:56:48 -0400292#if GR_ALLOCATION_SPEW
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500293 SkDebugf("assigning %d ops\n", fNumOps);
Robert Phillips715d08c2018-07-18 13:56:48 -0400294 this->dumpIntervals();
295#endif
Robert Phillipseafd48a2017-11-16 07:52:08 -0500296
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500297 // TODO: Can this be done inline during the main iteration?
298 this->determineRecyclability();
299
Adlai Holler19fd5142021-03-08 10:19:30 -0700300 Interval* cur = nullptr;
Adlai Holler043a7372021-03-08 17:35:27 -0700301 while ((cur = fIntvlList.popHead())) {
Robert Phillipsf8e25022017-11-08 15:24:31 -0500302 this->expire(cur->start());
Robert Phillips57aa3672017-07-21 11:38:13 -0400303
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400304 if (cur->proxy()->isInstantiated()) {
Robert Phillips57aa3672017-07-21 11:38:13 -0400305 fActiveIntvls.insertByIncreasingEnd(cur);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500306
Robert Phillips57aa3672017-07-21 11:38:13 -0400307 continue;
308 }
309
Brian Salomonbeb7f522019-08-30 16:19:42 -0400310 if (cur->proxy()->isLazy()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500311 if (!cur->proxy()->priv().doLazyInstantiation(fResourceProvider)) {
Adlai Holler19fd5142021-03-08 10:19:30 -0700312 fFailedInstantiation = true;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500313 }
Chris Dalton0b68dda2019-11-07 21:08:03 -0700314 } else if (sk_sp<GrSurface> surface = this->findSurfaceFor(cur->proxy())) {
Robert Phillipsf8e25022017-11-08 15:24:31 -0500315 // TODO: make getUniqueKey virtual on GrSurfaceProxy
Robert Phillips0790f8a2018-09-18 13:11:03 -0400316 GrTextureProxy* texProxy = cur->proxy()->asTextureProxy();
317
318 if (texProxy && texProxy->getUniqueKey().isValid()) {
319 if (!surface->getUniqueKey().isValid()) {
320 fResourceProvider->assignUniqueKeyToResource(texProxy->getUniqueKey(),
321 surface.get());
322 }
323 SkASSERT(surface->getUniqueKey() == texProxy->getUniqueKey());
Robert Phillipsf8e25022017-11-08 15:24:31 -0500324 }
325
Robert Phillips715d08c2018-07-18 13:56:48 -0400326#if GR_ALLOCATION_SPEW
327 SkDebugf("Assigning %d to %d\n",
328 surface->uniqueID().asUInt(),
329 cur->proxy()->uniqueID().asUInt());
330#endif
331
Robert Phillips5b65a842017-11-13 15:48:12 -0500332 cur->assign(std::move(surface));
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500333 } else {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400334 SkASSERT(!cur->proxy()->isInstantiated());
Adlai Holler19fd5142021-03-08 10:19:30 -0700335 fFailedInstantiation = true;
Robert Phillips5af44de2017-07-18 14:49:38 -0400336 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500337
Robert Phillips5af44de2017-07-18 14:49:38 -0400338 fActiveIntvls.insertByIncreasingEnd(cur);
339 }
Robert Phillips5b65a842017-11-13 15:48:12 -0500340
341 // expire all the remaining intervals to drain the active interval list
342 this->expire(std::numeric_limits<unsigned int>::max());
Adlai Holler19fd5142021-03-08 10:19:30 -0700343 return !fFailedInstantiation;
Robert Phillips5af44de2017-07-18 14:49:38 -0400344}
Robert Phillips715d08c2018-07-18 13:56:48 -0400345
346#if GR_ALLOCATION_SPEW
347void GrResourceAllocator::dumpIntervals() {
Robert Phillips715d08c2018-07-18 13:56:48 -0400348 // Print all the intervals while computing their range
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400349 SkDebugf("------------------------------------------------------------\n");
350 unsigned int min = std::numeric_limits<unsigned int>::max();
Robert Phillips715d08c2018-07-18 13:56:48 -0400351 unsigned int max = 0;
352 for(const Interval* cur = fIntvlList.peekHead(); cur; cur = cur->next()) {
Greg Danielc61d7e32020-02-04 14:27:45 -0500353 SkDebugf("{ %3d,%3d }: [%2d, %2d] - refProxys:%d surfaceRefs:%d\n",
Robert Phillips715d08c2018-07-18 13:56:48 -0400354 cur->proxy()->uniqueID().asUInt(),
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400355 cur->proxy()->isInstantiated() ? cur->proxy()->underlyingUniqueID().asUInt() : -1,
Robert Phillips715d08c2018-07-18 13:56:48 -0400356 cur->start(),
357 cur->end(),
358 cur->proxy()->priv().getProxyRefCnt(),
Robert Phillipsb5204762019-06-19 14:12:13 -0400359 cur->proxy()->testingOnly_getBackingRefCnt());
Brian Osman788b9162020-02-07 10:36:46 -0500360 min = std::min(min, cur->start());
361 max = std::max(max, cur->end());
Robert Phillips715d08c2018-07-18 13:56:48 -0400362 }
363
364 // Draw a graph of the useage intervals
365 for(const Interval* cur = fIntvlList.peekHead(); cur; cur = cur->next()) {
366 SkDebugf("{ %3d,%3d }: ",
367 cur->proxy()->uniqueID().asUInt(),
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400368 cur->proxy()->isInstantiated() ? cur->proxy()->underlyingUniqueID().asUInt() : -1);
Robert Phillips715d08c2018-07-18 13:56:48 -0400369 for (unsigned int i = min; i <= max; ++i) {
370 if (i >= cur->start() && i <= cur->end()) {
371 SkDebugf("x");
372 } else {
373 SkDebugf(" ");
374 }
375 }
376 SkDebugf("\n");
377 }
378}
379#endif