blob: 942daf2cc5fd97bea275c7f24f52ee6d6850b54a [file] [log] [blame]
robertphillips3dc6ae52015-10-20 09:54:32 -07001/*
2 * Copyright 2015 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
bsalomon5eb41fd2016-09-06 13:49:32 -07008#include "GrDrawingManager.h"
Greg Daniel51316782017-08-02 15:10:09 +00009#include "GrBackendSemaphore.h"
bsalomonb77a9072016-09-07 10:02:04 -070010#include "GrContext.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050011#include "GrContextPriv.h"
Robert Phillips646e4292017-06-13 12:44:56 -040012#include "GrGpu.h"
Robert Phillipsc994a932018-06-19 13:09:54 -040013#include "GrMemoryPool.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040014#include "GrOnFlushResourceProvider.h"
Robert Phillips9d6c64f2017-09-14 10:56:45 -040015#include "GrOpList.h"
Brian Osman11052242016-10-27 14:47:55 -040016#include "GrRenderTargetContext.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040017#include "GrRenderTargetProxy.h"
Robert Phillipsd375dbf2017-09-14 12:45:25 -040018#include "GrResourceAllocator.h"
robertphillips3dc6ae52015-10-20 09:54:32 -070019#include "GrResourceProvider.h"
robertphillips68737822015-10-29 12:12:21 -070020#include "GrSoftwarePathRenderer.h"
Robert Phillips7ee385e2017-03-30 08:02:11 -040021#include "GrSurfaceProxyPriv.h"
Brian Salomon930f9392018-06-20 16:25:26 -040022#include "GrTexture.h"
Brian Osman45580d32016-11-23 09:37:01 -050023#include "GrTextureContext.h"
24#include "GrTextureOpList.h"
Brian Salomon930f9392018-06-20 16:25:26 -040025#include "GrTexturePriv.h"
Chris Dalton706a6ff2017-11-29 22:01:06 -070026#include "GrTextureProxy.h"
27#include "GrTextureProxyPriv.h"
Brian Salomon930f9392018-06-20 16:25:26 -040028#include "GrTracing.h"
Robert Phillips62000362018-02-01 09:10:04 -050029#include "SkDeferredDisplayList.h"
brianosman0e22eb82016-08-30 07:07:59 -070030#include "SkSurface_Gpu.h"
robertphillips3dc6ae52015-10-20 09:54:32 -070031#include "SkTTopoSort.h"
Robert Phillips774168e2018-05-31 12:43:27 -040032#include "ccpr/GrCoverageCountingPathRenderer.h"
Herb Derby26cbe512018-05-24 14:39:01 -040033#include "text/GrTextContext.h"
robertphillips498d7ac2015-10-30 10:11:30 -070034
Robert Phillips22310d62018-09-05 11:07:21 -040035GrDrawingManager::OpListDAG::OpListDAG(bool explicitlyAllocating,
36 GrContextOptions::Enable sortOpLists) {
37 if (GrContextOptions::Enable::kNo == sortOpLists) {
38 fSortOpLists = false;
39 } else if (GrContextOptions::Enable::kYes == sortOpLists) {
40 fSortOpLists = true;
Robert Phillipsa3f70262018-02-08 10:59:38 -050041 } else {
Robert Phillips64ecdce2018-04-02 10:26:39 -040042 // By default we always enable sorting when we're explicitly allocating GPU resources
Robert Phillips22310d62018-09-05 11:07:21 -040043 fSortOpLists = explicitlyAllocating;
Robert Phillipsa3f70262018-02-08 10:59:38 -050044 }
45}
46
Robert Phillips22310d62018-09-05 11:07:21 -040047GrDrawingManager::OpListDAG::~OpListDAG() {}
48
49void GrDrawingManager::OpListDAG::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const {
50 idArray->reset(fOpLists.count());
Robert Phillipsf2361d22016-10-25 14:20:06 -040051 for (int i = 0; i < fOpLists.count(); ++i) {
Robert Phillips22310d62018-09-05 11:07:21 -040052 if (fOpLists[i]) {
53 (*idArray)[i] = fOpLists[i]->uniqueID();
54 }
55 }
56}
57
58void GrDrawingManager::OpListDAG::reset() {
59 fOpLists.reset();
60}
61
62void GrDrawingManager::OpListDAG::removeOpList(int index) {
63 if (!fOpLists[index]->unique()) {
64 // TODO: Eventually this should be guaranteed unique: http://skbug.com/7111
65 fOpLists[index]->endFlush();
66 }
67
68 fOpLists[index] = nullptr;
69}
70
71void GrDrawingManager::OpListDAG::removeOpLists(int startIndex, int stopIndex) {
72 for (int i = startIndex; i < stopIndex; ++i) {
73 if (!fOpLists[i]) {
74 continue;
75 }
76 this->removeOpList(i);
77 }
78}
79
80void GrDrawingManager::OpListDAG::add(sk_sp<GrOpList> opList) {
81 fOpLists.emplace_back(std::move(opList));
82}
83
84void GrDrawingManager::OpListDAG::add(const SkTArray<sk_sp<GrOpList>>& opLists) {
85 fOpLists.push_back_n(opLists.count(), opLists.begin());
86}
87
88void GrDrawingManager::OpListDAG::swap(SkTArray<sk_sp<GrOpList>>* opLists) {
89 SkASSERT(opLists->empty());
90 opLists->swap(fOpLists);
91}
92
93void GrDrawingManager::OpListDAG::prepForFlush() {
94 if (fSortOpLists) {
95 SkDEBUGCODE(bool result =) SkTTopoSort<GrOpList, GrOpList::TopoSortTraits>(&fOpLists);
96 SkASSERT(result);
97 }
98
99#ifdef SK_DEBUG
100 // This block checks for any unnecessary splits in the opLists. If two sequential opLists
101 // share the same backing GrSurfaceProxy it means the opList was artificially split.
102 if (fOpLists.count()) {
103 GrRenderTargetOpList* prevOpList = fOpLists[0]->asRenderTargetOpList();
104 for (int i = 1; i < fOpLists.count(); ++i) {
105 GrRenderTargetOpList* curOpList = fOpLists[i]->asRenderTargetOpList();
106
107 if (prevOpList && curOpList) {
108 SkASSERT(prevOpList->fTarget.get() != curOpList->fTarget.get());
109 }
110
111 prevOpList = curOpList;
112 }
113 }
114#endif
115}
116
117void GrDrawingManager::OpListDAG::closeAll(const GrCaps* caps) {
118 for (int i = 0; i < fOpLists.count(); ++i) {
119 if (fOpLists[i]) {
120 fOpLists[i]->makeClosed(*caps);
121 }
122 }
123}
124
125void GrDrawingManager::OpListDAG::cleanup(const GrCaps* caps) {
126 for (int i = 0; i < fOpLists.count(); ++i) {
127 if (!fOpLists[i]) {
128 continue;
129 }
130
Robert Phillipsee683652017-04-26 11:53:10 -0400131 // no opList should receive a new command after this
Robert Phillips22310d62018-09-05 11:07:21 -0400132 fOpLists[i]->makeClosed(*caps);
robertphillips0dfa62c2015-11-16 06:23:31 -0800133
Robert Phillipsf2361d22016-10-25 14:20:06 -0400134 // We shouldn't need to do this, but it turns out some clients still hold onto opLists
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400135 // after a cleanup.
136 // MDB TODO: is this still true?
Chris Daltona84cacf2017-10-04 10:30:29 -0600137 if (!fOpLists[i]->unique()) {
138 // TODO: Eventually this should be guaranteed unique.
139 // https://bugs.chromium.org/p/skia/issues/detail?id=7111
140 fOpLists[i]->endFlush();
141 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700142 }
143
Robert Phillipsf2361d22016-10-25 14:20:06 -0400144 fOpLists.reset();
Robert Phillips22310d62018-09-05 11:07:21 -0400145}
146
147///////////////////////////////////////////////////////////////////////////////////////////////////
148GrDrawingManager::GrDrawingManager(GrContext* context,
149 const GrPathRendererChain::Options& optionsForPathRendererChain,
150 const GrTextContext::Options& optionsForTextContext,
151 GrSingleOwner* singleOwner,
152 bool explicitlyAllocating,
Robert Phillips46acf9d2018-10-09 09:31:40 -0400153 GrContextOptions::Enable sortOpLists,
154 GrContextOptions::Enable reduceOpListSplitting)
Robert Phillips22310d62018-09-05 11:07:21 -0400155 : fContext(context)
156 , fOptionsForPathRendererChain(optionsForPathRendererChain)
157 , fOptionsForTextContext(optionsForTextContext)
158 , fSingleOwner(singleOwner)
159 , fAbandoned(false)
160 , fDAG(explicitlyAllocating, sortOpLists)
161 , fTextContext(nullptr)
162 , fPathRendererChain(nullptr)
163 , fSoftwarePathRenderer(nullptr)
164 , fFlushing(false) {
Robert Phillips46acf9d2018-10-09 09:31:40 -0400165 if (GrContextOptions::Enable::kNo == reduceOpListSplitting) {
166 fReduceOpListSplitting = false;
167 } else if (GrContextOptions::Enable::kYes == reduceOpListSplitting) {
168 fReduceOpListSplitting = true;
169 } else {
170 // For now, this is only turned on when explicitly enabled. Once mini-flushes are
171 // implemented it should be enabled whenever sorting is enabled.
172 fReduceOpListSplitting = false; // sortOpLists
173 }
Robert Phillips22310d62018-09-05 11:07:21 -0400174}
175
176void GrDrawingManager::cleanup() {
177 fDAG.cleanup(fContext->contextPriv().caps());
robertphillips3dc6ae52015-10-20 09:54:32 -0700178
robertphillips13391dd2015-10-30 05:15:11 -0700179 fPathRendererChain = nullptr;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400180 fSoftwarePathRenderer = nullptr;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400181
182 fOnFlushCBObjects.reset();
robertphillips3dc6ae52015-10-20 09:54:32 -0700183}
184
185GrDrawingManager::~GrDrawingManager() {
186 this->cleanup();
187}
188
189void GrDrawingManager::abandon() {
190 fAbandoned = true;
191 this->cleanup();
192}
193
robertphillips68737822015-10-29 12:12:21 -0700194void GrDrawingManager::freeGpuResources() {
Jim Van Verth106b5c42017-09-26 12:45:29 -0400195 for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) {
196 if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) {
197 // it's safe to just do this because we're iterating in reverse
198 fOnFlushCBObjects.removeShuffle(i);
199 }
200 }
201
robertphillips68737822015-10-29 12:12:21 -0700202 // a path renderer may be holding onto resources
robertphillips13391dd2015-10-30 05:15:11 -0700203 fPathRendererChain = nullptr;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400204 fSoftwarePathRenderer = nullptr;
Robert Phillipse3302df2017-04-24 07:31:02 -0400205}
206
Robert Phillips7ee385e2017-03-30 08:02:11 -0400207// MDB TODO: make use of the 'proxy' parameter.
Brian Salomon57d2bea2018-09-10 09:35:41 -0400208GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy*,
209 int numSemaphores,
210 GrBackendSemaphore backendSemaphores[]) {
211 GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
Brian Salomondcbb9d92017-07-19 10:53:20 -0400212
robertphillips7761d612016-05-16 09:14:53 -0700213 if (fFlushing || this->wasAbandoned()) {
Greg Daniel51316782017-08-02 15:10:09 +0000214 return GrSemaphoresSubmitted::kNo;
joshualittb8918c42015-12-18 09:59:46 -0800215 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400216 SkDEBUGCODE(this->validate());
217
Robert Phillips874b5352018-03-16 08:48:24 -0400218 GrGpu* gpu = fContext->contextPriv().getGpu();
219 if (!gpu) {
220 return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording
221 }
joshualittb8918c42015-12-18 09:59:46 -0800222 fFlushing = true;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400223
Robert Phillips38d64b02018-09-04 13:23:26 -0400224 // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh
225 // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed
226 // but need to be flushed anyway. Closing such GrOpLists here will mean new
227 // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again.
Robert Phillips22310d62018-09-05 11:07:21 -0400228 fDAG.closeAll(fContext->contextPriv().caps());
Robert Phillips38d64b02018-09-04 13:23:26 -0400229 fActiveOpList = nullptr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400230
Robert Phillips22310d62018-09-05 11:07:21 -0400231 fDAG.prepForFlush();
Brian Salomon58f153c2018-10-18 21:51:15 -0400232 SkASSERT(SkToBool(fVertexBufferSpace) == SkToBool(fIndexBufferSpace));
233 if (!fVertexBufferSpace) {
Brian Salomon294861f2018-10-22 09:24:16 -0400234 fVertexBufferSpace.reset(new char[GrBufferAllocPool::kDefaultBufferSize]());
235 fIndexBufferSpace.reset(new char[GrBufferAllocPool::kDefaultBufferSize]());
Brian Salomon58f153c2018-10-18 21:51:15 -0400236 }
Robert Phillipsa4c93ac2017-05-18 11:40:04 -0400237
Brian Salomon58f153c2018-10-18 21:51:15 -0400238 GrOpFlushState flushState(gpu, fContext->contextPriv().resourceProvider(), &fTokenTracker,
239 fVertexBufferSpace.get(), fIndexBufferSpace.get());
Robert Phillips40a29d72018-01-18 12:59:22 -0500240
Chris Daltonfe199b72017-05-05 11:26:15 -0400241 GrOnFlushResourceProvider onFlushProvider(this);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500242 // TODO: AFAICT the only reason fFlushState is on GrDrawingManager rather than on the
243 // stack here is to preserve the flush tokens.
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400244
Chris Dalton12658942017-10-05 19:45:25 -0600245 // Prepare any onFlush op lists (e.g. atlases).
Chris Daltonfe199b72017-05-05 11:26:15 -0400246 if (!fOnFlushCBObjects.empty()) {
Robert Phillips22310d62018-09-05 11:07:21 -0400247 fDAG.gatherIDs(&fFlushingOpListIDs);
248
Chris Dalton12658942017-10-05 19:45:25 -0600249 SkSTArray<4, sk_sp<GrRenderTargetContext>> renderTargetContexts;
Chris Daltonfe199b72017-05-05 11:26:15 -0400250 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
251 onFlushCBObject->preFlush(&onFlushProvider,
Chris Dalton3968ff92017-11-27 12:26:31 -0700252 fFlushingOpListIDs.begin(), fFlushingOpListIDs.count(),
Chris Daltonfe199b72017-05-05 11:26:15 -0400253 &renderTargetContexts);
Chris Dalton12658942017-10-05 19:45:25 -0600254 for (const sk_sp<GrRenderTargetContext>& rtc : renderTargetContexts) {
Chris Dalton706a6ff2017-11-29 22:01:06 -0700255 sk_sp<GrRenderTargetOpList> onFlushOpList = sk_ref_sp(rtc->getRTOpList());
Chris Dalton12658942017-10-05 19:45:25 -0600256 if (!onFlushOpList) {
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400257 continue; // Odd - but not a big deal
258 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700259#ifdef SK_DEBUG
260 // OnFlush callbacks are already invoked during flush, and are therefore expected to
261 // handle resource allocation & usage on their own. (No deferred or lazy proxies!)
262 onFlushOpList->visitProxies_debugOnly([](GrSurfaceProxy* p) {
263 SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred());
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500264 SkASSERT(GrSurfaceProxy::LazyState::kNot == p->lazyInstantiationState());
Chris Dalton706a6ff2017-11-29 22:01:06 -0700265 });
266#endif
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400267 onFlushOpList->makeClosed(*fContext->contextPriv().caps());
Robert Phillips40a29d72018-01-18 12:59:22 -0500268 onFlushOpList->prepare(&flushState);
Chris Dalton3968ff92017-11-27 12:26:31 -0700269 fOnFlushCBOpLists.push_back(std::move(onFlushOpList));
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400270 }
271 renderTargetContexts.reset();
272 }
273 }
274
robertphillipsa13e2022015-11-11 12:01:09 -0800275#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500276 // Enable this to print out verbose GrOp information
Robert Phillipsf2361d22016-10-25 14:20:06 -0400277 for (int i = 0; i < fOpLists.count(); ++i) {
278 SkDEBUGCODE(fOpLists[i]->dump();)
robertphillips3dc6ae52015-10-20 09:54:32 -0700279 }
robertphillipsa13e2022015-11-11 12:01:09 -0800280#endif
281
Robert Phillipseafd48a2017-11-16 07:52:08 -0500282 int startIndex, stopIndex;
283 bool flushed = false;
284
Robert Phillipsf8e25022017-11-08 15:24:31 -0500285 {
Brian Salomon577aa0f2018-11-30 13:32:23 -0500286 GrResourceAllocator alloc(fContext->contextPriv().resourceProvider(),
Brian Salomon967df202018-12-07 11:15:53 -0500287 flushState.deinstantiateProxyTracker());
Robert Phillips22310d62018-09-05 11:07:21 -0400288 for (int i = 0; i < fDAG.numOpLists(); ++i) {
289 if (fDAG.opList(i)) {
290 fDAG.opList(i)->gatherProxyIntervals(&alloc);
291 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500292 alloc.markEndOfOpList(i);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500293 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400294
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500295 GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError;
Greg Danield2073452018-12-07 11:20:33 -0500296 int numOpListsExecuted = 0;
Brian Salomon577aa0f2018-11-30 13:32:23 -0500297 while (alloc.assign(&startIndex, &stopIndex, &error)) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500298 if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) {
299 for (int i = startIndex; i < stopIndex; ++i) {
Robert Phillips22310d62018-09-05 11:07:21 -0400300 if (fDAG.opList(i) && !fDAG.opList(i)->isFullyInstantiated()) {
Robert Phillips01a91282018-07-26 08:03:04 -0400301 // If the backing surface wasn't allocated drop the entire opList.
Robert Phillips22310d62018-09-05 11:07:21 -0400302 fDAG.removeOpList(i);
Robert Phillips01a91282018-07-26 08:03:04 -0400303 }
Robert Phillips22310d62018-09-05 11:07:21 -0400304 if (fDAG.opList(i)) {
305 fDAG.opList(i)->purgeOpsWithUninstantiatedProxies();
Robert Phillipsbbcb7f72018-05-31 11:16:19 -0400306 }
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500307 }
308 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500309
Greg Danield2073452018-12-07 11:20:33 -0500310 if (this->executeOpLists(startIndex, stopIndex, &flushState, &numOpListsExecuted)) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500311 flushed = true;
312 }
bsalomondc438982016-08-31 11:53:49 -0700313 }
Greg Danielc42b20b2017-10-04 10:34:49 -0400314 }
315
Chris Dalton91ab1552018-04-18 13:24:25 -0600316#ifdef SK_DEBUG
Robert Phillips22310d62018-09-05 11:07:21 -0400317 for (int i = 0; i < fDAG.numOpLists(); ++i) {
Chris Dalton91ab1552018-04-18 13:24:25 -0600318 // If there are any remaining opLists at this point, make sure they will not survive the
319 // flush. Otherwise we need to call endFlush() on them.
320 // http://skbug.com/7111
Robert Phillips22310d62018-09-05 11:07:21 -0400321 SkASSERT(!fDAG.opList(i) || fDAG.opList(i)->unique());
Chris Dalton91ab1552018-04-18 13:24:25 -0600322 }
323#endif
Robert Phillips22310d62018-09-05 11:07:21 -0400324 fDAG.reset();
robertphillipsa13e2022015-11-11 12:01:09 -0800325
Robert Phillipsc994a932018-06-19 13:09:54 -0400326#ifdef SK_DEBUG
327 // In non-DDL mode this checks that all the flushed ops have been freed from the memory pool.
328 // When we move to partial flushes this assert will no longer be valid.
329 // In DDL mode this check is somewhat superfluous since the memory for most of the ops/opLists
330 // will be stored in the DDL's GrOpMemoryPools.
331 GrOpMemoryPool* opMemoryPool = fContext->contextPriv().opMemoryPool();
332 opMemoryPool->isEmpty();
333#endif
334
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500335 GrSemaphoresSubmitted result = gpu->finishFlush(numSemaphores, backendSemaphores);
robertphillipsa13e2022015-11-11 12:01:09 -0800336
Brian Salomon967df202018-12-07 11:15:53 -0500337 flushState.deinstantiateProxyTracker()->deinstantiateAllProxies();
Greg Daniel4684f822018-03-08 15:27:36 -0500338
Brian Salomon57d2bea2018-09-10 09:35:41 -0400339 // Give the cache a chance to purge resources that become purgeable due to flushing.
340 if (flushed) {
341 fContext->contextPriv().getResourceCache()->purgeAsNeeded();
bsalomonb77a9072016-09-07 10:02:04 -0700342 }
Chris Daltonfe199b72017-05-05 11:26:15 -0400343 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Robert Phillips40a29d72018-01-18 12:59:22 -0500344 onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingOpListIDs.begin(),
Chris Dalton3968ff92017-11-27 12:26:31 -0700345 fFlushingOpListIDs.count());
Chris Daltonfe199b72017-05-05 11:26:15 -0400346 }
Chris Dalton3968ff92017-11-27 12:26:31 -0700347 fFlushingOpListIDs.reset();
joshualittb8918c42015-12-18 09:59:46 -0800348 fFlushing = false;
Greg Daniel51316782017-08-02 15:10:09 +0000349
350 return result;
robertphillips3dc6ae52015-10-20 09:54:32 -0700351}
352
Greg Danield2073452018-12-07 11:20:33 -0500353bool GrDrawingManager::executeOpLists(int startIndex, int stopIndex, GrOpFlushState* flushState,
354 int* numOpListsExecuted) {
Robert Phillips22310d62018-09-05 11:07:21 -0400355 SkASSERT(startIndex <= stopIndex && stopIndex <= fDAG.numOpLists());
Robert Phillipseafd48a2017-11-16 07:52:08 -0500356
Robert Phillips27483912018-04-20 12:43:18 -0400357#if GR_FLUSH_TIME_OP_SPEW
358 SkDebugf("Flushing opLists: %d to %d out of [%d, %d]\n",
Robert Phillips22310d62018-09-05 11:07:21 -0400359 startIndex, stopIndex, 0, fDAG.numOpLists());
Robert Phillips27483912018-04-20 12:43:18 -0400360 for (int i = startIndex; i < stopIndex; ++i) {
Robert Phillips22310d62018-09-05 11:07:21 -0400361 if (fDAG.opList(i)) {
362 fDAG.opList(i)->dump(true);
Robert Phillips1734dd32018-08-21 13:52:09 -0400363 }
Robert Phillips27483912018-04-20 12:43:18 -0400364 }
365#endif
366
Robert Phillips4150eea2018-02-07 17:08:21 -0500367 GrResourceProvider* resourceProvider = fContext->contextPriv().resourceProvider();
Robert Phillipseafd48a2017-11-16 07:52:08 -0500368 bool anyOpListsExecuted = false;
369
370 for (int i = startIndex; i < stopIndex; ++i) {
Robert Phillips22310d62018-09-05 11:07:21 -0400371 if (!fDAG.opList(i)) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500372 continue;
373 }
374
Robert Phillips22310d62018-09-05 11:07:21 -0400375 GrOpList* opList = fDAG.opList(i);
376
Robert Phillips4150eea2018-02-07 17:08:21 -0500377 if (resourceProvider->explicitlyAllocateGPUResources()) {
Robert Phillips22310d62018-09-05 11:07:21 -0400378 if (!opList->isFullyInstantiated()) {
Robert Phillips4150eea2018-02-07 17:08:21 -0500379 // If the backing surface wasn't allocated drop the draw of the entire opList.
Robert Phillips22310d62018-09-05 11:07:21 -0400380 fDAG.removeOpList(i);
Robert Phillips4150eea2018-02-07 17:08:21 -0500381 continue;
382 }
383 } else {
Robert Phillips22310d62018-09-05 11:07:21 -0400384 if (!opList->instantiate(resourceProvider)) {
385 fDAG.removeOpList(i);
Robert Phillips4150eea2018-02-07 17:08:21 -0500386 continue;
387 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500388 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500389
390 // TODO: handle this instantiation via lazy surface proxies?
391 // Instantiate all deferred proxies (being built on worker threads) so we can upload them
Robert Phillips22310d62018-09-05 11:07:21 -0400392 opList->instantiateDeferredProxies(fContext->contextPriv().resourceProvider());
393 opList->prepare(flushState);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500394 }
395
396 // Upload all data to the GPU
397 flushState->preExecuteDraws();
398
Greg Danield2073452018-12-07 11:20:33 -0500399 // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources
400 // for each command buffer associated with the oplists. If this gets too large we can cause the
401 // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we
402 // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some
403 // memory pressure.
404 static constexpr int kMaxOpListsBeforeFlush = 100;
405
Robert Phillipseafd48a2017-11-16 07:52:08 -0500406 // Execute the onFlush op lists first, if any.
Chris Dalton3968ff92017-11-27 12:26:31 -0700407 for (sk_sp<GrOpList>& onFlushOpList : fOnFlushCBOpLists) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500408 if (!onFlushOpList->execute(flushState)) {
409 SkDebugf("WARNING: onFlushOpList failed to execute.\n");
410 }
411 SkASSERT(onFlushOpList->unique());
412 onFlushOpList = nullptr;
Greg Danield2073452018-12-07 11:20:33 -0500413 (*numOpListsExecuted)++;
414 if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) {
415 flushState->gpu()->finishFlush(0, nullptr);
416 *numOpListsExecuted = 0;
417 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500418 }
Chris Dalton3968ff92017-11-27 12:26:31 -0700419 fOnFlushCBOpLists.reset();
Robert Phillipseafd48a2017-11-16 07:52:08 -0500420
421 // Execute the normal op lists.
422 for (int i = startIndex; i < stopIndex; ++i) {
Robert Phillips22310d62018-09-05 11:07:21 -0400423 if (!fDAG.opList(i)) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500424 continue;
425 }
426
Robert Phillips22310d62018-09-05 11:07:21 -0400427 if (fDAG.opList(i)->execute(flushState)) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500428 anyOpListsExecuted = true;
429 }
Greg Danield2073452018-12-07 11:20:33 -0500430 (*numOpListsExecuted)++;
431 if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) {
432 flushState->gpu()->finishFlush(0, nullptr);
433 *numOpListsExecuted = 0;
434 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500435 }
436
437 SkASSERT(!flushState->commandBuffer());
Robert Phillips40a29d72018-01-18 12:59:22 -0500438 SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush());
Robert Phillipseafd48a2017-11-16 07:52:08 -0500439
440 // We reset the flush state before the OpLists so that the last resources to be freed are those
441 // that are written to in the OpLists. This helps to make sure the most recently used resources
442 // are the last to be purged by the resource cache.
443 flushState->reset();
444
Robert Phillips22310d62018-09-05 11:07:21 -0400445 fDAG.removeOpLists(startIndex, stopIndex);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500446
447 return anyOpListsExecuted;
448}
449
Greg Daniel51316782017-08-02 15:10:09 +0000450GrSemaphoresSubmitted GrDrawingManager::prepareSurfaceForExternalIO(
451 GrSurfaceProxy* proxy, int numSemaphores, GrBackendSemaphore backendSemaphores[]) {
bsalomon6a2b1942016-09-08 11:28:59 -0700452 if (this->wasAbandoned()) {
Greg Daniel51316782017-08-02 15:10:09 +0000453 return GrSemaphoresSubmitted::kNo;
bsalomon6a2b1942016-09-08 11:28:59 -0700454 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400455 SkDEBUGCODE(this->validate());
Robert Phillips7ee385e2017-03-30 08:02:11 -0400456 SkASSERT(proxy);
bsalomon6a2b1942016-09-08 11:28:59 -0700457
Robert Phillips874b5352018-03-16 08:48:24 -0400458 GrGpu* gpu = fContext->contextPriv().getGpu();
459 if (!gpu) {
460 return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording
461 }
462
Kevin Lubick42846132018-01-05 10:11:11 -0500463 GrSemaphoresSubmitted result = GrSemaphoresSubmitted::kNo;
Greg Daniel51316782017-08-02 15:10:09 +0000464 if (proxy->priv().hasPendingIO() || numSemaphores) {
465 result = this->flush(proxy, numSemaphores, backendSemaphores);
bsalomon6a2b1942016-09-08 11:28:59 -0700466 }
467
Robert Phillips6be756b2018-01-16 15:07:54 -0500468 if (!proxy->instantiate(fContext->contextPriv().resourceProvider())) {
Greg Daniel51316782017-08-02 15:10:09 +0000469 return result;
Robert Phillips7ee385e2017-03-30 08:02:11 -0400470 }
471
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400472 GrSurface* surface = proxy->peekSurface();
Brian Salomon930f9392018-06-20 16:25:26 -0400473 if (auto* rt = surface->asRenderTarget()) {
474 gpu->resolveRenderTarget(rt);
475 }
476 if (auto* tex = surface->asTexture()) {
477 if (tex->texturePriv().mipMapped() == GrMipMapped::kYes &&
478 tex->texturePriv().mipMapsAreDirty()) {
479 gpu->regenerateMipMapLevels(tex);
480 }
bsalomon6a2b1942016-09-08 11:28:59 -0700481 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400482
483 SkDEBUGCODE(this->validate());
Greg Daniel51316782017-08-02 15:10:09 +0000484 return result;
bsalomon6a2b1942016-09-08 11:28:59 -0700485}
486
Chris Daltonfe199b72017-05-05 11:26:15 -0400487void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
488 fOnFlushCBObjects.push_back(onFlushCBObject);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400489}
490
Robert Phillips62000362018-02-01 09:10:04 -0500491void GrDrawingManager::moveOpListsToDDL(SkDeferredDisplayList* ddl) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400492 SkDEBUGCODE(this->validate());
493
494 // no opList should receive a new command after this
Robert Phillips22310d62018-09-05 11:07:21 -0400495 fDAG.closeAll(fContext->contextPriv().caps());
Robert Phillips38d64b02018-09-04 13:23:26 -0400496 fActiveOpList = nullptr;
Robert Phillips7a137052018-02-01 11:23:12 -0500497
Robert Phillips22310d62018-09-05 11:07:21 -0400498 fDAG.swap(&ddl->fOpLists);
Robert Phillips867ce8f2018-06-21 10:28:36 -0400499
Robert Phillips774168e2018-05-31 12:43:27 -0400500 if (fPathRendererChain) {
501 if (auto ccpr = fPathRendererChain->getCoverageCountingPathRenderer()) {
502 ddl->fPendingPaths = ccpr->detachPendingPaths();
503 }
504 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400505
506 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500507}
508
509void GrDrawingManager::copyOpListsFromDDL(const SkDeferredDisplayList* ddl,
510 GrRenderTargetProxy* newDest) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400511 SkDEBUGCODE(this->validate());
512
513 if (fActiveOpList) {
514 // This is a temporary fix for the partial-MDB world. In that world we're not
515 // reordering so ops that (in the single opList world) would've just glommed onto the
516 // end of the single opList but referred to a far earlier RT need to appear in their
517 // own opList.
518 fActiveOpList->makeClosed(*fContext->contextPriv().caps());
519 fActiveOpList = nullptr;
520 }
521
Robert Phillips62000362018-02-01 09:10:04 -0500522 // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData.
523 // The lazy proxy that references it (in the copied opLists) will steal its GrTexture.
524 ddl->fLazyProxyData->fReplayDest = newDest;
Robert Phillips774168e2018-05-31 12:43:27 -0400525
526 if (ddl->fPendingPaths.size()) {
527 GrCoverageCountingPathRenderer* ccpr = this->getCoverageCountingPathRenderer();
528
529 ccpr->mergePendingPaths(ddl->fPendingPaths);
530 }
Robert Phillips22310d62018-09-05 11:07:21 -0400531
532 fDAG.add(ddl->fOpLists);
Robert Phillips38d64b02018-09-04 13:23:26 -0400533
534 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500535}
536
Robert Phillips38d64b02018-09-04 13:23:26 -0400537#ifdef SK_DEBUG
538void GrDrawingManager::validate() const {
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400539 if (fDAG.sortingOpLists() && fReduceOpListSplitting) {
540 SkASSERT(!fActiveOpList);
541 } else {
542 if (fActiveOpList) {
543 SkASSERT(!fDAG.empty());
544 SkASSERT(!fActiveOpList->isClosed());
545 SkASSERT(fActiveOpList == fDAG.back());
Robert Phillips38d64b02018-09-04 13:23:26 -0400546 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400547
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400548 for (int i = 0; i < fDAG.numOpLists(); ++i) {
549 if (fActiveOpList != fDAG.opList(i)) {
550 SkASSERT(fDAG.opList(i)->isClosed());
551 }
552 }
553
554 if (!fDAG.empty() && !fDAG.back()->isClosed()) {
555 SkASSERT(fActiveOpList == fDAG.back());
556 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400557 }
558}
559#endif
560
Robert Phillips941d1442017-06-14 16:37:02 -0400561sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(GrRenderTargetProxy* rtp,
562 bool managedOpList) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400563 SkDEBUGCODE(this->validate());
robertphillips3dc6ae52015-10-20 09:54:32 -0700564 SkASSERT(fContext);
565
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400566 if (fDAG.sortingOpLists() && fReduceOpListSplitting) {
567 // In this case we need to close all the opLists that rely on the current contents of
568 // 'rtp'. That is bc we're going to update the content of the proxy so they need to be
569 // split in case they use both the old and new content. (This is a bit of an overkill:
570 // they really only need to be split if they ever reference proxy's contents again but
571 // that is hard to predict/handle).
572 if (GrOpList* lastOpList = rtp->getLastOpList()) {
573 lastOpList->closeThoseWhoDependOnMe(*fContext->contextPriv().caps());
Robert Phillips46acf9d2018-10-09 09:31:40 -0400574 }
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400575 } else if (fActiveOpList) {
576 // This is a temporary fix for the partial-MDB world. In that world we're not
577 // reordering so ops that (in the single opList world) would've just glommed onto the
578 // end of the single opList but referred to a far earlier RT need to appear in their
579 // own opList.
580 fActiveOpList->makeClosed(*fContext->contextPriv().caps());
Robert Phillips38d64b02018-09-04 13:23:26 -0400581 fActiveOpList = nullptr;
robertphillips3dc6ae52015-10-20 09:54:32 -0700582 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700583
Robert Phillipsf35fd8d2018-01-22 10:48:15 -0500584 auto resourceProvider = fContext->contextPriv().resourceProvider();
585
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500586 sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500587 resourceProvider,
Robert Phillipsc994a932018-06-19 13:09:54 -0400588 fContext->contextPriv().refOpMemoryPool(),
Robert Phillips3a9710b2018-03-27 17:51:55 -0400589 rtp,
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500590 fContext->contextPriv().getAuditTrail()));
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400591 SkASSERT(rtp->getLastOpList() == opList.get());
robertphillips3dc6ae52015-10-20 09:54:32 -0700592
Robert Phillips941d1442017-06-14 16:37:02 -0400593 if (managedOpList) {
Robert Phillips22310d62018-09-05 11:07:21 -0400594 fDAG.add(opList);
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400595
596 if (!fDAG.sortingOpLists() || !fReduceOpListSplitting) {
597 fActiveOpList = opList.get();
598 }
Robert Phillips941d1442017-06-14 16:37:02 -0400599 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700600
Robert Phillips38d64b02018-09-04 13:23:26 -0400601 SkDEBUGCODE(this->validate());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400602 return opList;
robertphillips3dc6ae52015-10-20 09:54:32 -0700603}
604
Robert Phillipsb6deea82017-05-11 14:14:30 -0400605sk_sp<GrTextureOpList> GrDrawingManager::newTextureOpList(GrTextureProxy* textureProxy) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400606 SkDEBUGCODE(this->validate());
Brian Osman45580d32016-11-23 09:37:01 -0500607 SkASSERT(fContext);
608
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400609 if (fDAG.sortingOpLists() && fReduceOpListSplitting) {
610 // In this case we need to close all the opLists that rely on the current contents of
611 // 'texture'. That is bc we're going to update the content of the proxy so they need to
612 // be split in case they use both the old and new content. (This is a bit of an
613 // overkill: they really only need to be split if they ever reference proxy's contents
614 // again but that is hard to predict/handle).
615 if (GrOpList* lastOpList = textureProxy->getLastOpList()) {
616 lastOpList->closeThoseWhoDependOnMe(*fContext->contextPriv().caps());
Robert Phillips46acf9d2018-10-09 09:31:40 -0400617 }
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400618 } else if (fActiveOpList) {
619 // This is a temporary fix for the partial-MDB world. In that world we're not
620 // reordering so ops that (in the single opList world) would've just glommed onto the
621 // end of the single opList but referred to a far earlier RT need to appear in their
622 // own opList.
623 fActiveOpList->makeClosed(*fContext->contextPriv().caps());
624 fActiveOpList = nullptr;
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400625 }
626
Robert Phillips6be756b2018-01-16 15:07:54 -0500627 sk_sp<GrTextureOpList> opList(new GrTextureOpList(fContext->contextPriv().resourceProvider(),
Robert Phillipsc994a932018-06-19 13:09:54 -0400628 fContext->contextPriv().refOpMemoryPool(),
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400629 textureProxy,
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500630 fContext->contextPriv().getAuditTrail()));
Brian Osman45580d32016-11-23 09:37:01 -0500631
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400632 SkASSERT(textureProxy->getLastOpList() == opList.get());
Robert Phillips4a395042017-04-24 16:27:17 +0000633
Robert Phillips22310d62018-09-05 11:07:21 -0400634 fDAG.add(opList);
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400635 if (!fDAG.sortingOpLists() || !fReduceOpListSplitting) {
636 fActiveOpList = opList.get();
637 }
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400638
Robert Phillips38d64b02018-09-04 13:23:26 -0400639 SkDEBUGCODE(this->validate());
Robert Phillips4a395042017-04-24 16:27:17 +0000640 return opList;
Brian Osman45580d32016-11-23 09:37:01 -0500641}
642
Herb Derby26cbe512018-05-24 14:39:01 -0400643GrTextContext* GrDrawingManager::getTextContext() {
644 if (!fTextContext) {
645 fTextContext = GrTextContext::Make(fOptionsForTextContext);
brianosman86e76262016-08-11 12:17:31 -0700646 }
647
Herb Derby26cbe512018-05-24 14:39:01 -0400648 return fTextContext.get();
brianosman86e76262016-08-11 12:17:31 -0700649}
650
robertphillips68737822015-10-29 12:12:21 -0700651/*
652 * This method finds a path renderer that can draw the specified path on
653 * the provided target.
654 * Due to its expense, the software path renderer has split out so it can
655 * can be individually allowed/disallowed via the "allowSW" boolean.
656 */
657GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
658 bool allowSW,
659 GrPathRendererChain::DrawType drawType,
660 GrPathRenderer::StencilSupport* stencilSupport) {
661
662 if (!fPathRendererChain) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400663 fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
robertphillips68737822015-10-29 12:12:21 -0700664 }
665
666 GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
667 if (!pr && allowSW) {
Brian Salomone7df0bb2018-05-07 14:44:57 -0400668 auto swPR = this->getSoftwarePathRenderer();
669 if (GrPathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) {
670 pr = swPR;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500671 }
robertphillips68737822015-10-29 12:12:21 -0700672 }
673
674 return pr;
675}
676
Brian Salomone7df0bb2018-05-07 14:44:57 -0400677GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() {
678 if (!fSoftwarePathRenderer) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400679 fSoftwarePathRenderer.reset(
Brian Salomone7df0bb2018-05-07 14:44:57 -0400680 new GrSoftwarePathRenderer(fContext->contextPriv().proxyProvider(),
Ben Wagner9ec70c62018-07-12 13:30:47 -0400681 fOptionsForPathRendererChain.fAllowPathMaskCaching));
Brian Salomone7df0bb2018-05-07 14:44:57 -0400682 }
Ben Wagner9ec70c62018-07-12 13:30:47 -0400683 return fSoftwarePathRenderer.get();
Brian Salomone7df0bb2018-05-07 14:44:57 -0400684}
685
Chris Daltonfddb6c02017-11-04 15:22:22 -0600686GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() {
687 if (!fPathRendererChain) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400688 fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
Chris Daltonfddb6c02017-11-04 15:22:22 -0600689 }
690 return fPathRendererChain->getCoverageCountingPathRenderer();
691}
692
Brian Salomon653f42f2018-07-10 10:07:31 -0400693void GrDrawingManager::flushIfNecessary() {
694 GrResourceCache* resourceCache = fContext->contextPriv().getResourceCache();
695 if (resourceCache && resourceCache->requestsFlush()) {
Brian Salomon57d2bea2018-09-10 09:35:41 -0400696 this->flush(nullptr, 0, nullptr);
697 resourceCache->purgeAsNeeded();
Brian Salomon653f42f2018-07-10 10:07:31 -0400698 }
699}
700
Brian Osman11052242016-10-27 14:47:55 -0400701sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext(
Robert Phillips37430132016-11-09 06:50:43 -0500702 sk_sp<GrSurfaceProxy> sProxy,
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400703 sk_sp<SkColorSpace> colorSpace,
Robert Phillips941d1442017-06-14 16:37:02 -0400704 const SkSurfaceProps* surfaceProps,
705 bool managedOpList) {
Robert Phillips37430132016-11-09 06:50:43 -0500706 if (this->wasAbandoned() || !sProxy->asRenderTargetProxy()) {
robertphillips3dc6ae52015-10-20 09:54:32 -0700707 return nullptr;
708 }
709
brianosman0e22eb82016-08-30 07:07:59 -0700710 // SkSurface catches bad color space usage at creation. This check handles anything that slips
Brian Salomon366093f2018-02-13 09:25:22 -0500711 // by, including internal usage.
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400712 if (!SkSurface_Gpu::Valid(fContext->contextPriv().caps(), sProxy->config(), colorSpace.get())) {
brianosmana9c3c6a2016-09-29 10:08:36 -0700713 SkDEBUGFAIL("Invalid config and colorspace combination");
brianosman0e22eb82016-08-30 07:07:59 -0700714 return nullptr;
715 }
joshualitt96880d92016-02-16 10:36:53 -0800716
Robert Phillips2c862492017-01-18 10:08:39 -0500717 sk_sp<GrRenderTargetProxy> rtp(sk_ref_sp(sProxy->asRenderTargetProxy()));
718
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500719 return sk_sp<GrRenderTargetContext>(new GrRenderTargetContext(
720 fContext, this, std::move(rtp),
721 std::move(colorSpace),
722 surfaceProps,
723 fContext->contextPriv().getAuditTrail(),
724 fSingleOwner, managedOpList));
robertphillips3dc6ae52015-10-20 09:54:32 -0700725}
Brian Osman45580d32016-11-23 09:37:01 -0500726
Robert Phillips2c862492017-01-18 10:08:39 -0500727sk_sp<GrTextureContext> GrDrawingManager::makeTextureContext(sk_sp<GrSurfaceProxy> sProxy,
728 sk_sp<SkColorSpace> colorSpace) {
Brian Osman45580d32016-11-23 09:37:01 -0500729 if (this->wasAbandoned() || !sProxy->asTextureProxy()) {
730 return nullptr;
731 }
732
Robert Phillips2c862492017-01-18 10:08:39 -0500733 // SkSurface catches bad color space usage at creation. This check handles anything that slips
Brian Salomon366093f2018-02-13 09:25:22 -0500734 // by, including internal usage.
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400735 if (!SkSurface_Gpu::Valid(fContext->contextPriv().caps(), sProxy->config(), colorSpace.get())) {
Robert Phillips2c862492017-01-18 10:08:39 -0500736 SkDEBUGFAIL("Invalid config and colorspace combination");
737 return nullptr;
738 }
739
Robert Phillips383c4182018-02-07 12:47:44 -0500740 // GrTextureRenderTargets should always be using a GrRenderTargetContext
Brian Osman45580d32016-11-23 09:37:01 -0500741 SkASSERT(!sProxy->asRenderTargetProxy());
742
743 sk_sp<GrTextureProxy> textureProxy(sk_ref_sp(sProxy->asTextureProxy()));
744
745 return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy),
Robert Phillips2c862492017-01-18 10:08:39 -0500746 std::move(colorSpace),
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500747 fContext->contextPriv().getAuditTrail(),
Robert Phillips2c862492017-01-18 10:08:39 -0500748 fSingleOwner));
Brian Osman45580d32016-11-23 09:37:01 -0500749}