OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/playback/discardable_image_map.h" | 5 #include "cc/playback/discardable_image_map.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "cc/base/region.h" | 10 #include "cc/base/region.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 EXPECT_EQ(draw_images.size(), position_draw_images.size()); | 49 EXPECT_EQ(draw_images.size(), position_draw_images.size()); |
50 for (size_t i = 0; i < draw_images.size(); ++i) | 50 for (size_t i = 0; i < draw_images.size(); ++i) |
51 EXPECT_TRUE(draw_images[i].image() == position_draw_images[i].image); | 51 EXPECT_TRUE(draw_images[i].image() == position_draw_images[i].image); |
52 return position_draw_images; | 52 return position_draw_images; |
53 } | 53 } |
54 }; | 54 }; |
55 | 55 |
56 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectTest) { | 56 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectTest) { |
57 gfx::Rect visible_rect(2048, 2048); | 57 gfx::Rect visible_rect(2048, 2048); |
58 FakeContentLayerClient content_layer_client; | 58 FakeContentLayerClient content_layer_client; |
| 59 content_layer_client.set_bounds(visible_rect.size()); |
59 | 60 |
60 // Discardable pixel refs are found in the following grids: | 61 // Discardable pixel refs are found in the following grids: |
61 // |---|---|---|---| | 62 // |---|---|---|---| |
62 // | | x | | x | | 63 // | | x | | x | |
63 // |---|---|---|---| | 64 // |---|---|---|---| |
64 // | x | | x | | | 65 // | x | | x | | |
65 // |---|---|---|---| | 66 // |---|---|---|---| |
66 // | | x | | x | | 67 // | | x | | x | |
67 // |---|---|---|---| | 68 // |---|---|---|---| |
68 // | x | | x | | | 69 // | x | | x | | |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 EXPECT_TRUE(images[3].image == discardable_image[3][2].get()); | 126 EXPECT_TRUE(images[3].image == discardable_image[3][2].get()); |
126 EXPECT_EQ(gfx::RectF(2 * 512 + 6, 3 * 512 + 6, 500, 500), | 127 EXPECT_EQ(gfx::RectF(2 * 512 + 6, 3 * 512 + 6, 500, 500), |
127 images[3].image_rect); | 128 images[3].image_rect); |
128 } | 129 } |
129 | 130 |
130 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectNonZeroLayer) { | 131 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectNonZeroLayer) { |
131 gfx::Rect visible_rect(1024, 0, 2048, 2048); | 132 gfx::Rect visible_rect(1024, 0, 2048, 2048); |
132 // Make sure visible rect fits into the layer size. | 133 // Make sure visible rect fits into the layer size. |
133 gfx::Size layer_size(visible_rect.right(), visible_rect.bottom()); | 134 gfx::Size layer_size(visible_rect.right(), visible_rect.bottom()); |
134 FakeContentLayerClient content_layer_client; | 135 FakeContentLayerClient content_layer_client; |
| 136 content_layer_client.set_bounds(layer_size); |
135 | 137 |
136 // Discardable pixel refs are found in the following grids: | 138 // Discardable pixel refs are found in the following grids: |
137 // |---|---|---|---| | 139 // |---|---|---|---| |
138 // | | x | | x | | 140 // | | x | | x | |
139 // |---|---|---|---| | 141 // |---|---|---|---| |
140 // | x | | x | | | 142 // | x | | x | | |
141 // |---|---|---|---| | 143 // |---|---|---|---| |
142 // | | x | | x | | 144 // | | x | | x | |
143 // |---|---|---|---| | 145 // |---|---|---|---| |
144 // | x | | x | | | 146 // | x | | x | | |
145 // |---|---|---|---| | 147 // |---|---|---|---| |
146 skia::RefPtr<SkImage> discardable_image[4][4]; | 148 skia::RefPtr<SkImage> discardable_image[4][4]; |
147 for (int y = 0; y < 4; ++y) { | 149 for (int y = 0; y < 4; ++y) { |
148 for (int x = 0; x < 4; ++x) { | 150 for (int x = 0; x < 4; ++x) { |
149 if ((x + y) & 1) { | 151 if ((x + y) & 1) { |
150 discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); | 152 discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); |
151 SkPaint paint; | 153 SkPaint paint; |
152 content_layer_client.add_draw_image( | 154 content_layer_client.add_draw_image( |
153 discardable_image[y][x].get(), | 155 discardable_image[y][x].get(), |
154 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); | 156 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); |
155 } | 157 } |
156 } | 158 } |
157 } | 159 } |
158 | 160 |
159 FakeDisplayListRecordingSource recording_source; | 161 FakeDisplayListRecordingSource recording_source; |
160 Region invalidation(visible_rect); | 162 Region invalidation(visible_rect); |
161 recording_source.set_pixel_record_distance(0); | |
162 recording_source.SetGenerateDiscardableImagesMetadata(true); | 163 recording_source.SetGenerateDiscardableImagesMetadata(true); |
163 recording_source.UpdateAndExpandInvalidation( | 164 recording_source.UpdateAndExpandInvalidation( |
164 &content_layer_client, &invalidation, layer_size, visible_rect, 1, | 165 &content_layer_client, &invalidation, layer_size, visible_rect, 1, |
165 DisplayListRecordingSource::RECORD_NORMALLY); | 166 DisplayListRecordingSource::RECORD_NORMALLY); |
166 DisplayItemList* display_list = recording_source.display_list(); | 167 DisplayItemList* display_list = recording_source.display_list(); |
167 | 168 |
168 DiscardableImageMap image_map; | 169 DiscardableImageMap image_map; |
169 { | 170 { |
170 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | 171 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, |
171 layer_size); | 172 layer_size); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 { | 226 { |
226 std::vector<PositionDrawImage> images = GetDiscardableImagesInRect( | 227 std::vector<PositionDrawImage> images = GetDiscardableImagesInRect( |
227 image_map, gfx::Rect(3500, 1100, 1000, 1000)); | 228 image_map, gfx::Rect(3500, 1100, 1000, 1000)); |
228 EXPECT_EQ(0u, images.size()); | 229 EXPECT_EQ(0u, images.size()); |
229 } | 230 } |
230 } | 231 } |
231 | 232 |
232 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectOnePixelQuery) { | 233 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectOnePixelQuery) { |
233 gfx::Rect visible_rect(2048, 2048); | 234 gfx::Rect visible_rect(2048, 2048); |
234 FakeContentLayerClient content_layer_client; | 235 FakeContentLayerClient content_layer_client; |
| 236 content_layer_client.set_bounds(visible_rect.size()); |
235 | 237 |
236 // Discardable pixel refs are found in the following grids: | 238 // Discardable pixel refs are found in the following grids: |
237 // |---|---|---|---| | 239 // |---|---|---|---| |
238 // | | x | | x | | 240 // | | x | | x | |
239 // |---|---|---|---| | 241 // |---|---|---|---| |
240 // | x | | x | | | 242 // | x | | x | | |
241 // |---|---|---|---| | 243 // |---|---|---|---| |
242 // | | x | | x | | 244 // | | x | | x | |
243 // |---|---|---|---| | 245 // |---|---|---|---| |
244 // | x | | x | | | 246 // | x | | x | | |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } else { | 286 } else { |
285 EXPECT_EQ(0u, images.size()) << x << " " << y; | 287 EXPECT_EQ(0u, images.size()) << x << " " << y; |
286 } | 288 } |
287 } | 289 } |
288 } | 290 } |
289 } | 291 } |
290 | 292 |
291 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMassiveImage) { | 293 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMassiveImage) { |
292 gfx::Rect visible_rect(2048, 2048); | 294 gfx::Rect visible_rect(2048, 2048); |
293 FakeContentLayerClient content_layer_client; | 295 FakeContentLayerClient content_layer_client; |
| 296 content_layer_client.set_bounds(visible_rect.size()); |
294 | 297 |
295 skia::RefPtr<SkImage> discardable_image; | 298 skia::RefPtr<SkImage> discardable_image; |
296 discardable_image = CreateDiscardableImage(gfx::Size(1 << 25, 1 << 25)); | 299 discardable_image = CreateDiscardableImage(gfx::Size(1 << 25, 1 << 25)); |
297 SkPaint paint; | 300 SkPaint paint; |
298 content_layer_client.add_draw_image(discardable_image.get(), gfx::Point(0, 0), | 301 content_layer_client.add_draw_image(discardable_image.get(), gfx::Point(0, 0), |
299 paint); | 302 paint); |
300 | 303 |
301 FakeDisplayListRecordingSource recording_source; | 304 FakeDisplayListRecordingSource recording_source; |
302 Region invalidation(visible_rect); | 305 Region invalidation(visible_rect); |
303 recording_source.SetGenerateDiscardableImagesMetadata(true); | 306 recording_source.SetGenerateDiscardableImagesMetadata(true); |
304 recording_source.UpdateAndExpandInvalidation( | 307 recording_source.UpdateAndExpandInvalidation( |
305 &content_layer_client, &invalidation, visible_rect.size(), visible_rect, | 308 &content_layer_client, &invalidation, visible_rect.size(), visible_rect, |
306 1, DisplayListRecordingSource::RECORD_NORMALLY); | 309 1, DisplayListRecordingSource::RECORD_NORMALLY); |
307 DisplayItemList* display_list = recording_source.display_list(); | 310 DisplayItemList* display_list = recording_source.display_list(); |
308 | 311 |
309 DiscardableImageMap image_map; | 312 DiscardableImageMap image_map; |
310 { | 313 { |
311 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | 314 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, |
312 visible_rect.size()); | 315 visible_rect.size()); |
313 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); | 316 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); |
314 } | 317 } |
315 std::vector<PositionDrawImage> images = | 318 std::vector<PositionDrawImage> images = |
316 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 319 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
317 EXPECT_EQ(1u, images.size()); | 320 EXPECT_EQ(1u, images.size()); |
318 EXPECT_TRUE(images[0].image == discardable_image.get()); | 321 EXPECT_TRUE(images[0].image == discardable_image.get()); |
319 EXPECT_EQ(gfx::RectF(0, 0, 1 << 25, 1 << 25), images[0].image_rect); | 322 EXPECT_EQ(gfx::RectF(0, 0, 1 << 25, 1 << 25), images[0].image_rect); |
320 } | 323 } |
321 | 324 |
322 } // namespace cc | 325 } // namespace cc |
OLD | NEW |