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

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

Issue 1316163002: Make the LayoutRect->FloatRect constructor explicit. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/paint/LayoutObjectDrawingRecorder.h ('k') | Source/core/paint/SVGFilterPainter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 { 43 {
44 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE nabled); 44 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE nabled);
45 } 45 }
46 46
47 LayoutView* m_layoutView; 47 LayoutView* m_layoutView;
48 bool m_originalSlimmingPaintEnabled; 48 bool m_originalSlimmingPaintEnabled;
49 }; 49 };
50 50
51 namespace { 51 namespace {
52 52
53 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const FloatRect& bound) 53 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const LayoutRect& bound)
54 { 54 {
55 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase)) 55 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase))
56 return; 56 return;
57 57
58 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d); 58 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d);
59 } 59 }
60 60
61 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const FloatRect& bound) 61 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const LayoutRect& bound)
62 { 62 {
63 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase)) 63 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase))
64 return; 64 return;
65 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d); 65 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d);
66 IntRect rect(0, 0, 10, 10); 66 IntRect rect(0, 0, 10, 10);
67 context.drawRect(rect); 67 context.drawRect(rect);
68 } 68 }
69 69
70 bool isDrawing(const DisplayItem& item) 70 bool isDrawing(const DisplayItem& item)
71 { 71 {
72 return DisplayItem::isDrawingType(item.type()); 72 return DisplayItem::isDrawingType(item.type());
73 } 73 }
74 74
75 bool isCached(const DisplayItem& item) 75 bool isCached(const DisplayItem& item)
76 { 76 {
77 return DisplayItem::isCachedType(item.type()); 77 return DisplayItem::isCachedType(item.type());
78 } 78 }
79 79
80 TEST_F(LayoutObjectDrawingRecorderTest, Nothing) 80 TEST_F(LayoutObjectDrawingRecorderTest, Nothing)
81 { 81 {
82 GraphicsContext context(&rootDisplayItemList()); 82 GraphicsContext context(&rootDisplayItemList());
83 FloatRect bound = layoutView().viewRect(); 83 LayoutRect bound = layoutView().viewRect();
84 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size()); 84 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size());
85 85
86 drawNothing(context, layoutView(), PaintPhaseForeground, bound); 86 drawNothing(context, layoutView(), PaintPhaseForeground, bound);
87 rootDisplayItemList().commitNewDisplayItems(); 87 rootDisplayItemList().commitNewDisplayItems();
88 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 88 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
89 const auto& item = rootDisplayItemList().displayItems()[0]; 89 const auto& item = rootDisplayItemList().displayItems()[0];
90 ASSERT_TRUE(isDrawing(item)); 90 ASSERT_TRUE(isDrawing(item));
91 EXPECT_FALSE(static_cast<const DrawingDisplayItem&>(item).picture()); 91 EXPECT_FALSE(static_cast<const DrawingDisplayItem&>(item).picture());
92 } 92 }
93 93
94 TEST_F(LayoutObjectDrawingRecorderTest, Rect) 94 TEST_F(LayoutObjectDrawingRecorderTest, Rect)
95 { 95 {
96 GraphicsContext context(&rootDisplayItemList()); 96 GraphicsContext context(&rootDisplayItemList());
97 FloatRect bound = layoutView().viewRect(); 97 LayoutRect bound = layoutView().viewRect();
98 drawRect(context, layoutView(), PaintPhaseForeground, bound); 98 drawRect(context, layoutView(), PaintPhaseForeground, bound);
99 rootDisplayItemList().commitNewDisplayItems(); 99 rootDisplayItemList().commitNewDisplayItems();
100 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 100 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
101 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 101 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
102 } 102 }
103 103
104 TEST_F(LayoutObjectDrawingRecorderTest, Cached) 104 TEST_F(LayoutObjectDrawingRecorderTest, Cached)
105 { 105 {
106 GraphicsContext context(&rootDisplayItemList()); 106 GraphicsContext context(&rootDisplayItemList());
107 FloatRect bound = layoutView().viewRect(); 107 LayoutRect bound = layoutView().viewRect();
108 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound); 108 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound);
109 drawRect(context, layoutView(), PaintPhaseForeground, bound); 109 drawRect(context, layoutView(), PaintPhaseForeground, bound);
110 rootDisplayItemList().commitNewDisplayItems(); 110 rootDisplayItemList().commitNewDisplayItems();
111 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size()); 111 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size());
112 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 112 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
113 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1])); 113 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1]));
114 114
115 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound); 115 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound);
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> 126 template <typename T>
127 FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb ject, const T& bounds) 127 FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb ject, const T& bounds)
128 { 128 {
129 list.invalidateAll(); 129 list.invalidateAll();
130 { 130 {
131 // Draw some things which will produce a non-null picture. 131 // Draw some things which will produce a non-null picture.
132 GraphicsContext context(&list); 132 GraphicsContext context(&list);
133 LayoutObjectDrawingRecorder recorder( 133 LayoutObjectDrawingRecorder recorder(
134 context, layoutObject, DisplayItem::BoxDecorationBackground, bounds) ; 134 context, layoutObject, DisplayItem::BoxDecorationBackground, bounds) ;
135 context.drawRect(enclosedIntRect(bounds)); 135 context.drawRect(enclosedIntRect(FloatRect(bounds)));
136 } 136 }
137 list.commitNewDisplayItems(); 137 list.commitNewDisplayItems();
138 const auto& drawing = static_cast<const DrawingDisplayItem&>(list.displayIte ms()[0]); 138 const auto& drawing = static_cast<const DrawingDisplayItem&>(list.displayIte ms()[0]);
139 return drawing.picture()->cullRect(); 139 return drawing.picture()->cullRect();
140 } 140 }
141 141
142 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip) 142 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip)
143 { 143 {
144 // It's safe for the picture's cull rect to be expanded (though doing so 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. 145 // excessively may harm performance), but it cannot be contracted.
146 // For now, this test expects the two rects to match completely. 146 // For now, this test expects the two rects to match completely.
147 // 147 //
148 // This rect is chosen so that in the x direction, pixel snapping rounds in 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 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 150 // are exactly on a half-pixel boundary. The numbers chosen map nicely to
151 // both float and LayoutUnit, to make equality checking reliable. 151 // both float and LayoutUnit, to make equality checking reliable.
152 FloatRect rect(20.75, -5.5, 5.375, 10); 152 FloatRect rect(20.75, -5.5, 5.375, 10);
153 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), rect )); 153 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), rect ));
154 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), Layo utRect(rect))); 154 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), Layo utRect(rect)));
155 } 155 }
156 156
157 } // namespace 157 } // namespace
158 } // namespace blink 158 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/LayoutObjectDrawingRecorder.h ('k') | Source/core/paint/SVGFilterPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698