Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / cc / layers / delegated_renderer_layer.cc
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.
4
5 #include "cc/layers/delegated_renderer_layer.h"
6
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"
11
12 namespace cc {
13
14 scoped_refptr<DelegatedRendererLayer> DelegatedRendererLayer::Create(
15     const scoped_refptr<DelegatedFrameProvider>& frame_provider) {
16   return scoped_refptr<DelegatedRendererLayer>(
17       new DelegatedRendererLayer(frame_provider));
18 }
19
20 DelegatedRendererLayer::DelegatedRendererLayer(
21     const scoped_refptr<DelegatedFrameProvider>& frame_provider)
22     : Layer(),
23       frame_provider_(frame_provider),
24       should_collect_new_frame_(true),
25       frame_data_(NULL),
26       weak_ptrs_(this) {
27   frame_provider_->AddObserver(this);
28 }
29
30 DelegatedRendererLayer::~DelegatedRendererLayer() {
31   frame_provider_->RemoveObserver(this);
32 }
33
34 scoped_ptr<LayerImpl> DelegatedRendererLayer::CreateLayerImpl(
35     LayerTreeImpl* tree_impl) {
36   return DelegatedRendererLayerImpl::Create(
37       tree_impl, layer_id_).PassAs<LayerImpl>();
38 }
39
40 void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost* host) {
41   if (layer_tree_host() == host) {
42     Layer::SetLayerTreeHost(host);
43     return;
44   }
45
46   if (!host) {
47     // The active frame needs to be removed from the active tree and resources
48     // returned before the commit is called complete.
49     // TODO(danakj): Don't need to do this if the last frame commited was empty
50     // or we never commited a frame with resources.
51     SetNextCommitWaitsForActivation();
52   } else {
53     // There is no active frame in the new layer tree host to wait for so no
54     // need to call SetNextCommitWaitsForActivation().
55     should_collect_new_frame_ = true;
56     SetNeedsUpdate();
57   }
58
59   Layer::SetLayerTreeHost(host);
60 }
61
62 void DelegatedRendererLayer::PushPropertiesTo(LayerImpl* impl) {
63   Layer::PushPropertiesTo(impl);
64
65   DelegatedRendererLayerImpl* delegated_impl =
66       static_cast<DelegatedRendererLayerImpl*>(impl);
67
68   delegated_impl->CreateChildIdIfNeeded(
69       frame_provider_->GetReturnResourcesCallbackForImplThread());
70
71   if (frame_data_)
72     delegated_impl->SetFrameData(frame_data_, frame_damage_);
73   frame_data_ = NULL;
74   frame_damage_ = gfx::RectF();
75 }
76
77 void DelegatedRendererLayer::ProviderHasNewFrame() {
78   should_collect_new_frame_ = true;
79   SetNeedsUpdate();
80   // The active frame needs to be replaced and resources returned before the
81   // commit is called complete.
82   SetNextCommitWaitsForActivation();
83 }
84
85 bool DelegatedRendererLayer::Update(ResourceUpdateQueue* queue,
86                                     const OcclusionTracker<Layer>* occlusion) {
87   bool updated = Layer::Update(queue, occlusion);
88   if (!should_collect_new_frame_)
89     return updated;
90
91   frame_data_ =
92       frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
93   should_collect_new_frame_ = false;
94
95   SetNeedsPushProperties();
96   return true;
97 }
98
99 bool DelegatedRendererLayer::HasDelegatedContent() const {
100   return true;
101 }
102
103 }  // namespace cc