OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_TREES_THREAD_PROXY_H_ | 5 #ifndef CC_TREES_THREAD_PROXY_H_ |
6 #define CC_TREES_THREAD_PROXY_H_ | 6 #define CC_TREES_THREAD_PROXY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 namespace cc { | 25 namespace cc { |
26 | 26 |
27 class ContextProvider; | 27 class ContextProvider; |
28 class InputHandlerClient; | 28 class InputHandlerClient; |
29 class LayerTreeHost; | 29 class LayerTreeHost; |
30 class ResourceUpdateQueue; | 30 class ResourceUpdateQueue; |
31 class Scheduler; | 31 class Scheduler; |
32 class ScopedThreadProxy; | 32 class ScopedThreadProxy; |
33 | 33 |
34 class ThreadProxy : public Proxy, | 34 class CC_EXPORT ThreadProxy : public Proxy, |
35 LayerTreeHostImplClient, | 35 LayerTreeHostImplClient, |
36 SchedulerClient, | 36 SchedulerClient, |
37 ResourceUpdateControllerClient { | 37 ResourceUpdateControllerClient { |
38 public: | 38 public: |
39 static scoped_ptr<Proxy> Create( | 39 static scoped_ptr<Proxy> Create( |
40 LayerTreeHost* layer_tree_host, | 40 LayerTreeHost* layer_tree_host, |
41 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); | 41 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); |
42 | 42 |
43 virtual ~ThreadProxy(); | 43 virtual ~ThreadProxy(); |
44 | 44 |
45 struct BeginMainFrameAndCommitState { | |
46 BeginMainFrameAndCommitState(); | |
47 ~BeginMainFrameAndCommitState(); | |
48 | |
49 base::TimeTicks monotonic_frame_begin_time; | |
50 scoped_ptr<ScrollAndScaleSet> scroll_info; | |
51 size_t memory_allocation_limit_bytes; | |
52 int memory_allocation_priority_cutoff; | |
53 bool evicted_ui_resources; | |
54 }; | |
55 | |
56 struct MainThreadOnly { | |
57 MainThreadOnly(ThreadProxy* proxy, int layer_tree_host_id); | |
58 ~MainThreadOnly(); | |
59 | |
60 const int layer_tree_host_id; | |
61 | |
62 // Set only when SetNeedsAnimate is called. | |
63 bool animate_requested; | |
64 // Set only when SetNeedsCommit is called. | |
65 bool commit_requested; | |
66 // Set by SetNeedsAnimate, SetNeedsUpdateLayers, and SetNeedsCommit. | |
67 bool commit_request_sent_to_impl_thread; | |
68 | |
69 bool started; | |
70 bool in_composite_and_readback; | |
71 bool manage_tiles_pending; | |
72 bool can_cancel_commit; | |
73 bool defer_commits; | |
74 | |
75 base::CancelableClosure output_surface_creation_callback; | |
76 RendererCapabilities renderer_capabilities_main_thread_copy; | |
77 | |
78 scoped_ptr<BeginMainFrameAndCommitState> pending_deferred_commit; | |
79 base::WeakPtrFactory<ThreadProxy> weak_factory; | |
80 }; | |
81 | |
82 struct ReadbackRequest; | |
83 | |
84 struct CompositorThreadOnly { | |
85 CompositorThreadOnly(ThreadProxy* proxy, int layer_tree_host_id); | |
86 ~CompositorThreadOnly(); | |
87 | |
88 const int layer_tree_host_id; | |
89 | |
90 // Copy of the main thread side contents texture manager for work | |
91 // that needs to be done on the compositor thread. | |
92 PrioritizedResourceManager* contents_texture_manager; | |
93 | |
94 scoped_ptr<Scheduler> scheduler; | |
95 | |
96 // Set when the main thread is waiting on a | |
97 // ScheduledActionSendBeginMainFrame to be issued. | |
98 CompletionEvent* begin_main_frame_sent_completion_event; | |
99 | |
100 // Set when the main thread is waiting on a readback. | |
101 ReadbackRequest* readback_request; | |
102 | |
103 // Set when the main thread is waiting on a commit to complete. | |
104 CompletionEvent* commit_completion_event; | |
105 | |
106 // Set when the main thread is waiting on a pending tree activation. | |
107 CompletionEvent* completion_event_for_commit_held_on_tree_activation; | |
108 | |
109 scoped_ptr<ResourceUpdateController> current_resource_update_controller; | |
110 | |
111 // Set when the next draw should post DidCommitAndDrawFrame to the main | |
112 // thread. | |
113 bool next_frame_is_newly_committed_frame; | |
114 | |
115 bool inside_draw; | |
116 | |
117 bool input_throttled_until_commit; | |
118 | |
119 // Set when we freeze animations to avoid checkerboarding. | |
120 bool animations_frozen_until_next_draw; | |
121 base::TimeTicks animation_time; | |
122 | |
123 // Whether a commit has been completed since the last time animations were | |
124 // ticked. If this happens, we need to animate again. | |
125 bool did_commit_after_animating; | |
126 | |
127 base::TimeTicks smoothness_takes_priority_expiration_time; | |
128 bool renew_tree_priority_pending; | |
129 | |
130 ProxyTimingHistory timing_history; | |
131 | |
132 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl; | |
133 base::WeakPtrFactory<ThreadProxy> weak_factory; | |
134 }; | |
135 | |
45 // Proxy implementation | 136 // Proxy implementation |
46 virtual bool CompositeAndReadback(void* pixels, | 137 virtual bool CompositeAndReadback(void* pixels, |
47 const gfx::Rect& rect) OVERRIDE; | 138 const gfx::Rect& rect) OVERRIDE; |
48 virtual void FinishAllRendering() OVERRIDE; | 139 virtual void FinishAllRendering() OVERRIDE; |
49 virtual bool IsStarted() const OVERRIDE; | 140 virtual bool IsStarted() const OVERRIDE; |
50 virtual void SetLayerTreeHostClientReady() OVERRIDE; | 141 virtual void SetLayerTreeHostClientReady() OVERRIDE; |
51 virtual void SetVisible(bool visible) OVERRIDE; | 142 virtual void SetVisible(bool visible) OVERRIDE; |
52 virtual void CreateAndInitializeOutputSurface() OVERRIDE; | 143 virtual void CreateAndInitializeOutputSurface() OVERRIDE; |
53 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; | 144 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; |
54 virtual void SetNeedsAnimate() OVERRIDE; | 145 virtual void SetNeedsAnimate() OVERRIDE; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 virtual void ScheduledActionManageTiles() OVERRIDE; | 212 virtual void ScheduledActionManageTiles() OVERRIDE; |
122 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE; | 213 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE; |
123 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; | 214 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; |
124 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE; | 215 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE; |
125 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE; | 216 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE; |
126 virtual void DidBeginImplFrameDeadline() OVERRIDE; | 217 virtual void DidBeginImplFrameDeadline() OVERRIDE; |
127 | 218 |
128 // ResourceUpdateControllerClient implementation | 219 // ResourceUpdateControllerClient implementation |
129 virtual void ReadyToFinalizeTextureUpdates() OVERRIDE; | 220 virtual void ReadyToFinalizeTextureUpdates() OVERRIDE; |
130 | 221 |
131 private: | 222 protected: |
132 ThreadProxy(LayerTreeHost* layer_tree_host, | 223 ThreadProxy(LayerTreeHost* layer_tree_host, |
133 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); | 224 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); |
134 | 225 |
135 struct BeginMainFrameAndCommitState { | 226 MainThreadOnly& main(); |
brianderson
2014/05/14 21:12:07
Does this need to be protected too? It looks like
simonhong
2014/05/15 01:32:07
Done.
| |
136 BeginMainFrameAndCommitState(); | 227 const MainThreadOnly& main() const; |
137 ~BeginMainFrameAndCommitState(); | |
138 | 228 |
139 base::TimeTicks monotonic_frame_begin_time; | 229 CompositorThreadOnly& impl(); |
140 scoped_ptr<ScrollAndScaleSet> scroll_info; | 230 const CompositorThreadOnly& impl() const; |
141 size_t memory_allocation_limit_bytes; | |
142 int memory_allocation_priority_cutoff; | |
143 bool evicted_ui_resources; | |
144 }; | |
145 | 231 |
232 private: | |
146 // Called on main thread. | 233 // Called on main thread. |
147 void SetRendererCapabilitiesMainThreadCopy( | 234 void SetRendererCapabilitiesMainThreadCopy( |
148 const RendererCapabilities& capabilities); | 235 const RendererCapabilities& capabilities); |
149 void BeginMainFrame( | 236 void BeginMainFrame( |
150 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); | 237 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); |
151 void DidCommitAndDrawFrame(); | 238 void DidCommitAndDrawFrame(); |
152 void DidCompleteSwapBuffers(); | 239 void DidCompleteSwapBuffers(); |
153 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue); | 240 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue); |
154 void DoCreateAndInitializeOutputSurface(); | 241 void DoCreateAndInitializeOutputSurface(); |
155 void SendCommitRequestToImplThreadIfNeeded(); | 242 void SendCommitRequestToImplThreadIfNeeded(); |
156 | 243 |
157 // Called on impl thread. | 244 // Called on impl thread. |
158 struct ReadbackRequest; | |
159 struct CommitPendingRequest; | 245 struct CommitPendingRequest; |
160 struct SchedulerStateRequest; | 246 struct SchedulerStateRequest; |
161 | 247 |
162 void ForceCommitForReadbackOnImplThread( | 248 void ForceCommitForReadbackOnImplThread( |
163 CompletionEvent* begin_main_frame_sent_completion, | 249 CompletionEvent* begin_main_frame_sent_completion, |
164 ReadbackRequest* request); | 250 ReadbackRequest* request); |
165 void StartCommitOnImplThread(CompletionEvent* completion, | 251 void StartCommitOnImplThread(CompletionEvent* completion, |
166 ResourceUpdateQueue* queue); | 252 ResourceUpdateQueue* queue); |
167 void BeginMainFrameAbortedOnImplThread(bool did_handle); | 253 void BeginMainFrameAbortedOnImplThread(bool did_handle); |
168 void RequestReadbackOnImplThread(ReadbackRequest* request); | 254 void RequestReadbackOnImplThread(ReadbackRequest* request); |
(...skipping 23 matching lines...) Expand all Loading... | |
192 base::DictionaryValue* state) const; | 278 base::DictionaryValue* state) const; |
193 void RenewTreePriorityOnImplThread(); | 279 void RenewTreePriorityOnImplThread(); |
194 void SetSwapUsedIncompleteTileOnImplThread(bool used_incomplete_tile); | 280 void SetSwapUsedIncompleteTileOnImplThread(bool used_incomplete_tile); |
195 void MainThreadHasStoppedFlingingOnImplThread(); | 281 void MainThreadHasStoppedFlingingOnImplThread(); |
196 void SetInputThrottledUntilCommitOnImplThread(bool is_throttled); | 282 void SetInputThrottledUntilCommitOnImplThread(bool is_throttled); |
197 void SetDebugStateOnImplThread(const LayerTreeDebugState& debug_state); | 283 void SetDebugStateOnImplThread(const LayerTreeDebugState& debug_state); |
198 | 284 |
199 LayerTreeHost* layer_tree_host(); | 285 LayerTreeHost* layer_tree_host(); |
200 const LayerTreeHost* layer_tree_host() const; | 286 const LayerTreeHost* layer_tree_host() const; |
201 | 287 |
202 struct MainThreadOnly { | |
203 MainThreadOnly(ThreadProxy* proxy, int layer_tree_host_id); | |
204 ~MainThreadOnly(); | |
205 | |
206 const int layer_tree_host_id; | |
207 | |
208 // Set only when SetNeedsAnimate is called. | |
209 bool animate_requested; | |
210 // Set only when SetNeedsCommit is called. | |
211 bool commit_requested; | |
212 // Set by SetNeedsAnimate, SetNeedsUpdateLayers, and SetNeedsCommit. | |
213 bool commit_request_sent_to_impl_thread; | |
214 | |
215 bool started; | |
216 bool in_composite_and_readback; | |
217 bool manage_tiles_pending; | |
218 bool can_cancel_commit; | |
219 bool defer_commits; | |
220 | |
221 base::CancelableClosure output_surface_creation_callback; | |
222 RendererCapabilities renderer_capabilities_main_thread_copy; | |
223 | |
224 scoped_ptr<BeginMainFrameAndCommitState> pending_deferred_commit; | |
225 base::WeakPtrFactory<ThreadProxy> weak_factory; | |
226 }; | |
227 // Use accessors instead of this variable directly. | 288 // Use accessors instead of this variable directly. |
228 MainThreadOnly main_thread_only_vars_unsafe_; | 289 MainThreadOnly main_thread_only_vars_unsafe_; |
229 MainThreadOnly& main(); | |
230 const MainThreadOnly& main() const; | |
231 | 290 |
232 // Accessed on the main thread, or when main thread is blocked. | 291 // Accessed on the main thread, or when main thread is blocked. |
233 struct MainThreadOrBlockedMainThread { | 292 struct MainThreadOrBlockedMainThread { |
234 explicit MainThreadOrBlockedMainThread(LayerTreeHost* host); | 293 explicit MainThreadOrBlockedMainThread(LayerTreeHost* host); |
235 ~MainThreadOrBlockedMainThread(); | 294 ~MainThreadOrBlockedMainThread(); |
236 | 295 |
237 PrioritizedResourceManager* contents_texture_manager(); | 296 PrioritizedResourceManager* contents_texture_manager(); |
238 | 297 |
239 LayerTreeHost* layer_tree_host; | 298 LayerTreeHost* layer_tree_host; |
240 bool commit_waits_for_activation; | 299 bool commit_waits_for_activation; |
241 bool main_thread_inside_commit; | 300 bool main_thread_inside_commit; |
242 | 301 |
243 base::TimeTicks last_monotonic_frame_begin_time; | 302 base::TimeTicks last_monotonic_frame_begin_time; |
244 }; | 303 }; |
245 // Use accessors instead of this variable directly. | 304 // Use accessors instead of this variable directly. |
246 MainThreadOrBlockedMainThread main_thread_or_blocked_vars_unsafe_; | 305 MainThreadOrBlockedMainThread main_thread_or_blocked_vars_unsafe_; |
247 MainThreadOrBlockedMainThread& blocked_main(); | 306 MainThreadOrBlockedMainThread& blocked_main(); |
248 const MainThreadOrBlockedMainThread& blocked_main() const; | 307 const MainThreadOrBlockedMainThread& blocked_main() const; |
brianderson
2014/05/14 21:12:07
Please expose MainThreadOrBlockedMainThread as the
simonhong
2014/05/15 01:32:07
Done.
| |
249 | 308 |
250 struct CompositorThreadOnly { | |
251 CompositorThreadOnly(ThreadProxy* proxy, int layer_tree_host_id); | |
252 ~CompositorThreadOnly(); | |
253 | |
254 const int layer_tree_host_id; | |
255 | |
256 // Copy of the main thread side contents texture manager for work | |
257 // that needs to be done on the compositor thread. | |
258 PrioritizedResourceManager* contents_texture_manager; | |
259 | |
260 scoped_ptr<Scheduler> scheduler; | |
261 | |
262 // Set when the main thread is waiting on a | |
263 // ScheduledActionSendBeginMainFrame to be issued. | |
264 CompletionEvent* begin_main_frame_sent_completion_event; | |
265 | |
266 // Set when the main thread is waiting on a readback. | |
267 ReadbackRequest* readback_request; | |
268 | |
269 // Set when the main thread is waiting on a commit to complete. | |
270 CompletionEvent* commit_completion_event; | |
271 | |
272 // Set when the main thread is waiting on a pending tree activation. | |
273 CompletionEvent* completion_event_for_commit_held_on_tree_activation; | |
274 | |
275 scoped_ptr<ResourceUpdateController> current_resource_update_controller; | |
276 | |
277 // Set when the next draw should post DidCommitAndDrawFrame to the main | |
278 // thread. | |
279 bool next_frame_is_newly_committed_frame; | |
280 | |
281 bool inside_draw; | |
282 | |
283 bool input_throttled_until_commit; | |
284 | |
285 // Set when we freeze animations to avoid checkerboarding. | |
286 bool animations_frozen_until_next_draw; | |
287 base::TimeTicks animation_time; | |
288 | |
289 // Whether a commit has been completed since the last time animations were | |
290 // ticked. If this happens, we need to animate again. | |
291 bool did_commit_after_animating; | |
292 | |
293 base::TimeTicks smoothness_takes_priority_expiration_time; | |
294 bool renew_tree_priority_pending; | |
295 | |
296 ProxyTimingHistory timing_history; | |
297 | |
298 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl; | |
299 base::WeakPtrFactory<ThreadProxy> weak_factory; | |
300 }; | |
301 // Use accessors instead of this variable directly. | 309 // Use accessors instead of this variable directly. |
302 CompositorThreadOnly compositor_thread_vars_unsafe_; | 310 CompositorThreadOnly compositor_thread_vars_unsafe_; |
303 CompositorThreadOnly& impl(); | |
304 const CompositorThreadOnly& impl() const; | |
305 | 311 |
306 base::WeakPtr<ThreadProxy> main_thread_weak_ptr_; | 312 base::WeakPtr<ThreadProxy> main_thread_weak_ptr_; |
307 base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_; | 313 base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_; |
308 | 314 |
309 DISALLOW_COPY_AND_ASSIGN(ThreadProxy); | 315 DISALLOW_COPY_AND_ASSIGN(ThreadProxy); |
310 }; | 316 }; |
311 | 317 |
312 } // namespace cc | 318 } // namespace cc |
313 | 319 |
314 #endif // CC_TREES_THREAD_PROXY_H_ | 320 #endif // CC_TREES_THREAD_PROXY_H_ |
OLD | NEW |