Roll src/third_party/WebKit 2146135:dc7c4b0 (svn 202183:202185)
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer.cc
blob4c0e3cca9da456ac7bf10ff1801bed6fdd1c6afc
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"
12 namespace cc {
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)
24 : Layer(settings),
25 frame_provider_(frame_provider),
26 should_collect_new_frame_(true),
27 frame_data_(nullptr),
28 weak_ptrs_(this) {
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);
44 return;
47 if (!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();
53 } else {
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;
57 SetNeedsUpdate();
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());
72 if (frame_data_)
73 delegated_impl->SetFrameData(frame_data_, frame_damage_);
74 frame_data_ = nullptr;
75 frame_damage_ = gfx::Rect();
78 void DelegatedRendererLayer::ProviderHasNewFrame() {
79 should_collect_new_frame_ = true;
80 SetNeedsUpdate();
81 // The active frame needs to be replaced and resources returned before the
82 // commit is called complete.
83 SetNextCommitWaitsForActivation();
86 bool DelegatedRendererLayer::Update() {
87 bool updated = Layer::Update();
88 if (!should_collect_new_frame_)
89 return updated;
91 frame_data_ =
92 frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
93 should_collect_new_frame_ = false;
95 SetNeedsPushProperties();
96 return true;
99 bool DelegatedRendererLayer::HasDelegatedContent() const {
100 return true;
103 } // namespace cc