OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/graphics/paint/DisplayItemList.h" |
| 6 |
| 7 #include "SkTypes.h" |
| 8 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 9 #include "platform/graphics/paint/PaintFlags.h" |
| 10 #include "platform/graphics/paint/PaintRecorder.h" |
| 11 #include "platform/graphics/skia/SkiaUtils.h" |
| 12 #include "platform/testing/FakeDisplayItemClient.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace blink { |
| 16 namespace { |
| 17 |
| 18 #define EXPECT_RECT_EQ(expected, actual) \ |
| 19 do { \ |
| 20 const IntRect& actual_rect = actual; \ |
| 21 EXPECT_EQ(expected.X(), actual_rect.X()); \ |
| 22 EXPECT_EQ(expected.Y(), actual_rect.Y()); \ |
| 23 EXPECT_EQ(expected.Width(), actual_rect.Width()); \ |
| 24 EXPECT_EQ(expected.Height(), actual_rect.Height()); \ |
| 25 } while (false) |
| 26 |
| 27 static const size_t kDefaultListBytes = 10 * 1024; |
| 28 |
| 29 class DisplayItemListTest : public ::testing::Test { |
| 30 public: |
| 31 DisplayItemListTest() : list_(kDefaultListBytes) {} |
| 32 |
| 33 DisplayItemList list_; |
| 34 FakeDisplayItemClient client_; |
| 35 }; |
| 36 |
| 37 static sk_sp<PaintRecord> CreateRectRecord(const IntRect& bounds) { |
| 38 PaintRecorder recorder; |
| 39 PaintCanvas* canvas = |
| 40 recorder.beginRecording(bounds.Width(), bounds.Height()); |
| 41 canvas->drawRect( |
| 42 SkRect::MakeXYWH(bounds.X(), bounds.Y(), bounds.Width(), bounds.Height()), |
| 43 PaintFlags()); |
| 44 return recorder.finishRecordingAsPicture(); |
| 45 } |
| 46 |
| 47 TEST_F(DisplayItemListTest, AppendVisualRect_Simple) { |
| 48 IntRect drawing_bounds(5, 6, 7, 8); |
| 49 list_.AllocateAndConstruct<DrawingDisplayItem>( |
| 50 client_, DisplayItem::Type::kDocumentBackground, |
| 51 CreateRectRecord(drawing_bounds), true); |
| 52 list_.AppendVisualRect(drawing_bounds); |
| 53 |
| 54 EXPECT_EQ(static_cast<size_t>(1), list_.size()); |
| 55 EXPECT_RECT_EQ(drawing_bounds, list_.VisualRect(0)); |
| 56 } |
| 57 |
| 58 TEST_F(DisplayItemListTest, AppendVisualRect_BlockContainingDrawing) { |
| 59 // TODO(wkorman): Note the visual rects for the paired begin/end are now |
| 60 // irrelevant as they're overwritten in cc::DisplayItemList when rebuilt to |
| 61 // represent the union of all drawing display item visual rects between the |
| 62 // pair. We should consider revising Blink's display item list in some form |
| 63 // so as to only store visual rects for drawing display items. |
| 64 IntRect drawing_bounds(5, 6, 1, 1); |
| 65 list_.AllocateAndConstruct<DrawingDisplayItem>( |
| 66 client_, DisplayItem::Type::kDocumentBackground, |
| 67 CreateRectRecord(drawing_bounds), true); |
| 68 list_.AppendVisualRect(drawing_bounds); |
| 69 |
| 70 EXPECT_EQ(static_cast<size_t>(1), list_.size()); |
| 71 EXPECT_RECT_EQ(drawing_bounds, list_.VisualRect(0)); |
| 72 } |
| 73 } // namespace |
| 74 } // namespace blink |
OLD | NEW |