| 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_MAIN_H_ | 5 #ifndef CC_TREES_PROXY_MAIN_H_ |
| 6 #define CC_TREES_PROXY_MAIN_H_ | 6 #define CC_TREES_PROXY_MAIN_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "cc/base/cc_export.h" | 9 #include "cc/base/cc_export.h" |
| 10 #include "cc/input/browser_controls_state.h" | 10 #include "cc/input/browser_controls_state.h" |
| 11 #include "cc/trees/channel_main.h" | |
| 12 #include "cc/trees/proxy.h" | 11 #include "cc/trees/proxy.h" |
| 13 #include "cc/trees/proxy_common.h" | 12 #include "cc/trees/proxy_common.h" |
| 14 | 13 |
| 15 namespace cc { | 14 namespace cc { |
| 16 | 15 |
| 16 class BeginFrameSource; |
| 17 class MutatorEvents; | 17 class MutatorEvents; |
| 18 class ChannelMain; | 18 class CompletionEvent; |
| 19 class CompositorFrameSink; | 19 class CompositorFrameSink; |
| 20 class LayerTreeHostInProcess; | 20 class LayerTreeHostInProcess; |
| 21 class LayerTreeMutator; | 21 class LayerTreeMutator; |
| 22 class ProxyImpl; |
| 22 | 23 |
| 23 // This class aggregates all interactions that the impl side of the compositor | 24 // This class aggregates all interactions that the impl side of the compositor |
| 24 // needs to have with the main side. | 25 // needs to have with the main side. |
| 25 // The class is created and lives on the main thread. | 26 // The class is created and lives on the main thread. |
| 26 class CC_EXPORT ProxyMain : public Proxy { | 27 class CC_EXPORT ProxyMain : public Proxy { |
| 27 public: | 28 public: |
| 28 static std::unique_ptr<ProxyMain> CreateThreaded( | 29 ProxyMain(LayerTreeHostInProcess* layer_tree_host, |
| 29 LayerTreeHostInProcess* layer_tree_host, | 30 TaskRunnerProvider* task_runner_provider); |
| 30 TaskRunnerProvider* task_runner_provider); | |
| 31 | 31 |
| 32 ~ProxyMain() override; | 32 ~ProxyMain() override; |
| 33 | 33 |
| 34 // Commits between the main and impl threads are processed through a pipeline | 34 // Commits between the main and impl threads are processed through a pipeline |
| 35 // with the following stages. For efficiency we can early out at any stage if | 35 // with the following stages. For efficiency we can early out at any stage if |
| 36 // we decide that no further processing is necessary. | 36 // we decide that no further processing is necessary. |
| 37 enum CommitPipelineStage { | 37 enum CommitPipelineStage { |
| 38 NO_PIPELINE_STAGE, | 38 NO_PIPELINE_STAGE, |
| 39 ANIMATE_PIPELINE_STAGE, | 39 ANIMATE_PIPELINE_STAGE, |
| 40 UPDATE_LAYERS_PIPELINE_STAGE, | 40 UPDATE_LAYERS_PIPELINE_STAGE, |
| 41 COMMIT_PIPELINE_STAGE, | 41 COMMIT_PIPELINE_STAGE, |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 void DidReceiveCompositorFrameAck(); | 44 void DidReceiveCompositorFrameAck(); |
| 45 void BeginMainFrameNotExpectedSoon(); | 45 void BeginMainFrameNotExpectedSoon(); |
| 46 void DidCommitAndDrawFrame(); | 46 void DidCommitAndDrawFrame(); |
| 47 void SetAnimationEvents(std::unique_ptr<MutatorEvents> events); | 47 void SetAnimationEvents(std::unique_ptr<MutatorEvents> events); |
| 48 void DidLoseCompositorFrameSink(); | 48 void DidLoseCompositorFrameSink(); |
| 49 void RequestNewCompositorFrameSink(); | 49 void RequestNewCompositorFrameSink(); |
| 50 void DidInitializeCompositorFrameSink(bool success); | 50 void DidInitializeCompositorFrameSink(bool success); |
| 51 void DidCompletePageScaleAnimation(); | 51 void DidCompletePageScaleAnimation(); |
| 52 void BeginMainFrame( | 52 void BeginMainFrame( |
| 53 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); | 53 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state); |
| 54 | 54 |
| 55 ChannelMain* channel_main() const { return channel_main_.get(); } | |
| 56 CommitPipelineStage max_requested_pipeline_stage() const { | 55 CommitPipelineStage max_requested_pipeline_stage() const { |
| 57 return max_requested_pipeline_stage_; | 56 return max_requested_pipeline_stage_; |
| 58 } | 57 } |
| 59 CommitPipelineStage current_pipeline_stage() const { | 58 CommitPipelineStage current_pipeline_stage() const { |
| 60 return current_pipeline_stage_; | 59 return current_pipeline_stage_; |
| 61 } | 60 } |
| 62 CommitPipelineStage final_pipeline_stage() const { | 61 CommitPipelineStage final_pipeline_stage() const { |
| 63 return final_pipeline_stage_; | 62 return final_pipeline_stage_; |
| 64 } | 63 } |
| 65 | 64 |
| 66 protected: | |
| 67 ProxyMain(LayerTreeHostInProcess* layer_tree_host, | |
| 68 TaskRunnerProvider* task_runner_provider); | |
| 69 | |
| 70 private: | 65 private: |
| 71 friend class ProxyMainForTest; | |
| 72 | |
| 73 // Proxy implementation. | 66 // Proxy implementation. |
| 74 bool IsStarted() const override; | 67 bool IsStarted() const override; |
| 75 bool CommitToActiveTree() const override; | 68 bool CommitToActiveTree() const override; |
| 76 void SetCompositorFrameSink( | 69 void SetCompositorFrameSink( |
| 77 CompositorFrameSink* compositor_frame_sink) override; | 70 CompositorFrameSink* compositor_frame_sink) override; |
| 78 void SetVisible(bool visible) override; | 71 void SetVisible(bool visible) override; |
| 79 void SetNeedsAnimate() override; | 72 void SetNeedsAnimate() override; |
| 80 void SetNeedsUpdateLayers() override; | 73 void SetNeedsUpdateLayers() override; |
| 81 void SetNeedsCommit() override; | 74 void SetNeedsCommit() override; |
| 82 void SetNeedsRedraw(const gfx::Rect& damage_rect) override; | 75 void SetNeedsRedraw(const gfx::Rect& damage_rect) override; |
| 83 void SetNextCommitWaitsForActivation() override; | 76 void SetNextCommitWaitsForActivation() override; |
| 84 void NotifyInputThrottledUntilCommit() override; | 77 void NotifyInputThrottledUntilCommit() override; |
| 85 void SetDeferCommits(bool defer_commits) override; | 78 void SetDeferCommits(bool defer_commits) override; |
| 86 bool CommitRequested() const override; | 79 bool CommitRequested() const override; |
| 87 bool BeginMainFrameRequested() const override; | 80 bool BeginMainFrameRequested() const override; |
| 88 void MainThreadHasStoppedFlinging() override; | 81 void MainThreadHasStoppedFlinging() override; |
| 89 void Start() override; | 82 void Start() override; |
| 90 void Stop() override; | 83 void Stop() override; |
| 91 bool SupportsImplScrolling() const override; | 84 bool SupportsImplScrolling() const override; |
| 92 void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override; | 85 void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override; |
| 93 bool MainFrameWillHappenForTesting() override; | 86 bool MainFrameWillHappenForTesting() override; |
| 94 void ReleaseCompositorFrameSink() override; | 87 void ReleaseCompositorFrameSink() override; |
| 95 void UpdateBrowserControlsState(BrowserControlsState constraints, | 88 void UpdateBrowserControlsState(BrowserControlsState constraints, |
| 96 BrowserControlsState current, | 89 BrowserControlsState current, |
| 97 bool animate) override; | 90 bool animate) override; |
| 98 | 91 |
| 99 // This sets the channel used by ProxyMain to communicate with ProxyImpl. | |
| 100 void SetChannel(std::unique_ptr<ChannelMain> channel_main); | |
| 101 | |
| 102 // Returns |true| if the request was actually sent, |false| if one was | 92 // Returns |true| if the request was actually sent, |false| if one was |
| 103 // already outstanding. | 93 // already outstanding. |
| 104 bool SendCommitRequestToImplThreadIfNeeded( | 94 bool SendCommitRequestToImplThreadIfNeeded( |
| 105 CommitPipelineStage required_stage); | 95 CommitPipelineStage required_stage); |
| 106 bool IsMainThread() const; | 96 bool IsMainThread() const; |
| 97 bool IsImplThread() const; |
| 98 base::SingleThreadTaskRunner* ImplThreadTaskRunner(); |
| 99 |
| 100 void InitializeOnImplThread(CompletionEvent* completion_event); |
| 101 void DestroyProxyImplOnImplThread(CompletionEvent* completion_event); |
| 107 | 102 |
| 108 LayerTreeHostInProcess* layer_tree_host_; | 103 LayerTreeHostInProcess* layer_tree_host_; |
| 109 | 104 |
| 110 TaskRunnerProvider* task_runner_provider_; | 105 TaskRunnerProvider* task_runner_provider_; |
| 111 | 106 |
| 112 const int layer_tree_host_id_; | 107 const int layer_tree_host_id_; |
| 113 | 108 |
| 114 // The furthest pipeline stage which has been requested for the next | 109 // The furthest pipeline stage which has been requested for the next |
| 115 // commit. | 110 // commit. |
| 116 CommitPipelineStage max_requested_pipeline_stage_; | 111 CommitPipelineStage max_requested_pipeline_stage_; |
| 117 // The commit pipeline stage that is currently being processed. | 112 // The commit pipeline stage that is currently being processed. |
| 118 CommitPipelineStage current_pipeline_stage_; | 113 CommitPipelineStage current_pipeline_stage_; |
| 119 // The commit pipeline stage at which processing for the current commit | 114 // The commit pipeline stage at which processing for the current commit |
| 120 // will stop. Only valid while we are executing the pipeline (i.e., | 115 // will stop. Only valid while we are executing the pipeline (i.e., |
| 121 // |current_pipeline_stage| is set to a pipeline stage). | 116 // |current_pipeline_stage| is set to a pipeline stage). |
| 122 CommitPipelineStage final_pipeline_stage_; | 117 CommitPipelineStage final_pipeline_stage_; |
| 123 | 118 |
| 124 bool commit_waits_for_activation_; | 119 bool commit_waits_for_activation_; |
| 125 | 120 |
| 126 // Set when the Proxy is started using Proxy::Start() and reset when it is | 121 // Set when the Proxy is started using Proxy::Start() and reset when it is |
| 127 // stopped using Proxy::Stop(). | 122 // stopped using Proxy::Stop(). |
| 128 bool started_; | 123 bool started_; |
| 129 | 124 |
| 130 bool defer_commits_; | 125 bool defer_commits_; |
| 131 | 126 |
| 132 std::unique_ptr<ChannelMain> channel_main_; | 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 |
| 134 base::WeakPtrFactory<ProxyMain> weak_factory_; |
| 133 | 135 |
| 134 DISALLOW_COPY_AND_ASSIGN(ProxyMain); | 136 DISALLOW_COPY_AND_ASSIGN(ProxyMain); |
| 135 }; | 137 }; |
| 136 | 138 |
| 137 } // namespace cc | 139 } // namespace cc |
| 138 | 140 |
| 139 #endif // CC_TREES_PROXY_MAIN_H_ | 141 #endif // CC_TREES_PROXY_MAIN_H_ |
| OLD | NEW |