| 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 // Accessed on the main thread, or when main thread is blocked. |
| 83 struct MainThreadOrBlockedMainThread { |
| 84 explicit MainThreadOrBlockedMainThread(LayerTreeHost* host); |
| 85 ~MainThreadOrBlockedMainThread(); |
| 86 |
| 87 PrioritizedResourceManager* contents_texture_manager(); |
| 88 |
| 89 LayerTreeHost* layer_tree_host; |
| 90 bool commit_waits_for_activation; |
| 91 bool main_thread_inside_commit; |
| 92 |
| 93 base::TimeTicks last_monotonic_frame_begin_time; |
| 94 }; |
| 95 |
| 96 struct ReadbackRequest; |
| 97 |
| 98 struct CompositorThreadOnly { |
| 99 CompositorThreadOnly(ThreadProxy* proxy, int layer_tree_host_id); |
| 100 ~CompositorThreadOnly(); |
| 101 |
| 102 const int layer_tree_host_id; |
| 103 |
| 104 // Copy of the main thread side contents texture manager for work |
| 105 // that needs to be done on the compositor thread. |
| 106 PrioritizedResourceManager* contents_texture_manager; |
| 107 |
| 108 scoped_ptr<Scheduler> scheduler; |
| 109 |
| 110 // Set when the main thread is waiting on a |
| 111 // ScheduledActionSendBeginMainFrame to be issued. |
| 112 CompletionEvent* begin_main_frame_sent_completion_event; |
| 113 |
| 114 // Set when the main thread is waiting on a readback. |
| 115 ReadbackRequest* readback_request; |
| 116 |
| 117 // Set when the main thread is waiting on a commit to complete. |
| 118 CompletionEvent* commit_completion_event; |
| 119 |
| 120 // Set when the main thread is waiting on a pending tree activation. |
| 121 CompletionEvent* completion_event_for_commit_held_on_tree_activation; |
| 122 |
| 123 scoped_ptr<ResourceUpdateController> current_resource_update_controller; |
| 124 |
| 125 // Set when the next draw should post DidCommitAndDrawFrame to the main |
| 126 // thread. |
| 127 bool next_frame_is_newly_committed_frame; |
| 128 |
| 129 bool inside_draw; |
| 130 |
| 131 bool input_throttled_until_commit; |
| 132 |
| 133 // Set when we freeze animations to avoid checkerboarding. |
| 134 bool animations_frozen_until_next_draw; |
| 135 base::TimeTicks animation_time; |
| 136 |
| 137 // Whether a commit has been completed since the last time animations were |
| 138 // ticked. If this happens, we need to animate again. |
| 139 bool did_commit_after_animating; |
| 140 |
| 141 base::TimeTicks smoothness_takes_priority_expiration_time; |
| 142 bool renew_tree_priority_pending; |
| 143 |
| 144 ProxyTimingHistory timing_history; |
| 145 |
| 146 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl; |
| 147 base::WeakPtrFactory<ThreadProxy> weak_factory; |
| 148 }; |
| 149 |
| 45 // Proxy implementation | 150 // Proxy implementation |
| 46 virtual bool CompositeAndReadback(void* pixels, | 151 virtual bool CompositeAndReadback(void* pixels, |
| 47 const gfx::Rect& rect) OVERRIDE; | 152 const gfx::Rect& rect) OVERRIDE; |
| 48 virtual void FinishAllRendering() OVERRIDE; | 153 virtual void FinishAllRendering() OVERRIDE; |
| 49 virtual bool IsStarted() const OVERRIDE; | 154 virtual bool IsStarted() const OVERRIDE; |
| 50 virtual void SetLayerTreeHostClientReady() OVERRIDE; | 155 virtual void SetLayerTreeHostClientReady() OVERRIDE; |
| 51 virtual void SetVisible(bool visible) OVERRIDE; | 156 virtual void SetVisible(bool visible) OVERRIDE; |
| 52 virtual void CreateAndInitializeOutputSurface() OVERRIDE; | 157 virtual void CreateAndInitializeOutputSurface() OVERRIDE; |
| 53 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; | 158 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; |
| 54 virtual void SetNeedsAnimate() OVERRIDE; | 159 virtual void SetNeedsAnimate() OVERRIDE; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 virtual void ScheduledActionManageTiles() OVERRIDE; | 226 virtual void ScheduledActionManageTiles() OVERRIDE; |
| 122 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE; | 227 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE; |
| 123 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; | 228 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; |
| 124 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE; | 229 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE; |
| 125 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE; | 230 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE; |
| 126 virtual void DidBeginImplFrameDeadline() OVERRIDE; | 231 virtual void DidBeginImplFrameDeadline() OVERRIDE; |
| 127 | 232 |
| 128 // ResourceUpdateControllerClient implementation | 233 // ResourceUpdateControllerClient implementation |
| 129 virtual void ReadyToFinalizeTextureUpdates() OVERRIDE; | 234 virtual void ReadyToFinalizeTextureUpdates() OVERRIDE; |
| 130 | 235 |
| 131 private: | 236 protected: |
| 132 ThreadProxy(LayerTreeHost* layer_tree_host, | 237 ThreadProxy(LayerTreeHost* layer_tree_host, |
| 133 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); | 238 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); |
| 134 | 239 |
| 135 struct BeginMainFrameAndCommitState { | 240 const MainThreadOnly& main() const; |
| 136 BeginMainFrameAndCommitState(); | 241 const MainThreadOrBlockedMainThread& blocked_main() const; |
| 137 ~BeginMainFrameAndCommitState(); | 242 const CompositorThreadOnly& impl() const; |
| 138 | 243 |
| 139 base::TimeTicks monotonic_frame_begin_time; | 244 private: |
| 140 scoped_ptr<ScrollAndScaleSet> scroll_info; | |
| 141 size_t memory_allocation_limit_bytes; | |
| 142 int memory_allocation_priority_cutoff; | |
| 143 bool evicted_ui_resources; | |
| 144 }; | |
| 145 | |
| 146 // Called on main thread. | 245 // Called on main thread. |
| 147 void SetRendererCapabilitiesMainThreadCopy( | 246 void SetRendererCapabilitiesMainThreadCopy( |
| 148 const RendererCapabilities& capabilities); | 247 const RendererCapabilities& capabilities); |
| 149 void BeginMainFrame( | 248 void BeginMainFrame( |
| 150 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); | 249 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); |
| 151 void DidCommitAndDrawFrame(); | 250 void DidCommitAndDrawFrame(); |
| 152 void DidCompleteSwapBuffers(); | 251 void DidCompleteSwapBuffers(); |
| 153 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue); | 252 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue); |
| 154 void DoCreateAndInitializeOutputSurface(); | 253 void DoCreateAndInitializeOutputSurface(); |
| 155 void SendCommitRequestToImplThreadIfNeeded(); | 254 void SendCommitRequestToImplThreadIfNeeded(); |
| 156 | 255 |
| 157 // Called on impl thread. | 256 // Called on impl thread. |
| 158 struct ReadbackRequest; | |
| 159 struct CommitPendingRequest; | 257 struct CommitPendingRequest; |
| 160 struct SchedulerStateRequest; | 258 struct SchedulerStateRequest; |
| 161 | 259 |
| 162 void ForceCommitForReadbackOnImplThread( | 260 void ForceCommitForReadbackOnImplThread( |
| 163 CompletionEvent* begin_main_frame_sent_completion, | 261 CompletionEvent* begin_main_frame_sent_completion, |
| 164 ReadbackRequest* request); | 262 ReadbackRequest* request); |
| 165 void StartCommitOnImplThread(CompletionEvent* completion, | 263 void StartCommitOnImplThread(CompletionEvent* completion, |
| 166 ResourceUpdateQueue* queue); | 264 ResourceUpdateQueue* queue); |
| 167 void BeginMainFrameAbortedOnImplThread(bool did_handle); | 265 void BeginMainFrameAbortedOnImplThread(bool did_handle); |
| 168 void RequestReadbackOnImplThread(ReadbackRequest* request); | 266 void RequestReadbackOnImplThread(ReadbackRequest* request); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 192 base::DictionaryValue* state) const; | 290 base::DictionaryValue* state) const; |
| 193 void RenewTreePriorityOnImplThread(); | 291 void RenewTreePriorityOnImplThread(); |
| 194 void SetSwapUsedIncompleteTileOnImplThread(bool used_incomplete_tile); | 292 void SetSwapUsedIncompleteTileOnImplThread(bool used_incomplete_tile); |
| 195 void MainThreadHasStoppedFlingingOnImplThread(); | 293 void MainThreadHasStoppedFlingingOnImplThread(); |
| 196 void SetInputThrottledUntilCommitOnImplThread(bool is_throttled); | 294 void SetInputThrottledUntilCommitOnImplThread(bool is_throttled); |
| 197 void SetDebugStateOnImplThread(const LayerTreeDebugState& debug_state); | 295 void SetDebugStateOnImplThread(const LayerTreeDebugState& debug_state); |
| 198 | 296 |
| 199 LayerTreeHost* layer_tree_host(); | 297 LayerTreeHost* layer_tree_host(); |
| 200 const LayerTreeHost* layer_tree_host() const; | 298 const LayerTreeHost* layer_tree_host() const; |
| 201 | 299 |
| 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. | 300 // Use accessors instead of this variable directly. |
| 228 MainThreadOnly main_thread_only_vars_unsafe_; | 301 MainThreadOnly main_thread_only_vars_unsafe_; |
| 229 MainThreadOnly& main(); | 302 MainThreadOnly& main(); |
| 230 const MainThreadOnly& main() const; | |
| 231 | 303 |
| 232 // Accessed on the main thread, or when main thread is blocked. | |
| 233 struct MainThreadOrBlockedMainThread { | |
| 234 explicit MainThreadOrBlockedMainThread(LayerTreeHost* host); | |
| 235 ~MainThreadOrBlockedMainThread(); | |
| 236 | |
| 237 PrioritizedResourceManager* contents_texture_manager(); | |
| 238 | |
| 239 LayerTreeHost* layer_tree_host; | |
| 240 bool commit_waits_for_activation; | |
| 241 bool main_thread_inside_commit; | |
| 242 | |
| 243 base::TimeTicks last_monotonic_frame_begin_time; | |
| 244 }; | |
| 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; | |
| 249 | 307 |
| 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. | 308 // Use accessors instead of this variable directly. |
| 302 CompositorThreadOnly compositor_thread_vars_unsafe_; | 309 CompositorThreadOnly compositor_thread_vars_unsafe_; |
| 303 CompositorThreadOnly& impl(); | 310 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 |