Update To 11.40.268.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_(nullptr),
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(tree_impl, layer_id_);
37 }
38
39 void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost* host) {
40   if (layer_tree_host() == host) {
41     Layer::SetLayerTreeHost(host);
42     return;
43   }
44
45   if (!host) {
46     // The active frame needs to be removed from the active tree and resources
47     // returned before the commit is called complete.
48     // TODO(danakj): Don't need to do this if the last frame commited was empty
49     // or we never commited a frame with resources.
50     SetNextCommitWaitsForActivation();
51   } else {
52     // There is no active frame in the new layer tree host to wait for so no
53     // need to call SetNextCommitWaitsForActivation().
54     should_collect_new_frame_ = true;
55     SetNeedsUpdate();
56   }
57
58   Layer::SetLayerTreeHost(host);
59 }
60
61 void DelegatedRendererLayer::PushPropertiesTo(LayerImpl* impl) {
62   Layer::PushPropertiesTo(impl);
63
64   DelegatedRendererLayerImpl* delegated_impl =
65       static_cast<DelegatedRendererLayerImpl*>(impl);
66
67   delegated_impl->CreateChildIdIfNeeded(
68       frame_provider_->GetReturnResourcesCallbackForImplThread());
69
70   if (frame_data_)
71     delegated_impl->SetFrameData(frame_data_, frame_damage_);
72   frame_data_ = nullptr;
73   frame_damage_ = gfx::RectF();
74 }
75
76 void DelegatedRendererLayer::ProviderHasNewFrame() {
77   should_collect_new_frame_ = true;
78   SetNeedsUpdate();
79   // The active frame needs to be replaced and resources returned before the
80   // commit is called complete.
81   SetNextCommitWaitsForActivation();
82 }
83
84 bool DelegatedRendererLayer::Update(ResourceUpdateQueue* queue,
85                                     const OcclusionTracker<Layer>* occlusion) {
86   bool updated = Layer::Update(queue, occlusion);
87   if (!should_collect_new_frame_)
88     return updated;
89
90   frame_data_ =
91       frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
92   should_collect_new_frame_ = false;
93
94   SetNeedsPushProperties();
95   return true;
96 }
97
98 bool DelegatedRendererLayer::HasDelegatedContent() const {
99   return true;
100 }
101
102 }  // namespace cc