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_TREES_LAYER_SORTER_H_
6 #define CC_TREES_LAYER_SORTER_H_
10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/layers/layer_impl.h"
14 #include "ui/gfx/point3_f.h"
15 #include "ui/gfx/quad_f.h"
16 #include "ui/gfx/rect_f.h"
17 #include "ui/gfx/vector3d_f.h"
19 #if defined(COMPILER_GCC)
20 namespace cc
{ struct GraphEdge
; }
22 namespace BASE_HASH_NAMESPACE
{
24 struct hash
<cc::GraphEdge
*> {
25 size_t operator()(cc::GraphEdge
* ptr
) const {
26 return hash
<size_t>()(reinterpret_cast<size_t>(ptr
));
29 } // namespace BASE_HASH_NAMESPACE
39 // Holds various useful properties derived from a layer's 3D outline.
40 struct CC_EXPORT LayerShape
{
42 LayerShape(float width
, float height
, const gfx::Transform
& draw_transform
);
45 float LayerZFromProjectedPoint(const gfx::PointF
& p
) const;
47 gfx::Vector3dF layer_normal
;
48 gfx::Point3F transform_origin
;
49 gfx::QuadF projected_quad
;
50 gfx::RectF projected_bounds
;
54 explicit GraphNode(LayerImpl
* layer_impl
);
59 std::vector
<GraphEdge
*> incoming
;
60 std::vector
<GraphEdge
*> outgoing
;
61 float incoming_edge_weight
;
65 GraphEdge(GraphNode
* from_node
, GraphNode
* to_node
, float weight
)
77 class CC_EXPORT LayerSorter
{
82 void Sort(LayerImplList::iterator first
, LayerImplList::iterator last
);
84 enum ABCompareResult
{
90 static ABCompareResult
CheckOverlap(LayerShape
* a
,
96 typedef std::vector
<GraphNode
> NodeList
;
97 typedef std::vector
<GraphEdge
> EdgeList
;
102 typedef base::hash_map
<GraphEdge
*, GraphEdge
*> EdgeMap
;
103 EdgeMap active_edges_
;
105 void CreateGraphNodes(LayerImplList::iterator first
,
106 LayerImplList::iterator last
);
107 void CreateGraphEdges();
108 void RemoveEdgeFromList(GraphEdge
* graph
, std::vector
<GraphEdge
*>* list
);
110 DISALLOW_COPY_AND_ASSIGN(LayerSorter
);
114 #endif // CC_TREES_LAYER_SORTER_H_