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/geometry/point3_f.h"
15 #include "ui/gfx/geometry/quad_f.h"
16 #include "ui/gfx/geometry/rect_f.h"
17 #include "ui/gfx/geometry/vector3d_f.h"
26 // Holds various useful properties derived from a layer's 3D outline.
27 struct CC_EXPORT LayerShape
{
29 LayerShape(float width
, float height
, const gfx::Transform
& draw_transform
);
32 float LayerZFromProjectedPoint(const gfx::PointF
& p
) const;
34 gfx::Vector3dF layer_normal
;
35 gfx::Point3F transform_origin
;
36 gfx::QuadF projected_quad
;
37 gfx::RectF projected_bounds
;
41 explicit GraphNode(LayerImpl
* layer_impl
);
46 std::vector
<GraphEdge
*> incoming
;
47 std::vector
<GraphEdge
*> outgoing
;
48 float incoming_edge_weight
;
52 GraphEdge(GraphNode
* from_node
, GraphNode
* to_node
, float weight
)
64 class CC_EXPORT LayerSorter
{
69 void Sort(LayerImplList::iterator first
, LayerImplList::iterator last
);
71 enum ABCompareResult
{
77 static ABCompareResult
CheckOverlap(LayerShape
* a
,
83 typedef std::vector
<GraphNode
> NodeList
;
84 typedef std::vector
<GraphEdge
> EdgeList
;
89 typedef base::hash_map
<GraphEdge
*, GraphEdge
*> EdgeMap
;
90 EdgeMap active_edges_
;
92 void CreateGraphNodes(LayerImplList::iterator first
,
93 LayerImplList::iterator last
);
94 void CreateGraphEdges();
95 void RemoveEdgeFromList(GraphEdge
* graph
, std::vector
<GraphEdge
*>* list
);
97 DISALLOW_COPY_AND_ASSIGN(LayerSorter
);
101 #endif // CC_TREES_LAYER_SORTER_H_