blob: 16ecad9af83338628284a2a8a4fabbc5ffc973ae [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrContextPriv.h"
15#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 Salomon4eb38b72019-08-05 12:58:39 -040028 auto backendRT =
29 gpu->createTestingOnlyBackendRenderTarget(size.width(), size.height(), colorType);
Robert Phillipsa1121332020-06-29 13:05:29 -040030 return provider->wrapBackendRenderTarget(backendRT, nullptr);
Robert Phillips84a81202016-11-04 11:59:10 -040031}
32
Brian Salomon52e943a2018-03-13 09:32:39 -040033void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
Robert Phillipse5f73282019-06-18 17:15:04 -040034 SkASSERT(proxy->unique());
Brian Salomonfd98c2c2018-07-31 17:25:29 -040035 SkASSERT(proxy->peekRenderTarget());
36 GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget();
Brian Salomon52e943a2018-03-13 09:32:39 -040037 proxy.reset();
38 gpu->deleteTestingOnlyBackendRenderTarget(rt);
39}
40
41static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider,
Brian Salomona56a7462020-02-07 14:17:25 -050042 SkISize dimensions,
Greg Daniel3a365112020-02-14 10:47:18 -050043 GrColorType colorType) {
Brian Salomona56a7462020-02-07 14:17:25 -050044 return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, GrRenderable::kYes,
Greg Daniel3a365112020-02-14 10:47:18 -050045 1, SkBackingFit::kExact, SkBudgeted::kYes,
46 GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -040047}
48
Brian Salomon52e943a2018-03-13 09:32:39 -040049static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
Brian Salomona56a7462020-02-07 14:17:25 -050050 SkISize dimensions,
Brian Salomon4eb38b72019-08-05 12:58:39 -040051 GrColorType colorType,
Greg Daniel3a365112020-02-14 10:47:18 -050052 GrRenderable renderable) {
Brian Salomona56a7462020-02-07 14:17:25 -050053 return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, renderable, 1,
Greg Daniel3a365112020-02-14 10:47:18 -050054 SkBackingFit::kExact, SkBudgeted::kYes,
55 GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -040056}
57
Brian Salomon52e943a2018-03-13 09:32:39 -040058// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
59DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -040060 auto context = ctxInfo.directContext();
61 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
62 GrGpu* gpu = context->priv().getGpu();
Robert Phillips84a81202016-11-04 11:59:10 -040063
Brian Salomon4eb38b72019-08-05 12:58:39 -040064 static constexpr auto kSize = SkISize::Make(64, 64);
65 static constexpr auto kColorType = GrColorType::kRGBA_8888;
Robert Phillips84a81202016-11-04 11:59:10 -040066
Brian Salomon52e943a2018-03-13 09:32:39 -040067 {
Robert Phillips84a81202016-11-04 11:59:10 -040068 // External on-screen render target.
Greg Daniel3a365112020-02-14 10:47:18 -050069 sk_sp<GrSurfaceProxy> sProxy(
70 make_wrapped_rt(proxyProvider, gpu, reporter, kSize, kColorType));
Robert Phillips78d762d2018-01-23 16:57:35 -050071 if (sProxy) {
72 // RenderTarget-only
73 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
74 REPORTER_ASSERT(reporter, rtProxy);
75 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
76 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Brian Salomon52e943a2018-03-13 09:32:39 -040077 clean_up_wrapped_rt(gpu, std::move(sProxy));
Robert Phillips78d762d2018-01-23 16:57:35 -050078 }
Robert Phillips84a81202016-11-04 11:59:10 -040079 }
80
81 {
82 // Internal offscreen render target.
Greg Daniel3a365112020-02-14 10:47:18 -050083 sk_sp<GrSurfaceProxy> sProxy(make_offscreen_rt(proxyProvider, kSize, kColorType));
Robert Phillips78d762d2018-01-23 16:57:35 -050084 if (sProxy) {
85 // Both RenderTarget and Texture
86 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
87 REPORTER_ASSERT(reporter, rtProxy);
88 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
89 REPORTER_ASSERT(reporter, tProxy);
90 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
91 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
92 }
Robert Phillips84a81202016-11-04 11:59:10 -040093 }
94
95 {
96 // Internal offscreen render target - but through GrTextureProxy
Greg Daniel3a365112020-02-14 10:47:18 -050097 sk_sp<GrSurfaceProxy> sProxy(
98 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kYes));
Robert Phillips78d762d2018-01-23 16:57:35 -050099 if (sProxy) {
100 // Both RenderTarget and Texture
101 GrTextureProxy* tProxy = sProxy->asTextureProxy();
102 REPORTER_ASSERT(reporter, tProxy);
103 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
104 REPORTER_ASSERT(reporter, rtProxy);
105 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
106 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
107 }
Robert Phillips84a81202016-11-04 11:59:10 -0400108 }
109
110 {
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400111 // force no-RT
Greg Daniel3a365112020-02-14 10:47:18 -0500112 sk_sp<GrSurfaceProxy> sProxy(
113 make_texture(proxyProvider, kSize, kColorType, GrRenderable::kNo));
Robert Phillips78d762d2018-01-23 16:57:35 -0500114 if (sProxy) {
115 // Texture-only
116 GrTextureProxy* tProxy = sProxy->asTextureProxy();
117 REPORTER_ASSERT(reporter, tProxy);
118 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
119 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
120 }
Robert Phillips84a81202016-11-04 11:59:10 -0400121 }
122}
123
124// Test converting between RenderTargetProxies and TextureProxies for deferred
125// Proxies
126DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -0400127 auto context = ctxInfo.directContext();
Robert Phillips0a15cc62019-07-30 12:49:10 -0400128 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
129 const GrCaps* caps = context->priv().caps();
Robert Phillips84a81202016-11-04 11:59:10 -0400130
Brian Salomona56a7462020-02-07 14:17:25 -0500131 static constexpr SkISize kDims = {64, 64};
Robert Phillips84a81202016-11-04 11:59:10 -0400132
Robert Phillips0a15cc62019-07-30 12:49:10 -0400133 const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
134 GrRenderable::kYes);
Robert Phillips84a81202016-11-04 11:59:10 -0400135 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500136 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400137 format, kDims, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBackingFit::kApprox,
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400138 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400139
140 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500141 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500142 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400143 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
144 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500145 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
146 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400147 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400148
Robert Phillips84a81202016-11-04 11:59:10 -0400149 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500150 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400151 format, kDims, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBackingFit::kApprox,
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400152 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400153
154 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500155 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500156 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400157 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
158 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500159 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
160 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400161 }
162
163 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500164 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400165 format, kDims, GrRenderable::kNo, 1, GrMipmapped::kNo, SkBackingFit::kApprox,
Brian Salomondf1bd6d2020-03-26 20:37:01 -0400166 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400167 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500168 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500169 REPORTER_ASSERT(reporter, tProxy);
170 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400171 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
172 }
173}