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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrContextPriv.h" |
| 12 | #include "src/gpu/GrDrawingManager.h" |
| 13 | #include "src/gpu/GrProxyProvider.h" |
| 14 | #include "src/gpu/GrRecordingContextPriv.h" |
| 15 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrSurfaceProxy.h" |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 17 | #include "src/gpu/GrTextureResolveRenderTask.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 18 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 19 | std::unique_ptr<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext( |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 20 | sk_sp<GrSurfaceProxy> proxy, GrColorType colorType, sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 21 | const SkSurfaceProps* props) { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 22 | // 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 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 29 | auto renderTargetContext = fDrawingMgr->makeRenderTargetContext( |
| 30 | std::move(proxy), colorType, std::move(colorSpace), props, false); |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 31 | |
| 32 | if (!renderTargetContext) { |
| 33 | return nullptr; |
| 34 | } |
| 35 | |
| 36 | renderTargetContext->discard(); |
| 37 | |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 38 | // FIXME: http://skbug.com/9357: This breaks if the renderTargetContext splits its opsTask. |
| 39 | fDrawingMgr->fOnFlushRenderTasks.push_back(sk_ref_sp(renderTargetContext->getOpsTask())); |
| 40 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 41 | return renderTargetContext; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 44 | void GrOnFlushResourceProvider::addTextureResolveTask(sk_sp<GrTextureProxy> textureProxy, |
| 45 | GrSurfaceProxy::ResolveFlags resolveFlags) { |
| 46 | // Since we are bypassing normal DAG operation, we need to ensure the textureProxy's last render |
| 47 | // task gets closed before making a texture resolve task. makeClosed is what will mark msaa and |
| 48 | // mipmaps dirty. |
| 49 | if (GrRenderTask* renderTask = textureProxy->getLastRenderTask()) { |
| 50 | renderTask->makeClosed(*this->caps()); |
| 51 | } |
| 52 | auto task = static_cast<GrTextureResolveRenderTask*>(fDrawingMgr->fOnFlushRenderTasks.push_back( |
| 53 | sk_make_sp<GrTextureResolveRenderTask>(std::move(textureProxy), resolveFlags)).get()); |
| 54 | task->init(*this->caps()); |
| 55 | } |
| 56 | |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 57 | bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, |
| 58 | GrTextureProxy* proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 59 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 60 | return proxyProvider->assignUniqueKeyToProxy(key, proxy); |
| 61 | } |
| 62 | |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 63 | void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 64 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Chris Dalton | 2de13dd | 2019-01-03 15:11:59 -0700 | [diff] [blame] | 65 | proxyProvider->removeUniqueKeyFromProxy(proxy); |
| 66 | } |
| 67 | |
| 68 | void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) { |
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->processInvalidUniqueKey(key, nullptr, |
| 71 | GrProxyProvider::InvalidateGPUResource::kYes); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey( |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 75 | const GrUniqueKey& key, |
| 76 | GrColorType colorType, |
| 77 | GrSurfaceOrigin origin, |
| 78 | UseAllocator useAllocator) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 79 | auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider(); |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 80 | return proxyProvider->findOrCreateProxyByUniqueKey(key, colorType, origin, useAllocator); |
Chris Dalton | 50edafa | 2018-05-17 21:45:25 -0600 | [diff] [blame] | 81 | } |
| 82 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 83 | bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 84 | SkASSERT(proxy->canSkipResourceAllocator()); |
Robert Phillips | 7eeb74f | 2019-03-29 07:26:46 -0400 | [diff] [blame] | 85 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 86 | // TODO: this class should probably just get a GrDirectContext |
| 87 | auto direct = fDrawingMgr->getContext()->priv().asDirectContext(); |
| 88 | if (!direct) { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | auto resourceProvider = direct->priv().resourceProvider(); |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 93 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 94 | if (proxy->isLazy()) { |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 95 | return proxy->priv().doLazyInstantiation(resourceProvider); |
| 96 | } |
| 97 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 98 | return proxy->instantiate(resourceProvider); |
| 99 | } |
| 100 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 101 | sk_sp<GrGpuBuffer> GrOnFlushResourceProvider::makeBuffer(GrGpuBufferType intendedType, size_t size, |
| 102 | const void* data) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 103 | // TODO: this 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 Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 111 | return sk_sp<GrGpuBuffer>( |
| 112 | resourceProvider->createBuffer(size, intendedType, kDynamic_GrAccessPattern, data)); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 115 | sk_sp<const GrGpuBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer( |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 116 | GrGpuBufferType intendedType, size_t size, const void* data, const GrUniqueKey& key) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 117 | // TODO: class should probably just get a GrDirectContext |
| 118 | auto direct = fDrawingMgr->getContext()->priv().asDirectContext(); |
| 119 | if (!direct) { |
| 120 | return nullptr; |
| 121 | } |
| 122 | |
| 123 | auto resourceProvider = direct->priv().resourceProvider(); |
| 124 | |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame^] | 125 | return resourceProvider->findOrMakeStaticBuffer(intendedType, size, data, key); |
Chris Dalton | e9e91dd | 2017-07-14 08:48:57 -0600 | [diff] [blame] | 126 | } |
| 127 | |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 128 | uint32_t GrOnFlushResourceProvider::contextID() const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 129 | return fDrawingMgr->getContext()->priv().contextID(); |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 130 | } |
| 131 | |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 132 | const GrCaps* GrOnFlushResourceProvider::caps() const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 133 | return fDrawingMgr->getContext()->priv().caps(); |
Chris Dalton | 6081ebb | 2017-06-20 11:35:59 -0700 | [diff] [blame] | 134 | } |