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