[GCM] Investigatory CHECKs for crash in parsing stream
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer.cc
blob6ccdbec6b7761afdf4c811bf331a053a99cab64c
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/layer_tree_host.h"
12 namespace cc {
14 scoped_refptr<DelegatedRendererLayer> DelegatedRendererLayer::Create(
15 const scoped_refptr<DelegatedFrameProvider>& frame_provider) {
16 return scoped_refptr<DelegatedRendererLayer>(
17 new DelegatedRendererLayer(frame_provider));
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);
30 DelegatedRendererLayer::~DelegatedRendererLayer() {
31 frame_provider_->RemoveObserver(this);
34 scoped_ptr<LayerImpl> DelegatedRendererLayer::CreateLayerImpl(
35 LayerTreeImpl* tree_impl) {
36 return DelegatedRendererLayerImpl::Create(
37 tree_impl, layer_id_).PassAs<LayerImpl>();
40 void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost* host) {
41 if (layer_tree_host() == host) {
42 Layer::SetLayerTreeHost(host);
43 return;
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();
59 Layer::SetLayerTreeHost(host);
62 void DelegatedRendererLayer::PushPropertiesTo(LayerImpl* impl) {
63 Layer::PushPropertiesTo(impl);
65 DelegatedRendererLayerImpl* delegated_impl =
66 static_cast<DelegatedRendererLayerImpl*>(impl);
68 delegated_impl->CreateChildIdIfNeeded(
69 frame_provider_->GetReturnResourcesCallbackForImplThread());
71 if (frame_data_)
72 delegated_impl->SetFrameData(frame_data_, frame_damage_);
73 frame_data_ = NULL;
74 frame_damage_ = gfx::RectF();
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();
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;
91 frame_data_ =
92 frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
93 should_collect_new_frame_ = false;
95 SetNeedsPushProperties();
96 return true;
99 bool DelegatedRendererLayer::HasDelegatedContent() const {
100 return true;
103 } // namespace cc