summaryrefslogtreecommitdiffstats
path: root/chromium/cc/layers/delegated_renderer_layer.cc
blob: c47206172ceedcd205e21525f3d11d3778700d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/layers/delegated_renderer_layer.h"

#include "cc/layers/delegated_renderer_layer_impl.h"
#include "cc/output/delegated_frame_data.h"
#include "cc/quads/render_pass_draw_quad.h"
#include "cc/trees/blocking_task_runner.h"
#include "cc/trees/layer_tree_host.h"

namespace cc {

scoped_refptr<DelegatedRendererLayer> DelegatedRendererLayer::Create(
    const scoped_refptr<DelegatedFrameProvider>& frame_provider) {
  return scoped_refptr<DelegatedRendererLayer>(
      new DelegatedRendererLayer(frame_provider));
}

DelegatedRendererLayer::DelegatedRendererLayer(
    const scoped_refptr<DelegatedFrameProvider>& frame_provider)
    : Layer(),
      frame_provider_(frame_provider),
      should_collect_new_frame_(true),
      frame_data_(NULL),
      main_thread_runner_(BlockingTaskRunner::current()),
      weak_ptrs_(this) {
  frame_provider_->AddObserver(this);
}

DelegatedRendererLayer::~DelegatedRendererLayer() {
  frame_provider_->RemoveObserver(this);
}

scoped_ptr<LayerImpl> DelegatedRendererLayer::CreateLayerImpl(
    LayerTreeImpl* tree_impl) {
  return DelegatedRendererLayerImpl::Create(
      tree_impl, layer_id_).PassAs<LayerImpl>();
}

void DelegatedRendererLayer::SetLayerTreeHost(LayerTreeHost* host) {
  if (layer_tree_host() == host) {
    Layer::SetLayerTreeHost(host);
    return;
  }

  if (!host) {
    // The active frame needs to be removed from the active tree and resources
    // returned before the commit is called complete.
    // TODO(danakj): Don't need to do this if the last frame commited was empty
    // or we never commited a frame with resources.
    SetNextCommitWaitsForActivation();
  } else {
    // There is no active frame in the new layer tree host to wait for so no
    // need to call SetNextCommitWaitsForActivation().
    should_collect_new_frame_ = true;
    SetNeedsUpdate();
  }

  Layer::SetLayerTreeHost(host);
}

void DelegatedRendererLayer::PushPropertiesTo(LayerImpl* impl) {
  Layer::PushPropertiesTo(impl);

  DelegatedRendererLayerImpl* delegated_impl =
      static_cast<DelegatedRendererLayerImpl*>(impl);

  delegated_impl->CreateChildIdIfNeeded(
      frame_provider_->GetReturnResourcesCallbackForImplThread());

  if (frame_data_)
    delegated_impl->SetFrameData(frame_data_, frame_damage_);
  frame_data_ = NULL;
  frame_damage_ = gfx::RectF();
}

void DelegatedRendererLayer::ProviderHasNewFrame() {
  should_collect_new_frame_ = true;
  SetNeedsUpdate();
  // The active frame needs to be replaced and resources returned before the
  // commit is called complete.
  SetNextCommitWaitsForActivation();
}

bool DelegatedRendererLayer::Update(ResourceUpdateQueue* queue,
                                    const OcclusionTracker<Layer>* occlusion) {
  bool updated = Layer::Update(queue, occlusion);
  if (!should_collect_new_frame_)
    return updated;

  frame_data_ =
      frame_provider_->GetFrameDataAndRefResources(this, &frame_damage_);
  should_collect_new_frame_ = false;

  SetNeedsPushProperties();
  return true;
}

}  // namespace cc