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" |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 9 | #include "GrContext.h" |
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" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetContext.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 14 | #include "GrSurfaceProxy.h" |
| 15 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 16 | sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext( |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 17 | sk_sp<GrSurfaceProxy> proxy, |
| 18 | sk_sp<SkColorSpace> colorSpace, |
| 19 | const SkSurfaceProps* props) { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 20 | // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator |
| 21 | // we have to manually ensure it is allocated here. The proxy had best have been created |
| 22 | // with the kNoPendingIO flag! |
| 23 | if (!this->instatiateProxy(proxy.get())) { |
| 24 | return nullptr; |
| 25 | } |
| 26 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 27 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 28 | fDrawingMgr->makeRenderTargetContext(std::move(proxy), |
| 29 | std::move(colorSpace), |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 30 | props, false)); |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 31 | |
| 32 | if (!renderTargetContext) { |
| 33 | return nullptr; |
| 34 | } |
| 35 | |
| 36 | renderTargetContext->discard(); |
| 37 | |
| 38 | return renderTargetContext; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 39 | } |
| 40 | |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 41 | bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, |
| 42 | GrTextureProxy* proxy) { |
| 43 | auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider(); |
| 44 | return proxyProvider->assignUniqueKeyToProxy(key, proxy); |
| 45 | } |
| 46 | |
| 47 | void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(const GrUniqueKey& key, |
| 48 | GrTextureProxy* proxy) { |
| 49 | auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider(); |
| 50 | proxyProvider->removeUniqueKeyFromProxy(key, proxy); |
| 51 | } |
| 52 | |
| 53 | sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey( |
| 54 | const GrUniqueKey& key, GrSurfaceOrigin origin) { |
| 55 | auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider(); |
| 56 | return proxyProvider->findOrCreateProxyByUniqueKey(key, origin); |
| 57 | } |
| 58 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 59 | bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) { |
| 60 | auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider(); |
| 61 | |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 62 | if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 63 | // DDL TODO: Decide if we ever plan to have these proxies use the GrUninstantiateTracker |
| 64 | // to support unistantiating them at the end of a flush. |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 65 | return proxy->priv().doLazyInstantiation(resourceProvider); |
| 66 | } |
| 67 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 68 | return proxy->instantiate(resourceProvider); |
| 69 | } |
| 70 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 71 | sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, size_t size, |
| 72 | const void* data) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 73 | auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider(); |
| 74 | return sk_sp<GrBuffer>(resourceProvider->createBuffer(size, intendedType, |
| 75 | kDynamic_GrAccessPattern, |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 76 | GrResourceProvider::Flags::kNoPendingIO, |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 77 | data)); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 80 | sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType, |
| 81 | size_t size, |
| 82 | const void* data, |
| 83 | const GrUniqueKey& key) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 84 | auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider(); |
| 85 | sk_sp<const GrBuffer> buffer = resourceProvider->findOrMakeStaticBuffer(intendedType, size, |
| 86 | data, key); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 87 | // Static buffers should never have pending IO. |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 88 | SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly()); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 89 | return buffer; |
| 90 | } |
| 91 | |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 92 | uint32_t GrOnFlushResourceProvider::contextUniqueID() const { |
| 93 | return fDrawingMgr->getContext()->uniqueID(); |
| 94 | } |
| 95 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 96 | const GrCaps* GrOnFlushResourceProvider::caps() const { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 97 | return fDrawingMgr->getContext()->contextPriv().caps(); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 98 | } |