Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: tests/ResourceCacheTest.cpp

Issue 1367533004: Make methods on GrGpuResource safe to call on abandoned resource (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrGpuResource.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ResourceCacheTest.cpp
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 6370b924909a150f70b414d4a14c99c5e598ff0a..a4dd2a5940bd66582a9283e3e4c185942020dfb1 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -1250,6 +1250,38 @@ static void test_custom_data(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132);
}
+static void test_abandoned(skiatest::Reporter* reporter) {
+ Mock mock(10, 300);
+ GrContext* context = mock.context();
+ TestResource* resource = new TestResource(context->getGpu());
+ context->abandonContext();
+
+ REPORTER_ASSERT(reporter, resource->wasDestroyed());
+
+ // Call all the public methods on resource in the abandoned state. They shouldn't crash.
+
+ int foo = 4132;
+ SkAutoTUnref<SkData> data(SkData::NewWithCopy(&foo, sizeof(foo)));
+ resource->setCustomData(data.get());
+ resource->getCustomData();
+ resource->getUniqueID();
+ resource->getUniqueKey();
+ resource->wasDestroyed();
+ resource->gpuMemorySize();
+ resource->getContext();
+
+ resource->abandon();
+ resource->resourcePriv().getScratchKey();
+ resource->resourcePriv().isBudgeted();
+ resource->resourcePriv().makeBudgeted();
+ resource->resourcePriv().makeUnbudgeted();
+ resource->resourcePriv().removeScratchKey();
+ GrUniqueKey key;
+ make_unique_key<0>(&key, 1);
+ resource->resourcePriv().setUniqueKey(key);
+ resource->resourcePriv().removeUniqueKey();
+}
+
////////////////////////////////////////////////////////////////////////////////
DEF_GPUTEST(ResourceCache, reporter, factory) {
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
@@ -1290,6 +1322,7 @@ DEF_GPUTEST(ResourceCache, reporter, factory) {
test_flush(reporter);
test_large_resource_count(reporter);
test_custom_data(reporter);
+ test_abandoned(reporter);
}
#endif
« no previous file with comments | « src/gpu/GrGpuResource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698