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 | eb35f4d | 2017-03-21 07:56:47 -0400 | [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 | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 13 | #include "GrSurfaceProxy.h" |
| 14 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 15 | sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext( |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 16 | const GrSurfaceDesc& desc, |
| 17 | sk_sp<SkColorSpace> colorSpace, |
| 18 | const SkSurfaceProps* props) { |
| 19 | GrSurfaceDesc tmpDesc = desc; |
| 20 | tmpDesc.fFlags |= kRenderTarget_GrSurfaceFlag; |
| 21 | |
| 22 | // Because this is being allocated at the start of a flush we must ensure the proxy |
| 23 | // will, when instantiated, have no pending IO. |
| 24 | // TODO: fold the kNoPendingIO_Flag into GrSurfaceFlags? |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 25 | GrProxyProvider* proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider(); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 26 | sk_sp<GrSurfaceProxy> proxy = proxyProvider->createProxy(tmpDesc, SkBackingFit::kExact, |
| 27 | SkBudgeted::kYes, |
| 28 | GrResourceProvider::kNoPendingIO_Flag); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 29 | if (!proxy->asRenderTargetProxy()) { |
| 30 | return nullptr; |
| 31 | } |
| 32 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 33 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 34 | fDrawingMgr->makeRenderTargetContext(std::move(proxy), |
| 35 | std::move(colorSpace), |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 36 | props, false)); |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 37 | |
| 38 | if (!renderTargetContext) { |
| 39 | return nullptr; |
| 40 | } |
| 41 | |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 42 | // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator |
| 43 | // we have to manually ensure it is allocated here. The proxy had best have been created |
| 44 | // with the kNoPendingIO flag! |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 45 | if (!renderTargetContext->asSurfaceProxy()->instantiate( |
| 46 | fDrawingMgr->getContext()->resourceProvider())) { |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 47 | return nullptr; |
| 48 | } |
| 49 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 50 | renderTargetContext->discard(); |
| 51 | |
| 52 | return renderTargetContext; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // TODO: we only need this entry point as long as we have to pre-allocate the atlas. |
| 56 | // Remove it ASAP. |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 57 | sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext( |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 58 | sk_sp<GrSurfaceProxy> proxy, |
| 59 | sk_sp<SkColorSpace> colorSpace, |
| 60 | const SkSurfaceProps* props) { |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 61 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 62 | fDrawingMgr->makeRenderTargetContext(std::move(proxy), |
| 63 | std::move(colorSpace), |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 64 | props, false)); |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 65 | |
| 66 | if (!renderTargetContext) { |
| 67 | return nullptr; |
| 68 | } |
| 69 | |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 70 | // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator |
| 71 | // we have to manually ensure it is allocated here. The proxy had best have been created |
| 72 | // with the kNoPendingIO flag! |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 73 | if (!renderTargetContext->asSurfaceProxy()->instantiate( |
| 74 | fDrawingMgr->getContext()->resourceProvider())) { |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 75 | return nullptr; |
| 76 | } |
| 77 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 78 | renderTargetContext->discard(); |
| 79 | |
| 80 | return renderTargetContext; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 81 | } |
| 82 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 83 | sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, size_t size, |
| 84 | const void* data) { |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 85 | GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider(); |
| 86 | return sk_sp<GrBuffer>(rp->createBuffer(size, intendedType, kDynamic_GrAccessPattern, |
| 87 | GrResourceProvider::kNoPendingIO_Flag, |
| 88 | data)); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 91 | sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType, |
| 92 | size_t size, |
| 93 | const void* data, |
| 94 | const GrUniqueKey& key) { |
Hal Canary | be46e24 | 2018-01-16 18:33:07 +0000 | [diff] [blame^] | 95 | GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider(); |
| 96 | sk_sp<const GrBuffer> buffer = rp->findOrMakeStaticBuffer(intendedType, size, data, key); |
Chris Dalton | 5d2de08 | 2017-12-19 10:40:23 -0700 | [diff] [blame] | 97 | // Static buffers should never have pending IO. |
| 98 | SkASSERT(!buffer->resourcePriv().hasPendingIO_debugOnly()); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 99 | return buffer; |
| 100 | } |
| 101 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 102 | const GrCaps* GrOnFlushResourceProvider::caps() const { |
| 103 | return fDrawingMgr->getContext()->caps(); |
| 104 | } |