| 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/trees/layer_tree_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 832 |
| 833 if (!root_layer()) | 833 if (!root_layer()) |
| 834 return false; | 834 return false; |
| 835 | 835 |
| 836 { | 836 { |
| 837 base::ElapsedTimer timer; | 837 base::ElapsedTimer timer; |
| 838 TRACE_EVENT2( | 838 TRACE_EVENT2( |
| 839 "cc", "LayerTreeImpl::UpdateDrawProperties::CalculateDrawProperties", | 839 "cc", "LayerTreeImpl::UpdateDrawProperties::CalculateDrawProperties", |
| 840 "IsActive", IsActiveTree(), "SourceFrameNumber", source_frame_number_); | 840 "IsActive", IsActiveTree(), "SourceFrameNumber", source_frame_number_); |
| 841 bool can_render_to_separate_surface = | 841 bool can_render_to_separate_surface = |
| 842 (!is_in_resourceless_software_draw_mode()); | 842 (layer_tree_host_impl_->GetDrawMode() != |
| 843 DRAW_MODE_RESOURCELESS_SOFTWARE); |
| 843 | 844 |
| 844 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( | 845 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
| 845 root_layer(), DrawViewportSize(), | 846 root_layer(), DrawViewportSize(), |
| 846 layer_tree_host_impl_->DrawTransform(), device_scale_factor(), | 847 layer_tree_host_impl_->DrawTransform(), device_scale_factor(), |
| 847 current_page_scale_factor(), PageScaleLayer(), | 848 current_page_scale_factor(), PageScaleLayer(), |
| 848 InnerViewportScrollLayer(), OuterViewportScrollLayer(), | 849 InnerViewportScrollLayer(), OuterViewportScrollLayer(), |
| 849 elastic_overscroll()->Current(IsActiveTree()), | 850 elastic_overscroll()->Current(IsActiveTree()), |
| 850 OverscrollElasticityLayer(), resource_provider()->max_texture_size(), | 851 OverscrollElasticityLayer(), resource_provider()->max_texture_size(), |
| 851 can_render_to_separate_surface, | 852 can_render_to_separate_surface, |
| 852 settings().layer_transforms_should_scale_layer_contents, | 853 settings().layer_transforms_should_scale_layer_contents, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 : layer_tree_host_impl_->pending_tree(); | 945 : layer_tree_host_impl_->pending_tree(); |
| 945 // If this is not the sync tree, then it is not safe to update lcd text | 946 // If this is not the sync tree, then it is not safe to update lcd text |
| 946 // as it causes invalidations and the tiles may be in use. | 947 // as it causes invalidations and the tiles may be in use. |
| 947 DCHECK_EQ(this, sync_tree); | 948 DCHECK_EQ(this, sync_tree); |
| 948 for (const auto& layer : picture_layers_) | 949 for (const auto& layer : picture_layers_) |
| 949 layer->UpdateCanUseLCDTextAfterCommit(); | 950 layer->UpdateCanUseLCDTextAfterCommit(); |
| 950 } | 951 } |
| 951 | 952 |
| 952 // Resourceless draw do not need tiles and should not affect existing tile | 953 // Resourceless draw do not need tiles and should not affect existing tile |
| 953 // priorities. | 954 // priorities. |
| 954 if (!is_in_resourceless_software_draw_mode()) { | 955 if (layer_tree_host_impl_->GetDrawMode() != DRAW_MODE_RESOURCELESS_SOFTWARE) { |
| 955 TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateDrawProperties::UpdateTiles", | 956 TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateDrawProperties::UpdateTiles", |
| 956 "IsActive", IsActiveTree(), "SourceFrameNumber", | 957 "IsActive", IsActiveTree(), "SourceFrameNumber", |
| 957 source_frame_number_); | 958 source_frame_number_); |
| 958 size_t layers_updated_count = 0; | 959 size_t layers_updated_count = 0; |
| 959 bool tile_priorities_updated = false; | 960 bool tile_priorities_updated = false; |
| 960 for (PictureLayerImpl* layer : picture_layers_) { | 961 for (PictureLayerImpl* layer : picture_layers_) { |
| 961 if (!layer->is_drawn_render_surface_layer_list_member()) | 962 if (!layer->is_drawn_render_surface_layer_list_member()) |
| 962 continue; | 963 continue; |
| 963 ++layers_updated_count; | 964 ++layers_updated_count; |
| 964 tile_priorities_updated |= layer->UpdateTiles(); | 965 tile_priorities_updated |= layer->UpdateTiles(); |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1613 for (const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); | 1614 for (const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); |
| 1614 clip_node->id > 1; clip_node = clip_tree.parent(clip_node)) { | 1615 clip_node->id > 1; clip_node = clip_tree.parent(clip_node)) { |
| 1615 if (clip_node->data.applies_local_clip) { | 1616 if (clip_node->data.applies_local_clip) { |
| 1616 const TransformNode* transform_node = | 1617 const TransformNode* transform_node = |
| 1617 transform_tree.Node(clip_node->data.target_id); | 1618 transform_tree.Node(clip_node->data.target_id); |
| 1618 gfx::Rect combined_clip_in_target_space = | 1619 gfx::Rect combined_clip_in_target_space = |
| 1619 gfx::ToEnclosingRect(clip_node->data.combined_clip_in_target_space); | 1620 gfx::ToEnclosingRect(clip_node->data.combined_clip_in_target_space); |
| 1620 | 1621 |
| 1621 const LayerImpl* target_layer = | 1622 const LayerImpl* target_layer = |
| 1622 layer->layer_tree_impl()->LayerById(transform_node->owner_id); | 1623 layer->layer_tree_impl()->LayerById(transform_node->owner_id); |
| 1623 DCHECK(transform_node->id == 0 || target_layer->render_surface() || | 1624 DCHECK(transform_node->id == 0 || target_layer->render_surface()); |
| 1624 layer->layer_tree_impl()->is_in_resourceless_software_draw_mode()); | |
| 1625 gfx::Transform surface_screen_space_transform = | 1625 gfx::Transform surface_screen_space_transform = |
| 1626 transform_node->id == 0 || | 1626 transform_node->id == 0 |
| 1627 (layer->layer_tree_impl() | |
| 1628 ->is_in_resourceless_software_draw_mode()) | |
| 1629 ? gfx::Transform() | 1627 ? gfx::Transform() |
| 1630 : SurfaceScreenSpaceTransform(target_layer, transform_tree); | 1628 : SurfaceScreenSpaceTransform(target_layer, transform_tree); |
| 1631 if (!PointHitsRect(screen_space_point, surface_screen_space_transform, | 1629 if (!PointHitsRect(screen_space_point, surface_screen_space_transform, |
| 1632 combined_clip_in_target_space, NULL)) { | 1630 combined_clip_in_target_space, NULL)) { |
| 1633 return true; | 1631 return true; |
| 1634 } | 1632 } |
| 1635 } | 1633 } |
| 1636 const LayerImpl* clip_node_owner = | 1634 const LayerImpl* clip_node_owner = |
| 1637 layer->layer_tree_impl()->LayerById(clip_node->owner_id); | 1635 layer->layer_tree_impl()->LayerById(clip_node->owner_id); |
| 1638 if (clip_node_owner->render_surface() && | 1636 if (clip_node_owner->render_surface() && |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 FindClosestMatchingLayer(screen_space_point, root_layer(), func, | 1821 FindClosestMatchingLayer(screen_space_point, root_layer(), func, |
| 1824 property_trees_.transform_tree, | 1822 property_trees_.transform_tree, |
| 1825 property_trees_.clip_tree, &state); | 1823 property_trees_.clip_tree, &state); |
| 1826 return state.closest_match; | 1824 return state.closest_match; |
| 1827 } | 1825 } |
| 1828 | 1826 |
| 1829 void LayerTreeImpl::RegisterSelection(const LayerSelection& selection) { | 1827 void LayerTreeImpl::RegisterSelection(const LayerSelection& selection) { |
| 1830 selection_ = selection; | 1828 selection_ = selection; |
| 1831 } | 1829 } |
| 1832 | 1830 |
| 1833 static ViewportSelectionBound ComputeViewportSelectionBound( | 1831 static gfx::SelectionBound ComputeViewportSelectionBound( |
| 1834 const LayerSelectionBound& layer_bound, | 1832 const LayerSelectionBound& layer_bound, |
| 1835 LayerImpl* layer, | 1833 LayerImpl* layer, |
| 1836 float device_scale_factor, | 1834 float device_scale_factor, |
| 1837 const TransformTree& transform_tree, | 1835 const TransformTree& transform_tree, |
| 1838 const ClipTree& clip_tree) { | 1836 const ClipTree& clip_tree) { |
| 1839 ViewportSelectionBound viewport_bound; | 1837 gfx::SelectionBound viewport_bound; |
| 1840 viewport_bound.type = layer_bound.type; | 1838 viewport_bound.set_type( |
| 1839 static_cast<gfx::SelectionBound::Type>(layer_bound.type)); |
| 1841 | 1840 |
| 1842 if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY) | 1841 if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY) |
| 1843 return viewport_bound; | 1842 return viewport_bound; |
| 1844 | 1843 |
| 1845 auto layer_top = gfx::PointF(layer_bound.edge_top); | 1844 auto layer_top = gfx::PointF(layer_bound.edge_top); |
| 1846 auto layer_bottom = gfx::PointF(layer_bound.edge_bottom); | 1845 auto layer_bottom = gfx::PointF(layer_bound.edge_bottom); |
| 1847 gfx::Transform screen_space_transform = layer->ScreenSpaceTransform(); | 1846 gfx::Transform screen_space_transform = layer->ScreenSpaceTransform(); |
| 1848 | 1847 |
| 1849 bool clipped = false; | 1848 bool clipped = false; |
| 1850 gfx::PointF screen_top = | 1849 gfx::PointF screen_top = |
| 1851 MathUtil::MapPoint(screen_space_transform, layer_top, &clipped); | 1850 MathUtil::MapPoint(screen_space_transform, layer_top, &clipped); |
| 1852 gfx::PointF screen_bottom = | 1851 gfx::PointF screen_bottom = |
| 1853 MathUtil::MapPoint(screen_space_transform, layer_bottom, &clipped); | 1852 MathUtil::MapPoint(screen_space_transform, layer_bottom, &clipped); |
| 1854 | 1853 |
| 1855 // MapPoint can produce points with NaN components (even when no inputs are | 1854 // MapPoint can produce points with NaN components (even when no inputs are |
| 1856 // NaN). Since consumers of ViewportSelectionBounds may round |edge_top| or | 1855 // NaN). Since consumers of gfx::SelectionBounds may round |edge_top| or |
| 1857 // |edge_bottom| (and since rounding will crash on NaN), we return an empty | 1856 // |edge_bottom| (and since rounding will crash on NaN), we return an empty |
| 1858 // bound instead. | 1857 // bound instead. |
| 1859 if (std::isnan(screen_top.x()) || std::isnan(screen_top.y()) || | 1858 if (std::isnan(screen_top.x()) || std::isnan(screen_top.y()) || |
| 1860 std::isnan(screen_bottom.x()) || std::isnan(screen_bottom.y())) | 1859 std::isnan(screen_bottom.x()) || std::isnan(screen_bottom.y())) |
| 1861 return ViewportSelectionBound(); | 1860 return gfx::SelectionBound(); |
| 1862 | 1861 |
| 1863 const float inv_scale = 1.f / device_scale_factor; | 1862 const float inv_scale = 1.f / device_scale_factor; |
| 1864 viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale); | 1863 viewport_bound.SetEdgeTop(gfx::ScalePoint(screen_top, inv_scale)); |
| 1865 viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale); | 1864 viewport_bound.SetEdgeBottom(gfx::ScalePoint(screen_bottom, inv_scale)); |
| 1866 | 1865 |
| 1867 // The bottom edge point is used for visibility testing as it is the logical | 1866 // The bottom edge point is used for visibility testing as it is the logical |
| 1868 // focal point for bound selection handles (this may change in the future). | 1867 // focal point for bound selection handles (this may change in the future). |
| 1869 // Shifting the visibility point fractionally inward ensures that neighboring | 1868 // Shifting the visibility point fractionally inward ensures that neighboring |
| 1870 // or logically coincident layers aligned to integral DPI coordinates will not | 1869 // or logically coincident layers aligned to integral DPI coordinates will not |
| 1871 // spuriously occlude the bound. | 1870 // spuriously occlude the bound. |
| 1872 gfx::Vector2dF visibility_offset = layer_top - layer_bottom; | 1871 gfx::Vector2dF visibility_offset = layer_top - layer_bottom; |
| 1873 visibility_offset.Scale(device_scale_factor / visibility_offset.Length()); | 1872 visibility_offset.Scale(device_scale_factor / visibility_offset.Length()); |
| 1874 gfx::PointF visibility_point = layer_bottom + visibility_offset; | 1873 gfx::PointF visibility_point = layer_bottom + visibility_offset; |
| 1875 if (visibility_point.x() <= 0) | 1874 if (visibility_point.x() <= 0) |
| 1876 visibility_point.set_x(visibility_point.x() + device_scale_factor); | 1875 visibility_point.set_x(visibility_point.x() + device_scale_factor); |
| 1877 visibility_point = | 1876 visibility_point = |
| 1878 MathUtil::MapPoint(screen_space_transform, visibility_point, &clipped); | 1877 MathUtil::MapPoint(screen_space_transform, visibility_point, &clipped); |
| 1879 | 1878 |
| 1880 float intersect_distance = 0.f; | 1879 float intersect_distance = 0.f; |
| 1881 viewport_bound.visible = PointHitsLayer( | 1880 viewport_bound.set_visible(PointHitsLayer( |
| 1882 layer, visibility_point, &intersect_distance, transform_tree, clip_tree); | 1881 layer, visibility_point, &intersect_distance, transform_tree, clip_tree)); |
| 1883 | 1882 |
| 1884 return viewport_bound; | 1883 return viewport_bound; |
| 1885 } | 1884 } |
| 1886 | 1885 |
| 1887 void LayerTreeImpl::GetViewportSelection(ViewportSelection* selection) { | 1886 void LayerTreeImpl::GetViewportSelection( |
| 1887 Selection<gfx::SelectionBound>* selection) { |
| 1888 DCHECK(selection); | 1888 DCHECK(selection); |
| 1889 | 1889 |
| 1890 selection->start = ComputeViewportSelectionBound( | 1890 selection->start = ComputeViewportSelectionBound( |
| 1891 selection_.start, | 1891 selection_.start, |
| 1892 selection_.start.layer_id ? LayerById(selection_.start.layer_id) : NULL, | 1892 selection_.start.layer_id ? LayerById(selection_.start.layer_id) : NULL, |
| 1893 device_scale_factor(), property_trees_.transform_tree, | 1893 device_scale_factor(), property_trees_.transform_tree, |
| 1894 property_trees_.clip_tree); | 1894 property_trees_.clip_tree); |
| 1895 selection->is_editable = selection_.is_editable; | 1895 selection->is_editable = selection_.is_editable; |
| 1896 selection->is_empty_text_form_control = selection_.is_empty_text_form_control; | 1896 selection->is_empty_text_form_control = selection_.is_empty_text_form_control; |
| 1897 if (selection->start.type == SELECTION_BOUND_CENTER || | 1897 if (selection->start.type() == gfx::SelectionBound::CENTER || |
| 1898 selection->start.type == SELECTION_BOUND_EMPTY) { | 1898 selection->start.type() == gfx::SelectionBound::EMPTY) { |
| 1899 selection->end = selection->start; | 1899 selection->end = selection->start; |
| 1900 } else { | 1900 } else { |
| 1901 selection->end = ComputeViewportSelectionBound( | 1901 selection->end = ComputeViewportSelectionBound( |
| 1902 selection_.end, | 1902 selection_.end, |
| 1903 selection_.end.layer_id ? LayerById(selection_.end.layer_id) : NULL, | 1903 selection_.end.layer_id ? LayerById(selection_.end.layer_id) : NULL, |
| 1904 device_scale_factor(), property_trees_.transform_tree, | 1904 device_scale_factor(), property_trees_.transform_tree, |
| 1905 property_trees_.clip_tree); | 1905 property_trees_.clip_tree); |
| 1906 } | 1906 } |
| 1907 } | 1907 } |
| 1908 | 1908 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2055 } | 2055 } |
| 2056 | 2056 |
| 2057 void LayerTreeImpl::ResetAllChangeTracking() { | 2057 void LayerTreeImpl::ResetAllChangeTracking() { |
| 2058 layers_that_should_push_properties_.clear(); | 2058 layers_that_should_push_properties_.clear(); |
| 2059 for (auto* layer : *this) | 2059 for (auto* layer : *this) |
| 2060 layer->ResetChangeTracking(); | 2060 layer->ResetChangeTracking(); |
| 2061 property_trees_.ResetAllChangeTracking(); | 2061 property_trees_.ResetAllChangeTracking(); |
| 2062 } | 2062 } |
| 2063 | 2063 |
| 2064 } // namespace cc | 2064 } // namespace cc |
| OLD | NEW |