Home | History | Annotate | Download | only in layers
      1 // Copyright 2012 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_LAYERS_DELEGATED_RENDERER_LAYER_IMPL_H_
      6 #define CC_LAYERS_DELEGATED_RENDERER_LAYER_IMPL_H_
      7 
      8 #include "base/containers/hash_tables.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "cc/base/cc_export.h"
     11 #include "cc/base/scoped_ptr_vector.h"
     12 #include "cc/layers/layer_impl.h"
     13 
     14 namespace cc {
     15 class DelegatedFrameData;
     16 class RenderPassSink;
     17 
     18 class CC_EXPORT DelegatedRendererLayerImpl : public LayerImpl {
     19  public:
     20   static scoped_ptr<DelegatedRendererLayerImpl> Create(
     21       LayerTreeImpl* tree_impl, int id) {
     22     return make_scoped_ptr(new DelegatedRendererLayerImpl(tree_impl, id));
     23   }
     24   virtual ~DelegatedRendererLayerImpl();
     25 
     26   // LayerImpl overrides.
     27   virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
     28       OVERRIDE;
     29   virtual bool HasDelegatedContent() const OVERRIDE;
     30   virtual bool HasContributingDelegatedRenderPasses() const OVERRIDE;
     31   virtual RenderPass::Id FirstContributingRenderPassId() const OVERRIDE;
     32   virtual RenderPass::Id NextContributingRenderPassId(
     33       RenderPass::Id previous) const OVERRIDE;
     34   virtual void DidLoseOutputSurface() OVERRIDE;
     35   virtual bool WillDraw(DrawMode draw_mode,
     36                         ResourceProvider* resource_provider) OVERRIDE;
     37   virtual void AppendQuads(QuadSink* quad_sink,
     38                            AppendQuadsData* append_quads_data) OVERRIDE;
     39   virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
     40 
     41   void AppendContributingRenderPasses(RenderPassSink* render_pass_sink);
     42 
     43   // Creates an ID with the resource provider for the child renderer
     44   // that will be sending quads to the layer. Registers the callback to
     45   // inform when resources are no longer in use.
     46   void CreateChildIdIfNeeded(const ReturnCallback& return_callback);
     47 
     48   void SetFrameData(const DelegatedFrameData* frame_data,
     49                     gfx::RectF damage_in_frame);
     50 
     51   void SetDisplaySize(gfx::Size size);
     52 
     53  protected:
     54   DelegatedRendererLayerImpl(LayerTreeImpl* tree_impl, int id);
     55 
     56   int ChildIdForTesting() const { return child_id_; }
     57   const ScopedPtrVector<RenderPass>& RenderPassesInDrawOrderForTesting() const {
     58     return render_passes_in_draw_order_;
     59   }
     60   const ResourceProvider::ResourceIdArray& ResourcesForTesting() const {
     61     return resources_;
     62   }
     63 
     64  private:
     65   void ClearChildId();
     66 
     67   void AppendRainbowDebugBorder(QuadSink* quad_sink,
     68                                 AppendQuadsData* append_quads_data);
     69 
     70   void SetRenderPasses(
     71       ScopedPtrVector<RenderPass>* render_passes_in_draw_order);
     72   void ClearRenderPasses();
     73 
     74   // Returns |true| if the delegated_render_pass_id is part of the current
     75   // frame and can be converted.
     76   bool ConvertDelegatedRenderPassId(
     77       RenderPass::Id delegated_render_pass_id,
     78       RenderPass::Id* output_render_pass_id) const;
     79 
     80   gfx::Transform DelegatedFrameToLayerSpaceTransform(gfx::Size frame_size)
     81       const;
     82 
     83   void AppendRenderPassQuads(
     84       QuadSink* quad_sink,
     85       AppendQuadsData* append_quads_data,
     86       const RenderPass* delegated_render_pass,
     87       gfx::Size frame_size) const;
     88 
     89   // LayerImpl overrides.
     90   virtual const char* LayerTypeAsString() const OVERRIDE;
     91 
     92   bool have_render_passes_to_push_;
     93   ScopedPtrVector<RenderPass> render_passes_in_draw_order_;
     94   base::hash_map<RenderPass::Id, int> render_passes_index_by_id_;
     95   ResourceProvider::ResourceIdArray resources_;
     96 
     97   gfx::Size display_size_;
     98   int child_id_;
     99   bool own_child_id_;
    100 
    101   DISALLOW_COPY_AND_ASSIGN(DelegatedRendererLayerImpl);
    102 };
    103 
    104 }  // namespace cc
    105 
    106 #endif  // CC_LAYERS_DELEGATED_RENDERER_LAYER_IMPL_H_
    107