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 | 22 |
18 // an interface with the implementation provided by ThreadProxy and will be | 23 // This class is a proxy to the impl side of the compositor. It is created and |
Wez
2015/11/21 01:00:30
nit: Can we clarify in what sense it is a "proxy t
Khushal
2015/11/23 20:07:20
ProxyImpl now has the code from ThreadProxy that g
| |
19 // made an independent class. | 24 // owned by the ChannelImpl implementation. The class lives entirely on the |
20 // The methods added to this interface should only use the CompositorThreadOnly | 25 // impl thread. |
21 // variables from ThreadProxy. | 26 class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient), |
22 // See crbug/527200 | 27 public NON_EXPORTED_BASE(SchedulerClient) { |
23 class CC_EXPORT ProxyImpl { | 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 // The members of this struct should be accessed on the impl thread only when | |
38 // the main thread is blocked for a commit. | |
39 struct BlockedMainCommitOnly { | |
40 BlockedMainCommitOnly(); | |
41 ~BlockedMainCommitOnly(); | |
42 LayerTreeHost* layer_tree_host; | |
43 }; | |
44 | |
45 // LayerTreeHostImplClient implementation | |
46 void UpdateRendererCapabilitiesOnImplThread() override; | |
47 void DidLoseOutputSurfaceOnImplThread() override; | |
48 void CommitVSyncParameters(base::TimeTicks timebase, | |
49 base::TimeDelta interval) override; | |
50 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override; | |
51 void SetMaxSwapsPendingOnImplThread(int max) override; | |
52 void DidSwapBuffersOnImplThread() override; | |
53 void DidSwapBuffersCompleteOnImplThread() override; | |
54 void OnResourcelessSoftareDrawStateChanged(bool resourceless_draw) override; | |
55 void OnCanDrawStateChanged(bool can_draw) override; | |
56 void NotifyReadyToActivate() override; | |
57 void NotifyReadyToDraw() override; | |
58 // Please call these 3 functions through | |
59 // LayerTreeHostImpl's SetNeedsRedraw(), SetNeedsRedrawRect() and | |
60 // SetNeedsAnimate(). | |
61 void SetNeedsRedrawOnImplThread() override; | |
62 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override; | |
63 void SetNeedsAnimateOnImplThread() override; | |
64 void SetNeedsPrepareTilesOnImplThread() override; | |
65 void SetNeedsCommitOnImplThread() override; | |
66 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override; | |
67 void PostAnimationEventsToMainThreadOnImplThread( | |
68 scoped_ptr<AnimationEventsVector> queue) override; | |
69 bool IsInsideDraw() override; | |
70 void RenewTreePriority() override; | |
71 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, | |
72 base::TimeDelta delay) override; | |
73 void DidActivateSyncTree() override; | |
74 void WillPrepareTiles() override; | |
75 void DidPrepareTiles() override; | |
76 void DidCompletePageScaleAnimationOnImplThread() override; | |
77 void OnDrawForOutputSurface() override; | |
78 // This should only be called by LayerTreeHostImpl::PostFrameTimingEvents. | |
79 void PostFrameTimingEventsOnImplThread( | |
80 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | |
81 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | |
82 override; | |
83 | |
84 // SchedulerClient implementation | |
85 void WillBeginImplFrame(const BeginFrameArgs& args) override; | |
86 void DidFinishImplFrame() override; | |
87 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override; | |
88 DrawResult ScheduledActionDrawAndSwapIfPossible() override; | |
89 DrawResult ScheduledActionDrawAndSwapForced() override; | |
90 void ScheduledActionAnimate() override; | |
91 void ScheduledActionCommit() override; | |
92 void ScheduledActionActivateSyncTree() override; | |
93 void ScheduledActionBeginOutputSurfaceCreation() override; | |
94 void ScheduledActionPrepareTiles() override; | |
95 void ScheduledActionInvalidateOutputSurface() override; | |
96 void SendBeginFramesToChildren(const BeginFrameArgs& args) override; | |
97 void SendBeginMainFrameNotExpectedSoon() override; | |
98 | |
99 bool HasCommitCompletionEvent() const; | |
100 bool next_commit_waits_for_activation() const { | |
101 return next_commit_waits_for_activation_; | |
102 } | |
103 | |
104 protected: | |
105 ProxyImpl(ChannelImpl* channel_impl, | |
106 LayerTreeHost* layer_tree_host, | |
107 TaskRunnerProvider* task_runner_provider, | |
108 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
109 | |
24 private: | 110 private: |
25 friend class ThreadedChannel; | 111 friend class ThreadedChannel; |
112 friend class ProxyImplForTest; | |
26 | 113 |
27 // Callback for impl side commands received from the channel. | 114 // ProxyImpl interface for the channel. |
28 virtual void SetThrottleFrameProductionOnImpl(bool throttle) = 0; | 115 // virtual for testing. |
116 virtual void SetThrottleFrameProductionOnImpl(bool throttle); | |
29 virtual void UpdateTopControlsStateOnImpl(TopControlsState constraints, | 117 virtual void UpdateTopControlsStateOnImpl(TopControlsState constraints, |
30 TopControlsState current, | 118 TopControlsState current, |
31 bool animate) = 0; | 119 bool animate); |
32 virtual void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) = 0; | 120 virtual void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface); |
33 virtual void MainThreadHasStoppedFlingingOnImpl() = 0; | 121 virtual void MainThreadHasStoppedFlingingOnImpl(); |
34 virtual void SetInputThrottledUntilCommitOnImpl(bool is_throttled) = 0; | 122 virtual void SetInputThrottledUntilCommitOnImpl(bool is_throttled); |
35 virtual void SetDeferCommitsOnImpl(bool defer_commits) const = 0; | 123 virtual void SetDeferCommitsOnImpl(bool defer_commits) const; |
36 virtual void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) = 0; | 124 virtual void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect); |
37 virtual void SetNeedsCommitOnImpl() = 0; | 125 virtual void SetNeedsCommitOnImpl(); |
38 virtual void FinishAllRenderingOnImpl(CompletionEvent* completion) = 0; | 126 virtual void BeginMainFrameAbortedOnImpl( |
39 virtual void SetVisibleOnImpl(bool visible) = 0; | 127 CommitEarlyOutReason reason, |
40 virtual void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) = 0; | 128 base::TimeTicks main_thread_start_time); |
41 virtual void FinishGLOnImpl(CompletionEvent* completion) = 0; | 129 virtual void FinishAllRenderingOnImpl(CompletionEvent* completion); |
130 virtual void SetVisibleOnImpl(bool visible); | |
131 virtual void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion); | |
132 virtual void FinishGLOnImpl(CompletionEvent* completion); | |
42 virtual void MainFrameWillHappenOnImplForTesting( | 133 virtual void MainFrameWillHappenOnImplForTesting( |
43 CompletionEvent* completion, | 134 CompletionEvent* completion, |
44 bool* main_frame_will_happen) = 0; | 135 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, | 136 virtual void StartCommitOnImpl(CompletionEvent* completion, |
49 LayerTreeHost* layer_tree_host, | 137 LayerTreeHost* layer_tree_host, |
50 base::TimeTicks main_thread_start_time, | 138 base::TimeTicks main_thread_start_time, |
51 bool hold_commit_for_activation) = 0; | 139 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 | 140 |
56 // TODO(khushalsagar): Rename as GetWeakPtr() once ThreadProxy is split. | 141 DrawResult DrawSwapInternal(bool forced_draw); |
57 virtual base::WeakPtr<ProxyImpl> GetImplWeakPtr() = 0; | |
58 | 142 |
59 protected: | 143 bool IsImplThread() const; |
60 virtual ~ProxyImpl() {} | 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 |