| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CC_TREES_THREAD_PROXY_H_ | |
| 6 #define CC_TREES_THREAD_PROXY_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 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" | |
| 20 #include "cc/trees/threaded_channel.h" | |
| 21 | |
| 22 namespace base { | |
| 23 class SingleThreadTaskRunner; | |
| 24 } | |
| 25 | |
| 26 namespace cc { | |
| 27 | |
| 28 class BeginFrameSource; | |
| 29 class ChannelImpl; | |
| 30 class ChannelMain; | |
| 31 class ContextProvider; | |
| 32 class InputHandlerClient; | |
| 33 class LayerTreeHost; | |
| 34 class ProxyImpl; | |
| 35 class ProxyMain; | |
| 36 class Scheduler; | |
| 37 class ScopedThreadProxy; | |
| 38 class ThreadedChannel; | |
| 39 | |
| 40 class CC_EXPORT ThreadProxy : public Proxy, | |
| 41 public ProxyMain, | |
| 42 public ProxyImpl, | |
| 43 NON_EXPORTED_BASE(LayerTreeHostImplClient), | |
| 44 NON_EXPORTED_BASE(SchedulerClient) { | |
| 45 public: | |
| 46 static scoped_ptr<Proxy> Create( | |
| 47 LayerTreeHost* layer_tree_host, | |
| 48 TaskRunnerProvider* task_runner_provider, | |
| 49 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
| 50 | |
| 51 ~ThreadProxy() override; | |
| 52 | |
| 53 // Commits between the main and impl threads are processed through a pipeline | |
| 54 // with the following stages. For efficiency we can early out at any stage if | |
| 55 // we decide that no further processing is necessary. | |
| 56 enum CommitPipelineStage { | |
| 57 NO_PIPELINE_STAGE, | |
| 58 ANIMATE_PIPELINE_STAGE, | |
| 59 UPDATE_LAYERS_PIPELINE_STAGE, | |
| 60 COMMIT_PIPELINE_STAGE, | |
| 61 }; | |
| 62 | |
| 63 struct MainThreadOnly { | |
| 64 MainThreadOnly(ThreadProxy* proxy, LayerTreeHost* layer_tree_host); | |
| 65 ~MainThreadOnly(); | |
| 66 | |
| 67 const int layer_tree_host_id; | |
| 68 | |
| 69 LayerTreeHost* layer_tree_host; | |
| 70 | |
| 71 // The furthest pipeline stage which has been requested for the next | |
| 72 // commit. | |
| 73 CommitPipelineStage max_requested_pipeline_stage; | |
| 74 // The commit pipeline stage that is currently being processed. | |
| 75 CommitPipelineStage current_pipeline_stage; | |
| 76 // The commit pipeline stage at which processing for the current commit | |
| 77 // will stop. Only valid while we are executing the pipeline (i.e., | |
| 78 // |current_pipeline_stage| is set to a pipeline stage). | |
| 79 CommitPipelineStage final_pipeline_stage; | |
| 80 | |
| 81 bool commit_waits_for_activation; | |
| 82 | |
| 83 bool started; | |
| 84 bool prepare_tiles_pending; | |
| 85 bool defer_commits; | |
| 86 | |
| 87 RendererCapabilities renderer_capabilities_main_thread_copy; | |
| 88 | |
| 89 // TODO(khushalsagar): Make this scoped_ptr<ChannelMain> when ProxyMain | |
| 90 // and ProxyImpl are split. | |
| 91 ChannelMain* channel_main; | |
| 92 | |
| 93 base::WeakPtrFactory<ThreadProxy> weak_factory; | |
| 94 }; | |
| 95 | |
| 96 // Accessed on the impl thread when the main thread is blocked for a commit. | |
| 97 struct BlockedMainCommitOnly { | |
| 98 BlockedMainCommitOnly(); | |
| 99 ~BlockedMainCommitOnly(); | |
| 100 LayerTreeHost* layer_tree_host; | |
| 101 }; | |
| 102 | |
| 103 struct CompositorThreadOnly { | |
| 104 CompositorThreadOnly( | |
| 105 ThreadProxy* proxy, | |
| 106 int layer_tree_host_id, | |
| 107 RenderingStatsInstrumentation* rendering_stats_instrumentation, | |
| 108 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
| 109 ~CompositorThreadOnly(); | |
| 110 | |
| 111 const int layer_tree_host_id; | |
| 112 | |
| 113 scoped_ptr<Scheduler> scheduler; | |
| 114 | |
| 115 // Set when the main thread is waiting on a pending tree activation. | |
| 116 bool next_commit_waits_for_activation; | |
| 117 | |
| 118 // Set when the main thread is waiting on a commit to complete or on a | |
| 119 // pending tree activation. | |
| 120 CompletionEvent* commit_completion_event; | |
| 121 | |
| 122 // Set when the next draw should post DidCommitAndDrawFrame to the main | |
| 123 // thread. | |
| 124 bool next_frame_is_newly_committed_frame; | |
| 125 | |
| 126 bool inside_draw; | |
| 127 | |
| 128 bool input_throttled_until_commit; | |
| 129 | |
| 130 // Whether a commit has been completed since the last time animations were | |
| 131 // ticked. If this happens, we need to animate again. | |
| 132 bool did_commit_after_animating; | |
| 133 | |
| 134 DelayedUniqueNotifier smoothness_priority_expiration_notifier; | |
| 135 | |
| 136 scoped_ptr<BeginFrameSource> external_begin_frame_source; | |
| 137 | |
| 138 RenderingStatsInstrumentation* rendering_stats_instrumentation; | |
| 139 | |
| 140 // Values used to keep track of frame durations. Used only in frame timing. | |
| 141 BeginFrameArgs last_begin_main_frame_args; | |
| 142 BeginFrameArgs last_processed_begin_main_frame_args; | |
| 143 | |
| 144 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl; | |
| 145 | |
| 146 ChannelImpl* channel_impl; | |
| 147 | |
| 148 base::WeakPtrFactory<ThreadProxy> weak_factory; | |
| 149 }; | |
| 150 | |
| 151 const MainThreadOnly& main() const; | |
| 152 const CompositorThreadOnly& impl() const; | |
| 153 TaskRunnerProvider* task_runner_provider() { return task_runner_provider_; } | |
| 154 | |
| 155 // Proxy implementation | |
| 156 void FinishAllRendering() override; | |
| 157 bool IsStarted() const override; | |
| 158 bool CommitToActiveTree() const override; | |
| 159 void SetOutputSurface(OutputSurface* output_surface) override; | |
| 160 void SetVisible(bool visible) override; | |
| 161 void SetThrottleFrameProduction(bool throttle) override; | |
| 162 const RendererCapabilities& GetRendererCapabilities() const override; | |
| 163 void SetNeedsAnimate() override; | |
| 164 void SetNeedsUpdateLayers() override; | |
| 165 void SetNeedsCommit() override; | |
| 166 void SetNeedsRedraw(const gfx::Rect& damage_rect) override; | |
| 167 void SetNextCommitWaitsForActivation() override; | |
| 168 void NotifyInputThrottledUntilCommit() override; | |
| 169 void SetDeferCommits(bool defer_commits) override; | |
| 170 bool CommitRequested() const override; | |
| 171 bool BeginMainFrameRequested() const override; | |
| 172 void MainThreadHasStoppedFlinging() override; | |
| 173 void Start() override; | |
| 174 void Stop() override; | |
| 175 bool SupportsImplScrolling() const override; | |
| 176 bool MainFrameWillHappenForTesting() override; | |
| 177 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override; | |
| 178 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override; | |
| 179 void ReleaseOutputSurface() override; | |
| 180 void UpdateTopControlsState(TopControlsState constraints, | |
| 181 TopControlsState current, | |
| 182 bool animate) override; | |
| 183 | |
| 184 // LayerTreeHostImplClient implementation | |
| 185 void UpdateRendererCapabilitiesOnImplThread() override; | |
| 186 void DidLoseOutputSurfaceOnImplThread() override; | |
| 187 void CommitVSyncParameters(base::TimeTicks timebase, | |
| 188 base::TimeDelta interval) override; | |
| 189 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override; | |
| 190 void DidSwapBuffersOnImplThread() override; | |
| 191 void DidSwapBuffersCompleteOnImplThread() override; | |
| 192 void OnResourcelessSoftareDrawStateChanged(bool resourceless_draw) override; | |
| 193 void OnCanDrawStateChanged(bool can_draw) override; | |
| 194 void NotifyReadyToActivate() override; | |
| 195 void NotifyReadyToDraw() override; | |
| 196 // Please call these 3 functions through | |
| 197 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and | |
| 198 // SetNeedsAnimate(). | |
| 199 void SetNeedsRedrawOnImplThread() override; | |
| 200 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override; | |
| 201 void SetNeedsAnimateOnImplThread() override; | |
| 202 void SetNeedsPrepareTilesOnImplThread() override; | |
| 203 void SetNeedsCommitOnImplThread() override; | |
| 204 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override; | |
| 205 void PostAnimationEventsToMainThreadOnImplThread( | |
| 206 scoped_ptr<AnimationEventsVector> queue) override; | |
| 207 bool IsInsideDraw() override; | |
| 208 void RenewTreePriority() override; | |
| 209 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, | |
| 210 base::TimeDelta delay) override; | |
| 211 void DidActivateSyncTree() override; | |
| 212 void WillPrepareTiles() override; | |
| 213 void DidPrepareTiles() override; | |
| 214 void DidCompletePageScaleAnimationOnImplThread() override; | |
| 215 void OnDrawForOutputSurface() override; | |
| 216 // This should only be called by LayerTreeHostImpl::PostFrameTimingEvents. | |
| 217 void PostFrameTimingEventsOnImplThread( | |
| 218 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | |
| 219 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | |
| 220 override; | |
| 221 | |
| 222 // SchedulerClient implementation | |
| 223 void WillBeginImplFrame(const BeginFrameArgs& args) override; | |
| 224 void DidFinishImplFrame() override; | |
| 225 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override; | |
| 226 DrawResult ScheduledActionDrawAndSwapIfPossible() override; | |
| 227 DrawResult ScheduledActionDrawAndSwapForced() override; | |
| 228 void ScheduledActionAnimate() override; | |
| 229 void ScheduledActionCommit() override; | |
| 230 void ScheduledActionActivateSyncTree() override; | |
| 231 void ScheduledActionBeginOutputSurfaceCreation() override; | |
| 232 void ScheduledActionPrepareTiles() override; | |
| 233 void ScheduledActionInvalidateOutputSurface() override; | |
| 234 void SendBeginFramesToChildren(const BeginFrameArgs& args) override; | |
| 235 void SendBeginMainFrameNotExpectedSoon() override; | |
| 236 | |
| 237 // ProxyMain implementation | |
| 238 void SetChannel(scoped_ptr<ThreadedChannel> threaded_channel) override; | |
| 239 | |
| 240 protected: | |
| 241 ThreadProxy(LayerTreeHost* layer_tree_host, | |
| 242 TaskRunnerProvider* task_runner_provider, | |
| 243 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
| 244 | |
| 245 private: | |
| 246 friend class ThreadProxyForTest; | |
| 247 | |
| 248 // ProxyMain implementation. | |
| 249 base::WeakPtr<ProxyMain> GetMainWeakPtr() override; | |
| 250 void DidCompleteSwapBuffers() override; | |
| 251 void SetRendererCapabilitiesMainCopy( | |
| 252 const RendererCapabilities& capabilities) override; | |
| 253 void BeginMainFrameNotExpectedSoon() override; | |
| 254 void DidCommitAndDrawFrame() override; | |
| 255 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override; | |
| 256 void DidLoseOutputSurface() override; | |
| 257 void RequestNewOutputSurface() override; | |
| 258 void DidInitializeOutputSurface( | |
| 259 bool success, | |
| 260 const RendererCapabilities& capabilities) override; | |
| 261 void DidCompletePageScaleAnimation() override; | |
| 262 void PostFrameTimingEventsOnMain( | |
| 263 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | |
| 264 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | |
| 265 override; | |
| 266 void BeginMainFrame( | |
| 267 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override; | |
| 268 | |
| 269 // ProxyImpl implementation | |
| 270 base::WeakPtr<ProxyImpl> GetImplWeakPtr() override; | |
| 271 void SetThrottleFrameProductionOnImpl(bool throttle) override; | |
| 272 void UpdateTopControlsStateOnImpl(TopControlsState constraints, | |
| 273 TopControlsState current, | |
| 274 bool animate) override; | |
| 275 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override; | |
| 276 void MainThreadHasStoppedFlingingOnImpl() override; | |
| 277 void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override; | |
| 278 void SetDeferCommitsOnImpl(bool defer_commits) const override; | |
| 279 void FinishAllRenderingOnImpl(CompletionEvent* completion) override; | |
| 280 void SetVisibleOnImpl(bool visible) override; | |
| 281 void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override; | |
| 282 void FinishGLOnImpl(CompletionEvent* completion) override; | |
| 283 void MainFrameWillHappenOnImplForTesting( | |
| 284 CompletionEvent* completion, | |
| 285 bool* main_frame_will_happen) override; | |
| 286 void SetNeedsCommitOnImpl() override; | |
| 287 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override; | |
| 288 void BeginMainFrameAbortedOnImpl( | |
| 289 CommitEarlyOutReason reason, | |
| 290 base::TimeTicks main_thread_start_time) override; | |
| 291 void StartCommitOnImpl(CompletionEvent* completion, | |
| 292 LayerTreeHost* layer_tree_host, | |
| 293 base::TimeTicks main_thread_start_time, | |
| 294 bool hold_commit_for_activation) override; | |
| 295 void InitializeImplOnImpl(CompletionEvent* completion, | |
| 296 LayerTreeHost* layer_tree_host) override; | |
| 297 void LayerTreeHostClosedOnImpl(CompletionEvent* completion) override; | |
| 298 | |
| 299 // Returns |true| if the request was actually sent, |false| if one was | |
| 300 // already outstanding. | |
| 301 bool SendCommitRequestToImplThreadIfNeeded( | |
| 302 CommitPipelineStage required_stage); | |
| 303 | |
| 304 // Called on impl thread. | |
| 305 struct SchedulerStateRequest; | |
| 306 | |
| 307 DrawResult DrawSwapInternal(bool forced_draw); | |
| 308 | |
| 309 TaskRunnerProvider* task_runner_provider_; | |
| 310 | |
| 311 // Use accessors instead of this variable directly. | |
| 312 MainThreadOnly main_thread_only_vars_unsafe_; | |
| 313 MainThreadOnly& main(); | |
| 314 | |
| 315 // Use accessors instead of this variable directly. | |
| 316 BlockedMainCommitOnly main_thread_blocked_commit_vars_unsafe_; | |
| 317 BlockedMainCommitOnly& blocked_main_commit(); | |
| 318 | |
| 319 // Use accessors instead of this variable directly. | |
| 320 CompositorThreadOnly compositor_thread_vars_unsafe_; | |
| 321 CompositorThreadOnly& impl(); | |
| 322 | |
| 323 // TODO(khushalsagar): Remove this. Temporary variable to hold the channel. | |
| 324 scoped_ptr<ThreadedChannel> threaded_channel_; | |
| 325 | |
| 326 base::WeakPtr<ThreadProxy> main_thread_weak_ptr_; | |
| 327 base::WeakPtr<ThreadProxy> impl_thread_weak_ptr_; | |
| 328 | |
| 329 DISALLOW_COPY_AND_ASSIGN(ThreadProxy); | |
| 330 }; | |
| 331 | |
| 332 } // namespace cc | |
| 333 | |
| 334 #endif // CC_TREES_THREAD_PROXY_H_ | |
| OLD | NEW |