[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #ifndef CC_TREES_LAYER_TREE_HOST_COMMON_H_ |
| 6 | #define CC_TREES_LAYER_TREE_HOST_COMMON_H_ |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 7 | |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 11 | #include "cc/base/cc_export.h" |
| 12 | #include "cc/base/scoped_ptr_vector.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame^] | 13 | #include "cc/layers/layer_lists.h" |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 14 | #include "ui/gfx/rect.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 15 | #include "ui/gfx/transform.h" |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 16 | #include "ui/gfx/vector2d.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 17 | |
| 18 | namespace cc { |
| 19 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 20 | class LayerImpl; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 21 | class Layer; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 22 | |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 23 | class CC_EXPORT LayerTreeHostCommon { |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 24 | public: |
| 25 | static gfx::Rect CalculateVisibleRect(gfx::Rect target_surface_rect, |
| 26 | gfx::Rect layer_bound_rect, |
| 27 | const gfx::Transform& transform); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 28 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 29 | static void CalculateDrawProperties( |
| 30 | Layer* root_layer, |
| 31 | gfx::Size device_viewport_size, |
| 32 | float device_scale_factor, |
| 33 | float page_scale_factor, |
| 34 | int max_texture_size, |
| 35 | bool can_use_lcd_text, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame^] | 36 | LayerList* render_surface_layer_list); |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 37 | static void CalculateDrawProperties( |
| 38 | LayerImpl* root_layer, |
| 39 | gfx::Size device_viewport_size, |
| 40 | float device_scale_factor, |
| 41 | float page_scale_factor, |
| 42 | int max_texture_size, |
| 43 | bool can_use_lcd_text, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame^] | 44 | LayerImplList* render_surface_layer_list, |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 45 | bool update_tile_priorities); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 46 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 47 | // Performs hit testing for a given render_surface_layer_list. |
| 48 | static LayerImpl* FindLayerThatIsHitByPoint( |
| 49 | gfx::PointF screen_space_point, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame^] | 50 | const LayerImplList& render_surface_layer_list); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 51 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 52 | static LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 53 | gfx::PointF screen_space_point, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame^] | 54 | const LayerImplList& render_surface_layer_list); |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 55 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 56 | static bool LayerHasTouchEventHandlersAt(gfx::PointF screen_space_point, |
| 57 | LayerImpl* layer_impl); |
[email protected] | 35d2edd2 | 2012-12-13 02:19:05 | [diff] [blame] | 58 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 59 | template <typename LayerType> |
| 60 | static bool RenderSurfaceContributesToTarget(LayerType*, |
| 61 | int target_surface_layer_id); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 62 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 63 | template <class Function, typename LayerType> |
| 64 | static void CallFunctionForSubtree(LayerType* root_layer); |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 65 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 66 | // Returns a layer with the given id if one exists in the subtree starting |
| 67 | // from the given root layer (including mask and replica layers). |
| 68 | template <typename LayerType> |
| 69 | static LayerType* FindLayerInSubtree(LayerType* root_layer, int layer_id); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 70 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 71 | static Layer* get_child_as_raw_ptr( |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame^] | 72 | const LayerList& children, |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 73 | size_t index) { |
| 74 | return children[index].get(); |
| 75 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 76 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 77 | static LayerImpl* get_child_as_raw_ptr( |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame^] | 78 | const OwnedLayerImplList& children, |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 79 | size_t index) { |
| 80 | return children[index]; |
| 81 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 82 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 83 | struct ScrollUpdateInfo { |
| 84 | int layer_id; |
| 85 | gfx::Vector2d scroll_delta; |
| 86 | }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 87 | }; |
| 88 | |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 89 | struct CC_EXPORT ScrollAndScaleSet { |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 90 | ScrollAndScaleSet(); |
| 91 | ~ScrollAndScaleSet(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 92 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 93 | std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls; |
| 94 | float page_scale_delta; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 95 | }; |
| 96 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 97 | template <typename LayerType> |
| 98 | bool LayerTreeHostCommon::RenderSurfaceContributesToTarget( |
| 99 | LayerType* layer, |
| 100 | int target_surface_layer_id) { |
| 101 | // A layer will either contribute its own content, or its render surface's |
| 102 | // content, to the target surface. The layer contributes its surface's content |
| 103 | // when both the following are true: |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 104 | // (1) The layer actually has a render surface, and |
| 105 | // (2) The layer's render surface is not the same as the target surface. |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 106 | // |
| 107 | // Otherwise, the layer just contributes itself to the target surface. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 108 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 109 | return layer->render_surface() && layer->id() != target_surface_layer_id; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 112 | template <typename LayerType> |
| 113 | LayerType* LayerTreeHostCommon::FindLayerInSubtree(LayerType* root_layer, |
| 114 | int layer_id) { |
| 115 | if (root_layer->id() == layer_id) |
| 116 | return root_layer; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 117 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 118 | if (root_layer->mask_layer() && root_layer->mask_layer()->id() == layer_id) |
| 119 | return root_layer->mask_layer(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 120 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 121 | if (root_layer->replica_layer() && |
| 122 | root_layer->replica_layer()->id() == layer_id) |
| 123 | return root_layer->replica_layer(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 124 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 125 | for (size_t i = 0; i < root_layer->children().size(); ++i) { |
| 126 | if (LayerType* found = FindLayerInSubtree( |
| 127 | get_child_as_raw_ptr(root_layer->children(), i), layer_id)) |
| 128 | return found; |
| 129 | } |
| 130 | return NULL; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 133 | template <class Function, typename LayerType> |
| 134 | void LayerTreeHostCommon::CallFunctionForSubtree(LayerType* root_layer) { |
| 135 | Function()(root_layer); |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 136 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 137 | if (LayerType* mask_layer = root_layer->mask_layer()) |
| 138 | Function()(mask_layer); |
| 139 | if (LayerType* replica_layer = root_layer->replica_layer()) { |
| 140 | Function()(replica_layer); |
| 141 | if (LayerType* mask_layer = replica_layer->mask_layer()) |
| 142 | Function()(mask_layer); |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | for (size_t i = 0; i < root_layer->children().size(); ++i) { |
| 146 | CallFunctionForSubtree<Function>( |
| 147 | get_child_as_raw_ptr(root_layer->children(), i)); |
| 148 | } |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | e17f307 | 2012-10-26 22:15:34 | [diff] [blame] | 151 | } // namespace cc |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 152 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 153 | #endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_ |