robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
bsalomon | 5eb41fd | 2016-09-06 13:49:32 -0700 | [diff] [blame] | 8 | #include "GrDrawingManager.h" |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 9 | |
| 10 | #include "GrContext.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 11 | #include "GrGpu.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 12 | #include "GrOnFlushResourceProvider.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetContext.h" |
| 14 | #include "GrPathRenderingRenderTargetContext.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetProxy.h" |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 16 | #include "GrResourceProvider.h" |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 17 | #include "GrSoftwarePathRenderer.h" |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 18 | #include "GrSurfacePriv.h" |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 19 | #include "GrSurfaceProxyPriv.h" |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 20 | #include "GrTextureContext.h" |
| 21 | #include "GrTextureOpList.h" |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 22 | #include "SkSurface_Gpu.h" |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 23 | #include "SkTTopoSort.h" |
| 24 | |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 25 | #include "GrTracing.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 26 | #include "text/GrAtlasTextContext.h" |
| 27 | #include "text/GrStencilAndCoverTextContext.h" |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 28 | |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 29 | void GrDrawingManager::cleanup() { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 30 | for (int i = 0; i < fOpLists.count(); ++i) { |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 31 | // no opList should receive a new command after this |
| 32 | fOpLists[i]->makeClosed(*fContext->caps()); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 33 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 34 | // 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] | 35 | // after a cleanup. |
| 36 | // MDB TODO: is this still true? |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 37 | fOpLists[i]->reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 40 | fOpLists.reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 41 | |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 42 | delete fPathRendererChain; |
| 43 | fPathRendererChain = nullptr; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 44 | SkSafeSetNull(fSoftwarePathRenderer); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | GrDrawingManager::~GrDrawingManager() { |
| 48 | this->cleanup(); |
| 49 | } |
| 50 | |
| 51 | void GrDrawingManager::abandon() { |
| 52 | fAbandoned = true; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 53 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 54 | fOpLists[i]->abandonGpuResources(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 55 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 56 | this->cleanup(); |
| 57 | } |
| 58 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 59 | void GrDrawingManager::freeGpuResources() { |
| 60 | // a path renderer may be holding onto resources |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 61 | delete fPathRendererChain; |
| 62 | fPathRendererChain = nullptr; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 63 | SkSafeSetNull(fSoftwarePathRenderer); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 64 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 65 | fOpLists[i]->freeGpuResources(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 66 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 67 | } |
| 68 | |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 69 | void GrDrawingManager::reset() { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 70 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 71 | fOpLists[i]->reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 72 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 73 | fFlushState.reset(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 76 | gr_instanced::OpAllocator* GrDrawingManager::instancingAllocator() { |
| 77 | if (fInstancingAllocator) { |
| 78 | return fInstancingAllocator.get(); |
| 79 | } |
| 80 | |
| 81 | fInstancingAllocator = fContext->getGpu()->createInstancedRenderingAllocator(); |
| 82 | return fInstancingAllocator.get(); |
| 83 | } |
| 84 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 85 | // MDB TODO: make use of the 'proxy' parameter. |
Mike Reed | 8724b46 | 2017-07-22 17:33:48 +0000 | [diff] [blame] | 86 | void GrDrawingManager::internalFlush(GrSurfaceProxy*, GrResourceCache::FlushType type) { |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 87 | GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "internalFlush", fContext); |
| 88 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 89 | if (fFlushing || this->wasAbandoned()) { |
Mike Reed | 8724b46 | 2017-07-22 17:33:48 +0000 | [diff] [blame] | 90 | return; |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 91 | } |
| 92 | fFlushing = true; |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 93 | bool flushed = false; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 94 | |
| 95 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 96 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 97 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 98 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 99 | // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again. |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 100 | fOpLists[i]->makeClosed(*fContext->caps()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Robert Phillips | a4c93ac | 2017-05-18 11:40:04 -0400 | [diff] [blame] | 103 | #ifdef SK_DEBUG |
| 104 | // This block checks for any unnecessary splits in the opLists. If two sequential opLists |
| 105 | // share the same backing GrSurfaceProxy it means the opList was artificially split. |
| 106 | if (fOpLists.count()) { |
| 107 | GrRenderTargetOpList* prevOpList = fOpLists[0]->asRenderTargetOpList(); |
| 108 | for (int i = 1; i < fOpLists.count(); ++i) { |
| 109 | GrRenderTargetOpList* curOpList = fOpLists[i]->asRenderTargetOpList(); |
| 110 | |
| 111 | if (prevOpList && curOpList) { |
| 112 | SkASSERT(prevOpList->fTarget.get() != curOpList->fTarget.get()); |
| 113 | } |
| 114 | |
| 115 | prevOpList = curOpList; |
| 116 | } |
| 117 | } |
| 118 | #endif |
| 119 | |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 120 | #ifdef ENABLE_MDB |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 121 | SkDEBUGCODE(bool result =) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 122 | SkTTopoSort<GrOpList, GrOpList::TopoSortTraits>(&fOpLists); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 123 | SkASSERT(result); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 124 | #endif |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 125 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 126 | GrOnFlushResourceProvider onFlushProvider(this); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 127 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 128 | if (!fOnFlushCBObjects.empty()) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 129 | // MDB TODO: pre-MDB '1' is the correct pre-allocated size. Post-MDB it will need |
| 130 | // to be larger. |
| 131 | SkAutoSTArray<1, uint32_t> opListIds(fOpLists.count()); |
| 132 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 133 | opListIds[i] = fOpLists[i]->uniqueID(); |
| 134 | } |
| 135 | |
| 136 | SkSTArray<1, sk_sp<GrRenderTargetContext>> renderTargetContexts; |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 137 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
| 138 | onFlushCBObject->preFlush(&onFlushProvider, |
| 139 | opListIds.get(), opListIds.count(), |
| 140 | &renderTargetContexts); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 141 | if (!renderTargetContexts.count()) { |
| 142 | continue; // This is fine. No atlases of this type are required for this flush |
| 143 | } |
| 144 | |
| 145 | for (int j = 0; j < renderTargetContexts.count(); ++j) { |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 146 | GrOpList* opList = renderTargetContexts[j]->getOpList(); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 147 | if (!opList) { |
| 148 | continue; // Odd - but not a big deal |
| 149 | } |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 150 | opList->makeClosed(*fContext->caps()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 151 | opList->prepareOps(&fFlushState); |
| 152 | if (!opList->executeOps(&fFlushState)) { |
| 153 | continue; // This is bad |
| 154 | } |
| 155 | } |
| 156 | renderTargetContexts.reset(); |
| 157 | } |
| 158 | } |
| 159 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 160 | #if 0 |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 161 | // Enable this to print out verbose GrOp information |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 162 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 163 | SkDEBUGCODE(fOpLists[i]->dump();) |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 164 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 165 | #endif |
| 166 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 167 | for (int i = 0; i < fOpLists.count(); ++i) { |
| 168 | if (!fOpLists[i]->instantiate(fContext->resourceProvider())) { |
| 169 | fOpLists[i] = nullptr; |
| 170 | continue; |
| 171 | } |
| 172 | |
| 173 | fOpLists[i]->prepareOps(&fFlushState); |
| 174 | } |
| 175 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 176 | // Upload all data to the GPU |
| 177 | fFlushState.preIssueDraws(); |
| 178 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 179 | for (int i = 0; i < fOpLists.count(); ++i) { |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 180 | if (!fOpLists[i]) { |
| 181 | continue; |
| 182 | } |
| 183 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 184 | if (fOpLists[i]->executeOps(&fFlushState)) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 185 | flushed = true; |
| 186 | } |
Robert Phillips | 18e9484 | 2017-05-15 13:06:44 -0400 | [diff] [blame] | 187 | fOpLists[i]->reset(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 188 | } |
Robert Phillips | 18e9484 | 2017-05-15 13:06:44 -0400 | [diff] [blame] | 189 | fOpLists.reset(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 190 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 191 | SkASSERT(fFlushState.nextDrawToken() == fFlushState.nextTokenToFlush()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 192 | |
Mike Reed | 8724b46 | 2017-07-22 17:33:48 +0000 | [diff] [blame] | 193 | fContext->getGpu()->finishFlush(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 194 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 195 | fFlushState.reset(); |
robertphillips | ee843b2 | 2016-10-04 05:30:20 -0700 | [diff] [blame] | 196 | // We always have to notify the cache when it requested a flush so it can reset its state. |
| 197 | if (flushed || type == GrResourceCache::FlushType::kCacheRequested) { |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 198 | fContext->getResourceCache()->notifyFlushOccurred(type); |
| 199 | } |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 200 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
| 201 | onFlushCBObject->postFlush(); |
| 202 | } |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 203 | fFlushing = false; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Mike Reed | 8724b46 | 2017-07-22 17:33:48 +0000 | [diff] [blame] | 206 | void GrDrawingManager::prepareSurfaceForExternalIO(GrSurfaceProxy* proxy) { |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 207 | if (this->wasAbandoned()) { |
Mike Reed | 8724b46 | 2017-07-22 17:33:48 +0000 | [diff] [blame] | 208 | return; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 209 | } |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 210 | SkASSERT(proxy); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 211 | |
Mike Reed | 8724b46 | 2017-07-22 17:33:48 +0000 | [diff] [blame] | 212 | if (proxy->priv().hasPendingIO()) { |
| 213 | this->flush(proxy); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 216 | if (!proxy->instantiate(fContext->resourceProvider())) { |
Mike Reed | 8724b46 | 2017-07-22 17:33:48 +0000 | [diff] [blame] | 217 | return; |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 220 | GrSurface* surface = proxy->priv().peekSurface(); |
| 221 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 222 | if (fContext->getGpu() && surface->asRenderTarget()) { |
| 223 | fContext->getGpu()->resolveRenderTarget(surface->asRenderTarget()); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 227 | void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 228 | fOnFlushCBObjects.push_back(onFlushCBObject); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 229 | } |
| 230 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 231 | sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(GrRenderTargetProxy* rtp, |
| 232 | bool managedOpList) { |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 233 | SkASSERT(fContext); |
| 234 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 235 | // This is a temporary fix for the partial-MDB world. In that world we're not reordering |
| 236 | // so ops that (in the single opList world) would've just glommed onto the end of the single |
| 237 | // opList but referred to a far earlier RT need to appear in their own opList. |
| 238 | if (!fOpLists.empty()) { |
| 239 | fOpLists.back()->makeClosed(*fContext->caps()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 240 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 241 | |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 242 | sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(rtp, |
| 243 | fContext->getGpu(), |
Robert Phillips | 8185f59 | 2017-04-26 08:31:08 -0400 | [diff] [blame] | 244 | fContext->getAuditTrail())); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 245 | SkASSERT(rtp->getLastOpList() == opList.get()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 246 | |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 247 | if (managedOpList) { |
| 248 | fOpLists.push_back() = opList; |
| 249 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 250 | |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 251 | return opList; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 254 | sk_sp<GrTextureOpList> GrDrawingManager::newTextureOpList(GrTextureProxy* textureProxy) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 255 | SkASSERT(fContext); |
| 256 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 257 | // This is a temporary fix for the partial-MDB world. In that world we're not reordering |
| 258 | // so ops that (in the single opList world) would've just glommed onto the end of the single |
| 259 | // opList but referred to a far earlier RT need to appear in their own opList. |
| 260 | if (!fOpLists.empty()) { |
| 261 | fOpLists.back()->makeClosed(*fContext->caps()); |
| 262 | } |
| 263 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 264 | sk_sp<GrTextureOpList> opList(new GrTextureOpList(fContext->resourceProvider(), |
| 265 | textureProxy, |
| 266 | fContext->getAuditTrail())); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 267 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 268 | SkASSERT(textureProxy->getLastOpList() == opList.get()); |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 269 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 270 | fOpLists.push_back() = opList; |
| 271 | |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 272 | return opList; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 273 | } |
| 274 | |
brianosman | 86e7626 | 2016-08-11 12:17:31 -0700 | [diff] [blame] | 275 | GrAtlasTextContext* GrDrawingManager::getAtlasTextContext() { |
| 276 | if (!fAtlasTextContext) { |
| 277 | fAtlasTextContext.reset(GrAtlasTextContext::Create()); |
| 278 | } |
| 279 | |
| 280 | return fAtlasTextContext.get(); |
| 281 | } |
| 282 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 283 | /* |
| 284 | * This method finds a path renderer that can draw the specified path on |
| 285 | * the provided target. |
| 286 | * Due to its expense, the software path renderer has split out so it can |
| 287 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 288 | */ |
| 289 | GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 290 | bool allowSW, |
| 291 | GrPathRendererChain::DrawType drawType, |
| 292 | GrPathRenderer::StencilSupport* stencilSupport) { |
| 293 | |
| 294 | if (!fPathRendererChain) { |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 295 | fPathRendererChain = new GrPathRendererChain(fContext, fOptionsForPathRendererChain); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport); |
| 299 | if (!pr && allowSW) { |
| 300 | if (!fSoftwarePathRenderer) { |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 301 | fSoftwarePathRenderer = |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 302 | new GrSoftwarePathRenderer(fContext->resourceProvider(), |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 303 | fOptionsForPathRendererChain.fAllowPathMaskCaching); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 304 | } |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 305 | if (fSoftwarePathRenderer->canDrawPath(args)) { |
| 306 | pr = fSoftwarePathRenderer; |
| 307 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return pr; |
| 311 | } |
| 312 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 313 | sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext( |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 314 | sk_sp<GrSurfaceProxy> sProxy, |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 315 | sk_sp<SkColorSpace> colorSpace, |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 316 | const SkSurfaceProps* surfaceProps, |
| 317 | bool managedOpList) { |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 318 | if (this->wasAbandoned() || !sProxy->asRenderTargetProxy()) { |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 319 | return nullptr; |
| 320 | } |
| 321 | |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 322 | // SkSurface catches bad color space usage at creation. This check handles anything that slips |
| 323 | // by, including internal usage. We allow a null color space here, for read/write pixels and |
| 324 | // other special code paths. If a color space is provided, though, enforce all other rules. |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 325 | if (colorSpace && !SkSurface_Gpu::Valid(fContext, sProxy->config(), colorSpace.get())) { |
brianosman | a9c3c6a | 2016-09-29 10:08:36 -0700 | [diff] [blame] | 326 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 327 | return nullptr; |
| 328 | } |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 329 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 330 | sk_sp<GrRenderTargetProxy> rtp(sk_ref_sp(sProxy->asRenderTargetProxy())); |
| 331 | |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 332 | bool useDIF = false; |
| 333 | if (surfaceProps) { |
| 334 | useDIF = surfaceProps->isUseDeviceIndependentFonts(); |
| 335 | } |
| 336 | |
| 337 | if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() && |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 338 | GrFSAAType::kNone != rtp->fsaaType()) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 339 | // TODO: defer stencil buffer attachment for PathRenderingDrawContext |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 340 | if (!rtp->instantiate(fContext->resourceProvider())) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 341 | return nullptr; |
| 342 | } |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 343 | GrRenderTarget* rt = rtp->priv().peekRenderTarget(); |
| 344 | |
| 345 | GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 346 | if (sb) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 347 | return sk_sp<GrRenderTargetContext>(new GrPathRenderingRenderTargetContext( |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 348 | fContext, this, std::move(rtp), |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 349 | std::move(colorSpace), surfaceProps, |
robertphillips | 6c7e325 | 2016-04-27 10:47:51 -0700 | [diff] [blame] | 350 | fContext->getAuditTrail(), fSingleOwner)); |
joshualitt | 96880d9 | 2016-02-16 10:36:53 -0800 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 354 | return sk_sp<GrRenderTargetContext>(new GrRenderTargetContext(fContext, this, std::move(rtp), |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 355 | std::move(colorSpace), |
| 356 | surfaceProps, |
| 357 | fContext->getAuditTrail(), |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 358 | fSingleOwner, managedOpList)); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 359 | } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 360 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 361 | sk_sp<GrTextureContext> GrDrawingManager::makeTextureContext(sk_sp<GrSurfaceProxy> sProxy, |
| 362 | sk_sp<SkColorSpace> colorSpace) { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 363 | if (this->wasAbandoned() || !sProxy->asTextureProxy()) { |
| 364 | return nullptr; |
| 365 | } |
| 366 | |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 367 | // SkSurface catches bad color space usage at creation. This check handles anything that slips |
| 368 | // by, including internal usage. We allow a null color space here, for read/write pixels and |
| 369 | // other special code paths. If a color space is provided, though, enforce all other rules. |
| 370 | if (colorSpace && !SkSurface_Gpu::Valid(fContext, sProxy->config(), colorSpace.get())) { |
| 371 | SkDEBUGFAIL("Invalid config and colorspace combination"); |
| 372 | return nullptr; |
| 373 | } |
| 374 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 375 | // GrTextureRenderTargets should always be using GrRenderTargetContext |
| 376 | SkASSERT(!sProxy->asRenderTargetProxy()); |
| 377 | |
| 378 | sk_sp<GrTextureProxy> textureProxy(sk_ref_sp(sProxy->asTextureProxy())); |
| 379 | |
| 380 | return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy), |
Robert Phillips | 2c86249 | 2017-01-18 10:08:39 -0500 | [diff] [blame] | 381 | std::move(colorSpace), |
| 382 | fContext->getAuditTrail(), |
| 383 | fSingleOwner)); |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 384 | } |