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
& content_to_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
& content_to_target_transform
,
61 const ClipData
& clip_rect
,
62 RenderPass
* dest_pass
);
63 void CopySharedQuadState(const SharedQuadState
* source_sqs
,
64 const gfx::Transform
& content_to_target_transform
,
65 const ClipData
& clip_rect
,
66 RenderPass
* dest_render_pass
);
67 void CopyQuadsToPass(const QuadList
& source_quad_list
,
68 const SharedQuadStateList
& source_shared_quad_state_list
,
69 const DrawQuad::ResourceIteratorCallback
& remap
,
70 const gfx::Transform
& content_to_target_transform
,
71 const ClipData
& clip_rect
,
72 RenderPass
* dest_pass
,
73 SurfaceId surface_id
);
74 void CopyPasses(const DelegatedFrameData
* frame_data
, Surface
* surface
);
76 // Remove Surfaces that were referenced before but aren't currently
77 // referenced from the ResourceProvider.
78 void RemoveUnreferencedChildren();
80 bool ValidateResources(Surface
* surface
,
81 const DelegatedFrameData
* frame_data
);
82 int ChildIdForSurface(Surface
* surface
);
83 gfx::Rect
DamageRectForSurface(const Surface
* surface
,
84 const RenderPass
& source
,
85 const gfx::Rect
& full_rect
);
87 SurfaceManager
* manager_
;
88 ResourceProvider
* provider_
;
90 class RenderPassIdAllocator
;
91 typedef base::ScopedPtrHashMap
<SurfaceId
, RenderPassIdAllocator
>
92 RenderPassIdAllocatorMap
;
93 RenderPassIdAllocatorMap render_pass_allocator_map_
;
94 int next_render_pass_id_
;
96 typedef base::hash_map
<SurfaceId
, int> SurfaceToResourceChildIdMap
;
97 SurfaceToResourceChildIdMap surface_id_to_resource_child_id_
;
99 // The following state is only valid for the duration of one Aggregate call
100 // and is only stored on the class to avoid having to pass through every
103 // This is the set of surfaces referenced in the aggregation so far, used to
105 typedef std::set
<SurfaceId
> SurfaceSet
;
106 SurfaceSet referenced_surfaces_
;
108 // For each Surface used in the last aggregation, gives the frame_index at
110 SurfaceIndexMap previous_contained_surfaces_
;
111 SurfaceIndexMap contained_surfaces_
;
113 // This is the pass list for the aggregated frame.
114 RenderPassList
* dest_pass_list_
;
116 // Resource list for the aggregated frame.
117 TransferableResourceArray
* dest_resource_list_
;
119 DISALLOW_COPY_AND_ASSIGN(SurfaceAggregator
);
124 #endif // CC_SURFACES_SURFACE_AGGREGATOR_H_