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

Side by Side Diff: tests/GpuLayerCacheTest.cpp

Issue 753253002: Use variable length key (rather than accumulated matrix) as save layer hoisting key (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 6 years 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
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 class TestingAccess { 16 class TestingAccess {
17 public: 17 public:
18 static int NumLayers(GrLayerCache* cache) { 18 static int NumLayers(GrLayerCache* cache) {
19 return cache->numLayers(); 19 return cache->numLayers();
20 } 20 }
21 static void Purge(GrLayerCache* cache, uint32_t pictureID) { 21 static void Purge(GrLayerCache* cache, uint32_t pictureID) {
22 cache->purge(pictureID); 22 cache->purge(pictureID);
23 } 23 }
24 static int Uses(GrCachedLayer* layer) { 24 static int Uses(GrCachedLayer* layer) {
25 return layer->uses(); 25 return layer->uses();
26 } 26 }
27 static GrCachedLayer* Find(GrLayerCache* cache, uint32_t pictureID,
28 const SkMatrix& initialMat, const int* key, int k eySize) {
29 return cache->findLayer(pictureID, initialMat, key, keySize);
30 }
27 }; 31 };
28 32
29 // Add several layers to the cache 33 // Add several layers to the cache
30 static void create_layers(skiatest::Reporter* reporter, 34 static void create_layers(skiatest::Reporter* reporter,
31 GrLayerCache* cache, 35 GrLayerCache* cache,
32 const SkPicture& picture, 36 const SkPicture& picture,
33 int numToAdd, 37 int numToAdd,
34 int idOffset) { 38 int idOffset) {
35 39
36 for (int i = 0; i < numToAdd; ++i) { 40 for (int i = 0; i < numToAdd; ++i) {
41 int indices[1] = { idOffset+i+1 };
37 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), 42 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(),
38 idOffset+i+1, idOffset+i +2, 43 idOffset+i+1, idOffset+i +2,
39 SkIRect::MakeEmpty(), 44 SkIRect::MakeEmpty(),
40 SkMatrix::I(), 45 SkMatrix::I(),
46 indices, 1,
41 NULL); 47 NULL);
42 REPORTER_ASSERT(reporter, layer); 48 REPORTER_ASSERT(reporter, layer);
43 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset + i + 1, 49 GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkM atrix::I(),
44 SkIRect::MakeEmpty(), SkMatrix::I ()); 50 indices, 1);
45 REPORTER_ASSERT(reporter, temp == layer); 51 REPORTER_ASSERT(reporter, temp == layer);
46 52
47 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1); 53 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1);
48 54
49 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); 55 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID());
50 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); 56 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1);
51 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); 57 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2);
52 REPORTER_ASSERT(reporter, NULL == layer->texture()); 58 REPORTER_ASSERT(reporter, NULL == layer->texture());
53 REPORTER_ASSERT(reporter, NULL == layer->paint()); 59 REPORTER_ASSERT(reporter, NULL == layer->paint());
54 REPORTER_ASSERT(reporter, !layer->isAtlased()); 60 REPORTER_ASSERT(reporter, !layer->isAtlased());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 110
105 SkPictureRecorder recorder; 111 SkPictureRecorder recorder;
106 recorder.beginRecording(1, 1); 112 recorder.beginRecording(1, 1);
107 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 113 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
108 114
109 GrLayerCache cache(context); 115 GrLayerCache cache(context);
110 116
111 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); 117 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
112 118
113 for (int i = 0; i < kInitialNumLayers; ++i) { 119 for (int i = 0; i < kInitialNumLayers; ++i) {
114 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, 120 int indices[1] = { i + 1 };
115 SkIRect::MakeEmpty(), SkMatri x::I()); 121 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID (), SkMatrix::I(),
122 indices, 1);
116 REPORTER_ASSERT(reporter, layer); 123 REPORTER_ASSERT(reporter, layer);
117 124
118 lock_layer(reporter, &cache, layer); 125 lock_layer(reporter, &cache, layer);
119 126
120 // The first 4 layers should be in the atlas (and thus have non-empt y 127 // The first 4 layers should be in the atlas (and thus have non-empt y
121 // rects) 128 // rects)
122 if (i < 4) { 129 if (i < 4) {
123 REPORTER_ASSERT(reporter, layer->isAtlased()); 130 REPORTER_ASSERT(reporter, layer->isAtlased());
124 } else { 131 } else {
125 // The 5th layer couldn't fit in the atlas 132 // The 5th layer couldn't fit in the atlas
126 REPORTER_ASSERT(reporter, !layer->isAtlased()); 133 REPORTER_ASSERT(reporter, !layer->isAtlased());
127 } 134 }
128 } 135 }
129 136
130 // Unlock the textures 137 // Unlock the textures
131 for (int i = 0; i < kInitialNumLayers; ++i) { 138 for (int i = 0; i < kInitialNumLayers; ++i) {
132 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, 139 int indices[1] = { i+1 };
133 SkIRect::MakeEmpty(), SkMatri x::I()); 140
141 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID (), SkMatrix::I(),
142 indices, 1);
134 REPORTER_ASSERT(reporter, layer); 143 REPORTER_ASSERT(reporter, layer);
135 cache.removeUse(layer); 144 cache.removeUse(layer);
136 } 145 }
137 146
138 for (int i = 0; i < kInitialNumLayers; ++i) { 147 for (int i = 0; i < kInitialNumLayers; ++i) {
139 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, 148 int indices[1] = { i+1 };
140 SkIRect::MakeEmpty(), SkMatri x::I()); 149
150 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID (), SkMatrix::I(),
151 indices, 1);
141 REPORTER_ASSERT(reporter, layer); 152 REPORTER_ASSERT(reporter, layer);
142 153
143 // All the layers should be unlocked 154 // All the layers should be unlocked
144 REPORTER_ASSERT(reporter, !layer->locked()); 155 REPORTER_ASSERT(reporter, !layer->locked());
145 156
146 // When hoisted layers aren't cached they are aggressively removed 157 // When hoisted layers aren't cached they are aggressively removed
147 // from the atlas 158 // from the atlas
148 #if GR_CACHE_HOISTED_LAYERS 159 #if GR_CACHE_HOISTED_LAYERS
149 // The first 4 layers should still be in the atlas. 160 // The first 4 layers should still be in the atlas.
150 if (i < 4) { 161 if (i < 4) {
151 REPORTER_ASSERT(reporter, layer->texture()); 162 REPORTER_ASSERT(reporter, layer->texture());
152 REPORTER_ASSERT(reporter, layer->isAtlased()); 163 REPORTER_ASSERT(reporter, layer->isAtlased());
153 } else { 164 } else {
154 #endif 165 #endif
155 // The final layer should not be atlased. 166 // The final layer should not be atlased.
156 REPORTER_ASSERT(reporter, NULL == layer->texture()); 167 REPORTER_ASSERT(reporter, NULL == layer->texture());
157 REPORTER_ASSERT(reporter, !layer->isAtlased()); 168 REPORTER_ASSERT(reporter, !layer->isAtlased());
158 #if GR_CACHE_HOISTED_LAYERS 169 #if GR_CACHE_HOISTED_LAYERS
159 } 170 }
160 #endif 171 #endif
161 } 172 }
162 173
163 { 174 {
175 int indices[1] = { kInitialNumLayers+1 };
176
164 // Add an additional layer. Since all the layers are unlocked this 177 // Add an additional layer. Since all the layers are unlocked this
165 // will force out the first atlased layer 178 // will force out the first atlased layer
166 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); 179 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers);
167 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), 180 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID (), SkMatrix::I(),
168 kInitialNumLayers+1, 181 indices, 1);
169 SkIRect::MakeEmpty(), SkMatri x::I());
170 REPORTER_ASSERT(reporter, layer); 182 REPORTER_ASSERT(reporter, layer);
171 183
172 lock_layer(reporter, &cache, layer); 184 lock_layer(reporter, &cache, layer);
173 cache.removeUse(layer); 185 cache.removeUse(layer);
174 } 186 }
175 187
176 for (int i = 0; i < kInitialNumLayers+1; ++i) { 188 for (int i = 0; i < kInitialNumLayers+1; ++i) {
177 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i + 1, 189 int indices[1] = { i+1 };
178 SkIRect::MakeEmpty(), SkMatri x::I()); 190
191 GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID (), SkMatrix::I(),
192 indices, 1);
179 #if GR_CACHE_HOISTED_LAYERS 193 #if GR_CACHE_HOISTED_LAYERS
180 // 3 old layers plus the new one should be in the atlas. 194 // 3 old layers plus the new one should be in the atlas.
181 if (1 == i || 2 == i || 3 == i || 5 == i) { 195 if (1 == i || 2 == i || 3 == i || 5 == i) {
182 REPORTER_ASSERT(reporter, layer); 196 REPORTER_ASSERT(reporter, layer);
183 REPORTER_ASSERT(reporter, !layer->locked()); 197 REPORTER_ASSERT(reporter, !layer->locked());
184 REPORTER_ASSERT(reporter, layer->texture()); 198 REPORTER_ASSERT(reporter, layer->texture());
185 REPORTER_ASSERT(reporter, layer->isAtlased()); 199 REPORTER_ASSERT(reporter, layer->isAtlased());
186 } else if (4 == i) { 200 } else if (4 == i) {
187 #endif 201 #endif
188 // The one that was never atlased should still be around 202 // The one that was never atlased should still be around
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 239
226 picture.reset(NULL); 240 picture.reset(NULL);
227 cache.processDeletedPictures(); 241 cache.processDeletedPictures();
228 242
229 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); 243 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
230 // TODO: add VRAM/resource cache check here 244 // TODO: add VRAM/resource cache check here
231 } 245 }
232 } 246 }
233 247
234 #endif 248 #endif
OLDNEW
« src/gpu/GrLayerCache.h ('K') | « src/gpu/SkGpuDevice.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698