blob: aaf96bab14414aea5fdaabe75c47b6fa28932241 [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 "include/gpu/GrTexture.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"
20#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,
26 GrColorType colorType,
Brian Salomon52e943a2018-03-13 09:32:39 -040027 GrSurfaceOrigin origin) {
Brian Salomon4eb38b72019-08-05 12:58:39 -040028 auto backendRT =
29 gpu->createTestingOnlyBackendRenderTarget(size.width(), size.height(), colorType);
30 return provider->wrapBackendRenderTarget(backendRT, colorType, origin, nullptr, 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 Salomon4eb38b72019-08-05 12:58:39 -040042 const SkISize& size,
43 GrColorType colorType,
Brian Salomon52e943a2018-03-13 09:32:39 -040044 GrSurfaceOrigin origin) {
Brian Salomon4eb38b72019-08-05 12:58:39 -040045 return provider->testingOnly_createInstantiatedProxy(size, colorType, GrRenderable::kYes, 1,
46 origin, SkBackingFit::kExact,
47 SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -040048}
49
Brian Salomon52e943a2018-03-13 09:32:39 -040050static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
Brian Salomon4eb38b72019-08-05 12:58:39 -040051 const SkISize& size,
52 GrColorType colorType,
Brian Salomonf2c2ba92019-07-17 09:59:59 -040053 GrRenderable renderable,
Brian Salomon52e943a2018-03-13 09:32:39 -040054 GrSurfaceOrigin origin) {
Brian Salomon4eb38b72019-08-05 12:58:39 -040055 return provider->testingOnly_createInstantiatedProxy(size, colorType, renderable, 1, origin,
56 SkBackingFit::kExact, SkBudgeted::kYes,
57 GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -040058}
59
Brian Salomon52e943a2018-03-13 09:32:39 -040060// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
61DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
Robert Phillips9da87e02019-02-04 13:26:26 -050062 GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
63 GrGpu* gpu = ctxInfo.grContext()->priv().getGpu();
Robert Phillips84a81202016-11-04 11:59:10 -040064
Brian Salomon4eb38b72019-08-05 12:58:39 -040065 static constexpr auto kSize = SkISize::Make(64, 64);
66 static constexpr auto kColorType = GrColorType::kRGBA_8888;
Robert Phillips84a81202016-11-04 11:59:10 -040067
Brian Salomon52e943a2018-03-13 09:32:39 -040068 {
Robert Phillips84a81202016-11-04 11:59:10 -040069 // External on-screen render target.
Brian Salomon4eb38b72019-08-05 12:58:39 -040070 sk_sp<GrSurfaceProxy> sProxy(make_wrapped_rt(proxyProvider, gpu, reporter, kSize,
71 kColorType, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050072 if (sProxy) {
73 // RenderTarget-only
74 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
75 REPORTER_ASSERT(reporter, rtProxy);
76 REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
77 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Brian Salomon52e943a2018-03-13 09:32:39 -040078 clean_up_wrapped_rt(gpu, std::move(sProxy));
Robert Phillips78d762d2018-01-23 16:57:35 -050079 }
Robert Phillips84a81202016-11-04 11:59:10 -040080 }
81
82 {
83 // Internal offscreen render target.
Brian Salomon2a4f9832018-03-03 22:43:43 -050084 sk_sp<GrSurfaceProxy> sProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -040085 make_offscreen_rt(proxyProvider, kSize, kColorType, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -050086 if (sProxy) {
87 // Both RenderTarget and Texture
88 GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
89 REPORTER_ASSERT(reporter, rtProxy);
90 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
91 REPORTER_ASSERT(reporter, tProxy);
92 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
93 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
94 }
Robert Phillips84a81202016-11-04 11:59:10 -040095 }
96
97 {
98 // Internal offscreen render target - but through GrTextureProxy
Brian Salomon4eb38b72019-08-05 12:58:39 -040099 sk_sp<GrSurfaceProxy> sProxy(make_texture(proxyProvider, kSize, kColorType,
100 GrRenderable::kYes, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500101 if (sProxy) {
102 // Both RenderTarget and Texture
103 GrTextureProxy* tProxy = sProxy->asTextureProxy();
104 REPORTER_ASSERT(reporter, tProxy);
105 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
106 REPORTER_ASSERT(reporter, rtProxy);
107 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
108 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
109 }
Robert Phillips84a81202016-11-04 11:59:10 -0400110 }
111
112 {
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400113 // force no-RT
Brian Salomon4eb38b72019-08-05 12:58:39 -0400114 sk_sp<GrSurfaceProxy> sProxy(make_texture(proxyProvider, kSize, kColorType,
115 GrRenderable::kNo, kBottomLeft_GrSurfaceOrigin));
Robert Phillips78d762d2018-01-23 16:57:35 -0500116 if (sProxy) {
117 // Texture-only
118 GrTextureProxy* tProxy = sProxy->asTextureProxy();
119 REPORTER_ASSERT(reporter, tProxy);
120 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
121 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
122 }
Robert Phillips84a81202016-11-04 11:59:10 -0400123 }
124}
125
126// Test converting between RenderTargetProxies and TextureProxies for deferred
127// Proxies
128DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
Robert Phillips0a15cc62019-07-30 12:49:10 -0400129 GrContext* context = ctxInfo.grContext();
130 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
131 const GrCaps* caps = context->priv().caps();
Robert Phillips84a81202016-11-04 11:59:10 -0400132
133 GrSurfaceDesc desc;
Robert Phillips84a81202016-11-04 11:59:10 -0400134 desc.fWidth = 64;
135 desc.fHeight = 64;
Robert Phillips84a81202016-11-04 11:59:10 -0400136
Robert Phillips0a15cc62019-07-30 12:49:10 -0400137 const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
138 GrRenderable::kYes);
Greg Daniel47c20e82020-01-21 14:29:57 -0500139 GrSwizzle swizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
Robert Phillips0a15cc62019-07-30 12:49:10 -0400140
Robert Phillips84a81202016-11-04 11:59:10 -0400141 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500142 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -0500143 format, desc, swizzle, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin,
144 GrMipMapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400145
146 // Both RenderTarget and Texture
Robert Phillips2f493142017-03-02 18:18:38 -0500147 GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500148 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400149 GrTextureProxy* tProxy = rtProxy->asTextureProxy();
150 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500151 REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
152 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400153 }
Robert Phillips26c90e02017-03-14 14:39:29 -0400154
Robert Phillips84a81202016-11-04 11:59:10 -0400155 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500156 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -0500157 format, desc, swizzle, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin,
158 GrMipMapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400159
160 // Both RenderTarget and Texture - but via GrTextureProxy
Robert Phillips2f493142017-03-02 18:18:38 -0500161 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500162 REPORTER_ASSERT(reporter, tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400163 GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
164 REPORTER_ASSERT(reporter, rtProxy);
Robert Phillips37430132016-11-09 06:50:43 -0500165 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
166 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400167 }
168
169 {
Brian Salomon2a4f9832018-03-03 22:43:43 -0500170 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -0500171 format, desc, swizzle, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin,
172 GrMipMapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
Robert Phillips84a81202016-11-04 11:59:10 -0400173 // Texture-only
Robert Phillips2f493142017-03-02 18:18:38 -0500174 GrTextureProxy* tProxy = proxy->asTextureProxy();
Robert Phillips37430132016-11-09 06:50:43 -0500175 REPORTER_ASSERT(reporter, tProxy);
176 REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
Robert Phillips84a81202016-11-04 11:59:10 -0400177 REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
178 }
179}