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

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

Issue 1157653005: Move use of DisplayItemList's vector behind an explicit DisplayItems interface. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: DisplayItems must be noncopyable (Windows build fix) Created 5 years, 6 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
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"
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/DisplayItemList.h" 13 #include "platform/graphics/paint/DisplayItemList.h"
14 #include "platform/graphics/paint/DrawingDisplayItem.h" 14 #include "platform/graphics/paint/DrawingDisplayItem.h"
15 #include <gtest/gtest.h> 15 #include <gtest/gtest.h>
16 16
17 namespace blink { 17 namespace blink {
18 18
19 class LayoutObjectDrawingRecorderTest : public RenderingTest { 19 class LayoutObjectDrawingRecorderTest : public RenderingTest {
20 public: 20 public:
21 LayoutObjectDrawingRecorderTest() : m_layoutView(nullptr) { } 21 LayoutObjectDrawingRecorderTest() : m_layoutView(nullptr) { }
22 22
23 protected: 23 protected:
24 LayoutView& layoutView() { return *m_layoutView; } 24 LayoutView& layoutView() { return *m_layoutView; }
25 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph icsLayerBacking()->displayItemList(); } 25 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph icsLayerBacking()->displayItemList(); }
26 const Vector<OwnPtr<DisplayItem>>& newdisplayItemsBeforeUpdate() { return ro otDisplayItemList().m_newDisplayItems; } 26 const DisplayItems& newDisplayItemsBeforeUpdate() { return rootDisplayItemLi st().m_newDisplayItems; }
27 27
28 private: 28 private:
29 virtual void SetUp() override 29 virtual void SetUp() override
30 { 30 {
31 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true); 31 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true);
32 32
33 RenderingTest::SetUp(); 33 RenderingTest::SetUp();
34 enableCompositing(); 34 enableCompositing();
35 35
36 m_layoutView = document().view()->layoutView(); 36 m_layoutView = document().view()->layoutView();
37 ASSERT_TRUE(m_layoutView); 37 ASSERT_TRUE(m_layoutView);
38 } 38 }
39 39
40 virtual void TearDown() override 40 virtual void TearDown() override
41 { 41 {
42 RuntimeEnabledFeatures::setSlimmingPaintEnabled(false); 42 RuntimeEnabledFeatures::setSlimmingPaintEnabled(false);
43 } 43 }
44 44
45 LayoutView* m_layoutView; 45 LayoutView* m_layoutView;
46 }; 46 };
47 47
48 namespace {
49
48 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const FloatRect& bound) 50 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const FloatRect& bound)
49 { 51 {
50 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d); 52 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d);
51 53
52 // Redundant when there's nothing to draw but we must always do this check. 54 // Redundant when there's nothing to draw but we must always do this check.
53 if (drawingRecorder.canUseCachedDrawing()) 55 if (drawingRecorder.canUseCachedDrawing())
54 return; 56 return;
55 } 57 }
56 58
57 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const FloatRect& bound) 59 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const FloatRect& bound)
58 { 60 {
59 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d); 61 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d);
60 if (drawingRecorder.canUseCachedDrawing()) 62 if (drawingRecorder.canUseCachedDrawing())
61 return; 63 return;
62 IntRect rect(0, 0, 10, 10); 64 IntRect rect(0, 0, 10, 10);
63 context.drawRect(rect); 65 context.drawRect(rect);
64 } 66 }
65 67
68 bool isDrawing(const DisplayItems::ItemHandle& item)
69 {
70 return DisplayItem::isDrawingType(item.type());
71 }
72
73 bool isCached(const DisplayItems::ItemHandle& item)
74 {
75 return DisplayItem::isCachedType(item.type());
76 }
66 77
67 TEST_F(LayoutObjectDrawingRecorderTest, Nothing) 78 TEST_F(LayoutObjectDrawingRecorderTest, Nothing)
68 { 79 {
69 GraphicsContext context(&rootDisplayItemList()); 80 GraphicsContext context(&rootDisplayItemList());
70 FloatRect bound = layoutView().viewRect(); 81 FloatRect bound = layoutView().viewRect();
71 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size()); 82 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size());
72 83
73 drawNothing(context, layoutView(), PaintPhaseForeground, bound); 84 drawNothing(context, layoutView(), PaintPhaseForeground, bound);
74 rootDisplayItemList().commitNewDisplayItems(); 85 rootDisplayItemList().commitNewDisplayItems();
75 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 86 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
76 ASSERT_TRUE(rootDisplayItemList().displayItems()[0]->isDrawing()); 87 const auto& item = rootDisplayItemList().displayItems()[0];
77 EXPECT_FALSE(static_cast<DrawingDisplayItem*>(rootDisplayItemList().displayI tems()[0].get())->picture()); 88 ASSERT_TRUE(isDrawing(item));
89 EXPECT_FALSE(item.picture());
78 } 90 }
79 91
80 TEST_F(LayoutObjectDrawingRecorderTest, Rect) 92 TEST_F(LayoutObjectDrawingRecorderTest, Rect)
81 { 93 {
82 GraphicsContext context(&rootDisplayItemList()); 94 GraphicsContext context(&rootDisplayItemList());
83 FloatRect bound = layoutView().viewRect(); 95 FloatRect bound = layoutView().viewRect();
84 drawRect(context, layoutView(), PaintPhaseForeground, bound); 96 drawRect(context, layoutView(), PaintPhaseForeground, bound);
85 rootDisplayItemList().commitNewDisplayItems(); 97 rootDisplayItemList().commitNewDisplayItems();
86 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 98 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
87 EXPECT_TRUE(rootDisplayItemList().displayItems()[0]->isDrawing()); 99 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
88 } 100 }
89 101
90 TEST_F(LayoutObjectDrawingRecorderTest, Cached) 102 TEST_F(LayoutObjectDrawingRecorderTest, Cached)
91 { 103 {
92 GraphicsContext context(&rootDisplayItemList()); 104 GraphicsContext context(&rootDisplayItemList());
93 FloatRect bound = layoutView().viewRect(); 105 FloatRect bound = layoutView().viewRect();
94 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound); 106 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound);
95 drawRect(context, layoutView(), PaintPhaseForeground, bound); 107 drawRect(context, layoutView(), PaintPhaseForeground, bound);
96 rootDisplayItemList().commitNewDisplayItems(); 108 rootDisplayItemList().commitNewDisplayItems();
97 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size()); 109 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size());
98 EXPECT_TRUE(rootDisplayItemList().displayItems()[0]->isDrawing()); 110 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
99 EXPECT_TRUE(rootDisplayItemList().displayItems()[1]->isDrawing()); 111 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1]));
100 112
101 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound); 113 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound);
102 drawRect(context, layoutView(), PaintPhaseForeground, bound); 114 drawRect(context, layoutView(), PaintPhaseForeground, bound);
103 EXPECT_EQ((size_t)2, newdisplayItemsBeforeUpdate().size()); 115 EXPECT_EQ((size_t)2, newDisplayItemsBeforeUpdate().size());
104 EXPECT_TRUE(newdisplayItemsBeforeUpdate()[0]->isCached()); 116 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[0]));
105 EXPECT_TRUE(newdisplayItemsBeforeUpdate()[1]->isCached()); 117 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[1]));
106 rootDisplayItemList().commitNewDisplayItems(); 118 rootDisplayItemList().commitNewDisplayItems();
107 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size()); 119 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size());
108 EXPECT_TRUE(rootDisplayItemList().displayItems()[0]->isDrawing()); 120 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
109 EXPECT_TRUE(rootDisplayItemList().displayItems()[1]->isDrawing()); 121 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1]));
110 } 122 }
111 123
112 } 124 } // namespace
125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698