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 "config.h" | 5 #include "config.h" |
6 #include "core/paint/LayoutObjectDrawingRecorder.h" | 6 #include "core/paint/LayoutObjectDrawingRecorder.h" |
7 | 7 |
8 #include "core/layout/LayoutTestHelper.h" | 8 #include "core/layout/LayoutTestHelper.h" |
9 #include "core/layout/LayoutView.h" | 9 #include "core/layout/LayoutView.h" |
10 #include "core/paint/DeprecatedPaintLayer.h" | 10 #include "core/paint/DeprecatedPaintLayer.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 drawRect(context, layoutView(), PaintPhaseForeground, bound); | 116 drawRect(context, layoutView(), PaintPhaseForeground, bound); |
117 EXPECT_EQ((size_t)2, newDisplayItemsBeforeUpdate().size()); | 117 EXPECT_EQ((size_t)2, newDisplayItemsBeforeUpdate().size()); |
118 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[0])); | 118 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[0])); |
119 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[1])); | 119 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[1])); |
120 rootDisplayItemList().commitNewDisplayItems(); | 120 rootDisplayItemList().commitNewDisplayItems(); |
121 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size()); | 121 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size()); |
122 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); | 122 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); |
123 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1])); | 123 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1])); |
124 } | 124 } |
125 | 125 |
| 126 template <typename T> |
| 127 FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb
ject, const T& bounds) |
| 128 { |
| 129 list.invalidateAll(); |
| 130 { |
| 131 // Draw some things which will produce a non-null picture. |
| 132 GraphicsContext context(&list); |
| 133 LayoutObjectDrawingRecorder recorder( |
| 134 context, layoutObject, DisplayItem::BoxDecorationBackground, bounds)
; |
| 135 context.drawRect(enclosedIntRect(bounds)); |
| 136 } |
| 137 list.commitNewDisplayItems(); |
| 138 const auto& drawing = static_cast<const DrawingDisplayItem&>(list.displayIte
ms()[0]); |
| 139 return drawing.picture()->cullRect(); |
| 140 } |
| 141 |
| 142 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip) |
| 143 { |
| 144 // It's safe for the picture's cull rect to be expanded (though doing so |
| 145 // excessively may harm performance), but it cannot be contracted. |
| 146 // For now, this test expects the two rects to match completely. |
| 147 // |
| 148 // This rect is chosen so that in the x direction, pixel snapping rounds in |
| 149 // the opposite direction to enclosing, and in the y direction, the edges |
| 150 // are exactly on a half-pixel boundary. The numbers chosen map nicely to |
| 151 // both float and LayoutUnit, to make equality checking reliable. |
| 152 FloatRect rect(20.75, -5.5, 5.375, 10); |
| 153 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), rect
)); |
| 154 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), Layo
utRect(rect))); |
| 155 } |
| 156 |
126 } // namespace | 157 } // namespace |
127 } // namespace blink | 158 } // namespace blink |
OLD | NEW |