blob: 7fcd30f941176d9eb4d173db04cdddedb7c42de5 [file] [log] [blame]
Robert Phillipseb35f4d2017-03-21 07:56:47 -04001/*
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 Daltonfe199b72017-05-05 11:26:15 -04008#include "GrOnFlushResourceProvider.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -04009
Robert Phillips1afd4cd2018-01-08 13:40:32 -050010#include "GrContextPriv.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040011#include "GrDrawingManager.h"
Robert Phillips0bd24dc2018-01-16 08:06:32 -050012#include "GrProxyProvider.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040013#include "GrSurfaceProxy.h"
14
Chris Daltonfe199b72017-05-05 11:26:15 -040015sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
Robert Phillipseb35f4d2017-03-21 07:56:47 -040016 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 Canarybe46e242018-01-16 18:33:07 +000025 GrProxyProvider* proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
Robert Phillips0bd24dc2018-01-16 08:06:32 -050026 sk_sp<GrSurfaceProxy> proxy = proxyProvider->createProxy(tmpDesc, SkBackingFit::kExact,
27 SkBudgeted::kYes,
28 GrResourceProvider::kNoPendingIO_Flag);
Robert Phillipseb35f4d2017-03-21 07:56:47 -040029 if (!proxy->asRenderTargetProxy()) {
30 return nullptr;
31 }
32
Robert Phillips1119dc32017-04-11 12:54:57 -040033 sk_sp<GrRenderTargetContext> renderTargetContext(
34 fDrawingMgr->makeRenderTargetContext(std::move(proxy),
35 std::move(colorSpace),
Robert Phillips941d1442017-06-14 16:37:02 -040036 props, false));
Robert Phillips1119dc32017-04-11 12:54:57 -040037
38 if (!renderTargetContext) {
39 return nullptr;
40 }
41
Robert Phillipse0070c02017-11-13 12:47:24 -050042 // 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 Canarybe46e242018-01-16 18:33:07 +000045 if (!renderTargetContext->asSurfaceProxy()->instantiate(
46 fDrawingMgr->getContext()->resourceProvider())) {
Robert Phillipse0070c02017-11-13 12:47:24 -050047 return nullptr;
48 }
49
Robert Phillips1119dc32017-04-11 12:54:57 -040050 renderTargetContext->discard();
51
52 return renderTargetContext;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040053}
54
55// TODO: we only need this entry point as long as we have to pre-allocate the atlas.
56// Remove it ASAP.
Chris Daltonfe199b72017-05-05 11:26:15 -040057sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
Robert Phillipseb35f4d2017-03-21 07:56:47 -040058 sk_sp<GrSurfaceProxy> proxy,
59 sk_sp<SkColorSpace> colorSpace,
60 const SkSurfaceProps* props) {
Robert Phillips1119dc32017-04-11 12:54:57 -040061 sk_sp<GrRenderTargetContext> renderTargetContext(
62 fDrawingMgr->makeRenderTargetContext(std::move(proxy),
63 std::move(colorSpace),
Robert Phillips941d1442017-06-14 16:37:02 -040064 props, false));
Robert Phillips1119dc32017-04-11 12:54:57 -040065
66 if (!renderTargetContext) {
67 return nullptr;
68 }
69
Robert Phillipse0070c02017-11-13 12:47:24 -050070 // 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 Canarybe46e242018-01-16 18:33:07 +000073 if (!renderTargetContext->asSurfaceProxy()->instantiate(
74 fDrawingMgr->getContext()->resourceProvider())) {
Robert Phillipse0070c02017-11-13 12:47:24 -050075 return nullptr;
76 }
77
Robert Phillips1119dc32017-04-11 12:54:57 -040078 renderTargetContext->discard();
79
80 return renderTargetContext;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040081}
82
Chris Dalton6081ebb2017-06-20 11:35:59 -070083sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, size_t size,
84 const void* data) {
Hal Canarybe46e242018-01-16 18:33:07 +000085 GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider();
86 return sk_sp<GrBuffer>(rp->createBuffer(size, intendedType, kDynamic_GrAccessPattern,
87 GrResourceProvider::kNoPendingIO_Flag,
88 data));
Chris Dalton6081ebb2017-06-20 11:35:59 -070089}
90
Chris Dalton5d2de082017-12-19 10:40:23 -070091sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType,
92 size_t size,
93 const void* data,
94 const GrUniqueKey& key) {
Hal Canarybe46e242018-01-16 18:33:07 +000095 GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider();
96 sk_sp<const GrBuffer> buffer = rp->findOrMakeStaticBuffer(intendedType, size, data, key);
Chris Dalton5d2de082017-12-19 10:40:23 -070097 // Static buffers should never have pending IO.
98 SkASSERT(!buffer->resourcePriv().hasPendingIO_debugOnly());
Chris Daltone9e91dd2017-07-14 08:48:57 -060099 return buffer;
100}
101
Chris Dalton6081ebb2017-06-20 11:35:59 -0700102const GrCaps* GrOnFlushResourceProvider::caps() const {
103 return fDrawingMgr->getContext()->caps();
104}