1 // Copyright 2014 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_SURFACES_SURFACE_AGGREGATOR_H_
6 #define CC_SURFACES_SURFACE_AGGREGATOR_H_
10 #include "base/containers/hash_tables.h"
11 #include "base/containers/scoped_ptr_hash_map.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "cc/quads/draw_quad.h"
14 #include "cc/quads/render_pass.h"
15 #include "cc/resources/transferable_resource.h"
16 #include "cc/surfaces/surface_id.h"
17 #include "cc/surfaces/surfaces_export.h"
21 class CompositorFrame
;
22 class DelegatedFrameData
;
23 class ResourceProvider
;
25 class SurfaceDrawQuad
;
28 class CC_SURFACES_EXPORT SurfaceAggregator
{
30 typedef base::hash_map
<SurfaceId
, int> SurfaceIndexMap
;
32 SurfaceAggregator(SurfaceManager
* manager
,
33 ResourceProvider
* provider
,
34 bool aggregate_only_damaged
);
37 scoped_ptr
<CompositorFrame
> Aggregate(SurfaceId surface_id
);
38 void ReleaseResources(SurfaceId surface_id
);
39 SurfaceIndexMap
& previous_contained_surfaces() {
40 return previous_contained_surfaces_
;
42 void SetFullDamageForSurface(SurfaceId surface_id
);
46 ClipData() : is_clipped(false) {}
47 ClipData(bool is_clipped
, const gfx::Rect
& rect
)
48 : is_clipped(is_clipped
), rect(rect
) {}
54 ClipData
CalculateClipRect(const ClipData
& surface_clip
,
55 const ClipData
& quad_clip
,
56 const gfx::Transform
& target_transform
);
58 RenderPassId
RemapPassId(RenderPassId surface_local_pass_id
,
59 SurfaceId surface_id
);
61 void HandleSurfaceQuad(const SurfaceDrawQuad
* surface_quad
,
62 const gfx::Transform
& target_transform
,
63 const ClipData
& clip_rect
,
64 RenderPass
* dest_pass
);
65 SharedQuadState
* CopySharedQuadState(const SharedQuadState
* source_sqs
,
66 const gfx::Transform
& target_transform
,
67 const ClipData
& clip_rect
,
68 RenderPass
* dest_render_pass
);
70 const QuadList
& source_quad_list
,
71 const SharedQuadStateList
& source_shared_quad_state_list
,
72 const base::hash_map
<ResourceId
, ResourceId
>& resource_to_child_map
,
73 const gfx::Transform
& target_transform
,
74 const ClipData
& clip_rect
,
75 RenderPass
* dest_pass
,
76 SurfaceId surface_id
);
77 gfx::Rect
PrewalkTree(SurfaceId surface_id
);
78 void CopyPasses(const DelegatedFrameData
* frame_data
, Surface
* surface
);
80 // Remove Surfaces that were referenced before but aren't currently
81 // referenced from the ResourceProvider.
82 void RemoveUnreferencedChildren();
84 int ChildIdForSurface(Surface
* surface
);
85 gfx::Rect
DamageRectForSurface(const Surface
* surface
,
86 const RenderPass
& source
,
87 const gfx::Rect
& full_rect
);
89 SurfaceManager
* manager_
;
90 ResourceProvider
* provider_
;
92 class RenderPassIdAllocator
;
93 typedef base::ScopedPtrHashMap
<SurfaceId
, scoped_ptr
<RenderPassIdAllocator
>>
94 RenderPassIdAllocatorMap
;
95 RenderPassIdAllocatorMap render_pass_allocator_map_
;
96 int next_render_pass_id_
;
97 const bool aggregate_only_damaged_
;
99 typedef base::hash_map
<SurfaceId
, int> SurfaceToResourceChildIdMap
;
100 SurfaceToResourceChildIdMap surface_id_to_resource_child_id_
;
102 // The following state is only valid for the duration of one Aggregate call
103 // and is only stored on the class to avoid having to pass through every
106 // This is the set of surfaces referenced in the aggregation so far, used to
108 typedef std::set
<SurfaceId
> SurfaceSet
;
109 SurfaceSet referenced_surfaces_
;
111 // For each Surface used in the last aggregation, gives the frame_index at
113 SurfaceIndexMap previous_contained_surfaces_
;
114 SurfaceIndexMap contained_surfaces_
;
116 // After surface validation, every Surface in this set is valid.
117 base::hash_set
<SurfaceId
> valid_surfaces_
;
119 // This is the pass list for the aggregated frame.
120 RenderPassList
* dest_pass_list_
;
122 // The root damage rect of the currently-aggregating frame.
123 gfx::Rect root_damage_rect_
;
125 // True if the frame that's currently being aggregated has copy requests.
126 // This is valid during Aggregate after PrewalkTree is called.
127 bool has_copy_requests_
;
129 // Resource list for the aggregated frame.
130 TransferableResourceArray
* dest_resource_list_
;
132 DISALLOW_COPY_AND_ASSIGN(SurfaceAggregator
);
137 #endif // CC_SURFACES_SURFACE_AGGREGATOR_H_