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
3 // found in the LICENSE file.
5 #ifndef CC_LAYER_TREE_HOST_COMMON_H_
6 #define CC_LAYER_TREE_HOST_COMMON_H_
8 #include "base/memory/ref_counted.h"
9 #include "cc/cc_export.h"
10 #include "cc/scoped_ptr_vector.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/transform.h"
13 #include "ui/gfx/vector2d.h"
21 class CC_EXPORT LayerTreeHostCommon
{
23 static gfx::Rect
calculateVisibleRect(const gfx::Rect
& targetSurfaceRect
, const gfx::Rect
& layerBoundRect
, const gfx::Transform
&);
25 static void calculateDrawTransforms(Layer
* rootLayer
, const gfx::Size
& deviceViewportSize
, float deviceScaleFactor
, float pageScaleFactor
, int maxTextureSize
, std::vector
<scoped_refptr
<Layer
> >& renderSurfaceLayerList
);
26 static void calculateDrawTransforms(LayerImpl
* rootLayer
, const gfx::Size
& deviceViewportSize
, float deviceScaleFactor
, float pageScaleFactor
, LayerSorter
*, int maxTextureSize
, std::vector
<LayerImpl
*>& renderSurfaceLayerList
);
28 // Performs hit testing for a given renderSurfaceLayerList.
29 static LayerImpl
* findLayerThatIsHitByPoint(const gfx::PointF
& screenSpacePoint
, std::vector
<LayerImpl
*>& renderSurfaceLayerList
);
31 static LayerImpl
* findLayerThatIsHitByPointInTouchHandlerRegion(const gfx::PointF
& screenSpacePoint
, std::vector
<LayerImpl
*>& renderSurfaceLayerList
);
33 template<typename LayerType
> static bool renderSurfaceContributesToTarget(LayerType
*, int targetSurfaceLayerID
);
35 // Returns a layer with the given id if one exists in the subtree starting
36 // from the given root layer (including mask and replica layers).
37 template<typename LayerType
> static LayerType
* findLayerInSubtree(LayerType
* rootLayer
, int layerId
);
39 static Layer
* getChildAsRawPtr(const std::vector
<scoped_refptr
<Layer
> >& children
, size_t index
)
41 return children
[index
].get();
44 static LayerImpl
* getChildAsRawPtr(const ScopedPtrVector
<LayerImpl
>& children
, size_t index
)
46 return children
[index
];
49 struct ScrollUpdateInfo
{
51 gfx::Vector2d scrollDelta
;
55 struct CC_EXPORT ScrollAndScaleSet
{
59 std::vector
<LayerTreeHostCommon::ScrollUpdateInfo
> scrolls
;
63 template<typename LayerType
>
64 bool LayerTreeHostCommon::renderSurfaceContributesToTarget(LayerType
* layer
, int targetSurfaceLayerID
)
66 // A layer will either contribute its own content, or its render surface's content, to
67 // the target surface. The layer contributes its surface's content when both the
68 // following are true:
69 // (1) The layer actually has a renderSurface, and
70 // (2) The layer's renderSurface is not the same as the targetSurface.
72 // Otherwise, the layer just contributes itself to the target surface.
74 return layer
->renderSurface() && layer
->id() != targetSurfaceLayerID
;
77 template<typename LayerType
>
78 LayerType
* LayerTreeHostCommon::findLayerInSubtree(LayerType
* rootLayer
, int layerId
)
80 if (rootLayer
->id() == layerId
)
83 if (rootLayer
->maskLayer() && rootLayer
->maskLayer()->id() == layerId
)
84 return rootLayer
->maskLayer();
86 if (rootLayer
->replicaLayer() && rootLayer
->replicaLayer()->id() == layerId
)
87 return rootLayer
->replicaLayer();
89 for (size_t i
= 0; i
< rootLayer
->children().size(); ++i
) {
90 if (LayerType
* found
= findLayerInSubtree(getChildAsRawPtr(rootLayer
->children(), i
), layerId
))
98 #endif // CC_LAYER_TREE_HOST_COMMON_H_