blob: c9fc77ed480f9d0d7df89eba458136a706924286 [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
10#include "GrDrawingManager.h"
11#include "GrSurfaceProxy.h"
12
Chris Daltonfe199b72017-05-05 11:26:15 -040013sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
Robert Phillipseb35f4d2017-03-21 07:56:47 -040014 const GrSurfaceDesc& desc,
15 sk_sp<SkColorSpace> colorSpace,
16 const SkSurfaceProps* props) {
17 GrSurfaceDesc tmpDesc = desc;
18 tmpDesc.fFlags |= kRenderTarget_GrSurfaceFlag;
19
20 // Because this is being allocated at the start of a flush we must ensure the proxy
21 // will, when instantiated, have no pending IO.
22 // TODO: fold the kNoPendingIO_Flag into GrSurfaceFlags?
23 sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(
24 fDrawingMgr->getContext()->resourceProvider(),
25 tmpDesc,
26 SkBackingFit::kExact,
27 SkBudgeted::kYes,
28 GrResourceProvider::kNoPendingIO_Flag);
29 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!
45 if (!renderTargetContext->asSurfaceProxy()->instantiate(
46 fDrawingMgr->getContext()->resourceProvider())) {
47 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!
73 if (!renderTargetContext->asSurfaceProxy()->instantiate(
74 fDrawingMgr->getContext()->resourceProvider())) {
75 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) {
85 GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider();
86 return sk_sp<GrBuffer>(rp->createBuffer(size, intendedType, kDynamic_GrAccessPattern,
87 GrResourceProvider::kNoPendingIO_Flag,
88 data));
89}
90
Chris Daltone9e91dd2017-07-14 08:48:57 -060091sk_sp<GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(const GrUniqueKey& key,
92 GrBufferType intendedType,
93 size_t size, const void* data) {
94 GrResourceProvider* rp = fDrawingMgr->getContext()->resourceProvider();
Brian Salomond28a79d2017-10-16 13:01:07 -040095 sk_sp<GrBuffer> buffer(rp->findByUniqueKey<GrBuffer>(key));
Chris Daltone9e91dd2017-07-14 08:48:57 -060096 if (!buffer) {
97 buffer.reset(rp->createBuffer(size, intendedType, kStatic_GrAccessPattern, 0, data));
98 if (!buffer) {
99 return nullptr;
100 }
101 SkASSERT(buffer->sizeInBytes() == size); // rp shouldn't bin and/or cache static buffers.
102 buffer->resourcePriv().setUniqueKey(key);
103 }
104 return buffer;
105}
106
Chris Dalton6081ebb2017-06-20 11:35:59 -0700107const GrCaps* GrOnFlushResourceProvider::caps() const {
108 return fDrawingMgr->getContext()->caps();
109}