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.
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
|
2017-05-01 13:50:58 +00:00
|
|
|
#include "GrBackendSurface.h"
|
2018-01-08 18:40:32 +00:00
|
|
|
#include "GrContextPriv.h"
|
2018-03-13 13:32:39 +00:00
|
|
|
#include "GrGpu.h"
|
2018-01-16 13:06:32 +00:00
|
|
|
#include "GrProxyProvider.h"
|
2017-06-15 18:01:04 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#include "GrRenderTargetProxy.h"
|
2016-11-04 15:59:10 +00:00
|
|
|
#include "GrSurfaceProxy.h"
|
2017-06-13 16:44:56 +00:00
|
|
|
#include "GrTexture.h"
|
2016-11-04 15:59:10 +00:00
|
|
|
#include "GrTextureProxy.h"
|
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider,
|
|
|
|
GrGpu* gpu,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
const GrSurfaceDesc& desc,
|
|
|
|
GrSurfaceOrigin origin) {
|
|
|
|
// We don't currently have a way of making MSAA backend render targets.
|
|
|
|
SkASSERT(1 == desc.fSampleCnt);
|
|
|
|
GrSRGBEncoded srgbEncoded;
|
|
|
|
auto ct = GrPixelConfigToColorTypeAndEncoding(desc.fConfig, &srgbEncoded);
|
2018-08-09 14:55:09 +00:00
|
|
|
auto backendRT = gpu->createTestingOnlyBackendRenderTarget(desc.fWidth, desc.fHeight, ct);
|
2018-03-07 19:39:54 +00:00
|
|
|
return provider->wrapBackendRenderTarget(backendRT, origin);
|
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) {
|
|
|
|
SkASSERT(proxy->isUnique_debugOnly());
|
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,
|
|
|
|
const GrSurfaceDesc& desc,
|
|
|
|
GrSurfaceOrigin origin) {
|
2016-11-04 15:59:10 +00:00
|
|
|
SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
|
|
|
|
|
2018-09-27 15:28:03 +00:00
|
|
|
return provider->testingOnly_createInstantiatedProxy(desc, origin, SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kYes);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
|
|
|
|
const GrSurfaceDesc& desc,
|
|
|
|
GrSurfaceOrigin origin) {
|
2018-09-27 15:28:03 +00:00
|
|
|
return provider->testingOnly_createInstantiatedProxy(desc, origin, SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kYes);
|
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) {
|
2018-01-16 13:06:32 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
|
2018-03-13 13:32:39 +00:00
|
|
|
GrGpu* gpu = ctxInfo.grContext()->contextPriv().getGpu();
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = 64;
|
|
|
|
desc.fHeight = 64;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2018-03-13 13:32:39 +00:00
|
|
|
{
|
2016-11-04 15:59:10 +00:00
|
|
|
// External on-screen render target.
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(
|
2018-03-13 13:32:39 +00:00
|
|
|
make_wrapped_rt(proxyProvider, gpu, reporter, desc, kBottomLeft_GrSurfaceOrigin));
|
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.
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(
|
2018-03-13 13:32:39 +00:00
|
|
|
make_offscreen_rt(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
|
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
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(
|
2018-03-13 13:32:39 +00:00
|
|
|
make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
|
|
|
|
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(
|
2018-03-13 13:32:39 +00:00
|
|
|
make_texture(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
|
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) {
|
2018-01-08 18:40:32 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = 64;
|
|
|
|
desc.fHeight = 64;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
|
|
|
{
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2018-11-14 15:28:10 +00:00
|
|
|
desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
|
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(
|
2018-11-14 15:28:10 +00:00
|
|
|
desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
|
|
|
|
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2018-11-14 15:28:10 +00:00
|
|
|
desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
|
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());
|
|
|
|
}
|
|
|
|
}
|