| 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_SINGLE_THREAD_PROXY_H_ | 5 #ifndef CC_TREES_SINGLE_THREAD_PROXY_H_ |
| 6 #define CC_TREES_SINGLE_THREAD_PROXY_H_ | 6 #define CC_TREES_SINGLE_THREAD_PROXY_H_ |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "cc/animation/animation_events.h" | 11 #include "cc/animation/animation_events.h" |
| 12 #include "cc/output/begin_frame_args.h" | 12 #include "cc/output/begin_frame_args.h" |
| 13 #include "cc/scheduler/scheduler.h" |
| 13 #include "cc/trees/layer_tree_host_impl.h" | 14 #include "cc/trees/layer_tree_host_impl.h" |
| 14 #include "cc/trees/proxy.h" | 15 #include "cc/trees/proxy.h" |
| 16 #include "cc/trees/proxy_timing_history.h" |
| 15 | 17 |
| 16 namespace cc { | 18 namespace cc { |
| 17 | 19 |
| 18 class ContextProvider; | 20 class ContextProvider; |
| 19 class LayerTreeHost; | 21 class LayerTreeHost; |
| 20 class LayerTreeHostSingleThreadClient; | 22 class LayerTreeHostSingleThreadClient; |
| 21 | 23 |
| 22 class CC_EXPORT SingleThreadProxy : public Proxy, | 24 class CC_EXPORT SingleThreadProxy : public Proxy, |
| 23 NON_EXPORTED_BASE(LayerTreeHostImplClient) { | 25 NON_EXPORTED_BASE(LayerTreeHostImplClient), |
| 26 SchedulerClient { |
| 24 public: | 27 public: |
| 25 static scoped_ptr<Proxy> Create( | 28 static scoped_ptr<Proxy> Create( |
| 26 LayerTreeHost* layer_tree_host, | 29 LayerTreeHost* layer_tree_host, |
| 27 LayerTreeHostSingleThreadClient* client); | 30 LayerTreeHostSingleThreadClient* client); |
| 28 virtual ~SingleThreadProxy(); | 31 virtual ~SingleThreadProxy(); |
| 29 | 32 |
| 30 // Proxy implementation | 33 // Proxy implementation |
| 31 virtual void FinishAllRendering() OVERRIDE; | 34 virtual void FinishAllRendering() OVERRIDE; |
| 32 virtual bool IsStarted() const OVERRIDE; | 35 virtual bool IsStarted() const OVERRIDE; |
| 33 virtual void SetLayerTreeHostClientReady() OVERRIDE; | 36 virtual void SetLayerTreeHostClientReady() OVERRIDE; |
| 34 virtual void SetVisible(bool visible) OVERRIDE; | 37 virtual void SetVisible(bool visible) OVERRIDE; |
| 35 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; | 38 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; |
| 36 virtual void SetNeedsAnimate() OVERRIDE; | 39 virtual void SetNeedsAnimate() OVERRIDE; |
| 37 virtual void SetNeedsUpdateLayers() OVERRIDE; | 40 virtual void SetNeedsUpdateLayers() OVERRIDE; |
| 38 virtual void SetNeedsCommit() OVERRIDE; | 41 virtual void SetNeedsCommit() OVERRIDE; |
| 39 virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) OVERRIDE; | 42 virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) OVERRIDE; |
| 40 virtual void SetNextCommitWaitsForActivation() OVERRIDE; | 43 virtual void SetNextCommitWaitsForActivation() OVERRIDE; |
| 41 virtual void NotifyInputThrottledUntilCommit() OVERRIDE {} | 44 virtual void NotifyInputThrottledUntilCommit() OVERRIDE {} |
| 42 virtual void SetDeferCommits(bool defer_commits) OVERRIDE; | 45 virtual void SetDeferCommits(bool defer_commits) OVERRIDE; |
| 43 virtual bool CommitRequested() const OVERRIDE; | 46 virtual bool CommitRequested() const OVERRIDE; |
| 44 virtual bool BeginMainFrameRequested() const OVERRIDE; | 47 virtual bool BeginMainFrameRequested() const OVERRIDE; |
| 45 virtual void MainThreadHasStoppedFlinging() OVERRIDE {} | 48 virtual void MainThreadHasStoppedFlinging() OVERRIDE {} |
| 46 virtual void Start() OVERRIDE; | 49 virtual void Start() OVERRIDE; |
| 47 virtual void Stop() OVERRIDE; | 50 virtual void Stop() OVERRIDE; |
| 48 virtual size_t MaxPartialTextureUpdates() const OVERRIDE; | 51 virtual size_t MaxPartialTextureUpdates() const OVERRIDE; |
| 49 virtual void ForceSerializeOnSwapBuffers() OVERRIDE; | 52 virtual void ForceSerializeOnSwapBuffers() OVERRIDE; |
| 50 virtual scoped_ptr<base::Value> AsValue() const OVERRIDE; | 53 virtual scoped_ptr<base::Value> AsValue() const OVERRIDE; |
| 51 virtual bool CommitPendingForTesting() OVERRIDE; | 54 virtual bool CommitPendingForTesting() OVERRIDE; |
| 55 virtual scoped_ptr<base::Value> SchedulerAsValueForTesting() OVERRIDE; |
| 56 |
| 57 // SchedulerClient implementation |
| 58 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE; |
| 59 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE; |
| 60 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE; |
| 61 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE; |
| 62 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE; |
| 63 virtual void ScheduledActionCommit() OVERRIDE; |
| 64 virtual void ScheduledActionAnimate() OVERRIDE; |
| 65 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE; |
| 66 virtual void ScheduledActionActivatePendingTree() OVERRIDE; |
| 67 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE; |
| 68 virtual void ScheduledActionManageTiles() OVERRIDE; |
| 69 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE; |
| 70 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; |
| 71 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE; |
| 72 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE; |
| 73 virtual void DidBeginImplFrameDeadline() OVERRIDE; |
| 52 | 74 |
| 53 // LayerTreeHostImplClient implementation | 75 // LayerTreeHostImplClient implementation |
| 54 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE; | 76 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE; |
| 55 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE; | 77 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE; |
| 56 virtual void CommitVSyncParameters(base::TimeTicks timebase, | 78 virtual void CommitVSyncParameters(base::TimeTicks timebase, |
| 57 base::TimeDelta interval) OVERRIDE {} | 79 base::TimeDelta interval) OVERRIDE {} |
| 58 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) OVERRIDE {} | 80 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) OVERRIDE {} |
| 59 virtual void SetMaxSwapsPendingOnImplThread(int max) OVERRIDE {} | 81 virtual void SetMaxSwapsPendingOnImplThread(int max) OVERRIDE {} |
| 60 virtual void DidSwapBuffersOnImplThread() OVERRIDE; | 82 virtual void DidSwapBuffersOnImplThread() OVERRIDE; |
| 61 virtual void DidSwapBuffersCompleteOnImplThread() OVERRIDE; | 83 virtual void DidSwapBuffersCompleteOnImplThread() OVERRIDE; |
| 62 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE {} | 84 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
| 63 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE; | 85 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE; |
| 64 virtual void NotifyReadyToActivate() OVERRIDE; | 86 virtual void NotifyReadyToActivate() OVERRIDE; |
| 65 virtual void SetNeedsRedrawOnImplThread() OVERRIDE; | 87 virtual void SetNeedsRedrawOnImplThread() OVERRIDE; |
| 66 virtual void SetNeedsRedrawRectOnImplThread( | 88 virtual void SetNeedsRedrawRectOnImplThread( |
| 67 const gfx::Rect& dirty_rect) OVERRIDE; | 89 const gfx::Rect& dirty_rect) OVERRIDE; |
| 68 virtual void SetNeedsAnimateOnImplThread() OVERRIDE; | 90 virtual void SetNeedsAnimateOnImplThread() OVERRIDE; |
| 69 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE; | 91 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE; |
| 70 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE; | 92 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE; |
| 71 virtual void SetNeedsCommitOnImplThread() OVERRIDE; | 93 virtual void SetNeedsCommitOnImplThread() OVERRIDE; |
| 72 virtual void PostAnimationEventsToMainThreadOnImplThread( | 94 virtual void PostAnimationEventsToMainThreadOnImplThread( |
| 73 scoped_ptr<AnimationEventsVector> events) OVERRIDE; | 95 scoped_ptr<AnimationEventsVector> events) OVERRIDE; |
| 74 virtual bool ReduceContentsTextureMemoryOnImplThread( | 96 virtual bool ReduceContentsTextureMemoryOnImplThread( |
| 75 size_t limit_bytes, | 97 size_t limit_bytes, |
| 76 int priority_cutoff) OVERRIDE; | 98 int priority_cutoff) OVERRIDE; |
| 77 virtual bool IsInsideDraw() OVERRIDE; | 99 virtual bool IsInsideDraw() OVERRIDE; |
| 78 virtual void RenewTreePriority() OVERRIDE {} | 100 virtual void RenewTreePriority() OVERRIDE {} |
| 79 virtual void PostDelayedScrollbarFadeOnImplThread( | 101 virtual void PostDelayedScrollbarFadeOnImplThread( |
| 80 const base::Closure& start_fade, | 102 const base::Closure& start_fade, |
| 81 base::TimeDelta delay) OVERRIDE {} | 103 base::TimeDelta delay) OVERRIDE {} |
| 82 virtual void DidActivatePendingTree() OVERRIDE {} | 104 virtual void DidActivatePendingTree() OVERRIDE; |
| 83 virtual void DidManageTiles() OVERRIDE {} | 105 virtual void DidManageTiles() OVERRIDE; |
| 84 virtual void SetDebugState(const LayerTreeDebugState& debug_state) OVERRIDE {} | 106 virtual void SetDebugState(const LayerTreeDebugState& debug_state) OVERRIDE {} |
| 85 | 107 |
| 86 // Attempts to create the context and renderer synchronously. Calls | 108 // Attempts to create the context and renderer synchronously. Calls |
| 87 // LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted with the result. | 109 // LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted with the result. |
| 88 void CreateAndInitializeOutputSurface(); | 110 void CreateAndInitializeOutputSurface(); |
| 89 | 111 |
| 90 // Called by the legacy path where RenderWidget does the scheduling. | 112 // Called by the legacy path where RenderWidget does the scheduling. |
| 91 void CompositeImmediately(base::TimeTicks frame_begin_time); | 113 void CompositeImmediately(base::TimeTicks frame_begin_time); |
| 92 | 114 |
| 93 private: | 115 private: |
| 94 SingleThreadProxy(LayerTreeHost* layer_tree_host, | 116 SingleThreadProxy(LayerTreeHost* layer_tree_host, |
| 95 LayerTreeHostSingleThreadClient* client); | 117 LayerTreeHostSingleThreadClient* client); |
| 96 | 118 |
| 97 void DoCommit(scoped_ptr<ResourceUpdateQueue> queue); | 119 void DoCommit(base::TimeTicks frame_begin_time); |
| 98 bool DoComposite(base::TimeTicks frame_begin_time, | 120 DrawResult DoComposite(base::TimeTicks frame_begin_time, |
| 99 LayerTreeHostImpl::FrameData* frame); | 121 LayerTreeHostImpl::FrameData* frame); |
| 100 void DidSwapFrame(); | 122 void DoSwap(); |
| 123 void DidCommitAndDrawFrame(); |
| 101 | 124 |
| 102 bool ShouldComposite() const; | 125 bool ShouldComposite() const; |
| 103 void UpdateBackgroundAnimateTicking(); | 126 void UpdateBackgroundAnimateTicking(); |
| 104 | 127 |
| 105 // Accessed on main thread only. | 128 // Accessed on main thread only. |
| 106 LayerTreeHost* layer_tree_host_; | 129 LayerTreeHost* layer_tree_host_; |
| 107 LayerTreeHostSingleThreadClient* client_; | 130 LayerTreeHostSingleThreadClient* client_; |
| 108 | 131 |
| 109 // Used on the Thread, but checked on main thread during | 132 // Used on the Thread, but checked on main thread during |
| 110 // initialization/shutdown. | 133 // initialization/shutdown. |
| 111 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_; | 134 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_; |
| 112 RendererCapabilities renderer_capabilities_for_main_thread_; | 135 RendererCapabilities renderer_capabilities_for_main_thread_; |
| 113 | 136 |
| 137 // Accessed from both threads. |
| 138 scoped_ptr<Scheduler> scheduler_on_impl_thread_; |
| 139 ProxyTimingHistory timing_history_; |
| 140 |
| 114 bool next_frame_is_newly_committed_frame_; | 141 bool next_frame_is_newly_committed_frame_; |
| 115 | 142 |
| 116 bool inside_draw_; | 143 bool inside_draw_; |
| 144 bool defer_commits_; |
| 145 bool commit_was_deferred_; |
| 146 bool commit_requested_; |
| 147 |
| 148 base::WeakPtrFactory<SingleThreadProxy> weak_factory_; |
| 117 | 149 |
| 118 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy); | 150 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy); |
| 119 }; | 151 }; |
| 120 | 152 |
| 121 // For use in the single-threaded case. In debug builds, it pretends that the | 153 // For use in the single-threaded case. In debug builds, it pretends that the |
| 122 // code is running on the impl thread to satisfy assertion checks. | 154 // code is running on the impl thread to satisfy assertion checks. |
| 123 class DebugScopedSetImplThread { | 155 class DebugScopedSetImplThread { |
| 124 public: | 156 public: |
| 125 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) { | 157 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) { |
| 126 #if DCHECK_IS_ON | 158 #if DCHECK_IS_ON |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 private: | 207 private: |
| 176 DebugScopedSetImplThread impl_thread_; | 208 DebugScopedSetImplThread impl_thread_; |
| 177 DebugScopedSetMainThreadBlocked main_thread_blocked_; | 209 DebugScopedSetMainThreadBlocked main_thread_blocked_; |
| 178 | 210 |
| 179 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked); | 211 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked); |
| 180 }; | 212 }; |
| 181 | 213 |
| 182 } // namespace cc | 214 } // namespace cc |
| 183 | 215 |
| 184 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_ | 216 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_ |
| OLD | NEW |