| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/paint/paint_op_buffer.h" | 5 #include "cc/paint/paint_op_buffer.h" |
| 6 #include "cc/paint/display_item_list.h" |
| 7 #include "cc/test/skia_common.h" |
| 6 #include "cc/test/test_skcanvas.h" | 8 #include "cc/test/test_skcanvas.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 10 |
| 9 namespace { | 11 namespace { |
| 10 | 12 |
| 11 template <typename T> | 13 template <typename T> |
| 12 void CheckRefCnt(const T& obj, int32_t count) { | 14 void CheckRefCnt(const T& obj, int32_t count) { |
| 13 // Skia doesn't define getRefCnt in all builds. | 15 // Skia doesn't define getRefCnt in all builds. |
| 14 #ifdef SK_DEBUG | 16 #ifdef SK_DEBUG |
| 15 EXPECT_EQ(obj->getRefCnt(), count); | 17 EXPECT_EQ(obj->getRefCnt(), count); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 buffer.push<DrawRecordOp>(std::move(record)); | 324 buffer.push<DrawRecordOp>(std::move(record)); |
| 323 buffer.push<RestoreOp>(); | 325 buffer.push<RestoreOp>(); |
| 324 | 326 |
| 325 SaveCountingCanvas canvas; | 327 SaveCountingCanvas canvas; |
| 326 buffer.playback(&canvas); | 328 buffer.playback(&canvas); |
| 327 | 329 |
| 328 EXPECT_EQ(1, canvas.save_count_); | 330 EXPECT_EQ(1, canvas.save_count_); |
| 329 EXPECT_EQ(1, canvas.restore_count_); | 331 EXPECT_EQ(1, canvas.restore_count_); |
| 330 } | 332 } |
| 331 | 333 |
| 334 TEST(PaintOpBufferTest, GathersDiscardableImagesFromNestedOps) { |
| 335 sk_sp<PaintRecord> internal_record = sk_make_sp<PaintRecord>(); |
| 336 sk_sp<SkImage> discardable_image = |
| 337 CreateDiscardableImage(gfx::Size(100, 100)); |
| 338 internal_record->push<DrawImageOp>( |
| 339 PaintImage(discardable_image, PaintImage::AnimationType::STATIC, |
| 340 PaintImage::CompletionState::DONE), |
| 341 0, 0, nullptr); |
| 342 |
| 343 sk_sp<PaintRecord> list_record = sk_make_sp<PaintRecord>(); |
| 344 sk_sp<SkImage> discardable_image2 = |
| 345 CreateDiscardableImage(gfx::Size(100, 100)); |
| 346 list_record->push<DrawImageOp>( |
| 347 PaintImage(discardable_image2, PaintImage::AnimationType::STATIC, |
| 348 PaintImage::CompletionState::DONE), |
| 349 100, 100, nullptr); |
| 350 scoped_refptr<DisplayItemList> display_list = new DisplayItemList; |
| 351 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 352 gfx::Rect(100, 100, 100, 100), list_record); |
| 353 display_list->Finalize(); |
| 354 |
| 355 PaintOpBuffer buffer; |
| 356 buffer.push<DrawRecordOp>(internal_record); |
| 357 buffer.push<DrawDisplayItemListOp>(display_list); |
| 358 DiscardableImageMap image_map_; |
| 359 { |
| 360 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map_, |
| 361 gfx::Size(200, 200)); |
| 362 buffer.GatherDiscardableImages(generator.image_store()); |
| 363 } |
| 364 |
| 365 gfx::ColorSpace target_color_space; |
| 366 std::vector<DrawImage> images; |
| 367 image_map_.GetDiscardableImagesInRect(gfx::Rect(0, 0, 5, 95), 1.f, |
| 368 target_color_space, &images); |
| 369 EXPECT_EQ(1u, images.size()); |
| 370 EXPECT_TRUE(discardable_image == images[0].image()); |
| 371 |
| 372 images.clear(); |
| 373 image_map_.GetDiscardableImagesInRect(gfx::Rect(105, 105, 5, 95), 1.f, |
| 374 target_color_space, &images); |
| 375 EXPECT_EQ(1u, images.size()); |
| 376 EXPECT_TRUE(discardable_image2 == images[0].image()); |
| 377 } |
| 378 |
| 332 } // namespace cc | 379 } // namespace cc |
| OLD | NEW |