OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 | 6 |
7 #include "cc/layer_tree_host_impl.h" | 7 #include "cc/layer_tree_host_impl.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "cc/page_scale_animation.h" | 24 #include "cc/page_scale_animation.h" |
25 #include "cc/prioritized_texture_manager.h" | 25 #include "cc/prioritized_texture_manager.h" |
26 #include "cc/render_pass_draw_quad.h" | 26 #include "cc/render_pass_draw_quad.h" |
27 #include "cc/rendering_stats.h" | 27 #include "cc/rendering_stats.h" |
28 #include "cc/scrollbar_animation_controller.h" | 28 #include "cc/scrollbar_animation_controller.h" |
29 #include "cc/scrollbar_layer_impl.h" | 29 #include "cc/scrollbar_layer_impl.h" |
30 #include "cc/settings.h" | 30 #include "cc/settings.h" |
31 #include "cc/single_thread_proxy.h" | 31 #include "cc/single_thread_proxy.h" |
32 #include "cc/software_renderer.h" | 32 #include "cc/software_renderer.h" |
33 #include "cc/texture_uploader.h" | 33 #include "cc/texture_uploader.h" |
| 34 #include "ui/gfx/size_conversions.h" |
34 #include <algorithm> | 35 #include <algorithm> |
35 | 36 |
36 using WebKit::WebTransformationMatrix; | 37 using WebKit::WebTransformationMatrix; |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) | 41 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) |
41 { | 42 { |
42 if (visible) { | 43 if (visible) { |
43 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); | 44 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 291 } |
291 | 292 |
292 void LayerTreeHostImpl::startPageScaleAnimation(const IntSize& targetPosition, b
ool anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta dur
ation) | 293 void LayerTreeHostImpl::startPageScaleAnimation(const IntSize& targetPosition, b
ool anchorPoint, float pageScale, base::TimeTicks startTime, base::TimeDelta dur
ation) |
293 { | 294 { |
294 if (!m_rootScrollLayerImpl) | 295 if (!m_rootScrollLayerImpl) |
295 return; | 296 return; |
296 | 297 |
297 IntSize scrollTotal = flooredIntSize(m_rootScrollLayerImpl->scrollPosition()
+ m_rootScrollLayerImpl->scrollDelta()); | 298 IntSize scrollTotal = flooredIntSize(m_rootScrollLayerImpl->scrollPosition()
+ m_rootScrollLayerImpl->scrollDelta()); |
298 scrollTotal.scale(m_pinchZoomViewport.pageScaleDelta()); | 299 scrollTotal.scale(m_pinchZoomViewport.pageScaleDelta()); |
299 float scaleTotal = m_pinchZoomViewport.totalPageScaleFactor(); | 300 float scaleTotal = m_pinchZoomViewport.totalPageScaleFactor(); |
300 IntSize scaledContentSize = cc::IntSize(contentSize()); | 301 gfx::Size scaledContentSize = gfx::ToFlooredSize(contentSize().Scale(m_pinch
ZoomViewport.pageScaleDelta())); |
301 scaledContentSize.scale(m_pinchZoomViewport.pageScaleDelta()); | |
302 | 302 |
303 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); | 303 double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); |
304 m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, scaleTotal, c
c::IntSize(m_deviceViewportSize), scaledContentSize, startTimeSeconds); | 304 m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, scaleTotal, c
c::IntSize(m_deviceViewportSize), scaledContentSize, startTimeSeconds); |
305 | 305 |
306 if (anchorPoint) { | 306 if (anchorPoint) { |
307 IntSize windowAnchor(targetPosition); | 307 IntSize windowAnchor(targetPosition); |
308 windowAnchor.scale(scaleTotal / pageScale); | 308 windowAnchor.scale(scaleTotal / pageScale); |
309 windowAnchor -= scrollTotal; | 309 windowAnchor -= scrollTotal; |
310 m_pageScaleAnimation->zoomWithAnchor(windowAnchor, pageScale, duration.I
nSecondsF()); | 310 m_pageScaleAnimation->zoomWithAnchor(windowAnchor, pageScale, duration.I
nSecondsF()); |
311 } else | 311 } else |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 | 1010 |
1011 // If we are called after setRootLayer() but before prepareToDraw(), we need | 1011 // If we are called after setRootLayer() but before prepareToDraw(), we need |
1012 // to recalculate the visible layers. This prevents being unable to scroll | 1012 // to recalculate the visible layers. This prevents being unable to scroll |
1013 // during part of a commit. | 1013 // during part of a commit. |
1014 m_renderSurfaceLayerList.clear(); | 1014 m_renderSurfaceLayerList.clear(); |
1015 calculateRenderSurfaceLayerList(m_renderSurfaceLayerList); | 1015 calculateRenderSurfaceLayerList(m_renderSurfaceLayerList); |
1016 | 1016 |
1017 return m_renderSurfaceLayerList.size(); | 1017 return m_renderSurfaceLayerList.size(); |
1018 } | 1018 } |
1019 | 1019 |
1020 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(const IntPoint&
viewportPoint, InputHandlerClient::ScrollInputType type) | 1020 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(const gfx::Point
& viewportPoint, InputHandlerClient::ScrollInputType type) |
1021 { | 1021 { |
1022 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); | 1022 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); |
1023 | 1023 |
1024 DCHECK(!m_currentlyScrollingLayerImpl); | 1024 DCHECK(!m_currentlyScrollingLayerImpl); |
1025 clearCurrentlyScrollingLayer(); | 1025 clearCurrentlyScrollingLayer(); |
1026 | 1026 |
1027 if (!ensureRenderSurfaceLayerList()) | 1027 if (!ensureRenderSurfaceLayerList()) |
1028 return ScrollIgnored; | 1028 return ScrollIgnored; |
1029 | 1029 |
1030 IntPoint deviceViewportPoint = viewportPoint; | 1030 gfx::PointF deviceViewportPoint = viewportPoint.Scale(m_deviceScaleFactor); |
1031 deviceViewportPoint.scale(m_deviceScaleFactor, m_deviceScaleFactor); | |
1032 | 1031 |
1033 // First find out which layer was hit from the saved list of visible layers | 1032 // First find out which layer was hit from the saved list of visible layers |
1034 // in the most recent frame. | 1033 // in the most recent frame. |
1035 LayerImpl* layerImpl = LayerTreeHostCommon::findLayerThatIsHitByPoint(device
ViewportPoint, m_renderSurfaceLayerList); | 1034 LayerImpl* layerImpl = LayerTreeHostCommon::findLayerThatIsHitByPoint(device
ViewportPoint, m_renderSurfaceLayerList); |
1036 | 1035 |
1037 // Walk up the hierarchy and look for a scrollable layer. | 1036 // Walk up the hierarchy and look for a scrollable layer. |
1038 LayerImpl* potentiallyScrollingLayerImpl = 0; | 1037 LayerImpl* potentiallyScrollingLayerImpl = 0; |
1039 for (; layerImpl; layerImpl = layerImpl->parent()) { | 1038 for (; layerImpl; layerImpl = layerImpl->parent()) { |
1040 // The content layer can also block attempts to scroll outside the main
thread. | 1039 // The content layer can also block attempts to scroll outside the main
thread. |
1041 if (layerImpl->tryScroll(deviceViewportPoint, type) == ScrollOnMainThrea
d) { | 1040 if (layerImpl->tryScroll(deviceViewportPoint, type) == ScrollOnMainThrea
d) { |
(...skipping 22 matching lines...) Expand all Loading... |
1064 // Gesture events need to be transformed from viewport coordinates to lo
cal layer coordinates | 1063 // Gesture events need to be transformed from viewport coordinates to lo
cal layer coordinates |
1065 // so that the scrolling contents exactly follow the user's finger. In c
ontrast, wheel | 1064 // so that the scrolling contents exactly follow the user's finger. In c
ontrast, wheel |
1066 // events are already in local layer coordinates so we can just apply th
em directly. | 1065 // events are already in local layer coordinates so we can just apply th
em directly. |
1067 m_scrollDeltaIsInViewportSpace = (type == Gesture); | 1066 m_scrollDeltaIsInViewportSpace = (type == Gesture); |
1068 m_numImplThreadScrolls++; | 1067 m_numImplThreadScrolls++; |
1069 return ScrollStarted; | 1068 return ScrollStarted; |
1070 } | 1069 } |
1071 return ScrollIgnored; | 1070 return ScrollIgnored; |
1072 } | 1071 } |
1073 | 1072 |
1074 static FloatSize scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewport,
LayerImpl& layerImpl, float scaleFromViewportToScreenSpace, const FloatPoint& vi
ewportPoint, const FloatSize& viewportDelta) | 1073 static FloatSize scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewport,
LayerImpl& layerImpl, float scaleFromViewportToScreenSpace, const gfx::PointF& v
iewportPoint, const FloatSize& viewportDelta) |
1075 { | 1074 { |
1076 // Layers with non-invertible screen space transforms should not have passed
the scroll hit | 1075 // Layers with non-invertible screen space transforms should not have passed
the scroll hit |
1077 // test in the first place. | 1076 // test in the first place. |
1078 DCHECK(layerImpl.screenSpaceTransform().isInvertible()); | 1077 DCHECK(layerImpl.screenSpaceTransform().isInvertible()); |
1079 WebTransformationMatrix inverseScreenSpaceTransform = layerImpl.screenSpaceT
ransform().inverse(); | 1078 WebTransformationMatrix inverseScreenSpaceTransform = layerImpl.screenSpaceT
ransform().inverse(); |
1080 | 1079 |
1081 FloatPoint screenSpacePoint = viewportPoint; | 1080 gfx::PointF screenSpacePoint = viewportPoint.Scale(scaleFromViewportToScreen
Space); |
1082 screenSpacePoint.scale(scaleFromViewportToScreenSpace, scaleFromViewportToSc
reenSpace); | |
1083 | 1081 |
1084 FloatSize screenSpaceDelta = viewportDelta; | 1082 FloatSize screenSpaceDelta = viewportDelta; |
1085 screenSpaceDelta.scale(scaleFromViewportToScreenSpace, scaleFromViewportToSc
reenSpace); | 1083 screenSpaceDelta.scale(scaleFromViewportToScreenSpace, scaleFromViewportToSc
reenSpace); |
1086 | 1084 |
1087 // First project the scroll start and end points to local layer space to fin
d the scroll delta | 1085 // First project the scroll start and end points to local layer space to fin
d the scroll delta |
1088 // in layer coordinates. | 1086 // in layer coordinates. |
1089 bool startClipped, endClipped; | 1087 bool startClipped, endClipped; |
1090 FloatPoint screenSpaceEndPoint = screenSpacePoint + screenSpaceDelta; | 1088 gfx::PointF screenSpaceEndPoint = screenSpacePoint + screenSpaceDelta; |
1091 FloatPoint localStartPoint = cc::FloatPoint(MathUtil::projectPoint(inverseSc
reenSpaceTransform, screenSpacePoint, startClipped)); | 1089 gfx::PointF localStartPoint = MathUtil::projectPoint(inverseScreenSpaceTrans
form, screenSpacePoint, startClipped); |
1092 FloatPoint localEndPoint = cc::FloatPoint(MathUtil::projectPoint(inverseScre
enSpaceTransform, screenSpaceEndPoint, endClipped)); | 1090 gfx::PointF localEndPoint = MathUtil::projectPoint(inverseScreenSpaceTransfo
rm, screenSpaceEndPoint, endClipped); |
1093 | 1091 |
1094 // In general scroll point coordinates should not get clipped. | 1092 // In general scroll point coordinates should not get clipped. |
1095 DCHECK(!startClipped); | 1093 DCHECK(!startClipped); |
1096 DCHECK(!endClipped); | 1094 DCHECK(!endClipped); |
1097 if (startClipped || endClipped) | 1095 if (startClipped || endClipped) |
1098 return FloatSize(); | 1096 return FloatSize(); |
1099 | 1097 |
1100 // localStartPoint and localEndPoint are in content space but we want to mov
e them to layer space for scrolling. | 1098 // localStartPoint and localEndPoint are in content space but we want to mov
e them to layer space for scrolling. |
1101 float widthScale = 1 / layerImpl.contentsScaleX(); | 1099 float widthScale = 1 / layerImpl.contentsScaleX(); |
1102 float heightScale = 1 / layerImpl.contentsScaleY(); | 1100 float heightScale = 1 / layerImpl.contentsScaleY(); |
1103 localStartPoint.scale(widthScale, heightScale); | 1101 localStartPoint = localStartPoint.Scale(widthScale, heightScale); |
1104 localEndPoint.scale(widthScale, heightScale); | 1102 localEndPoint = localEndPoint.Scale(widthScale, heightScale); |
1105 | 1103 |
1106 // Apply the scroll delta. | 1104 // Apply the scroll delta. |
1107 FloatSize previousDelta(layerImpl.scrollDelta()); | 1105 FloatSize previousDelta(layerImpl.scrollDelta()); |
1108 FloatSize unscrolled = layerImpl.scrollBy(localEndPoint - localStartPoint); | 1106 FloatSize unscrolled = layerImpl.scrollBy(cc::FloatSize(localEndPoint - loca
lStartPoint)); |
1109 | 1107 |
1110 if (viewport) | 1108 if (viewport) |
1111 viewport->applyScroll(unscrolled); | 1109 viewport->applyScroll(unscrolled); |
1112 | 1110 |
1113 // Get the end point in the layer's content space so we can apply its screen
SpaceTransform. | 1111 // Get the end point in the layer's content space so we can apply its screen
SpaceTransform. |
1114 FloatPoint actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta() -
previousDelta; | 1112 gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta()
- previousDelta; |
1115 gfx::PointF actualLocalContentEndPoint = actualLocalEndPoint; | 1113 gfx::PointF actualLocalContentEndPoint = actualLocalEndPoint.Scale(1 / width
Scale, 1 / heightScale); |
1116 actualLocalContentEndPoint = actualLocalContentEndPoint.Scale(1 / widthScale
, 1 / heightScale); | |
1117 | 1114 |
1118 // Calculate the applied scroll delta in viewport space coordinates. | 1115 // Calculate the applied scroll delta in viewport space coordinates. |
1119 FloatPoint actualScreenSpaceEndPoint = cc::FloatPoint(MathUtil::mapPoint(lay
erImpl.screenSpaceTransform(), actualLocalContentEndPoint, endClipped)); | 1116 gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenS
paceTransform(), actualLocalContentEndPoint, endClipped); |
1120 DCHECK(!endClipped); | 1117 DCHECK(!endClipped); |
1121 if (endClipped) | 1118 if (endClipped) |
1122 return FloatSize(); | 1119 return FloatSize(); |
1123 FloatPoint actualViewportEndPoint = actualScreenSpaceEndPoint; | 1120 gfx::PointF actualViewportEndPoint = actualScreenSpaceEndPoint.Scale(1 / sca
leFromViewportToScreenSpace); |
1124 actualViewportEndPoint.scale(1 / scaleFromViewportToScreenSpace, 1 / scaleFr
omViewportToScreenSpace); | 1121 return cc::FloatSize(actualViewportEndPoint - viewportPoint); |
1125 return actualViewportEndPoint - viewportPoint; | |
1126 } | 1122 } |
1127 | 1123 |
1128 static FloatSize scrollLayerWithLocalDelta(LayerImpl& layerImpl, const FloatSize
& localDelta) | 1124 static FloatSize scrollLayerWithLocalDelta(LayerImpl& layerImpl, const FloatSize
& localDelta) |
1129 { | 1125 { |
1130 FloatSize previousDelta(layerImpl.scrollDelta()); | 1126 FloatSize previousDelta(layerImpl.scrollDelta()); |
1131 layerImpl.scrollBy(localDelta); | 1127 layerImpl.scrollBy(localDelta); |
1132 return layerImpl.scrollDelta() - previousDelta; | 1128 return layerImpl.scrollDelta() - previousDelta; |
1133 } | 1129 } |
1134 | 1130 |
1135 void LayerTreeHostImpl::scrollBy(const IntPoint& viewportPoint, const IntSize& s
crollDelta) | 1131 void LayerTreeHostImpl::scrollBy(const gfx::Point& viewportPoint, const IntSize&
scrollDelta) |
1136 { | 1132 { |
1137 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBy"); | 1133 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBy"); |
1138 if (!m_currentlyScrollingLayerImpl) | 1134 if (!m_currentlyScrollingLayerImpl) |
1139 return; | 1135 return; |
1140 | 1136 |
1141 FloatSize pendingDelta(scrollDelta); | 1137 FloatSize pendingDelta(scrollDelta); |
1142 | 1138 |
1143 for (LayerImpl* layerImpl = m_currentlyScrollingLayerImpl; layerImpl; layerI
mpl = layerImpl->parent()) { | 1139 for (LayerImpl* layerImpl = m_currentlyScrollingLayerImpl; layerImpl; layerI
mpl = layerImpl->parent()) { |
1144 if (!layerImpl->scrollable()) | 1140 if (!layerImpl->scrollable()) |
1145 continue; | 1141 continue; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); | 1472 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); |
1477 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 1473 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
1478 if (scrollbarController && scrollbarController->animate(monotonicTime)) | 1474 if (scrollbarController && scrollbarController->animate(monotonicTime)) |
1479 m_client->setNeedsRedrawOnImplThread(); | 1475 m_client->setNeedsRedrawOnImplThread(); |
1480 | 1476 |
1481 for (size_t i = 0; i < layer->children().size(); ++i) | 1477 for (size_t i = 0; i < layer->children().size(); ++i) |
1482 animateScrollbarsRecursive(layer->children()[i], time); | 1478 animateScrollbarsRecursive(layer->children()[i], time); |
1483 } | 1479 } |
1484 | 1480 |
1485 } // namespace cc | 1481 } // namespace cc |
OLD | NEW |