| 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 "core/paint/LayoutObjectDrawingRecorder.h" | 5 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
| 8 #include "core/layout/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
| 9 #include "core/paint/PaintControllerPaintTest.h" | 9 #include "core/paint/PaintControllerPaintTest.h" |
| 10 #include "core/paint/PaintLayer.h" | 10 #include "core/paint/PaintLayer.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 context.drawRect(rect); | 37 context.drawRect(rect); |
| 38 } | 38 } |
| 39 | 39 |
| 40 TEST_F(LayoutObjectDrawingRecorderTest, Nothing) | 40 TEST_F(LayoutObjectDrawingRecorderTest, Nothing) |
| 41 { | 41 { |
| 42 rootPaintController().invalidateAll(); | 42 rootPaintController().invalidateAll(); |
| 43 GraphicsContext context(rootPaintController()); | 43 GraphicsContext context(rootPaintController()); |
| 44 LayoutRect bound = layoutView().viewRect(); | 44 LayoutRect bound = layoutView().viewRect(); |
| 45 drawNothing(context, layoutView(), PaintPhaseForeground, bound); | 45 drawNothing(context, layoutView(), PaintPhaseForeground, bound); |
| 46 rootPaintController().commitNewDisplayItems(); | 46 rootPaintController().commitNewDisplayItems(); |
| 47 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 1, | 47 EXPECT_DISPLAY_LIST(rootPaintController().getDisplayItemList(), 1, |
| 48 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); | 48 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); |
| 49 EXPECT_FALSE(static_cast<const DrawingDisplayItem&>(rootPaintController().di
splayItemList()[0]).picture()); | 49 EXPECT_FALSE(static_cast<const DrawingDisplayItem&>(rootPaintController().ge
tDisplayItemList()[0]).picture()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST_F(LayoutObjectDrawingRecorderTest, Rect) | 52 TEST_F(LayoutObjectDrawingRecorderTest, Rect) |
| 53 { | 53 { |
| 54 rootPaintController().invalidateAll(); | 54 rootPaintController().invalidateAll(); |
| 55 GraphicsContext context(rootPaintController()); | 55 GraphicsContext context(rootPaintController()); |
| 56 LayoutRect bound = layoutView().viewRect(); | 56 LayoutRect bound = layoutView().viewRect(); |
| 57 drawRect(context, layoutView(), PaintPhaseForeground, bound); | 57 drawRect(context, layoutView(), PaintPhaseForeground, bound); |
| 58 rootPaintController().commitNewDisplayItems(); | 58 rootPaintController().commitNewDisplayItems(); |
| 59 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 1, | 59 EXPECT_DISPLAY_LIST(rootPaintController().getDisplayItemList(), 1, |
| 60 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); | 60 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(LayoutObjectDrawingRecorderTest, Cached) | 63 TEST_F(LayoutObjectDrawingRecorderTest, Cached) |
| 64 { | 64 { |
| 65 rootPaintController().invalidateAll(); | 65 rootPaintController().invalidateAll(); |
| 66 GraphicsContext context(rootPaintController()); | 66 GraphicsContext context(rootPaintController()); |
| 67 LayoutRect bound = layoutView().viewRect(); | 67 LayoutRect bound = layoutView().viewRect(); |
| 68 drawNothing(context, layoutView(), PaintPhaseSelfBlockBackgroundOnly, bound)
; | 68 drawNothing(context, layoutView(), PaintPhaseSelfBlockBackgroundOnly, bound)
; |
| 69 drawRect(context, layoutView(), PaintPhaseForeground, bound); | 69 drawRect(context, layoutView(), PaintPhaseForeground, bound); |
| 70 rootPaintController().commitNewDisplayItems(); | 70 rootPaintController().commitNewDisplayItems(); |
| 71 | 71 |
| 72 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 2, | 72 EXPECT_DISPLAY_LIST(rootPaintController().getDisplayItemList(), 2, |
| 73 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseSelfBlockBackgroundOnly)), | 73 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseSelfBlockBackgroundOnly)), |
| 74 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); | 74 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); |
| 75 | 75 |
| 76 drawNothing(context, layoutView(), PaintPhaseSelfBlockBackgroundOnly, bound)
; | 76 drawNothing(context, layoutView(), PaintPhaseSelfBlockBackgroundOnly, bound)
; |
| 77 drawRect(context, layoutView(), PaintPhaseForeground, bound); | 77 drawRect(context, layoutView(), PaintPhaseForeground, bound); |
| 78 | 78 |
| 79 EXPECT_DISPLAY_LIST(rootPaintController().newDisplayItemList(), 2, | 79 EXPECT_DISPLAY_LIST(rootPaintController().newDisplayItemList(), 2, |
| 80 TestDisplayItem(layoutView(), DisplayItem::drawingTypeToCachedDrawingTyp
e(DisplayItem::paintPhaseToDrawingType(PaintPhaseSelfBlockBackgroundOnly))), | 80 TestDisplayItem(layoutView(), DisplayItem::drawingTypeToCachedDrawingTyp
e(DisplayItem::paintPhaseToDrawingType(PaintPhaseSelfBlockBackgroundOnly))), |
| 81 TestDisplayItem(layoutView(), DisplayItem::drawingTypeToCachedDrawingTyp
e(DisplayItem::paintPhaseToDrawingType(PaintPhaseForeground)))); | 81 TestDisplayItem(layoutView(), DisplayItem::drawingTypeToCachedDrawingTyp
e(DisplayItem::paintPhaseToDrawingType(PaintPhaseForeground)))); |
| 82 | 82 |
| 83 rootPaintController().commitNewDisplayItems(); | 83 rootPaintController().commitNewDisplayItems(); |
| 84 | 84 |
| 85 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 2, | 85 EXPECT_DISPLAY_LIST(rootPaintController().getDisplayItemList(), 2, |
| 86 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseSelfBlockBackgroundOnly)), | 86 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseSelfBlockBackgroundOnly)), |
| 87 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); | 87 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); |
| 88 } | 88 } |
| 89 | 89 |
| 90 template <typename T> | 90 template <typename T> |
| 91 FloatRect drawAndGetCullRect(PaintController& controller, const LayoutObject& la
youtObject, const T& bounds) | 91 FloatRect drawAndGetCullRect(PaintController& controller, const LayoutObject& la
youtObject, const T& bounds) |
| 92 { | 92 { |
| 93 controller.invalidateAll(); | 93 controller.invalidateAll(); |
| 94 { | 94 { |
| 95 // Draw some things which will produce a non-null picture. | 95 // Draw some things which will produce a non-null picture. |
| 96 GraphicsContext context(controller); | 96 GraphicsContext context(controller); |
| 97 LayoutObjectDrawingRecorder recorder(context, layoutObject, DisplayItem:
:BoxDecorationBackground, bounds); | 97 LayoutObjectDrawingRecorder recorder(context, layoutObject, DisplayItem:
:BoxDecorationBackground, bounds); |
| 98 context.drawRect(enclosedIntRect(FloatRect(bounds))); | 98 context.drawRect(enclosedIntRect(FloatRect(bounds))); |
| 99 } | 99 } |
| 100 controller.commitNewDisplayItems(); | 100 controller.commitNewDisplayItems(); |
| 101 const auto& drawing = static_cast<const DrawingDisplayItem&>(controller.disp
layItemList()[0]); | 101 const auto& drawing = static_cast<const DrawingDisplayItem&>(controller.getD
isplayItemList()[0]); |
| 102 return drawing.picture()->cullRect(); | 102 return drawing.picture()->cullRect(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip) | 105 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip) |
| 106 { | 106 { |
| 107 // It's safe for the picture's cull rect to be expanded (though doing so | 107 // It's safe for the picture's cull rect to be expanded (though doing so |
| 108 // excessively may harm performance), but it cannot be contracted. | 108 // excessively may harm performance), but it cannot be contracted. |
| 109 // For now, this test expects the two rects to match completely. | 109 // For now, this test expects the two rects to match completely. |
| 110 // | 110 // |
| 111 // This rect is chosen so that in the x direction, pixel snapping rounds in | 111 // This rect is chosen so that in the x direction, pixel snapping rounds in |
| (...skipping 16 matching lines...) Expand all Loading... |
| 128 | 128 |
| 129 rootPaintController().invalidateAll(); | 129 rootPaintController().invalidateAll(); |
| 130 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context
, layoutView(), PaintPhaseForeground)); | 130 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context
, layoutView(), PaintPhaseForeground)); |
| 131 { | 131 { |
| 132 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint
PhaseForeground, bounds); | 132 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint
PhaseForeground, bounds); |
| 133 IntRect rect(0, 0, 10, 10); | 133 IntRect rect(0, 0, 10, 10); |
| 134 context.drawRect(rect); | 134 context.drawRect(rect); |
| 135 } | 135 } |
| 136 | 136 |
| 137 rootPaintController().commitNewDisplayItems(); | 137 rootPaintController().commitNewDisplayItems(); |
| 138 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 1, | 138 EXPECT_DISPLAY_LIST(rootPaintController().getDisplayItemList(), 1, |
| 139 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); | 139 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); |
| 140 | 140 |
| 141 // Ensure we cannot use the cache with a new paint offset. | 141 // Ensure we cannot use the cache with a new paint offset. |
| 142 LayoutPoint newPaintOffset(2, 3); | 142 LayoutPoint newPaintOffset(2, 3); |
| 143 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context
, layoutView(), PaintPhaseForeground)); | 143 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context
, layoutView(), PaintPhaseForeground)); |
| 144 | 144 |
| 145 // Test that a new paint offset is recorded. | 145 // Test that a new paint offset is recorded. |
| 146 { | 146 { |
| 147 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint
PhaseForeground, bounds); | 147 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint
PhaseForeground, bounds); |
| 148 IntRect rect(0, 0, 10, 10); | 148 IntRect rect(0, 0, 10, 10); |
| 149 context.drawRect(rect); | 149 context.drawRect(rect); |
| 150 } | 150 } |
| 151 | 151 |
| 152 rootPaintController().commitNewDisplayItems(); | 152 rootPaintController().commitNewDisplayItems(); |
| 153 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 1, | 153 EXPECT_DISPLAY_LIST(rootPaintController().getDisplayItemList(), 1, |
| 154 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); | 154 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); |
| 155 | 155 |
| 156 // Ensure the old paint offset cannot be used. | 156 // Ensure the old paint offset cannot be used. |
| 157 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context
, layoutView(), PaintPhaseForeground)); | 157 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context
, layoutView(), PaintPhaseForeground)); |
| 158 | 158 |
| 159 // Ensure the new paint offset can be used. | 159 // Ensure the new paint offset can be used. |
| 160 EXPECT_TRUE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context,
layoutView(), PaintPhaseForeground)); | 160 EXPECT_TRUE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context,
layoutView(), PaintPhaseForeground)); |
| 161 rootPaintController().commitNewDisplayItems(); | 161 rootPaintController().commitNewDisplayItems(); |
| 162 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 1, | 162 EXPECT_DISPLAY_LIST(rootPaintController().getDisplayItemList(), 1, |
| 163 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); | 163 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint
PhaseForeground))); |
| 164 } | 164 } |
| 165 #endif | 165 #endif |
| 166 | 166 |
| 167 } // namespace | 167 } // namespace |
| 168 } // namespace blink | 168 } // namespace blink |
| OLD | NEW |