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