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 "cc/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 void LayerTreeHostImpl::scheduleAnimation() | 291 void LayerTreeHostImpl::scheduleAnimation() |
292 { | 292 { |
293 m_client->setNeedsRedrawOnImplThread(); | 293 m_client->setNeedsRedrawOnImplThread(); |
294 } | 294 } |
295 | 295 |
296 bool LayerTreeHostImpl::haveTouchEventHandlersAt(const gfx::Point& viewportPoint ) | 296 bool LayerTreeHostImpl::haveTouchEventHandlersAt(const gfx::Point& viewportPoint ) |
297 { | 297 { |
298 if (!ensureRenderSurfaceLayerList()) | 298 if (!ensureRenderSurfaceLayerList()) |
299 return false; | 299 return false; |
300 | 300 |
301 gfx::PointF deviceViewportPoint = gfx::ScalePoint(viewportPoint, m_deviceSca leFactor); | |
danakj
2013/01/22 23:42:15
This looks like it will break hidpi. The findLayer
aelias_OOO_until_Jul13
2013/01/24 00:47:02
Removed this change, it was speculative.
| |
302 | |
303 // First find out which layer was hit from the saved list of visible layers | 301 // First find out which layer was hit from the saved list of visible layers |
304 // in the most recent frame. | 302 // in the most recent frame. |
305 LayerImpl* layerImpl = LayerTreeHostCommon::findLayerThatIsHitByPoint(device ViewportPoint, activeTree()->RenderSurfaceLayerList()); | 303 LayerImpl* layerImpl = LayerTreeHostCommon::findLayerThatIsHitByPoint(viewpo rtPoint, activeTree()->RenderSurfaceLayerList()); |
306 | 304 |
307 // Walk up the hierarchy and look for a layer with a touch event handler reg ion that the given point hits. | 305 // Walk up the hierarchy and look for a layer with a touch event handler reg ion that the given point hits. |
308 for (; layerImpl; layerImpl = layerImpl->parent()) { | 306 for (; layerImpl; layerImpl = layerImpl->parent()) { |
309 if (LayerTreeHostCommon::layerHasTouchEventHandlersAt(deviceViewportPoint, layerImpl)) | 307 if (LayerTreeHostCommon::layerHasTouchEventHandlersAt(viewportPoint, layer Impl)) |
310 return true; | 308 return true; |
311 } | 309 } |
312 | 310 |
313 return false; | 311 return false; |
314 } | 312 } |
315 | 313 |
316 void LayerTreeHostImpl::trackDamageForAllSurfaces(LayerImpl* rootDrawLayer, cons t LayerList& renderSurfaceLayerList) | 314 void LayerTreeHostImpl::trackDamageForAllSurfaces(LayerImpl* rootDrawLayer, cons t LayerList& renderSurfaceLayerList) |
317 { | 315 { |
318 // For now, we use damage tracking to compute a global scissor. To do this, we must | 316 // For now, we use damage tracking to compute a global scissor. To do this, we must |
319 // compute all damage tracking before drawing anything, so that we know the root | 317 // compute all damage tracking before drawing anything, so that we know the root |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 | 763 |
766 void LayerTreeHostImpl::OnCanDrawStateChangedForTree(LayerTreeImpl*) | 764 void LayerTreeHostImpl::OnCanDrawStateChangedForTree(LayerTreeImpl*) |
767 { | 765 { |
768 m_client->onCanDrawStateChanged(canDraw()); | 766 m_client->onCanDrawStateChanged(canDraw()); |
769 } | 767 } |
770 | 768 |
771 CompositorFrameMetadata LayerTreeHostImpl::makeCompositorFrameMetadata() const | 769 CompositorFrameMetadata LayerTreeHostImpl::makeCompositorFrameMetadata() const |
772 { | 770 { |
773 CompositorFrameMetadata metadata; | 771 CompositorFrameMetadata metadata; |
774 metadata.page_scale_factor = m_pinchZoomViewport.total_page_scale_factor(); | 772 metadata.page_scale_factor = m_pinchZoomViewport.total_page_scale_factor(); |
775 metadata.viewport_size = m_pinchZoomViewport.ZoomedViewport().size(); | 773 metadata.viewport_size = m_pinchZoomViewport.LayoutSpaceViewportSize(); |
776 metadata.root_layer_size = activeTree()->ScrollableSize(); | 774 metadata.root_layer_size = activeTree()->ScrollableSize(); |
777 metadata.min_page_scale_factor = m_pinchZoomViewport.min_page_scale_factor() ; | 775 metadata.min_page_scale_factor = m_pinchZoomViewport.min_page_scale_factor() ; |
778 metadata.max_page_scale_factor = m_pinchZoomViewport.max_page_scale_factor() ; | 776 metadata.max_page_scale_factor = m_pinchZoomViewport.max_page_scale_factor() ; |
779 if (m_topControlsManager) { | 777 if (m_topControlsManager) { |
780 metadata.location_bar_offset = gfx::Vector2dF(0.f, m_topControlsManager- >controls_top_offset()); | 778 metadata.location_bar_offset = gfx::Vector2dF(0.f, m_topControlsManager- >controls_top_offset()); |
781 metadata.location_bar_content_translation = gfx::Vector2dF(0.f, m_topCon trolsManager->content_top_offset()); | 779 metadata.location_bar_content_translation = gfx::Vector2dF(0.f, m_topCon trolsManager->content_top_offset()); |
782 } | 780 } |
783 | 781 |
784 if (!rootScrollLayer()) | 782 if (!rootScrollLayer()) |
785 return metadata; | 783 return metadata; |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1222 return gfx::Vector2dF(); | 1220 return gfx::Vector2dF(); |
1223 | 1221 |
1224 // localStartPoint and localEndPoint are in content space but we want to mov e them to layer space for scrolling. | 1222 // localStartPoint and localEndPoint are in content space but we want to mov e them to layer space for scrolling. |
1225 float widthScale = 1 / layerImpl.contentsScaleX(); | 1223 float widthScale = 1 / layerImpl.contentsScaleX(); |
1226 float heightScale = 1 / layerImpl.contentsScaleY(); | 1224 float heightScale = 1 / layerImpl.contentsScaleY(); |
1227 localStartPoint.Scale(widthScale, heightScale); | 1225 localStartPoint.Scale(widthScale, heightScale); |
1228 localEndPoint.Scale(widthScale, heightScale); | 1226 localEndPoint.Scale(widthScale, heightScale); |
1229 | 1227 |
1230 // Apply the scroll delta. | 1228 // Apply the scroll delta. |
1231 gfx::Vector2dF previousDelta = layerImpl.scrollDelta(); | 1229 gfx::Vector2dF previousDelta = layerImpl.scrollDelta(); |
1232 gfx::Vector2dF unscrolled = layerImpl.scrollBy(localEndPoint - localStartPoi nt); | 1230 layerImpl.scrollBy(localEndPoint - localStartPoint); |
1233 gfx::Vector2dF scrollAmount = localEndPoint - localStartPoint; | |
1234 | |
1235 gfx::Vector2dF viewportAppliedPan; | |
1236 if (viewport) | |
1237 viewportAppliedPan = unscrolled - viewport->ApplyScroll(unscrolled); | |
1238 | 1231 |
1239 // Get the end point in the layer's content space so we can apply its screen SpaceTransform. | 1232 // Get the end point in the layer's content space so we can apply its screen SpaceTransform. |
1240 gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta() + viewportAppliedPan - previousDelta; | 1233 gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta() - previousDelta; |
danakj
2013/01/22 23:42:15
We definitely have some tests for this code, does
| |
1241 gfx::PointF actualLocalContentEndPoint = gfx::ScalePoint(actualLocalEndPoint , 1 / widthScale, 1 / heightScale); | 1234 gfx::PointF actualLocalContentEndPoint = gfx::ScalePoint(actualLocalEndPoint , 1 / widthScale, 1 / heightScale); |
1242 | 1235 |
1243 // Calculate the applied scroll delta in viewport space coordinates. | 1236 // Calculate the applied scroll delta in viewport space coordinates. |
1244 gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenS paceTransform(), actualLocalContentEndPoint, endClipped); | 1237 gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenS paceTransform(), actualLocalContentEndPoint, endClipped); |
1245 DCHECK(!endClipped); | 1238 DCHECK(!endClipped); |
1246 if (endClipped) | 1239 if (endClipped) |
1247 return gfx::Vector2dF(); | 1240 return gfx::Vector2dF(); |
1248 gfx::PointF actualViewportEndPoint = gfx::ScalePoint(actualScreenSpaceEndPoi nt, 1 / scaleFromViewportToScreenSpace); | 1241 gfx::PointF actualViewportEndPoint = gfx::ScalePoint(actualScreenSpaceEndPoi nt, 1 / scaleFromViewportToScreenSpace); |
1249 return actualViewportEndPoint - viewportPoint; | 1242 return actualViewportEndPoint - viewportPoint; |
1250 } | 1243 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 gfx::PointF newScaleAnchor = gfx::ScalePoint(anchor, 1 / pageScaleDelta); | 1341 gfx::PointF newScaleAnchor = gfx::ScalePoint(anchor, 1 / pageScaleDelta); |
1349 gfx::Vector2dF move = previousScaleAnchor - newScaleAnchor; | 1342 gfx::Vector2dF move = previousScaleAnchor - newScaleAnchor; |
1350 | 1343 |
1351 m_previousPinchAnchor = anchor; | 1344 m_previousPinchAnchor = anchor; |
1352 | 1345 |
1353 if (m_settings.pageScalePinchZoomEnabled) { | 1346 if (m_settings.pageScalePinchZoomEnabled) { |
1354 // Compute the application of the delta with respect to the current page zoom of the page. | 1347 // Compute the application of the delta with respect to the current page zoom of the page. |
1355 move.Scale(1 / m_pinchZoomViewport.page_scale_factor()); | 1348 move.Scale(1 / m_pinchZoomViewport.page_scale_factor()); |
1356 } | 1349 } |
1357 | 1350 |
1358 gfx::Vector2dF scrollOverflow = m_settings.pageScalePinchZoomEnabled ? m_pin chZoomViewport.ApplyScroll(move) : move; | 1351 rootScrollLayer()->scrollBy(move); |
1359 rootScrollLayer()->scrollBy(scrollOverflow); | |
1360 | 1352 |
1361 if (rootScrollLayer()->scrollbarAnimationController()) | 1353 if (rootScrollLayer()->scrollbarAnimationController()) |
1362 rootScrollLayer()->scrollbarAnimationController()->didPinchGestureUpdate (base::TimeTicks::Now()); | 1354 rootScrollLayer()->scrollbarAnimationController()->didPinchGestureUpdate (base::TimeTicks::Now()); |
1363 | 1355 |
1364 m_client->setNeedsCommitOnImplThread(); | 1356 m_client->setNeedsCommitOnImplThread(); |
1365 m_client->setNeedsRedrawOnImplThread(); | 1357 m_client->setNeedsRedrawOnImplThread(); |
1366 setNeedsUpdateDrawProperties(); | 1358 setNeedsUpdateDrawProperties(); |
1367 } | 1359 } |
1368 | 1360 |
1369 void LayerTreeHostImpl::pinchGestureEnd() | 1361 void LayerTreeHostImpl::pinchGestureEnd() |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1428 activeTree()->RootScrollLayer()->setSentScrollDelta(scroll.scrollDelta); | 1420 activeTree()->RootScrollLayer()->setSentScrollDelta(scroll.scrollDelta); |
1429 scrollInfo->pageScaleDelta = pageScale / m_pinchZoomViewport.page_scale_fact or(); | 1421 scrollInfo->pageScaleDelta = pageScale / m_pinchZoomViewport.page_scale_fact or(); |
1430 m_pinchZoomViewport.set_sent_page_scale_delta(scrollInfo->pageScaleDelta); | 1422 m_pinchZoomViewport.set_sent_page_scale_delta(scrollInfo->pageScaleDelta); |
1431 } | 1423 } |
1432 | 1424 |
1433 static void collectScrollDeltas(ScrollAndScaleSet* scrollInfo, LayerImpl* layerI mpl) | 1425 static void collectScrollDeltas(ScrollAndScaleSet* scrollInfo, LayerImpl* layerI mpl) |
1434 { | 1426 { |
1435 if (!layerImpl) | 1427 if (!layerImpl) |
1436 return; | 1428 return; |
1437 | 1429 |
1438 if (!layerImpl->scrollDelta().IsZero()) { | 1430 gfx::Vector2d scrollDelta = gfx::ToFlooredVector2d(layerImpl->scrollDelta()) ; |
1439 gfx::Vector2d scrollDelta = gfx::ToFlooredVector2d(layerImpl->scrollDelt a()); | 1431 if (!scrollDelta.IsZero()) { |
1440 LayerTreeHostCommon::ScrollUpdateInfo scroll; | 1432 LayerTreeHostCommon::ScrollUpdateInfo scroll; |
1441 scroll.layerId = layerImpl->id(); | 1433 scroll.layerId = layerImpl->id(); |
1442 scroll.scrollDelta = scrollDelta; | 1434 scroll.scrollDelta = scrollDelta; |
1443 scrollInfo->scrolls.push_back(scroll); | 1435 scrollInfo->scrolls.push_back(scroll); |
1444 layerImpl->setSentScrollDelta(scrollDelta); | 1436 layerImpl->setSentScrollDelta(scrollDelta); |
1445 } | 1437 } |
1446 | 1438 |
1447 for (size_t i = 0; i < layerImpl->children().size(); ++i) | 1439 for (size_t i = 0; i < layerImpl->children().size(); ++i) |
1448 collectScrollDeltas(scrollInfo, layerImpl->children()[i]); | 1440 collectScrollDeltas(scrollInfo, layerImpl->children()[i]); |
1449 } | 1441 } |
1450 | 1442 |
1451 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::processScrollDeltas() | 1443 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::processScrollDeltas() |
1452 { | 1444 { |
1453 scoped_ptr<ScrollAndScaleSet> scrollInfo(new ScrollAndScaleSet()); | 1445 scoped_ptr<ScrollAndScaleSet> scrollInfo(new ScrollAndScaleSet()); |
1454 | 1446 |
1455 if (m_pinchGestureActive || m_pageScaleAnimation) { | 1447 if (!m_settings.pageScalePinchZoomEnabled && (m_pinchGestureActive || m_page ScaleAnimation)) { |
1456 scrollInfo->pageScaleDelta = 1; | 1448 scrollInfo->pageScaleDelta = 1; |
1457 m_pinchZoomViewport.set_sent_page_scale_delta(1); | 1449 m_pinchZoomViewport.set_sent_page_scale_delta(1); |
1458 // FIXME(aelias): Make pinch-zoom painting optimization compatible with | 1450 if (m_pinchGestureActive) |
1459 // compositor-side scaling. | |
1460 if (!m_settings.pageScalePinchZoomEnabled && m_pinchGestureActive) | |
1461 computePinchZoomDeltas(scrollInfo.get()); | 1451 computePinchZoomDeltas(scrollInfo.get()); |
1462 else if (m_pageScaleAnimation.get()) | 1452 else if (m_pageScaleAnimation.get()) |
1463 computeDoubleTapZoomDeltas(scrollInfo.get()); | 1453 computeDoubleTapZoomDeltas(scrollInfo.get()); |
1464 return scrollInfo.Pass(); | 1454 return scrollInfo.Pass(); |
1465 } | 1455 } |
1466 | 1456 |
1467 collectScrollDeltas(scrollInfo.get(), rootLayer()); | 1457 collectScrollDeltas(scrollInfo.get(), rootLayer()); |
1468 scrollInfo->pageScaleDelta = m_pinchZoomViewport.page_scale_delta(); | 1458 scrollInfo->pageScaleDelta = m_pinchZoomViewport.page_scale_delta(); |
1469 m_pinchZoomViewport.set_sent_page_scale_delta(scrollInfo->pageScaleDelta); | 1459 m_pinchZoomViewport.set_sent_page_scale_delta(scrollInfo->pageScaleDelta); |
1470 | 1460 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1674 LayerImpl* layer = getNonCompositedContentLayerRecursive(tree->RootLayer()); | 1664 LayerImpl* layer = getNonCompositedContentLayerRecursive(tree->RootLayer()); |
1675 return layer ? layer->getPicture() : skia::RefPtr<SkPicture>(); | 1665 return layer ? layer->getPicture() : skia::RefPtr<SkPicture>(); |
1676 } | 1666 } |
1677 | 1667 |
1678 void LayerTreeHostImpl::savePaintTime(const base::TimeDelta& totalPaintTime) | 1668 void LayerTreeHostImpl::savePaintTime(const base::TimeDelta& totalPaintTime) |
1679 { | 1669 { |
1680 m_paintTimeCounter->SavePaintTime(totalPaintTime); | 1670 m_paintTimeCounter->SavePaintTime(totalPaintTime); |
1681 } | 1671 } |
1682 | 1672 |
1683 } // namespace cc | 1673 } // namespace cc |
OLD | NEW |