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