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

Side by Side Diff: tests/GpuLayerCacheTest.cpp

Issue 476833004: Refactor GrLayerCache for new API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add DISABLE_CACHING guard 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"
(...skipping 13 matching lines...) Expand all
24 }; 24 };
25 25
26 // Add several layers to the cache 26 // Add several layers to the cache
27 static void create_layers(skiatest::Reporter* reporter, 27 static void create_layers(skiatest::Reporter* reporter,
28 GrLayerCache* cache, 28 GrLayerCache* cache,
29 const SkPicture& picture, 29 const SkPicture& picture,
30 int numToAdd, 30 int numToAdd,
31 int idOffset) { 31 int idOffset) {
32 32
33 for (int i = 0; i < numToAdd; ++i) { 33 for (int i = 0; i < numToAdd; ++i) {
34 GrCachedLayer* layer = cache->findLayerOrCreate(&picture, 34 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(),
35 idOffset+i+1, idOffset+i +2, 35 idOffset+i+1, idOffset+i +2,
36 SkMatrix::I()); 36 SkMatrix::I());
37 REPORTER_ASSERT(reporter, NULL != layer); 37 REPORTER_ASSERT(reporter, NULL != layer);
38 GrCachedLayer* temp = cache->findLayer(&picture, idOffset+i+1, idOffset+ i+2, SkMatrix::I()); 38 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset+i+1, idOffset+i+2, SkMatrix::I());
39 REPORTER_ASSERT(reporter, temp == layer); 39 REPORTER_ASSERT(reporter, temp == layer);
40 40
41 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1); 41 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1);
42 42
43 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); 43 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID());
44 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); 44 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1);
45 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); 45 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2);
46 REPORTER_ASSERT(reporter, layer->ctm() == SkMatrix::I()); 46 REPORTER_ASSERT(reporter, layer->ctm() == SkMatrix::I());
47 REPORTER_ASSERT(reporter, NULL == layer->texture()); 47 REPORTER_ASSERT(reporter, NULL == layer->texture());
48 REPORTER_ASSERT(reporter, !layer->isAtlased()); 48 REPORTER_ASSERT(reporter, !layer->isAtlased());
49 } 49 }
50 50
51 cache->trackPicture(&picture); 51 cache->trackPicture(&picture);
52 } 52 }
53 53
54 static void lock_layer(skiatest::Reporter* reporter, 54 static void lock_layer(skiatest::Reporter* reporter,
55 GrLayerCache* cache, 55 GrLayerCache* cache,
56 GrCachedLayer* layer) { 56 GrCachedLayer* layer) {
57 // Make the layer 512x512 (so it can be atlased) 57 // Make the layer 512x512 (so it can be atlased)
58 GrTextureDesc desc; 58 GrTextureDesc desc;
59 desc.fWidth = 512; 59 desc.fWidth = 512;
60 desc.fHeight = 512; 60 desc.fHeight = 512;
61 desc.fConfig = kSkia8888_GrPixelConfig; 61 desc.fConfig = kSkia8888_GrPixelConfig;
62 62
63 bool foundInCache = cache->lock(layer, desc); 63 bool needsRerendering = cache->lock(layer, desc, false);
64 REPORTER_ASSERT(reporter, !foundInCache); 64 REPORTER_ASSERT(reporter, needsRerendering);
65 65
66 foundInCache = cache->lock(layer, desc); 66 needsRerendering = cache->lock(layer, desc, false);
67 REPORTER_ASSERT(reporter, foundInCache); 67 REPORTER_ASSERT(reporter, !needsRerendering);
68 68
69 REPORTER_ASSERT(reporter, NULL != layer->texture()); 69 REPORTER_ASSERT(reporter, NULL != layer->texture());
70 REPORTER_ASSERT(reporter, layer->locked()); 70 REPORTER_ASSERT(reporter, layer->locked());
71 } 71 }
72 72
73 // This test case exercises the public API of the GrLayerCache class. 73 // This test case exercises the public API of the GrLayerCache class.
74 // In particular it checks its interaction with the resource cache (w.r.t. 74 // In particular it checks its interaction with the resource cache (w.r.t.
75 // locking & unlocking textures). 75 // locking & unlocking textures).
76 // TODO: need to add checks on VRAM usage! 76 // TODO: need to add checks on VRAM usage!
77 DEF_GPUTEST(GpuLayerCache, reporter, factory) { 77 DEF_GPUTEST(GpuLayerCache, reporter, factory) {
(...skipping 14 matching lines...) Expand all
92 92
93 SkPictureRecorder recorder; 93 SkPictureRecorder recorder;
94 recorder.beginRecording(1, 1); 94 recorder.beginRecording(1, 1);
95 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 95 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
96 96
97 GrLayerCache cache(context); 97 GrLayerCache cache(context);
98 98
99 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); 99 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
100 100
101 for (int i = 0; i < kInitialNumLayers; ++i) { 101 for (int i = 0; i < kInitialNumLayers; ++i) {
102 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix:: I()); 102 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2 , SkMatrix::I());
103 REPORTER_ASSERT(reporter, NULL != layer); 103 REPORTER_ASSERT(reporter, NULL != layer);
104 104
105 lock_layer(reporter, &cache, layer); 105 lock_layer(reporter, &cache, layer);
106 106
107 // The first 4 layers should be in the atlas (and thus have non-empt y 107 // The first 4 layers should be in the atlas (and thus have non-empt y
108 // rects) 108 // rects)
109 if (i < 4) { 109 if (i < 4) {
110 REPORTER_ASSERT(reporter, layer->isAtlased()); 110 REPORTER_ASSERT(reporter, layer->isAtlased());
111 } else { 111 } else {
112 // The 5th layer couldn't fit in the atlas 112 // The 5th layer couldn't fit in the atlas
113 REPORTER_ASSERT(reporter, !layer->isAtlased()); 113 REPORTER_ASSERT(reporter, !layer->isAtlased());
114 } 114 }
115 } 115 }
116 116
117 // Unlock the textures 117 // Unlock the textures
118 for (int i = 0; i < kInitialNumLayers; ++i) { 118 for (int i = 0; i < kInitialNumLayers; ++i) {
119 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix:: I()); 119 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2 , SkMatrix::I());
120 REPORTER_ASSERT(reporter, NULL != layer); 120 REPORTER_ASSERT(reporter, NULL != layer);
121 121
122 cache.unlock(layer); 122 cache.unlock(layer);
123 } 123 }
124 124
125 for (int i = 0; i < kInitialNumLayers; ++i) { 125 for (int i = 0; i < kInitialNumLayers; ++i) {
126 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix:: I()); 126 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2 , SkMatrix::I());
127 REPORTER_ASSERT(reporter, NULL != layer); 127 REPORTER_ASSERT(reporter, NULL != layer);
128 128
129 REPORTER_ASSERT(reporter, !layer->locked()); 129 REPORTER_ASSERT(reporter, !layer->locked());
130 // The first 4 layers should still be in the atlas. 130 // The first 4 layers should still be in the atlas.
131 if (i < 4) { 131 if (i < 4) {
132 REPORTER_ASSERT(reporter, NULL != layer->texture()); 132 REPORTER_ASSERT(reporter, NULL != layer->texture());
133 REPORTER_ASSERT(reporter, layer->isAtlased()); 133 REPORTER_ASSERT(reporter, layer->isAtlased());
134 } else { 134 } else {
135 // The final layer should be unlocked. 135 // The final layer should be unlocked.
136 REPORTER_ASSERT(reporter, NULL == layer->texture()); 136 REPORTER_ASSERT(reporter, NULL == layer->texture());
137 REPORTER_ASSERT(reporter, !layer->isAtlased()); 137 REPORTER_ASSERT(reporter, !layer->isAtlased());
138 } 138 }
139 } 139 }
140 140
141 { 141 {
142 // Add an additional layer. Since all the layers are unlocked this 142 // Add an additional layer. Since all the layers are unlocked this
143 // will force out the first atlased layer 143 // will force out the first atlased layer
144 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); 144 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers);
145 GrCachedLayer* layer = cache.findLayer(picture, 145 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(),
146 kInitialNumLayers+1, kInitial NumLayers+2, 146 kInitialNumLayers+1, kInitial NumLayers+2,
147 SkMatrix::I()); 147 SkMatrix::I());
148 REPORTER_ASSERT(reporter, NULL != layer); 148 REPORTER_ASSERT(reporter, NULL != layer);
149 149
150 lock_layer(reporter, &cache, layer); 150 lock_layer(reporter, &cache, layer);
151 cache.unlock(layer); 151 cache.unlock(layer);
152 } 152 }
153 153
154 for (int i = 0; i < kInitialNumLayers+1; ++i) { 154 for (int i = 0; i < kInitialNumLayers+1; ++i) {
155 GrCachedLayer* layer = cache.findLayer(picture, i+1, i+2, SkMatrix:: I()); 155 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2 , SkMatrix::I());
156 // 3 old layers plus the new one should be in the atlas. 156 // 3 old layers plus the new one should be in the atlas.
157 if (1 == i || 2 == i || 3 == i || 5 == i) { 157 if (1 == i || 2 == i || 3 == i || 5 == i) {
158 REPORTER_ASSERT(reporter, NULL != layer); 158 REPORTER_ASSERT(reporter, NULL != layer);
159 REPORTER_ASSERT(reporter, !layer->locked()); 159 REPORTER_ASSERT(reporter, !layer->locked());
160 REPORTER_ASSERT(reporter, NULL != layer->texture()); 160 REPORTER_ASSERT(reporter, NULL != layer->texture());
161 REPORTER_ASSERT(reporter, layer->isAtlased()); 161 REPORTER_ASSERT(reporter, layer->isAtlased());
162 } else if (4 == i) { 162 } else if (4 == i) {
163 // The one that was never atlased should still be around 163 // The one that was never atlased should still be around
164 REPORTER_ASSERT(reporter, NULL != layer); 164 REPORTER_ASSERT(reporter, NULL != layer);
165 165
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 picture.reset(NULL); 199 picture.reset(NULL);
200 cache.processDeletedPictures(); 200 cache.processDeletedPictures();
201 201
202 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); 202 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
203 // TODO: add VRAM/resource cache check here 203 // TODO: add VRAM/resource cache check here
204 } 204 }
205 } 205 }
206 206
207 #endif 207 #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