[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #ifndef CC_TREES_SINGLE_THREAD_PROXY_H_ |
| 6 | #define CC_TREES_SINGLE_THREAD_PROXY_H_ |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 7 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 8 | #include <limits> |
| 9 | |
[email protected] | 1b0df50 | 2013-06-27 23:39:58 | [diff] [blame] | 10 | #include "base/time/time.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 11 | #include "cc/animation/animation_events.h" |
[email protected] | df3c24c9 | 2013-06-19 03:54:35 | [diff] [blame] | 12 | #include "cc/output/begin_frame_args.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 13 | #include "cc/trees/layer_tree_host_impl.h" |
| 14 | #include "cc/trees/proxy.h" |
[email protected] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 15 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 16 | namespace cc { |
| 17 | |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame] | 18 | class ContextProvider; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 19 | class LayerTreeHost; |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 20 | class LayerTreeHostSingleThreadClient; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 21 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 22 | class SingleThreadProxy : public Proxy, LayerTreeHostImplClient { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 23 | public: |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 24 | static scoped_ptr<Proxy> Create( |
| 25 | LayerTreeHost* layer_tree_host, |
| 26 | LayerTreeHostSingleThreadClient* client); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 27 | virtual ~SingleThreadProxy(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 28 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 29 | // Proxy implementation |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 30 | virtual bool CompositeAndReadback(void* pixels, |
| 31 | const gfx::Rect& rect) OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 32 | virtual void FinishAllRendering() OVERRIDE; |
| 33 | virtual bool IsStarted() const OVERRIDE; |
[email protected] | 14bd554 | 2013-05-08 21:51:30 | [diff] [blame] | 34 | virtual void SetLayerTreeHostClientReady() OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 35 | virtual void SetVisible(bool visible) OVERRIDE; |
[email protected] | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 36 | virtual void CreateAndInitializeOutputSurface() OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 37 | virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE; |
[email protected] | 8b9e52b | 2014-01-17 16:35:31 | [diff] [blame] | 38 | virtual void SetNeedsAnimate() OVERRIDE; |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 39 | virtual void SetNeedsUpdateLayers() OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 40 | virtual void SetNeedsCommit() OVERRIDE; |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 41 | virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) OVERRIDE; |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 42 | virtual void SetNextCommitWaitsForActivation() OVERRIDE; |
[email protected] | df09e05 | 2013-07-31 18:59:50 | [diff] [blame] | 43 | virtual void NotifyInputThrottledUntilCommit() OVERRIDE {} |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 44 | virtual void SetDeferCommits(bool defer_commits) OVERRIDE; |
| 45 | virtual bool CommitRequested() const OVERRIDE; |
[email protected] | 971728d | 2013-10-26 10:39:31 | [diff] [blame] | 46 | virtual bool BeginMainFrameRequested() const OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 47 | virtual void MainThreadHasStoppedFlinging() OVERRIDE {} |
[email protected] | e96e343 | 2013-12-19 18:56:07 | [diff] [blame] | 48 | virtual void Start() OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 49 | virtual void Stop() OVERRIDE; |
| 50 | virtual size_t MaxPartialTextureUpdates() const OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 51 | virtual void ForceSerializeOnSwapBuffers() OVERRIDE; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 52 | virtual scoped_ptr<base::Value> AsValue() const OVERRIDE; |
| 53 | virtual bool CommitPendingForTesting() OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 54 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 55 | // LayerTreeHostImplClient implementation |
[email protected] | fa33903 | 2014-02-18 22:11:59 | [diff] [blame] | 56 | virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 57 | virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE; |
[email protected] | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 58 | virtual void CommitVSyncParameters(base::TimeTicks timebase, |
| 59 | base::TimeDelta interval) OVERRIDE {} |
| 60 | virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) OVERRIDE {} |
[email protected] | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 61 | virtual void SetMaxSwapsPendingOnImplThread(int max) OVERRIDE {} |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 62 | virtual void DidSwapBuffersOnImplThread() OVERRIDE; |
[email protected] | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 63 | virtual void DidSwapBuffersCompleteOnImplThread() OVERRIDE; |
[email protected] | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 64 | virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE {} |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 65 | virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE; |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 66 | virtual void NotifyReadyToActivate() OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 67 | virtual void SetNeedsRedrawOnImplThread() OVERRIDE; |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 68 | virtual void SetNeedsRedrawRectOnImplThread( |
| 69 | const gfx::Rect& dirty_rect) OVERRIDE; |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 70 | virtual void SetNeedsManageTilesOnImplThread() OVERRIDE; |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 71 | virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 72 | virtual void SetNeedsCommitOnImplThread() OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 73 | virtual void PostAnimationEventsToMainThreadOnImplThread( |
[email protected] | 85b5750 | 2014-03-11 15:37:48 | [diff] [blame] | 74 | scoped_ptr<AnimationEventsVector> events) OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 75 | virtual bool ReduceContentsTextureMemoryOnImplThread( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 76 | size_t limit_bytes, |
| 77 | int priority_cutoff) OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 78 | virtual void SendManagedMemoryStats() OVERRIDE; |
| 79 | virtual bool IsInsideDraw() OVERRIDE; |
| 80 | virtual void RenewTreePriority() OVERRIDE {} |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 81 | virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) |
| 82 | OVERRIDE {} |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame] | 83 | virtual void DidActivatePendingTree() OVERRIDE {} |
[email protected] | bac0e55 | 2013-11-05 22:38:51 | [diff] [blame] | 84 | virtual void DidManageTiles() OVERRIDE {} |
[email protected] | 2c6998c | 2014-04-03 11:33:57 | [diff] [blame] | 85 | virtual void SetDebugState(const LayerTreeDebugState& debug_state) OVERRIDE {} |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 86 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 87 | // Called by the legacy path where RenderWidget does the scheduling. |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 88 | void CompositeImmediately(base::TimeTicks frame_begin_time); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 89 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 90 | private: |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 91 | SingleThreadProxy(LayerTreeHost* layer_tree_host, |
| 92 | LayerTreeHostSingleThreadClient* client); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 93 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 94 | bool CommitAndComposite(base::TimeTicks frame_begin_time, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 95 | const gfx::Rect& device_viewport_damage_rect, |
[email protected] | 2921d04 | 2013-05-10 05:01:39 | [diff] [blame] | 96 | bool for_readback, |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 97 | LayerTreeHostImpl::FrameData* frame); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 98 | void DoCommit(scoped_ptr<ResourceUpdateQueue> queue); |
[email protected] | 3b2eb88 | 2014-04-24 19:48:56 | [diff] [blame] | 99 | bool DoComposite(base::TimeTicks frame_begin_time, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 100 | const gfx::Rect& device_viewport_damage_rect, |
[email protected] | e51444a | 2013-12-10 23:05:01 | [diff] [blame] | 101 | bool for_readback, |
| 102 | LayerTreeHostImpl::FrameData* frame); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 103 | void DidSwapFrame(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 104 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 105 | bool ShouldComposite() const; |
[email protected] | d9fce672 | 2013-08-30 01:10:01 | [diff] [blame] | 106 | void UpdateBackgroundAnimateTicking(); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 107 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 108 | // Accessed on main thread only. |
| 109 | LayerTreeHost* layer_tree_host_; |
[email protected] | 943528e | 2013-11-07 05:01:32 | [diff] [blame] | 110 | LayerTreeHostSingleThreadClient* client_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 111 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 112 | // Used on the Thread, but checked on main thread during |
| 113 | // initialization/shutdown. |
| 114 | scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 115 | RendererCapabilities renderer_capabilities_for_main_thread_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 116 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 117 | bool next_frame_is_newly_committed_frame_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 118 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 119 | bool inside_draw_; |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 120 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | // For use in the single-threaded case. In debug builds, it pretends that the |
| 125 | // code is running on the impl thread to satisfy assertion checks. |
| 126 | class DebugScopedSetImplThread { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 127 | public: |
| 128 | explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) { |
[email protected] | 767f38d7 | 2014-03-18 21:26:41 | [diff] [blame] | 129 | #if DCHECK_IS_ON |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 130 | previous_value_ = proxy_->impl_thread_is_overridden_; |
| 131 | proxy_->SetCurrentThreadIsImplThread(true); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 132 | #endif |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 133 | } |
| 134 | ~DebugScopedSetImplThread() { |
[email protected] | 767f38d7 | 2014-03-18 21:26:41 | [diff] [blame] | 135 | #if DCHECK_IS_ON |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 136 | proxy_->SetCurrentThreadIsImplThread(previous_value_); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 137 | #endif |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | private: |
| 141 | bool previous_value_; |
| 142 | Proxy* proxy_; |
| 143 | |
| 144 | DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | // For use in the single-threaded case. In debug builds, it pretends that the |
| 148 | // code is running on the main thread to satisfy assertion checks. |
| 149 | class DebugScopedSetMainThread { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 150 | public: |
| 151 | explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) { |
[email protected] | 767f38d7 | 2014-03-18 21:26:41 | [diff] [blame] | 152 | #if DCHECK_IS_ON |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 153 | previous_value_ = proxy_->impl_thread_is_overridden_; |
| 154 | proxy_->SetCurrentThreadIsImplThread(false); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 155 | #endif |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 156 | } |
| 157 | ~DebugScopedSetMainThread() { |
[email protected] | 767f38d7 | 2014-03-18 21:26:41 | [diff] [blame] | 158 | #if DCHECK_IS_ON |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 159 | proxy_->SetCurrentThreadIsImplThread(previous_value_); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 160 | #endif |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | private: |
| 164 | bool previous_value_; |
| 165 | Proxy* proxy_; |
| 166 | |
| 167 | DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | // For use in the single-threaded case. In debug builds, it pretends that the |
| 171 | // code is running on the impl thread and that the main thread is blocked to |
| 172 | // satisfy assertion checks |
| 173 | class DebugScopedSetImplThreadAndMainThreadBlocked { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 174 | public: |
| 175 | explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy) |
| 176 | : impl_thread_(proxy), main_thread_blocked_(proxy) {} |
| 177 | |
| 178 | private: |
| 179 | DebugScopedSetImplThread impl_thread_; |
| 180 | DebugScopedSetMainThreadBlocked main_thread_blocked_; |
| 181 | |
| 182 | DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 183 | }; |
| 184 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 185 | } // namespace cc |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 186 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 187 | #endif // CC_TREES_SINGLE_THREAD_PROXY_H_ |