Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer.cc
blobc47206172ceedcd205e21525f3d11d3778700d3c
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->CreateChildIdIfNeeded(
71 frame_provider_->GetReturnResourcesCallbackForImplThread());
73 if (frame_data_)
74 delegated_impl->SetFrameData(frame_data_, frame_damage_);
75 frame_data_ = NULL;
76 frame_damage_ = gfx::RectF();
79 void DelegatedRendererLayer::ProviderHasNewFrame() {
80 should_collect_new_frame_ = true;
81 SetNeedsUpdate();
82 // The active frame needs to be replaced and resources returned before the
83 // commit is called complete.
84 SetNextCommitWaitsForActivation();
87 bool DelegatedRendererLayer::Update(ResourceUpdateQueue* queue,
88 const OcclusionTracker<Layer>* occlusion) {
89 bool updated = Layer::Update(queue, occlusion);
90 if (!should_collect_new_frame_)
91 return updated;
93 frame_data_ =
94 frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
95 should_collect_new_frame_ = false;
97 SetNeedsPushProperties();
98 return true;
101 } // namespace cc