Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010, 2011 Apple 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 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2192 // Regardless, mark the graphics layer, scrolling layer and scrolling block | 2192 // Regardless, mark the graphics layer, scrolling layer and scrolling block |
| 2193 // selection layer (if they exist) as not flattening. Having them flatten | 2193 // selection layer (if they exist) as not flattening. Having them flatten |
| 2194 // causes unclipped render surfaces which cause bugs. | 2194 // causes unclipped render surfaces which cause bugs. |
| 2195 // http://crbug.com/521768 | 2195 // http://crbug.com/521768 |
| 2196 if (HasScrollingLayer()) { | 2196 if (HasScrollingLayer()) { |
| 2197 graphics_layer_->SetShouldFlattenTransform(false); | 2197 graphics_layer_->SetShouldFlattenTransform(false); |
| 2198 scrolling_layer_->SetShouldFlattenTransform(false); | 2198 scrolling_layer_->SetShouldFlattenTransform(false); |
| 2199 } | 2199 } |
| 2200 } | 2200 } |
| 2201 | 2201 |
| 2202 struct AnimatingData { | |
| 2203 Persistent<Node> owning_node = nullptr; | |
|
wkorman
2017/05/18 21:31:57
add STACK_ALLOCATED()? seems to be MO.
chrishtr
2017/05/18 22:15:31
Done.
| |
| 2204 Persistent<Element> animating_element = nullptr; | |
| 2205 const ComputedStyle* animating_style = nullptr; | |
| 2206 }; | |
| 2207 | |
| 2208 void GetAnimatingData(PaintLayer& paint_layer, AnimatingData& data) { | |
| 2209 if (!RuntimeEnabledFeatures::compositorWorkerEnabled()) | |
| 2210 return; | |
| 2211 | |
| 2212 data.owning_node = paint_layer.GetLayoutObject().GetNode(); | |
| 2213 | |
| 2214 if (!data.owning_node) | |
| 2215 return; | |
| 2216 | |
| 2217 Document& document = data.owning_node->GetDocument(); | |
| 2218 Element* scrolling_element = document.ScrollingElementNoLayout(); | |
| 2219 if (data.owning_node->IsElementNode() && | |
| 2220 (!RuntimeEnabledFeatures::rootLayerScrollingEnabled() || | |
| 2221 data.owning_node != scrolling_element)) { | |
| 2222 data.animating_element = ToElement(data.owning_node); | |
| 2223 data.animating_style = paint_layer.GetLayoutObject().Style(); | |
| 2224 } else if (data.owning_node->IsDocumentNode() && | |
| 2225 RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | |
| 2226 data.owning_node = data.animating_element = scrolling_element; | |
| 2227 if (scrolling_element && scrolling_element->GetLayoutObject()) | |
| 2228 data.animating_style = scrolling_element->GetLayoutObject()->Style(); | |
| 2229 } | |
| 2230 } | |
| 2231 | |
| 2202 // Some background on when you receive an element id or mutable properties. | 2232 // Some background on when you receive an element id or mutable properties. |
| 2203 // | 2233 // |
| 2204 // element id: | 2234 // element id: |
| 2205 // If you have a compositor proxy, an animation, or you're a scroller (and | 2235 // If you have a compositor proxy, an animation, or you're a scroller (and |
| 2206 // might impl animate). | 2236 // might impl animate). |
| 2207 // | 2237 // |
| 2208 // mutable properties: | 2238 // mutable properties: |
| 2209 // Only if you have a compositor proxy. | 2239 // Only if you have a compositor proxy. |
| 2210 // | 2240 // |
| 2211 // The element id for the scroll layers is assigned when they're constructed, | 2241 // The element id for the scroll layers is assigned when they're constructed, |
| 2212 // since this is unconditional. However, the element id for the primary layer as | 2242 // since this is unconditional. However, the element id for the primary layer as |
| 2213 // well as the mutable properties for all layers may change according to the | 2243 // well as the mutable properties for all layers may change according to the |
| 2214 // rules above so we update those values here. | 2244 // rules above so we update those values here. |
| 2215 void CompositedLayerMapping::UpdateElementIdAndCompositorMutableProperties() { | 2245 void CompositedLayerMapping::UpdateElementIdAndCompositorMutableProperties() { |
| 2216 int element_id = 0; | |
| 2217 uint32_t primary_mutable_properties = CompositorMutableProperty::kNone; | 2246 uint32_t primary_mutable_properties = CompositorMutableProperty::kNone; |
| 2218 uint32_t scroll_mutable_properties = CompositorMutableProperty::kNone; | 2247 uint32_t scroll_mutable_properties = CompositorMutableProperty::kNone; |
| 2219 | 2248 |
| 2220 Node* owning_node = owning_layer_.GetLayoutObject().GetNode(); | 2249 AnimatingData data; |
| 2221 Element* animating_element = nullptr; | 2250 GetAnimatingData(owning_layer_, data); |
| 2222 const ComputedStyle* animating_style = nullptr; | |
| 2223 if (owning_node) { | |
| 2224 Document& document = owning_node->GetDocument(); | |
| 2225 Element* scrolling_element = document.ScrollingElementNoLayout(); | |
| 2226 if (owning_node->IsElementNode() && | |
| 2227 (!RuntimeEnabledFeatures::rootLayerScrollingEnabled() || | |
| 2228 owning_node != scrolling_element)) { | |
| 2229 animating_element = ToElement(owning_node); | |
| 2230 animating_style = owning_layer_.GetLayoutObject().Style(); | |
| 2231 } else if (owning_node->IsDocumentNode() && | |
| 2232 RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | |
| 2233 owning_node = animating_element = scrolling_element; | |
| 2234 if (scrolling_element && scrolling_element->GetLayoutObject()) | |
| 2235 animating_style = scrolling_element->GetLayoutObject()->Style(); | |
| 2236 } | |
| 2237 } | |
| 2238 | 2251 |
| 2239 if (RuntimeEnabledFeatures::compositorWorkerEnabled() && animating_style && | 2252 CompositorElementId element_id; |
| 2240 animating_style->HasCompositorProxy()) { | 2253 if (data.animating_style && data.animating_style->HasCompositorProxy()) { |
| 2254 // Compositor proxy element ids cannot be based on PaintLayers, since | |
| 2255 // those are not kept alive by script across frames. | |
| 2256 element_id = CompositorElementIdFromDOMNodeId( | |
| 2257 DOMNodeIds::IdForNode(data.owning_node), | |
| 2258 CompositorElementIdNamespace::kPrimaryCompositorProxy); | |
| 2259 | |
| 2241 uint32_t compositor_mutable_properties = | 2260 uint32_t compositor_mutable_properties = |
| 2242 animating_element->CompositorMutableProperties(); | 2261 data.animating_element->CompositorMutableProperties(); |
| 2243 element_id = DOMNodeIds::IdForNode(owning_node); | |
| 2244 primary_mutable_properties = (CompositorMutableProperty::kOpacity | | 2262 primary_mutable_properties = (CompositorMutableProperty::kOpacity | |
| 2245 CompositorMutableProperty::kTransform) & | 2263 CompositorMutableProperty::kTransform) & |
| 2246 compositor_mutable_properties; | 2264 compositor_mutable_properties; |
| 2247 scroll_mutable_properties = (CompositorMutableProperty::kScrollLeft | | 2265 scroll_mutable_properties = (CompositorMutableProperty::kScrollLeft | |
| 2248 CompositorMutableProperty::kScrollTop) & | 2266 CompositorMutableProperty::kScrollTop) & |
| 2249 compositor_mutable_properties; | 2267 compositor_mutable_properties; |
| 2268 } else { | |
| 2269 element_id = CompositorElementIdFromPaintLayerId( | |
|
wkorman
2017/05/18 21:31:57
Perhaps worth adding a comment here re: why we pre
chrishtr
2017/05/18 22:15:31
Done.
| |
| 2270 owning_layer_.UniqueId(), CompositorElementIdNamespace::kPrimary); | |
| 2250 } | 2271 } |
| 2251 | 2272 |
| 2252 if (animating_style && animating_style->ShouldCompositeForCurrentAnimations()) | 2273 graphics_layer_->SetElementId(element_id); |
| 2253 element_id = DOMNodeIds::IdForNode(owning_node); | |
| 2254 | |
| 2255 CompositorElementId compositor_element_id; | |
| 2256 if (element_id) { | |
| 2257 compositor_element_id = CompositorElementIdFromDOMNodeId( | |
| 2258 element_id, CompositorElementIdNamespace::kPrimary); | |
| 2259 } | |
| 2260 | |
| 2261 graphics_layer_->SetElementId(compositor_element_id); | |
| 2262 graphics_layer_->SetCompositorMutableProperties(primary_mutable_properties); | 2274 graphics_layer_->SetCompositorMutableProperties(primary_mutable_properties); |
| 2263 | 2275 |
| 2264 // We always set the elementId for m_scrollingContentsLayer since it can be | 2276 // We always set the elementId for m_scrollingContentsLayer since it can be |
| 2265 // animated for smooth scrolling, so we don't need to set it conditionally | 2277 // animated for smooth scrolling, so we don't need to set it conditionally |
| 2266 // here. | 2278 // here. |
| 2267 if (scrolling_contents_layer_.get()) | 2279 if (scrolling_contents_layer_.get()) |
| 2268 scrolling_contents_layer_->SetCompositorMutableProperties( | 2280 scrolling_contents_layer_->SetCompositorMutableProperties( |
| 2269 scroll_mutable_properties); | 2281 scroll_mutable_properties); |
| 2270 } | 2282 } |
| 2271 | 2283 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2373 // Outer layer which corresponds with the scroll view. | 2385 // Outer layer which corresponds with the scroll view. |
| 2374 scrolling_layer_ = | 2386 scrolling_layer_ = |
| 2375 CreateGraphicsLayer(kCompositingReasonLayerForScrollingContainer); | 2387 CreateGraphicsLayer(kCompositingReasonLayerForScrollingContainer); |
| 2376 scrolling_layer_->SetDrawsContent(false); | 2388 scrolling_layer_->SetDrawsContent(false); |
| 2377 scrolling_layer_->SetMasksToBounds(true); | 2389 scrolling_layer_->SetMasksToBounds(true); |
| 2378 | 2390 |
| 2379 // Inner layer which renders the content that scrolls. | 2391 // Inner layer which renders the content that scrolls. |
| 2380 scrolling_contents_layer_ = | 2392 scrolling_contents_layer_ = |
| 2381 CreateGraphicsLayer(kCompositingReasonLayerForScrollingContents); | 2393 CreateGraphicsLayer(kCompositingReasonLayerForScrollingContents); |
| 2382 | 2394 |
| 2383 if (Node* owning_node = owning_layer_.GetLayoutObject().GetNode()) { | 2395 AnimatingData data; |
| 2384 scrolling_contents_layer_->SetElementId( | 2396 GetAnimatingData(owning_layer_, data); |
| 2385 CompositorElementIdFromDOMNodeId( | 2397 |
| 2386 DOMNodeIds::IdForNode(owning_node), | 2398 CompositorElementId element_id; |
| 2387 CompositorElementIdNamespace::kScroll)); | 2399 if (data.animating_style && data.animating_style->HasCompositorProxy()) { |
| 2400 element_id = CompositorElementIdFromDOMNodeId( | |
| 2401 DOMNodeIds::IdForNode(data.owning_node), | |
| 2402 CompositorElementIdNamespace::kScrollCompositorProxy); | |
| 2403 } else { | |
| 2404 element_id = CompositorElementIdFromPaintLayerId( | |
| 2405 owning_layer_.UniqueId(), CompositorElementIdNamespace::kScroll); | |
| 2388 } | 2406 } |
| 2389 | 2407 |
| 2408 scrolling_contents_layer_->SetElementId(element_id); | |
| 2409 | |
| 2390 scrolling_layer_->AddChild(scrolling_contents_layer_.get()); | 2410 scrolling_layer_->AddChild(scrolling_contents_layer_.get()); |
| 2391 | 2411 |
| 2392 layer_changed = true; | 2412 layer_changed = true; |
| 2393 if (scrolling_coordinator) { | 2413 if (scrolling_coordinator) { |
| 2394 scrolling_coordinator->ScrollableAreaScrollLayerDidChange( | 2414 scrolling_coordinator->ScrollableAreaScrollLayerDidChange( |
| 2395 owning_layer_.GetScrollableArea()); | 2415 owning_layer_.GetScrollableArea()); |
| 2396 scrolling_coordinator->ScrollableAreasDidChange(); | 2416 scrolling_coordinator->ScrollableAreasDidChange(); |
| 2397 } | 2417 } |
| 2398 } | 2418 } |
| 2399 } else if (scrolling_layer_) { | 2419 } else if (scrolling_layer_) { |
| (...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3634 } else if (graphics_layer == decoration_outline_layer_.get()) { | 3654 } else if (graphics_layer == decoration_outline_layer_.get()) { |
| 3635 name = "Decoration Layer"; | 3655 name = "Decoration Layer"; |
| 3636 } else { | 3656 } else { |
| 3637 NOTREACHED(); | 3657 NOTREACHED(); |
| 3638 } | 3658 } |
| 3639 | 3659 |
| 3640 return name; | 3660 return name; |
| 3641 } | 3661 } |
| 3642 | 3662 |
| 3643 } // namespace blink | 3663 } // namespace blink |
| OLD | NEW |