OLD | NEW |
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 15 matching lines...) Expand all Loading... |
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.uniqueID(), | 34 GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), |
35 idOffset+i+1, idOffset+i
+2, | 35 idOffset+i+1, idOffset+i
+2, |
| 36 SkIPoint::Make(0, 0), |
36 SkMatrix::I()); | 37 SkMatrix::I()); |
37 REPORTER_ASSERT(reporter, layer); | 38 REPORTER_ASSERT(reporter, layer); |
38 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset+i+1,
idOffset+i+2, SkMatrix::I()); | 39 GrCachedLayer* temp = cache->findLayer(picture.uniqueID(), idOffset+i+1,
idOffset+i+2, |
| 40 SkIPoint::Make(0, 0), SkMatrix::I
()); |
39 REPORTER_ASSERT(reporter, temp == layer); | 41 REPORTER_ASSERT(reporter, temp == layer); |
40 | 42 |
41 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); | 43 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset +
i + 1); |
42 | 44 |
43 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); | 45 REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); |
44 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); | 46 REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1); |
45 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); | 47 REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2); |
46 REPORTER_ASSERT(reporter, layer->ctm() == SkMatrix::I()); | 48 REPORTER_ASSERT(reporter, layer->ctm() == SkMatrix::I()); |
47 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 49 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
48 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 50 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 94 |
93 SkPictureRecorder recorder; | 95 SkPictureRecorder recorder; |
94 recorder.beginRecording(1, 1); | 96 recorder.beginRecording(1, 1); |
95 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 97 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
96 | 98 |
97 GrLayerCache cache(context); | 99 GrLayerCache cache(context); |
98 | 100 |
99 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); | 101 create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
100 | 102 |
101 for (int i = 0; i < kInitialNumLayers; ++i) { | 103 for (int i = 0; i < kInitialNumLayers; ++i) { |
102 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, SkMatrix::I()); | 104 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, |
| 105 SkIPoint::Make(0, 0), SkMatri
x::I()); |
103 REPORTER_ASSERT(reporter, layer); | 106 REPORTER_ASSERT(reporter, layer); |
104 | 107 |
105 lock_layer(reporter, &cache, layer); | 108 lock_layer(reporter, &cache, layer); |
106 | 109 |
107 // The first 4 layers should be in the atlas (and thus have non-empt
y | 110 // The first 4 layers should be in the atlas (and thus have non-empt
y |
108 // rects) | 111 // rects) |
109 if (i < 4) { | 112 if (i < 4) { |
110 REPORTER_ASSERT(reporter, layer->isAtlased()); | 113 REPORTER_ASSERT(reporter, layer->isAtlased()); |
111 } else { | 114 } else { |
112 // The 5th layer couldn't fit in the atlas | 115 // The 5th layer couldn't fit in the atlas |
113 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 116 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
114 } | 117 } |
115 } | 118 } |
116 | 119 |
117 // Unlock the textures | 120 // Unlock the textures |
118 for (int i = 0; i < kInitialNumLayers; ++i) { | 121 for (int i = 0; i < kInitialNumLayers; ++i) { |
119 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, SkMatrix::I()); | 122 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, |
| 123 SkIPoint::Make(0, 0), SkMatri
x::I()); |
120 REPORTER_ASSERT(reporter, layer); | 124 REPORTER_ASSERT(reporter, layer); |
121 | |
122 cache.unlock(layer); | 125 cache.unlock(layer); |
123 } | 126 } |
124 | 127 |
125 for (int i = 0; i < kInitialNumLayers; ++i) { | 128 for (int i = 0; i < kInitialNumLayers; ++i) { |
126 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, SkMatrix::I()); | 129 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, |
| 130 SkIPoint::Make(0, 0), SkMatri
x::I()); |
127 REPORTER_ASSERT(reporter, layer); | 131 REPORTER_ASSERT(reporter, layer); |
128 | 132 |
129 REPORTER_ASSERT(reporter, !layer->locked()); | 133 REPORTER_ASSERT(reporter, !layer->locked()); |
130 // The first 4 layers should still be in the atlas. | 134 // The first 4 layers should still be in the atlas. |
131 if (i < 4) { | 135 if (i < 4) { |
132 REPORTER_ASSERT(reporter, layer->texture()); | 136 REPORTER_ASSERT(reporter, layer->texture()); |
133 REPORTER_ASSERT(reporter, layer->isAtlased()); | 137 REPORTER_ASSERT(reporter, layer->isAtlased()); |
134 } else { | 138 } else { |
135 // The final layer should be unlocked. | 139 // The final layer should be unlocked. |
136 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 140 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
137 REPORTER_ASSERT(reporter, !layer->isAtlased()); | 141 REPORTER_ASSERT(reporter, !layer->isAtlased()); |
138 } | 142 } |
139 } | 143 } |
140 | 144 |
141 { | 145 { |
142 // Add an additional layer. Since all the layers are unlocked this | 146 // Add an additional layer. Since all the layers are unlocked this |
143 // will force out the first atlased layer | 147 // will force out the first atlased layer |
144 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); | 148 create_layers(reporter, &cache, *picture, 1, kInitialNumLayers); |
145 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), | 149 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), |
146 kInitialNumLayers+1, kInitial
NumLayers+2, | 150 kInitialNumLayers+1, kInitial
NumLayers+2, |
147 SkMatrix::I()); | 151 SkIPoint::Make(0, 0), SkMatri
x::I()); |
148 REPORTER_ASSERT(reporter, layer); | 152 REPORTER_ASSERT(reporter, layer); |
149 | 153 |
150 lock_layer(reporter, &cache, layer); | 154 lock_layer(reporter, &cache, layer); |
151 cache.unlock(layer); | 155 cache.unlock(layer); |
152 } | 156 } |
153 | 157 |
154 for (int i = 0; i < kInitialNumLayers+1; ++i) { | 158 for (int i = 0; i < kInitialNumLayers+1; ++i) { |
155 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, SkMatrix::I()); | 159 GrCachedLayer* layer = cache.findLayer(picture->uniqueID(), i+1, i+2
, |
| 160 SkIPoint::Make(0, 0), SkMatri
x::I()); |
156 // 3 old layers plus the new one should be in the atlas. | 161 // 3 old layers plus the new one should be in the atlas. |
157 if (1 == i || 2 == i || 3 == i || 5 == i) { | 162 if (1 == i || 2 == i || 3 == i || 5 == i) { |
158 REPORTER_ASSERT(reporter, layer); | 163 REPORTER_ASSERT(reporter, layer); |
159 REPORTER_ASSERT(reporter, !layer->locked()); | 164 REPORTER_ASSERT(reporter, !layer->locked()); |
160 REPORTER_ASSERT(reporter, layer->texture()); | 165 REPORTER_ASSERT(reporter, layer->texture()); |
161 REPORTER_ASSERT(reporter, layer->isAtlased()); | 166 REPORTER_ASSERT(reporter, layer->isAtlased()); |
162 } else if (4 == i) { | 167 } else if (4 == i) { |
163 // The one that was never atlased should still be around | 168 // The one that was never atlased should still be around |
164 REPORTER_ASSERT(reporter, layer); | 169 REPORTER_ASSERT(reporter, layer); |
165 | 170 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 203 |
199 picture.reset(NULL); | 204 picture.reset(NULL); |
200 cache.processDeletedPictures(); | 205 cache.processDeletedPictures(); |
201 | 206 |
202 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); | 207 REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0); |
203 // TODO: add VRAM/resource cache check here | 208 // TODO: add VRAM/resource cache check here |
204 } | 209 } |
205 } | 210 } |
206 | 211 |
207 #endif | 212 #endif |
OLD | NEW |