Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 8 | #include "GrOnFlushResourceProvider.h" |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 9 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 10 | #include "GrContextPriv.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 11 | #include "GrDrawingManager.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 12 | #include "GrProxyProvider.h" |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 13 | #include "GrRecordingContext.h" |
| 14 | #include "GrRecordingContextPriv.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetContext.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 16 | #include "GrSurfaceProxy.h" |
| 17 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 18 | sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext( |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 19 | sk_sp<GrSurfaceProxy> proxy, |
| 20 | sk_sp<SkColorSpace> colorSpace, |
| 21 | const SkSurfaceProps* props) { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 22 | // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator |
| 23 | // we have to manually ensure it is allocated here. The proxy had best have been created |
| 24 | // with the kNoPendingIO flag! |
| 25 | if (!this->instatiateProxy(proxy.get())) { |
| 26 | return nullptr; |
| 27 | } |
| 28 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 29 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 30 | fDrawingMgr->makeRenderTargetContext(std::move(proxy), |
| 31 | std::move(colorSpace), |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 32 | props, false)); |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 33 | |
| 34 | if (!renderTargetContext) { |
| 35 | return nullptr; |
| 36 | } |
| 37 | |
| 38 | renderTargetContext->discard(); |
| 39 | |
| 40 | return renderTargetContext; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 43 | bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, |
| 44 | GrTextureProxy* proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 45 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 46 | return proxyProvider->assignUniqueKeyToProxy(key, proxy); |
| 47 | } |
| 48 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 49 | void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 50 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 51 | proxyProvider->removeUniqueKeyFromProxy(proxy); |
| 52 | } |
| 53 | |
| 54 | void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 55 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 56 | proxyProvider->processInvalidUniqueKey(key, nullptr, |
| 57 | GrProxyProvider::InvalidateGPUResource::kYes); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey( |
| 61 | const GrUniqueKey& key, GrSurfaceOrigin origin) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 62 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 63 | return proxyProvider->findOrCreateProxyByUniqueKey(key, origin); |
| 64 | } |
| 65 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 66 | bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 67 | // TODO: this class should probably just get a GrDirectContext |
| 68 | auto direct = fDrawingMgr->getContext()->priv().asDirectContext(); |
| 69 | if (!direct) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | auto resourceProvider = direct->priv().resourceProvider(); |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 74 | |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 75 | if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) { |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 76 | // DDL TODO: Decide if we ever plan to have these proxies use the GrDeinstantiateTracker |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 77 | // to support unistantiating them at the end of a flush. |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 78 | return proxy->priv().doLazyInstantiation(resourceProvider); |
| 79 | } |
| 80 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 81 | return proxy->instantiate(resourceProvider); |
| 82 | } |
| 83 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 84 | sk_sp<GrGpuBuffer> GrOnFlushResourceProvider::makeBuffer(GrGpuBufferType intendedType, size_t size, |
| 85 | const void* data) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 86 | // TODO: this class should probably just get a GrDirectContext |
| 87 | auto direct = fDrawingMgr->getContext()->priv().asDirectContext(); |
| 88 | if (!direct) { |
| 89 | return nullptr; |
| 90 | } |
| 91 | |
| 92 | auto resourceProvider = direct->priv().resourceProvider(); |
| 93 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 94 | return sk_sp<GrGpuBuffer>( |
| 95 | resourceProvider->createBuffer(size, intendedType, kDynamic_GrAccessPattern, data)); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 98 | sk_sp<const GrGpuBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer( |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 99 | GrGpuBufferType intendedType, size_t size, const void* data, const GrUniqueKey& key) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 100 | // TODO: class should probably just get a GrDirectContext |
| 101 | auto direct = fDrawingMgr->getContext()->priv().asDirectContext(); |
| 102 | if (!direct) { |
| 103 | return nullptr; |
| 104 | } |
| 105 | |
| 106 | auto resourceProvider = direct->priv().resourceProvider(); |
| 107 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 108 | sk_sp<const GrGpuBuffer> buffer = |
| 109 | resourceProvider->findOrMakeStaticBuffer(intendedType, size, data, key); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 110 | // Static buffers should never have pending IO. |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 111 | SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly()); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 112 | return buffer; |
| 113 | } |
| 114 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 115 | uint32_t GrOnFlushResourceProvider::contextID() const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 116 | return fDrawingMgr->getContext()->priv().contextID(); |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 119 | const GrCaps* GrOnFlushResourceProvider::caps() const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 120 | return fDrawingMgr->getContext()->priv().caps(); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 121 | } |