| 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->RerecordPile(); | 35 recording_source->Rerecord(); |
| 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->RerecordPile(); | 54 recording_source->Rerecord(); |
| 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->RerecordPile(); | 100 recording_source->Rerecord(); |
| 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->RerecordPile(); | 119 recording_source->Rerecord(); |
| 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 | |
| 413 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { | 162 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { |
| 414 gfx::Size tile_size(256, 256); | 163 gfx::Size tile_size(256, 256); |
| 415 gfx::Size layer_bounds(512, 512); | 164 gfx::Size layer_bounds(512, 512); |
| 416 | 165 |
| 417 scoped_ptr<FakePicturePile> recording_source = | 166 scoped_ptr<FakePicturePile> recording_source = |
| 418 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | 167 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
| 419 | 168 |
| 420 SkBitmap discardable_bitmap[2][2]; | 169 SkBitmap discardable_bitmap[2][2]; |
| 421 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); | 170 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); |
| 422 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]); | 171 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]); |
| 423 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); | 172 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); |
| 424 | 173 |
| 425 // Discardable pixel refs are found in the following cells: | 174 // Discardable pixel refs are found in the following cells: |
| 426 // |---|---| | 175 // |---|---| |
| 427 // | x | x | | 176 // | x | x | |
| 428 // |---|---| | 177 // |---|---| |
| 429 // | | x | | 178 // | | x | |
| 430 // |---|---| | 179 // |---|---| |
| 431 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); | 180 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
| 432 recording_source->add_draw_bitmap(discardable_bitmap[0][1], | 181 recording_source->add_draw_bitmap(discardable_bitmap[0][1], |
| 433 gfx::Point(260, 0)); | 182 gfx::Point(260, 0)); |
| 434 recording_source->add_draw_bitmap(discardable_bitmap[1][1], | 183 recording_source->add_draw_bitmap(discardable_bitmap[1][1], |
| 435 gfx::Point(260, 260)); | 184 gfx::Point(260, 260)); |
| 436 recording_source->RerecordPile(); | 185 recording_source->Rerecord(); |
| 437 | 186 |
| 438 scoped_refptr<FakePicturePileImpl> pile = | 187 scoped_refptr<FakePicturePileImpl> pile = |
| 439 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 188 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 440 | 189 |
| 441 // Tile sized iterators. These should find only one pixel ref. | 190 // Tile sized iterators. These should find only one pixel ref. |
| 442 { | 191 { |
| 443 PicturePileImpl::PixelRefIterator iterator( | 192 PicturePileImpl::PixelRefIterator iterator( |
| 444 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); | 193 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
| 445 EXPECT_TRUE(iterator); | 194 EXPECT_TRUE(iterator); |
| 446 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); | 195 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); | 287 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
| 539 EXPECT_FALSE(++iterator); | 288 EXPECT_FALSE(++iterator); |
| 540 | 289 |
| 541 EXPECT_TRUE(copy); | 290 EXPECT_TRUE(copy); |
| 542 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef()); | 291 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef()); |
| 543 EXPECT_TRUE(++copy); | 292 EXPECT_TRUE(++copy); |
| 544 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef()); | 293 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef()); |
| 545 EXPECT_FALSE(++copy); | 294 EXPECT_FALSE(++copy); |
| 546 } | 295 } |
| 547 | 296 |
| 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 | |
| 667 TEST(PicturePileImplTest, RasterFullContents) { | 297 TEST(PicturePileImplTest, RasterFullContents) { |
| 668 gfx::Size tile_size(1000, 1000); | 298 gfx::Size tile_size(1000, 1000); |
| 669 gfx::Size layer_bounds(3, 5); | 299 gfx::Size layer_bounds(3, 5); |
| 670 float contents_scale = 1.5f; | 300 float contents_scale = 1.5f; |
| 671 float raster_divisions = 2.f; | 301 float raster_divisions = 2.f; |
| 672 | 302 |
| 673 scoped_ptr<FakePicturePile> recording_source = | 303 scoped_ptr<FakePicturePile> recording_source = |
| 674 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | 304 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
| 675 recording_source->SetBackgroundColor(SK_ColorBLACK); | 305 recording_source->SetBackgroundColor(SK_ColorBLACK); |
| 676 recording_source->SetIsSolidColor(false); | 306 recording_source->SetIsSolidColor(false); |
| 677 recording_source->SetRequiresClear(false); | 307 recording_source->SetRequiresClear(false); |
| 678 recording_source->SetClearCanvasWithDebugColor(false); | 308 recording_source->SetClearCanvasWithDebugColor(false); |
| 679 | 309 |
| 680 // Because the caller sets content opaque, it also promises that it | 310 // Because the caller sets content opaque, it also promises that it |
| 681 // has at least filled in layer_bounds opaquely. | 311 // has at least filled in layer_bounds opaquely. |
| 682 SkPaint white_paint; | 312 SkPaint white_paint; |
| 683 white_paint.setColor(SK_ColorWHITE); | 313 white_paint.setColor(SK_ColorWHITE); |
| 684 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 314 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
| 685 white_paint); | 315 white_paint); |
| 686 | 316 |
| 687 recording_source->SetMinContentsScale(contents_scale); | 317 recording_source->SetMinContentsScale(contents_scale); |
| 688 recording_source->RerecordPile(); | 318 recording_source->Rerecord(); |
| 689 | 319 |
| 690 scoped_refptr<FakePicturePileImpl> pile = | 320 scoped_refptr<FakePicturePileImpl> pile = |
| 691 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 321 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 692 | 322 |
| 693 gfx::Size content_bounds( | 323 gfx::Size content_bounds( |
| 694 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 324 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
| 695 | 325 |
| 696 // Simulate drawing into different tiles at different offsets. | 326 // Simulate drawing into different tiles at different offsets. |
| 697 int step_x = std::ceil(content_bounds.width() / raster_divisions); | 327 int step_x = std::ceil(content_bounds.width() / raster_divisions); |
| 698 int step_y = std::ceil(content_bounds.height() / raster_divisions); | 328 int step_y = std::ceil(content_bounds.height() / raster_divisions); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 gfx::Size tile_size(1000, 1000); | 368 gfx::Size tile_size(1000, 1000); |
| 739 gfx::Size layer_bounds(5, 3); | 369 gfx::Size layer_bounds(5, 3); |
| 740 float contents_scale = 0.5f; | 370 float contents_scale = 0.5f; |
| 741 | 371 |
| 742 scoped_ptr<FakePicturePile> recording_source = | 372 scoped_ptr<FakePicturePile> recording_source = |
| 743 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | 373 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
| 744 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); | 374 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 745 recording_source->SetRequiresClear(true); | 375 recording_source->SetRequiresClear(true); |
| 746 recording_source->SetMinContentsScale(contents_scale); | 376 recording_source->SetMinContentsScale(contents_scale); |
| 747 recording_source->SetClearCanvasWithDebugColor(false); | 377 recording_source->SetClearCanvasWithDebugColor(false); |
| 748 recording_source->RerecordPile(); | 378 recording_source->Rerecord(); |
| 749 | 379 |
| 750 scoped_refptr<FakePicturePileImpl> pile = | 380 scoped_refptr<FakePicturePileImpl> pile = |
| 751 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 381 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 752 gfx::Size content_bounds( | 382 gfx::Size content_bounds( |
| 753 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 383 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
| 754 | 384 |
| 755 gfx::Rect canvas_rect(content_bounds); | 385 gfx::Rect canvas_rect(content_bounds); |
| 756 canvas_rect.Inset(0, 0, -1, -1); | 386 canvas_rect.Inset(0, 0, -1, -1); |
| 757 | 387 |
| 758 SkBitmap bitmap; | 388 SkBitmap bitmap; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 788 recording_source->SetMinContentsScale(MinContentsScale()); | 418 recording_source->SetMinContentsScale(MinContentsScale()); |
| 789 recording_source->SetClearCanvasWithDebugColor(true); | 419 recording_source->SetClearCanvasWithDebugColor(true); |
| 790 | 420 |
| 791 SkPaint color_paint; | 421 SkPaint color_paint; |
| 792 color_paint.setColor(test_color); | 422 color_paint.setColor(test_color); |
| 793 // Additive paint, so that if two paints overlap, the color will change. | 423 // Additive paint, so that if two paints overlap, the color will change. |
| 794 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); | 424 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); |
| 795 // Paint outside the layer to make sure that blending works. | 425 // Paint outside the layer to make sure that blending works. |
| 796 recording_source->add_draw_rect_with_paint( | 426 recording_source->add_draw_rect_with_paint( |
| 797 gfx::RectF(bigger_than_layer_bounds), color_paint); | 427 gfx::RectF(bigger_than_layer_bounds), color_paint); |
| 798 recording_source->RerecordPile(); | 428 recording_source->Rerecord(); |
| 799 | 429 |
| 800 scoped_refptr<FakePicturePileImpl> pile = | 430 scoped_refptr<FakePicturePileImpl> pile = |
| 801 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 431 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 802 gfx::Size content_bounds( | 432 gfx::Size content_bounds( |
| 803 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | 433 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); |
| 804 | 434 |
| 805 SkBitmap bitmap; | 435 SkBitmap bitmap; |
| 806 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 436 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
| 807 SkCanvas canvas(bitmap); | 437 SkCanvas canvas(bitmap); |
| 808 | 438 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 recording_source->tiling().TileBounds(2, 0), | 479 recording_source->tiling().TileBounds(2, 0), |
| 850 }; | 480 }; |
| 851 SkBitmap discardable_bitmap[arraysize(bitmap_rects)]; | 481 SkBitmap discardable_bitmap[arraysize(bitmap_rects)]; |
| 852 | 482 |
| 853 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { | 483 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { |
| 854 CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]); | 484 CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]); |
| 855 recording_source->add_draw_bitmap(discardable_bitmap[i], | 485 recording_source->add_draw_bitmap(discardable_bitmap[i], |
| 856 bitmap_rects[i].origin()); | 486 bitmap_rects[i].origin()); |
| 857 } | 487 } |
| 858 | 488 |
| 859 recording_source->RerecordPile(); | 489 recording_source->Rerecord(); |
| 860 | 490 |
| 861 scoped_refptr<FakePicturePileImpl> pile = | 491 scoped_refptr<FakePicturePileImpl> pile = |
| 862 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | 492 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); |
| 863 | 493 |
| 864 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent | 494 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent |
| 865 // tiles, but not the actual tiles. | 495 // tiles, but not the actual tiles. |
| 866 EXPECT_TRUE( | 496 EXPECT_TRUE( |
| 867 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); | 497 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); |
| 868 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0))); | 498 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0))); |
| 869 EXPECT_TRUE( | 499 EXPECT_TRUE( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 EXPECT_TRUE(iterator); | 538 EXPECT_TRUE(iterator); |
| 909 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); | 539 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); |
| 910 EXPECT_TRUE(++iterator); | 540 EXPECT_TRUE(++iterator); |
| 911 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); | 541 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); |
| 912 EXPECT_FALSE(++iterator); | 542 EXPECT_FALSE(++iterator); |
| 913 } | 543 } |
| 914 } | 544 } |
| 915 | 545 |
| 916 } // namespace | 546 } // namespace |
| 917 } // namespace cc | 547 } // namespace cc |
| OLD | NEW |