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, |
| 153 | GrContextOptions::Enable sortOpLists) |
| 154 | : fContext(context) |
| 155 | , fOptionsForPathRendererChain(optionsForPathRendererChain) |
| 156 | , fOptionsForTextContext(optionsForTextContext) |
| 157 | , fSingleOwner(singleOwner) |
| 158 | , fAbandoned(false) |
| 159 | , fDAG(explicitlyAllocating, sortOpLists) |
| 160 | , fTextContext(nullptr) |
| 161 | , fPathRendererChain(nullptr) |
| 162 | , fSoftwarePathRenderer(nullptr) |
| 163 | , fFlushing(false) { |
| 164 | } |
| 165 | |
| 166 | void GrDrawingManager::cleanup() { |
| 167 | fDAG.cleanup(fContext->contextPriv().caps()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 168 | |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 169 | fPathRendererChain = nullptr; |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 170 | fSoftwarePathRenderer = nullptr; |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 171 | |
| 172 | fOnFlushCBObjects.reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | GrDrawingManager::~GrDrawingManager() { |
| 176 | this->cleanup(); |
| 177 | } |
| 178 | |
| 179 | void GrDrawingManager::abandon() { |
| 180 | fAbandoned = true; |
| 181 | this->cleanup(); |
| 182 | } |
| 183 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 184 | void GrDrawingManager::freeGpuResources() { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 185 | for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) { |
| 186 | if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) { |
| 187 | // it's safe to just do this because we're iterating in reverse |
| 188 | fOnFlushCBObjects.removeShuffle(i); |
| 189 | } |
| 190 | } |
| 191 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 192 | // a path renderer may be holding onto resources |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 193 | fPathRendererChain = nullptr; |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 194 | fSoftwarePathRenderer = nullptr; |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 197 | // MDB TODO: make use of the 'proxy' parameter. |
Brian Salomon | 57d2bea | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 198 | GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy*, |
| 199 | int numSemaphores, |
| 200 | GrBackendSemaphore backendSemaphores[]) { |
| 201 | GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext); |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 202 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 203 | if (fFlushing || this->wasAbandoned()) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 204 | return GrSemaphoresSubmitted::kNo; |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 205 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 206 | SkDEBUGCODE(this->validate()); |
| 207 | |
Robert Phillips | 874b535 | 2018-03-16 08:48:24 -0400 | [diff] [blame] | 208 | GrGpu* gpu = fContext->contextPriv().getGpu(); |
| 209 | if (!gpu) { |
| 210 | return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording |
| 211 | } |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 212 | fFlushing = true; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 213 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 214 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 215 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 216 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 217 | // 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] | 218 | fDAG.closeAll(fContext->contextPriv().caps()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 219 | fActiveOpList = nullptr; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 220 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 221 | fDAG.prepForFlush(); |
Robert Phillips | a4c93ac | 2017-05-18 11:40:04 -0400 | [diff] [blame] | 222 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 223 | GrOpFlushState flushState(gpu, fContext->contextPriv().resourceProvider(), |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 224 | &fTokenTracker); |
| 225 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 226 | GrOnFlushResourceProvider onFlushProvider(this); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 227 | // TODO: AFAICT the only reason fFlushState is on GrDrawingManager rather than on the |
| 228 | // stack here is to preserve the flush tokens. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 229 | |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 230 | // Prepare any onFlush op lists (e.g. atlases). |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 231 | if (!fOnFlushCBObjects.empty()) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 232 | fDAG.gatherIDs(&fFlushingOpListIDs); |
| 233 | |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 234 | SkSTArray<4, sk_sp<GrRenderTargetContext>> renderTargetContexts; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 235 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
| 236 | onFlushCBObject->preFlush(&onFlushProvider, |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 237 | fFlushingOpListIDs.begin(), fFlushingOpListIDs.count(), |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 238 | &renderTargetContexts); |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 239 | for (const sk_sp<GrRenderTargetContext>& rtc : renderTargetContexts) { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 240 | sk_sp<GrRenderTargetOpList> onFlushOpList = sk_ref_sp(rtc->getRTOpList()); |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 241 | if (!onFlushOpList) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 242 | continue; // Odd - but not a big deal |
| 243 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 244 | #ifdef SK_DEBUG |
| 245 | // OnFlush callbacks are already invoked during flush, and are therefore expected to |
| 246 | // handle resource allocation & usage on their own. (No deferred or lazy proxies!) |
| 247 | onFlushOpList->visitProxies_debugOnly([](GrSurfaceProxy* p) { |
| 248 | SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred()); |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 249 | SkASSERT(GrSurfaceProxy::LazyState::kNot == p->lazyInstantiationState()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 250 | }); |
| 251 | #endif |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 252 | onFlushOpList->makeClosed(*fContext->contextPriv().caps()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 253 | onFlushOpList->prepare(&flushState); |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 254 | fOnFlushCBOpLists.push_back(std::move(onFlushOpList)); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 255 | } |
| 256 | renderTargetContexts.reset(); |
| 257 | } |
| 258 | } |
| 259 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 260 | #if 0 |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 261 | // Enable this to print out verbose GrOp information |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 262 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 263 | SkDEBUGCODE(fOpLists[i]->dump();) |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 264 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 265 | #endif |
| 266 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 267 | int startIndex, stopIndex; |
| 268 | bool flushed = false; |
| 269 | |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 270 | { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 271 | GrResourceAllocator alloc(fContext->contextPriv().resourceProvider()); |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 272 | for (int i = 0; i < fDAG.numOpLists(); ++i) { |
| 273 | if (fDAG.opList(i)) { |
| 274 | fDAG.opList(i)->gatherProxyIntervals(&alloc); |
| 275 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 276 | alloc.markEndOfOpList(i); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 277 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 278 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 279 | GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError; |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 280 | while (alloc.assign(&startIndex, &stopIndex, flushState.uninstantiateProxyTracker(), |
| 281 | &error)) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 282 | if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) { |
| 283 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 284 | if (fDAG.opList(i) && !fDAG.opList(i)->isFullyInstantiated()) { |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 285 | // If the backing surface wasn't allocated drop the entire opList. |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 286 | fDAG.removeOpList(i); |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 287 | } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 288 | if (fDAG.opList(i)) { |
| 289 | fDAG.opList(i)->purgeOpsWithUninstantiatedProxies(); |
Robert Phillips | bbcb7f7 | 2018-05-31 11:16:19 -0400 | [diff] [blame] | 290 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 291 | } |
| 292 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 293 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 294 | if (this->executeOpLists(startIndex, stopIndex, &flushState)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 295 | flushed = true; |
| 296 | } |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 297 | } |
Greg Daniel | c42b20b | 2017-10-04 10:34:49 -0400 | [diff] [blame] | 298 | } |
| 299 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 300 | #ifdef SK_DEBUG |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 301 | for (int i = 0; i < fDAG.numOpLists(); ++i) { |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 302 | // If there are any remaining opLists at this point, make sure they will not survive the |
| 303 | // flush. Otherwise we need to call endFlush() on them. |
| 304 | // http://skbug.com/7111 |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 305 | SkASSERT(!fDAG.opList(i) || fDAG.opList(i)->unique()); |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 306 | } |
| 307 | #endif |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 308 | fDAG.reset(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 309 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 310 | #ifdef SK_DEBUG |
| 311 | // In non-DDL mode this checks that all the flushed ops have been freed from the memory pool. |
| 312 | // When we move to partial flushes this assert will no longer be valid. |
| 313 | // In DDL mode this check is somewhat superfluous since the memory for most of the ops/opLists |
| 314 | // will be stored in the DDL's GrOpMemoryPools. |
| 315 | GrOpMemoryPool* opMemoryPool = fContext->contextPriv().opMemoryPool(); |
| 316 | opMemoryPool->isEmpty(); |
| 317 | #endif |
| 318 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 319 | GrSemaphoresSubmitted result = gpu->finishFlush(numSemaphores, backendSemaphores); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 320 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 321 | flushState.uninstantiateProxyTracker()->uninstantiateAllProxies(); |
| 322 | |
Brian Salomon | 57d2bea | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 323 | // Give the cache a chance to purge resources that become purgeable due to flushing. |
| 324 | if (flushed) { |
| 325 | fContext->contextPriv().getResourceCache()->purgeAsNeeded(); |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 326 | } |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 327 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 328 | onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingOpListIDs.begin(), |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 329 | fFlushingOpListIDs.count()); |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 330 | } |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 331 | fFlushingOpListIDs.reset(); |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 332 | fFlushing = false; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 333 | |
| 334 | return result; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 337 | bool GrDrawingManager::executeOpLists(int startIndex, int stopIndex, GrOpFlushState* flushState) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 338 | SkASSERT(startIndex <= stopIndex && stopIndex <= fDAG.numOpLists()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 339 | |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 340 | #if GR_FLUSH_TIME_OP_SPEW |
| 341 | SkDebugf("Flushing opLists: %d to %d out of [%d, %d]\n", |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 342 | startIndex, stopIndex, 0, fDAG.numOpLists()); |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 343 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 344 | if (fDAG.opList(i)) { |
| 345 | fDAG.opList(i)->dump(true); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 346 | } |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 347 | } |
| 348 | #endif |
| 349 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 350 | GrResourceProvider* resourceProvider = fContext->contextPriv().resourceProvider(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 351 | bool anyOpListsExecuted = false; |
| 352 | |
| 353 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 354 | if (!fDAG.opList(i)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 355 | continue; |
| 356 | } |
| 357 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 358 | GrOpList* opList = fDAG.opList(i); |
| 359 | |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 360 | if (resourceProvider->explicitlyAllocateGPUResources()) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 361 | if (!opList->isFullyInstantiated()) { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 362 | // 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] | 363 | fDAG.removeOpList(i); |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 364 | continue; |
| 365 | } |
| 366 | } else { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 367 | if (!opList->instantiate(resourceProvider)) { |
| 368 | fDAG.removeOpList(i); |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 369 | continue; |
| 370 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 371 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 372 | |
| 373 | // TODO: handle this instantiation via lazy surface proxies? |
| 374 | // 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] | 375 | opList->instantiateDeferredProxies(fContext->contextPriv().resourceProvider()); |
| 376 | opList->prepare(flushState); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | // Upload all data to the GPU |
| 380 | flushState->preExecuteDraws(); |
| 381 | |
| 382 | // Execute the onFlush op lists first, if any. |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 383 | for (sk_sp<GrOpList>& onFlushOpList : fOnFlushCBOpLists) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 384 | if (!onFlushOpList->execute(flushState)) { |
| 385 | SkDebugf("WARNING: onFlushOpList failed to execute.\n"); |
| 386 | } |
| 387 | SkASSERT(onFlushOpList->unique()); |
| 388 | onFlushOpList = nullptr; |
| 389 | } |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 390 | fOnFlushCBOpLists.reset(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 391 | |
| 392 | // Execute the normal op lists. |
| 393 | for (int i = startIndex; i < stopIndex; ++i) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 394 | if (!fDAG.opList(i)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 395 | continue; |
| 396 | } |
| 397 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 398 | if (fDAG.opList(i)->execute(flushState)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 399 | anyOpListsExecuted = true; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | SkASSERT(!flushState->commandBuffer()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 404 | SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 405 | |
| 406 | // We reset the flush state before the OpLists so that the last resources to be freed are those |
| 407 | // that are written to in the OpLists. This helps to make sure the most recently used resources |
| 408 | // are the last to be purged by the resource cache. |
| 409 | flushState->reset(); |
| 410 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 411 | fDAG.removeOpLists(startIndex, stopIndex); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 412 | |
| 413 | return anyOpListsExecuted; |
| 414 | } |
| 415 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 416 | GrSemaphoresSubmitted GrDrawingManager::prepareSurfaceForExternalIO( |
| 417 | GrSurfaceProxy* proxy, int numSemaphores, GrBackendSemaphore backendSemaphores[]) { |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 418 | if (this->wasAbandoned()) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 419 | return GrSemaphoresSubmitted::kNo; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 420 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 421 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 422 | SkASSERT(proxy); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 423 | |
Robert Phillips | 874b535 | 2018-03-16 08:48:24 -0400 | [diff] [blame] | 424 | GrGpu* gpu = fContext->contextPriv().getGpu(); |
| 425 | if (!gpu) { |
| 426 | return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording |
| 427 | } |
| 428 | |
Kevin Lubick | 4284613 | 2018-01-05 10:11:11 -0500 | [diff] [blame] | 429 | GrSemaphoresSubmitted result = GrSemaphoresSubmitted::kNo; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 430 | if (proxy->priv().hasPendingIO() || numSemaphores) { |
| 431 | result = this->flush(proxy, numSemaphores, backendSemaphores); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 434 | if (!proxy->instantiate(fContext->contextPriv().resourceProvider())) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 435 | return result; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 438 | GrSurface* surface = proxy->peekSurface(); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 439 | if (auto* rt = surface->asRenderTarget()) { |
| 440 | gpu->resolveRenderTarget(rt); |
| 441 | } |
| 442 | if (auto* tex = surface->asTexture()) { |
| 443 | if (tex->texturePriv().mipMapped() == GrMipMapped::kYes && |
| 444 | tex->texturePriv().mipMapsAreDirty()) { |
| 445 | gpu->regenerateMipMapLevels(tex); |
| 446 | } |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 447 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 448 | |
| 449 | SkDEBUGCODE(this->validate()); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 450 | return result; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 453 | void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 454 | fOnFlushCBObjects.push_back(onFlushCBObject); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 457 | void GrDrawingManager::moveOpListsToDDL(SkDeferredDisplayList* ddl) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 458 | SkDEBUGCODE(this->validate()); |
| 459 | |
| 460 | // no opList should receive a new command after this |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 461 | fDAG.closeAll(fContext->contextPriv().caps()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 462 | fActiveOpList = nullptr; |
Robert Phillips | 7a13705 | 2018-02-01 11:23:12 -0500 | [diff] [blame] | 463 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 464 | fDAG.swap(&ddl->fOpLists); |
Robert Phillips | 867ce8f | 2018-06-21 10:28:36 -0400 | [diff] [blame] | 465 | |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 466 | if (fPathRendererChain) { |
| 467 | if (auto ccpr = fPathRendererChain->getCoverageCountingPathRenderer()) { |
| 468 | ddl->fPendingPaths = ccpr->detachPendingPaths(); |
| 469 | } |
| 470 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 471 | |
| 472 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | void GrDrawingManager::copyOpListsFromDDL(const SkDeferredDisplayList* ddl, |
| 476 | GrRenderTargetProxy* newDest) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 477 | SkDEBUGCODE(this->validate()); |
| 478 | |
| 479 | if (fActiveOpList) { |
| 480 | // This is a temporary fix for the partial-MDB world. In that world we're not |
| 481 | // reordering so ops that (in the single opList world) would've just glommed onto the |
| 482 | // end of the single opList but referred to a far earlier RT need to appear in their |
| 483 | // own opList. |
| 484 | fActiveOpList->makeClosed(*fContext->contextPriv().caps()); |
| 485 | fActiveOpList = nullptr; |
| 486 | } |
| 487 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 488 | // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData. |
| 489 | // The lazy proxy that references it (in the copied opLists) will steal its GrTexture. |
| 490 | ddl->fLazyProxyData->fReplayDest = newDest; |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 491 | |
| 492 | if (ddl->fPendingPaths.size()) { |
| 493 | GrCoverageCountingPathRenderer* ccpr = this->getCoverageCountingPathRenderer(); |
| 494 | |
| 495 | ccpr->mergePendingPaths(ddl->fPendingPaths); |
| 496 | } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 497 | |
| 498 | fDAG.add(ddl->fOpLists); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 499 | |
| 500 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 501 | } |
| 502 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 503 | #ifdef SK_DEBUG |
| 504 | void GrDrawingManager::validate() const { |
| 505 | if (fActiveOpList) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 506 | SkASSERT(!fDAG.empty()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 507 | SkASSERT(!fActiveOpList->isClosed()); |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 508 | SkASSERT(fActiveOpList == fDAG.back()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 511 | for (int i = 0; i < fDAG.numOpLists(); ++i) { |
| 512 | if (fActiveOpList != fDAG.opList(i)) { |
| 513 | SkASSERT(fDAG.opList(i)->isClosed()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 517 | if (!fDAG.empty() && !fDAG.back()->isClosed()) { |
| 518 | SkASSERT(fActiveOpList == fDAG.back()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | #endif |
| 522 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 523 | sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(GrRenderTargetProxy* rtp, |
| 524 | bool managedOpList) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 525 | SkDEBUGCODE(this->validate()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 526 | SkASSERT(fContext); |
| 527 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 528 | if (fActiveOpList) { |
Robert Phillips | 6a4e60b | 2018-07-24 16:09:40 +0000 | [diff] [blame] | 529 | // This is a temporary fix for the partial-MDB world. In that world we're not |
| 530 | // reordering so ops that (in the single opList world) would've just glommed onto the |
| 531 | // end of the single opList but referred to a far earlier RT need to appear in their |
| 532 | // own opList. |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 533 | fActiveOpList->makeClosed(*fContext->contextPriv().caps()); |
| 534 | fActiveOpList = nullptr; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 535 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 536 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 537 | auto resourceProvider = fContext->contextPriv().resourceProvider(); |
| 538 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 539 | sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList( |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 540 | resourceProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 541 | fContext->contextPriv().refOpMemoryPool(), |
Robert Phillips | 3a9710b | 2018-03-27 17:51:55 -0400 | [diff] [blame] | 542 | rtp, |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 543 | fContext->contextPriv().getAuditTrail())); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 544 | SkASSERT(rtp->getLastOpList() == opList.get()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 545 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 546 | if (managedOpList) { |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 547 | fDAG.add(opList); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 548 | fActiveOpList = opList.get(); |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 549 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 550 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 551 | SkDEBUGCODE(this->validate()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 552 | return opList; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 555 | sk_sp<GrTextureOpList> GrDrawingManager::newTextureOpList(GrTextureProxy* textureProxy) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 556 | SkDEBUGCODE(this->validate()); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 557 | SkASSERT(fContext); |
| 558 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 559 | if (fActiveOpList) { |
Robert Phillips | 6a4e60b | 2018-07-24 16:09:40 +0000 | [diff] [blame] | 560 | // This is a temporary fix for the partial-MDB world. In that world we're not |
| 561 | // reordering so ops that (in the single opList world) would've just glommed onto the |
| 562 | // end of the single opList but referred to a far earlier RT need to appear in their |
| 563 | // own opList. |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 564 | fActiveOpList->makeClosed(*fContext->contextPriv().caps()); |
| 565 | fActiveOpList = nullptr; |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 566 | } |
| 567 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 568 | sk_sp<GrTextureOpList> opList(new GrTextureOpList(fContext->contextPriv().resourceProvider(), |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 569 | fContext->contextPriv().refOpMemoryPool(), |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 570 | textureProxy, |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 571 | fContext->contextPriv().getAuditTrail())); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 572 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 573 | SkASSERT(textureProxy->getLastOpList() == opList.get()); |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 574 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 575 | fDAG.add(opList); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 576 | fActiveOpList = opList.get(); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 577 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 578 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 579 | return opList; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 580 | } |
| 581 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 582 | GrTextContext* GrDrawingManager::getTextContext() { |
| 583 | if (!fTextContext) { |
| 584 | fTextContext = GrTextContext::Make(fOptionsForTextContext); |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 587 | return fTextContext.get(); |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 588 | } |
| 589 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 590 | /* |
| 591 | * This method finds a path renderer that can draw the specified path on |
| 592 | * the provided target. |
| 593 | * Due to its expense, the software path renderer has split out so it can |
| 594 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 595 | */ |
| 596 | GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 597 | bool allowSW, |
| 598 | GrPathRendererChain::DrawType drawType, |
| 599 | GrPathRenderer::StencilSupport* stencilSupport) { |
| 600 | |
| 601 | if (!fPathRendererChain) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 602 | fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain)); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport); |
| 606 | if (!pr && allowSW) { |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 607 | auto swPR = this->getSoftwarePathRenderer(); |
| 608 | if (GrPathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) { |
| 609 | pr = swPR; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 610 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | return pr; |
| 614 | } |
| 615 | |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 616 | GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() { |
| 617 | if (!fSoftwarePathRenderer) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 618 | fSoftwarePathRenderer.reset( |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 619 | new GrSoftwarePathRenderer(fContext->contextPriv().proxyProvider(), |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 620 | fOptionsForPathRendererChain.fAllowPathMaskCaching)); |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 621 | } |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 622 | return fSoftwarePathRenderer.get(); |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 623 | } |
| 624 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 625 | GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() { |
| 626 | if (!fPathRendererChain) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 627 | fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain)); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 628 | } |
| 629 | return fPathRendererChain->getCoverageCountingPathRenderer(); |
| 630 | } |
| 631 | |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 632 | void GrDrawingManager::flushIfNecessary() { |
| 633 | GrResourceCache* resourceCache = fContext->contextPriv().getResourceCache(); |
| 634 | if (resourceCache && resourceCache->requestsFlush()) { |
Brian Salomon | 57d2bea | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 635 | this->flush(nullptr, 0, nullptr); |
| 636 | resourceCache->purgeAsNeeded(); |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 640 | sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext( |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 641 | sk_sp<GrSurfaceProxy> sProxy, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 642 | sk_sp<SkColorSpace> colorSpace, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 643 | const SkSurfaceProps* surfaceProps, |
| 644 | bool managedOpList) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 645 | if (this->wasAbandoned() || !sProxy->asRenderTargetProxy()) { |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 646 | return nullptr; |
| 647 | } |
| 648 | |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 649 | // 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] | 650 | // by, including internal usage. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 651 | if (!SkSurface_Gpu::Valid(fContext->contextPriv().caps(), sProxy->config(), colorSpace.get())) { |
brianosman | a9c3c6a | 2016-09-29 10:08:36 -0700 | [diff] [blame] | 652 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 653 | return nullptr; |
| 654 | } |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 655 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 656 | sk_sp<GrRenderTargetProxy> rtp(sk_ref_sp(sProxy->asRenderTargetProxy())); |
| 657 | |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 658 | return sk_sp<GrRenderTargetContext>(new GrRenderTargetContext( |
| 659 | fContext, this, std::move(rtp), |
| 660 | std::move(colorSpace), |
| 661 | surfaceProps, |
| 662 | fContext->contextPriv().getAuditTrail(), |
| 663 | fSingleOwner, managedOpList)); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 664 | } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 665 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 666 | sk_sp<GrTextureContext> GrDrawingManager::makeTextureContext(sk_sp<GrSurfaceProxy> sProxy, |
| 667 | sk_sp<SkColorSpace> colorSpace) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 668 | if (this->wasAbandoned() || !sProxy->asTextureProxy()) { |
| 669 | return nullptr; |
| 670 | } |
| 671 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 672 | // 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] | 673 | // by, including internal usage. |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 674 | if (!SkSurface_Gpu::Valid(fContext->contextPriv().caps(), sProxy->config(), colorSpace.get())) { |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 675 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
| 676 | return nullptr; |
| 677 | } |
| 678 | |
Robert Phillips | 383c418 | 2018-02-07 12:47:44 -0500 | [diff] [blame] | 679 | // GrTextureRenderTargets should always be using a GrRenderTargetContext |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 680 | SkASSERT(!sProxy->asRenderTargetProxy()); |
| 681 | |
| 682 | sk_sp<GrTextureProxy> textureProxy(sk_ref_sp(sProxy->asTextureProxy())); |
| 683 | |
| 684 | return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy), |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 685 | std::move(colorSpace), |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 686 | fContext->contextPriv().getAuditTrail(), |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 687 | fSingleOwner)); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 688 | } |