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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) |
jbroman
2015/08/26 19:06:44
same line of reasoning here
chrishtr
2015/08/26 20:53:51
Left it LayoutRect because layoutView().viewRect()
| |
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 } // namespace | 126 } // namespace |
127 } // namespace blink | 127 } // namespace blink |
OLD | NEW |