summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_layer_tree_host.cc
blob: d323a8e19939713ec3000d3e2caa47756da28bfe (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
// Copyright 2013 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/test/fake_layer_tree_host.h"

#include "cc/layers/layer.h"
#include "cc/test/test_task_graph_runner.h"

namespace cc {
FakeLayerTreeHost::FakeLayerTreeHost(FakeLayerTreeHostClient* client,
                                     LayerTreeHost::InitParams* params)
    : LayerTreeHost(params),
      client_(client),
      host_impl_(*params->settings,
                 &proxy_,
                 &manager_,
                 params->task_graph_runner),
      needs_commit_(false) {
  client_->SetLayerTreeHost(this);
}

scoped_ptr<FakeLayerTreeHost> FakeLayerTreeHost::Create(
    FakeLayerTreeHostClient* client,
    TestTaskGraphRunner* task_graph_runner) {
  LayerTreeSettings settings;
  return Create(client, task_graph_runner, settings);
}

scoped_ptr<FakeLayerTreeHost> FakeLayerTreeHost::Create(
    FakeLayerTreeHostClient* client,
    TestTaskGraphRunner* task_graph_runner,
    const LayerTreeSettings& settings) {
  LayerTreeHost::InitParams params;
  params.client = client;
  params.settings = &settings;
  params.task_graph_runner = task_graph_runner;
  return make_scoped_ptr(new FakeLayerTreeHost(client, &params));
}

FakeLayerTreeHost::~FakeLayerTreeHost() {
  client_->SetLayerTreeHost(NULL);
}

void FakeLayerTreeHost::SetNeedsCommit() { needs_commit_ = true; }

LayerImpl* FakeLayerTreeHost::CommitAndCreateLayerImplTree() {
  scoped_ptr<LayerImpl> old_root_layer_impl = active_tree()->DetachLayerTree();

  scoped_ptr<LayerImpl> layer_impl = TreeSynchronizer::SynchronizeTrees(
      root_layer(), old_root_layer_impl.Pass(), active_tree());
  active_tree()->SetPropertyTrees(*property_trees());
  TreeSynchronizer::PushProperties(root_layer(), layer_impl.get());

  active_tree()->SetRootLayer(layer_impl.Pass());

  if (page_scale_layer() && inner_viewport_scroll_layer()) {
    active_tree()->SetViewportLayersFromIds(
        overscroll_elasticity_layer() ? overscroll_elasticity_layer()->id()
                                      : Layer::INVALID_ID,
        page_scale_layer()->id(), inner_viewport_scroll_layer()->id(),
        outer_viewport_scroll_layer() ? outer_viewport_scroll_layer()->id()
                                      : Layer::INVALID_ID);
  }

  active_tree()->UpdatePropertyTreesForBoundsDelta();
  return active_tree()->root_layer();
}

}  // namespace cc