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 | |
| 10 | #include "Test.h" |
| 11 | |
| 12 | #if SK_SUPPORT_GPU |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 13 | #include "GrBackendSurface.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 14 | #include "GrContextPriv.h" |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 15 | #include "GrGpu.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 16 | #include "GrProxyProvider.h" |
Robert Phillips | 009e9af | 2017-06-15 14:01:04 -0400 | [diff] [blame] | 17 | #include "GrRenderTarget.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 18 | #include "GrRenderTargetProxy.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 19 | #include "GrSurfaceProxy.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 20 | #include "GrTexture.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 21 | #include "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, |
| 26 | const GrSurfaceDesc& desc, |
| 27 | GrSurfaceOrigin origin) { |
| 28 | // We don't currently have a way of making MSAA backend render targets. |
| 29 | SkASSERT(1 == desc.fSampleCnt); |
| 30 | GrSRGBEncoded srgbEncoded; |
| 31 | auto ct = GrPixelConfigToColorTypeAndEncoding(desc.fConfig, &srgbEncoded); |
| 32 | auto backendRT = gpu->createTestingOnlyBackendRenderTarget(desc.fWidth, desc.fHeight, ct, |
| 33 | GrSRGBEncoded::kNo); |
Brian Salomon | 7578f3e | 2018-03-07 14:39:54 -0500 | [diff] [blame] | 34 | return provider->wrapBackendRenderTarget(backendRT, origin); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 35 | } |
| 36 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 37 | void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) { |
| 38 | SkASSERT(proxy->isUnique_debugOnly()); |
| 39 | SkASSERT(proxy->priv().peekRenderTarget()); |
| 40 | GrBackendRenderTarget rt = proxy->priv().peekRenderTarget()->getBackendRenderTarget(); |
| 41 | proxy.reset(); |
| 42 | gpu->deleteTestingOnlyBackendRenderTarget(rt); |
| 43 | } |
| 44 | |
| 45 | static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider, |
| 46 | const GrSurfaceDesc& desc, |
| 47 | GrSurfaceOrigin origin) { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 48 | SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags); |
| 49 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 50 | return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, SkBudgeted::kYes); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 53 | static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider, |
| 54 | const GrSurfaceDesc& desc, |
| 55 | GrSurfaceOrigin origin) { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 56 | return provider->createInstantiatedProxy(desc, origin, SkBackingFit::kExact, SkBudgeted::kYes); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 59 | // Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies |
| 60 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) { |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 61 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 62 | GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu(); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 63 | |
| 64 | GrSurfaceDesc desc; |
| 65 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 66 | desc.fWidth = 64; |
| 67 | desc.fHeight = 64; |
| 68 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 69 | |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 70 | { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 71 | // External on-screen render target. |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 72 | sk_sp<GrSurfaceProxy> sProxy( |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 73 | make_wrapped_rt(proxyProvider, gpu, reporter, desc, kBottomLeft_GrSurfaceOrigin)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 74 | if (sProxy) { |
| 75 | // RenderTarget-only |
| 76 | GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy(); |
| 77 | REPORTER_ASSERT(reporter, rtProxy); |
| 78 | REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy()); |
| 79 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 80 | clean_up_wrapped_rt(gpu, std::move(sProxy)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 81 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | { |
| 85 | // Internal offscreen render target. |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 86 | sk_sp<GrSurfaceProxy> sProxy( |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 87 | make_offscreen_rt(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 88 | if (sProxy) { |
| 89 | // Both RenderTarget and Texture |
| 90 | GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy(); |
| 91 | REPORTER_ASSERT(reporter, rtProxy); |
| 92 | GrTextureProxy* tProxy = rtProxy->asTextureProxy(); |
| 93 | REPORTER_ASSERT(reporter, tProxy); |
| 94 | REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy); |
| 95 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
| 96 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | { |
| 100 | // Internal offscreen render target - but through GrTextureProxy |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 101 | sk_sp<GrSurfaceProxy> sProxy( |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 102 | make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 103 | if (sProxy) { |
| 104 | // Both RenderTarget and Texture |
| 105 | GrTextureProxy* tProxy = sProxy->asTextureProxy(); |
| 106 | REPORTER_ASSERT(reporter, tProxy); |
| 107 | GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy(); |
| 108 | REPORTER_ASSERT(reporter, rtProxy); |
| 109 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy); |
| 110 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
| 111 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | { |
| 115 | desc.fFlags = kNone_GrSurfaceFlags; // force no-RT |
| 116 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 117 | sk_sp<GrSurfaceProxy> sProxy( |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 118 | make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin)); |
Robert Phillips | 78d762d | 2018-01-23 16:57:35 -0500 | [diff] [blame] | 119 | if (sProxy) { |
| 120 | // Texture-only |
| 121 | GrTextureProxy* tProxy = sProxy->asTextureProxy(); |
| 122 | REPORTER_ASSERT(reporter, tProxy); |
| 123 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
| 124 | REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy()); |
| 125 | } |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | // Test converting between RenderTargetProxies and TextureProxies for deferred |
| 130 | // Proxies |
| 131 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) { |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 132 | GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider(); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 133 | |
| 134 | GrSurfaceDesc desc; |
| 135 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 136 | desc.fWidth = 64; |
| 137 | desc.fHeight = 64; |
| 138 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 139 | |
| 140 | { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 141 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
| 142 | desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 143 | |
| 144 | // Both RenderTarget and Texture |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 145 | GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 146 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 147 | GrTextureProxy* tProxy = rtProxy->asTextureProxy(); |
| 148 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy); |
| 150 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 151 | } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 152 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 153 | { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 154 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
| 155 | desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 156 | |
| 157 | // Both RenderTarget and Texture - but via GrTextureProxy |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 158 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 159 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 160 | GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy(); |
| 161 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 162 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy); |
| 163 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | { |
| 167 | desc.fFlags = kNone_GrSurfaceFlags; // force no-RT |
| 168 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 169 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
| 170 | desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 171 | // Texture-only |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 172 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 173 | REPORTER_ASSERT(reporter, tProxy); |
| 174 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 175 | REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy()); |
| 176 | } |
| 177 | } |
| 178 | #endif |