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

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

Issue 2259493004: Fix Compositing of Opaque Scrolling Layers and Add Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment. Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/PaintLayerScrollableAreaTest.h" 5 #include "core/paint/PaintLayerScrollableAreaTest.h"
6 6
7 #include "platform/graphics/GraphicsLayer.h"
8
7 namespace blink { 9 namespace blink {
8 10
11 TEST_F(PaintLayerScrollableAreaTest, ShouldPaintBackgroundOntoScrollingContentsL ayer)
12 {
13 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true);
14 setBodyInnerHTML(
15 "<style>.scroller { overflow: scroll; will-change: transform; width: 300 px; height: 300px;} .spacer { height: 1000px; }</style>"
16 "<div id='scroller1' class='scroller' style='background: white local;'>"
17 " <div id='negative-composited-child' style='background-color: red; w idth: 1px; height: 1px; position: absolute; backface-visibility: hidden; z-index : -1'></div>"
18 " <div class='spacer'></div>"
19 "</div>"
20 "<div id='scroller2' class='scroller' style='background: white content-b ox; padding: 10px;'><div class='spacer'></div></div>"
21 "<div id='scroller3' class='scroller' style='background: white local con tent-box; padding: 10px;'><div class='spacer'></div></div>"
22 "<div id='scroller4' class='scroller' style='background: url(data:image/ png;base64,iVBORw0KGgoAAAANSUhEUg), white local;'><div class='spacer'></div></di v>"
23 "<div id='scroller5' class='scroller' style='background: url(data:image/ png;base64,iVBORw0KGgoAAAANSUhEUg) local, white local;'><div class='spacer'></di v></div>"
24 "<div id='scroller6' class='scroller' style='background: url(data:image/ png;base64,iVBORw0KGgoAAAANSUhEUg) local, white padding-box; padding: 10px;'><di v class='spacer'></div></div>"
25 "<div id='scroller7' class='scroller' style='background: url(data:image/ png;base64,iVBORw0KGgoAAAANSUhEUg) local, white content-box; padding: 10px;'><di v class='spacer'></div></div>"
26 );
27
28 // First scroller cannot paint background into scrolling contents layer beca use it has a negative z-index child.
29 EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller1"));
30
31 // Second scroller cannot paint background into scrolling contents layer bec ause it has a content-box clip without local attachment.
32 EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller2"));
33
34 // Third scroller can paint background into scrolling contents layer.
35 EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller3"));
36
37 // Fourth scroller cannot paint background into scrolling contents layer bec ause the background image is not locally attached.
38 EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller4"));
39
40 // Fifth scroller can paint background into scrolling contents layer because both the image and color are locally attached.
41 EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller5"));
42
43 // Sixth scroller can paint background into scrolling contents layer because the image is locally attached and even though
44 // the color is not, it is filled to the padding box so it will be drawn the same as a locally attached background.
45 EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller6"));
46
47 // Seventh scroller cannot paint background into scrolling contents layer be cause the color is filled to the content
48 // box and we have padding so it is not equivalent to a locally attached bac kground.
49 EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller7"));
50 }
51
9 TEST_F(PaintLayerScrollableAreaTest, OpaqueLayersPromoted) 52 TEST_F(PaintLayerScrollableAreaTest, OpaqueLayersPromoted)
10 { 53 {
11 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true); 54 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true);
12 55
13 setBodyInnerHTML( 56 setBodyInnerHTML(
14 "<style>" 57 "<style>"
15 "#scroller { overflow: scroll; height: 300px; width: 300px; background-c olor: rgb(0,128,0); }" 58 "#scroller { overflow: scroll; height: 200px; width: 200px; background: white local content-box; border: 10px solid rgba(0, 255, 0, 0.5); }"
16 "#scrolled { height: 1000px; width: 250px; }" 59 "#scrolled { height: 300px; }"
17 "</style>" 60 "</style>"
18 "<div id=\"scroller\"><div id=\"scrolled\"></div></div>"); 61 "<div id=\"scroller\"><div id=\"scrolled\"></div></div>");
19 document().view()->updateAllLifecyclePhases(); 62 document().view()->updateAllLifecyclePhases();
20 63
21 ASSERT_TRUE(RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled()); 64 EXPECT_TRUE(RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled());
22 Element* scroller = document().getElementById("scroller"); 65 Element* scroller = document().getElementById("scroller");
23 PaintLayer* paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->l ayer(); 66 PaintLayer* paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->l ayer();
24 ASSERT_TRUE(paintLayer); 67 ASSERT_TRUE(paintLayer);
25 ASSERT_TRUE(paintLayer->needsCompositedScrolling()); 68 EXPECT_TRUE(paintLayer->needsCompositedScrolling());
69 EXPECT_TRUE(paintLayer->graphicsLayerBacking());
70 ASSERT_TRUE(paintLayer->graphicsLayerBackingForScrolling());
71 EXPECT_TRUE(paintLayer->graphicsLayerBackingForScrolling()->contentsOpaque() );
26 } 72 }
27 73
28 TEST_F(PaintLayerScrollableAreaTest, TransparentLayersNotPromoted) 74 TEST_F(PaintLayerScrollableAreaTest, TransparentLayersNotPromoted)
29 { 75 {
30 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true); 76 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true);
31 77
32 setBodyInnerHTML( 78 setBodyInnerHTML(
33 "<style>" 79 "<style>"
34 "#scroller { overflow: scroll; height: 300px; width: 300px; background-c olor: rgba(0,128,0,0.5); }" 80 "#scroller { overflow: scroll; height: 200px; width: 200px; background: rgba(0, 255, 0, 0.5) local content-box; border: 10px solid rgba(0, 255, 0, 0.5); }"
35 "#scrolled { height: 1000px; width: 250px; }" 81 "#scrolled { height: 300px; }"
36 "</style>" 82 "</style>"
37 "<div id=\"scroller\"><div id=\"scrolled\"></div></div>"); 83 "<div id=\"scroller\"><div id=\"scrolled\"></div></div>");
38 document().view()->updateAllLifecyclePhases(); 84 document().view()->updateAllLifecyclePhases();
39 85
40 ASSERT_TRUE(RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled()); 86 EXPECT_TRUE(RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled());
41 Element* scroller = document().getElementById("scroller"); 87 Element* scroller = document().getElementById("scroller");
42 PaintLayer* paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->l ayer(); 88 PaintLayer* paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->l ayer();
43 ASSERT_TRUE(paintLayer); 89 ASSERT_TRUE(paintLayer);
44 ASSERT_TRUE(!paintLayer->needsCompositedScrolling()); 90 EXPECT_FALSE(paintLayer->needsCompositedScrolling());
91 EXPECT_FALSE(paintLayer->graphicsLayerBacking());
92 EXPECT_FALSE(paintLayer->graphicsLayerBackingForScrolling());
45 } 93 }
46 94
95 TEST_F(PaintLayerScrollableAreaTest, OpaqueLayersDepromotedOnStyleChange)
96 {
97 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true);
98
99 setBodyInnerHTML(
100 "<style>"
101 "#scroller { overflow: scroll; height: 200px; width: 200px; background: white local content-box; }"
102 "#scrolled { height: 300px; }"
103 "</style>"
104 "<div id=\"scroller\"><div id=\"scrolled\"></div></div>");
105 document().view()->updateAllLifecyclePhases();
106
107 EXPECT_TRUE(RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled());
108 Element* scroller = document().getElementById("scroller");
109 PaintLayer* paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->l ayer();
110 ASSERT_TRUE(paintLayer);
111 EXPECT_TRUE(paintLayer->needsCompositedScrolling());
112
113 // Change the background to transparent
114 scroller->setAttribute(HTMLNames::styleAttr, "background: rgba(255,255,255,0 .5) local content-box;");
115 document().view()->updateAllLifecyclePhases();
116 paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->layer();
117 ASSERT_TRUE(paintLayer);
118 EXPECT_FALSE(paintLayer->needsCompositedScrolling());
119 EXPECT_FALSE(paintLayer->graphicsLayerBacking());
120 EXPECT_FALSE(paintLayer->graphicsLayerBackingForScrolling());
47 } 121 }
122
123 TEST_F(PaintLayerScrollableAreaTest, OpaqueLayersPromotedOnStyleChange)
124 {
125 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true);
126
127 setBodyInnerHTML(
128 "<style>"
129 "#scroller { overflow: scroll; height: 200px; width: 200px; background: rgba(255,255,255,0.5) local content-box; }"
130 "#scrolled { height: 300px; }"
131 "</style>"
132 "<div id=\"scroller\"><div id=\"scrolled\"></div></div>");
133 document().view()->updateAllLifecyclePhases();
134
135 EXPECT_TRUE(RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled());
136 Element* scroller = document().getElementById("scroller");
137 PaintLayer* paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->l ayer();
138 ASSERT_TRUE(paintLayer);
139 EXPECT_FALSE(paintLayer->needsCompositedScrolling());
140
141 // Change the background to transparent
142 scroller->setAttribute(HTMLNames::styleAttr, "background: white local conten t-box;");
143 document().view()->updateAllLifecyclePhases();
144 paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->layer();
145 ASSERT_TRUE(paintLayer);
146 EXPECT_TRUE(paintLayer->needsCompositedScrolling());
147 EXPECT_TRUE(paintLayer->graphicsLayerBacking());
148 ASSERT_TRUE(paintLayer->graphicsLayerBackingForScrolling());
149 EXPECT_TRUE(paintLayer->graphicsLayerBackingForScrolling()->contentsOpaque() );
150 }
151
152
153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698