delegated_renderer_layer.cc revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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#include "cc/layers/delegated_renderer_layer.h" 6 7#include "cc/layers/delegated_renderer_layer_client.h" 8#include "cc/layers/delegated_renderer_layer_impl.h" 9#include "cc/output/delegated_frame_data.h" 10 11namespace cc { 12 13scoped_refptr<DelegatedRendererLayer> DelegatedRendererLayer::Create( 14 DelegatedRendererLayerClient* client) { 15 return scoped_refptr<DelegatedRendererLayer>( 16 new DelegatedRendererLayer(client)); 17} 18 19DelegatedRendererLayer::DelegatedRendererLayer( 20 DelegatedRendererLayerClient* client) 21 : Layer(), 22 client_(client) {} 23 24DelegatedRendererLayer::~DelegatedRendererLayer() {} 25 26scoped_ptr<LayerImpl> DelegatedRendererLayer::CreateLayerImpl( 27 LayerTreeImpl* tree_impl) { 28 return DelegatedRendererLayerImpl::Create( 29 tree_impl, layer_id_).PassAs<LayerImpl>(); 30} 31 32void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost* host) { 33 if (layer_tree_host() == host) { 34 Layer::SetLayerTreeHost(host); 35 return; 36 } 37 38 if (!host) { 39 // The active frame needs to be removed from the active tree and resources 40 // returned before the commit is called complete. 41 // TODO(danakj): Don't need to do this if the last frame commited was empty 42 // or we never commited a frame with resources. 43 SetNextCommitWaitsForActivation(); 44 } 45 46 Layer::SetLayerTreeHost(host); 47} 48 49bool DelegatedRendererLayer::DrawsContent() const { 50 return Layer::DrawsContent() && !frame_size_.IsEmpty(); 51} 52 53void DelegatedRendererLayer::PushPropertiesTo(LayerImpl* impl) { 54 Layer::PushPropertiesTo(impl); 55 56 DelegatedRendererLayerImpl* delegated_impl = 57 static_cast<DelegatedRendererLayerImpl*>(impl); 58 59 delegated_impl->SetDisplaySize(display_size_); 60 61 if (frame_data_) 62 delegated_impl->SetFrameData(frame_data_.Pass(), damage_in_frame_); 63 frame_data_.reset(); 64 damage_in_frame_ = gfx::RectF(); 65 66 delegated_impl->CollectUnusedResources( 67 &unused_resources_for_child_compositor_); 68 69 if (client_) 70 client_->DidCommitFrameData(); 71 72 // TODO(danakj): TakeUnusedResourcesForChildCompositor requires a push 73 // properties to happen in order to collect unused resources returned 74 // from the parent compositor. crbug.com/259090 75 needs_push_properties_ = true; 76} 77 78void DelegatedRendererLayer::SetDisplaySize(gfx::Size size) { 79 if (display_size_ == size) 80 return; 81 display_size_ = size; 82 SetNeedsCommit(); 83} 84 85void DelegatedRendererLayer::SetFrameData( 86 scoped_ptr<DelegatedFrameData> new_frame_data) { 87 if (frame_data_) { 88 // Copy the resources from the last provided frame into the unused resources 89 // list, as the new frame will provide its own resources. 90 TransferableResource::ReturnResources( 91 frame_data_->resource_list, 92 &unused_resources_for_child_compositor_); 93 } 94 frame_data_ = new_frame_data.Pass(); 95 if (!frame_data_->render_pass_list.empty()) { 96 RenderPass* root_pass = frame_data_->render_pass_list.back(); 97 damage_in_frame_.Union(root_pass->damage_rect); 98 frame_size_ = root_pass->output_rect.size(); 99 } else { 100 frame_size_ = gfx::Size(); 101 } 102 SetNeedsCommit(); 103 // The active frame needs to be replaced and resources returned before the 104 // commit is called complete. 105 SetNextCommitWaitsForActivation(); 106} 107 108void DelegatedRendererLayer::TakeUnusedResourcesForChildCompositor( 109 ReturnedResourceArray* array) { 110 DCHECK(array->empty()); 111 array->clear(); 112 113 array->swap(unused_resources_for_child_compositor_); 114} 115 116} // namespace cc 117