aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ResourceAllocatorTest.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-07-18 13:56:48 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-18 18:51:02 +0000
commit715d08c381b4cc8af33d7dcdefc9533dcc97e4c9 (patch)
tree328830165cfa268c5a6645e30088472836283a18 /tests/ResourceAllocatorTest.cpp
parent946c37057f2618af7eda34fd6d2dd8625a9e9b61 (diff)
Fix explicit allocation bug
Change-Id: I9866f563e02b2ab290cc46ede05f8eda21f6d3b2 Reviewed-on: https://skia-review.googlesource.com/142163 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tests/ResourceAllocatorTest.cpp')
-rw-r--r--tests/ResourceAllocatorTest.cpp74
1 files changed, 50 insertions, 24 deletions
diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp
index 51ecdb7ed0..852fe5aa33 100644
--- a/tests/ResourceAllocatorTest.cpp
+++ b/tests/ResourceAllocatorTest.cpp
@@ -30,7 +30,7 @@ struct ProxyParams {
// TODO: do we care about mipmapping
};
-static sk_sp<GrSurfaceProxy> make_deferred(GrProxyProvider* proxyProvider, const ProxyParams& p) {
+static GrSurfaceProxy* make_deferred(GrProxyProvider* proxyProvider, const ProxyParams& p) {
GrSurfaceDesc desc;
desc.fFlags = p.fIsRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
desc.fWidth = p.fSize;
@@ -38,11 +38,20 @@ static sk_sp<GrSurfaceProxy> make_deferred(GrProxyProvider* proxyProvider, const
desc.fConfig = p.fConfig;
desc.fSampleCnt = p.fSampleCnt;
- return proxyProvider->createProxy(desc, p.fOrigin, p.fFit, SkBudgeted::kNo);
+ auto tmp = proxyProvider->createProxy(desc, p.fOrigin, p.fFit, SkBudgeted::kNo);
+ if (!tmp) {
+ return nullptr;
+ }
+ GrSurfaceProxy* ret = tmp.release();
+
+ // Add a read to keep the proxy around but unref it so its backing surfaces can be recycled
+ ret->addPendingRead();
+ ret->unref();
+ return ret;
}
-static sk_sp<GrSurfaceProxy> make_backend(GrContext* context, const ProxyParams& p,
- GrBackendTexture* backendTex) {
+static GrSurfaceProxy* make_backend(GrContext* context, const ProxyParams& p,
+ GrBackendTexture* backendTex) {
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
GrGpu* gpu = context->contextPriv().getGpu();
@@ -50,7 +59,16 @@ static sk_sp<GrSurfaceProxy> make_backend(GrContext* context, const ProxyParams&
p.fConfig, false,
GrMipMapped::kNo);
- return proxyProvider->wrapBackendTexture(*backendTex, p.fOrigin);
+ auto tmp = proxyProvider->wrapBackendTexture(*backendTex, p.fOrigin);
+ if (!tmp) {
+ return nullptr;
+ }
+ GrSurfaceProxy* ret = tmp.release();
+
+ // Add a read to keep the proxy around but unref it so its backing surfaces can be recycled
+ ret->addPendingRead();
+ ret->unref();
+ return ret;
}
static void cleanup_backend(GrContext* context, const GrBackendTexture& backendTex) {
@@ -60,12 +78,11 @@ static void cleanup_backend(GrContext* context, const GrBackendTexture& backendT
// Basic test that two proxies with overlapping intervals and compatible descriptors are
// assigned different GrSurfaces.
static void overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider,
- sk_sp<GrSurfaceProxy> p1, sk_sp<GrSurfaceProxy> p2,
- bool expectedResult) {
+ GrSurfaceProxy* p1, GrSurfaceProxy* p2, bool expectedResult) {
GrResourceAllocator alloc(resourceProvider);
- alloc.addInterval(p1.get(), 0, 4);
- alloc.addInterval(p2.get(), 1, 2);
+ alloc.addInterval(p1, 0, 4);
+ alloc.addInterval(p2, 1, 2);
alloc.markEndOfOpList(0);
int startIndex, stopIndex;
@@ -83,12 +100,12 @@ static void overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resou
// Test various cases when two proxies do not have overlapping intervals.
// This mainly acts as a test of the ResourceAllocator's free pool.
static void non_overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider,
- sk_sp<GrSurfaceProxy> p1, sk_sp<GrSurfaceProxy> p2,
+ GrSurfaceProxy* p1, GrSurfaceProxy* p2,
bool expectedResult) {
GrResourceAllocator alloc(resourceProvider);
- alloc.addInterval(p1.get(), 0, 2);
- alloc.addInterval(p2.get(), 3, 5);
+ alloc.addInterval(p1, 0, 2);
+ alloc.addInterval(p2, 3, 5);
alloc.markEndOfOpList(0);
int startIndex, stopIndex;
@@ -149,10 +166,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
};
for (auto test : gOverlappingTests) {
- sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, test.fP1);
- sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, test.fP2);
- overlap_test(reporter, resourceProvider,
- std::move(p1), std::move(p2), test.fExpectation);
+ GrSurfaceProxy* p1 = make_deferred(proxyProvider, test.fP1);
+ GrSurfaceProxy* p2 = make_deferred(proxyProvider, test.fP2);
+ overlap_test(reporter, resourceProvider, p1, p2, test.fExpectation);
+ p1->completedRead();
+ p2->completedRead();
}
int k2 = ctxInfo.grContext()->contextPriv().caps()->getRenderTargetSampleCount(2, kRGBA);
@@ -188,13 +206,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
};
for (auto test : gNonOverlappingTests) {
- sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, test.fP1);
- sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, test.fP2);
+ GrSurfaceProxy* p1 = make_deferred(proxyProvider, test.fP1);
+ GrSurfaceProxy* p2 = make_deferred(proxyProvider, test.fP2);
+
if (!p1 || !p2) {
continue; // creation can fail (i.e., for msaa4 on iOS)
}
- non_overlap_test(reporter, resourceProvider,
- std::move(p1), std::move(p2), test.fExpectation);
+
+ non_overlap_test(reporter, resourceProvider, p1, p2, test.fExpectation);
+
+ p1->completedRead();
+ p2->completedRead();
}
{
@@ -204,10 +226,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
};
GrBackendTexture backEndTex;
- sk_sp<GrSurfaceProxy> p1 = make_backend(ctxInfo.grContext(), t[0].fP1, &backEndTex);
- sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, t[0].fP2);
- non_overlap_test(reporter, resourceProvider,
- std::move(p1), std::move(p2), t[0].fExpectation);
+ GrSurfaceProxy* p1 = make_backend(ctxInfo.grContext(), t[0].fP1, &backEndTex);
+ GrSurfaceProxy* p2 = make_deferred(proxyProvider, t[0].fP2);
+
+ non_overlap_test(reporter, resourceProvider, p1, p2, t[0].fExpectation);
+
+ p1->completedRead();
+ p2->completedRead();
+
cleanup_backend(ctxInfo.grContext(), backEndTex);
}