khushalsagar | 5d6eb98 | 2015-09-25 22:44:56 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CC_TREES_PROXY_MAIN_H_ |
| 6 | #define CC_TREES_PROXY_MAIN_H_ |
| 7 | |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 8 | #include "base/macros.h" |
chrishtr | ac41ff9 | 2017-03-17 05:07:30 | [diff] [blame] | 9 | #include "cc/cc_export.h" |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 10 | #include "cc/input/browser_controls_state.h" |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 11 | #include "cc/trees/proxy.h" |
khushalsagar | e3c9fa9 | 2015-10-28 02:08:29 | [diff] [blame] | 12 | #include "cc/trees/proxy_common.h" |
khushalsagar | 5d6eb98 | 2015-09-25 22:44:56 | [diff] [blame] | 13 | |
| 14 | namespace cc { |
loyso | e926437dd | 2016-01-14 22:55:30 | [diff] [blame] | 15 | |
loyso | c601b7b8 | 2016-11-10 02:56:44 | [diff] [blame] | 16 | class MutatorEvents; |
khushalsagar | 12020cd4 | 2016-11-21 09:22:48 | [diff] [blame] | 17 | class CompletionEvent; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 18 | class LayerTreeFrameSink; |
khushalsagar | e0e4486e | 2017-01-25 03:15:03 | [diff] [blame] | 19 | class LayerTreeHost; |
flackr | f54e9b4 | 2016-05-31 15:20:10 | [diff] [blame] | 20 | class LayerTreeMutator; |
khushalsagar | 12020cd4 | 2016-11-21 09:22:48 | [diff] [blame] | 21 | class ProxyImpl; |
khushalsagar | 5d6eb98 | 2015-09-25 22:44:56 | [diff] [blame] | 22 | |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 23 | // This class aggregates all interactions that the impl side of the compositor |
| 24 | // needs to have with the main side. |
| 25 | // The class is created and lives on the main thread. |
| 26 | class CC_EXPORT ProxyMain : public Proxy { |
khushalsagar | 5d6eb98 | 2015-09-25 22:44:56 | [diff] [blame] | 27 | public: |
khushalsagar | e0e4486e | 2017-01-25 03:15:03 | [diff] [blame] | 28 | ProxyMain(LayerTreeHost* layer_tree_host, |
khushalsagar | 12020cd4 | 2016-11-21 09:22:48 | [diff] [blame] | 29 | TaskRunnerProvider* task_runner_provider); |
khushalsagar | 5d6eb98 | 2015-09-25 22:44:56 | [diff] [blame] | 30 | |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 31 | ~ProxyMain() override; |
khushalsagar | e3c9fa9 | 2015-10-28 02:08:29 | [diff] [blame] | 32 | |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 33 | // Commits between the main and impl threads are processed through a pipeline |
| 34 | // with the following stages. For efficiency we can early out at any stage if |
| 35 | // we decide that no further processing is necessary. |
| 36 | enum CommitPipelineStage { |
| 37 | NO_PIPELINE_STAGE, |
| 38 | ANIMATE_PIPELINE_STAGE, |
| 39 | UPDATE_LAYERS_PIPELINE_STAGE, |
| 40 | COMMIT_PIPELINE_STAGE, |
| 41 | }; |
| 42 | |
danakj | 9d12442 | 2016-10-14 03:15:08 | [diff] [blame] | 43 | void DidReceiveCompositorFrameAck(); |
danakj | 94b7e4f | 2016-07-20 01:49:38 | [diff] [blame] | 44 | void BeginMainFrameNotExpectedSoon(); |
delphick | 9db74aa | 2017-05-05 10:20:49 | [diff] [blame] | 45 | void BeginMainFrameNotExpectedUntil(base::TimeTicks time); |
danakj | 94b7e4f | 2016-07-20 01:49:38 | [diff] [blame] | 46 | void DidCommitAndDrawFrame(); |
loyso | c601b7b8 | 2016-11-10 02:56:44 | [diff] [blame] | 47 | void SetAnimationEvents(std::unique_ptr<MutatorEvents> events); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 48 | void DidLoseLayerTreeFrameSink(); |
| 49 | void RequestNewLayerTreeFrameSink(); |
| 50 | void DidInitializeLayerTreeFrameSink(bool success); |
danakj | 94b7e4f | 2016-07-20 01:49:38 | [diff] [blame] | 51 | void DidCompletePageScaleAnimation(); |
| 52 | void BeginMainFrame( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 53 | std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); |
khushalsagar | 5d6eb98 | 2015-09-25 22:44:56 | [diff] [blame] | 54 | |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 55 | CommitPipelineStage max_requested_pipeline_stage() const { |
| 56 | return max_requested_pipeline_stage_; |
| 57 | } |
| 58 | CommitPipelineStage current_pipeline_stage() const { |
| 59 | return current_pipeline_stage_; |
| 60 | } |
| 61 | CommitPipelineStage final_pipeline_stage() const { |
| 62 | return final_pipeline_stage_; |
| 63 | } |
| 64 | |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 65 | private: |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 66 | // Proxy implementation. |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 67 | bool IsStarted() const override; |
| 68 | bool CommitToActiveTree() const override; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 69 | void SetLayerTreeFrameSink( |
| 70 | LayerTreeFrameSink* layer_tree_frame_sink) override; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 71 | void SetVisible(bool visible) override; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 72 | void SetNeedsAnimate() override; |
| 73 | void SetNeedsUpdateLayers() override; |
| 74 | void SetNeedsCommit() override; |
| 75 | void SetNeedsRedraw(const gfx::Rect& damage_rect) override; |
| 76 | void SetNextCommitWaitsForActivation() override; |
| 77 | void NotifyInputThrottledUntilCommit() override; |
| 78 | void SetDeferCommits(bool defer_commits) override; |
| 79 | bool CommitRequested() const override; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 80 | void MainThreadHasStoppedFlinging() override; |
enne | 2b0ad68 | 2016-09-21 01:44:47 | [diff] [blame] | 81 | void Start() override; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 82 | void Stop() override; |
| 83 | bool SupportsImplScrolling() const override; |
flackr | f54e9b4 | 2016-05-31 15:20:10 | [diff] [blame] | 84 | void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 85 | bool MainFrameWillHappenForTesting() override; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 86 | void ReleaseLayerTreeFrameSink() override; |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 87 | void UpdateBrowserControlsState(BrowserControlsState constraints, |
| 88 | BrowserControlsState current, |
| 89 | bool animate) override; |
Dan Elphick | 95929fd | 2017-06-13 09:15:07 | [diff] [blame] | 90 | void RequestBeginMainFrameNotExpected(bool new_state) override; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 91 | |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 92 | // Returns |true| if the request was actually sent, |false| if one was |
| 93 | // already outstanding. |
| 94 | bool SendCommitRequestToImplThreadIfNeeded( |
| 95 | CommitPipelineStage required_stage); |
| 96 | bool IsMainThread() const; |
khushalsagar | 12020cd4 | 2016-11-21 09:22:48 | [diff] [blame] | 97 | bool IsImplThread() const; |
| 98 | base::SingleThreadTaskRunner* ImplThreadTaskRunner(); |
| 99 | |
| 100 | void InitializeOnImplThread(CompletionEvent* completion_event); |
| 101 | void DestroyProxyImplOnImplThread(CompletionEvent* completion_event); |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 102 | |
khushalsagar | e0e4486e | 2017-01-25 03:15:03 | [diff] [blame] | 103 | LayerTreeHost* layer_tree_host_; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 104 | |
| 105 | TaskRunnerProvider* task_runner_provider_; |
| 106 | |
| 107 | const int layer_tree_host_id_; |
| 108 | |
| 109 | // The furthest pipeline stage which has been requested for the next |
| 110 | // commit. |
| 111 | CommitPipelineStage max_requested_pipeline_stage_; |
| 112 | // The commit pipeline stage that is currently being processed. |
| 113 | CommitPipelineStage current_pipeline_stage_; |
| 114 | // The commit pipeline stage at which processing for the current commit |
| 115 | // will stop. Only valid while we are executing the pipeline (i.e., |
| 116 | // |current_pipeline_stage| is set to a pipeline stage). |
| 117 | CommitPipelineStage final_pipeline_stage_; |
| 118 | |
| 119 | bool commit_waits_for_activation_; |
| 120 | |
| 121 | // Set when the Proxy is started using Proxy::Start() and reset when it is |
| 122 | // stopped using Proxy::Stop(). |
| 123 | bool started_; |
| 124 | |
| 125 | bool defer_commits_; |
| 126 | |
khushalsagar | 12020cd4 | 2016-11-21 09:22:48 | [diff] [blame] | 127 | // ProxyImpl is created and destroyed on the impl thread, and should only be |
| 128 | // accessed on the impl thread. |
| 129 | // It is safe to use base::Unretained to post tasks to ProxyImpl on the impl |
| 130 | // thread, since we control its lifetime. Any tasks posted to it are bound to |
| 131 | // run before we destroy it on the impl thread. |
| 132 | std::unique_ptr<ProxyImpl> proxy_impl_; |
| 133 | |
samans | 44b6dfc | 2017-04-19 16:50:53 | [diff] [blame] | 134 | // WeakPtrs generated by this factory will be invalidated when |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame^] | 135 | // LayerTreeFrameSink is released. |
samans | 44b6dfc | 2017-04-19 16:50:53 | [diff] [blame] | 136 | base::WeakPtrFactory<ProxyMain> frame_sink_bound_weak_factory_; |
| 137 | |
khushalsagar | 12020cd4 | 2016-11-21 09:22:48 | [diff] [blame] | 138 | base::WeakPtrFactory<ProxyMain> weak_factory_; |
khushalsagar | 0a226af | 2015-12-09 10:30:20 | [diff] [blame] | 139 | |
| 140 | DISALLOW_COPY_AND_ASSIGN(ProxyMain); |
khushalsagar | 5d6eb98 | 2015-09-25 22:44:56 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | } // namespace cc |
| 144 | |
| 145 | #endif // CC_TREES_PROXY_MAIN_H_ |