Home | History | Annotate | Download | only in surfaces
      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.
      4 
      5 #ifndef CC_SURFACES_SURFACE_AGGREGATOR_H_
      6 #define CC_SURFACES_SURFACE_AGGREGATOR_H_
      7 
      8 #include <set>
      9 
     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"
     17 
     18 namespace cc {
     19 
     20 class CompositorFrame;
     21 class DelegatedFrameData;
     22 class ResourceProvider;
     23 class Surface;
     24 class SurfaceDrawQuad;
     25 class SurfaceManager;
     26 
     27 class CC_SURFACES_EXPORT SurfaceAggregator {
     28  public:
     29   typedef base::hash_map<SurfaceId, int> SurfaceIndexMap;
     30 
     31   SurfaceAggregator(SurfaceManager* manager, ResourceProvider* provider);
     32   ~SurfaceAggregator();
     33 
     34   scoped_ptr<CompositorFrame> Aggregate(SurfaceId surface_id);
     35   SurfaceIndexMap& previous_contained_surfaces() {
     36     return previous_contained_surfaces_;
     37   }
     38 
     39  private:
     40   RenderPassId RemapPassId(RenderPassId surface_local_pass_id,
     41                            SurfaceId surface_id);
     42 
     43   void HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad,
     44                          RenderPass* dest_pass);
     45   void CopySharedQuadState(const SharedQuadState* source_sqs,
     46                            const gfx::Transform& content_to_target_transform,
     47                            RenderPass* dest_render_pass);
     48   void CopyQuadsToPass(const QuadList& source_quad_list,
     49                        const SharedQuadStateList& source_shared_quad_state_list,
     50                        const gfx::Transform& content_to_target_transform,
     51                        RenderPass* dest_pass,
     52                        SurfaceId surface_id);
     53   void CopyPasses(const RenderPassList& source_pass_list,
     54                   const Surface* surface);
     55 
     56   bool TakeResources(Surface* surface,
     57                      const DelegatedFrameData* frame_data,
     58                      RenderPassList* render_pass_list);
     59   int ChildIdForSurface(Surface* surface);
     60   gfx::Rect DamageRectForSurface(const Surface* surface,
     61                                  const RenderPass& source);
     62 
     63   SurfaceManager* manager_;
     64   ResourceProvider* provider_;
     65 
     66   class RenderPassIdAllocator;
     67   typedef base::ScopedPtrHashMap<SurfaceId, RenderPassIdAllocator>
     68       RenderPassIdAllocatorMap;
     69   RenderPassIdAllocatorMap render_pass_allocator_map_;
     70 
     71   typedef base::hash_map<SurfaceId, int> SurfaceToResourceChildIdMap;
     72   SurfaceToResourceChildIdMap surface_id_to_resource_child_id_;
     73 
     74   // The following state is only valid for the duration of one Aggregate call
     75   // and is only stored on the class to avoid having to pass through every
     76   // function call.
     77 
     78   // This is the set of surfaces referenced in the aggregation so far, used to
     79   // detect cycles.
     80   typedef std::set<SurfaceId> SurfaceSet;
     81   SurfaceSet referenced_surfaces_;
     82 
     83   // For each Surface used in the last aggregation, gives the frame_index at
     84   // that time.
     85   SurfaceIndexMap previous_contained_surfaces_;
     86   SurfaceIndexMap contained_surfaces_;
     87 
     88   // This is the pass list for the aggregated frame.
     89   RenderPassList* dest_pass_list_;
     90 
     91   // Resource list for the aggregated frame.
     92   TransferableResourceArray* dest_resource_list_;
     93 
     94   DISALLOW_COPY_AND_ASSIGN(SurfaceAggregator);
     95 };
     96 
     97 }  // namespace cc
     98 
     99 #endif  // CC_SURFACES_SURFACE_AGGREGATOR_H_
    100