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