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"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2017-05-01 13:50:58 +00:00
|
|
|
#include "GrBackendSurface.h"
|
2017-06-15 18:01:04 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#include "GrRenderTargetProxy.h"
|
|
|
|
#include "GrResourceProvider.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"
|
|
|
|
|
2017-03-04 13:12:46 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider,
|
2016-11-09 11:50:43 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
const GrSurfaceDesc& desc) {
|
2017-05-01 13:50:58 +00:00
|
|
|
GrGLFramebufferInfo fboInfo;
|
|
|
|
fboInfo.fFBOID = 0;
|
|
|
|
GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
|
|
|
|
desc.fConfig, fboInfo);
|
|
|
|
|
2017-08-29 12:26:54 +00:00
|
|
|
sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT));
|
2016-11-04 15:59:10 +00:00
|
|
|
SkASSERT(!defaultFBO->asTexture());
|
|
|
|
|
2017-07-25 14:16:35 +00:00
|
|
|
return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO), desc.fOrigin);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 13:12:46 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrResourceProvider* provider,
|
2016-11-09 11:50:43 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
const GrSurfaceDesc& desc,
|
|
|
|
SkBudgeted budgeted) {
|
2016-11-04 15:59:10 +00:00
|
|
|
SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
|
|
|
|
|
|
|
|
sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
|
|
|
|
|
2017-07-25 14:16:35 +00:00
|
|
|
return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 13:12:46 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrResourceProvider* provider,
|
2016-11-04 15:59:10 +00:00
|
|
|
const GrSurfaceDesc& desc,
|
|
|
|
SkBudgeted budgeted) {
|
|
|
|
sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
|
|
|
|
|
2017-07-25 14:16:35 +00:00
|
|
|
return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test converting between RenderTargetProxies and TextureProxies for wrapped
|
|
|
|
// Proxies
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
|
2017-03-04 13:12:46 +00:00
|
|
|
GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
|
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;
|
2017-05-01 13:50:58 +00:00
|
|
|
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
if (kOpenGL_GrBackend == ctxInfo.backend()) {
|
|
|
|
// External on-screen render target.
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// RenderTarget-only
|
2016-11-09 11:50:43 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Internal offscreen render target.
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider,
|
|
|
|
reporter, desc,
|
|
|
|
SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture
|
2016-11-09 11:50:43 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Internal offscreen render target - but through GrTextureProxy
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture
|
2016-11-09 11:50:43 +00:00
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
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
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Texture-only
|
2016-11-09 11:50:43 +00:00
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test converting between RenderTargetProxies and TextureProxies for deferred
|
|
|
|
// Proxies
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
|
2017-03-04 13:12:46 +00:00
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->resourceProvider();
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2017-07-27 20:16:25 +00:00
|
|
|
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
2016-11-04 15:59:10 +00:00
|
|
|
desc.fWidth = 64;
|
|
|
|
desc.fHeight = 64;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
|
|
|
{
|
2017-03-14 18:39:29 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
|
2017-03-02 23:18:38 +00:00
|
|
|
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
|
|
|
{
|
2017-03-14 18:39:29 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
|
2017-03-02 23:18:38 +00:00
|
|
|
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
|
2017-07-27 20:16:25 +00:00
|
|
|
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
|
2016-11-04 15:59:10 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
|
2017-03-02 23:18:38 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|