Add ICU message format support
[chromium-blink-merge.git] / cc / trees / thread_proxy.h
blobca76e42669b1cbfbd1f3e19dda3a2bbced27aa7a
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_THREAD_PROXY_H_
6 #define CC_TREES_THREAD_PROXY_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13 #include "cc/animation/animation_events.h"
14 #include "cc/base/completion_event.h"
15 #include "cc/base/delayed_unique_notifier.h"
16 #include "cc/scheduler/commit_earlyout_reason.h"
17 #include "cc/scheduler/scheduler.h"
18 #include "cc/trees/layer_tree_host_impl.h"
19 #include "cc/trees/proxy.h"
21 namespace base {
22 class SingleThreadTaskRunner;
25 namespace cc {
27 class BeginFrameSource;
28 class ContextProvider;
29 class InputHandlerClient;
30 class LayerTreeHost;
31 class Scheduler;
32 class ScopedThreadProxy;
34 class CC_EXPORT ThreadProxy : public Proxy,
35 NON_EXPORTED_BASE(LayerTreeHostImplClient),
36 NON_EXPORTED_BASE(SchedulerClient) {
37 public:
38 static scoped_ptr<Proxy> Create(
39 LayerTreeHost* layer_tree_host,
40 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
41 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
42 scoped_ptr<BeginFrameSource> external_begin_frame_source);
44 ~ThreadProxy() override;
46 struct BeginMainFrameAndCommitState {
47 BeginMainFrameAndCommitState();
48 ~BeginMainFrameAndCommitState();
50 unsigned int begin_frame_id;
51 BeginFrameArgs begin_frame_args;
52 scoped_ptr<ScrollAndScaleSet> scroll_info;
53 size_t memory_allocation_limit_bytes;
54 bool evicted_ui_resources;
57 struct MainThreadOnly {
58 MainThreadOnly(ThreadProxy* proxy, int layer_tree_host_id);
59 ~MainThreadOnly();
61 const int layer_tree_host_id;
63 // Set only when SetNeedsAnimate is called.
64 bool animate_requested;
65 // Set only when SetNeedsCommit is called.
66 bool commit_requested;
67 // Set by SetNeedsAnimate, SetNeedsUpdateLayers, and SetNeedsCommit.
68 bool commit_request_sent_to_impl_thread;
70 bool started;
71 bool prepare_tiles_pending;
72 bool can_cancel_commit;
73 bool defer_commits;
75 RendererCapabilities renderer_capabilities_main_thread_copy;
77 base::WeakPtrFactory<ThreadProxy> weak_factory;
80 // Accessed on the main thread, or when main thread is blocked.
81 struct MainThreadOrBlockedMainThread {
82 explicit MainThreadOrBlockedMainThread(LayerTreeHost* host);
83 ~MainThreadOrBlockedMainThread();
85 LayerTreeHost* layer_tree_host;
86 bool commit_waits_for_activation;
87 bool main_thread_inside_commit;
90 struct CompositorThreadOnly {
91 CompositorThreadOnly(
92 ThreadProxy* proxy,
93 int layer_tree_host_id,
94 RenderingStatsInstrumentation* rendering_stats_instrumentation,
95 scoped_ptr<BeginFrameSource> external_begin_frame_source);
96 ~CompositorThreadOnly();
98 const int layer_tree_host_id;
100 scoped_ptr<Scheduler> scheduler;
102 // Set when the main thread is waiting on a
103 // ScheduledActionSendBeginMainFrame to be issued.
104 CompletionEvent* begin_main_frame_sent_completion_event;
106 // Set when the main thread is waiting on a commit to complete.
107 CompletionEvent* commit_completion_event;
109 // Set when the main thread is waiting on a pending tree activation.
110 CompletionEvent* completion_event_for_commit_held_on_tree_activation;
112 // Set when the next draw should post DidCommitAndDrawFrame to the main
113 // thread.
114 bool next_frame_is_newly_committed_frame;
116 bool inside_draw;
118 bool input_throttled_until_commit;
120 base::TimeTicks animation_time;
122 // Whether a commit has been completed since the last time animations were
123 // ticked. If this happens, we need to animate again.
124 bool did_commit_after_animating;
126 DelayedUniqueNotifier smoothness_priority_expiration_notifier;
128 scoped_ptr<BeginFrameSource> external_begin_frame_source;
130 RenderingStatsInstrumentation* rendering_stats_instrumentation;
132 // Values used to keep track of frame durations. Used only in frame timing.
133 BeginFrameArgs last_begin_main_frame_args;
134 BeginFrameArgs last_processed_begin_main_frame_args;
136 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl;
137 base::WeakPtrFactory<ThreadProxy> weak_factory;
140 const MainThreadOnly& main() const;
141 const MainThreadOrBlockedMainThread& blocked_main() const;
142 const CompositorThreadOnly& impl() const;
144 // Proxy implementation
145 void FinishAllRendering() override;
146 bool IsStarted() const override;
147 bool CommitToActiveTree() const override;
148 void SetOutputSurface(scoped_ptr<OutputSurface>) override;
149 void SetLayerTreeHostClientReady() override;
150 void SetVisible(bool visible) override;
151 void SetThrottleFrameProduction(bool throttle) override;
152 const RendererCapabilities& GetRendererCapabilities() const override;
153 void SetNeedsAnimate() override;
154 void SetNeedsUpdateLayers() override;
155 void SetNeedsCommit() override;
156 void SetNeedsRedraw(const gfx::Rect& damage_rect) override;
157 void SetNextCommitWaitsForActivation() override;
158 void NotifyInputThrottledUntilCommit() override;
159 void SetDeferCommits(bool defer_commits) override;
160 bool CommitRequested() const override;
161 bool BeginMainFrameRequested() const override;
162 void MainThreadHasStoppedFlinging() override;
163 void Start() override;
164 void Stop() override;
165 void ForceSerializeOnSwapBuffers() override;
166 bool SupportsImplScrolling() const override;
167 void SetDebugState(const LayerTreeDebugState& debug_state) override;
168 bool MainFrameWillHappenForTesting() override;
169 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override;
170 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override;
172 // LayerTreeHostImplClient implementation
173 void UpdateRendererCapabilitiesOnImplThread() override;
174 void DidLoseOutputSurfaceOnImplThread() override;
175 void CommitVSyncParameters(base::TimeTicks timebase,
176 base::TimeDelta interval) override;
177 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override;
178 void SetMaxSwapsPendingOnImplThread(int max) override;
179 void DidSwapBuffersOnImplThread() override;
180 void DidSwapBuffersCompleteOnImplThread() override;
181 void OnCanDrawStateChanged(bool can_draw) override;
182 void NotifyReadyToActivate() override;
183 void NotifyReadyToDraw() override;
184 // Please call these 3 functions through
185 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and
186 // SetNeedsAnimate().
187 void SetNeedsRedrawOnImplThread() override;
188 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override;
189 void SetNeedsAnimateOnImplThread() override;
190 void SetNeedsPrepareTilesOnImplThread() override;
191 void SetNeedsCommitOnImplThread() override;
192 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override;
193 void PostAnimationEventsToMainThreadOnImplThread(
194 scoped_ptr<AnimationEventsVector> queue) override;
195 bool IsInsideDraw() override;
196 void RenewTreePriority() override;
197 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task,
198 base::TimeDelta delay) override;
199 void DidActivateSyncTree() override;
200 void WillPrepareTiles() override;
201 void DidPrepareTiles() override;
202 void DidCompletePageScaleAnimationOnImplThread() override;
203 void OnDrawForOutputSurface() override;
204 // This should only be called by LayerTreeHostImpl::PostFrameTimingEvents.
205 void PostFrameTimingEventsOnImplThread(
206 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
207 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
208 override;
210 // SchedulerClient implementation
211 void WillBeginImplFrame(const BeginFrameArgs& args) override;
212 void DidFinishImplFrame() override;
213 void ScheduledActionSendBeginMainFrame() override;
214 DrawResult ScheduledActionDrawAndSwapIfPossible() override;
215 DrawResult ScheduledActionDrawAndSwapForced() override;
216 void ScheduledActionAnimate() override;
217 void ScheduledActionCommit() override;
218 void ScheduledActionActivateSyncTree() override;
219 void ScheduledActionBeginOutputSurfaceCreation() override;
220 void ScheduledActionPrepareTiles() override;
221 void ScheduledActionInvalidateOutputSurface() override;
222 void SendBeginFramesToChildren(const BeginFrameArgs& args) override;
223 void SendBeginMainFrameNotExpectedSoon() override;
225 protected:
226 ThreadProxy(
227 LayerTreeHost* layer_tree_host,
228 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
229 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
230 scoped_ptr<BeginFrameSource> external_begin_frame_source);
232 private:
233 // Called on main thread.
234 void SetRendererCapabilitiesMainThreadCopy(
235 const RendererCapabilities& capabilities);
236 void BeginMainFrame(
237 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state);
238 void BeginMainFrameNotExpectedSoon();
239 void DidCommitAndDrawFrame();
240 void DidCompleteSwapBuffers();
241 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue);
242 void DidLoseOutputSurface();
243 void RequestNewOutputSurface();
244 void DidInitializeOutputSurface(bool success,
245 const RendererCapabilities& capabilities);
246 void SendCommitRequestToImplThreadIfNeeded();
247 void DidCompletePageScaleAnimation();
249 // Called on impl thread.
250 struct SchedulerStateRequest;
252 void StartCommitOnImplThread(CompletionEvent* completion);
253 void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason);
254 void FinishAllRenderingOnImplThread(CompletionEvent* completion);
255 void InitializeImplOnImplThread(CompletionEvent* completion);
256 void SetLayerTreeHostClientReadyOnImplThread();
257 void SetVisibleOnImplThread(CompletionEvent* completion, bool visible);
258 void SetThrottleFrameProductionOnImplThread(bool throttle);
259 void HasInitializedOutputSurfaceOnImplThread(
260 CompletionEvent* completion,
261 bool* has_initialized_output_surface);
262 void DeleteContentsTexturesOnImplThread(CompletionEvent* completion);
263 void InitializeOutputSurfaceOnImplThread(
264 scoped_ptr<OutputSurface> output_surface);
265 void FinishGLOnImplThread(CompletionEvent* completion);
266 void LayerTreeHostClosedOnImplThread(CompletionEvent* completion);
267 DrawResult DrawSwapInternal(bool forced_draw);
268 void ForceSerializeOnSwapBuffersOnImplThread(CompletionEvent* completion);
269 void MainFrameWillHappenOnImplThreadForTesting(CompletionEvent* completion,
270 bool* main_frame_will_happen);
271 void SetSwapUsedIncompleteTileOnImplThread(bool used_incomplete_tile);
272 void MainThreadHasStoppedFlingingOnImplThread();
273 void SetInputThrottledUntilCommitOnImplThread(bool is_throttled);
274 void SetDebugStateOnImplThread(const LayerTreeDebugState& debug_state);
275 void SetDeferCommitsOnImplThread(bool defer_commits) const;
276 void PostFrameTimingEvents(
277 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
278 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events);
280 LayerTreeHost* layer_tree_host();
281 const LayerTreeHost* layer_tree_host() const;
283 // Use accessors instead of this variable directly.
284 MainThreadOnly main_thread_only_vars_unsafe_;
285 MainThreadOnly& main();
287 // Use accessors instead of this variable directly.
288 MainThreadOrBlockedMainThread main_thread_or_blocked_vars_unsafe_;
289 MainThreadOrBlockedMainThread& blocked_main();
291 // Use accessors instead of this variable directly.
292 CompositorThreadOnly compositor_thread_vars_unsafe_;
293 CompositorThreadOnly& impl();
295 base::WeakPtr<ThreadProxy> main_thread_weak_ptr_;
296 base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_;
298 DISALLOW_COPY_AND_ASSIGN(ThreadProxy);
301 } // namespace cc
303 #endif // CC_TREES_THREAD_PROXY_H_