robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
bsalomon | 5eb41fd | 2016-09-06 13:49:32 -0700 | [diff] [blame] | 8 | #include "GrDrawingManager.h" |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 9 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 10 | #include "GrBackendSemaphore.h" |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 11 | #include "GrContext.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 12 | #include "GrContextPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 13 | #include "GrGpu.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 14 | #include "GrOnFlushResourceProvider.h" |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 15 | #include "GrOpList.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 16 | #include "GrRenderTargetContext.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 17 | #include "GrRenderTargetProxy.h" |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 18 | #include "GrResourceAllocator.h" |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 19 | #include "GrResourceProvider.h" |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 20 | #include "GrSoftwarePathRenderer.h" |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 21 | #include "GrSurfaceProxyPriv.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 22 | #include "GrTextureContext.h" |
| 23 | #include "GrTextureOpList.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 24 | #include "GrTextureProxy.h" |
| 25 | #include "GrTextureProxyPriv.h" |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 26 | |
| 27 | #include "SkDeferredDisplayList.h" |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 28 | #include "SkSurface_Gpu.h" |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 29 | #include "SkTTopoSort.h" |
| 30 | |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 31 | #include "GrTracing.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 32 | #include "text/GrAtlasTextContext.h" |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 33 | |
Robert Phillips | a3f7026 | 2018-02-08 10:59:38 -0500 | [diff] [blame] | 34 | // Turn on/off the sorting of opLists at flush time |
| 35 | #ifndef SK_DISABLE_RENDER_TARGET_SORTING |
| 36 | #define SK_DISABLE_RENDER_TARGET_SORTING |
| 37 | #endif |
| 38 | |
| 39 | #ifdef SK_DISABLE_RENDER_TARGET_SORTING |
| 40 | static const bool kDefaultSortRenderTargets = false; |
| 41 | #else |
| 42 | static const bool kDefaultSortRenderTargets = true; |
| 43 | #endif |
| 44 | |
| 45 | GrDrawingManager::GrDrawingManager(GrContext* context, |
| 46 | const GrPathRendererChain::Options& optionsForPathRendererChain, |
| 47 | const GrAtlasTextContext::Options& optionsForAtlasTextContext, |
| 48 | GrSingleOwner* singleOwner, |
| 49 | GrContextOptions::Enable sortRenderTargets) |
| 50 | : fContext(context) |
| 51 | , fOptionsForPathRendererChain(optionsForPathRendererChain) |
| 52 | , fOptionsForAtlasTextContext(optionsForAtlasTextContext) |
| 53 | , fSingleOwner(singleOwner) |
| 54 | , fAbandoned(false) |
| 55 | , fAtlasTextContext(nullptr) |
| 56 | , fPathRendererChain(nullptr) |
| 57 | , fSoftwarePathRenderer(nullptr) |
| 58 | , fFlushing(false) { |
| 59 | |
| 60 | if (GrContextOptions::Enable::kNo == sortRenderTargets) { |
| 61 | fSortRenderTargets = false; |
| 62 | } else if (GrContextOptions::Enable::kYes == sortRenderTargets) { |
| 63 | fSortRenderTargets = true; |
| 64 | } else { |
| 65 | fSortRenderTargets = kDefaultSortRenderTargets; |
| 66 | } |
| 67 | } |
| 68 | |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 69 | void GrDrawingManager::cleanup() { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 70 | for (int i = 0; i < fOpLists.count(); ++i) { |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 71 | // no opList should receive a new command after this |
| 72 | fOpLists[i]->makeClosed(*fContext->caps()); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 73 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 74 | // We shouldn't need to do this, but it turns out some clients still hold onto opLists |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 75 | // after a cleanup. |
| 76 | // MDB TODO: is this still true? |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 77 | if (!fOpLists[i]->unique()) { |
| 78 | // TODO: Eventually this should be guaranteed unique. |
| 79 | // https://bugs.chromium.org/p/skia/issues/detail?id=7111 |
| 80 | fOpLists[i]->endFlush(); |
| 81 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 84 | fOpLists.reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 85 | |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 86 | delete fPathRendererChain; |
| 87 | fPathRendererChain = nullptr; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 88 | SkSafeSetNull(fSoftwarePathRenderer); |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 89 | |
| 90 | fOnFlushCBObjects.reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | GrDrawingManager::~GrDrawingManager() { |
| 94 | this->cleanup(); |
| 95 | } |
| 96 | |
| 97 | void GrDrawingManager::abandon() { |
| 98 | fAbandoned = true; |
| 99 | this->cleanup(); |
| 100 | } |
| 101 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 102 | void GrDrawingManager::freeGpuResources() { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 103 | for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) { |
| 104 | if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) { |
| 105 | // it's safe to just do this because we're iterating in reverse |
| 106 | fOnFlushCBObjects.removeShuffle(i); |
| 107 | } |
| 108 | } |
| 109 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 110 | // a path renderer may be holding onto resources |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 111 | delete fPathRendererChain; |
| 112 | fPathRendererChain = nullptr; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 113 | SkSafeSetNull(fSoftwarePathRenderer); |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 114 | } |
| 115 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 116 | // MDB TODO: make use of the 'proxy' parameter. |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 117 | GrSemaphoresSubmitted GrDrawingManager::internalFlush(GrSurfaceProxy*, |
| 118 | GrResourceCache::FlushType type, |
| 119 | int numSemaphores, |
| 120 | GrBackendSemaphore backendSemaphores[]) { |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 121 | GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "internalFlush", fContext); |
| 122 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 123 | if (fFlushing || this->wasAbandoned()) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 124 | return GrSemaphoresSubmitted::kNo; |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 125 | } |
| 126 | fFlushing = true; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 127 | |
| 128 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 129 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 130 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 131 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 132 | // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again. |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 133 | fOpLists[i]->makeClosed(*fContext->caps()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Robert Phillips | a4c93ac | 2017-05-18 11:40:04 -0400 | [diff] [blame] | 136 | #ifdef SK_DEBUG |
| 137 | // This block checks for any unnecessary splits in the opLists. If two sequential opLists |
| 138 | // share the same backing GrSurfaceProxy it means the opList was artificially split. |
| 139 | if (fOpLists.count()) { |
| 140 | GrRenderTargetOpList* prevOpList = fOpLists[0]->asRenderTargetOpList(); |
| 141 | for (int i = 1; i < fOpLists.count(); ++i) { |
| 142 | GrRenderTargetOpList* curOpList = fOpLists[i]->asRenderTargetOpList(); |
| 143 | |
| 144 | if (prevOpList && curOpList) { |
| 145 | SkASSERT(prevOpList->fTarget.get() != curOpList->fTarget.get()); |
| 146 | } |
| 147 | |
| 148 | prevOpList = curOpList; |
| 149 | } |
| 150 | } |
| 151 | #endif |
| 152 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 153 | if (fSortRenderTargets) { |
| 154 | SkDEBUGCODE(bool result =) SkTTopoSort<GrOpList, GrOpList::TopoSortTraits>(&fOpLists); |
| 155 | SkASSERT(result); |
| 156 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 157 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 158 | GrGpu* gpu = fContext->contextPriv().getGpu(); |
| 159 | |
| 160 | GrOpFlushState flushState(gpu, fContext->contextPriv().resourceProvider(), |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 161 | &fTokenTracker); |
| 162 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 163 | GrOnFlushResourceProvider onFlushProvider(this); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 164 | // TODO: AFAICT the only reason fFlushState is on GrDrawingManager rather than on the |
| 165 | // stack here is to preserve the flush tokens. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 166 | |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 167 | // Prepare any onFlush op lists (e.g. atlases). |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 168 | if (!fOnFlushCBObjects.empty()) { |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 169 | fFlushingOpListIDs.reset(fOpLists.count()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 170 | for (int i = 0; i < fOpLists.count(); ++i) { |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 171 | fFlushingOpListIDs[i] = fOpLists[i]->uniqueID(); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 172 | } |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 173 | SkSTArray<4, sk_sp<GrRenderTargetContext>> renderTargetContexts; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 174 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
| 175 | onFlushCBObject->preFlush(&onFlushProvider, |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 176 | fFlushingOpListIDs.begin(), fFlushingOpListIDs.count(), |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 177 | &renderTargetContexts); |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 178 | for (const sk_sp<GrRenderTargetContext>& rtc : renderTargetContexts) { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 179 | sk_sp<GrRenderTargetOpList> onFlushOpList = sk_ref_sp(rtc->getRTOpList()); |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 180 | if (!onFlushOpList) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 181 | continue; // Odd - but not a big deal |
| 182 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 183 | #ifdef SK_DEBUG |
| 184 | // OnFlush callbacks are already invoked during flush, and are therefore expected to |
| 185 | // handle resource allocation & usage on their own. (No deferred or lazy proxies!) |
| 186 | onFlushOpList->visitProxies_debugOnly([](GrSurfaceProxy* p) { |
| 187 | SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred()); |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 188 | SkASSERT(GrSurfaceProxy::LazyState::kNot == p->lazyInstantiationState()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 189 | }); |
| 190 | #endif |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 191 | onFlushOpList->makeClosed(*fContext->caps()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 192 | onFlushOpList->prepare(&flushState); |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 193 | fOnFlushCBOpLists.push_back(std::move(onFlushOpList)); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 194 | } |
| 195 | renderTargetContexts.reset(); |
| 196 | } |
| 197 | } |
| 198 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 199 | #if 0 |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 200 | // Enable this to print out verbose GrOp information |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 201 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 202 | SkDEBUGCODE(fOpLists[i]->dump();) |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 203 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 204 | #endif |
| 205 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 206 | int startIndex, stopIndex; |
| 207 | bool flushed = false; |
| 208 | |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 209 | { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 210 | GrResourceAllocator alloc(fContext->contextPriv().resourceProvider()); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 211 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 212 | fOpLists[i]->gatherProxyIntervals(&alloc); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 213 | alloc.markEndOfOpList(i); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 214 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 215 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 216 | GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError; |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame^] | 217 | while (alloc.assign(&startIndex, &stopIndex, flushState.uninstantiateProxyTracker(), |
| 218 | &error)) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 219 | if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) { |
| 220 | for (int i = startIndex; i < stopIndex; ++i) { |
| 221 | fOpLists[i]->purgeOpsWithUninstantiatedProxies(); |
| 222 | } |
| 223 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 224 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 225 | if (this->executeOpLists(startIndex, stopIndex, &flushState)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 226 | flushed = true; |
| 227 | } |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 228 | } |
Greg Daniel | c42b20b | 2017-10-04 10:34:49 -0400 | [diff] [blame] | 229 | } |
| 230 | |
Robert Phillips | 18e9484 | 2017-05-15 13:06:44 -0400 | [diff] [blame] | 231 | fOpLists.reset(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 232 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 233 | GrSemaphoresSubmitted result = gpu->finishFlush(numSemaphores, backendSemaphores); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 234 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame^] | 235 | flushState.uninstantiateProxyTracker()->uninstantiateAllProxies(); |
| 236 | |
robertphillips | ee843b2 | 2016-10-04 05:30:20 -0700 | [diff] [blame] | 237 | // We always have to notify the cache when it requested a flush so it can reset its state. |
| 238 | if (flushed || type == GrResourceCache::FlushType::kCacheRequested) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 239 | fContext->contextPriv().getResourceCache()->notifyFlushOccurred(type); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 240 | } |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 241 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 242 | onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingOpListIDs.begin(), |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 243 | fFlushingOpListIDs.count()); |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 244 | } |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 245 | fFlushingOpListIDs.reset(); |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 246 | fFlushing = false; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 247 | |
| 248 | return result; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 251 | bool GrDrawingManager::executeOpLists(int startIndex, int stopIndex, GrOpFlushState* flushState) { |
| 252 | SkASSERT(startIndex <= stopIndex && stopIndex <= fOpLists.count()); |
| 253 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 254 | GrResourceProvider* resourceProvider = fContext->contextPriv().resourceProvider(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 255 | bool anyOpListsExecuted = false; |
| 256 | |
| 257 | for (int i = startIndex; i < stopIndex; ++i) { |
| 258 | if (!fOpLists[i]) { |
| 259 | continue; |
| 260 | } |
| 261 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 262 | if (resourceProvider->explicitlyAllocateGPUResources()) { |
| 263 | if (!fOpLists[i]->isInstantiated()) { |
| 264 | // If the backing surface wasn't allocated drop the draw of the entire opList. |
| 265 | fOpLists[i] = nullptr; |
| 266 | continue; |
| 267 | } |
| 268 | } else { |
| 269 | if (!fOpLists[i]->instantiate(resourceProvider)) { |
| 270 | SkDebugf("OpList failed to instantiate.\n"); |
| 271 | fOpLists[i] = nullptr; |
| 272 | continue; |
| 273 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 274 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 275 | |
| 276 | // TODO: handle this instantiation via lazy surface proxies? |
| 277 | // Instantiate all deferred proxies (being built on worker threads) so we can upload them |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 278 | fOpLists[i]->instantiateDeferredProxies(fContext->contextPriv().resourceProvider()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 279 | fOpLists[i]->prepare(flushState); |
| 280 | } |
| 281 | |
| 282 | // Upload all data to the GPU |
| 283 | flushState->preExecuteDraws(); |
| 284 | |
| 285 | // Execute the onFlush op lists first, if any. |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 286 | for (sk_sp<GrOpList>& onFlushOpList : fOnFlushCBOpLists) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 287 | if (!onFlushOpList->execute(flushState)) { |
| 288 | SkDebugf("WARNING: onFlushOpList failed to execute.\n"); |
| 289 | } |
| 290 | SkASSERT(onFlushOpList->unique()); |
| 291 | onFlushOpList = nullptr; |
| 292 | } |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 293 | fOnFlushCBOpLists.reset(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 294 | |
| 295 | // Execute the normal op lists. |
| 296 | for (int i = startIndex; i < stopIndex; ++i) { |
| 297 | if (!fOpLists[i]) { |
| 298 | continue; |
| 299 | } |
| 300 | |
| 301 | if (fOpLists[i]->execute(flushState)) { |
| 302 | anyOpListsExecuted = true; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | SkASSERT(!flushState->commandBuffer()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 307 | SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 308 | |
| 309 | // We reset the flush state before the OpLists so that the last resources to be freed are those |
| 310 | // that are written to in the OpLists. This helps to make sure the most recently used resources |
| 311 | // are the last to be purged by the resource cache. |
| 312 | flushState->reset(); |
| 313 | |
| 314 | for (int i = startIndex; i < stopIndex; ++i) { |
| 315 | if (!fOpLists[i]) { |
| 316 | continue; |
| 317 | } |
| 318 | if (!fOpLists[i]->unique()) { |
| 319 | // TODO: Eventually this should be guaranteed unique. |
| 320 | // https://bugs.chromium.org/p/skia/issues/detail?id=7111 |
| 321 | fOpLists[i]->endFlush(); |
| 322 | } |
| 323 | fOpLists[i] = nullptr; |
| 324 | } |
| 325 | |
| 326 | return anyOpListsExecuted; |
| 327 | } |
| 328 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 329 | GrSemaphoresSubmitted GrDrawingManager::prepareSurfaceForExternalIO( |
| 330 | GrSurfaceProxy* proxy, int numSemaphores, GrBackendSemaphore backendSemaphores[]) { |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 331 | if (this->wasAbandoned()) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 332 | return GrSemaphoresSubmitted::kNo; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 333 | } |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 334 | SkASSERT(proxy); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 335 | |
Kevin Lubick | 4284613 | 2018-01-05 10:11:11 -0500 | [diff] [blame] | 336 | GrSemaphoresSubmitted result = GrSemaphoresSubmitted::kNo; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 337 | if (proxy->priv().hasPendingIO() || numSemaphores) { |
| 338 | result = this->flush(proxy, numSemaphores, backendSemaphores); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 341 | if (!proxy->instantiate(fContext->contextPriv().resourceProvider())) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 342 | return result; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 343 | } |
| 344 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 345 | GrGpu* gpu = fContext->contextPriv().getGpu(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 346 | GrSurface* surface = proxy->priv().peekSurface(); |
| 347 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 348 | if (gpu && surface->asRenderTarget()) { |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 349 | gpu->resolveRenderTarget(surface->asRenderTarget()); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 350 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 351 | return result; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 354 | void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 355 | fOnFlushCBObjects.push_back(onFlushCBObject); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 356 | } |
| 357 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 358 | void GrDrawingManager::moveOpListsToDDL(SkDeferredDisplayList* ddl) { |
| 359 | #ifndef SK_RASTER_RECORDER_IMPLEMENTATION |
Robert Phillips | 7a13705 | 2018-02-01 11:23:12 -0500 | [diff] [blame] | 360 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 361 | // no opList should receive a new command after this |
| 362 | fOpLists[i]->makeClosed(*fContext->caps()); |
| 363 | } |
| 364 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 365 | ddl->fOpLists = std::move(fOpLists); |
| 366 | #endif |
| 367 | } |
| 368 | |
| 369 | void GrDrawingManager::copyOpListsFromDDL(const SkDeferredDisplayList* ddl, |
| 370 | GrRenderTargetProxy* newDest) { |
| 371 | #ifndef SK_RASTER_RECORDER_IMPLEMENTATION |
| 372 | // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData. |
| 373 | // The lazy proxy that references it (in the copied opLists) will steal its GrTexture. |
| 374 | ddl->fLazyProxyData->fReplayDest = newDest; |
| 375 | fOpLists.push_back_n(ddl->fOpLists.count(), ddl->fOpLists.begin()); |
| 376 | #endif |
| 377 | } |
| 378 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 379 | sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(GrRenderTargetProxy* rtp, |
| 380 | bool managedOpList) { |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 381 | SkASSERT(fContext); |
| 382 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 383 | // This is a temporary fix for the partial-MDB world. In that world we're not reordering |
| 384 | // so ops that (in the single opList world) would've just glommed onto the end of the single |
| 385 | // opList but referred to a far earlier RT need to appear in their own opList. |
| 386 | if (!fOpLists.empty()) { |
| 387 | fOpLists.back()->makeClosed(*fContext->caps()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 388 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 389 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 390 | auto resourceProvider = fContext->contextPriv().resourceProvider(); |
| 391 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 392 | sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList( |
| 393 | rtp, |
| 394 | resourceProvider, |
| 395 | fContext->contextPriv().getAuditTrail())); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 396 | SkASSERT(rtp->getLastOpList() == opList.get()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 397 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 398 | if (managedOpList) { |
| 399 | fOpLists.push_back() = opList; |
| 400 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 401 | |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 402 | return opList; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 405 | sk_sp<GrTextureOpList> GrDrawingManager::newTextureOpList(GrTextureProxy* textureProxy) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 406 | SkASSERT(fContext); |
| 407 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 408 | // This is a temporary fix for the partial-MDB world. In that world we're not reordering |
| 409 | // so ops that (in the single opList world) would've just glommed onto the end of the single |
| 410 | // opList but referred to a far earlier RT need to appear in their own opList. |
| 411 | if (!fOpLists.empty()) { |
| 412 | fOpLists.back()->makeClosed(*fContext->caps()); |
| 413 | } |
| 414 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 415 | sk_sp<GrTextureOpList> opList(new GrTextureOpList(fContext->contextPriv().resourceProvider(), |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 416 | textureProxy, |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 417 | fContext->contextPriv().getAuditTrail())); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 418 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 419 | SkASSERT(textureProxy->getLastOpList() == opList.get()); |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 420 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 421 | fOpLists.push_back() = opList; |
| 422 | |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 423 | return opList; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 424 | } |
| 425 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 426 | GrAtlasTextContext* GrDrawingManager::getAtlasTextContext() { |
| 427 | if (!fAtlasTextContext) { |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 428 | fAtlasTextContext = GrAtlasTextContext::Make(fOptionsForAtlasTextContext); |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | return fAtlasTextContext.get(); |
| 432 | } |
| 433 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 434 | /* |
| 435 | * This method finds a path renderer that can draw the specified path on |
| 436 | * the provided target. |
| 437 | * Due to its expense, the software path renderer has split out so it can |
| 438 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 439 | */ |
| 440 | GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 441 | bool allowSW, |
| 442 | GrPathRendererChain::DrawType drawType, |
| 443 | GrPathRenderer::StencilSupport* stencilSupport) { |
| 444 | |
| 445 | if (!fPathRendererChain) { |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 446 | fPathRendererChain = new GrPathRendererChain(fContext, fOptionsForPathRendererChain); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport); |
| 450 | if (!pr && allowSW) { |
| 451 | if (!fSoftwarePathRenderer) { |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 452 | fSoftwarePathRenderer = |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 453 | new GrSoftwarePathRenderer(fContext->contextPriv().proxyProvider(), |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 454 | fOptionsForPathRendererChain.fAllowPathMaskCaching); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 455 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 456 | if (GrPathRenderer::CanDrawPath::kNo != fSoftwarePathRenderer->canDrawPath(args)) { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 457 | pr = fSoftwarePathRenderer; |
| 458 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | return pr; |
| 462 | } |
| 463 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 464 | GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() { |
| 465 | if (!fPathRendererChain) { |
| 466 | fPathRendererChain = new GrPathRendererChain(fContext, fOptionsForPathRendererChain); |
| 467 | } |
| 468 | return fPathRendererChain->getCoverageCountingPathRenderer(); |
| 469 | } |
| 470 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 471 | sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext( |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 472 | sk_sp<GrSurfaceProxy> sProxy, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 473 | sk_sp<SkColorSpace> colorSpace, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 474 | const SkSurfaceProps* surfaceProps, |
| 475 | bool managedOpList) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 476 | if (this->wasAbandoned() || !sProxy->asRenderTargetProxy()) { |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 477 | return nullptr; |
| 478 | } |
| 479 | |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 480 | // SkSurface catches bad color space usage at creation. This check handles anything that slips |
Brian Salomon | 366093f | 2018-02-13 09:25:22 -0500 | [diff] [blame] | 481 | // by, including internal usage. |
| 482 | if (!SkSurface_Gpu::Valid(fContext, sProxy->config(), colorSpace.get())) { |
brianosman | a9c3c6a | 2016-09-29 10:08:36 -0700 | [diff] [blame] | 483 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 484 | return nullptr; |
| 485 | } |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 486 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 487 | sk_sp<GrRenderTargetProxy> rtp(sk_ref_sp(sProxy->asRenderTargetProxy())); |
| 488 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 489 | return sk_sp<GrRenderTargetContext>(new GrRenderTargetContext( |
| 490 | fContext, this, std::move(rtp), |
| 491 | std::move(colorSpace), |
| 492 | surfaceProps, |
| 493 | fContext->contextPriv().getAuditTrail(), |
| 494 | fSingleOwner, managedOpList)); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 495 | } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 496 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 497 | sk_sp<GrTextureContext> GrDrawingManager::makeTextureContext(sk_sp<GrSurfaceProxy> sProxy, |
| 498 | sk_sp<SkColorSpace> colorSpace) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 499 | if (this->wasAbandoned() || !sProxy->asTextureProxy()) { |
| 500 | return nullptr; |
| 501 | } |
| 502 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 503 | // SkSurface catches bad color space usage at creation. This check handles anything that slips |
Brian Salomon | 366093f | 2018-02-13 09:25:22 -0500 | [diff] [blame] | 504 | // by, including internal usage. |
| 505 | if (!SkSurface_Gpu::Valid(fContext, sProxy->config(), colorSpace.get())) { |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 506 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
| 507 | return nullptr; |
| 508 | } |
| 509 | |
Robert Phillips | 383c418 | 2018-02-07 12:47:44 -0500 | [diff] [blame] | 510 | // GrTextureRenderTargets should always be using a GrRenderTargetContext |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 511 | SkASSERT(!sProxy->asRenderTargetProxy()); |
| 512 | |
| 513 | sk_sp<GrTextureProxy> textureProxy(sk_ref_sp(sProxy->asTextureProxy())); |
| 514 | |
| 515 | return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy), |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 516 | std::move(colorSpace), |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 517 | fContext->contextPriv().getAuditTrail(), |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 518 | fSingleOwner)); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 519 | } |