Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrOnFlushResourceProvider.h" |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 9 | |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrDirectContext.h" |
| 11 | #include "include/gpu/GrRecordingContext.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrDrawingManager.h" |
| 14 | #include "src/gpu/GrProxyProvider.h" |
| 15 | #include "src/gpu/GrRecordingContextPriv.h" |
| 16 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrSurfaceProxy.h" |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 18 | #include "src/gpu/GrTextureResolveRenderTask.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 19 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 20 | std::unique_ptr<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext( |
Greg Daniel | d11ae2e | 2020-02-10 16:36:07 -0500 | [diff] [blame] | 21 | sk_sp<GrSurfaceProxy> proxy, GrSurfaceOrigin origin, GrColorType colorType, |
| 22 | sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 23 | // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 24 | // we have to manually ensure it is allocated here. |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 25 | if (!this->instatiateProxy(proxy.get())) { |
| 26 | return nullptr; |
| 27 | } |
| 28 | |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 29 | auto context = fDrawingMgr->getContext(); |
| 30 | |
| 31 | if (!proxy->asRenderTargetProxy()) { |
| 32 | return nullptr; |
| 33 | } |
| 34 | |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 35 | auto renderTargetContext = GrRenderTargetContext::Make( |
| 36 | context, colorType, std::move(colorSpace), std::move(proxy), |
Robert Phillips | 1900665 | 2020-11-19 14:20:57 -0500 | [diff] [blame] | 37 | origin, props, true); |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 38 | |
| 39 | if (!renderTargetContext) { |
| 40 | return nullptr; |
| 41 | } |
| 42 | |
| 43 | renderTargetContext->discard(); |
| 44 | |
| 45 | return renderTargetContext; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 48 | void GrOnFlushResourceProvider::addTextureResolveTask(sk_sp<GrTextureProxy> textureProxy, |
| 49 | GrSurfaceProxy::ResolveFlags resolveFlags) { |
| 50 | // Since we are bypassing normal DAG operation, we need to ensure the textureProxy's last render |
| 51 | // task gets closed before making a texture resolve task. makeClosed is what will mark msaa and |
| 52 | // mipmaps dirty. |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 53 | if (GrRenderTask* renderTask = fDrawingMgr->getLastRenderTask(textureProxy.get())) { |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 54 | renderTask->makeClosed(*this->caps()); |
| 55 | } |
| 56 | auto task = static_cast<GrTextureResolveRenderTask*>(fDrawingMgr->fOnFlushRenderTasks.push_back( |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 57 | sk_make_sp<GrTextureResolveRenderTask>()).get()); |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 58 | task->addProxy(fDrawingMgr, std::move(textureProxy), resolveFlags, *this->caps()); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 59 | task->makeClosed(*this->caps()); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 60 | } |
| 61 | |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 62 | bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, |
| 63 | GrTextureProxy* proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 64 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 65 | return proxyProvider->assignUniqueKeyToProxy(key, proxy); |
| 66 | } |
| 67 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 68 | void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 69 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 70 | proxyProvider->removeUniqueKeyFromProxy(proxy); |
| 71 | } |
| 72 | |
| 73 | void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 74 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 75 | proxyProvider->processInvalidUniqueKey(key, nullptr, |
| 76 | GrProxyProvider::InvalidateGPUResource::kYes); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey( |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 80 | const GrUniqueKey& key, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 81 | UseAllocator useAllocator) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 82 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 83 | return proxyProvider->findOrCreateProxyByUniqueKey(key, useAllocator); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 84 | } |
| 85 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 86 | bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 87 | SkASSERT(proxy->canSkipResourceAllocator()); |
Robert Phillips | 7eeb74f | 2019-03-29 07:26:46 -0400 | [diff] [blame] | 88 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 89 | // TODO: this class should probably just get a GrDirectContext |
Robert Phillips | f8f45d9 | 2020-07-01 11:11:18 -0400 | [diff] [blame] | 90 | auto direct = fDrawingMgr->getContext()->asDirectContext(); |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 91 | if (!direct) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | auto resourceProvider = direct->priv().resourceProvider(); |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 96 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 97 | if (proxy->isLazy()) { |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 98 | return proxy->priv().doLazyInstantiation(resourceProvider); |
| 99 | } |
| 100 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 101 | return proxy->instantiate(resourceProvider); |
| 102 | } |
| 103 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 104 | sk_sp<GrGpuBuffer> GrOnFlushResourceProvider::makeBuffer(GrGpuBufferType intendedType, size_t size, |
| 105 | const void* data) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 106 | // TODO: this class should probably just get a GrDirectContext |
Robert Phillips | f8f45d9 | 2020-07-01 11:11:18 -0400 | [diff] [blame] | 107 | auto direct = fDrawingMgr->getContext()->asDirectContext(); |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 108 | if (!direct) { |
| 109 | return nullptr; |
| 110 | } |
| 111 | |
| 112 | auto resourceProvider = direct->priv().resourceProvider(); |
| 113 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 114 | return sk_sp<GrGpuBuffer>( |
| 115 | resourceProvider->createBuffer(size, intendedType, kDynamic_GrAccessPattern, data)); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 118 | sk_sp<const GrGpuBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer( |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 119 | GrGpuBufferType intendedType, size_t size, const void* data, const GrUniqueKey& key) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 120 | // TODO: class should probably just get a GrDirectContext |
Robert Phillips | f8f45d9 | 2020-07-01 11:11:18 -0400 | [diff] [blame] | 121 | auto direct = fDrawingMgr->getContext()->asDirectContext(); |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 122 | if (!direct) { |
| 123 | return nullptr; |
| 124 | } |
| 125 | |
| 126 | auto resourceProvider = direct->priv().resourceProvider(); |
| 127 | |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 128 | return resourceProvider->findOrMakeStaticBuffer(intendedType, size, data, key); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 129 | } |
| 130 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 131 | uint32_t GrOnFlushResourceProvider::contextID() const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 132 | return fDrawingMgr->getContext()->priv().contextID(); |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 135 | const GrCaps* GrOnFlushResourceProvider::caps() const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 136 | return fDrawingMgr->getContext()->priv().caps(); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 137 | } |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 138 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 139 | GrRecordingContext* GrOnFlushResourceProvider::recordingContext() const { |
| 140 | return fDrawingMgr->getContext(); |
Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Chris Dalton | 5a5fe79 | 2020-02-15 11:41:30 -0700 | [diff] [blame] | 143 | void GrOnFlushResourceProvider::printWarningMessage(const char* msg) const { |
| 144 | fDrawingMgr->getContext()->priv().printWarningMessage(msg); |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 145 | } |