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_
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"
21 class BeginFrameSource
;
22 class ContextProvider
;
24 class LayerTreeHostSingleThreadClient
;
26 class CC_EXPORT SingleThreadProxy
: public Proxy
,
27 NON_EXPORTED_BASE(LayerTreeHostImplClient
),
30 static scoped_ptr
<Proxy
> Create(
31 LayerTreeHost
* layer_tree_host
,
32 LayerTreeHostSingleThreadClient
* client
,
33 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
34 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
);
35 ~SingleThreadProxy() override
;
37 // Proxy implementation
38 void FinishAllRendering() override
;
39 bool IsStarted() const override
;
40 bool CommitToActiveTree() const override
;
41 void SetOutputSurface(scoped_ptr
<OutputSurface
>) override
;
42 void SetLayerTreeHostClientReady() override
;
43 void SetVisible(bool visible
) override
;
44 void SetThrottleFrameProduction(bool throttle
) override
;
45 const RendererCapabilities
& GetRendererCapabilities() const override
;
46 void SetNeedsAnimate() override
;
47 void SetNeedsUpdateLayers() override
;
48 void SetNeedsCommit() override
;
49 void SetNeedsRedraw(const gfx::Rect
& damage_rect
) override
;
50 void SetNextCommitWaitsForActivation() override
;
51 void NotifyInputThrottledUntilCommit() override
{}
52 void SetDeferCommits(bool defer_commits
) override
;
53 bool CommitRequested() const override
;
54 bool BeginMainFrameRequested() const override
;
55 void MainThreadHasStoppedFlinging() override
{}
56 void Start() override
;
58 void ForceSerializeOnSwapBuffers() override
;
59 bool SupportsImplScrolling() const override
;
60 bool MainFrameWillHappenForTesting() override
;
61 void SetChildrenNeedBeginFrames(bool children_need_begin_frames
) override
;
62 void SetAuthoritativeVSyncInterval(const base::TimeDelta
& interval
) override
;
64 // SchedulerClient implementation
65 void WillBeginImplFrame(const BeginFrameArgs
& args
) override
;
66 void DidFinishImplFrame() override
;
67 void ScheduledActionSendBeginMainFrame() override
;
68 DrawResult
ScheduledActionDrawAndSwapIfPossible() override
;
69 DrawResult
ScheduledActionDrawAndSwapForced() override
;
70 void ScheduledActionCommit() override
;
71 void ScheduledActionAnimate() override
;
72 void ScheduledActionActivateSyncTree() override
;
73 void ScheduledActionBeginOutputSurfaceCreation() override
;
74 void ScheduledActionPrepareTiles() override
;
75 void ScheduledActionInvalidateOutputSurface() override
;
76 void SendBeginFramesToChildren(const BeginFrameArgs
& args
) override
;
77 void SendBeginMainFrameNotExpectedSoon() override
;
79 // LayerTreeHostImplClient implementation
80 void UpdateRendererCapabilitiesOnImplThread() override
;
81 void DidLoseOutputSurfaceOnImplThread() override
;
82 void CommitVSyncParameters(base::TimeTicks timebase
,
83 base::TimeDelta interval
) override
;
84 void SetEstimatedParentDrawTime(base::TimeDelta draw_time
) override
;
85 void SetMaxSwapsPendingOnImplThread(int max
) override
;
86 void DidSwapBuffersOnImplThread() override
;
87 void DidSwapBuffersCompleteOnImplThread() override
;
88 void OnCanDrawStateChanged(bool can_draw
) override
;
89 void NotifyReadyToActivate() override
;
90 void NotifyReadyToDraw() override
;
91 void SetNeedsRedrawOnImplThread() override
;
92 void SetNeedsRedrawRectOnImplThread(const gfx::Rect
& dirty_rect
) override
;
93 void SetNeedsAnimateOnImplThread() override
;
94 void SetNeedsPrepareTilesOnImplThread() override
;
95 void SetNeedsCommitOnImplThread() override
;
96 void SetVideoNeedsBeginFrames(bool needs_begin_frames
) override
;
97 void PostAnimationEventsToMainThreadOnImplThread(
98 scoped_ptr
<AnimationEventsVector
> events
) override
;
99 bool IsInsideDraw() override
;
100 void RenewTreePriority() override
{}
101 void PostDelayedAnimationTaskOnImplThread(const base::Closure
& task
,
102 base::TimeDelta delay
) override
{}
103 void DidActivateSyncTree() override
;
104 void WillPrepareTiles() override
;
105 void DidPrepareTiles() override
;
106 void DidCompletePageScaleAnimationOnImplThread() override
;
107 void OnDrawForOutputSurface() override
;
108 void PostFrameTimingEventsOnImplThread(
109 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> composite_events
,
110 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> main_frame_events
)
113 void SetDebugState(const LayerTreeDebugState
& debug_state
) override
{}
115 void RequestNewOutputSurface();
117 // Called by the legacy path where RenderWidget does the scheduling.
118 void LayoutAndUpdateLayers();
119 void CompositeImmediately(base::TimeTicks frame_begin_time
);
123 LayerTreeHost
* layer_tree_host
,
124 LayerTreeHostSingleThreadClient
* client
,
125 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
126 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
);
129 void BeginMainFrame(const BeginFrameArgs
& begin_frame_args
);
130 void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason
);
132 void DoBeginMainFrame(const BeginFrameArgs
& begin_frame_args
);
134 DrawResult
DoComposite(LayerTreeHostImpl::FrameData
* frame
);
136 void DidCommitAndDrawFrame();
137 void CommitComplete();
139 bool ShouldComposite() const;
140 void ScheduleRequestNewOutputSurface();
142 // Accessed on main thread only.
143 LayerTreeHost
* layer_tree_host_
;
144 LayerTreeHostSingleThreadClient
* client_
;
146 // Used on the Thread, but checked on main thread during
147 // initialization/shutdown.
148 scoped_ptr
<LayerTreeHostImpl
> layer_tree_host_impl_
;
149 RendererCapabilities renderer_capabilities_for_main_thread_
;
151 // Accessed from both threads.
152 scoped_ptr
<BeginFrameSource
> external_begin_frame_source_
;
153 scoped_ptr
<Scheduler
> scheduler_on_impl_thread_
;
155 scoped_ptr
<BlockingTaskRunner::CapturePostTasks
> commit_blocking_task_runner_
;
156 bool next_frame_is_newly_committed_frame_
;
159 bool inside_impl_frame_
;
163 bool animate_requested_
;
164 bool commit_requested_
;
165 bool inside_synchronous_composite_
;
167 // True if a request to the LayerTreeHostClient to create an output surface
168 // is still outstanding.
169 bool output_surface_creation_requested_
;
171 // This is the callback for the scheduled RequestNewOutputSurface.
172 base::CancelableClosure output_surface_creation_callback_
;
174 base::WeakPtrFactory
<SingleThreadProxy
> weak_factory_
;
176 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy
);
179 // For use in the single-threaded case. In debug builds, it pretends that the
180 // code is running on the impl thread to satisfy assertion checks.
181 class DebugScopedSetImplThread
{
183 explicit DebugScopedSetImplThread(Proxy
* proxy
) : proxy_(proxy
) {
185 previous_value_
= proxy_
->impl_thread_is_overridden_
;
186 proxy_
->SetCurrentThreadIsImplThread(true);
189 ~DebugScopedSetImplThread() {
191 proxy_
->SetCurrentThreadIsImplThread(previous_value_
);
196 bool previous_value_
;
199 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread
);
202 // For use in the single-threaded case. In debug builds, it pretends that the
203 // code is running on the main thread to satisfy assertion checks.
204 class DebugScopedSetMainThread
{
206 explicit DebugScopedSetMainThread(Proxy
* proxy
) : proxy_(proxy
) {
208 previous_value_
= proxy_
->impl_thread_is_overridden_
;
209 proxy_
->SetCurrentThreadIsImplThread(false);
212 ~DebugScopedSetMainThread() {
214 proxy_
->SetCurrentThreadIsImplThread(previous_value_
);
219 bool previous_value_
;
222 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread
);
225 // For use in the single-threaded case. In debug builds, it pretends that the
226 // code is running on the impl thread and that the main thread is blocked to
227 // satisfy assertion checks
228 class DebugScopedSetImplThreadAndMainThreadBlocked
{
230 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy
* proxy
)
231 : impl_thread_(proxy
), main_thread_blocked_(proxy
) {}
234 DebugScopedSetImplThread impl_thread_
;
235 DebugScopedSetMainThreadBlocked main_thread_blocked_
;
237 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked
);
242 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_