Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: third_party/WebKit/Source/core/paint/LayoutObjectDrawingRecorderTest.cpp

Issue 1755853002: Remove old paint offset caching code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "platform/graphics/GraphicsContext.h" 11 #include "platform/graphics/GraphicsContext.h"
12 #include "platform/graphics/GraphicsLayer.h" 12 #include "platform/graphics/GraphicsLayer.h"
13 #include "platform/graphics/paint/DrawingDisplayItem.h" 13 #include "platform/graphics/paint/DrawingDisplayItem.h"
14 #include "platform/graphics/paint/PaintController.h" 14 #include "platform/graphics/paint/PaintController.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 using LayoutObjectDrawingRecorderTest = PaintControllerPaintTest; 19 using LayoutObjectDrawingRecorderTest = PaintControllerPaintTest;
20 20
21 namespace { 21 namespace {
22 22
23 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const LayoutRect& bound) 23 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const LayoutRect& bound)
24 { 24 {
25 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint())) 25 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase))
26 return; 26 return;
27 27
28 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint()); 28 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d);
29 } 29 }
30 30
31 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const LayoutRect& bound) 31 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const LayoutRect& bound)
32 { 32 {
33 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint())) 33 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase))
34 return; 34 return;
35 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint()); 35 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d);
36 IntRect rect(0, 0, 10, 10); 36 IntRect rect(0, 0, 10, 10);
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);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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( 97 LayoutObjectDrawingRecorder recorder(context, layoutObject, DisplayItem: :BoxDecorationBackground, bounds);
98 context, layoutObject, DisplayItem::BoxDecorationBackground, bounds, LayoutPoint());
99 context.drawRect(enclosedIntRect(FloatRect(bounds))); 98 context.drawRect(enclosedIntRect(FloatRect(bounds)));
100 } 99 }
101 controller.commitNewDisplayItems(); 100 controller.commitNewDisplayItems();
102 const auto& drawing = static_cast<const DrawingDisplayItem&>(controller.disp layItemList()[0]); 101 const auto& drawing = static_cast<const DrawingDisplayItem&>(controller.disp layItemList()[0]);
103 return drawing.picture()->cullRect(); 102 return drawing.picture()->cullRect();
104 } 103 }
105 104
106 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip) 105 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip)
107 { 106 {
108 // 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
109 // excessively may harm performance), but it cannot be contracted. 108 // excessively may harm performance), but it cannot be contracted.
110 // For now, this test expects the two rects to match completely. 109 // For now, this test expects the two rects to match completely.
111 // 110 //
112 // 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
113 // the opposite direction to enclosing, and in the y direction, the edges 112 // the opposite direction to enclosing, and in the y direction, the edges
114 // are exactly on a half-pixel boundary. The numbers chosen map nicely to 113 // are exactly on a half-pixel boundary. The numbers chosen map nicely to
115 // both float and LayoutUnit, to make equality checking reliable. 114 // both float and LayoutUnit, to make equality checking reliable.
116 FloatRect rect(20.75, -5.5, 5.375, 10); 115 FloatRect rect(20.75, -5.5, 5.375, 10);
117 EXPECT_EQ(rect, drawAndGetCullRect(rootPaintController(), layoutView(), rect )); 116 EXPECT_EQ(rect, drawAndGetCullRect(rootPaintController(), layoutView(), rect ));
118 EXPECT_EQ(rect, drawAndGetCullRect(rootPaintController(), layoutView(), Layo utRect(rect))); 117 EXPECT_EQ(rect, drawAndGetCullRect(rootPaintController(), layoutView(), Layo utRect(rect)));
119 } 118 }
120 119
120 #if 0 // TODO(wangxianzhu): Rewrite this test for slimmingPaintInvalidation.
121 TEST_F(LayoutObjectDrawingRecorderTest, PaintOffsetCache) 121 TEST_F(LayoutObjectDrawingRecorderTest, PaintOffsetCache)
122 { 122 {
123 RuntimeEnabledFeatures::setSlimmingPaintOffsetCachingEnabled(true); 123 RuntimeEnabledFeatures::setSlimmingPaintOffsetCachingEnabled(true);
124 124
125 GraphicsContext context(rootPaintController()); 125 GraphicsContext context(rootPaintController());
126 LayoutRect bounds = layoutView().viewRect(); 126 LayoutRect bounds = layoutView().viewRect();
127 LayoutPoint paintOffset(1, 2); 127 LayoutPoint paintOffset(1, 2);
128 128
129 rootPaintController().invalidateAll(); 129 rootPaintController().invalidateAll();
130 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, paintOffset)); 130 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground));
131 { 131 {
132 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint PhaseForeground, bounds, paintOffset); 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().displayItemList(), 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, newPaintOffset)); 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, newPaintOffset); 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().displayItemList(), 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, paintOffset)); 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, newPaintOffset)); 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().displayItemList(), 1,
163 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground))); 163 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
164 } 164 }
165 #endif
165 166
166 } // namespace 167 } // namespace
167 } // namespace blink 168 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698