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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 134363002: Revert of Delete all invalidated resources with same key (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrResourceCache.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 9
10 // This is a GPU test 10 // This is a GPU test
11 #if SK_SUPPORT_GPU 11 #if SK_SUPPORT_GPU
12 #include "GrContextFactory.h" 12 #include "GrContextFactory.h"
13 #include "GrResourceCache.h"
14 #include "SkGpuDevice.h" 13 #include "SkGpuDevice.h"
15 14
16 static const int gWidth = 640; 15 static const int gWidth = 640;
17 static const int gHeight = 480; 16 static const int gHeight = 480;
18 17
19 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
20 static void test_cache(skiatest::Reporter* reporter, 19 static void test_cache(skiatest::Reporter* reporter,
21 GrContext* context, 20 GrContext* context,
22 SkCanvas* canvas) { 21 SkCanvas* canvas) {
23 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); 22 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight);
(...skipping 28 matching lines...) Expand all
52 51
53 size_t curCacheSize = context->getGpuTextureCacheBytes(); 52 size_t curCacheSize = context->getGpuTextureCacheBytes();
54 53
55 // we should never go over the size limit 54 // we should never go over the size limit
56 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); 55 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize);
57 } 56 }
58 57
59 context->setTextureCacheLimits(oldMaxNum, oldMaxBytes); 58 context->setTextureCacheLimits(oldMaxNum, oldMaxBytes);
60 } 59 }
61 60
62 class TestResource : public GrResource {
63 public:
64 SK_DECLARE_INST_COUNT(TestResource);
65 explicit TestResource(GrGpu* gpu)
66 : INHERITED(gpu, false)
67 , fCache(NULL)
68 , fToDelete(NULL) {
69 ++fAlive;
70 }
71
72 ~TestResource() {
73 --fAlive;
74 if (NULL != fToDelete) {
75 // Breaks our little 2-element cycle below.
76 fToDelete->setDeleteWhenDestroyed(NULL, NULL);
77 fCache->deleteResource(fToDelete->getCacheEntry());
78 }
79 this->release();
80 }
81
82 size_t sizeInBytes() const SK_OVERRIDE { return 100; }
83
84 static int alive() { return fAlive; }
85
86 void setDeleteWhenDestroyed(GrResourceCache* cache, TestResource* resource) {
87 fCache = cache;
88 fToDelete = resource;
89 }
90
91 private:
92 GrResourceCache* fCache;
93 TestResource* fToDelete;
94 static int fAlive;
95
96 typedef GrResource INHERITED;
97 };
98 SK_DEFINE_INST_COUNT(TestResource);
99 int TestResource::fAlive = 0;
100
101 static void test_purge_invalidated(skiatest::Reporter* reporter, GrContext* cont ext) {
102 GrCacheID::Domain domain = GrCacheID::GenerateDomain();
103 GrCacheID::Key keyData;
104 keyData.fData64[0] = 5;
105 keyData.fData64[1] = 18;
106 GrResourceKey::ResourceType t = GrResourceKey::GenerateResourceType();
107 GrResourceKey key(GrCacheID(domain, keyData), t, 0);
108
109 GrResourceCache cache(5, 30000);
110
111 // Add two resources with the same key that delete each other from the cache when destroyed.
112 TestResource* a = new TestResource(context->getGpu());
113 TestResource* b = new TestResource(context->getGpu());
114 cache.addResource(key, a);
115 cache.addResource(key, b);
116 // Circle back.
117 a->setDeleteWhenDestroyed(&cache, b);
118 b->setDeleteWhenDestroyed(&cache, a);
119 a->unref();
120 b->unref();
121
122 // Add a third independent resource also with the same key.
123 GrResource* r = new TestResource(context->getGpu());
124 cache.addResource(key, r);
125 r->unref();
126
127 // Invalidate all three, all three should be purged and destroyed.
128 REPORTER_ASSERT(reporter, 3 == TestResource::alive());
129 const GrResourceInvalidatedMessage msg = { key };
130 SkMessageBus<GrResourceInvalidatedMessage>::Post(msg);
131 cache.purgeAsNeeded();
132 REPORTER_ASSERT(reporter, 0 == TestResource::alive());
133 }
134
135 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
136 static void TestResourceCache(skiatest::Reporter* reporter, GrContextFactory* fa ctory) { 62 static void TestResourceCache(skiatest::Reporter* reporter, GrContextFactory* fa ctory) {
137 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { 63 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
138 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); 64 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type);
139 if (!GrContextFactory::IsRenderingGLContext(glType)) { 65 if (!GrContextFactory::IsRenderingGLContext(glType)) {
140 continue; 66 continue;
141 } 67 }
142 GrContext* context = factory->get(glType); 68 GrContext* context = factory->get(glType);
143 if (NULL == context) { 69 if (NULL == context) {
144 continue; 70 continue;
145 } 71 }
146 72
147 GrTextureDesc desc; 73 GrTextureDesc desc;
148 desc.fConfig = kSkia8888_GrPixelConfig; 74 desc.fConfig = kSkia8888_GrPixelConfig;
149 desc.fFlags = kRenderTarget_GrTextureFlagBit; 75 desc.fFlags = kRenderTarget_GrTextureFlagBit;
150 desc.fWidth = gWidth; 76 desc.fWidth = gWidth;
151 desc.fHeight = gHeight; 77 desc.fHeight = gHeight;
152 78
153 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NUL L, 0)); 79 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NUL L, 0));
154 SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (context, textu re.get()))); 80 SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (context, textu re.get())));
155 SkCanvas canvas(device.get()); 81 SkCanvas canvas(device.get());
156 82
157 test_cache(reporter, context, &canvas); 83 test_cache(reporter, context, &canvas);
158 test_purge_invalidated(reporter, context);
159 } 84 }
160 } 85 }
161 86
162 //////////////////////////////////////////////////////////////////////////////// 87 ////////////////////////////////////////////////////////////////////////////////
163 #include "TestClassDef.h" 88 #include "TestClassDef.h"
164 DEFINE_GPUTESTCLASS("ResourceCache", ResourceCacheTestClass, TestResourceCache) 89 DEFINE_GPUTESTCLASS("ResourceCache", ResourceCacheTestClass, TestResourceCache)
165 90
166 #endif 91 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698