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) {
|
|
|
|
SkASSERT(!fPendingReads);
|
|
|
|
return fTarget->fPendingReads;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fPendingReads;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GrIORefProxy::getPendingWriteCnt_TestOnly() const {
|
|
|
|
if (fTarget) {
|
|
|
|
SkASSERT(!fPendingWrites);
|
|
|
|
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-02-28 21:30:28 +00:00
|
|
|
SkBackingFit::kApprox, SkBudgeted::kYes);
|
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-03-30 12:02:11 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(tex));
|
|
|
|
|
2016-11-16 19:17:17 +00:00
|
|
|
// Flush the IOWrite from the initial discard or it will confuse the later ref count checks
|
2017-03-30 12:02:11 +00:00
|
|
|
context->contextPriv().flushSurfaceWrites(proxy.get());
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
return proxy;
|
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
|
|
|
const GrCaps& caps = *ctxInfo.grContext()->caps();
|
|
|
|
|
2017-02-21 14:49:20 +00:00
|
|
|
// Currently the op itself takes a pending write and the render target op list does as well.
|
|
|
|
static const int kWritesForDiscard = 2;
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 0, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2016-12-21 16:14:46 +00:00
|
|
|
// In the deferred case, the discard op created on instantiation adds an
|
2016-11-16 19:17:17 +00:00
|
|
|
// extra ref and write
|
2017-03-30 12:02:11 +00:00
|
|
|
bool proxyGetsDiscardRef = !proxy->isWrapped_ForTesting() &&
|
2016-11-16 19:17:17 +00:00
|
|
|
caps.discardRenderTargetSupport();
|
2017-02-21 14:49:20 +00:00
|
|
|
int expectedWrites = 1 + (proxyGetsDiscardRef ? kWritesForDiscard : 0);
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 0, expectedWrites);
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 1, 0);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2016-12-21 16:14:46 +00:00
|
|
|
// In the deferred case, the discard op created on instantiation adds an
|
2016-11-16 19:17:17 +00:00
|
|
|
// extra ref and write
|
2017-03-30 12:02:11 +00:00
|
|
|
bool proxyGetsDiscardRef = !proxy->isWrapped_ForTesting() &&
|
2016-11-16 19:17:17 +00:00
|
|
|
caps.discardRenderTargetSupport();
|
2017-02-21 14:49:20 +00:00
|
|
|
int expectedWrites = proxyGetsDiscardRef ? kWritesForDiscard : 0;
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 1, expectedWrites);
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 1, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2016-12-21 16:14:46 +00:00
|
|
|
// In the deferred case, the discard op created on instantiation adds an
|
2016-11-16 19:17:17 +00:00
|
|
|
// extra ref and write
|
2017-03-30 12:02:11 +00:00
|
|
|
bool proxyGetsDiscardRef = !proxy->isWrapped_ForTesting() &&
|
2016-11-16 19:17:17 +00:00
|
|
|
caps.discardRenderTargetSupport();
|
2017-02-21 14:49:20 +00:00
|
|
|
int expectedWrites = 1 + (proxyGetsDiscardRef ? kWritesForDiscard : 0);
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 1, expectedWrites);
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 3, 0, 0);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
bool proxyGetsDiscardRef = !proxy->isWrapped_ForTesting() &&
|
2016-11-16 19:17:17 +00:00
|
|
|
caps.discardRenderTargetSupport();
|
2017-02-21 14:49:20 +00:00
|
|
|
int expectedWrites = proxyGetsDiscardRef ? kWritesForDiscard : 0;
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 3, 3, 0, expectedWrites);
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, 2, 0, 1);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
bool proxyGetsDiscardRef = !proxy->isWrapped_ForTesting() &&
|
2016-11-16 19:17:17 +00:00
|
|
|
caps.discardRenderTargetSupport();
|
2017-02-21 14:49:20 +00:00
|
|
|
int expectedWrites = 1 + (proxyGetsDiscardRef ? kWritesForDiscard : 0);
|
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-03-30 12:02:11 +00:00
|
|
|
check_refs(reporter, proxy.get(), 2, 2, 0, expectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
proxy->unref();
|
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 0, expectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
|
2017-03-30 12:02:11 +00:00
|
|
|
GrPendingIOResource<GrSurfaceProxy, kRead_GrIOType> fRead(proxy.get());
|
|
|
|
check_refs(reporter, proxy.get(), 1, 1, 1, expectedWrites);
|
2016-11-16 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 21:30:28 +00:00
|
|
|
#endif
|