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 RenderPassId FirstContributingRenderPassId() const OVERRIDE; 32 virtual RenderPassId NextContributingRenderPassId( 33 RenderPassId previous) const OVERRIDE; 34 virtual void ReleaseResources() OVERRIDE; 35 virtual bool WillDraw(DrawMode draw_mode, 36 ResourceProvider* resource_provider) OVERRIDE; 37 virtual void AppendQuads(RenderPass* render_pass, 38 const OcclusionTracker<LayerImpl>& occlusion_tracker, 39 AppendQuadsData* append_quads_data) OVERRIDE; 40 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE; 41 42 void AppendContributingRenderPasses(RenderPassSink* render_pass_sink); 43 44 // Creates an ID with the resource provider for the child renderer 45 // that will be sending quads to the layer. Registers the callback to 46 // inform when resources are no longer in use. 47 void CreateChildIdIfNeeded(const ReturnCallback& return_callback); 48 49 void SetFrameData(const DelegatedFrameData* frame_data, 50 const gfx::RectF& damage_in_frame); 51 52 float inverse_device_scale_factor() const { 53 return inverse_device_scale_factor_; 54 } 55 56 protected: 57 DelegatedRendererLayerImpl(LayerTreeImpl* tree_impl, int id); 58 59 int ChildIdForTesting() const { return child_id_; } 60 const RenderPassList& RenderPassesInDrawOrderForTesting() const { 61 return render_passes_in_draw_order_; 62 } 63 const ResourceProvider::ResourceIdArray& ResourcesForTesting() const { 64 return resources_; 65 } 66 67 private: 68 void ClearChildId(); 69 70 void AppendRainbowDebugBorder(RenderPass* render_pass, 71 AppendQuadsData* append_quads_data); 72 73 void SetRenderPasses(RenderPassList* render_passes_in_draw_order); 74 void ClearRenderPasses(); 75 76 // Returns |true| if the delegated_render_pass_id is part of the current 77 // frame and can be converted. 78 bool ConvertDelegatedRenderPassId(RenderPassId delegated_render_pass_id, 79 RenderPassId* output_render_pass_id) const; 80 81 void AppendRenderPassQuads( 82 RenderPass* render_pass, 83 const OcclusionTracker<LayerImpl>& occlusion_tracker, 84 AppendQuadsData* append_quads_data, 85 const RenderPass* delegated_render_pass, 86 const gfx::Size& frame_size) const; 87 88 // LayerImpl overrides. 89 virtual const char* LayerTypeAsString() const OVERRIDE; 90 91 bool have_render_passes_to_push_; 92 float inverse_device_scale_factor_; 93 RenderPassList render_passes_in_draw_order_; 94 base::hash_map<RenderPassId, int> render_passes_index_by_id_; 95 ResourceProvider::ResourceIdArray resources_; 96 97 int child_id_; 98 bool own_child_id_; 99 100 DISALLOW_COPY_AND_ASSIGN(DelegatedRendererLayerImpl); 101 }; 102 103 } // namespace cc 104 105 #endif // CC_LAYERS_DELEGATED_RENDERER_LAYER_IMPL_H_ 106