1 // Copyright 2013 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/test/fake_layer_tree_host.h"
7 #include "cc/layers/layer.h"
8 #include "cc/test/test_task_graph_runner.h"
11 FakeLayerTreeHost::FakeLayerTreeHost(FakeLayerTreeHostClient
* client
,
12 LayerTreeHost::InitParams
* params
)
13 : LayerTreeHost(params
),
15 host_impl_(*params
->settings
,
18 params
->task_graph_runner
),
19 needs_commit_(false) {
20 client_
->SetLayerTreeHost(this);
23 scoped_ptr
<FakeLayerTreeHost
> FakeLayerTreeHost::Create(
24 FakeLayerTreeHostClient
* client
,
25 TestTaskGraphRunner
* task_graph_runner
) {
26 LayerTreeSettings settings
;
27 settings
.verify_property_trees
= true;
28 return Create(client
, task_graph_runner
, settings
);
31 scoped_ptr
<FakeLayerTreeHost
> FakeLayerTreeHost::Create(
32 FakeLayerTreeHostClient
* client
,
33 TestTaskGraphRunner
* task_graph_runner
,
34 const LayerTreeSettings
& settings
) {
35 LayerTreeHost::InitParams params
;
36 params
.client
= client
;
37 params
.settings
= &settings
;
38 params
.task_graph_runner
= task_graph_runner
;
39 return make_scoped_ptr(new FakeLayerTreeHost(client
, ¶ms
));
42 FakeLayerTreeHost::~FakeLayerTreeHost() {
43 client_
->SetLayerTreeHost(NULL
);
46 void FakeLayerTreeHost::SetNeedsCommit() { needs_commit_
= true; }
48 LayerImpl
* FakeLayerTreeHost::CommitAndCreateLayerImplTree() {
49 scoped_ptr
<LayerImpl
> old_root_layer_impl
= active_tree()->DetachLayerTree();
51 scoped_ptr
<LayerImpl
> layer_impl
= TreeSynchronizer::SynchronizeTrees(
52 root_layer(), old_root_layer_impl
.Pass(), active_tree());
53 active_tree()->SetPropertyTrees(*property_trees());
54 TreeSynchronizer::PushProperties(root_layer(), layer_impl
.get());
56 active_tree()->SetRootLayer(layer_impl
.Pass());
58 if (page_scale_layer() && inner_viewport_scroll_layer()) {
59 active_tree()->SetViewportLayersFromIds(
60 overscroll_elasticity_layer() ? overscroll_elasticity_layer()->id()
62 page_scale_layer()->id(), inner_viewport_scroll_layer()->id(),
63 outer_viewport_scroll_layer() ? outer_viewport_scroll_layer()->id()
67 active_tree()->UpdatePropertyTreesForBoundsDelta();
68 return active_tree()->root_layer();