| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 } else { | 1040 } else { |
| 1041 ASSERT_TRUE(scroll_layer); | 1041 ASSERT_TRUE(scroll_layer); |
| 1042 web_scroll_layer = scroll_layer->PlatformLayer(); | 1042 web_scroll_layer = scroll_layer->PlatformLayer(); |
| 1043 ASSERT_TRUE(web_scroll_layer->Scrollable()); | 1043 ASSERT_TRUE(web_scroll_layer->Scrollable()); |
| 1044 ASSERT_FALSE( | 1044 ASSERT_FALSE( |
| 1045 web_scroll_layer->MainThreadScrollingReasons() & | 1045 web_scroll_layer->MainThreadScrollingReasons() & |
| 1046 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); | 1046 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
| 1047 } | 1047 } |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 class NonCompositedMainThreadScrollingReasonTest | 1050 class StyleRelatedMainThreadScrollingReasonTest |
| 1051 : public ScrollingCoordinatorTest { | 1051 : public ScrollingCoordinatorTest { |
| 1052 static const uint32_t kLCDTextRelatedReasons = | 1052 static const uint32_t kLCDTextRelatedReasons = |
| 1053 MainThreadScrollingReason::kHasOpacityAndLCDText | | 1053 MainThreadScrollingReason::kHasOpacityAndLCDText | |
| 1054 MainThreadScrollingReason::kHasTransformAndLCDText | | 1054 MainThreadScrollingReason::kHasTransformAndLCDText | |
| 1055 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText; | 1055 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText; |
| 1056 | 1056 |
| 1057 protected: | 1057 protected: |
| 1058 NonCompositedMainThreadScrollingReasonTest() { | 1058 StyleRelatedMainThreadScrollingReasonTest() { |
| 1059 RegisterMockedHttpURLLoad("two_scrollable_area.html"); | 1059 RegisterMockedHttpURLLoad("two_scrollable_area.html"); |
| 1060 NavigateTo(base_url_ + "two_scrollable_area.html"); | 1060 NavigateTo(base_url_ + "two_scrollable_area.html"); |
| 1061 } | 1061 } |
| 1062 void TestNonCompositedReasons(const std::string& target, | 1062 void TestStyle(const std::string& target, const uint32_t reason) { |
| 1063 const uint32_t reason) { | |
| 1064 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( | 1063 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( |
| 1065 false); | 1064 false); |
| 1066 Document* document = GetFrame()->GetDocument(); | 1065 Document* document = GetFrame()->GetDocument(); |
| 1067 Element* container = document->GetElementById("scroller1"); | 1066 Element* container = document->GetElementById("scroller1"); |
| 1068 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); | 1067 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); |
| 1068 container = document->GetElementById("scroller2"); |
| 1069 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); |
| 1069 ForceFullCompositingUpdate(); | 1070 ForceFullCompositingUpdate(); |
| 1070 | 1071 |
| 1071 PaintLayerScrollableArea* scrollable_area = | |
| 1072 ToLayoutBoxModelObject(container->GetLayoutObject()) | |
| 1073 ->GetScrollableArea(); | |
| 1074 ASSERT_TRUE(scrollable_area); | |
| 1075 EXPECT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | |
| 1076 reason); | |
| 1077 | |
| 1078 Element* container2 = document->GetElementById("scroller2"); | |
| 1079 PaintLayerScrollableArea* scrollable_area2 = | |
| 1080 ToLayoutBoxModelObject(container2->GetLayoutObject()) | |
| 1081 ->GetScrollableArea(); | |
| 1082 ASSERT_TRUE(scrollable_area2); | |
| 1083 // Different scrollable area should remain unaffected. | |
| 1084 EXPECT_FALSE( | |
| 1085 scrollable_area2->GetNonCompositedMainThreadScrollingReasons() & | |
| 1086 reason); | |
| 1087 | |
| 1088 FrameView* frame_view = GetFrame()->View(); | 1072 FrameView* frame_view = GetFrame()->View(); |
| 1089 ASSERT_TRUE(frame_view); | 1073 ASSERT_TRUE(frame_view); |
| 1090 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); | 1074 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1091 | 1075 |
| 1092 // Remove attribute from the scroller 1 would lead to scroll on impl. | 1076 // Remove the target attribute from one of the scrollers. |
| 1077 // Still need to scroll on main thread. |
| 1078 container = document->GetElementById("scroller1"); |
| 1079 DCHECK(container); |
| 1080 |
| 1093 container->removeAttribute("class"); | 1081 container->removeAttribute("class"); |
| 1094 ForceFullCompositingUpdate(); | 1082 ForceFullCompositingUpdate(); |
| 1095 | 1083 |
| 1096 EXPECT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | 1084 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1097 reason); | 1085 |
| 1098 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); | 1086 // Remove attribute from the other scroller would lead to |
| 1087 // scroll on impl. |
| 1088 container = document->GetElementById("scroller2"); |
| 1089 DCHECK(container); |
| 1090 |
| 1091 container->removeAttribute("class"); |
| 1092 ForceFullCompositingUpdate(); |
| 1093 |
| 1094 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1099 | 1095 |
| 1100 // Add target attribute would again lead to scroll on main thread | 1096 // Add target attribute would again lead to scroll on main thread |
| 1101 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); | 1097 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); |
| 1102 ForceFullCompositingUpdate(); | 1098 ForceFullCompositingUpdate(); |
| 1103 | 1099 |
| 1104 EXPECT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | 1100 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1105 reason); | |
| 1106 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); | |
| 1107 | 1101 |
| 1108 if ((reason & kLCDTextRelatedReasons) && | 1102 if ((reason & kLCDTextRelatedReasons) && |
| 1109 !(reason & ~kLCDTextRelatedReasons)) { | 1103 !(reason & ~kLCDTextRelatedReasons)) { |
| 1110 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( | 1104 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( |
| 1111 true); | 1105 true); |
| 1112 ForceFullCompositingUpdate(); | 1106 ForceFullCompositingUpdate(); |
| 1113 EXPECT_FALSE( | 1107 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons()); |
| 1114 scrollable_area->GetNonCompositedMainThreadScrollingReasons()); | |
| 1115 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons()); | |
| 1116 } | 1108 } |
| 1117 } | 1109 } |
| 1118 }; | 1110 }; |
| 1119 | 1111 |
| 1120 INSTANTIATE_TEST_CASE_P(All, | 1112 INSTANTIATE_TEST_CASE_P(All, |
| 1121 NonCompositedMainThreadScrollingReasonTest, | 1113 StyleRelatedMainThreadScrollingReasonTest, |
| 1122 ::testing::Bool()); | 1114 ::testing::Bool()); |
| 1123 | 1115 |
| 1124 TEST_P(NonCompositedMainThreadScrollingReasonTest, TransparentTest) { | 1116 // TODO(yigu): This test and all other style realted main thread scrolling |
| 1125 TestNonCompositedReasons("transparent", | 1117 // reason tests below have been disabled due to https://crbug.com/701355. |
| 1126 MainThreadScrollingReason::kHasOpacityAndLCDText); | 1118 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_TransparentTest) { |
| 1119 TestStyle("transparent", MainThreadScrollingReason::kHasOpacityAndLCDText); |
| 1127 } | 1120 } |
| 1128 | 1121 |
| 1129 TEST_P(NonCompositedMainThreadScrollingReasonTest, TransformTest) { | 1122 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_TransformTest) { |
| 1130 TestNonCompositedReasons("transform", | 1123 TestStyle("transform", MainThreadScrollingReason::kHasTransformAndLCDText); |
| 1131 MainThreadScrollingReason::kHasTransformAndLCDText); | |
| 1132 } | 1124 } |
| 1133 | 1125 |
| 1134 TEST_P(NonCompositedMainThreadScrollingReasonTest, BackgroundNotOpaqueTest) { | 1126 TEST_P(StyleRelatedMainThreadScrollingReasonTest, |
| 1135 TestNonCompositedReasons( | 1127 DISABLED_BackgroundNotOpaqueTest) { |
| 1136 "background-not-opaque", | 1128 TestStyle("background-not-opaque", |
| 1137 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText); | 1129 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText); |
| 1138 } | 1130 } |
| 1139 | 1131 |
| 1140 TEST_P(NonCompositedMainThreadScrollingReasonTest, BorderRadiusTest) { | 1132 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_BorderRadiusTest) { |
| 1141 TestNonCompositedReasons("border-radius", | 1133 TestStyle("border-radius", MainThreadScrollingReason::kHasBorderRadius); |
| 1142 MainThreadScrollingReason::kHasBorderRadius); | |
| 1143 } | 1134 } |
| 1144 | 1135 |
| 1145 TEST_P(NonCompositedMainThreadScrollingReasonTest, ClipTest) { | 1136 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_ClipTest) { |
| 1146 TestNonCompositedReasons("clip", | 1137 TestStyle("clip", MainThreadScrollingReason::kHasClipRelatedProperty); |
| 1147 MainThreadScrollingReason::kHasClipRelatedProperty); | |
| 1148 } | 1138 } |
| 1149 | 1139 |
| 1150 TEST_P(NonCompositedMainThreadScrollingReasonTest, ClipPathTest) { | 1140 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_ClipPathTest) { |
| 1151 uint32_t clip_reason = MainThreadScrollingReason::kHasClipRelatedProperty; | 1141 uint32_t reason = MainThreadScrollingReason::kHasClipRelatedProperty; |
| 1152 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled(false); | 1142 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled(false); |
| 1153 Document* document = GetFrame()->GetDocument(); | 1143 Document* document = GetFrame()->GetDocument(); |
| 1154 // Test ancestor with ClipPath | 1144 // Test ancestor with ClipPath |
| 1155 Element* element = document->body(); | 1145 Element* element = document->body(); |
| 1156 ASSERT_TRUE(element); | 1146 DCHECK(element); |
| 1157 element->setAttribute(HTMLNames::styleAttr, | 1147 element->setAttribute(HTMLNames::styleAttr, |
| 1158 "clip-path:circle(115px at 20px 20px);"); | 1148 "clip-path:circle(115px at 20px 20px);"); |
| 1159 Element* container = document->getElementById("scroller1"); | |
| 1160 ASSERT_TRUE(container); | |
| 1161 ForceFullCompositingUpdate(); | 1149 ForceFullCompositingUpdate(); |
| 1162 | 1150 |
| 1163 PaintLayerScrollableArea* scrollable_area = | |
| 1164 ToLayoutBoxModelObject(container->GetLayoutObject())->GetScrollableArea(); | |
| 1165 ASSERT_TRUE(scrollable_area); | |
| 1166 EXPECT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | |
| 1167 clip_reason); | |
| 1168 | |
| 1169 FrameView* frame_view = GetFrame()->View(); | 1151 FrameView* frame_view = GetFrame()->View(); |
| 1170 ASSERT_TRUE(frame_view); | 1152 ASSERT_TRUE(frame_view); |
| 1171 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); | 1153 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1172 | 1154 |
| 1173 // Remove clip path from ancestor. | 1155 // Remove clip path from ancestor. |
| 1174 element->removeAttribute(HTMLNames::styleAttr); | 1156 element->removeAttribute(HTMLNames::styleAttr); |
| 1175 ForceFullCompositingUpdate(); | 1157 ForceFullCompositingUpdate(); |
| 1176 | 1158 |
| 1177 EXPECT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | 1159 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1178 clip_reason); | |
| 1179 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); | |
| 1180 | 1160 |
| 1181 // Test descendant with ClipPath | 1161 // Test descendant with ClipPath |
| 1182 element = document->GetElementById("content1"); | 1162 element = document->GetElementById("content1"); |
| 1183 ASSERT_TRUE(element); | 1163 DCHECK(element); |
| 1184 element->setAttribute(HTMLNames::styleAttr, | 1164 element->setAttribute(HTMLNames::styleAttr, |
| 1185 "clip-path:circle(115px at 20px 20px);"); | 1165 "clip-path:circle(115px at 20px 20px);"); |
| 1186 ForceFullCompositingUpdate(); | 1166 ForceFullCompositingUpdate(); |
| 1187 EXPECT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | 1167 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1188 clip_reason); | |
| 1189 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); | |
| 1190 | 1168 |
| 1191 // Remove clip path from descendant. | 1169 // Remove clip path from descendant. |
| 1192 element->removeAttribute(HTMLNames::styleAttr); | 1170 element->removeAttribute(HTMLNames::styleAttr); |
| 1193 ForceFullCompositingUpdate(); | 1171 ForceFullCompositingUpdate(); |
| 1194 EXPECT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | 1172 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); |
| 1195 clip_reason); | |
| 1196 EXPECT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); | |
| 1197 } | 1173 } |
| 1198 | 1174 |
| 1199 TEST_P(NonCompositedMainThreadScrollingReasonTest, LCDTextEnabledTest) { | 1175 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_LCDTextEnabledTest) { |
| 1200 TestNonCompositedReasons("transparent border-radius", | 1176 TestStyle("transparent border-radius", |
| 1201 MainThreadScrollingReason::kHasOpacityAndLCDText | | 1177 MainThreadScrollingReason::kHasOpacityAndLCDText | |
| 1202 MainThreadScrollingReason::kHasBorderRadius); | 1178 MainThreadScrollingReason::kHasBorderRadius); |
| 1203 } | 1179 } |
| 1204 | 1180 |
| 1205 TEST_P(NonCompositedMainThreadScrollingReasonTest, BoxShadowTest) { | 1181 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_BoxShadowTest) { |
| 1206 TestNonCompositedReasons( | 1182 TestStyle("box-shadow", |
| 1207 "box-shadow", MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer); | 1183 MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer); |
| 1208 } | |
| 1209 | |
| 1210 TEST_P(NonCompositedMainThreadScrollingReasonTest, | |
| 1211 CompositedWithLCDTextRelatedReasonsTest) { | |
| 1212 // With "will-change:transform" we composite elements with | |
| 1213 // LCDTextRelatedReasons only. For elements with other | |
| 1214 // NonCompositedReasons, we don't create scrollingLayer for their | |
| 1215 // CompositedLayerMapping therefore they don't get composited. | |
| 1216 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled(false); | |
| 1217 Document* document = GetFrame()->GetDocument(); | |
| 1218 Element* container = document->getElementById("scroller1"); | |
| 1219 ASSERT_TRUE(container); | |
| 1220 container->setAttribute("class", "composited transparent", | |
| 1221 ASSERT_NO_EXCEPTION); | |
| 1222 ForceFullCompositingUpdate(); | |
| 1223 | |
| 1224 PaintLayerScrollableArea* scrollable_area = | |
| 1225 ToLayoutBoxModelObject(container->GetLayoutObject())->GetScrollableArea(); | |
| 1226 ASSERT_TRUE(scrollable_area); | |
| 1227 EXPECT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons()); | |
| 1228 | |
| 1229 Element* container2 = document->getElementById("scroller2"); | |
| 1230 ASSERT_TRUE(container2); | |
| 1231 container2->setAttribute("class", "composited border-radius", | |
| 1232 ASSERT_NO_EXCEPTION); | |
| 1233 ForceFullCompositingUpdate(); | |
| 1234 PaintLayerScrollableArea* scrollable_area2 = | |
| 1235 ToLayoutBoxModelObject(container2->GetLayoutObject()) | |
| 1236 ->GetScrollableArea(); | |
| 1237 ASSERT_TRUE(scrollable_area2); | |
| 1238 EXPECT_TRUE(scrollable_area2->GetNonCompositedMainThreadScrollingReasons() & | |
| 1239 MainThreadScrollingReason::kHasBorderRadius); | |
| 1240 } | 1184 } |
| 1241 | 1185 |
| 1242 } // namespace blink | 1186 } // namespace blink |
| OLD | NEW |