Add Sad Tab resources to the iOS build.
[chromium-blink-merge.git] / cc / layer_tree_host_common.h
blobcc5e6213fc465b524ff7e88090a9488ee429a8f9
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/vector2d.h"
13 #include <public/WebTransformationMatrix.h>
15 namespace cc {
17 class LayerImpl;
18 class LayerSorter;
19 class Layer;
21 class CC_EXPORT LayerTreeHostCommon {
22 public:
23 static gfx::Rect calculateVisibleRect(const gfx::Rect& targetSurfaceRect, const gfx::Rect& layerBoundRect, const WebKit::WebTransformationMatrix&);
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 template<typename LayerType> static bool renderSurfaceContributesToTarget(LayerType*, int targetSurfaceLayerID);
33 // Returns a layer with the given id if one exists in the subtree starting
34 // from the given root layer (including mask and replica layers).
35 template<typename LayerType> static LayerType* findLayerInSubtree(LayerType* rootLayer, int layerId);
37 static Layer* getChildAsRawPtr(const std::vector<scoped_refptr<Layer> >& children, size_t index)
39 return children[index].get();
42 static LayerImpl* getChildAsRawPtr(const ScopedPtrVector<LayerImpl>& children, size_t index)
44 return children[index];
47 struct ScrollUpdateInfo {
48 int layerId;
49 gfx::Vector2d scrollDelta;
53 struct CC_EXPORT ScrollAndScaleSet {
54 ScrollAndScaleSet();
55 ~ScrollAndScaleSet();
57 std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls;
58 float pageScaleDelta;
61 template<typename LayerType>
62 bool LayerTreeHostCommon::renderSurfaceContributesToTarget(LayerType* layer, int targetSurfaceLayerID)
64 // A layer will either contribute its own content, or its render surface's content, to
65 // the target surface. The layer contributes its surface's content when both the
66 // following are true:
67 // (1) The layer actually has a renderSurface, and
68 // (2) The layer's renderSurface is not the same as the targetSurface.
70 // Otherwise, the layer just contributes itself to the target surface.
72 return layer->renderSurface() && layer->id() != targetSurfaceLayerID;
75 template<typename LayerType>
76 LayerType* LayerTreeHostCommon::findLayerInSubtree(LayerType* rootLayer, int layerId)
78 if (rootLayer->id() == layerId)
79 return rootLayer;
81 if (rootLayer->maskLayer() && rootLayer->maskLayer()->id() == layerId)
82 return rootLayer->maskLayer();
84 if (rootLayer->replicaLayer() && rootLayer->replicaLayer()->id() == layerId)
85 return rootLayer->replicaLayer();
87 for (size_t i = 0; i < rootLayer->children().size(); ++i) {
88 if (LayerType* found = findLayerInSubtree(getChildAsRawPtr(rootLayer->children(), i), layerId))
89 return found;
91 return 0;
94 } // namespace cc
96 #endif // CC_LAYER_TREE_HOST_COMMON_H_