NaCl: Reinstate the "nacl_revision" field in DEPS
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer.cc
blob99aebdc4a6d3eb8b05f9bf148f01c7ad59d74c8f
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 weak_ptrs_(this) {
28 frame_provider_->AddObserver(this);
31 DelegatedRendererLayer::~DelegatedRendererLayer() {
32 frame_provider_->RemoveObserver(this);
35 scoped_ptr<LayerImpl> DelegatedRendererLayer::CreateLayerImpl(
36 LayerTreeImpl* tree_impl) {
37 return DelegatedRendererLayerImpl::Create(
38 tree_impl, layer_id_).PassAs<LayerImpl>();
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_ = NULL;
75 frame_damage_ = gfx::RectF();
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(ResourceUpdateQueue* queue,
87 const OcclusionTracker<Layer>* occlusion) {
88 bool updated = Layer::Update(queue, occlusion);
89 if (!should_collect_new_frame_)
90 return updated;
92 frame_data_ =
93 frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
94 should_collect_new_frame_ = false;
96 SetNeedsPushProperties();
97 return true;
100 bool DelegatedRendererLayer::HasDelegatedContent() const {
101 return true;
104 } // namespace cc