blob: e2ea013d4bc57814da3000fa794d9a4fa4a16b38 [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 Phillips69893702019-02-22 11:16:30 -05009
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 Phillips69893702019-02-22 11:16:30 -050013#include "GrRecordingContext.h"
14#include "GrRecordingContextPriv.h"
Brian Salomon653f42f2018-07-10 10:07:31 -040015#include "GrRenderTargetContext.h"
Robert Phillipseb35f4d2017-03-21 07:56:47 -040016#include "GrSurfaceProxy.h"
17
Chris Daltonfe199b72017-05-05 11:26:15 -040018sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
Robert Phillipseb35f4d2017-03-21 07:56:47 -040019 sk_sp<GrSurfaceProxy> proxy,
20 sk_sp<SkColorSpace> colorSpace,
21 const SkSurfaceProps* props) {
Chris Dalton4c458b12018-06-16 17:22:59 -060022 // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator
23 // we have to manually ensure it is allocated here. The proxy had best have been created
24 // with the kNoPendingIO flag!
25 if (!this->instatiateProxy(proxy.get())) {
26 return nullptr;
27 }
28
Robert Phillips1119dc32017-04-11 12:54:57 -040029 sk_sp<GrRenderTargetContext> renderTargetContext(
30 fDrawingMgr->makeRenderTargetContext(std::move(proxy),
31 std::move(colorSpace),
Robert Phillips941d1442017-06-14 16:37:02 -040032 props, false));
Robert Phillips1119dc32017-04-11 12:54:57 -040033
34 if (!renderTargetContext) {
35 return nullptr;
36 }
37
38 renderTargetContext->discard();
39
40 return renderTargetContext;
Robert Phillipseb35f4d2017-03-21 07:56:47 -040041}
42
Chris Dalton50edafa2018-05-17 21:45:25 -060043bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key,
44 GrTextureProxy* proxy) {
Robert Phillips9da87e02019-02-04 13:26:26 -050045 auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
Chris Dalton50edafa2018-05-17 21:45:25 -060046 return proxyProvider->assignUniqueKeyToProxy(key, proxy);
47}
48
Chris Dalton2de13dd2019-01-03 15:11:59 -070049void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) {
Robert Phillips9da87e02019-02-04 13:26:26 -050050 auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
Chris Dalton2de13dd2019-01-03 15:11:59 -070051 proxyProvider->removeUniqueKeyFromProxy(proxy);
52}
53
54void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) {
Robert Phillips9da87e02019-02-04 13:26:26 -050055 auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
Chris Dalton2de13dd2019-01-03 15:11:59 -070056 proxyProvider->processInvalidUniqueKey(key, nullptr,
57 GrProxyProvider::InvalidateGPUResource::kYes);
Chris Dalton50edafa2018-05-17 21:45:25 -060058}
59
60sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey(
61 const GrUniqueKey& key, GrSurfaceOrigin origin) {
Robert Phillips9da87e02019-02-04 13:26:26 -050062 auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
Chris Dalton50edafa2018-05-17 21:45:25 -060063 return proxyProvider->findOrCreateProxyByUniqueKey(key, origin);
64}
65
Robert Phillipscd5099c2018-02-09 09:56:56 -050066bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) {
Robert Phillips5f78adf2019-04-22 12:41:39 -040067 SkASSERT(proxy->priv().ignoredByResourceAllocator());
Robert Phillips7eeb74f2019-03-29 07:26:46 -040068 SkASSERT(proxy->priv().requiresNoPendingIO());
69
Robert Phillips6a6de562019-02-15 15:19:15 -050070 // TODO: this class should probably just get a GrDirectContext
71 auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
72 if (!direct) {
73 return false;
74 }
75
76 auto resourceProvider = direct->priv().resourceProvider();
Robert Phillipscd5099c2018-02-09 09:56:56 -050077
Robert Phillips7d79e7b2018-02-14 11:09:57 -050078 if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) {
Brian Salomon967df202018-12-07 11:15:53 -050079 // DDL TODO: Decide if we ever plan to have these proxies use the GrDeinstantiateTracker
Greg Daniel4684f822018-03-08 15:27:36 -050080 // to support unistantiating them at the end of a flush.
Robert Phillips7d79e7b2018-02-14 11:09:57 -050081 return proxy->priv().doLazyInstantiation(resourceProvider);
82 }
83
Robert Phillipscd5099c2018-02-09 09:56:56 -050084 return proxy->instantiate(resourceProvider);
85}
86
Brian Salomondbf70722019-02-07 11:31:24 -050087sk_sp<GrGpuBuffer> GrOnFlushResourceProvider::makeBuffer(GrGpuBufferType intendedType, size_t size,
88 const void* data) {
Robert Phillips6a6de562019-02-15 15:19:15 -050089 // TODO: this class should probably just get a GrDirectContext
90 auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
91 if (!direct) {
92 return nullptr;
93 }
94
95 auto resourceProvider = direct->priv().resourceProvider();
96
Brian Salomondbf70722019-02-07 11:31:24 -050097 return sk_sp<GrGpuBuffer>(
98 resourceProvider->createBuffer(size, intendedType, kDynamic_GrAccessPattern, data));
Chris Dalton6081ebb2017-06-20 11:35:59 -070099}
100
Brian Salomondbf70722019-02-07 11:31:24 -0500101sk_sp<const GrGpuBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(
Brian Salomonae64c192019-02-05 09:41:37 -0500102 GrGpuBufferType intendedType, size_t size, const void* data, const GrUniqueKey& key) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500103 // TODO: class should probably just get a GrDirectContext
104 auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
105 if (!direct) {
106 return nullptr;
107 }
108
109 auto resourceProvider = direct->priv().resourceProvider();
110
Brian Salomondbf70722019-02-07 11:31:24 -0500111 sk_sp<const GrGpuBuffer> buffer =
112 resourceProvider->findOrMakeStaticBuffer(intendedType, size, data, key);
Chris Dalton5d2de082017-12-19 10:40:23 -0700113 // Static buffers should never have pending IO.
Chris Dalton133944a2018-11-16 23:30:29 -0500114 SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly());
Chris Daltone9e91dd2017-07-14 08:48:57 -0600115 return buffer;
116}
117
Robert Phillipsfd0d9702019-02-01 10:19:42 -0500118uint32_t GrOnFlushResourceProvider::contextID() const {
Robert Phillips9da87e02019-02-04 13:26:26 -0500119 return fDrawingMgr->getContext()->priv().contextID();
Brian Salomon238069b2018-07-11 15:58:57 -0400120}
121
Chris Dalton6081ebb2017-06-20 11:35:59 -0700122const GrCaps* GrOnFlushResourceProvider::caps() const {
Robert Phillips9da87e02019-02-04 13:26:26 -0500123 return fDrawingMgr->getContext()->priv().caps();
Chris Dalton6081ebb2017-06-20 11:35:59 -0700124}