blob: e5bdfda07290af907e98c2dd258d2e51fb01fac1 [file] [log] [blame]
Robert Phillips84a81202016-11-04 11:59:10 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050010#include "tests/Test.h"
Robert Phillips84a81202016-11-04 11:59:10 -040011
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/gpu/GrBackendSurface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrContextPriv.h"
14#include "src/gpu/GrGpu.h"
15#include "src/gpu/GrProxyProvider.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040016#include "src/gpu/GrRenderTarget.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040017#include "src/gpu/GrRenderTargetProxy.h"
18#include "src/gpu/GrSurfaceProxy.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000019#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040020#include "src/gpu/GrTextureProxy.h"
Robert Phillips84a81202016-11-04 11:59:10 -040021
Brian Salomon52e943a2018-03-13 09:32:39 -040022static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider,
23 GrGpu* gpu,
24 skiatest::Reporter* reporter,
Brian Salomon4eb38b72019-08-05 12:58:39 -040025 const SkISize& size,
Greg Daniel3a365112020-02-14 10:47:18 -050026 GrColorType colorType) {
Brian Salomon4eb38b72019-08-05 12:58:39 -040027 auto backendRT =
28 gpu->createTestingOnlyBackendRenderTarget(size.width(), size.height(), colorType);
Brian Salomon8a78e9c2020-03-27 10:42:15 -040029 return provider->wrapBackendRenderTarget(backendRT, nullptr, nullptr);
Robert Phillips84a81202016-11-04 11:59:10 -040030}
31
Brian Salomon52e943a2018-03-13 09:32:39 -040032void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
Robert Phillipse5f73282019-06-18 17:15:04 -040033 SkASSERT(proxy->unique());
Brian Salomonfd98c2c2018-07-31 17:25:29 -040034 SkASSERT(proxy->peekRenderTarget());
35 GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget();
Brian Salomon52e943a2018-03-13 09:32:39 -040036 proxy.reset();
37 gpu->deleteTestingOnlyBackendRenderTarget(rt);
38}
39
40static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider,
Brian Salomona56a7462020-02-07 14:17:25 -050041 SkISize dimensions,
Greg Daniel3a365112020-02-14 10:47:18 -050042 GrColorType colorType) {
Brian Salomona56a7462020-02-07 14:17:25 -050043 return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, GrRenderable::kYes,
Greg Daniel3a365112020-02-14 10:47:18 -050044 1, SkBackingFit::kExact, SkBudgeted::kYes,
45 GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -040046}
47
Brian Salomon52e943a2018-03-13 09:32:39 -040048static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
Brian Salomona56a7462020-02-07 14:17:25 -050049 SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040050 GrColorType colorType,
Greg Daniel3a365112020-02-14 10:47:18 -050051 GrRenderable renderable) {
Brian Salomona56a7462020-02-07 14:17:25 -050052 return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, renderable, 1,
Greg Daniel3a365112020-02-14 10:47:18 -050053 SkBackingFit::kExact, SkBudgeted::kYes,
54 GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -040055}
56
Brian Salomon52e943a2018-03-13 09:32:39 -040057// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
58DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -050059 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
60 GrGpu* gpu = ctxInfo.grContext()->priv().getGpu();
Robert Phillips84a81202016-11-04 11:59:10 -040061
Brian Salomon4eb38b72019-08-05 12:58:39 -040062 static constexpr auto kSize = SkISize::Make(64, 64);
63 static constexpr auto kColorType = GrColorType::kRGBA_8888;
Robert Phillips84a81202016-11-04 11:59:10 -040064
Brian Salomon52e943a2018-03-13 09:32:39 -040065 {
Robert Phillips84a81202016-11-04 11:59:10 -040066 // External on-screen render target.
Greg Daniel3a365112020-02-14 10:47:18 -050067 sk_sp<GrSurfaceProxy> sProxy(
68 make_wrapped_rt(proxyProvider, gpu, reporter, kSize, kColorType));
Robert Phillips78d762d2018-01-23 16:57:35 -050069 if (sProxy) {
70 // RenderTarget-only
71 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
72 REPORTER_ASSERT(reporter, rtProxy);
73 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
74 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Brian Salomon52e943a2018-03-13 09:32:39 -040075 clean_up_wrapped_rt(gpu, std::move(sProxy));
Robert Phillips78d762d2018-01-23 16:57:35 -050076 }
Robert Phillips84a81202016-11-04 11:59:10 -040077 }
78
79 {
80 // Internal offscreen render target.
Greg Daniel3a365112020-02-14 10:47:18 -050081 sk_sp<GrSurfaceProxy> sProxy(make_offscreen_rt(proxyProvider, kSize, kColorType));
Robert Phillips78d762d2018-01-23 16:57:35 -050082 if (sProxy) {
83 // Both RenderTarget and Texture
84 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
85 REPORTER_ASSERT(reporter, rtProxy);
86 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
87 REPORTER_ASSERT(reporter, tProxy);
88 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
89 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
90 }
Robert Phillips84a81202016-11-04 11:59:10 -040091 }
92
93 {
94 // Internal offscreen render target - but through GrTextureProxy
Greg Daniel3a365112020-02-14 10:47:18 -050095 sk_sp<GrSurfaceProxy> sProxy(
96 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kYes));
Robert Phillips78d762d2018-01-23 16:57:35 -050097 if (sProxy) {
98 // Both RenderTarget and Texture
99 GrTextureProxy* tProxy = sProxy->asTextureProxy();
100 REPORTER_ASSERT(reporter, tProxy);
101 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
102 REPORTER_ASSERT(reporter, rtProxy);
103 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
104 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
105 }
Robert Phillips84a81202016-11-04 11:59:10 -0400106 }
107
108 {
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400109 // force no-RT
Greg Daniel3a365112020-02-14 10:47:18 -0500110 sk_sp<GrSurfaceProxy> sProxy(
111 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kNo));
Robert Phillips78d762d2018-01-23 16:57:35 -0500112 if (sProxy) {
113 // Texture-only
114 GrTextureProxy* tProxy = sProxy->asTextureProxy();
115 REPORTER_ASSERT(reporter, tProxy);
116 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
117 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
118 }
Robert Phillips84a81202016-11-04 11:59:10 -0400119 }
120}
121
122// Test converting between RenderTargetProxies and TextureProxies for deferred
123// Proxies
124DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400125 GrContext* context = ctxInfo.grContext();
126 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
127 const GrCaps* caps = context->priv().caps();
Robert Phillips84a81202016-11-04 11:59:10 -0400128
Brian Salomona56a7462020-02-07 14:17:25 -0500129 static constexpr SkISize kDims = {64, 64};
Robert Phillips84a81202016-11-04 11:59:10 -0400130
Robert Phillips0a15cc62019-07-30 12:49:10 -0400131 const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
132 GrRenderable::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400133 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500134 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400135 format, kDims, GrRenderable::kYes, 1, GrMipMapped::kNo, SkBackingFit::kApprox,
136 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400137
138 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500139 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500140 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400141 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
142 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500143 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
144 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400145 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400146
Robert Phillips84a81202016-11-04 11:59:10 -0400147 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500148 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400149 format, kDims, GrRenderable::kYes, 1, GrMipMapped::kNo, SkBackingFit::kApprox,
150 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400151
152 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500153 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500154 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400155 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
156 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500157 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
158 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400159 }
160
161 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500162 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400163 format, kDims, GrRenderable::kNo, 1, GrMipMapped::kNo, SkBackingFit::kApprox,
164 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400165 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500166 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500167 REPORTER_ASSERT(reporter, tProxy);
168 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400169 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
170 }
171}