cc: Make VideoResourceUpdater use CopyToResource instead of SetPixels.
[chromium-blink-merge.git] / cc / layers / delegated_renderer_layer.cc
blobf95c9bd205b1bd9077dfcb7bf4d834ffb8e032f1
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_(nullptr),
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(tree_impl, layer_id_);
39 void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost* host) {
40 if (layer_tree_host() == host) {
41 Layer::SetLayerTreeHost(host);
42 return;
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();
58 Layer::SetLayerTreeHost(host);
61 void DelegatedRendererLayer::PushPropertiesTo(LayerImpl* impl) {
62 Layer::PushPropertiesTo(impl);
64 DelegatedRendererLayerImpl* delegated_impl =
65 static_cast<DelegatedRendererLayerImpl*>(impl);
67 delegated_impl->CreateChildIdIfNeeded(
68 frame_provider_->GetReturnResourcesCallbackForImplThread());
70 if (frame_data_)
71 delegated_impl->SetFrameData(frame_data_, frame_damage_);
72 frame_data_ = nullptr;
73 frame_damage_ = gfx::RectF();
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();
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;
90 frame_data_ =
91 frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
92 should_collect_new_frame_ = false;
94 SetNeedsPushProperties();
95 return true;
98 bool DelegatedRendererLayer::HasDelegatedContent() const {
99 return true;
102 } // namespace cc