blob: 8180924303874c11e41f365e9a8b09219fda56fd [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrDrawingManager.h"
Robert Phillips69893702019-02-22 11:16:30 -05009
Robert Phillips4d5594d2020-02-21 14:24:40 -050010#include "include/core/SkDeferredDisplayList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrBackendSemaphore.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/private/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/core/SkTTopoSort.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040014#include "src/gpu/GrAuditTrail.h"
Brian Salomon9241a6d2019-10-03 13:26:54 -040015#include "src/gpu/GrClientMappedBufferManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/GrContextPriv.h"
Greg Daniele227fe42019-08-21 13:52:24 -040017#include "src/gpu/GrCopyRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrGpu.h"
19#include "src/gpu/GrMemoryPool.h"
20#include "src/gpu/GrOnFlushResourceProvider.h"
21#include "src/gpu/GrRecordingContextPriv.h"
22#include "src/gpu/GrRenderTargetContext.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040023#include "src/gpu/GrRenderTargetProxy.h"
Chris Dalton6b498102019-08-01 14:14:52 -060024#include "src/gpu/GrRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/GrResourceAllocator.h"
26#include "src/gpu/GrResourceProvider.h"
27#include "src/gpu/GrSoftwarePathRenderer.h"
Greg Daniel46e366a2019-12-16 14:38:36 -050028#include "src/gpu/GrSurfaceContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029#include "src/gpu/GrSurfaceProxyPriv.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000030#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050031#include "src/gpu/GrTexturePriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040032#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050033#include "src/gpu/GrTextureProxyPriv.h"
Chris Dalton3d770272019-08-14 09:24:37 -060034#include "src/gpu/GrTextureResolveRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050035#include "src/gpu/GrTracing.h"
Greg Danielbbfec9d2019-08-20 10:56:51 -040036#include "src/gpu/GrTransferFromRenderTask.h"
Greg Danielc30f1a92019-09-06 15:28:58 -040037#include "src/gpu/GrWaitRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050038#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
39#include "src/gpu/text/GrTextContext.h"
40#include "src/image/SkSurface_Gpu.h"
robertphillips498d7ac2015-10-30 10:11:30 -070041
Chris Dalton6b498102019-08-01 14:14:52 -060042GrDrawingManager::RenderTaskDAG::RenderTaskDAG(bool sortRenderTasks)
43 : fSortRenderTasks(sortRenderTasks) {}
Robert Phillipsa3f70262018-02-08 10:59:38 -050044
Chris Dalton6b498102019-08-01 14:14:52 -060045GrDrawingManager::RenderTaskDAG::~RenderTaskDAG() {}
Robert Phillips22310d62018-09-05 11:07:21 -040046
Chris Dalton6b498102019-08-01 14:14:52 -060047void GrDrawingManager::RenderTaskDAG::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const {
48 idArray->reset(fRenderTasks.count());
49 for (int i = 0; i < fRenderTasks.count(); ++i) {
50 if (fRenderTasks[i]) {
51 (*idArray)[i] = fRenderTasks[i]->uniqueID();
Robert Phillips22310d62018-09-05 11:07:21 -040052 }
53 }
54}
55
Chris Dalton6b498102019-08-01 14:14:52 -060056void GrDrawingManager::RenderTaskDAG::reset() {
57 fRenderTasks.reset();
Robert Phillips22310d62018-09-05 11:07:21 -040058}
59
Chris Dalton6b498102019-08-01 14:14:52 -060060void GrDrawingManager::RenderTaskDAG::removeRenderTasks(int startIndex, int stopIndex) {
Robert Phillips22310d62018-09-05 11:07:21 -040061 for (int i = startIndex; i < stopIndex; ++i) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -040062 fRenderTasks[i] = nullptr;
Robert Phillips22310d62018-09-05 11:07:21 -040063 }
64}
65
Chris Dalton6b498102019-08-01 14:14:52 -060066bool GrDrawingManager::RenderTaskDAG::isUsed(GrSurfaceProxy* proxy) const {
67 for (int i = 0; i < fRenderTasks.count(); ++i) {
68 if (fRenderTasks[i] && fRenderTasks[i]->isUsed(proxy)) {
Robert Phillips9313aa72019-04-09 18:41:27 -040069 return true;
70 }
71 }
72
73 return false;
74}
75
Chris Dalton3d770272019-08-14 09:24:37 -060076GrRenderTask* GrDrawingManager::RenderTaskDAG::add(sk_sp<GrRenderTask> renderTask) {
Chris Dalton6aeb8e82019-08-27 11:52:19 -060077 if (renderTask) {
78 return fRenderTasks.emplace_back(std::move(renderTask)).get();
79 }
80 return nullptr;
Chris Dalton3d770272019-08-14 09:24:37 -060081}
82
83GrRenderTask* GrDrawingManager::RenderTaskDAG::addBeforeLast(sk_sp<GrRenderTask> renderTask) {
84 SkASSERT(!fRenderTasks.empty());
Chris Dalton6aeb8e82019-08-27 11:52:19 -060085 if (renderTask) {
86 // Release 'fRenderTasks.back()' and grab the raw pointer, in case the SkTArray grows
87 // and reallocates during emplace_back.
88 fRenderTasks.emplace_back(fRenderTasks.back().release());
89 return (fRenderTasks[fRenderTasks.count() - 2] = std::move(renderTask)).get();
90 }
91 return nullptr;
Robert Phillips22310d62018-09-05 11:07:21 -040092}
93
Greg Danielf41b2bd2019-08-22 16:19:24 -040094void GrDrawingManager::RenderTaskDAG::add(const SkTArray<sk_sp<GrRenderTask>>& renderTasks) {
Robert Phillips19f466d2020-02-26 10:27:07 -050095#ifdef SK_DEBUG
96 for (auto& renderTask : renderTasks) {
97 SkASSERT(renderTask->unique());
98 }
99#endif
100
Greg Danielf41b2bd2019-08-22 16:19:24 -0400101 fRenderTasks.push_back_n(renderTasks.count(), renderTasks.begin());
Robert Phillips22310d62018-09-05 11:07:21 -0400102}
103
Greg Danielf41b2bd2019-08-22 16:19:24 -0400104void GrDrawingManager::RenderTaskDAG::swap(SkTArray<sk_sp<GrRenderTask>>* renderTasks) {
105 SkASSERT(renderTasks->empty());
106 renderTasks->swap(fRenderTasks);
Robert Phillips22310d62018-09-05 11:07:21 -0400107}
108
Chris Dalton6b498102019-08-01 14:14:52 -0600109void GrDrawingManager::RenderTaskDAG::prepForFlush() {
110 if (fSortRenderTasks) {
111 SkDEBUGCODE(bool result =) SkTTopoSort<GrRenderTask, GrRenderTask::TopoSortTraits>(
112 &fRenderTasks);
Robert Phillips22310d62018-09-05 11:07:21 -0400113 SkASSERT(result);
114 }
115
116#ifdef SK_DEBUG
Greg Danielf41b2bd2019-08-22 16:19:24 -0400117 // This block checks for any unnecessary splits in the opsTasks. If two sequential opsTasks
118 // share the same backing GrSurfaceProxy it means the opsTask was artificially split.
Chris Dalton6b498102019-08-01 14:14:52 -0600119 if (fRenderTasks.count()) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400120 GrOpsTask* prevOpsTask = fRenderTasks[0]->asOpsTask();
Chris Dalton6b498102019-08-01 14:14:52 -0600121 for (int i = 1; i < fRenderTasks.count(); ++i) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400122 GrOpsTask* curOpsTask = fRenderTasks[i]->asOpsTask();
Robert Phillips22310d62018-09-05 11:07:21 -0400123
Greg Danielf41b2bd2019-08-22 16:19:24 -0400124 if (prevOpsTask && curOpsTask) {
Greg Daniel16f5c652019-10-29 11:26:01 -0400125 SkASSERT(prevOpsTask->fTargetView != curOpsTask->fTargetView);
Robert Phillips22310d62018-09-05 11:07:21 -0400126 }
127
Greg Danielf41b2bd2019-08-22 16:19:24 -0400128 prevOpsTask = curOpsTask;
Robert Phillips22310d62018-09-05 11:07:21 -0400129 }
130 }
131#endif
132}
133
Chris Dalton6b498102019-08-01 14:14:52 -0600134void GrDrawingManager::RenderTaskDAG::closeAll(const GrCaps* caps) {
135 for (int i = 0; i < fRenderTasks.count(); ++i) {
136 if (fRenderTasks[i]) {
137 fRenderTasks[i]->makeClosed(*caps);
Robert Phillips22310d62018-09-05 11:07:21 -0400138 }
139 }
140}
141
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400142void GrDrawingManager::RenderTaskDAG::cleanup(GrDrawingManager* drawingMgr, const GrCaps* caps) {
Chris Dalton6b498102019-08-01 14:14:52 -0600143 for (int i = 0; i < fRenderTasks.count(); ++i) {
144 if (!fRenderTasks[i]) {
Robert Phillips22310d62018-09-05 11:07:21 -0400145 continue;
146 }
147
Chris Dalton6b498102019-08-01 14:14:52 -0600148 // no renderTask should receive a dependency
149 fRenderTasks[i]->makeClosed(*caps);
robertphillips0dfa62c2015-11-16 06:23:31 -0800150
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400151 fRenderTasks[i]->disown(drawingMgr);
152
Greg Danielf41b2bd2019-08-22 16:19:24 -0400153 // We shouldn't need to do this, but it turns out some clients still hold onto opsTasks
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400154 // after a cleanup.
155 // MDB TODO: is this still true?
Chris Dalton6b498102019-08-01 14:14:52 -0600156 if (!fRenderTasks[i]->unique()) {
Chris Daltona84cacf2017-10-04 10:30:29 -0600157 // TODO: Eventually this should be guaranteed unique.
158 // https://bugs.chromium.org/p/skia/issues/detail?id=7111
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400159 fRenderTasks[i]->endFlush(drawingMgr);
Chris Daltona84cacf2017-10-04 10:30:29 -0600160 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700161 }
162
Chris Dalton6b498102019-08-01 14:14:52 -0600163 fRenderTasks.reset();
Robert Phillips22310d62018-09-05 11:07:21 -0400164}
165
166///////////////////////////////////////////////////////////////////////////////////////////////////
Robert Phillips69893702019-02-22 11:16:30 -0500167GrDrawingManager::GrDrawingManager(GrRecordingContext* context,
Robert Phillips22310d62018-09-05 11:07:21 -0400168 const GrPathRendererChain::Options& optionsForPathRendererChain,
169 const GrTextContext::Options& optionsForTextContext,
Chris Dalton6b498102019-08-01 14:14:52 -0600170 bool sortRenderTasks,
Greg Danielf41b2bd2019-08-22 16:19:24 -0400171 bool reduceOpsTaskSplitting)
Robert Phillips22310d62018-09-05 11:07:21 -0400172 : fContext(context)
173 , fOptionsForPathRendererChain(optionsForPathRendererChain)
174 , fOptionsForTextContext(optionsForTextContext)
Chris Dalton6b498102019-08-01 14:14:52 -0600175 , fDAG(sortRenderTasks)
Robert Phillips22310d62018-09-05 11:07:21 -0400176 , fTextContext(nullptr)
177 , fPathRendererChain(nullptr)
178 , fSoftwarePathRenderer(nullptr)
Robert Phillips6db27c22019-05-01 10:43:56 -0400179 , fFlushing(false)
Greg Danielf41b2bd2019-08-22 16:19:24 -0400180 , fReduceOpsTaskSplitting(reduceOpsTaskSplitting) {
Robert Phillips22310d62018-09-05 11:07:21 -0400181}
182
183void GrDrawingManager::cleanup() {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400184 fDAG.cleanup(this, fContext->priv().caps());
robertphillips3dc6ae52015-10-20 09:54:32 -0700185
robertphillips13391dd2015-10-30 05:15:11 -0700186 fPathRendererChain = nullptr;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400187 fSoftwarePathRenderer = nullptr;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400188
189 fOnFlushCBObjects.reset();
robertphillips3dc6ae52015-10-20 09:54:32 -0700190}
191
192GrDrawingManager::~GrDrawingManager() {
193 this->cleanup();
194}
195
Robert Phillipsa9162df2019-02-11 14:12:03 -0500196bool GrDrawingManager::wasAbandoned() const {
Robert Phillips6a6de562019-02-15 15:19:15 -0500197 return fContext->priv().abandoned();
robertphillips3dc6ae52015-10-20 09:54:32 -0700198}
199
robertphillips68737822015-10-29 12:12:21 -0700200void GrDrawingManager::freeGpuResources() {
Jim Van Verth106b5c42017-09-26 12:45:29 -0400201 for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) {
202 if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) {
203 // it's safe to just do this because we're iterating in reverse
204 fOnFlushCBObjects.removeShuffle(i);
205 }
206 }
207
robertphillips68737822015-10-29 12:12:21 -0700208 // a path renderer may be holding onto resources
robertphillips13391dd2015-10-30 05:15:11 -0700209 fPathRendererChain = nullptr;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400210 fSoftwarePathRenderer = nullptr;
Robert Phillipse3302df2017-04-24 07:31:02 -0400211}
212
Robert Phillips7ee385e2017-03-30 08:02:11 -0400213// MDB TODO: make use of the 'proxy' parameter.
Greg Danielfe159622020-04-10 17:43:51 +0000214bool GrDrawingManager::flush(GrSurfaceProxy* proxies[], int numProxies,
Greg Daniel797efca2019-05-09 14:04:20 -0400215 SkSurface::BackendSurfaceAccess access, const GrFlushInfo& info,
216 const GrPrepareForExternalIORequests& externalRequests) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400217 SkASSERT(numProxies >= 0);
218 SkASSERT(!numProxies || proxies);
Brian Salomon57d2beab2018-09-10 09:35:41 -0400219 GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
Brian Salomondcbb9d92017-07-19 10:53:20 -0400220
robertphillips7761d612016-05-16 09:14:53 -0700221 if (fFlushing || this->wasAbandoned()) {
Greg Daniel55822f12020-05-26 11:26:45 -0400222 if (info.fSubmittedProc) {
223 info.fSubmittedProc(info.fSubmittedContext, false);
224 }
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400225 if (info.fFinishedProc) {
226 info.fFinishedProc(info.fFinishedContext);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400227 }
Greg Danielfe159622020-04-10 17:43:51 +0000228 return false;
joshualittb8918c42015-12-18 09:59:46 -0800229 }
Robert Phillips602df412019-04-08 11:10:39 -0400230
Robert Phillips38d64b02018-09-04 13:23:26 -0400231 SkDEBUGCODE(this->validate());
232
Greg Daniel797efca2019-05-09 14:04:20 -0400233 if (kNone_GrFlushFlags == info.fFlags && !info.fNumSemaphores && !info.fFinishedProc &&
Jim Van Verth682a2f42020-05-13 16:54:09 -0400234 access == SkSurface::BackendSurfaceAccess::kNoAccess &&
Greg Daniel797efca2019-05-09 14:04:20 -0400235 !externalRequests.hasRequests()) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400236 bool canSkip = numProxies > 0;
237 for (int i = 0; i < numProxies && canSkip; ++i) {
238 canSkip = !fDAG.isUsed(proxies[i]) && !this->isDDLTarget(proxies[i]);
239 }
240 if (canSkip) {
Greg Daniel55822f12020-05-26 11:26:45 -0400241 if (info.fSubmittedProc) {
242 info.fSubmittedProc(info.fSubmittedContext, true);
243 }
Greg Danielfe159622020-04-10 17:43:51 +0000244 return false;
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400245 }
Robert Phillips9313aa72019-04-09 18:41:27 -0400246 }
247
Robert Phillips6a6de562019-02-15 15:19:15 -0500248 auto direct = fContext->priv().asDirectContext();
249 if (!direct) {
Greg Daniel55822f12020-05-26 11:26:45 -0400250 if (info.fSubmittedProc) {
251 info.fSubmittedProc(info.fSubmittedContext, false);
252 }
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400253 if (info.fFinishedProc) {
254 info.fFinishedProc(info.fFinishedContext);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400255 }
Greg Danielfe159622020-04-10 17:43:51 +0000256 return false; // Can't flush while DDL recording
Robert Phillips6a6de562019-02-15 15:19:15 -0500257 }
Brian Salomon9241a6d2019-10-03 13:26:54 -0400258 direct->priv().clientMappedBufferManager()->process();
Robert Phillips6a6de562019-02-15 15:19:15 -0500259
260 GrGpu* gpu = direct->priv().getGpu();
Greg Daniel55822f12020-05-26 11:26:45 -0400261 // We have a non abandoned and direct GrContext. It must have a GrGpu.
262 SkASSERT(gpu);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400263
joshualittb8918c42015-12-18 09:59:46 -0800264 fFlushing = true;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400265
Robert Phillips6a6de562019-02-15 15:19:15 -0500266 auto resourceProvider = direct->priv().resourceProvider();
267 auto resourceCache = direct->priv().getResourceCache();
268
Chris Dalton6b498102019-08-01 14:14:52 -0600269 // Semi-usually the GrRenderTasks are already closed at this point, but sometimes Ganesh needs
Greg Danielf41b2bd2019-08-22 16:19:24 -0400270 // to flush mid-draw. In that case, the SkGpuDevice's opsTasks won't be closed but need to be
271 // flushed anyway. Closing such opsTasks here will mean new ones will be created to replace them
Chris Dalton6b498102019-08-01 14:14:52 -0600272 // if the SkGpuDevice(s) write to them again.
Robert Phillips9da87e02019-02-04 13:26:26 -0500273 fDAG.closeAll(fContext->priv().caps());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400274 fActiveOpsTask = nullptr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400275
Robert Phillips22310d62018-09-05 11:07:21 -0400276 fDAG.prepForFlush();
Brian Salomon601ac802019-02-07 13:37:16 -0500277 if (!fCpuBufferCache) {
278 // We cache more buffers when the backend is using client side arrays. Otherwise, we
279 // expect each pool will use a CPU buffer as a staging buffer before uploading to a GPU
280 // buffer object. Each pool only requires one staging buffer at a time.
281 int maxCachedBuffers = fContext->priv().caps()->preferClientSideDynamicBuffers() ? 2 : 6;
282 fCpuBufferCache = GrBufferAllocPool::CpuBufferCache::Make(maxCachedBuffers);
Brian Salomon58f153c2018-10-18 21:51:15 -0400283 }
Robert Phillipsa4c93ac2017-05-18 11:40:04 -0400284
Robert Phillipse5f73282019-06-18 17:15:04 -0400285 GrOpFlushState flushState(gpu, resourceProvider, &fTokenTracker, fCpuBufferCache);
Robert Phillips40a29d72018-01-18 12:59:22 -0500286
Chris Daltonfe199b72017-05-05 11:26:15 -0400287 GrOnFlushResourceProvider onFlushProvider(this);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500288 // TODO: AFAICT the only reason fFlushState is on GrDrawingManager rather than on the
289 // stack here is to preserve the flush tokens.
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400290
Chris Dalton12658942017-10-05 19:45:25 -0600291 // Prepare any onFlush op lists (e.g. atlases).
Chris Daltonfe199b72017-05-05 11:26:15 -0400292 if (!fOnFlushCBObjects.empty()) {
Chris Dalton6b498102019-08-01 14:14:52 -0600293 fDAG.gatherIDs(&fFlushingRenderTaskIDs);
Robert Phillips22310d62018-09-05 11:07:21 -0400294
Chris Daltonfe199b72017-05-05 11:26:15 -0400295 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Chris Dalton6b498102019-08-01 14:14:52 -0600296 onFlushCBObject->preFlush(&onFlushProvider, fFlushingRenderTaskIDs.begin(),
Chris Daltonc4b47352019-08-23 10:10:36 -0600297 fFlushingRenderTaskIDs.count());
298 }
299 for (const auto& onFlushRenderTask : fOnFlushRenderTasks) {
300 onFlushRenderTask->makeClosed(*fContext->priv().caps());
Chris Dalton706a6ff2017-11-29 22:01:06 -0700301#ifdef SK_DEBUG
Chris Daltonc4b47352019-08-23 10:10:36 -0600302 // OnFlush callbacks are invoked during flush, and are therefore expected to handle
303 // resource allocation & usage on their own. (No deferred or lazy proxies!)
304 onFlushRenderTask->visitTargetAndSrcProxies_debugOnly(
305 [](GrSurfaceProxy* p, GrMipMapped mipMapped) {
306 SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred());
Brian Salomonbeb7f522019-08-30 16:19:42 -0400307 SkASSERT(!p->isLazy());
Chris Dalton4ece96d2019-08-30 11:26:39 -0600308 if (p->requiresManualMSAAResolve()) {
309 // The onFlush callback is responsible for ensuring MSAA gets resolved.
310 SkASSERT(p->asRenderTargetProxy() && !p->asRenderTargetProxy()->isMSAADirty());
311 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600312 if (GrMipMapped::kYes == mipMapped) {
313 // The onFlush callback is responsible for regenerating mips if needed.
314 SkASSERT(p->asTextureProxy() && !p->asTextureProxy()->mipMapsAreDirty());
315 }
316 });
Chris Dalton706a6ff2017-11-29 22:01:06 -0700317#endif
Chris Daltonc4b47352019-08-23 10:10:36 -0600318 onFlushRenderTask->prepare(&flushState);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400319 }
320 }
321
robertphillipsa13e2022015-11-11 12:01:09 -0800322#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500323 // Enable this to print out verbose GrOp information
Chris Daltonc4b47352019-08-23 10:10:36 -0600324 SkDEBUGCODE(SkDebugf("onFlush renderTasks:"));
325 for (const auto& onFlushRenderTask : fOnFlushRenderTasks) {
326 SkDEBUGCODE(onFlushRenderTask->dump();)
327 }
328 SkDEBUGCODE(SkDebugf("Normal renderTasks:"));
Chris Dalton6b498102019-08-01 14:14:52 -0600329 for (int i = 0; i < fRenderTasks.count(); ++i) {
330 SkDEBUGCODE(fRenderTasks[i]->dump();)
robertphillips3dc6ae52015-10-20 09:54:32 -0700331 }
robertphillipsa13e2022015-11-11 12:01:09 -0800332#endif
333
Robert Phillipseafd48a2017-11-16 07:52:08 -0500334 int startIndex, stopIndex;
335 bool flushed = false;
336
Robert Phillipsf8e25022017-11-08 15:24:31 -0500337 {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400338 GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, fDAG.numRenderTasks()));
Chris Dalton6b498102019-08-01 14:14:52 -0600339 for (int i = 0; i < fDAG.numRenderTasks(); ++i) {
340 if (fDAG.renderTask(i)) {
341 fDAG.renderTask(i)->gatherProxyIntervals(&alloc);
Robert Phillips22310d62018-09-05 11:07:21 -0400342 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400343 alloc.markEndOfOpsTask(i);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500344 }
Robert Phillipsc73666f2019-04-24 08:49:48 -0400345 alloc.determineRecyclability();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400346
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500347 GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError;
Chris Dalton6b498102019-08-01 14:14:52 -0600348 int numRenderTasksExecuted = 0;
Brian Salomon577aa0f2018-11-30 13:32:23 -0500349 while (alloc.assign(&startIndex, &stopIndex, &error)) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500350 if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) {
351 for (int i = startIndex; i < stopIndex; ++i) {
Chris Dalton6b498102019-08-01 14:14:52 -0600352 GrRenderTask* renderTask = fDAG.renderTask(i);
353 if (!renderTask) {
354 continue;
Robert Phillips01a91282018-07-26 08:03:04 -0400355 }
Chris Dalton6b498102019-08-01 14:14:52 -0600356 if (!renderTask->isInstantiated()) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400357 // No need to call the renderTask's handleInternalAllocationFailure
358 // since we will already skip executing the renderTask since it is not
359 // instantiated.
Chris Dalton6b498102019-08-01 14:14:52 -0600360 continue;
Robert Phillipsbbcb7f72018-05-31 11:16:19 -0400361 }
Chris Dalton6b498102019-08-01 14:14:52 -0600362 renderTask->handleInternalAllocationFailure();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500363 }
364 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500365
Chris Dalton6b498102019-08-01 14:14:52 -0600366 if (this->executeRenderTasks(
367 startIndex, stopIndex, &flushState, &numRenderTasksExecuted)) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500368 flushed = true;
369 }
bsalomondc438982016-08-31 11:53:49 -0700370 }
Greg Danielc42b20b2017-10-04 10:34:49 -0400371 }
372
Chris Dalton91ab1552018-04-18 13:24:25 -0600373#ifdef SK_DEBUG
Chris Dalton6b498102019-08-01 14:14:52 -0600374 for (int i = 0; i < fDAG.numRenderTasks(); ++i) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400375 // If there are any remaining opsTaskss at this point, make sure they will not survive the
Chris Dalton91ab1552018-04-18 13:24:25 -0600376 // flush. Otherwise we need to call endFlush() on them.
377 // http://skbug.com/7111
Chris Dalton6b498102019-08-01 14:14:52 -0600378 SkASSERT(!fDAG.renderTask(i) || fDAG.renderTask(i)->unique());
Chris Dalton91ab1552018-04-18 13:24:25 -0600379 }
380#endif
Adlai Holler25df1f72020-06-09 13:08:27 -0400381 fLastRenderTasks.reset();
Robert Phillips22310d62018-09-05 11:07:21 -0400382 fDAG.reset();
Robert Phillips15c91422019-05-07 16:54:48 -0400383 this->clearDDLTargets();
robertphillipsa13e2022015-11-11 12:01:09 -0800384
Robert Phillipsc994a932018-06-19 13:09:54 -0400385#ifdef SK_DEBUG
386 // In non-DDL mode this checks that all the flushed ops have been freed from the memory pool.
387 // When we move to partial flushes this assert will no longer be valid.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400388 // In DDL mode this check is somewhat superfluous since the memory for most of the ops/opsTasks
Robert Phillipsc994a932018-06-19 13:09:54 -0400389 // will be stored in the DDL's GrOpMemoryPools.
Robert Phillips9da87e02019-02-04 13:26:26 -0500390 GrOpMemoryPool* opMemoryPool = fContext->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -0400391 opMemoryPool->isEmpty();
392#endif
393
Greg Danielfe159622020-04-10 17:43:51 +0000394 gpu->executeFlushInfo(proxies, numProxies, access, info, externalRequests);
robertphillipsa13e2022015-11-11 12:01:09 -0800395
Brian Salomon57d2beab2018-09-10 09:35:41 -0400396 // Give the cache a chance to purge resources that become purgeable due to flushing.
397 if (flushed) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500398 resourceCache->purgeAsNeeded();
Brian Salomon876a0172019-03-08 11:12:14 -0500399 flushed = false;
bsalomonb77a9072016-09-07 10:02:04 -0700400 }
Chris Daltonfe199b72017-05-05 11:26:15 -0400401 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Chris Dalton6b498102019-08-01 14:14:52 -0600402 onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingRenderTaskIDs.begin(),
403 fFlushingRenderTaskIDs.count());
Brian Salomon876a0172019-03-08 11:12:14 -0500404 flushed = true;
405 }
406 if (flushed) {
407 resourceCache->purgeAsNeeded();
Chris Daltonfe199b72017-05-05 11:26:15 -0400408 }
Chris Dalton6b498102019-08-01 14:14:52 -0600409 fFlushingRenderTaskIDs.reset();
joshualittb8918c42015-12-18 09:59:46 -0800410 fFlushing = false;
Greg Daniel51316782017-08-02 15:10:09 +0000411
Greg Danielfe159622020-04-10 17:43:51 +0000412 return true;
413}
414
415bool GrDrawingManager::submitToGpu(bool syncToCpu) {
416 if (fFlushing || this->wasAbandoned()) {
417 return false;
418 }
419
420 auto direct = fContext->priv().asDirectContext();
421 if (!direct) {
422 return false; // Can't submit while DDL recording
423 }
424 GrGpu* gpu = direct->priv().getGpu();
425 return gpu->submitToGpu(syncToCpu);
robertphillips3dc6ae52015-10-20 09:54:32 -0700426}
427
Chris Dalton6b498102019-08-01 14:14:52 -0600428bool GrDrawingManager::executeRenderTasks(int startIndex, int stopIndex, GrOpFlushState* flushState,
429 int* numRenderTasksExecuted) {
430 SkASSERT(startIndex <= stopIndex && stopIndex <= fDAG.numRenderTasks());
Robert Phillipseafd48a2017-11-16 07:52:08 -0500431
Robert Phillips27483912018-04-20 12:43:18 -0400432#if GR_FLUSH_TIME_OP_SPEW
Greg Danielf41b2bd2019-08-22 16:19:24 -0400433 SkDebugf("Flushing opsTask: %d to %d out of [%d, %d]\n",
Chris Dalton6b498102019-08-01 14:14:52 -0600434 startIndex, stopIndex, 0, fDAG.numRenderTasks());
Robert Phillips27483912018-04-20 12:43:18 -0400435 for (int i = startIndex; i < stopIndex; ++i) {
Chris Dalton6b498102019-08-01 14:14:52 -0600436 if (fDAG.renderTask(i)) {
437 fDAG.renderTask(i)->dump(true);
Robert Phillips1734dd32018-08-21 13:52:09 -0400438 }
Robert Phillips27483912018-04-20 12:43:18 -0400439 }
440#endif
441
Chris Dalton6b498102019-08-01 14:14:52 -0600442 bool anyRenderTasksExecuted = false;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500443
444 for (int i = startIndex; i < stopIndex; ++i) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400445 GrRenderTask* renderTask = fDAG.renderTask(i);
446 if (!renderTask || !renderTask->isInstantiated()) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500447 continue;
448 }
449
Chris Dalton6b498102019-08-01 14:14:52 -0600450 SkASSERT(renderTask->deferredProxiesAreInstantiated());
Robert Phillips22310d62018-09-05 11:07:21 -0400451
Chris Dalton6b498102019-08-01 14:14:52 -0600452 renderTask->prepare(flushState);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500453 }
454
455 // Upload all data to the GPU
456 flushState->preExecuteDraws();
457
Greg Danield2073452018-12-07 11:20:33 -0500458 // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources
459 // for each command buffer associated with the oplists. If this gets too large we can cause the
460 // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we
461 // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some
462 // memory pressure.
Chris Dalton6b498102019-08-01 14:14:52 -0600463 static constexpr int kMaxRenderTasksBeforeFlush = 100;
Greg Danield2073452018-12-07 11:20:33 -0500464
Chris Daltonc4b47352019-08-23 10:10:36 -0600465 // Execute the onFlush renderTasks first, if any.
466 for (sk_sp<GrRenderTask>& onFlushRenderTask : fOnFlushRenderTasks) {
467 if (!onFlushRenderTask->execute(flushState)) {
468 SkDebugf("WARNING: onFlushRenderTask failed to execute.\n");
Robert Phillipseafd48a2017-11-16 07:52:08 -0500469 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600470 SkASSERT(onFlushRenderTask->unique());
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400471 onFlushRenderTask->disown(this);
Chris Daltonc4b47352019-08-23 10:10:36 -0600472 onFlushRenderTask = nullptr;
Chris Dalton6b498102019-08-01 14:14:52 -0600473 (*numRenderTasksExecuted)++;
474 if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
Greg Danielfe159622020-04-10 17:43:51 +0000475 flushState->gpu()->submitToGpu(false);
Chris Dalton6b498102019-08-01 14:14:52 -0600476 *numRenderTasksExecuted = 0;
Greg Danield2073452018-12-07 11:20:33 -0500477 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500478 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600479 fOnFlushRenderTasks.reset();
Robert Phillipseafd48a2017-11-16 07:52:08 -0500480
481 // Execute the normal op lists.
482 for (int i = startIndex; i < stopIndex; ++i) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400483 GrRenderTask* renderTask = fDAG.renderTask(i);
484 if (!renderTask || !renderTask->isInstantiated()) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500485 continue;
486 }
487
Greg Daniel15ecdf92019-08-30 15:35:23 -0400488 if (renderTask->execute(flushState)) {
Chris Dalton6b498102019-08-01 14:14:52 -0600489 anyRenderTasksExecuted = true;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500490 }
Chris Dalton6b498102019-08-01 14:14:52 -0600491 (*numRenderTasksExecuted)++;
492 if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
Greg Danielfe159622020-04-10 17:43:51 +0000493 flushState->gpu()->submitToGpu(false);
Chris Dalton6b498102019-08-01 14:14:52 -0600494 *numRenderTasksExecuted = 0;
Greg Danield2073452018-12-07 11:20:33 -0500495 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500496 }
497
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400498 SkASSERT(!flushState->opsRenderPass());
Robert Phillips40a29d72018-01-18 12:59:22 -0500499 SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush());
Robert Phillipseafd48a2017-11-16 07:52:08 -0500500
Chris Dalton6b498102019-08-01 14:14:52 -0600501 // We reset the flush state before the RenderTasks so that the last resources to be freed are
502 // those that are written to in the RenderTasks. This helps to make sure the most recently used
503 // resources are the last to be purged by the resource cache.
Robert Phillipseafd48a2017-11-16 07:52:08 -0500504 flushState->reset();
505
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400506 this->removeRenderTasks(startIndex, stopIndex);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500507
Chris Dalton6b498102019-08-01 14:14:52 -0600508 return anyRenderTasksExecuted;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500509}
510
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400511void GrDrawingManager::removeRenderTasks(int startIndex, int stopIndex) {
512 for (int i = startIndex; i < stopIndex; ++i) {
513 GrRenderTask* task = fDAG.renderTask(i);
514 if (!task) {
515 continue;
516 }
517 if (!task->unique()) {
518 // TODO: Eventually this should be guaranteed unique: http://skbug.com/7111
519 task->endFlush(this);
520 }
521 task->disown(this);
522 }
523 fDAG.removeRenderTasks(startIndex, stopIndex);
524}
525
Greg Daniel55f040b2020-02-13 15:38:32 +0000526GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400527 SkSurface::BackendSurfaceAccess access,
528 const GrFlushInfo& info) {
bsalomon6a2b1942016-09-08 11:28:59 -0700529 if (this->wasAbandoned()) {
Greg Daniel55822f12020-05-26 11:26:45 -0400530 if (info.fSubmittedProc) {
531 info.fSubmittedProc(info.fSubmittedContext, false);
532 }
533 if (info.fFinishedProc) {
534 info.fFinishedProc(info.fFinishedContext);
535 }
Greg Daniel51316782017-08-02 15:10:09 +0000536 return GrSemaphoresSubmitted::kNo;
bsalomon6a2b1942016-09-08 11:28:59 -0700537 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400538 SkDEBUGCODE(this->validate());
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400539 SkASSERT(numProxies >= 0);
540 SkASSERT(!numProxies || proxies);
bsalomon6a2b1942016-09-08 11:28:59 -0700541
Robert Phillips6a6de562019-02-15 15:19:15 -0500542 auto direct = fContext->priv().asDirectContext();
543 if (!direct) {
Greg Daniel55822f12020-05-26 11:26:45 -0400544 if (info.fSubmittedProc) {
545 info.fSubmittedProc(info.fSubmittedContext, false);
546 }
547 if (info.fFinishedProc) {
548 info.fFinishedProc(info.fFinishedContext);
549 }
Robert Phillips6a6de562019-02-15 15:19:15 -0500550 return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording
551 }
552
553 GrGpu* gpu = direct->priv().getGpu();
Greg Daniel55822f12020-05-26 11:26:45 -0400554 // We have a non abandoned and direct GrContext. It must have a GrGpu.
555 SkASSERT(gpu);
Robert Phillips874b5352018-03-16 08:48:24 -0400556
Robert Phillipsacc10fa2019-04-01 09:50:20 -0400557 // TODO: It is important to upgrade the drawingmanager to just flushing the
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400558 // portion of the DAG required by 'proxies' in order to restore some of the
Robert Phillipsacc10fa2019-04-01 09:50:20 -0400559 // semantics of this method.
Greg Danielfe159622020-04-10 17:43:51 +0000560 bool didFlush = this->flush(proxies, numProxies, access, info,
561 GrPrepareForExternalIORequests());
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400562 for (int i = 0; i < numProxies; ++i) {
Chris Dalton4ece96d2019-08-30 11:26:39 -0600563 GrSurfaceProxy* proxy = proxies[i];
564 if (!proxy->isInstantiated()) {
Greg Danielfe159622020-04-10 17:43:51 +0000565 continue;
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400566 }
Chris Dalton4ece96d2019-08-30 11:26:39 -0600567 // In the flushSurfaces case, we need to resolve MSAA immediately after flush. This is
568 // because the client will call through to this method when drawing into a target created by
569 // wrapBackendTextureAsRenderTarget, and will expect the original texture to be fully
570 // resolved upon return.
571 if (proxy->requiresManualMSAAResolve()) {
572 auto* rtProxy = proxy->asRenderTargetProxy();
573 SkASSERT(rtProxy);
574 if (rtProxy->isMSAADirty()) {
575 SkASSERT(rtProxy->peekRenderTarget());
Chris Dalton16a33c62019-09-24 22:19:17 -0600576 gpu->resolveRenderTarget(rtProxy->peekRenderTarget(), rtProxy->msaaDirtyRect(),
Greg Daniel242536f2020-02-13 14:12:46 -0500577 GrGpu::ForExternalIO::kYes);
Chris Dalton4ece96d2019-08-30 11:26:39 -0600578 rtProxy->markMSAAResolved();
579 }
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400580 }
Chris Dalton3d770272019-08-14 09:24:37 -0600581 // If, after a flush, any of the proxies of interest have dirty mipmaps, regenerate them in
582 // case their backend textures are being stolen.
583 // (This special case is exercised by the ReimportImageTextureWithMipLevels test.)
584 // FIXME: It may be more ideal to plumb down a "we're going to steal the backends" flag.
Chris Dalton4ece96d2019-08-30 11:26:39 -0600585 if (auto* textureProxy = proxy->asTextureProxy()) {
Chris Dalton3d770272019-08-14 09:24:37 -0600586 if (textureProxy->mipMapsAreDirty()) {
Chris Dalton4ece96d2019-08-30 11:26:39 -0600587 SkASSERT(textureProxy->peekTexture());
Chris Dalton3d770272019-08-14 09:24:37 -0600588 gpu->regenerateMipMapLevels(textureProxy->peekTexture());
589 textureProxy->markMipMapsClean();
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400590 }
Brian Salomon930f9392018-06-20 16:25:26 -0400591 }
bsalomon6a2b1942016-09-08 11:28:59 -0700592 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400593
594 SkDEBUGCODE(this->validate());
Greg Danielfe159622020-04-10 17:43:51 +0000595
Greg Daniel04283f32020-05-20 13:16:00 -0400596 if (!didFlush || (!direct->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
Greg Danielfe159622020-04-10 17:43:51 +0000597 return GrSemaphoresSubmitted::kNo;
598 }
599 return GrSemaphoresSubmitted::kYes;
bsalomon6a2b1942016-09-08 11:28:59 -0700600}
601
Chris Daltonfe199b72017-05-05 11:26:15 -0400602void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
603 fOnFlushCBObjects.push_back(onFlushCBObject);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400604}
605
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500606#if GR_TEST_UTILS
607void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
608 int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) -
609 fOnFlushCBObjects.begin();
610 SkASSERT(n < fOnFlushCBObjects.count());
611 fOnFlushCBObjects.removeShuffle(n);
612}
613#endif
614
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400615void GrDrawingManager::setLastRenderTask(const GrSurfaceProxy* proxy, GrRenderTask* task) {
616#ifdef SK_DEBUG
617 if (GrRenderTask* prior = this->getLastRenderTask(proxy)) {
618 SkASSERT(prior->isClosed());
619 }
620#endif
Adlai Holler25df1f72020-06-09 13:08:27 -0400621 uint32_t key = proxy->uniqueID().asUInt();
622 if (task) {
623 fLastRenderTasks.set(key, task);
624 } else if (fLastRenderTasks.find(key)) {
625 fLastRenderTasks.remove(key);
626 }
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400627}
628
629GrRenderTask* GrDrawingManager::getLastRenderTask(const GrSurfaceProxy* proxy) const {
630 auto entry = fLastRenderTasks.find(proxy->uniqueID().asUInt());
631 return entry ? *entry : nullptr;
632}
633
634GrOpsTask* GrDrawingManager::getLastOpsTask(const GrSurfaceProxy* proxy) const {
635 GrRenderTask* task = this->getLastRenderTask(proxy);
636 return task ? task->asOpsTask() : nullptr;
637}
638
639
Chris Dalton6b498102019-08-01 14:14:52 -0600640void GrDrawingManager::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400641 SkDEBUGCODE(this->validate());
642
Chris Dalton6b498102019-08-01 14:14:52 -0600643 // no renderTask should receive a new command after this
Robert Phillips9da87e02019-02-04 13:26:26 -0500644 fDAG.closeAll(fContext->priv().caps());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400645 fActiveOpsTask = nullptr;
Robert Phillips7a137052018-02-01 11:23:12 -0500646
Chris Dalton6b498102019-08-01 14:14:52 -0600647 fDAG.swap(&ddl->fRenderTasks);
Robert Phillips19f466d2020-02-26 10:27:07 -0500648 SkASSERT(!fDAG.numRenderTasks());
Robert Phillips867ce8f2018-06-21 10:28:36 -0400649
Robert Phillips19f466d2020-02-26 10:27:07 -0500650 for (auto& renderTask : ddl->fRenderTasks) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400651 renderTask->disown(this);
Robert Phillips29f38542019-10-16 09:20:25 -0400652 renderTask->prePrepare(fContext);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400653 }
654
Michael Ludwig2c316bd2019-12-19 14:50:44 -0500655 ddl->fArenas = std::move(fContext->priv().detachArenas());
Robert Phillips61fc7992019-10-22 11:58:17 -0400656
Robert Phillipsf6a0b452020-02-18 14:26:46 -0500657 fContext->priv().detachProgramData(&ddl->fProgramData);
Robert Phillips576b6a12019-12-06 13:05:49 -0500658
Robert Phillips774168e2018-05-31 12:43:27 -0400659 if (fPathRendererChain) {
660 if (auto ccpr = fPathRendererChain->getCoverageCountingPathRenderer()) {
661 ddl->fPendingPaths = ccpr->detachPendingPaths();
662 }
663 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400664
665 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500666}
667
Chris Dalton6b498102019-08-01 14:14:52 -0600668void GrDrawingManager::copyRenderTasksFromDDL(const SkDeferredDisplayList* ddl,
Robert Phillips933484f2019-11-26 09:38:55 -0500669 GrRenderTargetProxy* newDest) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400670 SkDEBUGCODE(this->validate());
671
Greg Danielf41b2bd2019-08-22 16:19:24 -0400672 if (fActiveOpsTask) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400673 // This is a temporary fix for the partial-MDB world. In that world we're not
Greg Danielf41b2bd2019-08-22 16:19:24 -0400674 // reordering so ops that (in the single opsTask world) would've just glommed onto the
675 // end of the single opsTask but referred to a far earlier RT need to appear in their
676 // own opsTask.
677 fActiveOpsTask->makeClosed(*fContext->priv().caps());
678 fActiveOpsTask = nullptr;
Robert Phillips38d64b02018-09-04 13:23:26 -0400679 }
680
Robert Phillips15c91422019-05-07 16:54:48 -0400681 this->addDDLTarget(newDest);
682
Robert Phillips62000362018-02-01 09:10:04 -0500683 // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400684 // The lazy proxy that references it (in the copied opsTasks) will steal its GrTexture.
Robert Phillips62000362018-02-01 09:10:04 -0500685 ddl->fLazyProxyData->fReplayDest = newDest;
Robert Phillips774168e2018-05-31 12:43:27 -0400686
687 if (ddl->fPendingPaths.size()) {
688 GrCoverageCountingPathRenderer* ccpr = this->getCoverageCountingPathRenderer();
689
690 ccpr->mergePendingPaths(ddl->fPendingPaths);
691 }
Robert Phillips22310d62018-09-05 11:07:21 -0400692
Chris Dalton6b498102019-08-01 14:14:52 -0600693 fDAG.add(ddl->fRenderTasks);
Robert Phillips38d64b02018-09-04 13:23:26 -0400694
695 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500696}
697
Robert Phillips38d64b02018-09-04 13:23:26 -0400698#ifdef SK_DEBUG
699void GrDrawingManager::validate() const {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400700 if (fDAG.sortingRenderTasks() && fReduceOpsTaskSplitting) {
701 SkASSERT(!fActiveOpsTask);
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400702 } else {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400703 if (fActiveOpsTask) {
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400704 SkASSERT(!fDAG.empty());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400705 SkASSERT(!fActiveOpsTask->isClosed());
706 SkASSERT(fActiveOpsTask == fDAG.back());
Robert Phillips38d64b02018-09-04 13:23:26 -0400707 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400708
Chris Dalton6b498102019-08-01 14:14:52 -0600709 for (int i = 0; i < fDAG.numRenderTasks(); ++i) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400710 if (fActiveOpsTask != fDAG.renderTask(i)) {
Chris Daltone2a903e2019-09-18 13:41:50 -0600711 // The resolveTask associated with the activeTask remains open for as long as the
712 // activeTask does.
713 bool isActiveResolveTask =
714 fActiveOpsTask && fActiveOpsTask->fTextureResolveTask == fDAG.renderTask(i);
715 SkASSERT(isActiveResolveTask || fDAG.renderTask(i)->isClosed());
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400716 }
717 }
718
719 if (!fDAG.empty() && !fDAG.back()->isClosed()) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400720 SkASSERT(fActiveOpsTask == fDAG.back());
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400721 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400722 }
723}
724#endif
725
Greg Danielbbfec9d2019-08-20 10:56:51 -0400726void GrDrawingManager::closeRenderTasksForNewRenderTask(GrSurfaceProxy* target) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400727 if (target && fDAG.sortingRenderTasks() && fReduceOpsTaskSplitting) {
Chris Dalton5fe99772019-08-06 11:57:39 -0600728 // In this case we need to close all the renderTasks that rely on the current contents of
729 // 'target'. That is bc we're going to update the content of the proxy so they need to be
730 // split in case they use both the old and new content. (This is a bit of an overkill: they
731 // really only need to be split if they ever reference proxy's contents again but that is
732 // hard to predict/handle).
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400733 if (GrRenderTask* lastRenderTask = this->getLastRenderTask(target)) {
Chris Dalton6b498102019-08-01 14:14:52 -0600734 lastRenderTask->closeThoseWhoDependOnMe(*fContext->priv().caps());
Robert Phillips46acf9d2018-10-09 09:31:40 -0400735 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400736 } else if (fActiveOpsTask) {
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400737 // This is a temporary fix for the partial-MDB world. In that world we're not
Greg Danielf41b2bd2019-08-22 16:19:24 -0400738 // reordering so ops that (in the single opsTask world) would've just glommed onto the
739 // end of the single opsTask but referred to a far earlier RT need to appear in their
740 // own opsTask.
741 fActiveOpsTask->makeClosed(*fContext->priv().caps());
742 fActiveOpsTask = nullptr;
robertphillips3dc6ae52015-10-20 09:54:32 -0700743 }
Chris Dalton5fe99772019-08-06 11:57:39 -0600744}
745
Greg Daniel16f5c652019-10-29 11:26:01 -0400746sk_sp<GrOpsTask> GrDrawingManager::newOpsTask(GrSurfaceProxyView surfaceView,
747 bool managedOpsTask) {
Chris Dalton5fe99772019-08-06 11:57:39 -0600748 SkDEBUGCODE(this->validate());
749 SkASSERT(fContext);
750
Greg Daniel16f5c652019-10-29 11:26:01 -0400751 GrSurfaceProxy* proxy = surfaceView.proxy();
752 this->closeRenderTasksForNewRenderTask(proxy);
robertphillips3dc6ae52015-10-20 09:54:32 -0700753
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400754 sk_sp<GrOpsTask> opsTask(new GrOpsTask(this, fContext->priv().arenas(),
Michael Ludwigd0840ec2019-12-12 09:48:38 -0500755 std::move(surfaceView),
756 fContext->priv().auditTrail()));
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400757 SkASSERT(this->getLastRenderTask(proxy) == opsTask.get());
robertphillips3dc6ae52015-10-20 09:54:32 -0700758
Greg Danielf41b2bd2019-08-22 16:19:24 -0400759 if (managedOpsTask) {
760 fDAG.add(opsTask);
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400761
Greg Danielf41b2bd2019-08-22 16:19:24 -0400762 if (!fDAG.sortingRenderTasks() || !fReduceOpsTaskSplitting) {
763 fActiveOpsTask = opsTask.get();
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400764 }
Robert Phillips941d1442017-06-14 16:37:02 -0400765 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700766
Robert Phillips38d64b02018-09-04 13:23:26 -0400767 SkDEBUGCODE(this->validate());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400768 return opsTask;
robertphillips3dc6ae52015-10-20 09:54:32 -0700769}
770
Chris Daltone2a903e2019-09-18 13:41:50 -0600771GrTextureResolveRenderTask* GrDrawingManager::newTextureResolveRenderTask(const GrCaps& caps) {
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600772 // Unlike in the "new opsTask" case, we do not want to close the active opsTask, nor (if we are
Chris Daltone2a903e2019-09-18 13:41:50 -0600773 // in sorting and opsTask reduction mode) the render tasks that depend on any proxy's current
Greg Danielf41b2bd2019-08-22 16:19:24 -0400774 // state. This is because those opsTasks can still receive new ops and because if they refer to
Chris Dalton4ece96d2019-08-30 11:26:39 -0600775 // the mipmapped version of 'proxy', they will then come to depend on the render task being
776 // created here.
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600777 //
Greg Danielf41b2bd2019-08-22 16:19:24 -0400778 // Add the new textureResolveTask before the fActiveOpsTask (if not in
779 // sorting/opsTask-splitting-reduction mode) because it will depend upon this resolve task.
Chris Dalton3d770272019-08-14 09:24:37 -0600780 // NOTE: Putting it here will also reduce the amount of work required by the topological sort.
Chris Daltone2a903e2019-09-18 13:41:50 -0600781 return static_cast<GrTextureResolveRenderTask*>(fDAG.addBeforeLast(
782 sk_make_sp<GrTextureResolveRenderTask>()));
Chris Dalton3d770272019-08-14 09:24:37 -0600783}
784
Greg Danielc30f1a92019-09-06 15:28:58 -0400785void GrDrawingManager::newWaitRenderTask(sk_sp<GrSurfaceProxy> proxy,
Greg Daniel301015c2019-11-18 14:06:46 -0500786 std::unique_ptr<std::unique_ptr<GrSemaphore>[]> semaphores,
Greg Danielc30f1a92019-09-06 15:28:58 -0400787 int numSemaphores) {
788 SkDEBUGCODE(this->validate());
789 SkASSERT(fContext);
790
791 const GrCaps& caps = *fContext->priv().caps();
792
Greg Daniel16f5c652019-10-29 11:26:01 -0400793 sk_sp<GrWaitRenderTask> waitTask = sk_make_sp<GrWaitRenderTask>(GrSurfaceProxyView(proxy),
794 std::move(semaphores),
Greg Danielc30f1a92019-09-06 15:28:58 -0400795 numSemaphores);
796 if (fReduceOpsTaskSplitting) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400797 GrRenderTask* lastTask = this->getLastRenderTask(proxy.get());
Greg Danielc30f1a92019-09-06 15:28:58 -0400798 if (lastTask && !lastTask->isClosed()) {
799 // We directly make the currently open renderTask depend on waitTask instead of using
800 // the proxy version of addDependency. The waitTask will never need to trigger any
801 // resolves or mip map generation which is the main advantage of going through the proxy
802 // version. Additionally we would've had to temporarily set the wait task as the
803 // lastRenderTask on the proxy, add the dependency, and then reset the lastRenderTask to
804 // lastTask. Additionally we add all dependencies of lastTask to waitTask so that the
805 // waitTask doesn't get reordered before them and unnecessarily block those tasks.
806 // Note: Any previous Ops already in lastTask will get blocked by the wait semaphore
807 // even though they don't need to be for correctness.
808
809 // Make sure we add the dependencies of lastTask to waitTask first or else we'll get a
810 // circular self dependency of waitTask on waitTask.
811 waitTask->addDependenciesFromOtherTask(lastTask);
812 lastTask->addDependency(waitTask.get());
813 } else {
814 // If there is a last task we set the waitTask to depend on it so that it doesn't get
815 // reordered in front of the lastTask causing the lastTask to be blocked by the
816 // semaphore. Again we directly just go through adding the dependency to the task and
817 // not the proxy since we don't need to worry about resolving anything.
818 if (lastTask) {
819 waitTask->addDependency(lastTask);
820 }
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400821 this->setLastRenderTask(proxy.get(), waitTask.get());
Greg Danielc30f1a92019-09-06 15:28:58 -0400822 }
823 fDAG.add(waitTask);
824 } else {
Greg Daniel16f5c652019-10-29 11:26:01 -0400825 if (fActiveOpsTask && (fActiveOpsTask->fTargetView.proxy() == proxy.get())) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400826 SkASSERT(this->getLastRenderTask(proxy.get()) == fActiveOpsTask);
Greg Danielc30f1a92019-09-06 15:28:58 -0400827 fDAG.addBeforeLast(waitTask);
828 // In this case we keep the current renderTask open but just insert the new waitTask
829 // before it in the list. The waitTask will never need to trigger any resolves or mip
830 // map generation which is the main advantage of going through the proxy version.
831 // Additionally we would've had to temporarily set the wait task as the lastRenderTask
832 // on the proxy, add the dependency, and then reset the lastRenderTask to
833 // fActiveOpsTask. Additionally we make the waitTask depend on all of fActiveOpsTask
834 // dependencies so that we don't unnecessarily reorder the waitTask before them.
835 // Note: Any previous Ops already in fActiveOpsTask will get blocked by the wait
836 // semaphore even though they don't need to be for correctness.
837
838 // Make sure we add the dependencies of fActiveOpsTask to waitTask first or else we'll
839 // get a circular self dependency of waitTask on waitTask.
840 waitTask->addDependenciesFromOtherTask(fActiveOpsTask);
841 fActiveOpsTask->addDependency(waitTask.get());
842 } else {
843 // In this case we just close the previous RenderTask and start and append the waitTask
844 // to the DAG. Since it is the last task now we call setLastRenderTask on the proxy. If
845 // there is a lastTask on the proxy we make waitTask depend on that task. This
846 // dependency isn't strictly needed but it does keep the DAG from reordering the
847 // waitTask earlier and blocking more tasks.
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400848 if (GrRenderTask* lastTask = this->getLastRenderTask(proxy.get())) {
Greg Danielc30f1a92019-09-06 15:28:58 -0400849 waitTask->addDependency(lastTask);
850 }
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400851 this->setLastRenderTask(proxy.get(), waitTask.get());
Greg Danielc30f1a92019-09-06 15:28:58 -0400852 this->closeRenderTasksForNewRenderTask(proxy.get());
853 fDAG.add(waitTask);
854 }
855 }
856 waitTask->makeClosed(caps);
857
858 SkDEBUGCODE(this->validate());
859}
860
Greg Danielbbfec9d2019-08-20 10:56:51 -0400861void GrDrawingManager::newTransferFromRenderTask(sk_sp<GrSurfaceProxy> srcProxy,
862 const SkIRect& srcRect,
863 GrColorType surfaceColorType,
864 GrColorType dstColorType,
865 sk_sp<GrGpuBuffer> dstBuffer,
866 size_t dstOffset) {
867 SkDEBUGCODE(this->validate());
868 SkASSERT(fContext);
869 // This copies from srcProxy to dstBuffer so it doesn't have a real target.
870 this->closeRenderTasksForNewRenderTask(nullptr);
871
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600872 GrRenderTask* task = fDAG.add(sk_make_sp<GrTransferFromRenderTask>(
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400873 srcProxy, srcRect, surfaceColorType, dstColorType,
874 std::move(dstBuffer), dstOffset));
Greg Danielbbfec9d2019-08-20 10:56:51 -0400875
876 const GrCaps& caps = *fContext->priv().caps();
877
878 // We always say GrMipMapped::kNo here since we are always just copying from the base layer. We
879 // don't need to make sure the whole mip map chain is valid.
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400880 task->addDependency(this, srcProxy.get(), GrMipMapped::kNo,
881 GrTextureResolveManager(this), caps);
Greg Danielbbfec9d2019-08-20 10:56:51 -0400882 task->makeClosed(caps);
883
Greg Danielbbfec9d2019-08-20 10:56:51 -0400884 // We have closed the previous active oplist but since a new oplist isn't being added there
885 // shouldn't be an active one.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400886 SkASSERT(!fActiveOpsTask);
Greg Danielbbfec9d2019-08-20 10:56:51 -0400887 SkDEBUGCODE(this->validate());
888}
889
Greg Daniel16f5c652019-10-29 11:26:01 -0400890bool GrDrawingManager::newCopyRenderTask(GrSurfaceProxyView srcView,
Greg Daniele227fe42019-08-21 13:52:24 -0400891 const SkIRect& srcRect,
Greg Daniel16f5c652019-10-29 11:26:01 -0400892 GrSurfaceProxyView dstView,
Greg Daniele227fe42019-08-21 13:52:24 -0400893 const SkIPoint& dstPoint) {
894 SkDEBUGCODE(this->validate());
895 SkASSERT(fContext);
Greg Daniele227fe42019-08-21 13:52:24 -0400896
Greg Daniel16f5c652019-10-29 11:26:01 -0400897 this->closeRenderTasksForNewRenderTask(dstView.proxy());
Brian Salomone4bce012019-09-20 15:34:23 -0400898 const GrCaps& caps = *fContext->priv().caps();
899
Greg Daniel16f5c652019-10-29 11:26:01 -0400900 GrSurfaceProxy* srcProxy = srcView.proxy();
901
Brian Salomone4bce012019-09-20 15:34:23 -0400902 GrRenderTask* task =
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400903 fDAG.add(GrCopyRenderTask::Make(this, std::move(srcView), srcRect, std::move(dstView),
Greg Daniel16f5c652019-10-29 11:26:01 -0400904 dstPoint, &caps));
Greg Daniele227fe42019-08-21 13:52:24 -0400905 if (!task) {
906 return false;
907 }
908
Greg Daniele227fe42019-08-21 13:52:24 -0400909 // We always say GrMipMapped::kNo here since we are always just copying from the base layer to
910 // another base layer. We don't need to make sure the whole mip map chain is valid.
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400911 task->addDependency(this, srcProxy, GrMipMapped::kNo, GrTextureResolveManager(this), caps);
Greg Daniele227fe42019-08-21 13:52:24 -0400912 task->makeClosed(caps);
913
Greg Daniele227fe42019-08-21 13:52:24 -0400914 // We have closed the previous active oplist but since a new oplist isn't being added there
915 // shouldn't be an active one.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400916 SkASSERT(!fActiveOpsTask);
Greg Daniele227fe42019-08-21 13:52:24 -0400917 SkDEBUGCODE(this->validate());
918 return true;
919}
920
Herb Derby26cbe512018-05-24 14:39:01 -0400921GrTextContext* GrDrawingManager::getTextContext() {
922 if (!fTextContext) {
923 fTextContext = GrTextContext::Make(fOptionsForTextContext);
brianosman86e76262016-08-11 12:17:31 -0700924 }
925
Herb Derby26cbe512018-05-24 14:39:01 -0400926 return fTextContext.get();
brianosman86e76262016-08-11 12:17:31 -0700927}
928
robertphillips68737822015-10-29 12:12:21 -0700929/*
930 * This method finds a path renderer that can draw the specified path on
931 * the provided target.
932 * Due to its expense, the software path renderer has split out so it can
933 * can be individually allowed/disallowed via the "allowSW" boolean.
934 */
935GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
936 bool allowSW,
937 GrPathRendererChain::DrawType drawType,
938 GrPathRenderer::StencilSupport* stencilSupport) {
939
940 if (!fPathRendererChain) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400941 fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
robertphillips68737822015-10-29 12:12:21 -0700942 }
943
944 GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
945 if (!pr && allowSW) {
Brian Salomone7df0bb2018-05-07 14:44:57 -0400946 auto swPR = this->getSoftwarePathRenderer();
947 if (GrPathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) {
948 pr = swPR;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500949 }
robertphillips68737822015-10-29 12:12:21 -0700950 }
951
Robert Phillipsd81379d2020-04-21 10:39:02 -0400952#if GR_PATH_RENDERER_SPEW
953 if (pr) {
954 SkDebugf("getPathRenderer: %s\n", pr->name());
955 }
956#endif
957
robertphillips68737822015-10-29 12:12:21 -0700958 return pr;
959}
960
Brian Salomone7df0bb2018-05-07 14:44:57 -0400961GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() {
962 if (!fSoftwarePathRenderer) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400963 fSoftwarePathRenderer.reset(
Robert Phillips9da87e02019-02-04 13:26:26 -0500964 new GrSoftwarePathRenderer(fContext->priv().proxyProvider(),
Ben Wagner9ec70c62018-07-12 13:30:47 -0400965 fOptionsForPathRendererChain.fAllowPathMaskCaching));
Brian Salomone7df0bb2018-05-07 14:44:57 -0400966 }
Ben Wagner9ec70c62018-07-12 13:30:47 -0400967 return fSoftwarePathRenderer.get();
Brian Salomone7df0bb2018-05-07 14:44:57 -0400968}
969
Chris Daltonfddb6c02017-11-04 15:22:22 -0600970GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() {
971 if (!fPathRendererChain) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400972 fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
Chris Daltonfddb6c02017-11-04 15:22:22 -0600973 }
974 return fPathRendererChain->getCoverageCountingPathRenderer();
975}
976
Brian Salomon653f42f2018-07-10 10:07:31 -0400977void GrDrawingManager::flushIfNecessary() {
Robert Phillips6a6de562019-02-15 15:19:15 -0500978 auto direct = fContext->priv().asDirectContext();
979 if (!direct) {
980 return;
981 }
982
983 auto resourceCache = direct->priv().getResourceCache();
Brian Salomon653f42f2018-07-10 10:07:31 -0400984 if (resourceCache && resourceCache->requestsFlush()) {
Greg Danielfe159622020-04-10 17:43:51 +0000985 if (this->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(),
986 GrPrepareForExternalIORequests())) {
987 this->submitToGpu(false);
988 }
Brian Salomon57d2beab2018-09-10 09:35:41 -0400989 resourceCache->purgeAsNeeded();
Brian Salomon653f42f2018-07-10 10:07:31 -0400990 }
991}
992