blob: 013c624efa3c0961e9feb840ca21f427a0fa9609 [file] [log] [blame]
robertphillips3dc6ae52015-10-20 09:54:32 -07001/*
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
bsalomon5eb41fd2016-09-06 13:49:32 -07008#include "GrDrawingManager.h"
bsalomonb77a9072016-09-07 10:02:04 -07009
Greg Daniel51316782017-08-02 15:10:09 +000010#include "GrBackendSemaphore.h"
bsalomonb77a9072016-09-07 10:02:04 -070011#include "GrContext.h"
Robert Phillips646e4292017-06-13 12:44:56 -040012#include "GrGpu.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040013#include "GrOnFlushResourceProvider.h"
Robert Phillips9d6c64f2017-09-14 10:56:45 -040014#include "GrOpList.h"
Brian Osman11052242016-10-27 14:47:55 -040015#include "GrRenderTargetContext.h"
16#include "GrPathRenderingRenderTargetContext.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040017#include "GrRenderTargetProxy.h"
Robert Phillipsd375dbf2017-09-14 12:45:25 -040018#include "GrResourceAllocator.h"
robertphillips3dc6ae52015-10-20 09:54:32 -070019#include "GrResourceProvider.h"
robertphillips68737822015-10-29 12:12:21 -070020#include "GrSoftwarePathRenderer.h"
Robert Phillips7ee385e2017-03-30 08:02:11 -040021#include "GrSurfaceProxyPriv.h"
Brian Osman45580d32016-11-23 09:37:01 -050022#include "GrTextureContext.h"
23#include "GrTextureOpList.h"
brianosman0e22eb82016-08-30 07:07:59 -070024#include "SkSurface_Gpu.h"
robertphillips3dc6ae52015-10-20 09:54:32 -070025#include "SkTTopoSort.h"
26
Brian Salomondcbb9d92017-07-19 10:53:20 -040027#include "GrTracing.h"
joshualitte8042922015-12-11 06:11:21 -080028#include "text/GrAtlasTextContext.h"
29#include "text/GrStencilAndCoverTextContext.h"
robertphillips498d7ac2015-10-30 10:11:30 -070030
robertphillips3dc6ae52015-10-20 09:54:32 -070031void GrDrawingManager::cleanup() {
Robert Phillipsf2361d22016-10-25 14:20:06 -040032 for (int i = 0; i < fOpLists.count(); ++i) {
Robert Phillipsee683652017-04-26 11:53:10 -040033 // no opList should receive a new command after this
34 fOpLists[i]->makeClosed(*fContext->caps());
robertphillips0dfa62c2015-11-16 06:23:31 -080035
Robert Phillipsf2361d22016-10-25 14:20:06 -040036 // We shouldn't need to do this, but it turns out some clients still hold onto opLists
Robert Phillips6cdc22c2017-05-11 16:29:14 -040037 // after a cleanup.
38 // MDB TODO: is this still true?
Robert Phillipsf2361d22016-10-25 14:20:06 -040039 fOpLists[i]->reset();
robertphillips3dc6ae52015-10-20 09:54:32 -070040 }
41
Robert Phillipsf2361d22016-10-25 14:20:06 -040042 fOpLists.reset();
robertphillips3dc6ae52015-10-20 09:54:32 -070043
robertphillips13391dd2015-10-30 05:15:11 -070044 delete fPathRendererChain;
45 fPathRendererChain = nullptr;
robertphillips68737822015-10-29 12:12:21 -070046 SkSafeSetNull(fSoftwarePathRenderer);
Jim Van Verth106b5c42017-09-26 12:45:29 -040047
48 fOnFlushCBObjects.reset();
robertphillips3dc6ae52015-10-20 09:54:32 -070049}
50
51GrDrawingManager::~GrDrawingManager() {
52 this->cleanup();
53}
54
55void GrDrawingManager::abandon() {
56 fAbandoned = true;
Robert Phillipsf2361d22016-10-25 14:20:06 -040057 for (int i = 0; i < fOpLists.count(); ++i) {
58 fOpLists[i]->abandonGpuResources();
csmartdaltona7f29642016-07-07 08:49:11 -070059 }
robertphillips3dc6ae52015-10-20 09:54:32 -070060 this->cleanup();
61}
62
robertphillips68737822015-10-29 12:12:21 -070063void GrDrawingManager::freeGpuResources() {
Jim Van Verth106b5c42017-09-26 12:45:29 -040064 for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) {
65 if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) {
66 // it's safe to just do this because we're iterating in reverse
67 fOnFlushCBObjects.removeShuffle(i);
68 }
69 }
70
robertphillips68737822015-10-29 12:12:21 -070071 // a path renderer may be holding onto resources
robertphillips13391dd2015-10-30 05:15:11 -070072 delete fPathRendererChain;
73 fPathRendererChain = nullptr;
robertphillips68737822015-10-29 12:12:21 -070074 SkSafeSetNull(fSoftwarePathRenderer);
Robert Phillipsf2361d22016-10-25 14:20:06 -040075 for (int i = 0; i < fOpLists.count(); ++i) {
76 fOpLists[i]->freeGpuResources();
csmartdaltona7f29642016-07-07 08:49:11 -070077 }
Jim Van Verth106b5c42017-09-26 12:45:29 -040078
robertphillips68737822015-10-29 12:12:21 -070079}
80
robertphillips3dc6ae52015-10-20 09:54:32 -070081void GrDrawingManager::reset() {
Robert Phillipsf2361d22016-10-25 14:20:06 -040082 for (int i = 0; i < fOpLists.count(); ++i) {
83 fOpLists[i]->reset();
robertphillips3dc6ae52015-10-20 09:54:32 -070084 }
robertphillipsa13e2022015-11-11 12:01:09 -080085 fFlushState.reset();
robertphillips3dc6ae52015-10-20 09:54:32 -070086}
87
Robert Phillipse3302df2017-04-24 07:31:02 -040088gr_instanced::OpAllocator* GrDrawingManager::instancingAllocator() {
89 if (fInstancingAllocator) {
90 return fInstancingAllocator.get();
91 }
92
93 fInstancingAllocator = fContext->getGpu()->createInstancedRenderingAllocator();
94 return fInstancingAllocator.get();
95}
96
Robert Phillips7ee385e2017-03-30 08:02:11 -040097// MDB TODO: make use of the 'proxy' parameter.
Greg Daniel51316782017-08-02 15:10:09 +000098GrSemaphoresSubmitted GrDrawingManager::internalFlush(GrSurfaceProxy*,
99 GrResourceCache::FlushType type,
100 int numSemaphores,
101 GrBackendSemaphore backendSemaphores[]) {
Brian Salomondcbb9d92017-07-19 10:53:20 -0400102 GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "internalFlush", fContext);
103
robertphillips7761d612016-05-16 09:14:53 -0700104 if (fFlushing || this->wasAbandoned()) {
Greg Daniel51316782017-08-02 15:10:09 +0000105 return GrSemaphoresSubmitted::kNo;
joshualittb8918c42015-12-18 09:59:46 -0800106 }
107 fFlushing = true;
bsalomondc438982016-08-31 11:53:49 -0700108 bool flushed = false;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400109
110 for (int i = 0; i < fOpLists.count(); ++i) {
111 // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh
112 // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed
113 // but need to be flushed anyway. Closing such GrOpLists here will mean new
114 // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again.
Robert Phillipsee683652017-04-26 11:53:10 -0400115 fOpLists[i]->makeClosed(*fContext->caps());
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400116 }
117
Robert Phillipsa4c93ac2017-05-18 11:40:04 -0400118#ifdef SK_DEBUG
119 // This block checks for any unnecessary splits in the opLists. If two sequential opLists
120 // share the same backing GrSurfaceProxy it means the opList was artificially split.
121 if (fOpLists.count()) {
122 GrRenderTargetOpList* prevOpList = fOpLists[0]->asRenderTargetOpList();
123 for (int i = 1; i < fOpLists.count(); ++i) {
124 GrRenderTargetOpList* curOpList = fOpLists[i]->asRenderTargetOpList();
125
126 if (prevOpList && curOpList) {
127 SkASSERT(prevOpList->fTarget.get() != curOpList->fTarget.get());
128 }
129
130 prevOpList = curOpList;
131 }
132 }
133#endif
134
Robert Phillips9d6c64f2017-09-14 10:56:45 -0400135#ifdef ENABLE_MDB_SORT
halcanary9d524f22016-03-29 09:03:52 -0700136 SkDEBUGCODE(bool result =)
Robert Phillipsf2361d22016-10-25 14:20:06 -0400137 SkTTopoSort<GrOpList, GrOpList::TopoSortTraits>(&fOpLists);
robertphillips3dc6ae52015-10-20 09:54:32 -0700138 SkASSERT(result);
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400139#endif
robertphillips3dc6ae52015-10-20 09:54:32 -0700140
Chris Daltonfe199b72017-05-05 11:26:15 -0400141 GrOnFlushResourceProvider onFlushProvider(this);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400142
Chris Daltonfe199b72017-05-05 11:26:15 -0400143 if (!fOnFlushCBObjects.empty()) {
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400144 // MDB TODO: pre-MDB '1' is the correct pre-allocated size. Post-MDB it will need
145 // to be larger.
146 SkAutoSTArray<1, uint32_t> opListIds(fOpLists.count());
147 for (int i = 0; i < fOpLists.count(); ++i) {
148 opListIds[i] = fOpLists[i]->uniqueID();
149 }
150
151 SkSTArray<1, sk_sp<GrRenderTargetContext>> renderTargetContexts;
Chris Daltonfe199b72017-05-05 11:26:15 -0400152 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
153 onFlushCBObject->preFlush(&onFlushProvider,
154 opListIds.get(), opListIds.count(),
155 &renderTargetContexts);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400156 if (!renderTargetContexts.count()) {
157 continue; // This is fine. No atlases of this type are required for this flush
158 }
159
160 for (int j = 0; j < renderTargetContexts.count(); ++j) {
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400161 GrOpList* opList = renderTargetContexts[j]->getOpList();
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400162 if (!opList) {
163 continue; // Odd - but not a big deal
164 }
Robert Phillipsb6deea82017-05-11 14:14:30 -0400165 opList->makeClosed(*fContext->caps());
Brian Osman407b3422017-08-22 15:01:32 -0400166 opList->prepare(&fFlushState);
167 if (!opList->execute(&fFlushState)) {
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400168 continue; // This is bad
169 }
170 }
171 renderTargetContexts.reset();
172 }
173 }
174
robertphillipsa13e2022015-11-11 12:01:09 -0800175#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500176 // Enable this to print out verbose GrOp information
Robert Phillipsf2361d22016-10-25 14:20:06 -0400177 for (int i = 0; i < fOpLists.count(); ++i) {
178 SkDEBUGCODE(fOpLists[i]->dump();)
robertphillips3dc6ae52015-10-20 09:54:32 -0700179 }
robertphillipsa13e2022015-11-11 12:01:09 -0800180#endif
181
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400182#ifdef MDB_ALLOC_RESOURCES
183 GrResourceAllocator alloc(fContext->resourceProvider());
184 for (int i = 0; i < fOpLists.count(); ++i) {
185 fOpLists[i]->gatherProxyIntervals(&alloc);
186 }
187
188 alloc.assign();
189#endif
190
Robert Phillips318c4192017-05-17 09:36:38 -0400191 for (int i = 0; i < fOpLists.count(); ++i) {
192 if (!fOpLists[i]->instantiate(fContext->resourceProvider())) {
Brian Osmane46c8d02017-08-23 16:15:22 -0400193 SkDebugf("OpList failed to instantiate.\n");
Robert Phillips318c4192017-05-17 09:36:38 -0400194 fOpLists[i] = nullptr;
195 continue;
196 }
197
Brian Osman407b3422017-08-22 15:01:32 -0400198 fOpLists[i]->prepare(&fFlushState);
Robert Phillips318c4192017-05-17 09:36:38 -0400199 }
200
robertphillipsa13e2022015-11-11 12:01:09 -0800201 // Upload all data to the GPU
202 fFlushState.preIssueDraws();
203
Robert Phillipsf2361d22016-10-25 14:20:06 -0400204 for (int i = 0; i < fOpLists.count(); ++i) {
Robert Phillips318c4192017-05-17 09:36:38 -0400205 if (!fOpLists[i]) {
206 continue;
207 }
208
Brian Osman407b3422017-08-22 15:01:32 -0400209 if (fOpLists[i]->execute(&fFlushState)) {
bsalomondc438982016-08-31 11:53:49 -0700210 flushed = true;
211 }
Robert Phillips18e94842017-05-15 13:06:44 -0400212 fOpLists[i]->reset();
robertphillipsa13e2022015-11-11 12:01:09 -0800213 }
Robert Phillips18e94842017-05-15 13:06:44 -0400214 fOpLists.reset();
robertphillipsa13e2022015-11-11 12:01:09 -0800215
bsalomon342bfc22016-04-01 06:06:20 -0700216 SkASSERT(fFlushState.nextDrawToken() == fFlushState.nextTokenToFlush());
robertphillips3dc6ae52015-10-20 09:54:32 -0700217
Greg Daniel51316782017-08-02 15:10:09 +0000218 GrSemaphoresSubmitted result = fContext->getGpu()->finishFlush(numSemaphores,
219 backendSemaphores);
robertphillipsa13e2022015-11-11 12:01:09 -0800220
robertphillipsa13e2022015-11-11 12:01:09 -0800221 fFlushState.reset();
robertphillipsee843b22016-10-04 05:30:20 -0700222 // We always have to notify the cache when it requested a flush so it can reset its state.
223 if (flushed || type == GrResourceCache::FlushType::kCacheRequested) {
bsalomonb77a9072016-09-07 10:02:04 -0700224 fContext->getResourceCache()->notifyFlushOccurred(type);
225 }
Chris Daltonfe199b72017-05-05 11:26:15 -0400226 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Jim Van Verth106b5c42017-09-26 12:45:29 -0400227 onFlushCBObject->postFlush(fFlushState.nextTokenToFlush());
Chris Daltonfe199b72017-05-05 11:26:15 -0400228 }
joshualittb8918c42015-12-18 09:59:46 -0800229 fFlushing = false;
Greg Daniel51316782017-08-02 15:10:09 +0000230
231 return result;
robertphillips3dc6ae52015-10-20 09:54:32 -0700232}
233
Greg Daniel51316782017-08-02 15:10:09 +0000234GrSemaphoresSubmitted GrDrawingManager::prepareSurfaceForExternalIO(
235 GrSurfaceProxy* proxy, int numSemaphores, GrBackendSemaphore backendSemaphores[]) {
bsalomon6a2b1942016-09-08 11:28:59 -0700236 if (this->wasAbandoned()) {
Greg Daniel51316782017-08-02 15:10:09 +0000237 return GrSemaphoresSubmitted::kNo;
bsalomon6a2b1942016-09-08 11:28:59 -0700238 }
Robert Phillips7ee385e2017-03-30 08:02:11 -0400239 SkASSERT(proxy);
bsalomon6a2b1942016-09-08 11:28:59 -0700240
Greg Daniel51316782017-08-02 15:10:09 +0000241 GrSemaphoresSubmitted result;
242 if (proxy->priv().hasPendingIO() || numSemaphores) {
243 result = this->flush(proxy, numSemaphores, backendSemaphores);
bsalomon6a2b1942016-09-08 11:28:59 -0700244 }
245
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400246 if (!proxy->instantiate(fContext->resourceProvider())) {
Greg Daniel51316782017-08-02 15:10:09 +0000247 return result;
Robert Phillips7ee385e2017-03-30 08:02:11 -0400248 }
249
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400250 GrSurface* surface = proxy->priv().peekSurface();
251
Robert Phillips7ee385e2017-03-30 08:02:11 -0400252 if (fContext->getGpu() && surface->asRenderTarget()) {
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400253 fContext->getGpu()->resolveRenderTarget(surface->asRenderTarget(), proxy->origin());
bsalomon6a2b1942016-09-08 11:28:59 -0700254 }
Greg Daniel51316782017-08-02 15:10:09 +0000255 return result;
bsalomon6a2b1942016-09-08 11:28:59 -0700256}
257
Chris Daltonfe199b72017-05-05 11:26:15 -0400258void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
259 fOnFlushCBObjects.push_back(onFlushCBObject);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400260}
261
Robert Phillips941d1442017-06-14 16:37:02 -0400262sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(GrRenderTargetProxy* rtp,
263 bool managedOpList) {
robertphillips3dc6ae52015-10-20 09:54:32 -0700264 SkASSERT(fContext);
265
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400266 // This is a temporary fix for the partial-MDB world. In that world we're not reordering
267 // so ops that (in the single opList world) would've just glommed onto the end of the single
268 // opList but referred to a far earlier RT need to appear in their own opList.
269 if (!fOpLists.empty()) {
270 fOpLists.back()->makeClosed(*fContext->caps());
robertphillips3dc6ae52015-10-20 09:54:32 -0700271 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700272
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400273 sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(rtp,
274 fContext->getGpu(),
Robert Phillips8185f592017-04-26 08:31:08 -0400275 fContext->getAuditTrail()));
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400276 SkASSERT(rtp->getLastOpList() == opList.get());
robertphillips3dc6ae52015-10-20 09:54:32 -0700277
Robert Phillips941d1442017-06-14 16:37:02 -0400278 if (managedOpList) {
279 fOpLists.push_back() = opList;
280 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700281
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400282 return opList;
robertphillips3dc6ae52015-10-20 09:54:32 -0700283}
284
Robert Phillipsb6deea82017-05-11 14:14:30 -0400285sk_sp<GrTextureOpList> GrDrawingManager::newTextureOpList(GrTextureProxy* textureProxy) {
Brian Osman45580d32016-11-23 09:37:01 -0500286 SkASSERT(fContext);
287
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400288 // This is a temporary fix for the partial-MDB world. In that world we're not reordering
289 // so ops that (in the single opList world) would've just glommed onto the end of the single
290 // opList but referred to a far earlier RT need to appear in their own opList.
291 if (!fOpLists.empty()) {
292 fOpLists.back()->makeClosed(*fContext->caps());
293 }
294
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400295 sk_sp<GrTextureOpList> opList(new GrTextureOpList(fContext->resourceProvider(),
296 textureProxy,
297 fContext->getAuditTrail()));
Brian Osman45580d32016-11-23 09:37:01 -0500298
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400299 SkASSERT(textureProxy->getLastOpList() == opList.get());
Robert Phillips4a395042017-04-24 16:27:17 +0000300
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400301 fOpLists.push_back() = opList;
302
Robert Phillips4a395042017-04-24 16:27:17 +0000303 return opList;
Brian Osman45580d32016-11-23 09:37:01 -0500304}
305
brianosman86e76262016-08-11 12:17:31 -0700306GrAtlasTextContext* GrDrawingManager::getAtlasTextContext() {
307 if (!fAtlasTextContext) {
308 fAtlasTextContext.reset(GrAtlasTextContext::Create());
309 }
310
311 return fAtlasTextContext.get();
312}
313
robertphillips68737822015-10-29 12:12:21 -0700314/*
315 * This method finds a path renderer that can draw the specified path on
316 * the provided target.
317 * Due to its expense, the software path renderer has split out so it can
318 * can be individually allowed/disallowed via the "allowSW" boolean.
319 */
320GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
321 bool allowSW,
322 GrPathRendererChain::DrawType drawType,
323 GrPathRenderer::StencilSupport* stencilSupport) {
324
325 if (!fPathRendererChain) {
bsalomon6b2552f2016-09-15 13:50:26 -0700326 fPathRendererChain = new GrPathRendererChain(fContext, fOptionsForPathRendererChain);
robertphillips68737822015-10-29 12:12:21 -0700327 }
328
329 GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
330 if (!pr && allowSW) {
331 if (!fSoftwarePathRenderer) {
bsalomon39ef7fb2016-09-21 11:16:05 -0700332 fSoftwarePathRenderer =
Brian Osman32342f02017-03-04 08:12:46 -0500333 new GrSoftwarePathRenderer(fContext->resourceProvider(),
bsalomon39ef7fb2016-09-21 11:16:05 -0700334 fOptionsForPathRendererChain.fAllowPathMaskCaching);
robertphillips68737822015-10-29 12:12:21 -0700335 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600336 if (GrPathRenderer::CanDrawPath::kNo != fSoftwarePathRenderer->canDrawPath(args)) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500337 pr = fSoftwarePathRenderer;
338 }
robertphillips68737822015-10-29 12:12:21 -0700339 }
340
341 return pr;
342}
343
Brian Osman11052242016-10-27 14:47:55 -0400344sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext(
Robert Phillips37430132016-11-09 06:50:43 -0500345 sk_sp<GrSurfaceProxy> sProxy,
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400346 sk_sp<SkColorSpace> colorSpace,
Robert Phillips941d1442017-06-14 16:37:02 -0400347 const SkSurfaceProps* surfaceProps,
348 bool managedOpList) {
Robert Phillips37430132016-11-09 06:50:43 -0500349 if (this->wasAbandoned() || !sProxy->asRenderTargetProxy()) {
robertphillips3dc6ae52015-10-20 09:54:32 -0700350 return nullptr;
351 }
352
brianosman0e22eb82016-08-30 07:07:59 -0700353 // SkSurface catches bad color space usage at creation. This check handles anything that slips
354 // by, including internal usage. We allow a null color space here, for read/write pixels and
355 // other special code paths. If a color space is provided, though, enforce all other rules.
Robert Phillips2c862492017-01-18 10:08:39 -0500356 if (colorSpace && !SkSurface_Gpu::Valid(fContext, sProxy->config(), colorSpace.get())) {
brianosmana9c3c6a2016-09-29 10:08:36 -0700357 SkDEBUGFAIL("Invalid config and colorspace combination");
brianosman0e22eb82016-08-30 07:07:59 -0700358 return nullptr;
359 }
joshualitt96880d92016-02-16 10:36:53 -0800360
Robert Phillips2c862492017-01-18 10:08:39 -0500361 sk_sp<GrRenderTargetProxy> rtp(sk_ref_sp(sProxy->asRenderTargetProxy()));
362
joshualitt96880d92016-02-16 10:36:53 -0800363 bool useDIF = false;
364 if (surfaceProps) {
365 useDIF = surfaceProps->isUseDeviceIndependentFonts();
366 }
367
368 if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
Brian Salomon7c8460e2017-05-12 11:36:10 -0400369 GrFSAAType::kNone != rtp->fsaaType()) {
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400370
Robert Phillipsc0192e32017-09-21 12:00:26 -0400371 return sk_sp<GrRenderTargetContext>(new GrPathRenderingRenderTargetContext(
372 fContext, this, std::move(rtp),
373 std::move(colorSpace), surfaceProps,
374 fContext->getAuditTrail(), fSingleOwner));
joshualitt96880d92016-02-16 10:36:53 -0800375 }
376
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400377 return sk_sp<GrRenderTargetContext>(new GrRenderTargetContext(fContext, this, std::move(rtp),
Brian Osman11052242016-10-27 14:47:55 -0400378 std::move(colorSpace),
379 surfaceProps,
380 fContext->getAuditTrail(),
Robert Phillips941d1442017-06-14 16:37:02 -0400381 fSingleOwner, managedOpList));
robertphillips3dc6ae52015-10-20 09:54:32 -0700382}
Brian Osman45580d32016-11-23 09:37:01 -0500383
Robert Phillips2c862492017-01-18 10:08:39 -0500384sk_sp<GrTextureContext> GrDrawingManager::makeTextureContext(sk_sp<GrSurfaceProxy> sProxy,
385 sk_sp<SkColorSpace> colorSpace) {
Brian Osman45580d32016-11-23 09:37:01 -0500386 if (this->wasAbandoned() || !sProxy->asTextureProxy()) {
387 return nullptr;
388 }
389
Robert Phillips2c862492017-01-18 10:08:39 -0500390 // SkSurface catches bad color space usage at creation. This check handles anything that slips
391 // by, including internal usage. We allow a null color space here, for read/write pixels and
392 // other special code paths. If a color space is provided, though, enforce all other rules.
393 if (colorSpace && !SkSurface_Gpu::Valid(fContext, sProxy->config(), colorSpace.get())) {
394 SkDEBUGFAIL("Invalid config and colorspace combination");
395 return nullptr;
396 }
397
Brian Osman45580d32016-11-23 09:37:01 -0500398 // GrTextureRenderTargets should always be using GrRenderTargetContext
399 SkASSERT(!sProxy->asRenderTargetProxy());
400
401 sk_sp<GrTextureProxy> textureProxy(sk_ref_sp(sProxy->asTextureProxy()));
402
403 return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy),
Robert Phillips2c862492017-01-18 10:08:39 -0500404 std::move(colorSpace),
405 fContext->getAuditTrail(),
406 fSingleOwner));
Brian Osman45580d32016-11-23 09:37:01 -0500407}