forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_thread_proxy.h
242 lines (205 loc) · 8.53 KB
/
single_thread_proxy.h
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2011 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.
#ifndef CC_TREES_SINGLE_THREAD_PROXY_H_
#define CC_TREES_SINGLE_THREAD_PROXY_H_
#include <limits>
#include "base/cancelable_callback.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "cc/output/begin_frame_args.h"
#include "cc/scheduler/scheduler.h"
#include "cc/trees/blocking_task_runner.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/proxy.h"
#include "cc/trees/task_runner_provider.h"
namespace cc {
class MutatorEvents;
class BeginFrameSource;
class ContextProvider;
class LayerTreeHostInProcess;
class LayerTreeHostSingleThreadClient;
class CC_EXPORT SingleThreadProxy : public Proxy,
NON_EXPORTED_BASE(LayerTreeHostImplClient),
public SchedulerClient {
public:
static std::unique_ptr<Proxy> Create(
LayerTreeHostInProcess* layer_tree_host,
LayerTreeHostSingleThreadClient* client,
TaskRunnerProvider* task_runner_provider_);
~SingleThreadProxy() override;
// Proxy implementation
bool IsStarted() const override;
bool CommitToActiveTree() const override;
void SetCompositorFrameSink(
CompositorFrameSink* compositor_frame_sink) override;
void ReleaseCompositorFrameSink() override;
void SetVisible(bool visible) override;
void SetNeedsAnimate() override;
void SetNeedsUpdateLayers() override;
void SetNeedsCommit() override;
void SetNeedsRedraw(const gfx::Rect& damage_rect) override;
void SetNextCommitWaitsForActivation() override;
void NotifyInputThrottledUntilCommit() override {}
void SetDeferCommits(bool defer_commits) override;
bool CommitRequested() const override;
bool BeginMainFrameRequested() const override;
void MainThreadHasStoppedFlinging() override {}
void Start() override;
void Stop() override;
void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override;
bool SupportsImplScrolling() const override;
bool MainFrameWillHappenForTesting() override;
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
bool animate) override;
// SchedulerClient implementation
void WillBeginImplFrame(const BeginFrameArgs& args) override;
void DidFinishImplFrame() override;
void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override;
DrawResult ScheduledActionDrawIfPossible() override;
DrawResult ScheduledActionDrawForced() override;
void ScheduledActionCommit() override;
void ScheduledActionActivateSyncTree() override;
void ScheduledActionBeginCompositorFrameSinkCreation() override;
void ScheduledActionPrepareTiles() override;
void ScheduledActionInvalidateCompositorFrameSink() override;
void SendBeginMainFrameNotExpectedSoon() override;
// LayerTreeHostImplClient implementation
void DidLoseCompositorFrameSinkOnImplThread() override;
void SetBeginFrameSource(BeginFrameSource* source) override;
void DidReceiveCompositorFrameAckOnImplThread() override;
void OnCanDrawStateChanged(bool can_draw) override;
void NotifyReadyToActivate() override;
void NotifyReadyToDraw() override;
void SetNeedsRedrawOnImplThread() override;
void SetNeedsOneBeginImplFrameOnImplThread() override;
void SetNeedsPrepareTilesOnImplThread() override;
void SetNeedsCommitOnImplThread() override;
void SetVideoNeedsBeginFrames(bool needs_begin_frames) override;
void PostAnimationEventsToMainThreadOnImplThread(
std::unique_ptr<MutatorEvents> events) override;
bool IsInsideDraw() override;
void RenewTreePriority() override {}
void PostDelayedAnimationTaskOnImplThread(const base::Closure& task,
base::TimeDelta delay) override {}
void DidActivateSyncTree() override;
void WillPrepareTiles() override;
void DidPrepareTiles() override;
void DidCompletePageScaleAnimationOnImplThread() override;
void OnDrawForCompositorFrameSink(bool resourceless_software_draw) override;
void RequestNewCompositorFrameSink();
// Called by the legacy path where RenderWidget does the scheduling.
void CompositeImmediately(base::TimeTicks frame_begin_time);
protected:
SingleThreadProxy(LayerTreeHostInProcess* layer_tree_host,
LayerTreeHostSingleThreadClient* client,
TaskRunnerProvider* task_runner_provider);
private:
void BeginMainFrame(const BeginFrameArgs& begin_frame_args);
void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason);
void DoBeginMainFrame(const BeginFrameArgs& begin_frame_args);
void DoCommit();
DrawResult DoComposite(LayerTreeHostImpl::FrameData* frame);
void DoSwap();
void DidCommitAndDrawFrame();
void CommitComplete();
bool ShouldComposite() const;
void ScheduleRequestNewCompositorFrameSink();
// Accessed on main thread only.
LayerTreeHostInProcess* layer_tree_host_;
LayerTreeHostSingleThreadClient* single_thread_client_;
TaskRunnerProvider* task_runner_provider_;
// Used on the Thread, but checked on main thread during
// initialization/shutdown.
std::unique_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
// Accessed from both threads.
std::unique_ptr<Scheduler> scheduler_on_impl_thread_;
std::unique_ptr<BlockingTaskRunner::CapturePostTasks>
commit_blocking_task_runner_;
bool next_frame_is_newly_committed_frame_;
#if DCHECK_IS_ON()
bool inside_impl_frame_;
#endif
bool inside_draw_;
bool defer_commits_;
bool animate_requested_;
bool commit_requested_;
bool inside_synchronous_composite_;
// True if a request to the LayerTreeHostClient to create an output surface
// is still outstanding.
bool compositor_frame_sink_creation_requested_;
// When output surface is lost, is set to true until a new output surface is
// initialized.
bool compositor_frame_sink_lost_;
// This is the callback for the scheduled RequestNewCompositorFrameSink.
base::CancelableClosure compositor_frame_sink_creation_callback_;
base::WeakPtrFactory<SingleThreadProxy> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
};
// For use in the single-threaded case. In debug builds, it pretends that the
// code is running on the impl thread to satisfy assertion checks.
class DebugScopedSetImplThread {
public:
#if DCHECK_IS_ON()
explicit DebugScopedSetImplThread(TaskRunnerProvider* task_runner_provider)
: task_runner_provider_(task_runner_provider) {
previous_value_ = task_runner_provider_->impl_thread_is_overridden_;
task_runner_provider_->SetCurrentThreadIsImplThread(true);
}
#else
explicit DebugScopedSetImplThread(TaskRunnerProvider* task_runner_provider) {}
#endif
~DebugScopedSetImplThread() {
#if DCHECK_IS_ON()
task_runner_provider_->SetCurrentThreadIsImplThread(previous_value_);
#endif
}
private:
#if DCHECK_IS_ON()
bool previous_value_;
TaskRunnerProvider* task_runner_provider_;
#endif
DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
};
// For use in the single-threaded case. In debug builds, it pretends that the
// code is running on the main thread to satisfy assertion checks.
class DebugScopedSetMainThread {
public:
#if DCHECK_IS_ON()
explicit DebugScopedSetMainThread(TaskRunnerProvider* task_runner_provider)
: task_runner_provider_(task_runner_provider) {
previous_value_ = task_runner_provider_->impl_thread_is_overridden_;
task_runner_provider_->SetCurrentThreadIsImplThread(false);
}
#else
explicit DebugScopedSetMainThread(TaskRunnerProvider* task_runner_provider) {}
#endif
~DebugScopedSetMainThread() {
#if DCHECK_IS_ON()
task_runner_provider_->SetCurrentThreadIsImplThread(previous_value_);
#endif
}
private:
#if DCHECK_IS_ON()
bool previous_value_;
TaskRunnerProvider* task_runner_provider_;
#endif
DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
};
// For use in the single-threaded case. In debug builds, it pretends that the
// code is running on the impl thread and that the main thread is blocked to
// satisfy assertion checks
class DebugScopedSetImplThreadAndMainThreadBlocked {
public:
explicit DebugScopedSetImplThreadAndMainThreadBlocked(
TaskRunnerProvider* task_runner_provider)
: impl_thread_(task_runner_provider),
main_thread_blocked_(task_runner_provider) {}
private:
DebugScopedSetImplThread impl_thread_;
DebugScopedSetMainThreadBlocked main_thread_blocked_;
DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
};
} // namespace cc
#endif // CC_TREES_SINGLE_THREAD_PROXY_H_