blob: bbf10297363f4ffa5d0800874779a692c7d6a7cc [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"
Brian Salomon238069b2018-07-11 15:58:57 -04009#include "GrContext.h"
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"
Brian Salomon653f42f2018-07-10 10:07:31 -040013#include "GrRenderTargetContext.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040014#include "GrSurfaceProxy.h"
15
Chris Daltonfe199b72017-05-05 11:26:15 -040016sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
Robert Phillipseb35f4d2017-03-21 07:56:47 -040017 sk_sp<GrSurfaceProxy> proxy,
18 sk_sp<SkColorSpace> colorSpace,
19 const SkSurfaceProps* props) {
Chris Dalton4c458b12018-06-16 17:22:59 -060020 // 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 Phillips1119dc32017-04-11 12:54:57 -040027 sk_sp<GrRenderTargetContext> renderTargetContext(
28 fDrawingMgr->makeRenderTargetContext(std::move(proxy),
29 std::move(colorSpace),
Robert Phillips941d1442017-06-14 16:37:02 -040030 props, false));
Robert Phillips1119dc32017-04-11 12:54:57 -040031
32 if (!renderTargetContext) {
33 return nullptr;
34 }
35
36 renderTargetContext->discard();
37
38 return renderTargetContext;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040039}
40
Chris Dalton50edafa2018-05-17 21:45:25 -060041bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key,
42 GrTextureProxy* proxy) {
43 auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
44 return proxyProvider->assignUniqueKeyToProxy(key, proxy);
45}
46
47void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(const GrUniqueKey& key,
48 GrTextureProxy* proxy) {
49 auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
50 proxyProvider->removeUniqueKeyFromProxy(key, proxy);
51}
52
53sk_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 Phillipscd5099c2018-02-09 09:56:56 -050059bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) {
60 auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
61
Robert Phillips7d79e7b2018-02-14 11:09:57 -050062 if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) {
Greg Daniel4684f822018-03-08 15:27:36 -050063 // 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 Phillips7d79e7b2018-02-14 11:09:57 -050065 return proxy->priv().doLazyInstantiation(resourceProvider);
66 }
67
Robert Phillipscd5099c2018-02-09 09:56:56 -050068 return proxy->instantiate(resourceProvider);
69}
70
Chris Dalton6081ebb2017-06-20 11:35:59 -070071sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, size_t size,
72 const void* data) {
Robert Phillips6be756b2018-01-16 15:07:54 -050073 auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
74 return sk_sp<GrBuffer>(resourceProvider->createBuffer(size, intendedType,
75 kDynamic_GrAccessPattern,
Chris Daltond004e0b2018-09-27 09:28:03 -060076 GrResourceProvider::Flags::kNoPendingIO,
Robert Phillips6be756b2018-01-16 15:07:54 -050077 data));
Chris Dalton6081ebb2017-06-20 11:35:59 -070078}
79
Chris Dalton5d2de082017-12-19 10:40:23 -070080sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType,
81 size_t size,
82 const void* data,
83 const GrUniqueKey& key) {
Robert Phillips6be756b2018-01-16 15:07:54 -050084 auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
85 sk_sp<const GrBuffer> buffer = resourceProvider->findOrMakeStaticBuffer(intendedType, size,
86 data, key);
Chris Dalton5d2de082017-12-19 10:40:23 -070087 // Static buffers should never have pending IO.
Chris Dalton133944a2018-11-16 23:30:29 -050088 SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly());
Chris Daltone9e91dd2017-07-14 08:48:57 -060089 return buffer;
90}
91
Brian Salomon238069b2018-07-11 15:58:57 -040092uint32_t GrOnFlushResourceProvider::contextUniqueID() const {
93 return fDrawingMgr->getContext()->uniqueID();
94}
95
Chris Dalton6081ebb2017-06-20 11:35:59 -070096const GrCaps* GrOnFlushResourceProvider::caps() const {
Brian Salomonc7fe0f72018-05-11 10:14:21 -040097 return fDrawingMgr->getContext()->contextPriv().caps();
Chris Dalton6081ebb2017-06-20 11:35:59 -070098}