| 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_common.h" | 5 #include "cc/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" |
| 9 #include "cc/layer.h" | 10 #include "cc/layer.h" |
| 10 #include "cc/layer_impl.h" | 11 #include "cc/layer_impl.h" |
| 11 #include "cc/layer_iterator.h" | 12 #include "cc/layer_iterator.h" |
| 12 #include "cc/layer_sorter.h" | 13 #include "cc/layer_sorter.h" |
| 13 #include "cc/math_util.h" | 14 #include "cc/math_util.h" |
| 14 #include "cc/render_surface.h" | 15 #include "cc/render_surface.h" |
| 15 #include "cc/render_surface_impl.h" | 16 #include "cc/render_surface_impl.h" |
| 16 #include "ui/gfx/point_conversions.h" | 17 #include "ui/gfx/point_conversions.h" |
| 17 #include "ui/gfx/rect_conversions.h" | 18 #include "ui/gfx/rect_conversions.h" |
| 18 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 19 | 20 |
| 20 namespace cc { | 21 namespace cc { |
| 21 | 22 |
| 22 ScrollAndScaleSet::ScrollAndScaleSet() | 23 ScrollAndScaleSet::ScrollAndScaleSet() |
| 23 { | 24 { |
| 24 } | 25 } |
| 25 | 26 |
| 26 ScrollAndScaleSet::~ScrollAndScaleSet() | 27 ScrollAndScaleSet::~ScrollAndScaleSet() |
| 27 { | 28 { |
| 28 } | 29 } |
| 29 | 30 |
| 31 static void sortLayers(std::vector<Layer*>::iterator first, std::vector<Layer*>:
:iterator end, LayerSorter* layerSorter) |
| 32 { |
| 33 NOTREACHED(); |
| 34 } |
| 35 |
| 36 static void sortLayers(std::vector<LayerImpl*>::iterator first, std::vector<Laye
rImpl*>::iterator end, LayerSorter* layerSorter) |
| 37 { |
| 38 DCHECK(layerSorter); |
| 39 TRACE_EVENT0("cc", "layer_tree_host_common::sortLayers"); |
| 40 layerSorter->sort(first, end); |
| 41 } |
| 42 |
| 30 gfx::Rect LayerTreeHostCommon::calculateVisibleRect(const gfx::Rect& targetSurfa
ceRect, const gfx::Rect& layerBoundRect, const gfx::Transform& transform) | 43 gfx::Rect LayerTreeHostCommon::calculateVisibleRect(const gfx::Rect& targetSurfa
ceRect, const gfx::Rect& layerBoundRect, const gfx::Transform& transform) |
| 31 { | 44 { |
| 32 // Is this layer fully contained within the target surface? | 45 // Is this layer fully contained within the target surface? |
| 33 gfx::Rect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBou
ndRect); | 46 gfx::Rect layerInSurfaceSpace = MathUtil::mapClippedRect(transform, layerBou
ndRect); |
| 34 if (targetSurfaceRect.Contains(layerInSurfaceSpace)) | 47 if (targetSurfaceRect.Contains(layerInSurfaceSpace)) |
| 35 return layerBoundRect; | 48 return layerBoundRect; |
| 36 | 49 |
| 37 // If the layer doesn't fill up the entire surface, then find the part of | 50 // If the layer doesn't fill up the entire surface, then find the part of |
| 38 // the surface rect where the layer could be visible. This avoids trying to | 51 // the surface rect where the layer could be visible. This avoids trying to |
| 39 // project surface rect points that are behind the projection point. | 52 // project surface rect points that are behind the projection point. |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 if (maskLayer) | 396 if (maskLayer) |
| 384 maskLayer->setContentsScale(contentsScale); | 397 maskLayer->setContentsScale(contentsScale); |
| 385 | 398 |
| 386 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas
kLayer() : 0; | 399 Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->mas
kLayer() : 0; |
| 387 if (replicaMaskLayer) | 400 if (replicaMaskLayer) |
| 388 replicaMaskLayer->setContentsScale(contentsScale); | 401 replicaMaskLayer->setContentsScale(contentsScale); |
| 389 } | 402 } |
| 390 | 403 |
| 391 // Recursively walks the layer tree starting at the given node and computes all
the | 404 // Recursively walks the layer tree starting at the given node and computes all
the |
| 392 // necessary transformations, clipRects, render surfaces, etc. | 405 // necessary transformations, clipRects, render surfaces, etc. |
| 393 template<typename LayerType, typename LayerList, typename RenderSurfaceType, typ
ename LayerSorter> | 406 template<typename LayerType, typename LayerList, typename RenderSurfaceType> |
| 394 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo
rm& parentMatrix, | 407 static void calculateDrawPropertiesInternal(LayerType* layer, const gfx::Transfo
rm& parentMatrix, |
| 395 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro
llCompensationMatrix, | 408 const gfx::Transform& fullHierarchyMatrix, const gfx::Transform& currentScro
llCompensationMatrix, |
| 396 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree, | 409 const gfx::Rect& clipRectFromAncestor, bool ancestorClipsSubtree, |
| 397 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL
ayerList, LayerList& layerList, | 410 RenderSurfaceType* nearestAncestorThatMovesPixels, LayerList& renderSurfaceL
ayerList, LayerList& layerList, |
| 398 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float
pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) | 411 LayerSorter* layerSorter, int maxTextureSize, float deviceScaleFactor, float
pageScaleFactor, gfx::Rect& drawableContentRectOfSubtree) |
| 399 { | 412 { |
| 400 // This function computes the new matrix transformations recursively for thi
s | 413 // This function computes the new matrix transformations recursively for thi
s |
| 401 // layer and all its descendants. It also computes the appropriate render su
rfaces. | 414 // layer and all its descendants. It also computes the appropriate render su
rfaces. |
| 402 // Some important points to remember: | 415 // Some important points to remember: |
| 403 // | 416 // |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 | 702 |
| 690 if (!layerShouldBeSkipped(layer)) | 703 if (!layerShouldBeSkipped(layer)) |
| 691 descendants.push_back(layer); | 704 descendants.push_back(layer); |
| 692 | 705 |
| 693 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri
xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; | 706 gfx::Transform nextScrollCompensationMatrix = computeScrollCompensationMatri
xForChildren(layer, parentMatrix, currentScrollCompensationMatrix);; |
| 694 | 707 |
| 695 gfx::Rect accumulatedDrawableContentRectOfChildren; | 708 gfx::Rect accumulatedDrawableContentRectOfChildren; |
| 696 for (size_t i = 0; i < layer->children().size(); ++i) { | 709 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 697 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children
(), i); | 710 LayerType* child = LayerTreeHostCommon::getChildAsRawPtr(layer->children
(), i); |
| 698 gfx::Rect drawableContentRectOfChildSubtree; | 711 gfx::Rect drawableContentRectOfChildSubtree; |
| 699 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType,
LayerSorter>(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensation
Matrix, | 712 calculateDrawPropertiesInternal<LayerType, LayerList, RenderSurfaceType>
(child, sublayerMatrix, nextHierarchyMatrix, nextScrollCompensationMatrix, |
| 700
clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMov
esPixels, | 713
clipRectForSubtree, subtreeShouldBeClipped, nearestAncestorThatMovesPixels, |
| 701
renderSurfaceLayerList, descendants, layerSorter, maxTextureSize,
deviceScaleFactor, pageScaleFactor, drawableContentRectOfChildSubtree); | 714
renderSurfaceLayerList, descendants, layerSorter, maxTextureSize, deviceScaleFa
ctor, pageScaleFactor, drawableContentRectOfChildSubtree); |
| 702 if (!drawableContentRectOfChildSubtree.IsEmpty()) { | 715 if (!drawableContentRectOfChildSubtree.IsEmpty()) { |
| 703 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf
ChildSubtree); | 716 accumulatedDrawableContentRectOfChildren.Union(drawableContentRectOf
ChildSubtree); |
| 704 if (child->renderSurface()) | 717 if (child->renderSurface()) |
| 705 descendants.push_back(child); | 718 descendants.push_back(child); |
| 706 } | 719 } |
| 707 } | 720 } |
| 708 | 721 |
| 709 // Compute the total drawableContentRect for this subtree (the rect is in ta
rgetSurface space) | 722 // Compute the total drawableContentRect for this subtree (the rect is in ta
rgetSurface space) |
| 710 gfx::Rect localDrawableContentRectOfSubtree = accumulatedDrawableContentRect
OfChildren; | 723 gfx::Rect localDrawableContentRectOfSubtree = accumulatedDrawableContentRect
OfChildren; |
| 711 if (layer->drawsContent()) | 724 if (layer->drawsContent()) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 | 822 |
| 810 markLayerAsUpdated(layer); | 823 markLayerAsUpdated(layer); |
| 811 | 824 |
| 812 // If neither this layer nor any of its children were added, early out. | 825 // If neither this layer nor any of its children were added, early out. |
| 813 if (sortingStartIndex == descendants.size()) | 826 if (sortingStartIndex == descendants.size()) |
| 814 return; | 827 return; |
| 815 | 828 |
| 816 // If preserves-3d then sort all the descendants in 3D so that they can be | 829 // If preserves-3d then sort all the descendants in 3D so that they can be |
| 817 // drawn from back to front. If the preserves-3d property is also set on the
parent then | 830 // drawn from back to front. If the preserves-3d property is also set on the
parent then |
| 818 // skip the sorting as the parent will sort all the descendants anyway. | 831 // skip the sorting as the parent will sort all the descendants anyway. |
| 819 if (descendants.size() && layer->preserves3D() && (!layer->parent() || !laye
r->parent()->preserves3D())) | 832 if (layerSorter && descendants.size() && layer->preserves3D() && (!layer->pa
rent() || !layer->parent()->preserves3D())) |
| 820 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l
ayerSorter); | 833 sortLayers(descendants.begin() + sortingStartIndex, descendants.end(), l
ayerSorter); |
| 821 | 834 |
| 822 if (layer->renderSurface()) | 835 if (layer->renderSurface()) |
| 823 drawableContentRectOfSubtree = gfx::ToEnclosingRect(layer->renderSurface
()->drawableContentRect()); | 836 drawableContentRectOfSubtree = gfx::ToEnclosingRect(layer->renderSurface
()->drawableContentRect()); |
| 824 else | 837 else |
| 825 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree; | 838 drawableContentRectOfSubtree = localDrawableContentRectOfSubtree; |
| 826 | 839 |
| 827 if (layer->hasContributingDelegatedRenderPasses()) | 840 if (layer->hasContributingDelegatedRenderPasses()) |
| 828 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa
ssLayer(layer); | 841 layer->renderTarget()->renderSurface()->addContributingDelegatedRenderPa
ssLayer(layer); |
| 829 } | 842 } |
| 830 | 843 |
| 831 void LayerTreeHostCommon::calculateDrawProperties(Layer* rootLayer, const gfx::S
ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max
TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) | 844 void LayerTreeHostCommon::calculateDrawProperties(Layer* rootLayer, const gfx::S
ize& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int max
TextureSize, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList) |
| 832 { | 845 { |
| 833 gfx::Rect totalDrawableContentRect; | 846 gfx::Rect totalDrawableContentRect; |
| 834 gfx::Transform identityMatrix; | 847 gfx::Transform identityMatrix; |
| 835 gfx::Transform deviceScaleTransform; | 848 gfx::Transform deviceScaleTransform; |
| 836 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 849 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
| 837 std::vector<scoped_refptr<Layer> > dummyLayerList; | 850 std::vector<scoped_refptr<Layer> > dummyLayerList; |
| 838 | 851 |
| 839 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. | 852 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. |
| 840 bool subtreeShouldBeClipped = true; | 853 bool subtreeShouldBeClipped = true; |
| 841 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 854 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
| 842 | 855 |
| 843 // This function should have received a root layer. | 856 // This function should have received a root layer. |
| 844 DCHECK(isRootLayer(rootLayer)); | 857 DCHECK(isRootLayer(rootLayer)); |
| 845 | 858 |
| 846 cc::calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer>
>, RenderSurface, void>( | 859 cc::calculateDrawPropertiesInternal<Layer, std::vector<scoped_refptr<Layer>
>, RenderSurface>( |
| 847 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 860 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
| 848 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, | 861 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, |
| 849 dummyLayerList, 0, maxTextureSize, | 862 dummyLayerList, 0, maxTextureSize, |
| 850 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 863 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
| 851 | 864 |
| 852 // The dummy layer list should not have been used. | 865 // The dummy layer list should not have been used. |
| 853 DCHECK(dummyLayerList.size() == 0); | 866 DCHECK(dummyLayerList.size() == 0); |
| 854 // A root layer renderSurface should always exist after calculateDrawPropert
ies. | 867 // A root layer renderSurface should always exist after calculateDrawPropert
ies. |
| 855 DCHECK(rootLayer->renderSurface()); | 868 DCHECK(rootLayer->renderSurface()); |
| 856 } | 869 } |
| 857 | 870 |
| 858 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf
x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, Lay
erSorter* layerSorter, int maxTextureSize, std::vector<LayerImpl*>& renderSurfac
eLayerList) | 871 void LayerTreeHostCommon::calculateDrawProperties(LayerImpl* rootLayer, const gf
x::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int
maxTextureSize, std::vector<LayerImpl*>& renderSurfaceLayerList) |
| 859 { | 872 { |
| 860 gfx::Rect totalDrawableContentRect; | 873 gfx::Rect totalDrawableContentRect; |
| 861 gfx::Transform identityMatrix; | 874 gfx::Transform identityMatrix; |
| 862 gfx::Transform deviceScaleTransform; | 875 gfx::Transform deviceScaleTransform; |
| 863 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); | 876 deviceScaleTransform.Scale(deviceScaleFactor, deviceScaleFactor); |
| 864 std::vector<LayerImpl*> dummyLayerList; | 877 std::vector<LayerImpl*> dummyLayerList; |
| 865 | 878 LayerSorter layerSorter; |
| 879 |
| 866 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. | 880 // The root layer's renderSurface should receive the deviceViewport as the i
nitial clipRect. |
| 867 bool subtreeShouldBeClipped = true; | 881 bool subtreeShouldBeClipped = true; |
| 868 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); | 882 gfx::Rect deviceViewportRect(gfx::Point(), deviceViewportSize); |
| 869 | 883 |
| 870 // This function should have received a root layer. | 884 // This function should have received a root layer. |
| 871 DCHECK(isRootLayer(rootLayer)); | 885 DCHECK(isRootLayer(rootLayer)); |
| 872 | 886 |
| 873 cc::calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, Rend
erSurfaceImpl, LayerSorter>( | 887 cc::calculateDrawPropertiesInternal<LayerImpl, std::vector<LayerImpl*>, Rend
erSurfaceImpl>( |
| 874 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, | 888 rootLayer, deviceScaleTransform, identityMatrix, identityMatrix, |
| 875 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, | 889 deviceViewportRect, subtreeShouldBeClipped, 0, renderSurfaceLayerList, |
| 876 dummyLayerList, layerSorter, maxTextureSize, | 890 dummyLayerList, &layerSorter, maxTextureSize, |
| 877 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); | 891 deviceScaleFactor, pageScaleFactor, totalDrawableContentRect); |
| 878 | 892 |
| 879 // The dummy layer list should not have been used. | 893 // The dummy layer list should not have been used. |
| 880 DCHECK(dummyLayerList.size() == 0); | 894 DCHECK(dummyLayerList.size() == 0); |
| 881 // A root layer renderSurface should always exist after calculateDrawPropert
ies. | 895 // A root layer renderSurface should always exist after calculateDrawPropert
ies. |
| 882 DCHECK(rootLayer->renderSurface()); | 896 DCHECK(rootLayer->renderSurface()); |
| 883 } | 897 } |
| 884 | 898 |
| 885 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf
orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) | 899 static bool pointHitsRect(const gfx::PointF& screenSpacePoint, const gfx::Transf
orm& localSpaceToScreenSpaceTransform, gfx::RectF localSpaceRect) |
| 886 { | 900 { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 | 1013 |
| 1000 foundLayer = currentLayer; | 1014 foundLayer = currentLayer; |
| 1001 break; | 1015 break; |
| 1002 } | 1016 } |
| 1003 | 1017 |
| 1004 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. | 1018 // This can potentially return 0, which means the screenSpacePoint did not s
uccessfully hit test any layers, not even the root layer. |
| 1005 return foundLayer; | 1019 return foundLayer; |
| 1006 } | 1020 } |
| 1007 | 1021 |
| 1008 } // namespace cc | 1022 } // namespace cc |
| OLD | NEW |