OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "cc/test/fake_picture_pile_impl.h" | 6 #include "cc/test/fake_picture_pile_impl.h" |
7 #include "cc/test/skia_common.h" | 7 #include "cc/test/skia_common.h" |
8 #include "skia/ext/refptr.h" | 8 #include "skia/ext/refptr.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkPixelRef.h" | 10 #include "third_party/skia/include/core/SkPixelRef.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 SkPaint solid_paint; | 25 SkPaint solid_paint; |
26 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 26 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
27 solid_paint.setColor(solid_color); | 27 solid_paint.setColor(solid_color); |
28 | 28 |
29 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 29 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
30 SkPaint non_solid_paint; | 30 SkPaint non_solid_paint; |
31 non_solid_paint.setColor(non_solid_color); | 31 non_solid_paint.setColor(non_solid_color); |
32 | 32 |
33 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), | 33 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), |
34 solid_paint); | 34 solid_paint); |
35 recording_source->Rerecord(); | 35 recording_source->RerecordPile(); |
36 | 36 |
37 scoped_refptr<FakePicturePileImpl> pile = | 37 scoped_refptr<FakePicturePileImpl> pile = |
38 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 38 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
39 | 39 |
40 // Ensure everything is solid. | 40 // Ensure everything is solid. |
41 for (int y = 0; y <= 300; y += 100) { | 41 for (int y = 0; y <= 300; y += 100) { |
42 for (int x = 0; x <= 300; x += 100) { | 42 for (int x = 0; x <= 300; x += 100) { |
43 RasterSource::SolidColorAnalysis analysis; | 43 RasterSource::SolidColorAnalysis analysis; |
44 gfx::Rect rect(x, y, 100, 100); | 44 gfx::Rect rect(x, y, 100, 100); |
45 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis); | 45 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis); |
46 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 46 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
47 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | 47 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 // Add one non-solid pixel and recreate the raster source. | 51 // Add one non-solid pixel and recreate the raster source. |
52 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | 52 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), |
53 non_solid_paint); | 53 non_solid_paint); |
54 recording_source->Rerecord(); | 54 recording_source->RerecordPile(); |
55 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 55 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
56 | 56 |
57 RasterSource::SolidColorAnalysis analysis; | 57 RasterSource::SolidColorAnalysis analysis; |
58 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); | 58 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); |
59 EXPECT_FALSE(analysis.is_solid_color); | 59 EXPECT_FALSE(analysis.is_solid_color); |
60 | 60 |
61 pile->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); | 61 pile->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); |
62 EXPECT_TRUE(analysis.is_solid_color); | 62 EXPECT_TRUE(analysis.is_solid_color); |
63 EXPECT_EQ(analysis.solid_color, solid_color); | 63 EXPECT_EQ(analysis.solid_color, solid_color); |
64 | 64 |
(...skipping 25 matching lines...) Expand all Loading... |
90 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 90 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
91 SkPaint solid_paint; | 91 SkPaint solid_paint; |
92 solid_paint.setColor(solid_color); | 92 solid_paint.setColor(solid_color); |
93 | 93 |
94 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 94 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
95 SkPaint non_solid_paint; | 95 SkPaint non_solid_paint; |
96 non_solid_paint.setColor(non_solid_color); | 96 non_solid_paint.setColor(non_solid_color); |
97 | 97 |
98 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), | 98 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), |
99 solid_paint); | 99 solid_paint); |
100 recording_source->Rerecord(); | 100 recording_source->RerecordPile(); |
101 | 101 |
102 scoped_refptr<FakePicturePileImpl> pile = | 102 scoped_refptr<FakePicturePileImpl> pile = |
103 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 103 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
104 | 104 |
105 // Ensure everything is solid. | 105 // Ensure everything is solid. |
106 for (int y = 0; y <= 30; y += 10) { | 106 for (int y = 0; y <= 30; y += 10) { |
107 for (int x = 0; x <= 30; x += 10) { | 107 for (int x = 0; x <= 30; x += 10) { |
108 RasterSource::SolidColorAnalysis analysis; | 108 RasterSource::SolidColorAnalysis analysis; |
109 gfx::Rect rect(x, y, 10, 10); | 109 gfx::Rect rect(x, y, 10, 10); |
110 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis); | 110 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis); |
111 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 111 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
112 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | 112 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 // Add one non-solid pixel and recreate the raster source. | 116 // Add one non-solid pixel and recreate the raster source. |
117 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | 117 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), |
118 non_solid_paint); | 118 non_solid_paint); |
119 recording_source->Rerecord(); | 119 recording_source->RerecordPile(); |
120 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 120 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
121 | 121 |
122 RasterSource::SolidColorAnalysis analysis; | 122 RasterSource::SolidColorAnalysis analysis; |
123 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); | 123 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); |
124 EXPECT_FALSE(analysis.is_solid_color); | 124 EXPECT_FALSE(analysis.is_solid_color); |
125 | 125 |
126 pile->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); | 126 pile->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); |
127 EXPECT_TRUE(analysis.is_solid_color); | 127 EXPECT_TRUE(analysis.is_solid_color); |
128 EXPECT_EQ(analysis.solid_color, solid_color); | 128 EXPECT_EQ(analysis.solid_color, solid_color); |
129 | 129 |
(...skipping 22 matching lines...) Expand all Loading... |
152 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 152 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
153 RasterSource::SolidColorAnalysis analysis; | 153 RasterSource::SolidColorAnalysis analysis; |
154 EXPECT_FALSE(analysis.is_solid_color); | 154 EXPECT_FALSE(analysis.is_solid_color); |
155 | 155 |
156 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); | 156 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); |
157 | 157 |
158 EXPECT_TRUE(analysis.is_solid_color); | 158 EXPECT_TRUE(analysis.is_solid_color); |
159 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); | 159 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); |
160 } | 160 } |
161 | 161 |
| 162 TEST(PicturePileImplTest, PixelRefIteratorEmpty) { |
| 163 gfx::Size tile_size(128, 128); |
| 164 gfx::Size layer_bounds(256, 256); |
| 165 |
| 166 // Create a filled pile with no recording. |
| 167 scoped_refptr<FakePicturePileImpl> pile = |
| 168 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 169 |
| 170 // Tile sized iterators. |
| 171 { |
| 172 PicturePileImpl::PixelRefIterator iterator( |
| 173 gfx::Rect(0, 0, 128, 128), 1.0, pile.get()); |
| 174 EXPECT_FALSE(iterator); |
| 175 } |
| 176 { |
| 177 PicturePileImpl::PixelRefIterator iterator( |
| 178 gfx::Rect(0, 0, 256, 256), 2.0, pile.get()); |
| 179 EXPECT_FALSE(iterator); |
| 180 } |
| 181 { |
| 182 PicturePileImpl::PixelRefIterator iterator( |
| 183 gfx::Rect(0, 0, 64, 64), 0.5, pile.get()); |
| 184 EXPECT_FALSE(iterator); |
| 185 } |
| 186 // Shifted tile sized iterators. |
| 187 { |
| 188 PicturePileImpl::PixelRefIterator iterator( |
| 189 gfx::Rect(140, 140, 128, 128), 1.0, pile.get()); |
| 190 EXPECT_FALSE(iterator); |
| 191 } |
| 192 { |
| 193 PicturePileImpl::PixelRefIterator iterator( |
| 194 gfx::Rect(280, 280, 256, 256), 2.0, pile.get()); |
| 195 EXPECT_FALSE(iterator); |
| 196 } |
| 197 { |
| 198 PicturePileImpl::PixelRefIterator iterator( |
| 199 gfx::Rect(70, 70, 64, 64), 0.5, pile.get()); |
| 200 EXPECT_FALSE(iterator); |
| 201 } |
| 202 // Layer sized iterators. |
| 203 { |
| 204 PicturePileImpl::PixelRefIterator iterator( |
| 205 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
| 206 EXPECT_FALSE(iterator); |
| 207 } |
| 208 { |
| 209 PicturePileImpl::PixelRefIterator iterator( |
| 210 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
| 211 EXPECT_FALSE(iterator); |
| 212 } |
| 213 { |
| 214 PicturePileImpl::PixelRefIterator iterator( |
| 215 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
| 216 EXPECT_FALSE(iterator); |
| 217 } |
| 218 } |
| 219 |
| 220 TEST(PicturePileImplTest, PixelRefIteratorNoDiscardableRefs) { |
| 221 gfx::Size tile_size(128, 128); |
| 222 gfx::Size layer_bounds(256, 256); |
| 223 |
| 224 scoped_ptr<FakePicturePile> recording_source = |
| 225 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
| 226 SkPaint simple_paint; |
| 227 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); |
| 228 |
| 229 SkBitmap non_discardable_bitmap; |
| 230 CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap); |
| 231 |
| 232 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), |
| 233 simple_paint); |
| 234 recording_source->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), |
| 235 simple_paint); |
| 236 recording_source->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), |
| 237 simple_paint); |
| 238 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), |
| 239 simple_paint); |
| 240 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0)); |
| 241 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128)); |
| 242 recording_source->add_draw_bitmap(non_discardable_bitmap, |
| 243 gfx::Point(150, 150)); |
| 244 recording_source->RerecordPile(); |
| 245 |
| 246 scoped_refptr<FakePicturePileImpl> pile = |
| 247 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 248 |
| 249 // Tile sized iterators. |
| 250 { |
| 251 PicturePileImpl::PixelRefIterator iterator( |
| 252 gfx::Rect(0, 0, 128, 128), 1.0, pile.get()); |
| 253 EXPECT_FALSE(iterator); |
| 254 } |
| 255 { |
| 256 PicturePileImpl::PixelRefIterator iterator( |
| 257 gfx::Rect(0, 0, 256, 256), 2.0, pile.get()); |
| 258 EXPECT_FALSE(iterator); |
| 259 } |
| 260 { |
| 261 PicturePileImpl::PixelRefIterator iterator( |
| 262 gfx::Rect(0, 0, 64, 64), 0.5, pile.get()); |
| 263 EXPECT_FALSE(iterator); |
| 264 } |
| 265 // Shifted tile sized iterators. |
| 266 { |
| 267 PicturePileImpl::PixelRefIterator iterator( |
| 268 gfx::Rect(140, 140, 128, 128), 1.0, pile.get()); |
| 269 EXPECT_FALSE(iterator); |
| 270 } |
| 271 { |
| 272 PicturePileImpl::PixelRefIterator iterator( |
| 273 gfx::Rect(280, 280, 256, 256), 2.0, pile.get()); |
| 274 EXPECT_FALSE(iterator); |
| 275 } |
| 276 { |
| 277 PicturePileImpl::PixelRefIterator iterator( |
| 278 gfx::Rect(70, 70, 64, 64), 0.5, pile.get()); |
| 279 EXPECT_FALSE(iterator); |
| 280 } |
| 281 // Layer sized iterators. |
| 282 { |
| 283 PicturePileImpl::PixelRefIterator iterator( |
| 284 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
| 285 EXPECT_FALSE(iterator); |
| 286 } |
| 287 { |
| 288 PicturePileImpl::PixelRefIterator iterator( |
| 289 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
| 290 EXPECT_FALSE(iterator); |
| 291 } |
| 292 { |
| 293 PicturePileImpl::PixelRefIterator iterator( |
| 294 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
| 295 EXPECT_FALSE(iterator); |
| 296 } |
| 297 } |
| 298 |
| 299 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefs) { |
| 300 gfx::Size tile_size(128, 128); |
| 301 gfx::Size layer_bounds(256, 256); |
| 302 |
| 303 scoped_ptr<FakePicturePile> recording_source = |
| 304 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
| 305 |
| 306 SkBitmap discardable_bitmap[2][2]; |
| 307 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); |
| 308 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]); |
| 309 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); |
| 310 |
| 311 // Discardable pixel refs are found in the following cells: |
| 312 // |---|---| |
| 313 // | x | | |
| 314 // |---|---| |
| 315 // | x | x | |
| 316 // |---|---| |
| 317 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
| 318 recording_source->add_draw_bitmap(discardable_bitmap[1][0], |
| 319 gfx::Point(0, 130)); |
| 320 recording_source->add_draw_bitmap(discardable_bitmap[1][1], |
| 321 gfx::Point(140, 140)); |
| 322 recording_source->RerecordPile(); |
| 323 |
| 324 scoped_refptr<FakePicturePileImpl> pile = |
| 325 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 326 |
| 327 // Tile sized iterators. These should find only one pixel ref. |
| 328 { |
| 329 PicturePileImpl::PixelRefIterator iterator( |
| 330 gfx::Rect(0, 0, 128, 128), 1.0, pile.get()); |
| 331 EXPECT_TRUE(iterator); |
| 332 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 333 EXPECT_FALSE(++iterator); |
| 334 } |
| 335 { |
| 336 PicturePileImpl::PixelRefIterator iterator( |
| 337 gfx::Rect(0, 0, 256, 256), 2.0, pile.get()); |
| 338 EXPECT_TRUE(iterator); |
| 339 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 340 EXPECT_FALSE(++iterator); |
| 341 } |
| 342 { |
| 343 PicturePileImpl::PixelRefIterator iterator( |
| 344 gfx::Rect(0, 0, 64, 64), 0.5, pile.get()); |
| 345 EXPECT_TRUE(iterator); |
| 346 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 347 EXPECT_FALSE(++iterator); |
| 348 } |
| 349 // Shifted tile sized iterators. These should find only one pixel ref. |
| 350 { |
| 351 PicturePileImpl::PixelRefIterator iterator( |
| 352 gfx::Rect(140, 140, 128, 128), 1.0, pile.get()); |
| 353 EXPECT_TRUE(iterator); |
| 354 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 355 EXPECT_FALSE(++iterator); |
| 356 } |
| 357 { |
| 358 PicturePileImpl::PixelRefIterator iterator( |
| 359 gfx::Rect(280, 280, 256, 256), 2.0, pile.get()); |
| 360 EXPECT_TRUE(iterator); |
| 361 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 362 EXPECT_FALSE(++iterator); |
| 363 } |
| 364 { |
| 365 PicturePileImpl::PixelRefIterator iterator( |
| 366 gfx::Rect(70, 70, 64, 64), 0.5, pile.get()); |
| 367 EXPECT_TRUE(iterator); |
| 368 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 369 EXPECT_FALSE(++iterator); |
| 370 } |
| 371 // Ensure there's no discardable pixel refs in the empty cell |
| 372 { |
| 373 PicturePileImpl::PixelRefIterator iterator( |
| 374 gfx::Rect(140, 0, 128, 128), 1.0, pile.get()); |
| 375 EXPECT_FALSE(iterator); |
| 376 } |
| 377 // Layer sized iterators. These should find all 3 pixel refs. |
| 378 { |
| 379 PicturePileImpl::PixelRefIterator iterator( |
| 380 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
| 381 EXPECT_TRUE(iterator); |
| 382 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 383 EXPECT_TRUE(++iterator); |
| 384 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef()); |
| 385 EXPECT_TRUE(++iterator); |
| 386 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 387 EXPECT_FALSE(++iterator); |
| 388 } |
| 389 { |
| 390 PicturePileImpl::PixelRefIterator iterator( |
| 391 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
| 392 EXPECT_TRUE(iterator); |
| 393 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 394 EXPECT_TRUE(++iterator); |
| 395 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef()); |
| 396 EXPECT_TRUE(++iterator); |
| 397 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 398 EXPECT_FALSE(++iterator); |
| 399 } |
| 400 { |
| 401 PicturePileImpl::PixelRefIterator iterator( |
| 402 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
| 403 EXPECT_TRUE(iterator); |
| 404 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 405 EXPECT_TRUE(++iterator); |
| 406 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef()); |
| 407 EXPECT_TRUE(++iterator); |
| 408 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 409 EXPECT_FALSE(++iterator); |
| 410 } |
| 411 } |
| 412 |
162 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { | 413 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { |
163 gfx::Size tile_size(256, 256); | 414 gfx::Size tile_size(256, 256); |
164 gfx::Size layer_bounds(512, 512); | 415 gfx::Size layer_bounds(512, 512); |
165 | 416 |
166 scoped_ptr<FakePicturePile> recording_source = | 417 scoped_ptr<FakePicturePile> recording_source = |
167 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | 418 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
168 | 419 |
169 SkBitmap discardable_bitmap[2][2]; | 420 SkBitmap discardable_bitmap[2][2]; |
170 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); | 421 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); |
171 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]); | 422 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]); |
172 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); | 423 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); |
173 | 424 |
174 // Discardable pixel refs are found in the following cells: | 425 // Discardable pixel refs are found in the following cells: |
175 // |---|---| | 426 // |---|---| |
176 // | x | x | | 427 // | x | x | |
177 // |---|---| | 428 // |---|---| |
178 // | | x | | 429 // | | x | |
179 // |---|---| | 430 // |---|---| |
180 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); | 431 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
181 recording_source->add_draw_bitmap(discardable_bitmap[0][1], | 432 recording_source->add_draw_bitmap(discardable_bitmap[0][1], |
182 gfx::Point(260, 0)); | 433 gfx::Point(260, 0)); |
183 recording_source->add_draw_bitmap(discardable_bitmap[1][1], | 434 recording_source->add_draw_bitmap(discardable_bitmap[1][1], |
184 gfx::Point(260, 260)); | 435 gfx::Point(260, 260)); |
185 recording_source->Rerecord(); | 436 recording_source->RerecordPile(); |
186 | 437 |
187 scoped_refptr<FakePicturePileImpl> pile = | 438 scoped_refptr<FakePicturePileImpl> pile = |
188 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 439 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
189 | 440 |
190 // Tile sized iterators. These should find only one pixel ref. | 441 // Tile sized iterators. These should find only one pixel ref. |
191 { | 442 { |
192 PicturePileImpl::PixelRefIterator iterator( | 443 PicturePileImpl::PixelRefIterator iterator( |
193 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); | 444 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
194 EXPECT_TRUE(iterator); | 445 EXPECT_TRUE(iterator); |
195 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); | 446 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); | 538 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
288 EXPECT_FALSE(++iterator); | 539 EXPECT_FALSE(++iterator); |
289 | 540 |
290 EXPECT_TRUE(copy); | 541 EXPECT_TRUE(copy); |
291 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef()); | 542 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef()); |
292 EXPECT_TRUE(++copy); | 543 EXPECT_TRUE(++copy); |
293 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef()); | 544 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef()); |
294 EXPECT_FALSE(++copy); | 545 EXPECT_FALSE(++copy); |
295 } | 546 } |
296 | 547 |
| 548 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsBaseNonDiscardable) { |
| 549 gfx::Size tile_size(256, 256); |
| 550 gfx::Size layer_bounds(512, 512); |
| 551 |
| 552 scoped_ptr<FakePicturePile> recording_source = |
| 553 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
| 554 |
| 555 SkBitmap non_discardable_bitmap; |
| 556 CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap); |
| 557 |
| 558 SkBitmap discardable_bitmap[2][2]; |
| 559 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][0]); |
| 560 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][1]); |
| 561 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[1][1]); |
| 562 |
| 563 // One large non-discardable bitmap covers the whole grid. |
| 564 // Discardable pixel refs are found in the following cells: |
| 565 // |---|---| |
| 566 // | x | x | |
| 567 // |---|---| |
| 568 // | | x | |
| 569 // |---|---| |
| 570 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0)); |
| 571 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
| 572 recording_source->add_draw_bitmap(discardable_bitmap[0][1], |
| 573 gfx::Point(260, 0)); |
| 574 recording_source->add_draw_bitmap(discardable_bitmap[1][1], |
| 575 gfx::Point(260, 260)); |
| 576 recording_source->RerecordPile(); |
| 577 |
| 578 scoped_refptr<FakePicturePileImpl> pile = |
| 579 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 580 |
| 581 // Tile sized iterators. These should find only one pixel ref. |
| 582 { |
| 583 PicturePileImpl::PixelRefIterator iterator( |
| 584 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
| 585 EXPECT_TRUE(iterator); |
| 586 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 587 EXPECT_FALSE(++iterator); |
| 588 } |
| 589 { |
| 590 PicturePileImpl::PixelRefIterator iterator( |
| 591 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
| 592 EXPECT_TRUE(iterator); |
| 593 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 594 EXPECT_FALSE(++iterator); |
| 595 } |
| 596 { |
| 597 PicturePileImpl::PixelRefIterator iterator( |
| 598 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
| 599 EXPECT_TRUE(iterator); |
| 600 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 601 EXPECT_FALSE(++iterator); |
| 602 } |
| 603 // Shifted tile sized iterators. These should find only one pixel ref. |
| 604 { |
| 605 PicturePileImpl::PixelRefIterator iterator( |
| 606 gfx::Rect(260, 260, 256, 256), 1.0, pile.get()); |
| 607 EXPECT_TRUE(iterator); |
| 608 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 609 EXPECT_FALSE(++iterator); |
| 610 } |
| 611 { |
| 612 PicturePileImpl::PixelRefIterator iterator( |
| 613 gfx::Rect(520, 520, 512, 512), 2.0, pile.get()); |
| 614 EXPECT_TRUE(iterator); |
| 615 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 616 EXPECT_FALSE(++iterator); |
| 617 } |
| 618 { |
| 619 PicturePileImpl::PixelRefIterator iterator( |
| 620 gfx::Rect(130, 130, 128, 128), 0.5, pile.get()); |
| 621 EXPECT_TRUE(iterator); |
| 622 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 623 EXPECT_FALSE(++iterator); |
| 624 } |
| 625 // Ensure there's no discardable pixel refs in the empty cell |
| 626 { |
| 627 PicturePileImpl::PixelRefIterator iterator( |
| 628 gfx::Rect(0, 256, 256, 256), 1.0, pile.get()); |
| 629 EXPECT_FALSE(iterator); |
| 630 } |
| 631 // Layer sized iterators. These should find three pixel ref. |
| 632 { |
| 633 PicturePileImpl::PixelRefIterator iterator( |
| 634 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); |
| 635 EXPECT_TRUE(iterator); |
| 636 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 637 EXPECT_TRUE(++iterator); |
| 638 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
| 639 EXPECT_TRUE(++iterator); |
| 640 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 641 EXPECT_FALSE(++iterator); |
| 642 } |
| 643 { |
| 644 PicturePileImpl::PixelRefIterator iterator( |
| 645 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get()); |
| 646 EXPECT_TRUE(iterator); |
| 647 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 648 EXPECT_TRUE(++iterator); |
| 649 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
| 650 EXPECT_TRUE(++iterator); |
| 651 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 652 EXPECT_FALSE(++iterator); |
| 653 } |
| 654 { |
| 655 PicturePileImpl::PixelRefIterator iterator( |
| 656 gfx::Rect(0, 0, 256, 256), 0.5, pile.get()); |
| 657 EXPECT_TRUE(iterator); |
| 658 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| 659 EXPECT_TRUE(++iterator); |
| 660 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
| 661 EXPECT_TRUE(++iterator); |
| 662 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 663 EXPECT_FALSE(++iterator); |
| 664 } |
| 665 } |
| 666 |
297 TEST(PicturePileImplTest, RasterFullContents) { | 667 TEST(PicturePileImplTest, RasterFullContents) { |
298 gfx::Size tile_size(1000, 1000); | 668 gfx::Size tile_size(1000, 1000); |
299 gfx::Size layer_bounds(3, 5); | 669 gfx::Size layer_bounds(3, 5); |
300 float contents_scale = 1.5f; | 670 float contents_scale = 1.5f; |
301 float raster_divisions = 2.f; | 671 float raster_divisions = 2.f; |
302 | 672 |
303 scoped_ptr<FakePicturePile> recording_source = | 673 scoped_ptr<FakePicturePile> recording_source = |
304 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | 674 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
305 recording_source->SetBackgroundColor(SK_ColorBLACK); | 675 recording_source->SetBackgroundColor(SK_ColorBLACK); |
306 recording_source->SetIsSolidColor(false); | 676 recording_source->SetIsSolidColor(false); |
307 recording_source->SetRequiresClear(false); | 677 recording_source->SetRequiresClear(false); |
308 recording_source->SetClearCanvasWithDebugColor(false); | 678 recording_source->SetClearCanvasWithDebugColor(false); |
309 | 679 |
310 // Because the caller sets content opaque, it also promises that it | 680 // Because the caller sets content opaque, it also promises that it |
311 // has at least filled in layer_bounds opaquely. | 681 // has at least filled in layer_bounds opaquely. |
312 SkPaint white_paint; | 682 SkPaint white_paint; |
313 white_paint.setColor(SK_ColorWHITE); | 683 white_paint.setColor(SK_ColorWHITE); |
314 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 684 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
315 white_paint); | 685 white_paint); |
316 | 686 |
317 recording_source->SetMinContentsScale(contents_scale); | 687 recording_source->SetMinContentsScale(contents_scale); |
318 recording_source->Rerecord(); | 688 recording_source->RerecordPile(); |
319 | 689 |
320 scoped_refptr<FakePicturePileImpl> pile = | 690 scoped_refptr<FakePicturePileImpl> pile = |
321 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 691 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
322 | 692 |
323 gfx::Size content_bounds( | 693 gfx::Size content_bounds( |
324 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 694 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
325 | 695 |
326 // Simulate drawing into different tiles at different offsets. | 696 // Simulate drawing into different tiles at different offsets. |
327 int step_x = std::ceil(content_bounds.width() / raster_divisions); | 697 int step_x = std::ceil(content_bounds.width() / raster_divisions); |
328 int step_y = std::ceil(content_bounds.height() / raster_divisions); | 698 int step_y = std::ceil(content_bounds.height() / raster_divisions); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 gfx::Size tile_size(1000, 1000); | 738 gfx::Size tile_size(1000, 1000); |
369 gfx::Size layer_bounds(5, 3); | 739 gfx::Size layer_bounds(5, 3); |
370 float contents_scale = 0.5f; | 740 float contents_scale = 0.5f; |
371 | 741 |
372 scoped_ptr<FakePicturePile> recording_source = | 742 scoped_ptr<FakePicturePile> recording_source = |
373 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | 743 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
374 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); | 744 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); |
375 recording_source->SetRequiresClear(true); | 745 recording_source->SetRequiresClear(true); |
376 recording_source->SetMinContentsScale(contents_scale); | 746 recording_source->SetMinContentsScale(contents_scale); |
377 recording_source->SetClearCanvasWithDebugColor(false); | 747 recording_source->SetClearCanvasWithDebugColor(false); |
378 recording_source->Rerecord(); | 748 recording_source->RerecordPile(); |
379 | 749 |
380 scoped_refptr<FakePicturePileImpl> pile = | 750 scoped_refptr<FakePicturePileImpl> pile = |
381 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 751 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
382 gfx::Size content_bounds( | 752 gfx::Size content_bounds( |
383 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 753 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
384 | 754 |
385 gfx::Rect canvas_rect(content_bounds); | 755 gfx::Rect canvas_rect(content_bounds); |
386 canvas_rect.Inset(0, 0, -1, -1); | 756 canvas_rect.Inset(0, 0, -1, -1); |
387 | 757 |
388 SkBitmap bitmap; | 758 SkBitmap bitmap; |
(...skipping 29 matching lines...) Expand all Loading... |
418 recording_source->SetMinContentsScale(MinContentsScale()); | 788 recording_source->SetMinContentsScale(MinContentsScale()); |
419 recording_source->SetClearCanvasWithDebugColor(true); | 789 recording_source->SetClearCanvasWithDebugColor(true); |
420 | 790 |
421 SkPaint color_paint; | 791 SkPaint color_paint; |
422 color_paint.setColor(test_color); | 792 color_paint.setColor(test_color); |
423 // Additive paint, so that if two paints overlap, the color will change. | 793 // Additive paint, so that if two paints overlap, the color will change. |
424 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); | 794 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); |
425 // Paint outside the layer to make sure that blending works. | 795 // Paint outside the layer to make sure that blending works. |
426 recording_source->add_draw_rect_with_paint( | 796 recording_source->add_draw_rect_with_paint( |
427 gfx::RectF(bigger_than_layer_bounds), color_paint); | 797 gfx::RectF(bigger_than_layer_bounds), color_paint); |
428 recording_source->Rerecord(); | 798 recording_source->RerecordPile(); |
429 | 799 |
430 scoped_refptr<FakePicturePileImpl> pile = | 800 scoped_refptr<FakePicturePileImpl> pile = |
431 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 801 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
432 gfx::Size content_bounds( | 802 gfx::Size content_bounds( |
433 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 803 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
434 | 804 |
435 SkBitmap bitmap; | 805 SkBitmap bitmap; |
436 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 806 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
437 SkCanvas canvas(bitmap); | 807 SkCanvas canvas(bitmap); |
438 | 808 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 recording_source->tiling().TileBounds(2, 0), | 849 recording_source->tiling().TileBounds(2, 0), |
480 }; | 850 }; |
481 SkBitmap discardable_bitmap[arraysize(bitmap_rects)]; | 851 SkBitmap discardable_bitmap[arraysize(bitmap_rects)]; |
482 | 852 |
483 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { | 853 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { |
484 CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]); | 854 CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]); |
485 recording_source->add_draw_bitmap(discardable_bitmap[i], | 855 recording_source->add_draw_bitmap(discardable_bitmap[i], |
486 bitmap_rects[i].origin()); | 856 bitmap_rects[i].origin()); |
487 } | 857 } |
488 | 858 |
489 recording_source->Rerecord(); | 859 recording_source->RerecordPile(); |
490 | 860 |
491 scoped_refptr<FakePicturePileImpl> pile = | 861 scoped_refptr<FakePicturePileImpl> pile = |
492 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 862 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
493 | 863 |
494 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent | 864 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent |
495 // tiles, but not the actual tiles. | 865 // tiles, but not the actual tiles. |
496 EXPECT_TRUE( | 866 EXPECT_TRUE( |
497 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); | 867 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); |
498 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0))); | 868 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0))); |
499 EXPECT_TRUE( | 869 EXPECT_TRUE( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 EXPECT_TRUE(iterator); | 908 EXPECT_TRUE(iterator); |
539 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); | 909 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); |
540 EXPECT_TRUE(++iterator); | 910 EXPECT_TRUE(++iterator); |
541 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); | 911 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); |
542 EXPECT_FALSE(++iterator); | 912 EXPECT_FALSE(++iterator); |
543 } | 913 } |
544 } | 914 } |
545 | 915 |
546 } // namespace | 916 } // namespace |
547 } // namespace cc | 917 } // namespace cc |
OLD | NEW |