blob: 8df901597b9d1208d5ebad78203bb372216436e2 [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"
Robert Phillips6d344c32020-07-06 10:56:46 -040013#include "include/gpu/GrDirectContext.h"
Adlai Hollera0693042020-10-14 11:23:11 -040014#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrProxyProvider.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040017#include "src/gpu/GrRenderTarget.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040018#include "src/gpu/GrRenderTargetProxy.h"
19#include "src/gpu/GrSurfaceProxy.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000020#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040021#include "src/gpu/GrTextureProxy.h"
Robert Phillips84a81202016-11-04 11:59:10 -040022
Brian Salomon52e943a2018-03-13 09:32:39 -040023static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider,
24 GrGpu* gpu,
25 skiatest::Reporter* reporter,
Brian Salomon4eb38b72019-08-05 12:58:39 -040026 const SkISize& size,
Greg Daniel3a365112020-02-14 10:47:18 -050027 GrColorType colorType) {
Brian Salomon72c7b982020-10-06 10:07:38 -040028 auto backendRT = gpu->createTestingOnlyBackendRenderTarget(size, colorType);
Robert Phillipsa1121332020-06-29 13:05:29 -040029 return provider->wrapBackendRenderTarget(backendRT, 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 Phillips6d344c32020-07-06 10:56:46 -040059 auto context = ctxInfo.directContext();
60 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
61 GrGpu* gpu = context->priv().getGpu();
Robert Phillips84a81202016-11-04 11:59:10 -040062
Brian Salomon4eb38b72019-08-05 12:58:39 -040063 static constexpr auto kSize = SkISize::Make(64, 64);
64 static constexpr auto kColorType = GrColorType::kRGBA_8888;
Robert Phillips84a81202016-11-04 11:59:10 -040065
Brian Salomon52e943a2018-03-13 09:32:39 -040066 {
Robert Phillips84a81202016-11-04 11:59:10 -040067 // External on-screen render target.
Greg Daniel3a365112020-02-14 10:47:18 -050068 sk_sp<GrSurfaceProxy> sProxy(
69 make_wrapped_rt(proxyProvider, gpu, reporter, kSize, kColorType));
Robert Phillips78d762d2018-01-23 16:57:35 -050070 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 Salomon52e943a2018-03-13 09:32:39 -040076 clean_up_wrapped_rt(gpu, std::move(sProxy));
Robert Phillips78d762d2018-01-23 16:57:35 -050077 }
Robert Phillips84a81202016-11-04 11:59:10 -040078 }
79
80 {
81 // Internal offscreen render target.
Greg Daniel3a365112020-02-14 10:47:18 -050082 sk_sp<GrSurfaceProxy> sProxy(make_offscreen_rt(proxyProvider, kSize, kColorType));
Robert Phillips78d762d2018-01-23 16:57:35 -050083 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 Phillips84a81202016-11-04 11:59:10 -040092 }
93
94 {
95 // Internal offscreen render target - but through GrTextureProxy
Greg Daniel3a365112020-02-14 10:47:18 -050096 sk_sp<GrSurfaceProxy> sProxy(
97 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kYes));
Robert Phillips78d762d2018-01-23 16:57:35 -050098 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 Phillips84a81202016-11-04 11:59:10 -0400107 }
108
109 {
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400110 // force no-RT
Greg Daniel3a365112020-02-14 10:47:18 -0500111 sk_sp<GrSurfaceProxy> sProxy(
112 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kNo));
Robert Phillips78d762d2018-01-23 16:57:35 -0500113 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 Phillips84a81202016-11-04 11:59:10 -0400120 }
121}
122
123// Test converting between RenderTargetProxies and TextureProxies for deferred
124// Proxies
125DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400126 auto context = ctxInfo.directContext();
Robert Phillips0a15cc62019-07-30 12:49:10 -0400127 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
128 const GrCaps* caps = context->priv().caps();
Robert Phillips84a81202016-11-04 11:59:10 -0400129
Brian Salomona56a7462020-02-07 14:17:25 -0500130 static constexpr SkISize kDims = {64, 64};
Robert Phillips84a81202016-11-04 11:59:10 -0400131
Robert Phillips0a15cc62019-07-30 12:49:10 -0400132 const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
133 GrRenderable::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400134 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500135 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400136 format, kDims, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBackingFit::kApprox,
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400137 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400138
139 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500140 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500141 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400142 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
143 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500144 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
145 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400146 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400147
Robert Phillips84a81202016-11-04 11:59:10 -0400148 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500149 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400150 format, kDims, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBackingFit::kApprox,
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400151 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400152
153 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500154 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500155 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400156 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
157 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500158 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
159 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400160 }
161
162 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500163 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400164 format, kDims, GrRenderable::kNo, 1, GrMipmapped::kNo, SkBackingFit::kApprox,
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400165 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400166 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500167 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500168 REPORTER_ASSERT(reporter, tProxy);
169 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400170 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
171 }
172}