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

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: Compiling 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"
(...skipping 16 matching lines...) Expand all
27 }; 27 };
28 28
29 // Add several layers to the cache 29 // Add several layers to the cache
30 static void create_layers(skiatest::Reporter* reporter, 30 static void create_layers(skiatest::Reporter* reporter,
31 GrLayerCache* cache, 31 GrLayerCache* cache,
32 const SkPicture& picture, 32 const SkPicture& picture,
33 int numToAdd, 33 int numToAdd,
34 int idOffset) { 34 int idOffset) {
35 35
36 for (int i = 0; i < numToAdd; ++i) { 36 for (int i = 0; i < numToAdd; ++i) {
37 int foo[2] = { picture.uniqueID(), idOffset+i+1 };
37 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), 38 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(),
38 idOffset+i+1, idOffset+i +2, 39 idOffset+i+1, idOffset+i +2,
39 SkIRect::MakeEmpty(), 40 SkIRect::MakeEmpty(),
40 SkMatrix::I(), 41 SkMatrix::I(),
42 foo, 2,
41 NULL); 43 NULL);
42 REPORTER_ASSERT(reporter, layer); 44 REPORTER_ASSERT(reporter, layer);
43 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset + i + 1, 45 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset + i + 1,
44 SkIRect::MakeEmpty(), SkMatrix::I ()); 46 SkIRect::MakeEmpty(), SkMatrix::I (), foo, 2);
45 REPORTER_ASSERT(reporter, temp == layer); 47 REPORTER_ASSERT(reporter, temp == layer);
46 48
47 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1); 49 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1);
48 50
49 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); 51 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID());
50 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); 52 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1);
51 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); 53 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2);
52 REPORTER_ASSERT(reporter, NULL == layer->texture()); 54 REPORTER_ASSERT(reporter, NULL == layer->texture());
53 REPORTER_ASSERT(reporter, NULL == layer->paint()); 55 REPORTER_ASSERT(reporter, NULL == layer->paint());
54 REPORTER_ASSERT(reporter, !layer->isAtlased()); 56 REPORTER_ASSERT(reporter, !layer->isAtlased());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 106
105 SkPictureRecorder recorder; 107 SkPictureRecorder recorder;
106 recorder.beginRecording(1, 1); 108 recorder.beginRecording(1, 1);
107 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 109 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
108 110
109 GrLayerCache cache(context); 111 GrLayerCache cache(context);
110 112
111 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); 113 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
112 114
113 for (int i = 0; i < kInitialNumLayers; ++i) { 115 for (int i = 0; i < kInitialNumLayers; ++i) {
114 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, 116 int foo[2] = { picture->uniqueID(), i + 1 };
115 SkIRect::MakeEmpty(), SkMatri x::I()); 117 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i + 1,
118 SkIRect::MakeEmpty(), SkMatri x::I(), foo, 2);
116 REPORTER_ASSERT(reporter, layer); 119 REPORTER_ASSERT(reporter, layer);
117 120
118 lock_layer(reporter, &cache, layer); 121 lock_layer(reporter, &cache, layer);
119 122
120 // The first 4 layers should be in the atlas (and thus have non-empt y 123 // The first 4 layers should be in the atlas (and thus have non-empt y
121 // rects) 124 // rects)
122 if (i < 4) { 125 if (i < 4) {
123 REPORTER_ASSERT(reporter, layer->isAtlased()); 126 REPORTER_ASSERT(reporter, layer->isAtlased());
124 } else { 127 } else {
125 // The 5th layer couldn't fit in the atlas 128 // The 5th layer couldn't fit in the atlas
126 REPORTER_ASSERT(reporter, !layer->isAtlased()); 129 REPORTER_ASSERT(reporter, !layer->isAtlased());
127 } 130 }
128 } 131 }
129 132
130 // Unlock the textures 133 // Unlock the textures
131 for (int i = 0; i < kInitialNumLayers; ++i) { 134 for (int i = 0; i < kInitialNumLayers; ++i) {
135 int foo[2] = { picture->uniqueID(), i+1 };
136
132 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, 137 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1,
133 SkIRect::MakeEmpty(), SkMatri x::I()); 138 SkIRect::MakeEmpty(), SkMatri x::I(), foo, 2);
134 REPORTER_ASSERT(reporter, layer); 139 REPORTER_ASSERT(reporter, layer);
135 cache.removeUse(layer); 140 cache.removeUse(layer);
136 } 141 }
137 142
138 for (int i = 0; i < kInitialNumLayers; ++i) { 143 for (int i = 0; i < kInitialNumLayers; ++i) {
144 int foo[2] = { picture->uniqueID(), i+1 };
145
139 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, 146 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1,
140 SkIRect::MakeEmpty(), SkMatri x::I()); 147 SkIRect::MakeEmpty(), SkMatri x::I(), foo, 2);
141 REPORTER_ASSERT(reporter, layer); 148 REPORTER_ASSERT(reporter, layer);
142 149
143 // All the layers should be unlocked 150 // All the layers should be unlocked
144 REPORTER_ASSERT(reporter, !layer->locked()); 151 REPORTER_ASSERT(reporter, !layer->locked());
145 152
146 // When hoisted layers aren't cached they are aggressively removed 153 // When hoisted layers aren't cached they are aggressively removed
147 // from the atlas 154 // from the atlas
148 #if GR_CACHE_HOISTED_LAYERS 155 #if GR_CACHE_HOISTED_LAYERS
149 // The first 4 layers should still be in the atlas. 156 // The first 4 layers should still be in the atlas.
150 if (i < 4) { 157 if (i < 4) {
151 REPORTER_ASSERT(reporter, layer->texture()); 158 REPORTER_ASSERT(reporter, layer->texture());
152 REPORTER_ASSERT(reporter, layer->isAtlased()); 159 REPORTER_ASSERT(reporter, layer->isAtlased());
153 } else { 160 } else {
154 #endif 161 #endif
155 // The final layer should not be atlased. 162 // The final layer should not be atlased.
156 REPORTER_ASSERT(reporter, NULL == layer->texture()); 163 REPORTER_ASSERT(reporter, NULL == layer->texture());
157 REPORTER_ASSERT(reporter, !layer->isAtlased()); 164 REPORTER_ASSERT(reporter, !layer->isAtlased());
158 #if GR_CACHE_HOISTED_LAYERS 165 #if GR_CACHE_HOISTED_LAYERS
159 } 166 }
160 #endif 167 #endif
161 } 168 }
162 169
163 { 170 {
171 int foo[2] = { picture->uniqueID(), kInitialNumLayers+1 };
172
164 // Add an additional layer. Since all the layers are unlocked this 173 // Add an additional layer. Since all the layers are unlocked this
165 // will force out the first atlased layer 174 // will force out the first atlased layer
166 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); 175 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers);
167 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), 176 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(),
168 kInitialNumLayers+1, 177 kInitialNumLayers+1,
169 SkIRect::MakeEmpty(), SkMatri x::I()); 178 SkIRect::MakeEmpty(), SkMatri x::I(), foo, 2);
170 REPORTER_ASSERT(reporter, layer); 179 REPORTER_ASSERT(reporter, layer);
171 180
172 lock_layer(reporter, &cache, layer); 181 lock_layer(reporter, &cache, layer);
173 cache.removeUse(layer); 182 cache.removeUse(layer);
174 } 183 }
175 184
176 for (int i = 0; i < kInitialNumLayers+1; ++i) { 185 for (int i = 0; i < kInitialNumLayers+1; ++i) {
177 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i + 1, 186 int foo[2] = { picture->uniqueID(), i+1 };
178 SkIRect::MakeEmpty(), SkMatri x::I()); 187
188 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1,
189 SkIRect::MakeEmpty(), SkMatri x::I(), foo, 2);
179 #if GR_CACHE_HOISTED_LAYERS 190 #if GR_CACHE_HOISTED_LAYERS
180 // 3 old layers plus the new one should be in the atlas. 191 // 3 old layers plus the new one should be in the atlas.
181 if (1 == i || 2 == i || 3 == i || 5 == i) { 192 if (1 == i || 2 == i || 3 == i || 5 == i) {
182 REPORTER_ASSERT(reporter, layer); 193 REPORTER_ASSERT(reporter, layer);
183 REPORTER_ASSERT(reporter, !layer->locked()); 194 REPORTER_ASSERT(reporter, !layer->locked());
184 REPORTER_ASSERT(reporter, layer->texture()); 195 REPORTER_ASSERT(reporter, layer->texture());
185 REPORTER_ASSERT(reporter, layer->isAtlased()); 196 REPORTER_ASSERT(reporter, layer->isAtlased());
186 } else if (4 == i) { 197 } else if (4 == i) {
187 #endif 198 #endif
188 // The one that was never atlased should still be around 199 // The one that was never atlased should still be around
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 236
226 picture.reset(NULL); 237 picture.reset(NULL);
227 cache.processDeletedPictures(); 238 cache.processDeletedPictures();
228 239
229 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); 240 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
230 // TODO: add VRAM/resource cache check here 241 // TODO: add VRAM/resource cache check here
231 } 242 }
232 } 243 }
233 244
234 #endif 245 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698