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" |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 9 | #include "GrBackendSemaphore.h" |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 10 | #include "GrContext.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 12 | #include "GrGpu.h" |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 13 | #include "GrMemoryPool.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 Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 22 | #include "GrTexture.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 23 | #include "GrTextureContext.h" |
| 24 | #include "GrTextureOpList.h" |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 25 | #include "GrTexturePriv.h" |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 26 | #include "GrTextureProxy.h" |
| 27 | #include "GrTextureProxyPriv.h" |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 28 | #include "GrTracing.h" |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 29 | #include "SkDeferredDisplayList.h" |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 30 | #include "SkSurface_Gpu.h" |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 31 | #include "SkTTopoSort.h" |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 32 | #include "ccpr/GrCoverageCountingPathRenderer.h" |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 33 | #include "text/GrTextContext.h" |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 34 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 35 | GrDrawingManager::OpListDAG::OpListDAG(bool explicitlyAllocating, |
| 36 | GrContextOptions::Enable sortOpLists) { |
| 37 | if (GrContextOptions::Enable::kNo == sortOpLists) { |
| 38 | fSortOpLists = false; |
| 39 | } else if (GrContextOptions::Enable::kYes == sortOpLists) { |
| 40 | fSortOpLists = true; |
Robert Phillips | a3f7026 | 2018-02-08 10:59:38 -0500 | [diff] [blame] | 41 | } else { |
Robert Phillips | 64ecdce | 2018-04-02 10:26:39 -0400 | [diff] [blame] | 42 | // By default we always enable sorting when we're explicitly allocating GPU resources |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 43 | fSortOpLists = explicitlyAllocating; |
Robert Phillips | a3f7026 | 2018-02-08 10:59:38 -0500 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 47 | GrDrawingManager::OpListDAG::~OpListDAG() {} |
| 48 | |
| 49 | void GrDrawingManager::OpListDAG::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const { |
| 50 | idArray->reset(fOpLists.count()); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 51 | for (int i = 0; i < fOpLists.count(); ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 52 | if (fOpLists[i]) { |
| 53 | (*idArray)[i] = fOpLists[i]->uniqueID(); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void GrDrawingManager::OpListDAG::reset() { |
| 59 | fOpLists.reset(); |
| 60 | } |
| 61 | |
| 62 | void GrDrawingManager::OpListDAG::removeOpList(int index) { |
| 63 | if (!fOpLists[index]->unique()) { |
| 64 | // TODO: Eventually this should be guaranteed unique: http://skbug.com/7111 |
| 65 | fOpLists[index]->endFlush(); |
| 66 | } |
| 67 | |
| 68 | fOpLists[index] = nullptr; |
| 69 | } |
| 70 | |
| 71 | void GrDrawingManager::OpListDAG::removeOpLists(int startIndex, int stopIndex) { |
| 72 | for (int i = startIndex; i < stopIndex; ++i) { |
| 73 | if (!fOpLists[i]) { |
| 74 | continue; |
| 75 | } |
| 76 | this->removeOpList(i); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void GrDrawingManager::OpListDAG::add(sk_sp<GrOpList> opList) { |
| 81 | fOpLists.emplace_back(std::move(opList)); |
| 82 | } |
| 83 | |
| 84 | void GrDrawingManager::OpListDAG::add(const SkTArray<sk_sp<GrOpList>>& opLists) { |
| 85 | fOpLists.push_back_n(opLists.count(), opLists.begin()); |
| 86 | } |
| 87 | |
| 88 | void GrDrawingManager::OpListDAG::swap(SkTArray<sk_sp<GrOpList>>* opLists) { |
| 89 | SkASSERT(opLists->empty()); |
| 90 | opLists->swap(fOpLists); |
| 91 | } |
| 92 | |
| 93 | void GrDrawingManager::OpListDAG::prepForFlush() { |
| 94 | if (fSortOpLists) { |
| 95 | SkDEBUGCODE(bool result =) SkTTopoSort<GrOpList, GrOpList::TopoSortTraits>(&fOpLists); |
| 96 | SkASSERT(result); |
| 97 | } |
| 98 | |
| 99 | #ifdef SK_DEBUG |
| 100 | // This block checks for any unnecessary splits in the opLists. If two sequential opLists |
| 101 | // share the same backing GrSurfaceProxy it means the opList was artificially split. |
| 102 | if (fOpLists.count()) { |
| 103 | GrRenderTargetOpList* prevOpList = fOpLists[0]->asRenderTargetOpList(); |
| 104 | for (int i = 1; i < fOpLists.count(); ++i) { |
| 105 | GrRenderTargetOpList* curOpList = fOpLists[i]->asRenderTargetOpList(); |
| 106 | |
| 107 | if (prevOpList && curOpList) { |
| 108 | SkASSERT(prevOpList->fTarget.get() != curOpList->fTarget.get()); |
| 109 | } |
| 110 | |
| 111 | prevOpList = curOpList; |
| 112 | } |
| 113 | } |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | void GrDrawingManager::OpListDAG::closeAll(const GrCaps* caps) { |
| 118 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 119 | if (fOpLists[i]) { |
| 120 | fOpLists[i]->makeClosed(*caps); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | void GrDrawingManager::OpListDAG::cleanup(const GrCaps* caps) { |
| 126 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 127 | if (!fOpLists[i]) { |
| 128 | continue; |
| 129 | } |
| 130 | |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 131 | // no opList should receive a new command after this |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 132 | fOpLists[i]->makeClosed(*caps); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 133 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 134 | // 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] | 135 | // after a cleanup. |
| 136 | // MDB TODO: is this still true? |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 137 | if (!fOpLists[i]->unique()) { |
| 138 | // TODO: Eventually this should be guaranteed unique. |
| 139 | // https://bugs.chromium.org/p/skia/issues/detail?id=7111 |
| 140 | fOpLists[i]->endFlush(); |
| 141 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 144 | fOpLists.reset(); |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 148 | GrDrawingManager::GrDrawingManager(GrContext* context, |
| 149 | const GrPathRendererChain::Options& optionsForPathRendererChain, |
| 150 | const GrTextContext::Options& optionsForTextContext, |
| 151 | GrSingleOwner* singleOwner, |
| 152 | bool explicitlyAllocating, |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 153 | GrContextOptions::Enable sortOpLists, |
| 154 | GrContextOptions::Enable reduceOpListSplitting) |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 155 | : fContext(context) |
| 156 | , fOptionsForPathRendererChain(optionsForPathRendererChain) |
| 157 | , fOptionsForTextContext(optionsForTextContext) |
| 158 | , fSingleOwner(singleOwner) |
| 159 | , fAbandoned(false) |
| 160 | , fDAG(explicitlyAllocating, sortOpLists) |
| 161 | , fTextContext(nullptr) |
| 162 | , fPathRendererChain(nullptr) |
| 163 | , fSoftwarePathRenderer(nullptr) |
| 164 | , fFlushing(false) { |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 165 | if (GrContextOptions::Enable::kNo == reduceOpListSplitting) { |
| 166 | fReduceOpListSplitting = false; |
| 167 | } else if (GrContextOptions::Enable::kYes == reduceOpListSplitting) { |
| 168 | fReduceOpListSplitting = true; |
| 169 | } else { |
| 170 | // For now, this is only turned on when explicitly enabled. Once mini-flushes are |
| 171 | // implemented it should be enabled whenever sorting is enabled. |
| 172 | fReduceOpListSplitting = false; // sortOpLists |
| 173 | } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void GrDrawingManager::cleanup() { |
| 177 | fDAG.cleanup(fContext->contextPriv().caps()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 178 | |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 179 | fPathRendererChain = nullptr; |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 180 | fSoftwarePathRenderer = nullptr; |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 181 | |
| 182 | fOnFlushCBObjects.reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | GrDrawingManager::~GrDrawingManager() { |
| 186 | this->cleanup(); |
| 187 | } |
| 188 | |
| 189 | void GrDrawingManager::abandon() { |
| 190 | fAbandoned = true; |
| 191 | this->cleanup(); |
| 192 | } |
| 193 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 194 | void GrDrawingManager::freeGpuResources() { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 195 | for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) { |
| 196 | if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) { |
| 197 | // it's safe to just do this because we're iterating in reverse |
| 198 | fOnFlushCBObjects.removeShuffle(i); |
| 199 | } |
| 200 | } |
| 201 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 202 | // a path renderer may be holding onto resources |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 203 | fPathRendererChain = nullptr; |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 204 | fSoftwarePathRenderer = nullptr; |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 205 | } |
| 206 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 207 | // MDB TODO: make use of the 'proxy' parameter. |
Brian Salomon | 57d2bea | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 208 | GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy*, |
| 209 | int numSemaphores, |
| 210 | GrBackendSemaphore backendSemaphores[]) { |
| 211 | GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext); |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 212 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 213 | if (fFlushing || this->wasAbandoned()) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 214 | return GrSemaphoresSubmitted::kNo; |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 215 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 216 | SkDEBUGCODE(this->validate()); |
| 217 | |
Robert Phillips | 874b535 | 2018-03-16 08:48:24 -0400 | [diff] [blame] | 218 | GrGpu* gpu = fContext->contextPriv().getGpu(); |
| 219 | if (!gpu) { |
| 220 | return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording |
| 221 | } |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 222 | fFlushing = true; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 223 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 224 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 225 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 226 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 227 | // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again. |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 228 | fDAG.closeAll(fContext->contextPriv().caps()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 229 | fActiveOpList = nullptr; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 230 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 231 | fDAG.prepForFlush(); |
Brian Salomon | 58f153c | 2018-10-18 21:51:15 -0400 | [diff] [blame] | 232 | SkASSERT(SkToBool(fVertexBufferSpace) == SkToBool(fIndexBufferSpace)); |
| 233 | if (!fVertexBufferSpace) { |
Brian Salomon | 294861f | 2018-10-22 09:24:16 -0400 | [diff] [blame] | 234 | fVertexBufferSpace.reset(new char[GrBufferAllocPool::kDefaultBufferSize]()); |
| 235 | fIndexBufferSpace.reset(new char[GrBufferAllocPool::kDefaultBufferSize]()); |
Brian Salomon | 58f153c | 2018-10-18 21:51:15 -0400 | [diff] [blame] | 236 | } |
Robert Phillips | a4c93ac | 2017-05-18 11:40:04 -0400 | [diff] [blame] | 237 | |
Brian Salomon | 58f153c | 2018-10-18 21:51:15 -0400 | [diff] [blame] | 238 | GrOpFlushState flushState(gpu, fContext->contextPriv().resourceProvider(), &fTokenTracker, |
| 239 | fVertexBufferSpace.get(), fIndexBufferSpace.get()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 240 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 241 | GrOnFlushResourceProvider onFlushProvider(this); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 242 | // TODO: AFAICT the only reason fFlushState is on GrDrawingManager rather than on the |
| 243 | // stack here is to preserve the flush tokens. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 244 | |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 245 | // Prepare any onFlush op lists (e.g. atlases). |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 246 | if (!fOnFlushCBObjects.empty()) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 247 | fDAG.gatherIDs(&fFlushingOpListIDs); |
| 248 | |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 249 | SkSTArray<4, sk_sp<GrRenderTargetContext>> renderTargetContexts; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 250 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
| 251 | onFlushCBObject->preFlush(&onFlushProvider, |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 252 | fFlushingOpListIDs.begin(), fFlushingOpListIDs.count(), |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 253 | &renderTargetContexts); |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 254 | for (const sk_sp<GrRenderTargetContext>& rtc : renderTargetContexts) { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 255 | sk_sp<GrRenderTargetOpList> onFlushOpList = sk_ref_sp(rtc->getRTOpList()); |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 256 | if (!onFlushOpList) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 257 | continue; // Odd - but not a big deal |
| 258 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 259 | #ifdef SK_DEBUG |
| 260 | // OnFlush callbacks are already invoked during flush, and are therefore expected to |
| 261 | // handle resource allocation & usage on their own. (No deferred or lazy proxies!) |
| 262 | onFlushOpList->visitProxies_debugOnly([](GrSurfaceProxy* p) { |
| 263 | SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred()); |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 264 | SkASSERT(GrSurfaceProxy::LazyState::kNot == p->lazyInstantiationState()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 265 | }); |
| 266 | #endif |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 267 | onFlushOpList->makeClosed(*fContext->contextPriv().caps()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 268 | onFlushOpList->prepare(&flushState); |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 269 | fOnFlushCBOpLists.push_back(std::move(onFlushOpList)); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 270 | } |
| 271 | renderTargetContexts.reset(); |
| 272 | } |
| 273 | } |
| 274 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 275 | #if 0 |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 276 | // Enable this to print out verbose GrOp information |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 277 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 278 | SkDEBUGCODE(fOpLists[i]->dump();) |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 279 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 280 | #endif |
| 281 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 282 | int startIndex, stopIndex; |
| 283 | bool flushed = false; |
| 284 | |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 285 | { |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 286 | GrResourceAllocator alloc(fContext->contextPriv().resourceProvider(), |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 287 | flushState.deinstantiateProxyTracker()); |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 288 | for (int i = 0; i < fDAG.numOpLists(); ++i) { |
| 289 | if (fDAG.opList(i)) { |
| 290 | fDAG.opList(i)->gatherProxyIntervals(&alloc); |
| 291 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 292 | alloc.markEndOfOpList(i); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 293 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 294 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 295 | GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError; |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 296 | int numOpListsExecuted = 0; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 297 | while (alloc.assign(&startIndex, &stopIndex, &error)) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 298 | if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) { |
| 299 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 300 | if (fDAG.opList(i) && !fDAG.opList(i)->isFullyInstantiated()) { |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 301 | // If the backing surface wasn't allocated drop the entire opList. |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 302 | fDAG.removeOpList(i); |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 303 | } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 304 | if (fDAG.opList(i)) { |
| 305 | fDAG.opList(i)->purgeOpsWithUninstantiatedProxies(); |
Robert Phillips | bbcb7f7 | 2018-05-31 11:16:19 -0400 | [diff] [blame] | 306 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 307 | } |
| 308 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 309 | |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 310 | if (this->executeOpLists(startIndex, stopIndex, &flushState, &numOpListsExecuted)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 311 | flushed = true; |
| 312 | } |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 313 | } |
Greg Daniel | c42b20b | 2017-10-04 10:34:49 -0400 | [diff] [blame] | 314 | } |
| 315 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 316 | #ifdef SK_DEBUG |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 317 | for (int i = 0; i < fDAG.numOpLists(); ++i) { |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 318 | // If there are any remaining opLists at this point, make sure they will not survive the |
| 319 | // flush. Otherwise we need to call endFlush() on them. |
| 320 | // http://skbug.com/7111 |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 321 | SkASSERT(!fDAG.opList(i) || fDAG.opList(i)->unique()); |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 322 | } |
| 323 | #endif |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 324 | fDAG.reset(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 325 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 326 | #ifdef SK_DEBUG |
| 327 | // In non-DDL mode this checks that all the flushed ops have been freed from the memory pool. |
| 328 | // When we move to partial flushes this assert will no longer be valid. |
| 329 | // In DDL mode this check is somewhat superfluous since the memory for most of the ops/opLists |
| 330 | // will be stored in the DDL's GrOpMemoryPools. |
| 331 | GrOpMemoryPool* opMemoryPool = fContext->contextPriv().opMemoryPool(); |
| 332 | opMemoryPool->isEmpty(); |
| 333 | #endif |
| 334 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 335 | GrSemaphoresSubmitted result = gpu->finishFlush(numSemaphores, backendSemaphores); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 336 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 337 | flushState.deinstantiateProxyTracker()->deinstantiateAllProxies(); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 338 | |
Brian Salomon | 57d2bea | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 339 | // Give the cache a chance to purge resources that become purgeable due to flushing. |
| 340 | if (flushed) { |
| 341 | fContext->contextPriv().getResourceCache()->purgeAsNeeded(); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 342 | } |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 343 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 344 | onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingOpListIDs.begin(), |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 345 | fFlushingOpListIDs.count()); |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 346 | } |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 347 | fFlushingOpListIDs.reset(); |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 348 | fFlushing = false; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 349 | |
| 350 | return result; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 353 | bool GrDrawingManager::executeOpLists(int startIndex, int stopIndex, GrOpFlushState* flushState, |
| 354 | int* numOpListsExecuted) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 355 | SkASSERT(startIndex <= stopIndex && stopIndex <= fDAG.numOpLists()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 356 | |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 357 | #if GR_FLUSH_TIME_OP_SPEW |
| 358 | SkDebugf("Flushing opLists: %d to %d out of [%d, %d]\n", |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 359 | startIndex, stopIndex, 0, fDAG.numOpLists()); |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 360 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 361 | if (fDAG.opList(i)) { |
| 362 | fDAG.opList(i)->dump(true); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 363 | } |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 364 | } |
| 365 | #endif |
| 366 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 367 | GrResourceProvider* resourceProvider = fContext->contextPriv().resourceProvider(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 368 | bool anyOpListsExecuted = false; |
| 369 | |
| 370 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 371 | if (!fDAG.opList(i)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 372 | continue; |
| 373 | } |
| 374 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 375 | GrOpList* opList = fDAG.opList(i); |
| 376 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 377 | if (resourceProvider->explicitlyAllocateGPUResources()) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 378 | if (!opList->isFullyInstantiated()) { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 379 | // If the backing surface wasn't allocated drop the draw of the entire opList. |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 380 | fDAG.removeOpList(i); |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 381 | continue; |
| 382 | } |
| 383 | } else { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 384 | if (!opList->instantiate(resourceProvider)) { |
| 385 | fDAG.removeOpList(i); |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 386 | continue; |
| 387 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 388 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 389 | |
| 390 | // TODO: handle this instantiation via lazy surface proxies? |
| 391 | // Instantiate all deferred proxies (being built on worker threads) so we can upload them |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 392 | opList->instantiateDeferredProxies(fContext->contextPriv().resourceProvider()); |
| 393 | opList->prepare(flushState); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | // Upload all data to the GPU |
| 397 | flushState->preExecuteDraws(); |
| 398 | |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 399 | // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources |
| 400 | // for each command buffer associated with the oplists. If this gets too large we can cause the |
| 401 | // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we |
| 402 | // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some |
| 403 | // memory pressure. |
| 404 | static constexpr int kMaxOpListsBeforeFlush = 100; |
| 405 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 406 | // Execute the onFlush op lists first, if any. |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 407 | for (sk_sp<GrOpList>& onFlushOpList : fOnFlushCBOpLists) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 408 | if (!onFlushOpList->execute(flushState)) { |
| 409 | SkDebugf("WARNING: onFlushOpList failed to execute.\n"); |
| 410 | } |
| 411 | SkASSERT(onFlushOpList->unique()); |
| 412 | onFlushOpList = nullptr; |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 413 | (*numOpListsExecuted)++; |
| 414 | if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) { |
| 415 | flushState->gpu()->finishFlush(0, nullptr); |
| 416 | *numOpListsExecuted = 0; |
| 417 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 418 | } |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 419 | fOnFlushCBOpLists.reset(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 420 | |
| 421 | // Execute the normal op lists. |
| 422 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 423 | if (!fDAG.opList(i)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 424 | continue; |
| 425 | } |
| 426 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 427 | if (fDAG.opList(i)->execute(flushState)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 428 | anyOpListsExecuted = true; |
| 429 | } |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 430 | (*numOpListsExecuted)++; |
| 431 | if (*numOpListsExecuted >= kMaxOpListsBeforeFlush) { |
| 432 | flushState->gpu()->finishFlush(0, nullptr); |
| 433 | *numOpListsExecuted = 0; |
| 434 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | SkASSERT(!flushState->commandBuffer()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 438 | SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 439 | |
| 440 | // We reset the flush state before the OpLists so that the last resources to be freed are those |
| 441 | // that are written to in the OpLists. This helps to make sure the most recently used resources |
| 442 | // are the last to be purged by the resource cache. |
| 443 | flushState->reset(); |
| 444 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 445 | fDAG.removeOpLists(startIndex, stopIndex); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 446 | |
| 447 | return anyOpListsExecuted; |
| 448 | } |
| 449 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 450 | GrSemaphoresSubmitted GrDrawingManager::prepareSurfaceForExternalIO( |
| 451 | GrSurfaceProxy* proxy, int numSemaphores, GrBackendSemaphore backendSemaphores[]) { |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 452 | if (this->wasAbandoned()) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 453 | return GrSemaphoresSubmitted::kNo; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 454 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 455 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 456 | SkASSERT(proxy); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 457 | |
Robert Phillips | 874b535 | 2018-03-16 08:48:24 -0400 | [diff] [blame] | 458 | GrGpu* gpu = fContext->contextPriv().getGpu(); |
| 459 | if (!gpu) { |
| 460 | return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording |
| 461 | } |
| 462 | |
Kevin Lubick | 4284613 | 2018-01-05 10:11:11 -0500 | [diff] [blame] | 463 | GrSemaphoresSubmitted result = GrSemaphoresSubmitted::kNo; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 464 | if (proxy->priv().hasPendingIO() || numSemaphores) { |
| 465 | result = this->flush(proxy, numSemaphores, backendSemaphores); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 468 | if (!proxy->instantiate(fContext->contextPriv().resourceProvider())) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 469 | return result; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 470 | } |
| 471 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 472 | GrSurface* surface = proxy->peekSurface(); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 473 | if (auto* rt = surface->asRenderTarget()) { |
| 474 | gpu->resolveRenderTarget(rt); |
| 475 | } |
| 476 | if (auto* tex = surface->asTexture()) { |
| 477 | if (tex->texturePriv().mipMapped() == GrMipMapped::kYes && |
| 478 | tex->texturePriv().mipMapsAreDirty()) { |
| 479 | gpu->regenerateMipMapLevels(tex); |
| 480 | } |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 481 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 482 | |
| 483 | SkDEBUGCODE(this->validate()); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 484 | return result; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 487 | void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 488 | fOnFlushCBObjects.push_back(onFlushCBObject); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 491 | void GrDrawingManager::moveOpListsToDDL(SkDeferredDisplayList* ddl) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 492 | SkDEBUGCODE(this->validate()); |
| 493 | |
| 494 | // no opList should receive a new command after this |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 495 | fDAG.closeAll(fContext->contextPriv().caps()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 496 | fActiveOpList = nullptr; |
Robert Phillips | 7a13705 | 2018-02-01 11:23:12 -0500 | [diff] [blame] | 497 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 498 | fDAG.swap(&ddl->fOpLists); |
Robert Phillips | 867ce8f | 2018-06-21 10:28:36 -0400 | [diff] [blame] | 499 | |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 500 | if (fPathRendererChain) { |
| 501 | if (auto ccpr = fPathRendererChain->getCoverageCountingPathRenderer()) { |
| 502 | ddl->fPendingPaths = ccpr->detachPendingPaths(); |
| 503 | } |
| 504 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 505 | |
| 506 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | void GrDrawingManager::copyOpListsFromDDL(const SkDeferredDisplayList* ddl, |
| 510 | GrRenderTargetProxy* newDest) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 511 | SkDEBUGCODE(this->validate()); |
| 512 | |
| 513 | if (fActiveOpList) { |
| 514 | // This is a temporary fix for the partial-MDB world. In that world we're not |
| 515 | // reordering so ops that (in the single opList world) would've just glommed onto the |
| 516 | // end of the single opList but referred to a far earlier RT need to appear in their |
| 517 | // own opList. |
| 518 | fActiveOpList->makeClosed(*fContext->contextPriv().caps()); |
| 519 | fActiveOpList = nullptr; |
| 520 | } |
| 521 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 522 | // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData. |
| 523 | // The lazy proxy that references it (in the copied opLists) will steal its GrTexture. |
| 524 | ddl->fLazyProxyData->fReplayDest = newDest; |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 525 | |
| 526 | if (ddl->fPendingPaths.size()) { |
| 527 | GrCoverageCountingPathRenderer* ccpr = this->getCoverageCountingPathRenderer(); |
| 528 | |
| 529 | ccpr->mergePendingPaths(ddl->fPendingPaths); |
| 530 | } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 531 | |
| 532 | fDAG.add(ddl->fOpLists); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 533 | |
| 534 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 535 | } |
| 536 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 537 | #ifdef SK_DEBUG |
| 538 | void GrDrawingManager::validate() const { |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 539 | if (fDAG.sortingOpLists() && fReduceOpListSplitting) { |
| 540 | SkASSERT(!fActiveOpList); |
| 541 | } else { |
| 542 | if (fActiveOpList) { |
| 543 | SkASSERT(!fDAG.empty()); |
| 544 | SkASSERT(!fActiveOpList->isClosed()); |
| 545 | SkASSERT(fActiveOpList == fDAG.back()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 546 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 547 | |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 548 | for (int i = 0; i < fDAG.numOpLists(); ++i) { |
| 549 | if (fActiveOpList != fDAG.opList(i)) { |
| 550 | SkASSERT(fDAG.opList(i)->isClosed()); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | if (!fDAG.empty() && !fDAG.back()->isClosed()) { |
| 555 | SkASSERT(fActiveOpList == fDAG.back()); |
| 556 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | #endif |
| 560 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 561 | sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(GrRenderTargetProxy* rtp, |
| 562 | bool managedOpList) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 563 | SkDEBUGCODE(this->validate()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 564 | SkASSERT(fContext); |
| 565 | |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 566 | if (fDAG.sortingOpLists() && fReduceOpListSplitting) { |
| 567 | // In this case we need to close all the opLists that rely on the current contents of |
| 568 | // 'rtp'. That is bc we're going to update the content of the proxy so they need to be |
| 569 | // split in case they use both the old and new content. (This is a bit of an overkill: |
| 570 | // they really only need to be split if they ever reference proxy's contents again but |
| 571 | // that is hard to predict/handle). |
| 572 | if (GrOpList* lastOpList = rtp->getLastOpList()) { |
| 573 | lastOpList->closeThoseWhoDependOnMe(*fContext->contextPriv().caps()); |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 574 | } |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 575 | } else if (fActiveOpList) { |
| 576 | // This is a temporary fix for the partial-MDB world. In that world we're not |
| 577 | // reordering so ops that (in the single opList world) would've just glommed onto the |
| 578 | // end of the single opList but referred to a far earlier RT need to appear in their |
| 579 | // own opList. |
| 580 | fActiveOpList->makeClosed(*fContext->contextPriv().caps()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 581 | fActiveOpList = nullptr; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 582 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 583 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 584 | auto resourceProvider = fContext->contextPriv().resourceProvider(); |
| 585 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 586 | sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList( |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 587 | resourceProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 588 | fContext->contextPriv().refOpMemoryPool(), |
Robert Phillips | 3a9710b | 2018-03-27 17:51:55 -0400 | [diff] [blame] | 589 | rtp, |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 590 | fContext->contextPriv().getAuditTrail())); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 591 | SkASSERT(rtp->getLastOpList() == opList.get()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 592 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 593 | if (managedOpList) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 594 | fDAG.add(opList); |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 595 | |
| 596 | if (!fDAG.sortingOpLists() || !fReduceOpListSplitting) { |
| 597 | fActiveOpList = opList.get(); |
| 598 | } |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 599 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 600 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 601 | SkDEBUGCODE(this->validate()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 602 | return opList; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 605 | sk_sp<GrTextureOpList> GrDrawingManager::newTextureOpList(GrTextureProxy* textureProxy) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 606 | SkDEBUGCODE(this->validate()); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 607 | SkASSERT(fContext); |
| 608 | |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 609 | if (fDAG.sortingOpLists() && fReduceOpListSplitting) { |
| 610 | // In this case we need to close all the opLists that rely on the current contents of |
| 611 | // 'texture'. That is bc we're going to update the content of the proxy so they need to |
| 612 | // be split in case they use both the old and new content. (This is a bit of an |
| 613 | // overkill: they really only need to be split if they ever reference proxy's contents |
| 614 | // again but that is hard to predict/handle). |
| 615 | if (GrOpList* lastOpList = textureProxy->getLastOpList()) { |
| 616 | lastOpList->closeThoseWhoDependOnMe(*fContext->contextPriv().caps()); |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 617 | } |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 618 | } else if (fActiveOpList) { |
| 619 | // This is a temporary fix for the partial-MDB world. In that world we're not |
| 620 | // reordering so ops that (in the single opList world) would've just glommed onto the |
| 621 | // end of the single opList but referred to a far earlier RT need to appear in their |
| 622 | // own opList. |
| 623 | fActiveOpList->makeClosed(*fContext->contextPriv().caps()); |
| 624 | fActiveOpList = nullptr; |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 625 | } |
| 626 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 627 | sk_sp<GrTextureOpList> opList(new GrTextureOpList(fContext->contextPriv().resourceProvider(), |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 628 | fContext->contextPriv().refOpMemoryPool(), |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 629 | textureProxy, |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 630 | fContext->contextPriv().getAuditTrail())); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 631 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 632 | SkASSERT(textureProxy->getLastOpList() == opList.get()); |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 633 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 634 | fDAG.add(opList); |
Robert Phillips | b7a98ef | 2018-10-10 09:26:00 -0400 | [diff] [blame] | 635 | if (!fDAG.sortingOpLists() || !fReduceOpListSplitting) { |
| 636 | fActiveOpList = opList.get(); |
| 637 | } |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 638 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 639 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 640 | return opList; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 641 | } |
| 642 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 643 | GrTextContext* GrDrawingManager::getTextContext() { |
| 644 | if (!fTextContext) { |
| 645 | fTextContext = GrTextContext::Make(fOptionsForTextContext); |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 648 | return fTextContext.get(); |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 649 | } |
| 650 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 651 | /* |
| 652 | * This method finds a path renderer that can draw the specified path on |
| 653 | * the provided target. |
| 654 | * Due to its expense, the software path renderer has split out so it can |
| 655 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 656 | */ |
| 657 | GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 658 | bool allowSW, |
| 659 | GrPathRendererChain::DrawType drawType, |
| 660 | GrPathRenderer::StencilSupport* stencilSupport) { |
| 661 | |
| 662 | if (!fPathRendererChain) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 663 | fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain)); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport); |
| 667 | if (!pr && allowSW) { |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 668 | auto swPR = this->getSoftwarePathRenderer(); |
| 669 | if (GrPathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) { |
| 670 | pr = swPR; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 671 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | return pr; |
| 675 | } |
| 676 | |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 677 | GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() { |
| 678 | if (!fSoftwarePathRenderer) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 679 | fSoftwarePathRenderer.reset( |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 680 | new GrSoftwarePathRenderer(fContext->contextPriv().proxyProvider(), |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 681 | fOptionsForPathRendererChain.fAllowPathMaskCaching)); |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 682 | } |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 683 | return fSoftwarePathRenderer.get(); |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 686 | GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() { |
| 687 | if (!fPathRendererChain) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 688 | fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain)); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 689 | } |
| 690 | return fPathRendererChain->getCoverageCountingPathRenderer(); |
| 691 | } |
| 692 | |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 693 | void GrDrawingManager::flushIfNecessary() { |
| 694 | GrResourceCache* resourceCache = fContext->contextPriv().getResourceCache(); |
| 695 | if (resourceCache && resourceCache->requestsFlush()) { |
Brian Salomon | 57d2bea | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 696 | this->flush(nullptr, 0, nullptr); |
| 697 | resourceCache->purgeAsNeeded(); |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 701 | sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext( |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 702 | sk_sp<GrSurfaceProxy> sProxy, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 703 | sk_sp<SkColorSpace> colorSpace, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 704 | const SkSurfaceProps* surfaceProps, |
| 705 | bool managedOpList) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 706 | if (this->wasAbandoned() || !sProxy->asRenderTargetProxy()) { |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 707 | return nullptr; |
| 708 | } |
| 709 | |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 710 | // 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] | 711 | // by, including internal usage. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 712 | if (!SkSurface_Gpu::Valid(fContext->contextPriv().caps(), sProxy->config(), colorSpace.get())) { |
brianosman | a9c3c6a | 2016-09-29 10:08:36 -0700 | [diff] [blame] | 713 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 714 | return nullptr; |
| 715 | } |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 716 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 717 | sk_sp<GrRenderTargetProxy> rtp(sk_ref_sp(sProxy->asRenderTargetProxy())); |
| 718 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 719 | return sk_sp<GrRenderTargetContext>(new GrRenderTargetContext( |
| 720 | fContext, this, std::move(rtp), |
| 721 | std::move(colorSpace), |
| 722 | surfaceProps, |
| 723 | fContext->contextPriv().getAuditTrail(), |
| 724 | fSingleOwner, managedOpList)); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 725 | } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 726 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 727 | sk_sp<GrTextureContext> GrDrawingManager::makeTextureContext(sk_sp<GrSurfaceProxy> sProxy, |
| 728 | sk_sp<SkColorSpace> colorSpace) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 729 | if (this->wasAbandoned() || !sProxy->asTextureProxy()) { |
| 730 | return nullptr; |
| 731 | } |
| 732 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 733 | // 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] | 734 | // by, including internal usage. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 735 | if (!SkSurface_Gpu::Valid(fContext->contextPriv().caps(), sProxy->config(), colorSpace.get())) { |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 736 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
| 737 | return nullptr; |
| 738 | } |
| 739 | |
Robert Phillips | 383c418 | 2018-02-07 12:47:44 -0500 | [diff] [blame] | 740 | // GrTextureRenderTargets should always be using a GrRenderTargetContext |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 741 | SkASSERT(!sProxy->asRenderTargetProxy()); |
| 742 | |
| 743 | sk_sp<GrTextureProxy> textureProxy(sk_ref_sp(sProxy->asTextureProxy())); |
| 744 | |
| 745 | return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy), |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 746 | std::move(colorSpace), |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 747 | fContext->contextPriv().getAuditTrail(), |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 748 | fSingleOwner)); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 749 | } |