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

Side by Side Diff: tests/GpuLayerCacheTest.cpp

Issue 411703003: Add plot-based purging to GrLayerCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Respond to code review comments Created 6 years, 4 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
« no previous file with comments | « src/gpu/SkGpuDevice.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 2014 Google Inc. 2 * Copyright 2014 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 #if SK_SUPPORT_GPU 8 #if SK_SUPPORT_GPU
9 9
10 #include "GrContext.h" 10 #include "GrContext.h"
11 #include "GrContextFactory.h" 11 #include "GrContextFactory.h"
12 #include "GrLayerCache.h" 12 #include "GrLayerCache.h"
13 #include "SkPictureRecorder.h" 13 #include "SkPictureRecorder.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 static const int kNumLayers = 5;
17
18 class TestingAccess { 16 class TestingAccess {
19 public: 17 public:
20 static int NumLayers(GrLayerCache* cache) { 18 static int NumLayers(GrLayerCache* cache) {
21 return cache->numLayers(); 19 return cache->numLayers();
22 } 20 }
23 static void Purge(GrLayerCache* cache, uint32_t pictureID) { 21 static void Purge(GrLayerCache* cache, uint32_t pictureID) {
24 cache->purge(pictureID); 22 cache->purge(pictureID);
25 } 23 }
26 }; 24 };
27 25
28 // Add several layers to the cache 26 // Add several layers to the cache
29 static void create_layers(skiatest::Reporter* reporter, 27 static void create_layers(skiatest::Reporter* reporter,
30 GrLayerCache* cache, 28 GrLayerCache* cache,
31 const SkPicture& picture) { 29 const SkPicture& picture,
32 GrCachedLayer* layers[kNumLayers]; 30 int numToAdd,
31 int idOffset) {
33 32
34 for (int i = 0; i < kNumLayers; ++i) { 33 for (int i = 0; i < numToAdd; ++i) {
35 layers[i] = cache->findLayerOrCreate(&picture, i); 34 GrCachedLayer* layer = cache->findLayerOrCreate(&picture, idOffset+i);
36 REPORTER_ASSERT(reporter, NULL != layers[i]); 35 REPORTER_ASSERT(reporter, NULL != layer);
37 GrCachedLayer* layer = cache->findLayer(&picture, i); 36 GrCachedLayer* temp = cache->findLayer(&picture, idOffset+i);
38 REPORTER_ASSERT(reporter, layer == layers[i]); 37 REPORTER_ASSERT(reporter, temp == layer);
39 38
40 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == i + 1); 39 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1);
41 40
42 REPORTER_ASSERT(reporter, picture.uniqueID() == layers[i]->pictureID()); 41 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID());
43 REPORTER_ASSERT(reporter, layers[i]->layerID() == i); 42 REPORTER_ASSERT(reporter, layer->layerID() == idOffset + i);
44 REPORTER_ASSERT(reporter, NULL == layers[i]->texture()); 43 REPORTER_ASSERT(reporter, NULL == layer->texture());
45 REPORTER_ASSERT(reporter, !layers[i]->isAtlased()); 44 REPORTER_ASSERT(reporter, !layer->isAtlased());
46 } 45 }
47 46
48 cache->trackPicture(&picture); 47 cache->trackPicture(&picture);
49 } 48 }
50 49
50 static void lock_layer(skiatest::Reporter* reporter,
51 GrLayerCache* cache,
52 GrCachedLayer* layer) {
53 // Make the layer 512x512 (so it can be atlased)
54 GrTextureDesc desc;
55 desc.fWidth = 512;
56 desc.fHeight = 512;
57 desc.fConfig = kSkia8888_GrPixelConfig;
58
59 bool foundInCache = cache->lock(layer, desc);
60 REPORTER_ASSERT(reporter, !foundInCache);
61
62 foundInCache = cache->lock(layer, desc);
63 REPORTER_ASSERT(reporter, foundInCache);
64
65 REPORTER_ASSERT(reporter, NULL != layer->texture());
66 REPORTER_ASSERT(reporter, layer->locked());
67 }
68
51 // This test case exercises the public API of the GrLayerCache class. 69 // This test case exercises the public API of the GrLayerCache class.
52 // In particular it checks its interaction with the resource cache (w.r.t. 70 // In particular it checks its interaction with the resource cache (w.r.t.
53 // locking & unlocking textures). 71 // locking & unlocking textures).
54 // TODO: need to add checks on VRAM usage! 72 // TODO: need to add checks on VRAM usage!
55 DEF_GPUTEST(GpuLayerCache, reporter, factory) { 73 DEF_GPUTEST(GpuLayerCache, reporter, factory) {
74 static const int kInitialNumLayers = 5;
75
56 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 76 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
57 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; 77 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
58 78
59 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 79 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
60 continue; 80 continue;
61 } 81 }
62 82
63 GrContext* context = factory->get(glCtxType); 83 GrContext* context = factory->get(glCtxType);
64 84
65 if (NULL == context) { 85 if (NULL == context) {
66 continue; 86 continue;
67 } 87 }
68 88
69 SkPictureRecorder recorder; 89 SkPictureRecorder recorder;
70 recorder.beginRecording(1, 1); 90 recorder.beginRecording(1, 1);
71 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 91 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
72 92
73 GrLayerCache cache(context); 93 GrLayerCache cache(context);
74 94
75 create_layers(reporter, &cache, *picture); 95 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
76 96
77 // Lock the layers making them all 512x512 97 for (int i = 0; i < kInitialNumLayers; ++i) {
78 GrTextureDesc desc;
79 desc.fWidth = 512;
80 desc.fHeight = 512;
81 desc.fConfig = kSkia8888_GrPixelConfig;
82
83 for (int i = 0; i < kNumLayers; ++i) {
84 GrCachedLayer* layer = cache.findLayer(picture, i); 98 GrCachedLayer* layer = cache.findLayer(picture, i);
85 REPORTER_ASSERT(reporter, NULL != layer); 99 REPORTER_ASSERT(reporter, NULL != layer);
86 100
87 bool foundInCache = cache.lock(layer, desc); 101 lock_layer(reporter, &cache, layer);
88 REPORTER_ASSERT(reporter, !foundInCache);
89 foundInCache = cache.lock(layer, desc);
90 REPORTER_ASSERT(reporter, foundInCache);
91 102
92 REPORTER_ASSERT(reporter, NULL != layer->texture());
93 #if USE_ATLAS 103 #if USE_ATLAS
94 // The first 4 layers should be in the atlas (and thus have non-empt y 104 // The first 4 layers should be in the atlas (and thus have non-empt y
95 // rects) 105 // rects)
96 if (i < 4) { 106 if (i < 4) {
97 REPORTER_ASSERT(reporter, layer->isAtlased()); 107 REPORTER_ASSERT(reporter, layer->isAtlased());
98 } else { 108 } else {
99 #endif 109 #endif
100 REPORTER_ASSERT(reporter, !layer->isAtlased()); 110 // The 5th layer couldn't fit in the atlas
111 REPORTER_ASSERT(reporter, !layer->isAtlased());
101 #if USE_ATLAS 112 #if USE_ATLAS
102 } 113 }
103 #endif 114 #endif
104 } 115 }
105 116
106 // Unlock the textures 117 // Unlock the textures
107 for (int i = 0; i < kNumLayers; ++i) { 118 for (int i = 0; i < kInitialNumLayers; ++i) {
108 GrCachedLayer* layer = cache.findLayer(picture, i); 119 GrCachedLayer* layer = cache.findLayer(picture, i);
109 REPORTER_ASSERT(reporter, NULL != layer); 120 REPORTER_ASSERT(reporter, NULL != layer);
110 121
111 cache.unlock(layer); 122 cache.unlock(layer);
112 } 123 }
113 124
114 for (int i = 0; i < kNumLayers; ++i) { 125 for (int i = 0; i < kInitialNumLayers; ++i) {
115 GrCachedLayer* layer = cache.findLayer(picture, i); 126 GrCachedLayer* layer = cache.findLayer(picture, i);
116 REPORTER_ASSERT(reporter, NULL != layer); 127 REPORTER_ASSERT(reporter, NULL != layer);
117 128
129 REPORTER_ASSERT(reporter, !layer->locked());
118 #if USE_ATLAS 130 #if USE_ATLAS
119 // The first 4 layers should be in the atlas (and thus do not 131 // The first 4 layers should still be in the atlas.
120 // currently unlock). The final layer should be unlocked.
121 if (i < 4) { 132 if (i < 4) {
122 REPORTER_ASSERT(reporter, NULL != layer->texture()); 133 REPORTER_ASSERT(reporter, NULL != layer->texture());
123 REPORTER_ASSERT(reporter, layer->isAtlased()); 134 REPORTER_ASSERT(reporter, layer->isAtlased());
124 } else { 135 } else {
125 #endif 136 #endif
137 // The final layer should be unlocked.
126 REPORTER_ASSERT(reporter, NULL == layer->texture()); 138 REPORTER_ASSERT(reporter, NULL == layer->texture());
127 REPORTER_ASSERT(reporter, !layer->isAtlased()); 139 REPORTER_ASSERT(reporter, !layer->isAtlased());
128 #if USE_ATLAS 140 #if USE_ATLAS
129 } 141 }
130 #endif 142 #endif
131 } 143 }
132 144
145 {
146 // Add an additional layer. Since all the layers are unlocked this
147 // will force out the first atlased layer
148 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers);
149 GrCachedLayer* layer = cache.findLayer(picture, kInitialNumLayers);
150 REPORTER_ASSERT(reporter, NULL != layer);
151
152 lock_layer(reporter, &cache, layer);
153 cache.unlock(layer);
154 }
155
156 for (int i = 0; i < kInitialNumLayers+1; ++i) {
157 GrCachedLayer* layer = cache.findLayer(picture, i);
158 #if USE_ATLAS
159 // 3 old layers plus the new one should be in the atlas.
160 if (1 == i || 2 == i || 3 == i || 5 == i) {
161 REPORTER_ASSERT(reporter, NULL != layer);
162 REPORTER_ASSERT(reporter, !layer->locked());
163 REPORTER_ASSERT(reporter, NULL != layer->texture());
164 REPORTER_ASSERT(reporter, layer->isAtlased());
165 } else if (4 == i) {
166 #endif
167 // The one that was never atlased should still be around
168 REPORTER_ASSERT(reporter, NULL != layer);
169
170 REPORTER_ASSERT(reporter, NULL == layer->texture());
171 REPORTER_ASSERT(reporter, !layer->isAtlased());
172 #if USE_ATLAS
173 } else {
174 // The one bumped out of the atlas (i.e., 0) should be gone
175 REPORTER_ASSERT(reporter, NULL == layer);
176 }
177 #endif
178 }
179
133 //-------------------------------------------------------------------- 180 //--------------------------------------------------------------------
134 // Free them all SkGpuDevice-style. This will not free up the 181 // Free them all SkGpuDevice-style. This will not free up the
135 // atlas' texture but will eliminate all the layers. 182 // atlas' texture but will eliminate all the layers.
136 TestingAccess::Purge(&cache, picture->uniqueID()); 183 TestingAccess::Purge(&cache, picture->uniqueID());
137 184
138 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); 185 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
139 // TODO: add VRAM/resource cache check here 186 // TODO: add VRAM/resource cache check here
140 187
141 //-------------------------------------------------------------------- 188 //--------------------------------------------------------------------
142 // Test out the GrContext-style purge. This should remove all the layers 189 // Test out the GrContext-style purge. This should remove all the layers
143 // and the atlas. 190 // and the atlas.
144 // Re-create the layers 191 // Re-create the layers
145 create_layers(reporter, &cache, *picture); 192 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
146 193
147 // Free them again GrContext-style. This should free up everything. 194 // Free them again GrContext-style. This should free up everything.
148 cache.freeAll(); 195 cache.freeAll();
149 196
150 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); 197 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
151 // TODO: add VRAM/resource cache check here 198 // TODO: add VRAM/resource cache check here
152 199
153 //-------------------------------------------------------------------- 200 //--------------------------------------------------------------------
154 // Test out the MessageBus-style purge. This will not free the atlas 201 // Test out the MessageBus-style purge. This will not free the atlas
155 // but should eliminate the free-floating layers. 202 // but should eliminate the free-floating layers.
156 create_layers(reporter, &cache, *picture); 203 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
157 204
158 picture.reset(NULL); 205 picture.reset(NULL);
159 cache.processDeletedPictures(); 206 cache.processDeletedPictures();
160 207
161 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); 208 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
162 // TODO: add VRAM/resource cache check here 209 // TODO: add VRAM/resource cache check here
163 } 210 }
164 } 211 }
165 212
166 #endif 213 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698