2016-05-04 19:47:41 +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
|
|
|
|
#include "GrSurfaceProxy.h"
|
|
|
|
#include "GrTextureProxy.h"
|
2016-10-28 17:25:24 +00:00
|
|
|
#include "GrRenderTargetPriv.h"
|
2016-05-04 19:47:41 +00:00
|
|
|
#include "GrRenderTargetProxy.h"
|
|
|
|
|
2016-08-31 21:04:06 +00:00
|
|
|
// Check that the surface proxy's member vars are set as expected
|
2016-05-04 19:47:41 +00:00
|
|
|
static void check_surface(skiatest::Reporter* reporter,
|
|
|
|
GrSurfaceProxy* proxy,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
int width, int height,
|
2016-08-31 21:04:06 +00:00
|
|
|
GrPixelConfig config,
|
2016-11-11 17:38:40 +00:00
|
|
|
const GrGpuResource::UniqueID& uniqueID,
|
2016-11-02 14:23:32 +00:00
|
|
|
SkBudgeted budgeted) {
|
2016-05-04 19:47:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->origin() == origin);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->width() == width);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->height() == height);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->config() == config);
|
2016-11-11 17:38:40 +00:00
|
|
|
if (!uniqueID.isInvalid()) {
|
|
|
|
REPORTER_ASSERT(reporter, proxy->uniqueID().asUInt() == uniqueID.asUInt());
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
|
2016-08-31 21:04:06 +00:00
|
|
|
}
|
2016-11-02 14:23:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
|
2016-05-04 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_rendertarget(skiatest::Reporter* reporter,
|
2016-11-09 13:54:35 +00:00
|
|
|
const GrCaps& caps,
|
2016-05-04 19:47:41 +00:00
|
|
|
GrTextureProvider* provider,
|
|
|
|
GrRenderTargetProxy* rtProxy,
|
2016-11-02 14:23:32 +00:00
|
|
|
int numSamples,
|
2016-11-09 13:54:35 +00:00
|
|
|
SkBackingFit fit,
|
2016-11-11 17:38:40 +00:00
|
|
|
int expectedMaxWindowRects,
|
|
|
|
bool wasWrapped) {
|
2016-11-09 13:54:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
|
2016-11-02 14:23:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
|
|
|
|
|
2016-11-11 17:38:40 +00:00
|
|
|
GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
|
2016-05-04 19:47:41 +00:00
|
|
|
GrRenderTarget* rt = rtProxy->instantiate(provider);
|
|
|
|
REPORTER_ASSERT(reporter, rt);
|
|
|
|
|
2016-11-11 17:38:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
|
|
|
|
if (wasWrapped) {
|
|
|
|
// Wrapped resources share their uniqueID with the wrapping RenderTargetProxy
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
|
|
|
|
} else {
|
|
|
|
// Deferred resources should always have a different ID from their instantiated rendertarget
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
|
|
|
|
}
|
|
|
|
|
2016-05-04 19:47:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
|
|
|
|
if (SkBackingFit::kExact == fit) {
|
|
|
|
REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
|
|
|
|
REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
|
2016-11-11 17:38:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
|
2016-05-04 19:47:41 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
|
|
|
|
REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
|
|
|
|
rtProxy->isStencilBufferMultisampled());
|
|
|
|
REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
|
|
|
|
REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
|
2016-08-10 18:09:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled());
|
|
|
|
REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags());
|
2016-05-04 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_texture(skiatest::Reporter* reporter,
|
|
|
|
GrTextureProvider* provider,
|
|
|
|
GrTextureProxy* texProxy,
|
2016-11-11 17:38:40 +00:00
|
|
|
SkBackingFit fit,
|
|
|
|
bool wasWrapped) {
|
|
|
|
GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
|
2016-05-04 19:47:41 +00:00
|
|
|
GrTexture* tex = texProxy->instantiate(provider);
|
|
|
|
REPORTER_ASSERT(reporter, tex);
|
|
|
|
|
2016-11-11 17:38:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
|
|
|
|
if (wasWrapped) {
|
|
|
|
// Wrapped resources share their uniqueID with the wrapping TextureProxy
|
|
|
|
REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
|
|
|
|
} else {
|
|
|
|
// Deferred resources should always have a different ID from their instantiated texture
|
|
|
|
REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
|
|
|
|
}
|
|
|
|
|
2016-05-04 19:47:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
|
|
|
|
if (SkBackingFit::kExact == fit) {
|
|
|
|
REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
|
|
|
|
REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
|
|
|
|
REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-31 21:04:06 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
|
2016-11-02 14:23:32 +00:00
|
|
|
const GrCaps& caps = *ctxInfo.grContext()->caps();
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2016-11-11 17:38:40 +00:00
|
|
|
const GrGpuResource::UniqueID kInvalidResourceID = GrGpuResource::UniqueID::InvalidID();
|
|
|
|
|
2017-02-01 14:20:00 +00:00
|
|
|
int attempt = 0; // useful for debugging
|
|
|
|
|
2016-05-04 19:47:41 +00:00
|
|
|
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
|
2017-01-30 19:15:59 +00:00
|
|
|
for (auto widthHeight : { 100, 128, 1048576 }) {
|
2017-02-01 14:20:00 +00:00
|
|
|
for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
|
|
|
|
kETC1_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
|
2016-05-04 19:47:41 +00:00
|
|
|
for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
|
|
|
|
for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
|
2017-02-01 14:20:00 +00:00
|
|
|
for (auto numSamples : { 0, 4, 16, 128 }) {
|
2016-05-04 19:47:41 +00:00
|
|
|
GrSurfaceDesc desc;
|
2016-11-04 15:59:10 +00:00
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2016-05-04 19:47:41 +00:00
|
|
|
desc.fOrigin = origin;
|
|
|
|
desc.fWidth = widthHeight;
|
|
|
|
desc.fHeight = widthHeight;
|
|
|
|
desc.fConfig = config;
|
|
|
|
desc.fSampleCnt = numSamples;
|
|
|
|
|
2017-02-01 14:20:00 +00:00
|
|
|
{
|
|
|
|
sk_sp<GrTexture> tex;
|
|
|
|
if (SkBackingFit::kApprox == fit) {
|
2017-02-01 15:53:20 +00:00
|
|
|
tex.reset(provider->createApproxTexture(desc));
|
2017-02-01 14:20:00 +00:00
|
|
|
} else {
|
2017-02-01 15:53:20 +00:00
|
|
|
tex.reset(provider->createTexture(desc, budgeted));
|
2017-02-01 14:20:00 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(
|
2017-01-30 19:15:59 +00:00
|
|
|
caps, desc,
|
2016-11-02 14:23:32 +00:00
|
|
|
fit, budgeted));
|
2017-02-01 14:20:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(sProxy));
|
2017-01-30 19:15:59 +00:00
|
|
|
if (sProxy) {
|
|
|
|
REPORTER_ASSERT(reporter, sProxy->asRenderTargetProxy());
|
|
|
|
// This forces the proxy to compute and cache its
|
|
|
|
// pre-instantiation size guess. Later, when it is actually
|
|
|
|
// instantiated, it checks that the instantiated size is <= to
|
|
|
|
// the pre-computation. If the proxy never computed its
|
|
|
|
// pre-instantiation size then the check is skipped.
|
|
|
|
sProxy->gpuMemorySize();
|
|
|
|
|
|
|
|
check_surface(reporter, sProxy.get(), origin,
|
|
|
|
widthHeight, widthHeight, config,
|
|
|
|
kInvalidResourceID, budgeted);
|
|
|
|
check_rendertarget(reporter, caps, provider,
|
2017-02-01 14:20:00 +00:00
|
|
|
sProxy->asRenderTargetProxy(),
|
|
|
|
SkTMin(numSamples, caps.maxSampleCount()),
|
2017-01-30 19:15:59 +00:00
|
|
|
fit, caps.maxWindowRectangles(), false);
|
|
|
|
}
|
2016-05-04 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
desc.fFlags = kNone_GrSurfaceFlags;
|
2017-02-01 14:20:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
sk_sp<GrTexture> tex;
|
|
|
|
if (SkBackingFit::kApprox == fit) {
|
2017-02-01 15:53:20 +00:00
|
|
|
tex.reset(provider->createApproxTexture(desc));
|
2017-02-01 14:20:00 +00:00
|
|
|
} else {
|
2017-02-01 15:53:20 +00:00
|
|
|
tex.reset(provider->createTexture(desc, budgeted));
|
2017-02-01 14:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps,
|
|
|
|
desc,
|
|
|
|
fit,
|
|
|
|
budgeted));
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(sProxy));
|
|
|
|
if (sProxy) {
|
|
|
|
// This forces the proxy to compute and cache its pre-instantiation
|
|
|
|
// size guess. Later, when it is actually instantiated, it checks
|
|
|
|
// that the instantiated size is <= to the pre-computation.
|
|
|
|
// If the proxy never computed its pre-instantiation size then the
|
|
|
|
// check is skipped.
|
|
|
|
sProxy->gpuMemorySize();
|
|
|
|
|
|
|
|
check_surface(reporter, sProxy.get(), origin,
|
|
|
|
widthHeight, widthHeight, config,
|
|
|
|
kInvalidResourceID, budgeted);
|
|
|
|
check_texture(reporter, provider, sProxy->asTextureProxy(),
|
|
|
|
fit, false);
|
|
|
|
}
|
2017-01-30 19:15:59 +00:00
|
|
|
}
|
2017-02-01 14:20:00 +00:00
|
|
|
|
|
|
|
attempt++;
|
2016-05-04 19:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
|
2016-08-10 18:09:07 +00:00
|
|
|
const GrCaps& caps = *ctxInfo.grContext()->caps();
|
2016-05-04 19:47:41 +00:00
|
|
|
|
|
|
|
static const int kWidthHeight = 100;
|
|
|
|
|
|
|
|
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
|
|
|
|
for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
|
|
|
|
for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
|
|
|
|
for (auto numSamples: { 0, 4}) {
|
2016-08-10 18:09:07 +00:00
|
|
|
bool renderable = caps.isConfigRenderable(config, numSamples > 0);
|
2016-05-04 19:47:41 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fOrigin = origin;
|
|
|
|
desc.fWidth = kWidthHeight;
|
|
|
|
desc.fHeight = kWidthHeight;
|
|
|
|
desc.fConfig = config;
|
|
|
|
desc.fSampleCnt = numSamples;
|
|
|
|
|
2016-08-10 18:09:07 +00:00
|
|
|
// External on-screen render target.
|
|
|
|
if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
|
|
|
|
GrBackendRenderTargetDesc backendDesc;
|
|
|
|
backendDesc.fWidth = kWidthHeight;
|
|
|
|
backendDesc.fHeight = kWidthHeight;
|
|
|
|
backendDesc.fConfig = config;
|
|
|
|
backendDesc.fOrigin = origin;
|
|
|
|
backendDesc.fSampleCnt = numSamples;
|
|
|
|
backendDesc.fStencilBits = 8;
|
|
|
|
backendDesc.fRenderTargetHandle = 0;
|
|
|
|
|
|
|
|
sk_sp<GrRenderTarget> defaultFBO(
|
2016-11-02 14:23:32 +00:00
|
|
|
provider->wrapBackendRenderTarget(backendDesc));
|
2016-08-10 18:09:07 +00:00
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
|
|
|
|
check_surface(reporter, sProxy.get(), origin,
|
2016-11-02 14:23:32 +00:00
|
|
|
kWidthHeight, kWidthHeight, config,
|
|
|
|
defaultFBO->uniqueID(), SkBudgeted::kNo);
|
2016-11-09 13:54:35 +00:00
|
|
|
check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
|
2016-11-11 17:38:40 +00:00
|
|
|
numSamples, SkBackingFit::kExact, 0, true);
|
2016-08-10 18:09:07 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 19:47:41 +00:00
|
|
|
sk_sp<GrTexture> tex;
|
|
|
|
|
2016-08-10 18:09:07 +00:00
|
|
|
// Internal offscreen render target.
|
2016-05-04 19:47:41 +00:00
|
|
|
if (renderable) {
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
tex.reset(provider->createTexture(desc, budgeted));
|
|
|
|
sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt));
|
|
|
|
check_surface(reporter, sProxy.get(), origin,
|
2016-11-02 14:23:32 +00:00
|
|
|
kWidthHeight, kWidthHeight, config,
|
|
|
|
rt->uniqueID(), budgeted);
|
2016-11-09 13:54:35 +00:00
|
|
|
check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
|
|
|
|
numSamples, SkBackingFit::kExact,
|
2016-11-11 17:38:40 +00:00
|
|
|
caps.maxWindowRectangles(), true);
|
2016-05-04 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!tex) {
|
|
|
|
SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
|
|
|
|
desc.fSampleCnt = 0;
|
|
|
|
tex.reset(provider->createTexture(desc, budgeted));
|
|
|
|
}
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(tex));
|
|
|
|
check_surface(reporter, sProxy.get(), origin,
|
2016-11-02 14:23:32 +00:00
|
|
|
kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
|
2016-11-09 11:50:43 +00:00
|
|
|
check_texture(reporter, provider, sProxy->asTextureProxy(),
|
2016-11-11 17:38:40 +00:00
|
|
|
SkBackingFit::kExact, true);
|
2016-05-04 19:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|