OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_PROXY_IMPL_H_ | 5 #ifndef CC_TREES_PROXY_IMPL_H_ |
6 #define CC_TREES_PROXY_IMPL_H_ | 6 #define CC_TREES_PROXY_IMPL_H_ |
7 | 7 |
8 #include "base/macros.h" | |
9 #include "base/memory/scoped_ptr.h" | |
8 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
9 #include "cc/base/cc_export.h" | 11 #include "base/time/time.h" |
12 #include "cc/animation/animation_events.h" | |
10 #include "cc/base/completion_event.h" | 13 #include "cc/base/completion_event.h" |
14 #include "cc/base/delayed_unique_notifier.h" | |
11 #include "cc/input/top_controls_state.h" | 15 #include "cc/input/top_controls_state.h" |
12 #include "cc/output/output_surface.h" | |
13 #include "cc/scheduler/commit_earlyout_reason.h" | 16 #include "cc/scheduler/commit_earlyout_reason.h" |
14 #include "cc/trees/proxy_common.h" | 17 #include "cc/scheduler/scheduler.h" |
18 #include "cc/trees/channel_impl.h" | |
19 #include "cc/trees/layer_tree_host_impl.h" | |
15 | 20 |
16 namespace cc { | 21 namespace cc { |
17 // TODO(khushalsagar): The impl side of ThreadProxy. It is currently defined as | |
18 // an interface with the implementation provided by ThreadProxy and will be | |
19 // made an independent class. | |
20 // The methods added to this interface should only use the CompositorThreadOnly | |
21 // variables from ThreadProxy. | |
22 // See crbug/527200 | |
23 class CC_EXPORT ProxyImpl { | |
24 private: | |
25 friend class ThreadedChannel; | |
26 | 22 |
27 // Callback for impl side commands received from the channel. | 23 // This class aggregates all the interactions that the main side of the |
28 virtual void SetThrottleFrameProductionOnImpl(bool throttle) = 0; | 24 // compositor needs to have with the impl side. It is created and owned by the |
25 // ChannelImpl implementation. The class lives entirely on the impl thread. | |
Wez
2015/11/26 00:39:47
\o/
Much clearer - thanks!
| |
26 class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient), | |
27 public NON_EXPORTED_BASE(SchedulerClient) { | |
28 public: | |
29 static scoped_ptr<ProxyImpl> Create( | |
30 ChannelImpl* channel_impl, | |
31 LayerTreeHost* layer_tree_host, | |
32 TaskRunnerProvider* task_runner_provider, | |
33 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
34 | |
35 ~ProxyImpl() override; | |
36 | |
37 // Virtual for testing. | |
38 virtual void SetThrottleFrameProductionOnImpl(bool throttle); | |
29 virtual void UpdateTopControlsStateOnImpl(TopControlsState constraints, | 39 virtual void UpdateTopControlsStateOnImpl(TopControlsState constraints, |
30 TopControlsState current, | 40 TopControlsState current, |
31 bool animate) = 0; | 41 bool animate); |
32 virtual void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) = 0; | 42 virtual void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface); |
33 virtual void MainThreadHasStoppedFlingingOnImpl() = 0; | 43 virtual void MainThreadHasStoppedFlingingOnImpl(); |
34 virtual void SetInputThrottledUntilCommitOnImpl(bool is_throttled) = 0; | 44 virtual void SetInputThrottledUntilCommitOnImpl(bool is_throttled); |
35 virtual void SetDeferCommitsOnImpl(bool defer_commits) const = 0; | 45 virtual void SetDeferCommitsOnImpl(bool defer_commits) const; |
36 virtual void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) = 0; | 46 virtual void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect); |
37 virtual void SetNeedsCommitOnImpl() = 0; | 47 virtual void SetNeedsCommitOnImpl(); |
38 virtual void FinishAllRenderingOnImpl(CompletionEvent* completion) = 0; | 48 virtual void BeginMainFrameAbortedOnImpl( |
39 virtual void SetVisibleOnImpl(bool visible) = 0; | 49 CommitEarlyOutReason reason, |
40 virtual void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) = 0; | 50 base::TimeTicks main_thread_start_time); |
41 virtual void FinishGLOnImpl(CompletionEvent* completion) = 0; | 51 virtual void FinishAllRenderingOnImpl(CompletionEvent* completion); |
52 virtual void SetVisibleOnImpl(bool visible); | |
53 virtual void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion); | |
54 virtual void FinishGLOnImpl(CompletionEvent* completion); | |
42 virtual void MainFrameWillHappenOnImplForTesting( | 55 virtual void MainFrameWillHappenOnImplForTesting( |
43 CompletionEvent* completion, | 56 CompletionEvent* completion, |
44 bool* main_frame_will_happen) = 0; | 57 bool* main_frame_will_happen); |
45 virtual void BeginMainFrameAbortedOnImpl( | |
46 CommitEarlyOutReason reason, | |
47 base::TimeTicks main_thread_start_time) = 0; | |
48 virtual void StartCommitOnImpl(CompletionEvent* completion, | 58 virtual void StartCommitOnImpl(CompletionEvent* completion, |
49 LayerTreeHost* layer_tree_host, | 59 LayerTreeHost* layer_tree_host, |
50 base::TimeTicks main_thread_start_time, | 60 base::TimeTicks main_thread_start_time, |
51 bool hold_commit_for_activation) = 0; | 61 bool hold_commit_for_activation); |
52 virtual void InitializeImplOnImpl(CompletionEvent* completion, | |
53 LayerTreeHost* layer_tree_host) = 0; | |
54 virtual void LayerTreeHostClosedOnImpl(CompletionEvent* completion) = 0; | |
55 | 62 |
56 // TODO(khushalsagar): Rename as GetWeakPtr() once ThreadProxy is split. | 63 bool HasCommitCompletionEventForTesting() const; |
57 virtual base::WeakPtr<ProxyImpl> GetImplWeakPtr() = 0; | 64 bool GetNextCommitWaitsForActivationForTesting() const; |
58 | 65 |
59 protected: | 66 protected: |
60 virtual ~ProxyImpl() {} | 67 // protected for testing. |
68 ProxyImpl(ChannelImpl* channel_impl, | |
69 LayerTreeHost* layer_tree_host, | |
70 TaskRunnerProvider* task_runner_provider, | |
71 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
72 | |
73 private: | |
74 // The members of this struct should be accessed on the impl thread only when | |
75 // the main thread is blocked for a commit. | |
76 struct BlockedMainCommitOnly { | |
77 BlockedMainCommitOnly(); | |
78 ~BlockedMainCommitOnly(); | |
79 LayerTreeHost* layer_tree_host; | |
80 }; | |
81 | |
82 friend class ProxyImplForTest; | |
83 friend class ThreadedChannelTestBeginMainFrameNotExpectedSoon; | |
84 friend class ThreadedChannelTestSetAnimationEvents; | |
85 friend class ThreadedChannelTestLoseOutputSurface; | |
86 friend class ThreadedChannelTestPageScaleAnimation; | |
87 | |
88 // LayerTreeHostImplClient implementation | |
89 void UpdateRendererCapabilitiesOnImplThread() override; | |
90 void DidLoseOutputSurfaceOnImplThread() override; | |
91 void CommitVSyncParameters(base::TimeTicks timebase, | |
92 base::TimeDelta interval) override; | |
93 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override; | |
94 void DidSwapBuffersOnImplThread() override; | |
95 void DidSwapBuffersCompleteOnImplThread() override; | |
96 void OnResourcelessSoftareDrawStateChanged(bool resourceless_draw) override; | |
97 void OnCanDrawStateChanged(bool can_draw) override; | |
98 void NotifyReadyToActivate() override; | |
99 void NotifyReadyToDraw() override; | |
100 // Please call these 3 functions through | |
101 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and | |
102 // SetNeedsAnimate(). | |
103 void SetNeedsRedrawOnImplThread() override; | |
104 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override; | |
105 void SetNeedsAnimateOnImplThread() override; | |
106 void SetNeedsPrepareTilesOnImplThread() override; | |
107 void SetNeedsCommitOnImplThread() override; | |
108 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override; | |
109 void PostAnimationEventsToMainThreadOnImplThread( | |
110 scoped_ptr<AnimationEventsVector> queue) override; | |
111 bool IsInsideDraw() override; | |
112 void RenewTreePriority() override; | |
113 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, | |
114 base::TimeDelta delay) override; | |
115 void DidActivateSyncTree() override; | |
116 void WillPrepareTiles() override; | |
117 void DidPrepareTiles() override; | |
118 void DidCompletePageScaleAnimationOnImplThread() override; | |
119 void OnDrawForOutputSurface() override; | |
120 // This should only be called by LayerTreeHostImpl::PostFrameTimingEvents. | |
121 void PostFrameTimingEventsOnImplThread( | |
122 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | |
123 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | |
124 override; | |
125 | |
126 // SchedulerClient implementation | |
127 void WillBeginImplFrame(const BeginFrameArgs& args) override; | |
128 void DidFinishImplFrame() override; | |
129 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override; | |
130 DrawResult ScheduledActionDrawAndSwapIfPossible() override; | |
131 DrawResult ScheduledActionDrawAndSwapForced() override; | |
132 void ScheduledActionAnimate() override; | |
133 void ScheduledActionCommit() override; | |
134 void ScheduledActionActivateSyncTree() override; | |
135 void ScheduledActionBeginOutputSurfaceCreation() override; | |
136 void ScheduledActionPrepareTiles() override; | |
137 void ScheduledActionInvalidateOutputSurface() override; | |
138 void SendBeginFramesToChildren(const BeginFrameArgs& args) override; | |
139 void SendBeginMainFrameNotExpectedSoon() override; | |
140 | |
141 DrawResult DrawAndSwapInternal(bool forced_draw); | |
142 | |
143 bool IsImplThread() const; | |
144 bool IsMainThreadBlocked() const; | |
145 | |
146 const int layer_tree_host_id_; | |
147 | |
148 scoped_ptr<Scheduler> scheduler_; | |
149 | |
150 // Set when the main thread is waiting on a pending tree activation. | |
151 bool next_commit_waits_for_activation_; | |
152 | |
153 // Set when the main thread is waiting on a commit to complete or on a | |
154 // pending tree activation. | |
155 CompletionEvent* commit_completion_event_; | |
156 | |
157 // Set when the next draw should post DidCommitAndDrawFrame to the main | |
158 // thread. | |
159 bool next_frame_is_newly_committed_frame_; | |
160 | |
161 bool inside_draw_; | |
162 bool input_throttled_until_commit_; | |
163 | |
164 // Whether a commit has been completed since the last time animations were | |
165 // ticked. If this happens, we need to animate again. | |
166 bool did_commit_after_animating_; | |
167 | |
168 TaskRunnerProvider* task_runner_provider_; | |
169 | |
170 DelayedUniqueNotifier smoothness_priority_expiration_notifier_; | |
171 | |
172 scoped_ptr<BeginFrameSource> external_begin_frame_source_; | |
173 | |
174 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | |
175 | |
176 // Values used to keep track of frame durations. Used only in frame timing. | |
177 BeginFrameArgs last_begin_main_frame_args_; | |
178 BeginFrameArgs last_processed_begin_main_frame_args_; | |
179 | |
180 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_; | |
181 | |
182 ChannelImpl* channel_impl_; | |
183 | |
184 // Use accessors instead of this variable directly. | |
185 BlockedMainCommitOnly main_thread_blocked_commit_vars_unsafe_; | |
186 BlockedMainCommitOnly& blocked_main_commit(); | |
187 | |
188 DISALLOW_COPY_AND_ASSIGN(ProxyImpl); | |
61 }; | 189 }; |
62 | 190 |
63 } // namespace cc | 191 } // namespace cc |
64 | 192 |
65 #endif // CC_TREES_PROXY_IMPL_H_ | 193 #endif // CC_TREES_PROXY_IMPL_H_ |
OLD | NEW |