Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / cc / surfaces / surface_aggregator.h
blob8ae3b04cad7757135a9ab2cc526dd5cf115c0c43
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_
8 #include <set>
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/render_pass.h"
14 #include "cc/resources/transferable_resource.h"
15 #include "cc/surfaces/surface_id.h"
16 #include "cc/surfaces/surfaces_export.h"
18 namespace cc {
20 class CompositorFrame;
21 class DelegatedFrameData;
22 class ResourceProvider;
23 class Surface;
24 class SurfaceDrawQuad;
25 class SurfaceManager;
27 class CC_SURFACES_EXPORT SurfaceAggregator {
28 public:
29 typedef base::hash_map<SurfaceId, int> SurfaceIndexMap;
31 SurfaceAggregator(SurfaceManager* manager, ResourceProvider* provider);
32 ~SurfaceAggregator();
34 scoped_ptr<CompositorFrame> Aggregate(SurfaceId surface_id);
35 void ReleaseResources(SurfaceId surface_id);
36 SurfaceIndexMap& previous_contained_surfaces() {
37 return previous_contained_surfaces_;
40 private:
41 struct ClipData {
42 ClipData() : is_clipped(false) {}
43 ClipData(bool is_clipped, const gfx::Rect& rect)
44 : is_clipped(is_clipped), rect(rect) {}
46 bool is_clipped;
47 gfx::Rect rect;
50 ClipData CalculateClipRect(const ClipData& surface_clip,
51 const ClipData& quad_clip,
52 const gfx::Transform& content_to_target_transform);
54 RenderPassId RemapPassId(RenderPassId surface_local_pass_id,
55 SurfaceId surface_id);
57 void HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad,
58 const gfx::Transform& content_to_target_transform,
59 const ClipData& clip_rect,
60 RenderPass* dest_pass);
61 void CopySharedQuadState(const SharedQuadState* source_sqs,
62 const gfx::Transform& content_to_target_transform,
63 const ClipData& clip_rect,
64 RenderPass* dest_render_pass);
65 void CopyQuadsToPass(const QuadList& source_quad_list,
66 const SharedQuadStateList& source_shared_quad_state_list,
67 const gfx::Transform& content_to_target_transform,
68 const ClipData& clip_rect,
69 RenderPass* dest_pass,
70 SurfaceId surface_id);
71 void CopyPasses(const DelegatedFrameData* frame_data, Surface* surface);
73 // Remove Surfaces that were referenced before but aren't currently
74 // referenced from the ResourceProvider.
75 void RemoveUnreferencedChildren();
77 bool TakeResources(Surface* surface,
78 const DelegatedFrameData* frame_data,
79 RenderPassList* render_pass_list);
80 int ChildIdForSurface(Surface* surface);
81 gfx::Rect DamageRectForSurface(const Surface* surface,
82 const RenderPass& source,
83 const gfx::Rect& full_rect);
85 SurfaceManager* manager_;
86 ResourceProvider* provider_;
88 class RenderPassIdAllocator;
89 typedef base::ScopedPtrHashMap<SurfaceId, RenderPassIdAllocator>
90 RenderPassIdAllocatorMap;
91 RenderPassIdAllocatorMap render_pass_allocator_map_;
92 int next_render_pass_id_;
94 typedef base::hash_map<SurfaceId, int> SurfaceToResourceChildIdMap;
95 SurfaceToResourceChildIdMap surface_id_to_resource_child_id_;
97 // The following state is only valid for the duration of one Aggregate call
98 // and is only stored on the class to avoid having to pass through every
99 // function call.
101 // This is the set of surfaces referenced in the aggregation so far, used to
102 // detect cycles.
103 typedef std::set<SurfaceId> SurfaceSet;
104 SurfaceSet referenced_surfaces_;
106 // For each Surface used in the last aggregation, gives the frame_index at
107 // that time.
108 SurfaceIndexMap previous_contained_surfaces_;
109 SurfaceIndexMap contained_surfaces_;
111 // This is the pass list for the aggregated frame.
112 RenderPassList* dest_pass_list_;
114 // Resource list for the aggregated frame.
115 TransferableResourceArray* dest_resource_list_;
117 DISALLOW_COPY_AND_ASSIGN(SurfaceAggregator);
120 } // namespace cc
122 #endif // CC_SURFACES_SURFACE_AGGREGATOR_H_