Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / trees / single_thread_proxy.h
blob98ac5e5c7d40ae7bae0ea8b9e0740e865f6068eb
1 // Copyright 2011 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 #ifndef CC_TREES_SINGLE_THREAD_PROXY_H_
6 #define CC_TREES_SINGLE_THREAD_PROXY_H_
8 #include <limits>
10 #include "base/cancelable_callback.h"
11 #include "base/time/time.h"
12 #include "cc/animation/animation_events.h"
13 #include "cc/output/begin_frame_args.h"
14 #include "cc/scheduler/scheduler.h"
15 #include "cc/trees/blocking_task_runner.h"
16 #include "cc/trees/layer_tree_host_impl.h"
17 #include "cc/trees/proxy.h"
18 #include "cc/trees/proxy_timing_history.h"
20 namespace cc {
22 class BeginFrameSource;
23 class ContextProvider;
24 class LayerTreeHost;
25 class LayerTreeHostSingleThreadClient;
26 class ResourceUpdateQueue;
28 class CC_EXPORT SingleThreadProxy : public Proxy,
29 NON_EXPORTED_BASE(LayerTreeHostImplClient),
30 SchedulerClient {
31 public:
32 static scoped_ptr<Proxy> Create(
33 LayerTreeHost* layer_tree_host,
34 LayerTreeHostSingleThreadClient* client,
35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
36 scoped_ptr<BeginFrameSource> external_begin_frame_source);
37 ~SingleThreadProxy() override;
39 // Proxy implementation
40 void FinishAllRendering() override;
41 bool IsStarted() const override;
42 bool CommitToActiveTree() const override;
43 void SetOutputSurface(scoped_ptr<OutputSurface>) override;
44 void SetLayerTreeHostClientReady() override;
45 void SetVisible(bool visible) override;
46 void SetThrottleFrameProduction(bool throttle) override;
47 const RendererCapabilities& GetRendererCapabilities() const override;
48 void SetNeedsAnimate() override;
49 void SetNeedsUpdateLayers() override;
50 void SetNeedsCommit() override;
51 void SetNeedsRedraw(const gfx::Rect& damage_rect) override;
52 void SetNextCommitWaitsForActivation() override;
53 void NotifyInputThrottledUntilCommit() override {}
54 void SetDeferCommits(bool defer_commits) override;
55 bool CommitRequested() const override;
56 bool BeginMainFrameRequested() const override;
57 void MainThreadHasStoppedFlinging() override {}
58 void Start() override;
59 void Stop() override;
60 size_t MaxPartialTextureUpdates() const override;
61 void ForceSerializeOnSwapBuffers() override;
62 bool SupportsImplScrolling() const override;
63 bool MainFrameWillHappenForTesting() override;
64 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override;
65 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override;
67 // SchedulerClient implementation
68 void WillBeginImplFrame(const BeginFrameArgs& args) override;
69 void DidFinishImplFrame() override;
70 void ScheduledActionSendBeginMainFrame() override;
71 DrawResult ScheduledActionDrawAndSwapIfPossible() override;
72 DrawResult ScheduledActionDrawAndSwapForced() override;
73 void ScheduledActionCommit() override;
74 void ScheduledActionAnimate() override;
75 void ScheduledActionActivateSyncTree() override;
76 void ScheduledActionBeginOutputSurfaceCreation() override;
77 void ScheduledActionPrepareTiles() override;
78 void ScheduledActionInvalidateOutputSurface() override;
79 void DidAnticipatedDrawTimeChange(base::TimeTicks time) override;
80 base::TimeDelta DrawDurationEstimate() override;
81 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override;
82 base::TimeDelta CommitToActivateDurationEstimate() override;
83 void SendBeginFramesToChildren(const BeginFrameArgs& args) override;
84 void SendBeginMainFrameNotExpectedSoon() override;
86 // LayerTreeHostImplClient implementation
87 void UpdateRendererCapabilitiesOnImplThread() override;
88 void DidLoseOutputSurfaceOnImplThread() override;
89 void CommitVSyncParameters(base::TimeTicks timebase,
90 base::TimeDelta interval) override;
91 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override;
92 void SetMaxSwapsPendingOnImplThread(int max) override;
93 void DidSwapBuffersOnImplThread() override;
94 void DidSwapBuffersCompleteOnImplThread() override;
95 void OnCanDrawStateChanged(bool can_draw) override;
96 void NotifyReadyToActivate() override;
97 void NotifyReadyToDraw() override;
98 void SetNeedsRedrawOnImplThread() override;
99 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override;
100 void SetNeedsAnimateOnImplThread() override;
101 void SetNeedsPrepareTilesOnImplThread() override;
102 void SetNeedsCommitOnImplThread() override;
103 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override;
104 void PostAnimationEventsToMainThreadOnImplThread(
105 scoped_ptr<AnimationEventsVector> events) override;
106 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes,
107 int priority_cutoff) override;
108 bool IsInsideDraw() override;
109 void RenewTreePriority() override {}
110 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task,
111 base::TimeDelta delay) override {}
112 void DidActivateSyncTree() override;
113 void DidPrepareTiles() override;
114 void DidCompletePageScaleAnimationOnImplThread() override;
115 void OnDrawForOutputSurface() override;
117 void SetDebugState(const LayerTreeDebugState& debug_state) override {}
119 void RequestNewOutputSurface();
121 // Called by the legacy path where RenderWidget does the scheduling.
122 void CompositeImmediately(base::TimeTicks frame_begin_time);
124 protected:
125 SingleThreadProxy(
126 LayerTreeHost* layer_tree_host,
127 LayerTreeHostSingleThreadClient* client,
128 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
129 scoped_ptr<BeginFrameSource> external_begin_frame_source);
131 private:
132 void BeginMainFrame(const BeginFrameArgs& begin_frame_args);
133 void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason);
134 void DoAnimate();
135 void DoBeginMainFrame(const BeginFrameArgs& begin_frame_args);
136 void DoCommit();
137 DrawResult DoComposite(LayerTreeHostImpl::FrameData* frame);
138 void DoSwap();
139 void DidCommitAndDrawFrame();
140 void CommitComplete();
142 bool ShouldComposite() const;
143 void ScheduleRequestNewOutputSurface();
145 // Accessed on main thread only.
146 LayerTreeHost* layer_tree_host_;
147 LayerTreeHostSingleThreadClient* client_;
149 // Used on the Thread, but checked on main thread during
150 // initialization/shutdown.
151 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
152 RendererCapabilities renderer_capabilities_for_main_thread_;
154 // Accessed from both threads.
155 scoped_ptr<Scheduler> scheduler_on_impl_thread_;
156 ProxyTimingHistory timing_history_;
158 scoped_ptr<BlockingTaskRunner::CapturePostTasks> commit_blocking_task_runner_;
159 scoped_ptr<ResourceUpdateQueue> queue_for_commit_;
160 bool next_frame_is_newly_committed_frame_;
162 #if DCHECK_IS_ON()
163 bool inside_impl_frame_;
164 #endif
165 bool inside_draw_;
166 bool defer_commits_;
167 bool animate_requested_;
168 bool commit_requested_;
169 bool inside_synchronous_composite_;
171 // True if a request to the LayerTreeHostClient to create an output surface
172 // is still outstanding.
173 bool output_surface_creation_requested_;
175 // This is the callback for the scheduled RequestNewOutputSurface.
176 base::CancelableClosure output_surface_creation_callback_;
178 base::WeakPtrFactory<SingleThreadProxy> weak_factory_;
180 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
183 // For use in the single-threaded case. In debug builds, it pretends that the
184 // code is running on the impl thread to satisfy assertion checks.
185 class DebugScopedSetImplThread {
186 public:
187 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
188 #if DCHECK_IS_ON()
189 previous_value_ = proxy_->impl_thread_is_overridden_;
190 proxy_->SetCurrentThreadIsImplThread(true);
191 #endif
193 ~DebugScopedSetImplThread() {
194 #if DCHECK_IS_ON()
195 proxy_->SetCurrentThreadIsImplThread(previous_value_);
196 #endif
199 private:
200 bool previous_value_;
201 Proxy* proxy_;
203 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
206 // For use in the single-threaded case. In debug builds, it pretends that the
207 // code is running on the main thread to satisfy assertion checks.
208 class DebugScopedSetMainThread {
209 public:
210 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
211 #if DCHECK_IS_ON()
212 previous_value_ = proxy_->impl_thread_is_overridden_;
213 proxy_->SetCurrentThreadIsImplThread(false);
214 #endif
216 ~DebugScopedSetMainThread() {
217 #if DCHECK_IS_ON()
218 proxy_->SetCurrentThreadIsImplThread(previous_value_);
219 #endif
222 private:
223 bool previous_value_;
224 Proxy* proxy_;
226 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
229 // For use in the single-threaded case. In debug builds, it pretends that the
230 // code is running on the impl thread and that the main thread is blocked to
231 // satisfy assertion checks
232 class DebugScopedSetImplThreadAndMainThreadBlocked {
233 public:
234 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
235 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
237 private:
238 DebugScopedSetImplThread impl_thread_;
239 DebugScopedSetMainThreadBlocked main_thread_blocked_;
241 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
244 } // namespace cc
246 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_