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"
18 #include "cc/trees/proxy_timing_history.h"
22 class BeginFrameSource
;
23 class ContextProvider
;
25 class LayerTreeHostSingleThreadClient
;
26 class ResourceUpdateQueue
;
28 class CC_EXPORT SingleThreadProxy
: public Proxy
,
29 NON_EXPORTED_BASE(LayerTreeHostImplClient
),
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
;
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 ScheduledActionSendBeginMainFrame() override
;
70 DrawResult
ScheduledActionDrawAndSwapIfPossible() override
;
71 DrawResult
ScheduledActionDrawAndSwapForced() override
;
72 void ScheduledActionCommit() override
;
73 void ScheduledActionAnimate() override
;
74 void ScheduledActionActivateSyncTree() override
;
75 void ScheduledActionBeginOutputSurfaceCreation() override
;
76 void ScheduledActionPrepareTiles() override
;
77 void ScheduledActionInvalidateOutputSurface() override
;
78 void DidAnticipatedDrawTimeChange(base::TimeTicks time
) override
;
79 base::TimeDelta
DrawDurationEstimate() override
;
80 base::TimeDelta
BeginMainFrameToCommitDurationEstimate() override
;
81 base::TimeDelta
CommitToActivateDurationEstimate() override
;
82 void DidBeginImplFrameDeadline() 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 PostAnimationEventsToMainThreadOnImplThread(
104 scoped_ptr
<AnimationEventsVector
> events
) override
;
105 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes
,
106 int priority_cutoff
) override
;
107 bool IsInsideDraw() override
;
108 void RenewTreePriority() override
{}
109 void PostDelayedAnimationTaskOnImplThread(const base::Closure
& task
,
110 base::TimeDelta delay
) override
{}
111 void DidActivateSyncTree() override
;
112 void DidPrepareTiles() override
;
113 void DidCompletePageScaleAnimationOnImplThread() override
;
114 void OnDrawForOutputSurface() override
;
116 void SetDebugState(const LayerTreeDebugState
& debug_state
) override
{}
118 void RequestNewOutputSurface();
120 // Called by the legacy path where RenderWidget does the scheduling.
121 void CompositeImmediately(base::TimeTicks frame_begin_time
);
125 LayerTreeHost
* layer_tree_host
,
126 LayerTreeHostSingleThreadClient
* client
,
127 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
128 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
);
131 void BeginMainFrame();
132 void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason
);
134 void DoBeginMainFrame(const BeginFrameArgs
& begin_frame_args
);
136 DrawResult
DoComposite(base::TimeTicks frame_begin_time
,
137 LayerTreeHostImpl::FrameData
* frame
);
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_
;
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 scoped_ptr
<BeginFrameSource
> external_begin_frame_source_
;
176 base::WeakPtrFactory
<SingleThreadProxy
> weak_factory_
;
178 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy
);
181 // For use in the single-threaded case. In debug builds, it pretends that the
182 // code is running on the impl thread to satisfy assertion checks.
183 class DebugScopedSetImplThread
{
185 explicit DebugScopedSetImplThread(Proxy
* proxy
) : proxy_(proxy
) {
187 previous_value_
= proxy_
->impl_thread_is_overridden_
;
188 proxy_
->SetCurrentThreadIsImplThread(true);
191 ~DebugScopedSetImplThread() {
193 proxy_
->SetCurrentThreadIsImplThread(previous_value_
);
198 bool previous_value_
;
201 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread
);
204 // For use in the single-threaded case. In debug builds, it pretends that the
205 // code is running on the main thread to satisfy assertion checks.
206 class DebugScopedSetMainThread
{
208 explicit DebugScopedSetMainThread(Proxy
* proxy
) : proxy_(proxy
) {
210 previous_value_
= proxy_
->impl_thread_is_overridden_
;
211 proxy_
->SetCurrentThreadIsImplThread(false);
214 ~DebugScopedSetMainThread() {
216 proxy_
->SetCurrentThreadIsImplThread(previous_value_
);
221 bool previous_value_
;
224 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread
);
227 // For use in the single-threaded case. In debug builds, it pretends that the
228 // code is running on the impl thread and that the main thread is blocked to
229 // satisfy assertion checks
230 class DebugScopedSetImplThreadAndMainThreadBlocked
{
232 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy
* proxy
)
233 : impl_thread_(proxy
), main_thread_blocked_(proxy
) {}
236 DebugScopedSetImplThread impl_thread_
;
237 DebugScopedSetMainThreadBlocked main_thread_blocked_
;
239 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked
);
244 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_