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

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

Issue 892293002: First version of new merge algorithm (not enabled yet) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove scope-related code (accidentally mixed in this CL) Created 5 years, 10 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/RenderDrawingRecorder.h" 6 #include "core/paint/RenderDrawingRecorder.h"
7 7
8 #include "core/rendering/RenderLayer.h" 8 #include "core/rendering/RenderLayer.h"
9 #include "core/rendering/RenderView.h" 9 #include "core/rendering/RenderView.h"
10 #include "core/rendering/RenderingTestHelper.h" 10 #include "core/rendering/RenderingTestHelper.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 <gtest/gtest.h> 14 #include <gtest/gtest.h>
15 15
16 namespace blink { 16 namespace blink {
17 namespace {
18 17
19 class DrawingRecorderTest : public RenderingTest { 18 class DrawingRecorderTest : public RenderingTest {
20 public: 19 public:
21 DrawingRecorderTest() : m_renderView(nullptr) { } 20 DrawingRecorderTest() : m_renderView(nullptr) { }
22 21
23 protected: 22 protected:
24 RenderView* renderView() { return m_renderView; } 23 RenderView* renderView() { return m_renderView; }
25 DisplayItemList& rootDisplayItemList() { return *renderView()->layer()->grap hicsLayerBacking()->displayItemList(); } 24 DisplayItemList& rootDisplayItemList() { return *renderView()->layer()->grap hicsLayerBacking()->displayItemList(); }
25 const Vector<OwnPtr<DisplayItem>>& newPaintListBeforeUpdate() { return rootD isplayItemList().m_newPaints; }
26 26
27 private: 27 private:
28 virtual void SetUp() override 28 virtual void SetUp() override
29 { 29 {
30 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true); 30 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true);
31 31
32 RenderingTest::SetUp(); 32 RenderingTest::SetUp();
33 enableCompositing(); 33 enableCompositing();
34 34
35 m_renderView = document().view()->renderView(); 35 m_renderView = document().view()->renderView();
36 ASSERT_TRUE(m_renderView); 36 ASSERT_TRUE(m_renderView);
37 } 37 }
38 38
39 virtual void TearDown() override
40 {
41 RuntimeEnabledFeatures::setSlimmingPaintEnabled(false);
42 RuntimeEnabledFeatures::setSlimmingPaintDisplayItemCacheEnabled(false);
43 }
44
39 RenderView* m_renderView; 45 RenderView* m_renderView;
40 }; 46 };
41 47
42 void drawNothing(GraphicsContext* context, RenderView* renderer, PaintPhase phas e, const FloatRect& bound) 48 void drawNothing(GraphicsContext* context, RenderView* renderer, PaintPhase phas e, const FloatRect& bound)
43 { 49 {
44 RenderDrawingRecorder drawingRecorder(context, *renderer, phase, bound); 50 RenderDrawingRecorder drawingRecorder(context, *renderer, phase, bound);
45 } 51 }
46 52
47 void drawRect(GraphicsContext* context, RenderView* renderer, PaintPhase phase, const FloatRect& bound) 53 void drawRect(GraphicsContext* context, RenderView* renderer, PaintPhase phase, const FloatRect& bound)
48 { 54 {
49 RenderDrawingRecorder drawingRecorder(context, *renderer, phase, bound); 55 RenderDrawingRecorder drawingRecorder(context, *renderer, phase, bound);
50 if (drawingRecorder.canUseCachedDrawing()) 56 if (drawingRecorder.canUseCachedDrawing())
51 return; 57 return;
52 IntRect rect(0, 0, 10, 10); 58 IntRect rect(0, 0, 10, 10);
53 context->drawRect(rect); 59 context->drawRect(rect);
54 } 60 }
55 61
56 62
57 TEST_F(DrawingRecorderTest, DrawingRecorderTest_Nothing) 63 TEST_F(DrawingRecorderTest, Nothing)
58 { 64 {
59 GraphicsContext context(nullptr, &rootDisplayItemList()); 65 GraphicsContext context(nullptr, &rootDisplayItemList());
60 FloatRect bound = renderView()->viewRect(); 66 FloatRect bound = renderView()->viewRect();
61 EXPECT_EQ((size_t)0, rootDisplayItemList().paintList().size()); 67 EXPECT_EQ((size_t)0, rootDisplayItemList().paintList().size());
62 68
63 drawNothing(&context, renderView(), PaintPhaseForeground, bound); 69 drawNothing(&context, renderView(), PaintPhaseForeground, bound);
64 rootDisplayItemList().endNewPaints(); 70 rootDisplayItemList().endNewPaints();
65 EXPECT_EQ((size_t)1, rootDisplayItemList().paintList().size()); 71 EXPECT_EQ((size_t)0, rootDisplayItemList().paintList().size());
66 } 72 }
67 73
68 TEST_F(DrawingRecorderTest, DrawingRecorderTest_Rect) 74 TEST_F(DrawingRecorderTest, Rect)
69 { 75 {
70 GraphicsContext context(nullptr, &rootDisplayItemList()); 76 GraphicsContext context(nullptr, &rootDisplayItemList());
71 FloatRect bound = renderView()->viewRect(); 77 FloatRect bound = renderView()->viewRect();
72 drawRect(&context, renderView(), PaintPhaseForeground, bound); 78 drawRect(&context, renderView(), PaintPhaseForeground, bound);
73 rootDisplayItemList().endNewPaints(); 79 rootDisplayItemList().endNewPaints();
74 EXPECT_EQ((size_t)1, rootDisplayItemList().paintList().size()); 80 EXPECT_EQ((size_t)1, rootDisplayItemList().paintList().size());
75 EXPECT_TRUE(rootDisplayItemList().paintList()[0]->isDrawing()); 81 EXPECT_TRUE(rootDisplayItemList().paintList()[0]->isDrawing());
76 } 82 }
77 83
78 TEST_F(DrawingRecorderTest, DrawingRecorderTest_Cached) 84 TEST_F(DrawingRecorderTest, Cached)
79 { 85 {
86 RuntimeEnabledFeatures::setSlimmingPaintDisplayItemCacheEnabled(true);
87
80 GraphicsContext context(nullptr, &rootDisplayItemList()); 88 GraphicsContext context(nullptr, &rootDisplayItemList());
81 FloatRect bound = renderView()->viewRect(); 89 FloatRect bound = renderView()->viewRect();
82 drawNothing(&context, renderView(), PaintPhaseBlockBackground, bound); 90 drawNothing(&context, renderView(), PaintPhaseBlockBackground, bound);
83 drawRect(&context, renderView(), PaintPhaseForeground, bound); 91 drawRect(&context, renderView(), PaintPhaseForeground, bound);
84 rootDisplayItemList().endNewPaints(); 92 rootDisplayItemList().endNewPaints();
85 EXPECT_EQ((size_t)2, rootDisplayItemList().paintList().size()); 93 EXPECT_EQ((size_t)1, rootDisplayItemList().paintList().size());
86 EXPECT_TRUE(rootDisplayItemList().paintList()[1]->isDrawing()); 94 EXPECT_TRUE(rootDisplayItemList().paintList()[0]->isDrawing());
87 95
88 drawNothing(&context, renderView(), PaintPhaseBlockBackground, bound); 96 drawNothing(&context, renderView(), PaintPhaseBlockBackground, bound);
89 drawRect(&context, renderView(), PaintPhaseForeground, bound); 97 drawRect(&context, renderView(), PaintPhaseForeground, bound);
98 EXPECT_EQ((size_t)2, newPaintListBeforeUpdate().size());
99 EXPECT_TRUE(newPaintListBeforeUpdate()[0]->isCached());
100 EXPECT_TRUE(newPaintListBeforeUpdate()[1]->isCached());
90 rootDisplayItemList().endNewPaints(); 101 rootDisplayItemList().endNewPaints();
91 EXPECT_EQ((size_t)2, rootDisplayItemList().paintList().size()); 102 EXPECT_EQ((size_t)1, rootDisplayItemList().paintList().size());
92 EXPECT_TRUE(rootDisplayItemList().paintList()[1]->isDrawing()); 103 EXPECT_TRUE(rootDisplayItemList().paintList()[0]->isDrawing());
93 } 104 }
94 105
95 } 106 }
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698