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.
5 #include "cc/layers/delegated_renderer_layer.h"
7 #include "cc/layers/delegated_renderer_layer_impl.h"
8 #include "cc/output/delegated_frame_data.h"
9 #include "cc/quads/render_pass_draw_quad.h"
10 #include "cc/trees/layer_tree_host.h"
14 scoped_refptr
<DelegatedRendererLayer
> DelegatedRendererLayer::Create(
15 const LayerSettings
& settings
,
16 const scoped_refptr
<DelegatedFrameProvider
>& frame_provider
) {
17 return scoped_refptr
<DelegatedRendererLayer
>(
18 new DelegatedRendererLayer(settings
, frame_provider
));
21 DelegatedRendererLayer::DelegatedRendererLayer(
22 const LayerSettings
& settings
,
23 const scoped_refptr
<DelegatedFrameProvider
>& frame_provider
)
25 frame_provider_(frame_provider
),
26 should_collect_new_frame_(true),
29 frame_provider_
->AddObserver(this);
32 DelegatedRendererLayer::~DelegatedRendererLayer() {
33 frame_provider_
->RemoveObserver(this);
36 scoped_ptr
<LayerImpl
> DelegatedRendererLayer::CreateLayerImpl(
37 LayerTreeImpl
* tree_impl
) {
38 return DelegatedRendererLayerImpl::Create(tree_impl
, layer_id_
);
41 void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost
* host
) {
42 if (layer_tree_host() == host
) {
43 Layer::SetLayerTreeHost(host
);
48 // The active frame needs to be removed from the active tree and resources
49 // returned before the commit is called complete.
50 // TODO(danakj): Don't need to do this if the last frame commited was empty
51 // or we never commited a frame with resources.
52 SetNextCommitWaitsForActivation();
54 // There is no active frame in the new layer tree host to wait for so no
55 // need to call SetNextCommitWaitsForActivation().
56 should_collect_new_frame_
= true;
60 Layer::SetLayerTreeHost(host
);
63 void DelegatedRendererLayer::PushPropertiesTo(LayerImpl
* impl
) {
64 Layer::PushPropertiesTo(impl
);
66 DelegatedRendererLayerImpl
* delegated_impl
=
67 static_cast<DelegatedRendererLayerImpl
*>(impl
);
69 delegated_impl
->CreateChildIdIfNeeded(
70 frame_provider_
->GetReturnResourcesCallbackForImplThread());
73 delegated_impl
->SetFrameData(frame_data_
, frame_damage_
);
74 frame_data_
= nullptr;
75 frame_damage_
= gfx::RectF();
78 void DelegatedRendererLayer::ProviderHasNewFrame() {
79 should_collect_new_frame_
= true;
81 // The active frame needs to be replaced and resources returned before the
82 // commit is called complete.
83 SetNextCommitWaitsForActivation();
86 bool DelegatedRendererLayer::Update(ResourceUpdateQueue
* queue
,
87 const OcclusionTracker
<Layer
>* occlusion
) {
88 bool updated
= Layer::Update(queue
, occlusion
);
89 if (!should_collect_new_frame_
)
93 frame_provider_
->GetFrameDataAndRefResources(this, &frame_damage_
);
94 should_collect_new_frame_
= false;
96 SetNeedsPushProperties();
100 bool DelegatedRendererLayer::HasDelegatedContent() const {