| 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 #ifndef CC_TREES_LAYER_TREE_HOST_COMMON_H_ | 5 #ifndef CC_TREES_LAYER_TREE_HOST_COMMON_H_ |
| 6 #define CC_TREES_LAYER_TREE_HOST_COMMON_H_ | 6 #define CC_TREES_LAYER_TREE_HOST_COMMON_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "cc/base/cc_export.h" | 9 #include "cc/base/cc_export.h" |
| 10 #include "cc/base/scoped_ptr_vector.h" | 10 #include "cc/base/scoped_ptr_vector.h" |
| 11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 12 #include "ui/gfx/transform.h" | 12 #include "ui/gfx/transform.h" |
| 13 #include "ui/gfx/vector2d.h" | 13 #include "ui/gfx/vector2d.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 class LayerImpl; | 17 class LayerImpl; |
| 18 class Layer; | 18 class Layer; |
| 19 | 19 |
| 20 class CC_EXPORT LayerTreeHostCommon { | 20 class CC_EXPORT LayerTreeHostCommon { |
| 21 public: | 21 public: |
| 22 static gfx::Rect CalculateVisibleRect(gfx::Rect target_surface_rect, | 22 static gfx::Rect calculateVisibleRect(const gfx::Rect& targetSurfaceRect, co
nst gfx::Rect& layerBoundRect, const gfx::Transform&); |
| 23 gfx::Rect layer_bound_rect, | |
| 24 const gfx::Transform& transform); | |
| 25 | 23 |
| 26 static void CalculateDrawProperties( | 24 static void calculateDrawProperties(Layer* rootLayer, const gfx::Size& devic
eViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSiz
e, bool canUseLCDText, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerLis
t); |
| 27 Layer* root_layer, | 25 static void calculateDrawProperties(LayerImpl* rootLayer, const gfx::Size& d
eviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextur
eSize, bool canUseLCDText, std::vector<LayerImpl*>& renderSurfaceLayerList, bool
updateTilePriorities); |
| 28 gfx::Size device_viewport_size, | |
| 29 float device_scale_factor, | |
| 30 float page_scale_factor, | |
| 31 int max_texture_size, | |
| 32 bool can_use_lcd_text, | |
| 33 std::vector<scoped_refptr<Layer> >* render_surface_layer_list); | |
| 34 static void CalculateDrawProperties( | |
| 35 LayerImpl* root_layer, | |
| 36 gfx::Size device_viewport_size, | |
| 37 float device_scale_factor, | |
| 38 float page_scale_factor, | |
| 39 int max_texture_size, | |
| 40 bool can_use_lcd_text, | |
| 41 std::vector<LayerImpl*>* render_surface_layer_list, | |
| 42 bool update_tile_priorities); | |
| 43 | 26 |
| 44 // Performs hit testing for a given render_surface_layer_list. | 27 // Performs hit testing for a given renderSurfaceLayerList. |
| 45 static LayerImpl* FindLayerThatIsHitByPoint( | 28 static LayerImpl* findLayerThatIsHitByPoint(const gfx::PointF& screenSpacePo
int, const std::vector<LayerImpl*>& renderSurfaceLayerList); |
| 46 gfx::PointF screen_space_point, | |
| 47 const std::vector<LayerImpl*>& render_surface_layer_list); | |
| 48 | 29 |
| 49 static LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion( | 30 static LayerImpl* findLayerThatIsHitByPointInTouchHandlerRegion(const gfx::P
ointF& screenSpacePoint, const std::vector<LayerImpl*>& renderSurfaceLayerList); |
| 50 gfx::PointF screen_space_point, | |
| 51 const std::vector<LayerImpl*>& render_surface_layer_list); | |
| 52 | 31 |
| 53 static bool LayerHasTouchEventHandlersAt(gfx::PointF screen_space_point, | 32 static bool layerHasTouchEventHandlersAt(const gfx::PointF& screenSpacePoint
, LayerImpl* layerImpl); |
| 54 LayerImpl* layer_impl); | |
| 55 | 33 |
| 56 template <typename LayerType> | 34 template<typename LayerType> static bool renderSurfaceContributesToTarget(La
yerType*, int targetSurfaceLayerID); |
| 57 static bool RenderSurfaceContributesToTarget(LayerType*, | |
| 58 int target_surface_layer_id); | |
| 59 | 35 |
| 60 template <class Function, typename LayerType> | 36 template<class Function, typename LayerType> static void callFunctionForSubt
ree(LayerType* rootLayer); |
| 61 static void CallFunctionForSubtree(LayerType* root_layer); | |
| 62 | 37 |
| 63 // Returns a layer with the given id if one exists in the subtree starting | 38 // Returns a layer with the given id if one exists in the subtree starting |
| 64 // from the given root layer (including mask and replica layers). | 39 // from the given root layer (including mask and replica layers). |
| 65 template <typename LayerType> | 40 template<typename LayerType> static LayerType* findLayerInSubtree(LayerType*
rootLayer, int layerId); |
| 66 static LayerType* FindLayerInSubtree(LayerType* root_layer, int layer_id); | |
| 67 | 41 |
| 68 static Layer* get_child_as_raw_ptr( | 42 static Layer* getChildAsRawPtr(const std::vector<scoped_refptr<Layer> >& chi
ldren, size_t index) |
| 69 const std::vector<scoped_refptr<Layer> >& children, | 43 { |
| 70 size_t index) { | 44 return children[index].get(); |
| 71 return children[index].get(); | 45 } |
| 72 } | |
| 73 | 46 |
| 74 static LayerImpl* get_child_as_raw_ptr( | 47 static LayerImpl* getChildAsRawPtr(const ScopedPtrVector<LayerImpl>& childre
n, size_t index) |
| 75 const ScopedPtrVector<LayerImpl>& children, | 48 { |
| 76 size_t index) { | 49 return children[index]; |
| 77 return children[index]; | 50 } |
| 78 } | |
| 79 | 51 |
| 80 struct ScrollUpdateInfo { | 52 struct ScrollUpdateInfo { |
| 81 int layer_id; | 53 int layerId; |
| 82 gfx::Vector2d scroll_delta; | 54 gfx::Vector2d scrollDelta; |
| 83 }; | 55 }; |
| 84 }; | 56 }; |
| 85 | 57 |
| 86 struct CC_EXPORT ScrollAndScaleSet { | 58 struct CC_EXPORT ScrollAndScaleSet { |
| 87 ScrollAndScaleSet(); | 59 ScrollAndScaleSet(); |
| 88 ~ScrollAndScaleSet(); | 60 ~ScrollAndScaleSet(); |
| 89 | 61 |
| 90 std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls; | 62 std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls; |
| 91 float page_scale_delta; | 63 float pageScaleDelta; |
| 92 }; | 64 }; |
| 93 | 65 |
| 94 template <typename LayerType> | 66 template<typename LayerType> |
| 95 bool LayerTreeHostCommon::RenderSurfaceContributesToTarget( | 67 bool LayerTreeHostCommon::renderSurfaceContributesToTarget(LayerType* layer, int
targetSurfaceLayerID) |
| 96 LayerType* layer, | 68 { |
| 97 int target_surface_layer_id) { | 69 // A layer will either contribute its own content, or its render surface's c
ontent, to |
| 98 // A layer will either contribute its own content, or its render surface's | 70 // the target surface. The layer contributes its surface's content when both
the |
| 99 // content, to the target surface. The layer contributes its surface's content | 71 // following are true: |
| 100 // when both the following are true: | 72 // (1) The layer actually has a renderSurface, and |
| 101 // (1) The layer actually has a renderSurface, and | 73 // (2) The layer's renderSurface is not the same as the targetSurface. |
| 102 // (2) The layer's renderSurface is not the same as the targetSurface. | 74 // |
| 103 // | 75 // Otherwise, the layer just contributes itself to the target surface. |
| 104 // Otherwise, the layer just contributes itself to the target surface. | |
| 105 | 76 |
| 106 return layer->render_surface() && layer->id() != target_surface_layer_id; | 77 return layer->render_surface() && layer->id() != targetSurfaceLayerID; |
| 107 } | 78 } |
| 108 | 79 |
| 109 template <typename LayerType> | 80 template<typename LayerType> |
| 110 LayerType* LayerTreeHostCommon::FindLayerInSubtree(LayerType* root_layer, | 81 LayerType* LayerTreeHostCommon::findLayerInSubtree(LayerType* rootLayer, int lay
erId) |
| 111 int layer_id) { | 82 { |
| 112 if (root_layer->id() == layer_id) | 83 if (rootLayer->id() == layerId) |
| 113 return root_layer; | 84 return rootLayer; |
| 114 | 85 |
| 115 if (root_layer->mask_layer() && root_layer->mask_layer()->id() == layer_id) | 86 if (rootLayer->mask_layer() && rootLayer->mask_layer()->id() == layerId) |
| 116 return root_layer->mask_layer(); | 87 return rootLayer->mask_layer(); |
| 117 | 88 |
| 118 if (root_layer->replica_layer() && | 89 if (rootLayer->replica_layer() && rootLayer->replica_layer()->id() == layerI
d) |
| 119 root_layer->replica_layer()->id() == layer_id) | 90 return rootLayer->replica_layer(); |
| 120 return root_layer->replica_layer(); | |
| 121 | 91 |
| 122 for (size_t i = 0; i < root_layer->children().size(); ++i) { | 92 for (size_t i = 0; i < rootLayer->children().size(); ++i) { |
| 123 if (LayerType* found = FindLayerInSubtree( | 93 if (LayerType* found = findLayerInSubtree(getChildAsRawPtr(rootLayer->ch
ildren(), i), layerId)) |
| 124 get_child_as_raw_ptr(root_layer->children(), i), layer_id)) | 94 return found; |
| 125 return found; | 95 } |
| 126 } | 96 return 0; |
| 127 return NULL; | |
| 128 } | 97 } |
| 129 | 98 |
| 130 template <class Function, typename LayerType> | 99 template<class Function, typename LayerType> |
| 131 void LayerTreeHostCommon::CallFunctionForSubtree(LayerType* root_layer) { | 100 void LayerTreeHostCommon::callFunctionForSubtree(LayerType* rootLayer) |
| 132 Function()(root_layer); | 101 { |
| 102 Function()(rootLayer); |
| 103 |
| 104 if (LayerType* maskLayer = rootLayer->mask_layer()) |
| 105 Function()(maskLayer); |
| 106 if (LayerType* replicaLayer = rootLayer->replica_layer()) { |
| 107 Function()(replicaLayer); |
| 108 if (LayerType* maskLayer = replicaLayer->mask_layer()) |
| 109 Function()(maskLayer); |
| 110 } |
| 133 | 111 |
| 134 if (LayerType* maskLayer = root_layer->mask_layer()) | 112 for (size_t i = 0; i < rootLayer->children().size(); ++i) |
| 135 Function()(maskLayer); | 113 callFunctionForSubtree<Function>(getChildAsRawPtr(rootLayer->children(),
i)); |
| 136 if (LayerType* replicaLayer = root_layer->replica_layer()) { | |
| 137 Function()(replicaLayer); | |
| 138 if (LayerType* maskLayer = replicaLayer->mask_layer()) | |
| 139 Function()(maskLayer); | |
| 140 } | |
| 141 | |
| 142 for (size_t i = 0; i < root_layer->children().size(); ++i) { | |
| 143 CallFunctionForSubtree<Function>( | |
| 144 get_child_as_raw_ptr(root_layer->children(), i)); | |
| 145 } | |
| 146 } | 114 } |
| 147 | 115 |
| 148 } // namespace cc | 116 } // namespace cc |
| 149 | 117 |
| 150 #endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_ | 118 #endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_ |
| OLD | NEW |