2016-11-16 19:17:17 +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-03-30 12:02:11 +00:00
|
|
|
#include "GrContextPriv.h"
|
2016-11-16 19:17:17 +00:00
|
|
|
#include "GrRenderTargetPriv.h"
|
|
|
|
#include "GrRenderTargetProxy.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#include "GrResourceProvider.h"
|
|
|
|
#include "GrSurfaceProxy.h"
|
|
|
|
#include "GrTextureProxy.h"
|
2016-11-16 19:17:17 +00:00
|
|
|
|
|
|
|
int32_t GrIORefProxy::getProxyRefCnt_TestOnly() const {
|
|
|
|
return fRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GrIORefProxy::getBackingRefCnt_TestOnly() const {
|
|
|
|
if (fTarget) {
|
|
|
|
return fTarget->fRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GrIORefProxy::getPendingReadCnt_TestOnly() const {
|
|
|
|
if (fTarget) {
|
|
|
|
return fTarget->fPendingReads;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fPendingReads;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GrIORefProxy::getPendingWriteCnt_TestOnly() const {
|
|
|
|
if (fTarget) {
|
|
|
|
return fTarget->fPendingWrites;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fPendingWrites;
|
|
|
|
}
|
|
|
|
|
2017-02-28 21:30:28 +00:00
|
|
|
static const int kWidthHeight = 128;
|
|
|
|
|
2016-11-16 19:17:17 +00:00
|
|
|
static void check_refs(skiatest::Reporter* reporter,
|
2017-03-30 12:02:11 +00:00
|
|
|
GrTextureProxy* proxy,
|
2016-11-16 19:17:17 +00:00
|
|
|
int32_t expectedProxyRefs,
|
|
|
|
int32_t expectedBackingRefs,
|
|
|
|
int32_t expectedNumReads,
|
|
|
|
int32_t expectedNumWrites) {
|
|
|
|
REPORTER_ASSERT(reporter, proxy->getProxyRefCnt_TestOnly() == expectedProxyRefs);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->getBackingRefCnt_TestOnly() == expectedBackingRefs);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->getPendingReadCnt_TestOnly() == expectedNumReads);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->getPendingWriteCnt_TestOnly() == expectedNumWrites);
|
|
|
|
|
|
|
|
SkASSERT(proxy->getProxyRefCnt_TestOnly() == expectedProxyRefs);
|
|
|
|
SkASSERT(proxy->getBackingRefCnt_TestOnly() == expectedBackingRefs);
|
|
|
|
SkASSERT(proxy->getPendingReadCnt_TestOnly() == expectedNumReads);
|
|
|
|
SkASSERT(proxy->getPendingWriteCnt_TestOnly() == expectedNumWrites);
|
|
|
|
}
|
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_deferred(GrContext* context) {
|
2016-11-16 19:17:17 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = kWidthHeight;
|
|
|
|
desc.fHeight = kWidthHeight;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2017-03-28 20:21:27 +00:00
|
|
|
return GrSurfaceProxy::MakeDeferred(context->resourceProvider(), desc,
|
2017-04-17 18:18:34 +00:00
|
|
|
SkBackingFit::kApprox, SkBudgeted::kYes,
|
|
|
|
GrResourceProvider::kNoPendingIO_Flag);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_wrapped(GrContext* context) {
|
2016-11-16 19:17:17 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = kWidthHeight;
|
|
|
|
desc.fHeight = kWidthHeight;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2017-03-28 20:21:27 +00:00
|
|
|
sk_sp<GrTexture> tex(context->resourceProvider()->createTexture(desc, SkBudgeted::kNo));
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
return GrSurfaceProxy::MakeWrapped(std::move(tex));
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
|
2017-03-04 13:12:46 +00:00
|
|
|
GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
|
|
|
for (auto make : { make_deferred, make_wrapped }) {
|
|
|
|
// A single write
|
|
|
|
{
|
2017-03-30 12:02:11 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fWrite(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
static const int kExpectedReads = 0;
|
|
|
|
static const int kExpectedWrites = 1;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->instantiate(provider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
|
|
|
// In the deferred case, this checks that the refs transfered to the GrSurface
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A single read
|
|
|
|
{
|
2017-03-30 12:02:11 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kRead_GrIOType> fRead(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
static const int kExpectedReads = 1;
|
|
|
|
static const int kExpectedWrites = 0;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->instantiate(provider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
|
|
|
// In the deferred case, this checks that the refs transfered to the GrSurface
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A single read/write pair
|
|
|
|
{
|
2017-03-30 12:02:11 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kRW_GrIOType> fRW(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
static const int kExpectedReads = 1;
|
|
|
|
static const int kExpectedWrites = 1;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->instantiate(provider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2016-12-21 16:14:46 +00:00
|
|
|
// In the deferred case, this checks that the refs transferred to the GrSurface
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Multiple normal refs
|
|
|
|
{
|
2017-03-30 12:02:11 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
|
|
|
proxy->ref();
|
|
|
|
proxy->ref();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
static const int kExpectedReads = 0;
|
|
|
|
static const int kExpectedWrites = 0;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 3,kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->instantiate(provider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2016-12-21 16:14:46 +00:00
|
|
|
// In the deferred case, this checks that the refs transferred to the GrSurface
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 3, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->unref();
|
|
|
|
proxy->unref();
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Continue using (reffing) proxy after instantiation
|
|
|
|
{
|
2017-03-30 12:02:11 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
|
|
|
|
proxy->ref();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fWrite(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
static const int kExpectedWrites = 1;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, 2, 0, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->instantiate(provider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
|
|
|
// In the deferred case, this checks that the refs transfered to the GrSurface
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, 2, 0, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->unref();
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 0, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kRead_GrIOType> fRead(proxy.get());
|
2017-04-11 16:54:57 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 1, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-11 13:09:24 +00:00
|
|
|
|
|
|
|
#endif
|