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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cc / test / fake_layer_tree_host.cc [blame]
// Copyright 2013 The Chromium Authors
// 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 <memory>
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.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),
needs_commit_(false) {
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner =
mode == CompositorMode::THREADED
? base::SingleThreadTaskRunner::GetCurrentDefault()
: nullptr;
SetTaskRunnerProviderForTesting(TaskRunnerProvider::Create(
base::SingleThreadTaskRunner::GetCurrentDefault(), impl_task_runner));
client_->SetLayerTreeHost(this);
}
void FakeLayerTreeHost::ClearPendingLayerCommitStates() {
for (auto layer :
pending_commit_state()->layers_that_should_push_properties) {
layer->ClearChangedPushPropertiesForTesting();
}
pending_commit_state()->layers_that_should_push_properties.clear();
}
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; }
std::unique_ptr<LayerTreeHostImpl>
FakeLayerTreeHost::CreateLayerTreeHostImplInternal(
LayerTreeHostImplClient* client,
MutatorHost*,
const LayerTreeSettings& settings,
TaskRunnerProvider* task_runner_provider,
raw_ptr<RasterDarkModeFilter>&,
int,
raw_ptr<TaskGraphRunner>& task_graph_runner,
scoped_refptr<base::SequencedTaskRunner>,
LayerTreeHostSchedulingClient*,
RenderingStatsInstrumentation*,
std::unique_ptr<UkmRecorderFactory>&,
base::WeakPtr<CompositorDelegateForInput>&) {
DCHECK(!host_impl_);
auto host_impl = std::make_unique<FakeLayerTreeHostImpl>(
settings, task_runner_provider, task_graph_runner);
host_impl_ = host_impl.get();
return host_impl;
}
void FakeLayerTreeHost::CreateFakeLayerTreeHostImpl() {
DCHECK(!host_impl_);
owned_host_impl_ = std::make_unique<FakeLayerTreeHostImpl>(
GetSettings(), &task_runner_provider(), task_graph_runner());
host_impl_ = owned_host_impl_.get();
}
LayerImpl* FakeLayerTreeHost::CommitToActiveTree() {
CHECK(host_impl_->CommitsToActiveTree());
CommitToTree(active_tree());
// This is part of LayerTreeHostImpl::CommitComplete(), but unit tests don't
// expect this function to do other things, e.g. animation updates.
active_tree()->HandleScrollbarShowRequests();
return active_tree()->root_layer();
}
LayerImpl* FakeLayerTreeHost::CommitToPendingTree() {
CHECK(!host_impl_->CommitsToActiveTree());
return CommitToTree(pending_tree());
}
LayerImpl* FakeLayerTreeHost::CommitToTree(LayerTreeImpl* tree) {
// pending_commit_state() is used in this function because this is a phony
// commit that doesn't actually call WillCommit() or ActivateCommitState().
tree->set_source_frame_number(SourceFrameNumber());
PropertyTreesChangeState change_state;
property_trees()->GetChangeState(change_state);
std::swap(change_state, pending_commit_state()->property_trees_change_state);
host_impl_->FinishCommit(*pending_commit_state(),
thread_unsafe_commit_state());
std::swap(change_state, pending_commit_state()->property_trees_change_state);
return tree->root_layer();
}
} // namespace cc