| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/display_item_list.h" | 5 #include "cc/paint/display_item_list.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 337 |
| 338 // Make an PaintRecord whose size is known. | 338 // Make an PaintRecord whose size is known. |
| 339 gfx::Rect layer_rect(100, 100); | 339 gfx::Rect layer_rect(100, 100); |
| 340 PaintRecorder recorder; | 340 PaintRecorder recorder; |
| 341 PaintFlags blue_flags; | 341 PaintFlags blue_flags; |
| 342 blue_flags.setColor(SK_ColorBLUE); | 342 blue_flags.setColor(SK_ColorBLUE); |
| 343 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); | 343 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); |
| 344 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) | 344 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) |
| 345 canvas->drawRect(SkRect(), blue_flags); | 345 canvas->drawRect(SkRect(), blue_flags); |
| 346 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 346 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 347 size_t record_size = record->approximateBytesUsed(); | 347 size_t record_size = record->bytes_used(); |
| 348 ASSERT_GE(record_size, kNumCommandsInTestSkPicture * sizeof(SkRect)); | 348 ASSERT_GE(record_size, kNumCommandsInTestSkPicture * sizeof(SkRect)); |
| 349 | 349 |
| 350 auto list = make_scoped_refptr(new DisplayItemList); | 350 auto list = make_scoped_refptr(new DisplayItemList); |
| 351 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, record); | 351 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, record); |
| 352 list->Finalize(); | 352 list->Finalize(); |
| 353 memory_usage = list->ApproximateMemoryUsage(); | 353 memory_usage = list->ApproximateMemoryUsage(); |
| 354 EXPECT_GE(memory_usage, record_size); | 354 EXPECT_GE(memory_usage, record_size); |
| 355 EXPECT_LE(memory_usage, 2 * record_size); | 355 EXPECT_LE(memory_usage, 2 * record_size); |
| 356 } | 356 } |
| 357 | 357 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 PaintRecorder recorder; | 797 PaintRecorder recorder; |
| 798 PaintCanvas* canvas = | 798 PaintCanvas* canvas = |
| 799 recorder.beginRecording(kVisualRect.width(), kVisualRect.height()); | 799 recorder.beginRecording(kVisualRect.width(), kVisualRect.height()); |
| 800 PaintFlags flags; | 800 PaintFlags flags; |
| 801 flags.setAlpha(40); | 801 flags.setAlpha(40); |
| 802 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); | 802 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); |
| 803 // Add an extra op here. | 803 // Add an extra op here. |
| 804 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); | 804 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); |
| 805 record = recorder.finishRecordingAsPicture(); | 805 record = recorder.finishRecordingAsPicture(); |
| 806 } | 806 } |
| 807 EXPECT_GT(record->approximateOpCount(), 1); | 807 EXPECT_GT(record->size(), 1u); |
| 808 | 808 |
| 809 auto list = make_scoped_refptr(new DisplayItemList); | 809 auto list = make_scoped_refptr(new DisplayItemList); |
| 810 | 810 |
| 811 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( | 811 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( |
| 812 80, SkBlendMode::kSrcOver, nullptr, nullptr, false); | 812 80, SkBlendMode::kSrcOver, nullptr, nullptr, false); |
| 813 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, | 813 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, |
| 814 std::move(record)); | 814 std::move(record)); |
| 815 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); | 815 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); |
| 816 list->Finalize(); | 816 list->Finalize(); |
| 817 | 817 |
| 818 SaveCountingCanvas canvas; | 818 SaveCountingCanvas canvas; |
| 819 list->Raster(&canvas); | 819 list->Raster(&canvas); |
| 820 | 820 |
| 821 EXPECT_EQ(1, canvas.save_count_); | 821 EXPECT_EQ(1, canvas.save_count_); |
| 822 EXPECT_EQ(1, canvas.restore_count_); | 822 EXPECT_EQ(1, canvas.restore_count_); |
| 823 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); | 823 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); |
| 824 EXPECT_LE(40, canvas.paint_.getAlpha()); | 824 EXPECT_LE(40, canvas.paint_.getAlpha()); |
| 825 } | 825 } |
| 826 | 826 |
| 827 } // namespace cc | 827 } // namespace cc |
| OLD | NEW |