Abstract GoogleURLTracker & google_util Profile dependencies
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer.cc
blob194455ac268a80805deea4a0798f7d5edb111454
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/blocking_task_runner.h"
11 #include "cc/trees/layer_tree_host.h"
13 namespace cc {
15 scoped_refptr<DelegatedRendererLayer> DelegatedRendererLayer::Create(
16 const scoped_refptr<DelegatedFrameProvider>& frame_provider) {
17 return scoped_refptr<DelegatedRendererLayer>(
18 new DelegatedRendererLayer(frame_provider));
21 DelegatedRendererLayer::DelegatedRendererLayer(
22 const scoped_refptr<DelegatedFrameProvider>& frame_provider)
23 : Layer(),
24 frame_provider_(frame_provider),
25 should_collect_new_frame_(true),
26 frame_data_(NULL),
27 main_thread_runner_(BlockingTaskRunner::current()),
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(
39 tree_impl, layer_id_).PassAs<LayerImpl>();
42 void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost* host) {
43 if (layer_tree_host() == host) {
44 Layer::SetLayerTreeHost(host);
45 return;
48 if (!host) {
49 // The active frame needs to be removed from the active tree and resources
50 // returned before the commit is called complete.
51 // TODO(danakj): Don't need to do this if the last frame commited was empty
52 // or we never commited a frame with resources.
53 SetNextCommitWaitsForActivation();
54 } else {
55 // There is no active frame in the new layer tree host to wait for so no
56 // need to call SetNextCommitWaitsForActivation().
57 should_collect_new_frame_ = true;
58 SetNeedsUpdate();
61 Layer::SetLayerTreeHost(host);
64 void DelegatedRendererLayer::PushPropertiesTo(LayerImpl* impl) {
65 Layer::PushPropertiesTo(impl);
67 DelegatedRendererLayerImpl* delegated_impl =
68 static_cast<DelegatedRendererLayerImpl*>(impl);
70 delegated_impl->SetDisplaySize(display_size_);
72 delegated_impl->CreateChildIdIfNeeded(
73 frame_provider_->GetReturnResourcesCallbackForImplThread());
75 if (frame_data_)
76 delegated_impl->SetFrameData(frame_data_, frame_damage_);
77 frame_data_ = NULL;
78 frame_damage_ = gfx::RectF();
81 void DelegatedRendererLayer::ProviderHasNewFrame() {
82 should_collect_new_frame_ = true;
83 SetNeedsUpdate();
84 // The active frame needs to be replaced and resources returned before the
85 // commit is called complete.
86 SetNextCommitWaitsForActivation();
89 void DelegatedRendererLayer::SetDisplaySize(const gfx::Size& size) {
90 if (display_size_ == size)
91 return;
92 display_size_ = size;
93 SetNeedsCommit();
96 bool DelegatedRendererLayer::Update(ResourceUpdateQueue* queue,
97 const OcclusionTracker<Layer>* occlusion) {
98 bool updated = Layer::Update(queue, occlusion);
99 if (!should_collect_new_frame_)
100 return updated;
102 frame_data_ =
103 frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
104 should_collect_new_frame_ = false;
106 SetNeedsPushProperties();
107 return true;
110 } // namespace cc