Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 8 | // This is a GPU-backend specific test. |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/GrBackendSurface.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrDirectContext.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrGpu.h" |
| 16 | #include "src/gpu/GrProxyProvider.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrRenderTarget.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrRenderTargetProxy.h" |
| 19 | #include "src/gpu/GrSurfaceProxy.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 20 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrTextureProxy.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 22 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 23 | static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider, |
| 24 | GrGpu* gpu, |
| 25 | skiatest::Reporter* reporter, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 26 | const SkISize& size, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 27 | GrColorType colorType) { |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 28 | auto backendRT = gpu->createTestingOnlyBackendRenderTarget(size, colorType); |
Robert Phillips | a112133 | 2020-06-29 13:05:29 -0400 | [diff] [blame] | 29 | return provider->wrapBackendRenderTarget(backendRT, nullptr); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 30 | } |
| 31 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 32 | void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) { |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 33 | SkASSERT(proxy->unique()); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 34 | SkASSERT(proxy->peekRenderTarget()); |
| 35 | GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget(); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 36 | proxy.reset(); |
| 37 | gpu->deleteTestingOnlyBackendRenderTarget(rt); |
| 38 | } |
| 39 | |
| 40 | static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 41 | SkISize dimensions, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 42 | GrColorType colorType) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 43 | return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, GrRenderable::kYes, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 44 | 1, SkBackingFit::kExact, SkBudgeted::kYes, |
| 45 | GrProtected::kNo); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 48 | static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 49 | SkISize dimensions, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 50 | GrColorType colorType, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 51 | GrRenderable renderable) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 52 | return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, renderable, 1, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 53 | SkBackingFit::kExact, SkBudgeted::kYes, |
| 54 | GrProtected::kNo); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 55 | } |
| 56 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 57 | // Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies |
| 58 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 59 | auto context = ctxInfo.directContext(); |
| 60 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 61 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 62 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 63 | static constexpr auto kSize = SkISize::Make(64, 64); |
| 64 | static constexpr auto kColorType = GrColorType::kRGBA_8888; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 65 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 66 | { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 67 | // External on-screen render target. |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 68 | sk_sp<GrSurfaceProxy> sProxy( |
| 69 | make_wrapped_rt(proxyProvider, gpu, reporter, kSize, kColorType)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 70 | if (sProxy) { |
| 71 | // RenderTarget-only |
| 72 | GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy(); |
| 73 | REPORTER_ASSERT(reporter, rtProxy); |
| 74 | REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy()); |
| 75 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 76 | clean_up_wrapped_rt(gpu, std::move(sProxy)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 77 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | { |
| 81 | // Internal offscreen render target. |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 82 | sk_sp<GrSurfaceProxy> sProxy(make_offscreen_rt(proxyProvider, kSize, kColorType)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 83 | if (sProxy) { |
| 84 | // Both RenderTarget and Texture |
| 85 | GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy(); |
| 86 | REPORTER_ASSERT(reporter, rtProxy); |
| 87 | GrTextureProxy* tProxy = rtProxy->asTextureProxy(); |
| 88 | REPORTER_ASSERT(reporter, tProxy); |
| 89 | REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy); |
| 90 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
| 91 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | { |
| 95 | // Internal offscreen render target - but through GrTextureProxy |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 96 | sk_sp<GrSurfaceProxy> sProxy( |
| 97 | make_texture(proxyProvider, kSize, kColorType, GrRenderable::kYes)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 98 | if (sProxy) { |
| 99 | // Both RenderTarget and Texture |
| 100 | GrTextureProxy* tProxy = sProxy->asTextureProxy(); |
| 101 | REPORTER_ASSERT(reporter, tProxy); |
| 102 | GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy(); |
| 103 | REPORTER_ASSERT(reporter, rtProxy); |
| 104 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy); |
| 105 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
| 106 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | { |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 110 | // force no-RT |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 111 | sk_sp<GrSurfaceProxy> sProxy( |
| 112 | make_texture(proxyProvider, kSize, kColorType, GrRenderable::kNo)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 113 | if (sProxy) { |
| 114 | // Texture-only |
| 115 | GrTextureProxy* tProxy = sProxy->asTextureProxy(); |
| 116 | REPORTER_ASSERT(reporter, tProxy); |
| 117 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
| 118 | REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy()); |
| 119 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | // Test converting between RenderTargetProxies and TextureProxies for deferred |
| 124 | // Proxies |
| 125 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 126 | auto context = ctxInfo.directContext(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 127 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 128 | const GrCaps* caps = context->priv().caps(); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 129 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 130 | static constexpr SkISize kDims = {64, 64}; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 131 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 132 | const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 133 | GrRenderable::kYes); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 134 | { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 135 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 136 | format, kDims, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBackingFit::kApprox, |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 137 | SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 138 | |
| 139 | // Both RenderTarget and Texture |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 140 | GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 141 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 142 | GrTextureProxy* tProxy = rtProxy->asTextureProxy(); |
| 143 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy); |
| 145 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 146 | } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 147 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 148 | { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 149 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 150 | format, kDims, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBackingFit::kApprox, |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 151 | SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 152 | |
| 153 | // Both RenderTarget and Texture - but via GrTextureProxy |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 154 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 156 | GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy(); |
| 157 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 158 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy); |
| 159 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 163 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 164 | format, kDims, GrRenderable::kNo, 1, GrMipmapped::kNo, SkBackingFit::kApprox, |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 165 | SkBudgeted::kYes, GrProtected::kNo); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 166 | // Texture-only |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 167 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, tProxy); |
| 169 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 170 | REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy()); |
| 171 | } |
| 172 | } |