diff options
author | Brian Osman <brianosman@google.com> | 2017-03-10 13:59:15 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-10 19:38:37 +0000 |
commit | cccda60aca592d2320d79e2871e057778b2688ab (patch) | |
tree | cd61c576ec6ae1e85a08ab36d27392eca1d098bb /tests | |
parent | dc175eaab60f7399fd3d232d2911511be187c436 (diff) |
Treat cross context images as Ganesh-created resources
Always create them budgeted, and register them with the cache (not as
wrapped resources).
BUG=skia:
Change-Id: Id18ecf6e9e512db4be21b4f2bfd8e8c060bbe805
Reviewed-on: https://skia-review.googlesource.com/9497
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CrossContextImageTest.cpp | 17 | ||||
-rw-r--r-- | tests/ResourceCacheTest.cpp | 21 |
2 files changed, 34 insertions, 4 deletions
diff --git a/tests/CrossContextImageTest.cpp b/tests/CrossContextImageTest.cpp index e37b095c93..82eb2d591e 100644 --- a/tests/CrossContextImageTest.cpp +++ b/tests/CrossContextImageTest.cpp @@ -140,9 +140,24 @@ DEF_GPUTEST(CrossContextImage_SharedContextSameThread, reporter, /*factory*/) { REPORTER_ASSERT(reporter, ccid != nullptr); ContextInfo info2 = factory.getSharedContextInfo(info.grContext()); - auto image = SkImage::MakeFromCrossContextImageData(info2.grContext(), std::move(ccid)); + GrContext* ctx2 = info2.grContext(); + int resourceCountBefore = 0, resourceCountAfter = 0; + size_t resourceBytesBefore = 0, resourceBytesAfter = 0; + if (ctx2) { + ctx2->getResourceCacheUsage(&resourceCountBefore, &resourceBytesBefore); + } + + auto image = SkImage::MakeFromCrossContextImageData(ctx2, std::move(ccid)); REPORTER_ASSERT(reporter, image != nullptr); + if (ctx2) { + // MakeFromCrossContextImageData should have imported the texture back into our + // cache, so we should see an uptick. + ctx2->getResourceCacheUsage(&resourceCountAfter, &resourceBytesAfter); + REPORTER_ASSERT(reporter, resourceCountAfter == resourceCountBefore + 1); + REPORTER_ASSERT(reporter, resourceBytesAfter > resourceBytesBefore); + } + // JPEG encode -> decode won't round trip the image perfectly assert_equal(reporter, testImage.get(), image.get(), SkEncodedImageFormat::kJPEG == format ? 2 : 0); diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index a2064ae557..24545369cb 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -208,12 +208,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI return; } - GrBackendObject texHandles[2]; + GrBackendObject texHandles[3]; static const int kW = 100; static const int kH = 100; texHandles[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig); texHandles[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig); + texHandles[2] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig); context->resetContext(); @@ -230,26 +231,40 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI sk_sp<GrTexture> adopted(context->resourceProvider()->wrapBackendTexture( desc, kAdopt_GrWrapOwnership)); - REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); - if (!borrowed || !adopted) { + desc.fTextureHandle = texHandles[2]; + sk_sp<GrTexture> adoptedAndCached(context->resourceProvider()->wrapBackendTexture( + desc, kAdoptAndCache_GrWrapOwnership)); + + REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr && + adoptedAndCached != nullptr); + if (!borrowed || !adopted || !adoptedAndCached) { return; } borrowed.reset(nullptr); adopted.reset(nullptr); + adoptedAndCached.reset(nullptr); context->flush(); bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[0]); bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[1]); + bool adoptedAndCachedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[2]); REPORTER_ASSERT(reporter, borrowedIsAlive); REPORTER_ASSERT(reporter, !adoptedIsAlive); + REPORTER_ASSERT(reporter, adoptedAndCachedIsAlive); // Still alive because it's in the cache gpu->deleteTestingOnlyBackendTexture(texHandles[0], !borrowedIsAlive); gpu->deleteTestingOnlyBackendTexture(texHandles[1], !adoptedIsAlive); + // We can't delete texHandles[2] - we've given control of the lifetime to the context/cache context->resetContext(); + + // Purge the cache. This should force texHandles[2] to be deleted + context->getResourceCache()->purgeAllUnlocked(); + adoptedAndCachedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[2]); + REPORTER_ASSERT(reporter, !adoptedAndCachedIsAlive); } class TestResource : public GrGpuResource { |