2016-11-04 15:59:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This is a GPU-backend specific test.
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2016-11-04 15:59:10 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2019-08-14 21:00:30 +00:00
|
|
|
#include "src/gpu/GrRenderTarget.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrRenderTargetProxy.h"
|
|
|
|
#include "src/gpu/GrSurfaceProxy.h"
|
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2016-11-04 15:59:10 +00:00
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider,
|
|
|
|
GrGpu* gpu,
|
|
|
|
skiatest::Reporter* reporter,
|
2019-08-05 16:58:39 +00:00
|
|
|
const SkISize& size,
|
2020-02-14 15:47:18 +00:00
|
|
|
GrColorType colorType) {
|
2019-08-05 16:58:39 +00:00
|
|
|
auto backendRT =
|
|
|
|
gpu->createTestingOnlyBackendRenderTarget(size.width(), size.height(), colorType);
|
2020-02-14 15:47:18 +00:00
|
|
|
return provider->wrapBackendRenderTarget(backendRT, colorType, nullptr, nullptr);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
|
2019-06-18 21:15:04 +00:00
|
|
|
SkASSERT(proxy->unique());
|
2018-07-31 21:25:29 +00:00
|
|
|
SkASSERT(proxy->peekRenderTarget());
|
|
|
|
GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget();
|
2018-03-13 13:32:39 +00:00
|
|
|
proxy.reset();
|
|
|
|
gpu->deleteTestingOnlyBackendRenderTarget(rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider,
|
2020-02-07 19:17:25 +00:00
|
|
|
SkISize dimensions,
|
2020-02-14 15:47:18 +00:00
|
|
|
GrColorType colorType) {
|
2020-02-07 19:17:25 +00:00
|
|
|
return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, GrRenderable::kYes,
|
2020-02-14 15:47:18 +00:00
|
|
|
1, SkBackingFit::kExact, SkBudgeted::kYes,
|
|
|
|
GrProtected::kNo);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
|
2020-02-07 19:17:25 +00:00
|
|
|
SkISize dimensions,
|
2019-08-05 16:58:39 +00:00
|
|
|
GrColorType colorType,
|
2020-02-14 15:47:18 +00:00
|
|
|
GrRenderable renderable) {
|
2020-02-07 19:17:25 +00:00
|
|
|
return provider->testingOnly_createInstantiatedProxy(dimensions, colorType, renderable, 1,
|
2020-02-14 15:47:18 +00:00
|
|
|
SkBackingFit::kExact, SkBudgeted::kYes,
|
|
|
|
GrProtected::kNo);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
// Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
|
|
|
|
GrGpu* gpu = ctxInfo.grContext()->priv().getGpu();
|
2016-11-04 15:59:10 +00:00
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
static constexpr auto kSize = SkISize::Make(64, 64);
|
|
|
|
static constexpr auto kColorType = GrColorType::kRGBA_8888;
|
2016-11-04 15:59:10 +00:00
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
{
|
2016-11-04 15:59:10 +00:00
|
|
|
// External on-screen render target.
|
2020-02-14 15:47:18 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(
|
|
|
|
make_wrapped_rt(proxyProvider, gpu, reporter, kSize, kColorType));
|
2018-01-23 21:57:35 +00:00
|
|
|
if (sProxy) {
|
|
|
|
// RenderTarget-only
|
|
|
|
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
|
|
|
REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
|
2018-03-13 13:32:39 +00:00
|
|
|
clean_up_wrapped_rt(gpu, std::move(sProxy));
|
2018-01-23 21:57:35 +00:00
|
|
|
}
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Internal offscreen render target.
|
2020-02-14 15:47:18 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_offscreen_rt(proxyProvider, kSize, kColorType));
|
2018-01-23 21:57:35 +00:00
|
|
|
if (sProxy) {
|
|
|
|
// Both RenderTarget and Texture
|
|
|
|
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
|
|
|
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
|
|
|
|
}
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Internal offscreen render target - but through GrTextureProxy
|
2020-02-14 15:47:18 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(
|
|
|
|
make_texture(proxyProvider, kSize, kColorType, GrRenderable::kYes));
|
2018-01-23 21:57:35 +00:00
|
|
|
if (sProxy) {
|
|
|
|
// Both RenderTarget and Texture
|
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
|
|
|
}
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-07-17 13:59:59 +00:00
|
|
|
// force no-RT
|
2020-02-14 15:47:18 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(
|
|
|
|
make_texture(proxyProvider, kSize, kColorType, GrRenderable::kNo));
|
2018-01-23 21:57:35 +00:00
|
|
|
if (sProxy) {
|
|
|
|
// Texture-only
|
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
|
|
|
|
}
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test converting between RenderTargetProxies and TextureProxies for deferred
|
|
|
|
// Proxies
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
|
2019-07-30 16:49:10 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
const GrCaps* caps = context->priv().caps();
|
2016-11-04 15:59:10 +00:00
|
|
|
|
2020-02-07 19:17:25 +00:00
|
|
|
static constexpr SkISize kDims = {64, 64};
|
2016-11-04 15:59:10 +00:00
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kYes);
|
2020-01-21 19:29:57 +00:00
|
|
|
GrSwizzle swizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
|
2019-07-30 16:49:10 +00:00
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
{
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2020-02-14 15:47:18 +00:00
|
|
|
format, kDims, swizzle, GrRenderable::kYes, 1, GrMipMapped::kNo,
|
|
|
|
SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture
|
2017-03-02 23:18:38 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
2017-03-14 18:39:29 +00:00
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
{
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2020-02-14 15:47:18 +00:00
|
|
|
format, kDims, swizzle, GrRenderable::kYes, 1, GrMipMapped::kNo,
|
|
|
|
SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture - but via GrTextureProxy
|
2017-03-02 23:18:38 +00:00
|
|
|
GrTextureProxy* tProxy = proxy->asTextureProxy();
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2020-02-14 15:47:18 +00:00
|
|
|
format, kDims, swizzle, GrRenderable::kNo, 1, GrMipMapped::kNo,
|
|
|
|
SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
|
2016-11-04 15:59:10 +00:00
|
|
|
// Texture-only
|
2017-03-02 23:18:38 +00:00
|
|
|
GrTextureProxy* tProxy = proxy->asTextureProxy();
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
|
|
|
|
}
|
|
|
|
}
|