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