| 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> | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 12 #include "base/time.h" | 10 #include "base/time.h" |
| 13 #include "cc/animation/animation_events.h" | 11 #include "cc/animation/animation_events.h" |
| 14 #include "cc/base/completion_event.h" | 12 #include "cc/base/completion_event.h" |
| 15 #include "cc/resources/resource_update_controller.h" | 13 #include "cc/resources/resource_update_controller.h" |
| 16 #include "cc/scheduler/rolling_time_delta_history.h" | 14 #include "cc/scheduler/rolling_time_delta_history.h" |
| 17 #include "cc/scheduler/scheduler.h" | 15 #include "cc/scheduler/scheduler.h" |
| 16 #include "cc/scheduler/vsync_time_source.h" |
| 18 #include "cc/trees/layer_tree_host_impl.h" | 17 #include "cc/trees/layer_tree_host_impl.h" |
| 19 #include "cc/trees/proxy.h" | 18 #include "cc/trees/proxy.h" |
| 20 | 19 |
| 21 namespace cc { | 20 namespace cc { |
| 22 | 21 |
| 23 class ContextProvider; | 22 class ContextProvider; |
| 24 class InputHandlerClient; | 23 class InputHandlerClient; |
| 25 class LayerTreeHost; | 24 class LayerTreeHost; |
| 26 class ResourceUpdateQueue; | 25 class ResourceUpdateQueue; |
| 27 class Scheduler; | 26 class Scheduler; |
| 28 class ScopedThreadProxy; | 27 class ScopedThreadProxy; |
| 29 class Thread; | 28 class Thread; |
| 30 | 29 |
| 31 class ThreadProxy : public Proxy, | 30 class ThreadProxy : public Proxy, |
| 32 LayerTreeHostImplClient, | 31 LayerTreeHostImplClient, |
| 33 SchedulerClient, | 32 SchedulerClient, |
| 34 ResourceUpdateControllerClient { | 33 ResourceUpdateControllerClient, |
| 34 VSyncProvider { |
| 35 public: | 35 public: |
| 36 static scoped_ptr<Proxy> Create(LayerTreeHost* layer_tree_host, | 36 static scoped_ptr<Proxy> Create(LayerTreeHost* layer_tree_host, |
| 37 scoped_ptr<Thread> impl_thread); | 37 scoped_ptr<Thread> impl_thread); |
| 38 | 38 |
| 39 virtual ~ThreadProxy(); | 39 virtual ~ThreadProxy(); |
| 40 | 40 |
| 41 // Proxy implementation | 41 // Proxy implementation |
| 42 virtual bool CompositeAndReadback(void* pixels, gfx::Rect rect) OVERRIDE; | 42 virtual bool CompositeAndReadback(void* pixels, gfx::Rect rect) OVERRIDE; |
| 43 virtual void FinishAllRendering() OVERRIDE; | 43 virtual void FinishAllRendering() OVERRIDE; |
| 44 virtual bool IsStarted() const OVERRIDE; | 44 virtual bool IsStarted() const OVERRIDE; |
| 45 virtual void SetLayerTreeHostClientReady() OVERRIDE; | 45 virtual void SetLayerTreeHostClientReady() OVERRIDE; |
| 46 virtual void SetVisible(bool visible) OVERRIDE; | 46 virtual void SetVisible(bool visible) OVERRIDE; |
| 47 virtual void CreateAndInitializeOutputSurface() OVERRIDE; | 47 virtual void CreateAndInitializeOutputSurface() OVERRIDE; |
| 48 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; | 48 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; |
| 49 virtual void SetNeedsAnimate() OVERRIDE; | 49 virtual void SetNeedsAnimate() OVERRIDE; |
| 50 virtual void SetNeedsCommit() OVERRIDE; | 50 virtual void SetNeedsCommit() OVERRIDE; |
| 51 virtual void SetNeedsRedraw(gfx::Rect damage_rect) OVERRIDE; | 51 virtual void SetNeedsRedraw(gfx::Rect damage_rect) OVERRIDE; |
| 52 virtual void SetDeferCommits(bool defer_commits) OVERRIDE; | 52 virtual void SetDeferCommits(bool defer_commits) OVERRIDE; |
| 53 virtual bool CommitRequested() const OVERRIDE; | 53 virtual bool CommitRequested() const OVERRIDE; |
| 54 virtual void MainThreadHasStoppedFlinging() OVERRIDE; | 54 virtual void MainThreadHasStoppedFlinging() OVERRIDE; |
| 55 virtual void Start(scoped_ptr<OutputSurface> first_output_surface) OVERRIDE; | 55 virtual void Start(scoped_ptr<OutputSurface> first_output_surface) OVERRIDE; |
| 56 virtual void Stop() OVERRIDE; | 56 virtual void Stop() OVERRIDE; |
| 57 virtual size_t MaxPartialTextureUpdates() const OVERRIDE; | 57 virtual size_t MaxPartialTextureUpdates() const OVERRIDE; |
| 58 virtual void AcquireLayerTextures() OVERRIDE; | 58 virtual void AcquireLayerTextures() OVERRIDE; |
| 59 virtual void ForceSerializeOnSwapBuffers() OVERRIDE; | 59 virtual void ForceSerializeOnSwapBuffers() OVERRIDE; |
| 60 virtual skia::RefPtr<SkPicture> CapturePicture() OVERRIDE; | 60 virtual skia::RefPtr<SkPicture> CapturePicture() OVERRIDE; |
| 61 virtual scoped_ptr<base::Value> AsValue() const OVERRIDE; | 61 virtual scoped_ptr<base::Value> AsValue() const OVERRIDE; |
| 62 virtual bool CommitPendingForTesting() OVERRIDE; | 62 virtual bool CommitPendingForTesting() OVERRIDE; |
| 63 virtual std::string SchedulerStateAsStringForTesting() OVERRIDE; | |
| 64 | 63 |
| 65 // LayerTreeHostImplClient implementation | 64 // LayerTreeHostImplClient implementation |
| 66 virtual void DidTryInitializeRendererOnImplThread( | 65 virtual void DidTryInitializeRendererOnImplThread( |
| 67 bool success, | 66 bool success, |
| 68 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE; | 67 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE; |
| 69 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE; | 68 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE; |
| 70 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE; | 69 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE; |
| 71 virtual void BeginFrameOnImplThread(base::TimeTicks frame_time) OVERRIDE; | 70 virtual void OnVSyncParametersChanged(base::TimeTicks timebase, |
| 71 base::TimeDelta interval) OVERRIDE; |
| 72 virtual void BeginFrameOnImplThread(base::TimeTicks frame_time) |
| 73 OVERRIDE; |
| 72 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE; | 74 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE; |
| 73 virtual void OnHasPendingTreeStateChanged(bool has_pending_tree) OVERRIDE; | 75 virtual void OnHasPendingTreeStateChanged(bool has_pending_tree) OVERRIDE; |
| 74 virtual void SetNeedsRedrawOnImplThread() OVERRIDE; | 76 virtual void SetNeedsRedrawOnImplThread() OVERRIDE; |
| 75 virtual void SetNeedsRedrawRectOnImplThread(gfx::Rect dirty_rect) OVERRIDE; | 77 virtual void SetNeedsRedrawRectOnImplThread(gfx::Rect dirty_rect) OVERRIDE; |
| 76 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE; | 78 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE; |
| 77 virtual void SetNeedsCommitOnImplThread() OVERRIDE; | 79 virtual void SetNeedsCommitOnImplThread() OVERRIDE; |
| 78 virtual void PostAnimationEventsToMainThreadOnImplThread( | 80 virtual void PostAnimationEventsToMainThreadOnImplThread( |
| 79 scoped_ptr<AnimationEventsVector> queue, | 81 scoped_ptr<AnimationEventsVector> queue, |
| 80 base::Time wall_clock_time) OVERRIDE; | 82 base::Time wall_clock_time) OVERRIDE; |
| 81 virtual bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, | 83 virtual bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, |
| 82 int priority_cutoff) | 84 int priority_cutoff) |
| 83 OVERRIDE; | 85 OVERRIDE; |
| 84 virtual void ReduceWastedContentsTextureMemoryOnImplThread() OVERRIDE; | 86 virtual void ReduceWastedContentsTextureMemoryOnImplThread() OVERRIDE; |
| 85 virtual void SendManagedMemoryStats() OVERRIDE; | 87 virtual void SendManagedMemoryStats() OVERRIDE; |
| 86 virtual bool IsInsideDraw() OVERRIDE; | 88 virtual bool IsInsideDraw() OVERRIDE; |
| 87 virtual void RenewTreePriority() OVERRIDE; | 89 virtual void RenewTreePriority() OVERRIDE; |
| 88 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) | 90 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) |
| 89 OVERRIDE; | 91 OVERRIDE; |
| 90 virtual void DidActivatePendingTree() OVERRIDE; | 92 virtual void DidActivatePendingTree() OVERRIDE; |
| 91 | 93 |
| 92 // SchedulerClient implementation | 94 // SchedulerClient implementation |
| 93 virtual void SetNeedsBeginFrameOnImplThread(bool enable) OVERRIDE; | |
| 94 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE; | 95 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE; |
| 95 virtual ScheduledActionDrawAndSwapResult | 96 virtual ScheduledActionDrawAndSwapResult |
| 96 ScheduledActionDrawAndSwapIfPossible() OVERRIDE; | 97 ScheduledActionDrawAndSwapIfPossible() OVERRIDE; |
| 97 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() | 98 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() |
| 98 OVERRIDE; | 99 OVERRIDE; |
| 99 virtual void ScheduledActionCommit() OVERRIDE; | 100 virtual void ScheduledActionCommit() OVERRIDE; |
| 100 virtual void ScheduledActionCheckForCompletedTileUploads() OVERRIDE; | 101 virtual void ScheduledActionCheckForCompletedTileUploads() OVERRIDE; |
| 101 virtual void ScheduledActionActivatePendingTreeIfNeeded() OVERRIDE; | 102 virtual void ScheduledActionActivatePendingTreeIfNeeded() OVERRIDE; |
| 102 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE; | 103 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE; |
| 103 virtual void ScheduledActionAcquireLayerTexturesForMainThread() OVERRIDE; | 104 virtual void ScheduledActionAcquireLayerTexturesForMainThread() OVERRIDE; |
| 104 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE; | 105 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) OVERRIDE; |
| 105 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; | 106 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE; |
| 106 | 107 |
| 107 // ResourceUpdateControllerClient implementation | 108 // ResourceUpdateControllerClient implementation |
| 108 virtual void ReadyToFinalizeTextureUpdates() OVERRIDE; | 109 virtual void ReadyToFinalizeTextureUpdates() OVERRIDE; |
| 109 | 110 |
| 111 // VSyncProvider implementation |
| 112 virtual void RequestVSyncNotification(VSyncClient* client) OVERRIDE; |
| 113 |
| 114 int MaxFramesPendingForTesting() const { |
| 115 return scheduler_on_impl_thread_->MaxFramesPending(); |
| 116 } |
| 117 |
| 118 int NumFramesPendingForTesting() const { |
| 119 return scheduler_on_impl_thread_->NumFramesPendingForTesting(); |
| 120 } |
| 121 |
| 110 private: | 122 private: |
| 111 ThreadProxy(LayerTreeHost* layer_tree_host, scoped_ptr<Thread> impl_thread); | 123 ThreadProxy(LayerTreeHost* layer_tree_host, scoped_ptr<Thread> impl_thread); |
| 112 | 124 |
| 113 struct BeginFrameAndCommitState { | 125 struct BeginFrameAndCommitState { |
| 114 BeginFrameAndCommitState(); | 126 BeginFrameAndCommitState(); |
| 115 ~BeginFrameAndCommitState(); | 127 ~BeginFrameAndCommitState(); |
| 116 | 128 |
| 117 base::TimeTicks monotonic_frame_begin_time; | 129 base::TimeTicks monotonic_frame_begin_time; |
| 118 scoped_ptr<ScrollAndScaleSet> scroll_info; | 130 scoped_ptr<ScrollAndScaleSet> scroll_info; |
| 119 size_t memory_allocation_limit_bytes; | 131 size_t memory_allocation_limit_bytes; |
| 120 }; | 132 }; |
| 121 | 133 |
| 122 // Called on main thread. | 134 // Called on main thread. |
| 123 void BeginFrameOnMainThread( | 135 void BeginFrameOnMainThread( |
| 124 scoped_ptr<BeginFrameAndCommitState> begin_frame_state); | 136 scoped_ptr<BeginFrameAndCommitState> begin_frame_state); |
| 125 void DidCommitAndDrawFrame(); | 137 void DidCommitAndDrawFrame(); |
| 126 void DidCompleteSwapBuffers(); | 138 void DidCompleteSwapBuffers(); |
| 127 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue, | 139 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue, |
| 128 base::Time wall_clock_time); | 140 base::Time wall_clock_time); |
| 129 void DoCreateAndInitializeOutputSurface(); | 141 void DoCreateAndInitializeOutputSurface(); |
| 130 // |capabilities| is set only when |success| is true. | 142 // |capabilities| is set only when |success| is true. |
| 131 void OnOutputSurfaceInitializeAttempted( | 143 void OnOutputSurfaceInitializeAttempted( |
| 132 bool success, | 144 bool success, |
| 133 const RendererCapabilities& capabilities); | 145 const RendererCapabilities& capabilities); |
| 134 | 146 |
| 135 // Called on impl thread. | 147 // Called on impl thread. |
| 136 struct ReadbackRequest; | 148 struct ReadbackRequest { |
| 137 struct CommitPendingRequest; | 149 CompletionEvent completion; |
| 138 struct SchedulerStateRequest; | 150 bool success; |
| 139 | 151 void* pixels; |
| 152 gfx::Rect rect; |
| 153 }; |
| 154 struct CommitPendingRequest { |
| 155 CompletionEvent completion; |
| 156 bool commit_pending; |
| 157 }; |
| 140 void ForceCommitOnImplThread(CompletionEvent* completion); | 158 void ForceCommitOnImplThread(CompletionEvent* completion); |
| 141 void StartCommitOnImplThread( | 159 void StartCommitOnImplThread( |
| 142 CompletionEvent* completion, | 160 CompletionEvent* completion, |
| 143 ResourceUpdateQueue* queue, | 161 ResourceUpdateQueue* queue, |
| 144 scoped_refptr<cc::ContextProvider> offscreen_context_provider); | 162 scoped_refptr<cc::ContextProvider> offscreen_context_provider); |
| 145 void BeginFrameAbortedByMainThreadOnImplThread(); | 163 void BeginFrameAbortedByMainThreadOnImplThread(); |
| 146 void RequestReadbackOnImplThread(ReadbackRequest* request); | 164 void RequestReadbackOnImplThread(ReadbackRequest* request); |
| 147 void FinishAllRenderingOnImplThread(CompletionEvent* completion); | 165 void FinishAllRenderingOnImplThread(CompletionEvent* completion); |
| 148 void InitializeImplOnImplThread(CompletionEvent* completion); | 166 void InitializeImplOnImplThread(CompletionEvent* completion); |
| 149 void SetLayerTreeHostClientReadyOnImplThread(); | 167 void SetLayerTreeHostClientReadyOnImplThread(); |
| 150 void SetVisibleOnImplThread(CompletionEvent* completion, bool visible); | 168 void SetVisibleOnImplThread(CompletionEvent* completion, bool visible); |
| 151 void HasInitializedOutputSurfaceOnImplThread( | 169 void HasInitializedOutputSurfaceOnImplThread( |
| 152 CompletionEvent* completion, | 170 CompletionEvent* completion, |
| 153 bool* has_initialized_output_surface); | 171 bool* has_initialized_output_surface); |
| 154 void InitializeOutputSurfaceOnImplThread( | 172 void InitializeOutputSurfaceOnImplThread( |
| 155 CompletionEvent* completion, | 173 CompletionEvent* completion, |
| 156 scoped_ptr<OutputSurface> output_surface, | 174 scoped_ptr<OutputSurface> output_surface, |
| 157 scoped_refptr<ContextProvider> offscreen_context_provider, | 175 scoped_refptr<ContextProvider> offscreen_context_provider, |
| 158 bool* success, | 176 bool* success, |
| 159 RendererCapabilities* capabilities); | 177 RendererCapabilities* capabilities); |
| 160 void FinishGLOnImplThread(CompletionEvent* completion); | 178 void FinishGLOnImplThread(CompletionEvent* completion); |
| 161 void LayerTreeHostClosedOnImplThread(CompletionEvent* completion); | 179 void LayerTreeHostClosedOnImplThread(CompletionEvent* completion); |
| 162 void AcquireLayerTexturesForMainThreadOnImplThread( | 180 void AcquireLayerTexturesForMainThreadOnImplThread( |
| 163 CompletionEvent* completion); | 181 CompletionEvent* completion); |
| 164 ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapInternal( | 182 ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapInternal( |
| 165 bool forced_draw); | 183 bool forced_draw); |
| 166 void ForceSerializeOnSwapBuffersOnImplThread(CompletionEvent* completion); | 184 void ForceSerializeOnSwapBuffersOnImplThread(CompletionEvent* completion); |
| 167 void CheckOutputSurfaceStatusOnImplThread(); | 185 void CheckOutputSurfaceStatusOnImplThread(); |
| 168 void CommitPendingOnImplThreadForTesting(CommitPendingRequest* request); | 186 void CommitPendingOnImplThreadForTesting(CommitPendingRequest* request); |
| 169 void SchedulerStateAsStringOnImplThreadForTesting( | |
| 170 SchedulerStateRequest* request); | |
| 171 void CapturePictureOnImplThread(CompletionEvent* completion, | 187 void CapturePictureOnImplThread(CompletionEvent* completion, |
| 172 skia::RefPtr<SkPicture>* picture); | 188 skia::RefPtr<SkPicture>* picture); |
| 173 void AsValueOnImplThread(CompletionEvent* completion, | 189 void AsValueOnImplThread(CompletionEvent* completion, |
| 174 base::DictionaryValue* state) const; | 190 base::DictionaryValue* state) const; |
| 175 void RenewTreePriorityOnImplThread(); | 191 void RenewTreePriorityOnImplThread(); |
| 176 void DidSwapUseIncompleteTileOnImplThread(); | 192 void DidSwapUseIncompleteTileOnImplThread(); |
| 177 void StartScrollbarAnimationOnImplThread(); | 193 void StartScrollbarAnimationOnImplThread(); |
| 178 void MainThreadHasStoppedFlingingOnImplThread(); | 194 void MainThreadHasStoppedFlingingOnImplThread(); |
| 179 | 195 |
| 180 // Accessed on main thread only. | 196 // Accessed on main thread only. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 scoped_ptr<ResourceUpdateController> | 245 scoped_ptr<ResourceUpdateController> |
| 230 current_resource_update_controller_on_impl_thread_; | 246 current_resource_update_controller_on_impl_thread_; |
| 231 | 247 |
| 232 // Set when the next draw should post DidCommitAndDrawFrame to the main | 248 // Set when the next draw should post DidCommitAndDrawFrame to the main |
| 233 // thread. | 249 // thread. |
| 234 bool next_frame_is_newly_committed_frame_on_impl_thread_; | 250 bool next_frame_is_newly_committed_frame_on_impl_thread_; |
| 235 | 251 |
| 236 bool throttle_frame_production_; | 252 bool throttle_frame_production_; |
| 237 bool begin_frame_scheduling_enabled_; | 253 bool begin_frame_scheduling_enabled_; |
| 238 bool using_synchronous_renderer_compositor_; | 254 bool using_synchronous_renderer_compositor_; |
| 255 VSyncClient* vsync_client_; |
| 239 | 256 |
| 240 bool inside_draw_; | 257 bool inside_draw_; |
| 241 | 258 |
| 242 bool defer_commits_; | 259 bool defer_commits_; |
| 243 scoped_ptr<BeginFrameAndCommitState> pending_deferred_commit_; | 260 scoped_ptr<BeginFrameAndCommitState> pending_deferred_commit_; |
| 244 | 261 |
| 245 base::TimeTicks smoothness_takes_priority_expiration_time_; | 262 base::TimeTicks smoothness_takes_priority_expiration_time_; |
| 246 bool renew_tree_priority_on_impl_thread_pending_; | 263 bool renew_tree_priority_on_impl_thread_pending_; |
| 247 | 264 |
| 248 RollingTimeDeltaHistory draw_duration_history_; | 265 RollingTimeDeltaHistory draw_duration_history_; |
| 249 | 266 |
| 250 DISALLOW_COPY_AND_ASSIGN(ThreadProxy); | 267 DISALLOW_COPY_AND_ASSIGN(ThreadProxy); |
| 251 }; | 268 }; |
| 252 | 269 |
| 253 } // namespace cc | 270 } // namespace cc |
| 254 | 271 |
| 255 #endif // CC_TREES_THREAD_PROXY_H_ | 272 #endif // CC_TREES_THREAD_PROXY_H_ |
| OLD | NEW |