forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_layer_tree_host.cc
111 lines (95 loc) · 4.34 KB
/
fake_layer_tree_host.cc
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
102
103
104
105
106
107
108
109
110
111
// 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 "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "cc/animation/animation_host.h"
#include "cc/layers/layer.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/mutator_host.h"
namespace cc {
FakeLayerTreeHost::FakeLayerTreeHost(FakeLayerTreeHostClient* client,
LayerTreeHost::InitParams params,
CompositorMode mode)
: LayerTreeHost(std::move(params), mode),
client_(client),
host_impl_(GetSettings(), &task_runner_provider_, task_graph_runner()),
needs_commit_(false) {
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner =
mode == CompositorMode::THREADED ? base::ThreadTaskRunnerHandle::Get()
: nullptr;
SetTaskRunnerProviderForTesting(TaskRunnerProvider::Create(
base::ThreadTaskRunnerHandle::Get(), impl_task_runner));
client_->SetLayerTreeHost(this);
}
std::unique_ptr<FakeLayerTreeHost> FakeLayerTreeHost::Create(
FakeLayerTreeHostClient* client,
TestTaskGraphRunner* task_graph_runner,
MutatorHost* mutator_host) {
LayerTreeSettings settings;
return Create(client, task_graph_runner, mutator_host, settings);
}
std::unique_ptr<FakeLayerTreeHost> FakeLayerTreeHost::Create(
FakeLayerTreeHostClient* client,
TestTaskGraphRunner* task_graph_runner,
MutatorHost* mutator_host,
const LayerTreeSettings& settings) {
return Create(client, task_graph_runner, mutator_host, settings,
CompositorMode::SINGLE_THREADED);
}
std::unique_ptr<FakeLayerTreeHost> FakeLayerTreeHost::Create(
FakeLayerTreeHostClient* client,
TestTaskGraphRunner* task_graph_runner,
MutatorHost* mutator_host,
const LayerTreeSettings& settings,
CompositorMode mode) {
LayerTreeHost::InitParams params;
params.client = client;
params.settings = &settings;
params.task_graph_runner = task_graph_runner;
params.mutator_host = mutator_host;
return base::WrapUnique(
new FakeLayerTreeHost(client, std::move(params), mode));
}
FakeLayerTreeHost::~FakeLayerTreeHost() {
client_->SetLayerTreeHost(nullptr);
}
void FakeLayerTreeHost::SetNeedsCommit() { needs_commit_ = true; }
LayerImpl* FakeLayerTreeHost::CommitAndCreateLayerImplTree() {
// TODO(pdr): Update the LayerTreeImpl lifecycle states here so lifecycle
// violations can be caught.
TreeSynchronizer::SynchronizeTrees(root_layer(), active_tree());
active_tree()->SetPropertyTrees(property_trees());
TreeSynchronizer::PushLayerProperties(root_layer()->layer_tree_host(),
active_tree());
mutator_host()->PushPropertiesTo(host_impl_.mutator_host());
active_tree()->property_trees()->scroll_tree.PushScrollUpdatesFromMainThread(
property_trees(), active_tree());
if (page_scale_layer() && inner_viewport_scroll_layer()) {
LayerTreeImpl::ViewportLayerIds ids;
ids.overscroll_elasticity_element_id = overscroll_elasticity_element_id();
ids.page_scale = page_scale_layer()->id();
if (inner_viewport_container_layer())
ids.inner_viewport_container = inner_viewport_container_layer()->id();
if (outer_viewport_container_layer())
ids.outer_viewport_container = outer_viewport_container_layer()->id();
ids.inner_viewport_scroll = inner_viewport_scroll_layer()->id();
if (outer_viewport_scroll_layer())
ids.outer_viewport_scroll = outer_viewport_scroll_layer()->id();
active_tree()->SetViewportLayersFromIds(ids);
}
return active_tree()->root_layer_for_testing();
}
LayerImpl* FakeLayerTreeHost::CommitAndCreatePendingTree() {
TreeSynchronizer::SynchronizeTrees(root_layer(), pending_tree());
pending_tree()->SetPropertyTrees(property_trees());
TreeSynchronizer::PushLayerProperties(root_layer()->layer_tree_host(),
pending_tree());
mutator_host()->PushPropertiesTo(host_impl_.mutator_host());
pending_tree()->property_trees()->scroll_tree.PushScrollUpdatesFromMainThread(
property_trees(), pending_tree());
return pending_tree()->root_layer_for_testing();
}
} // namespace cc