blob: aadd3534779c4565e1206551b5d8cf1f289f94b4 [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
Chris Dalton2de13dd2019-01-03 15:11:59 -070047void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) {
Chris Dalton50edafa2018-05-17 21:45:25 -060048 auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
Chris Dalton2de13dd2019-01-03 15:11:59 -070049 proxyProvider->removeUniqueKeyFromProxy(proxy);
50}
51
52void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) {
53 auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
54 proxyProvider->processInvalidUniqueKey(key, nullptr,
55 GrProxyProvider::InvalidateGPUResource::kYes);
Chris Dalton50edafa2018-05-17 21:45:25 -060056}
57
58sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey(
59 const GrUniqueKey& key, GrSurfaceOrigin origin) {
60 auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
61 return proxyProvider->findOrCreateProxyByUniqueKey(key, origin);
62}
63
Robert Phillipscd5099c2018-02-09 09:56:56 -050064bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) {
65 auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
66
Robert Phillips7d79e7b2018-02-14 11:09:57 -050067 if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) {
Brian Salomon967df202018-12-07 11:15:53 -050068 // DDL TODO: Decide if we ever plan to have these proxies use the GrDeinstantiateTracker
Greg Daniel4684f822018-03-08 15:27:36 -050069 // to support unistantiating them at the end of a flush.
Robert Phillips7d79e7b2018-02-14 11:09:57 -050070 return proxy->priv().doLazyInstantiation(resourceProvider);
71 }
72
Robert Phillipscd5099c2018-02-09 09:56:56 -050073 return proxy->instantiate(resourceProvider);
74}
75
Chris Dalton6081ebb2017-06-20 11:35:59 -070076sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, size_t size,
77 const void* data) {
Robert Phillips6be756b2018-01-16 15:07:54 -050078 auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
79 return sk_sp<GrBuffer>(resourceProvider->createBuffer(size, intendedType,
80 kDynamic_GrAccessPattern,
Chris Daltond004e0b2018-09-27 09:28:03 -060081 GrResourceProvider::Flags::kNoPendingIO,
Robert Phillips6be756b2018-01-16 15:07:54 -050082 data));
Chris Dalton6081ebb2017-06-20 11:35:59 -070083}
84
Chris Dalton5d2de082017-12-19 10:40:23 -070085sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType,
86 size_t size,
87 const void* data,
88 const GrUniqueKey& key) {
Robert Phillips6be756b2018-01-16 15:07:54 -050089 auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
90 sk_sp<const GrBuffer> buffer = resourceProvider->findOrMakeStaticBuffer(intendedType, size,
91 data, key);
Chris Dalton5d2de082017-12-19 10:40:23 -070092 // Static buffers should never have pending IO.
Chris Dalton133944a2018-11-16 23:30:29 -050093 SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly());
Chris Daltone9e91dd2017-07-14 08:48:57 -060094 return buffer;
95}
96
Brian Salomon238069b2018-07-11 15:58:57 -040097uint32_t GrOnFlushResourceProvider::contextUniqueID() const {
98 return fDrawingMgr->getContext()->uniqueID();
99}
100
Chris Dalton6081ebb2017-06-20 11:35:59 -0700101const GrCaps* GrOnFlushResourceProvider::caps() const {
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400102 return fDrawingMgr->getContext()->contextPriv().caps();
Chris Dalton6081ebb2017-06-20 11:35:59 -0700103}