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"
|
2017-06-15 18:01:04 +00:00
|
|
|
#include "GrGpuResourceRef.h"
|
2018-01-16 13:06:32 +00:00
|
|
|
#include "GrProxyProvider.h"
|
2016-11-16 19:17:17 +00:00
|
|
|
#include "GrRenderTargetProxy.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#include "GrResourceProvider.h"
|
|
|
|
#include "GrSurfaceProxy.h"
|
2017-06-13 16:44:56 +00:00
|
|
|
#include "GrTexture.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_deferred(GrProxyProvider* proxyProvider) {
|
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;
|
|
|
|
|
2018-03-04 03:43:43 +00:00
|
|
|
return proxyProvider->createProxy(desc, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox,
|
2018-03-16 20:47:25 +00:00
|
|
|
SkBudgeted::kYes, GrInternalSurfaceFlags::kNoPendingIO);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
static sk_sp<GrTextureProxy> make_wrapped(GrProxyProvider* proxyProvider) {
|
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;
|
|
|
|
|
2018-03-04 03:43:43 +00:00
|
|
|
return proxyProvider->createInstantiatedProxy(desc, kBottomLeft_GrSurfaceOrigin,
|
|
|
|
SkBackingFit::kExact, SkBudgeted::kNo);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
|
2018-01-16 13:06:32 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
|
2018-01-16 20:07:54 +00:00
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->contextPriv().resourceProvider();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
|
|
|
for (auto make : { make_deferred, make_wrapped }) {
|
|
|
|
// A single write
|
|
|
|
{
|
2018-01-16 13:06:32 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
|
|
|
GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fWrite(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
static const int kExpectedReads = 0;
|
|
|
|
static const int kExpectedWrites = 1;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
// In the deferred case, this checks that the refs transfered to the GrSurface
|
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
|
|
|
}
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A single read
|
|
|
|
{
|
2018-01-16 13:06:32 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
|
|
|
GrPendingIOResource<GrSurfaceProxy, kRead_GrIOType> fRead(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
static const int kExpectedReads = 1;
|
|
|
|
static const int kExpectedWrites = 0;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
// In the deferred case, this checks that the refs transfered to the GrSurface
|
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
|
|
|
}
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A single read/write pair
|
|
|
|
{
|
2018-01-16 13:06:32 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
|
|
|
GrPendingIOResource<GrSurfaceProxy, kRW_GrIOType> fRW(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
static const int kExpectedReads = 1;
|
|
|
|
static const int kExpectedWrites = 1;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
// In the deferred case, this checks that the refs transferred to the GrSurface
|
|
|
|
check_refs(reporter, proxy.get(), 1, 1, kExpectedReads, kExpectedWrites);
|
|
|
|
}
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Multiple normal refs
|
|
|
|
{
|
2018-01-16 13:06:32 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
|
|
|
proxy->ref();
|
|
|
|
proxy->ref();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
static const int kExpectedReads = 0;
|
|
|
|
static const int kExpectedWrites = 0;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 3,kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
// In the deferred case, this checks that the refs transferred to the GrSurface
|
|
|
|
check_refs(reporter, proxy.get(), 3, 3, kExpectedReads, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
proxy->unref();
|
|
|
|
proxy->unref();
|
|
|
|
}
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Continue using (reffing) proxy after instantiation
|
|
|
|
{
|
2018-01-16 13:06:32 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy((*make)(proxyProvider));
|
2017-09-20 21:51:59 +00:00
|
|
|
if (proxy.get()) {
|
|
|
|
proxy->ref();
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fWrite(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
static const int kExpectedWrites = 1;
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, 2, 0, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2018-01-16 13:06:32 +00:00
|
|
|
proxy->instantiate(resourceProvider);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
// In the deferred case, this checks that the refs transfered to the GrSurface
|
|
|
|
check_refs(reporter, proxy.get(), 2, 2, 0, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
proxy->unref();
|
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 0, kExpectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-09-20 21:51:59 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kRead_GrIOType> fRead(proxy.get());
|
|
|
|
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
|