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
, ResourceProvider
* provider
);
35 scoped_ptr
<CompositorFrame
> Aggregate(SurfaceId surface_id
);
36 void ReleaseResources(SurfaceId surface_id
);
37 SurfaceIndexMap
& previous_contained_surfaces() {
38 return previous_contained_surfaces_
;
40 void SetFullDamageForSurface(SurfaceId surface_id
);
44 ClipData() : is_clipped(false) {}
45 ClipData(bool is_clipped
, const gfx::Rect
& rect
)
46 : is_clipped(is_clipped
), rect(rect
) {}
52 ClipData
CalculateClipRect(const ClipData
& surface_clip
,
53 const ClipData
& quad_clip
,
54 const gfx::Transform
& target_transform
);
56 RenderPassId
RemapPassId(RenderPassId surface_local_pass_id
,
57 SurfaceId surface_id
);
59 void HandleSurfaceQuad(const SurfaceDrawQuad
* surface_quad
,
60 const gfx::Transform
& target_transform
,
61 const ClipData
& clip_rect
,
62 RenderPass
* dest_pass
);
63 void CopySharedQuadState(const SharedQuadState
* source_sqs
,
64 const gfx::Transform
& target_transform
,
65 const ClipData
& clip_rect
,
66 RenderPass
* dest_render_pass
);
68 const QuadList
& source_quad_list
,
69 const SharedQuadStateList
& source_shared_quad_state_list
,
70 const base::hash_map
<ResourceId
, ResourceId
>& resource_to_child_map
,
71 const gfx::Transform
& target_transform
,
72 const ClipData
& clip_rect
,
73 RenderPass
* dest_pass
,
74 SurfaceId surface_id
);
75 void CopyPasses(const DelegatedFrameData
* frame_data
, Surface
* surface
);
77 // Remove Surfaces that were referenced before but aren't currently
78 // referenced from the ResourceProvider.
79 void RemoveUnreferencedChildren();
81 bool ValidateResources(Surface
* surface
,
82 const DelegatedFrameData
* frame_data
);
83 int ChildIdForSurface(Surface
* surface
);
84 gfx::Rect
DamageRectForSurface(const Surface
* surface
,
85 const RenderPass
& source
,
86 const gfx::Rect
& full_rect
);
88 SurfaceManager
* manager_
;
89 ResourceProvider
* provider_
;
91 class RenderPassIdAllocator
;
92 typedef base::ScopedPtrHashMap
<SurfaceId
, scoped_ptr
<RenderPassIdAllocator
>>
93 RenderPassIdAllocatorMap
;
94 RenderPassIdAllocatorMap render_pass_allocator_map_
;
95 int next_render_pass_id_
;
97 typedef base::hash_map
<SurfaceId
, int> SurfaceToResourceChildIdMap
;
98 SurfaceToResourceChildIdMap surface_id_to_resource_child_id_
;
100 // The following state is only valid for the duration of one Aggregate call
101 // and is only stored on the class to avoid having to pass through every
104 // This is the set of surfaces referenced in the aggregation so far, used to
106 typedef std::set
<SurfaceId
> SurfaceSet
;
107 SurfaceSet referenced_surfaces_
;
109 // For each Surface used in the last aggregation, gives the frame_index at
111 SurfaceIndexMap previous_contained_surfaces_
;
112 SurfaceIndexMap contained_surfaces_
;
114 // This is the pass list for the aggregated frame.
115 RenderPassList
* dest_pass_list_
;
117 // Resource list for the aggregated frame.
118 TransferableResourceArray
* dest_resource_list_
;
120 DISALLOW_COPY_AND_ASSIGN(SurfaceAggregator
);
125 #endif // CC_SURFACES_SURFACE_AGGREGATOR_H_