[go: nahoru, domu]

blob: 5007bb296a980be62aef38af7e2636126fedcec2 [file] [log] [blame]
khushalsagar5d6eb982015-09-25 22:44:561// 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
khushalsagar0a226af2015-12-09 10:30:208#include "base/macros.h"
chrishtrac41ff92017-03-17 05:07:309#include "cc/cc_export.h"
mdjones2ee41afd2016-10-27 16:50:2010#include "cc/input/browser_controls_state.h"
khushalsagar0a226af2015-12-09 10:30:2011#include "cc/trees/proxy.h"
khushalsagare3c9fa92015-10-28 02:08:2912#include "cc/trees/proxy_common.h"
khushalsagar5d6eb982015-09-25 22:44:5613
14namespace cc {
loysoe926437dd2016-01-14 22:55:3015
loysoc601b7b82016-11-10 02:56:4416class MutatorEvents;
khushalsagar12020cd42016-11-21 09:22:4817class CompletionEvent;
danakjc7afae52017-06-20 21:12:4118class LayerTreeFrameSink;
khushalsagare0e4486e2017-01-25 03:15:0319class LayerTreeHost;
flackrf54e9b42016-05-31 15:20:1020class LayerTreeMutator;
khushalsagar12020cd42016-11-21 09:22:4821class ProxyImpl;
khushalsagar5d6eb982015-09-25 22:44:5622
khushalsagar0a226af2015-12-09 10:30:2023// 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.
26class CC_EXPORT ProxyMain : public Proxy {
khushalsagar5d6eb982015-09-25 22:44:5627 public:
khushalsagare0e4486e2017-01-25 03:15:0328 ProxyMain(LayerTreeHost* layer_tree_host,
khushalsagar12020cd42016-11-21 09:22:4829 TaskRunnerProvider* task_runner_provider);
khushalsagar5d6eb982015-09-25 22:44:5630
khushalsagar0a226af2015-12-09 10:30:2031 ~ProxyMain() override;
khushalsagare3c9fa92015-10-28 02:08:2932
khushalsagar0a226af2015-12-09 10:30:2033 // 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
danakj9d124422016-10-14 03:15:0843 void DidReceiveCompositorFrameAck();
danakj94b7e4f2016-07-20 01:49:3844 void BeginMainFrameNotExpectedSoon();
delphick9db74aa2017-05-05 10:20:4945 void BeginMainFrameNotExpectedUntil(base::TimeTicks time);
danakj94b7e4f2016-07-20 01:49:3846 void DidCommitAndDrawFrame();
loysoc601b7b82016-11-10 02:56:4447 void SetAnimationEvents(std::unique_ptr<MutatorEvents> events);
danakjc7afae52017-06-20 21:12:4148 void DidLoseLayerTreeFrameSink();
49 void RequestNewLayerTreeFrameSink();
50 void DidInitializeLayerTreeFrameSink(bool success);
danakj94b7e4f2016-07-20 01:49:3851 void DidCompletePageScaleAnimation();
52 void BeginMainFrame(
danakj60bc3bc2016-04-09 00:24:4853 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state);
khushalsagar5d6eb982015-09-25 22:44:5654
khushalsagar0a226af2015-12-09 10:30:2055 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
khushalsagar0a226af2015-12-09 10:30:2065 private:
khushalsagar0a226af2015-12-09 10:30:2066 // Proxy implementation.
khushalsagar0a226af2015-12-09 10:30:2067 bool IsStarted() const override;
68 bool CommitToActiveTree() const override;
danakjc7afae52017-06-20 21:12:4169 void SetLayerTreeFrameSink(
70 LayerTreeFrameSink* layer_tree_frame_sink) override;
khushalsagar0a226af2015-12-09 10:30:2071 void SetVisible(bool visible) override;
khushalsagar0a226af2015-12-09 10:30:2072 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;
khushalsagar0a226af2015-12-09 10:30:2080 void MainThreadHasStoppedFlinging() override;
enne2b0ad682016-09-21 01:44:4781 void Start() override;
khushalsagar0a226af2015-12-09 10:30:2082 void Stop() override;
83 bool SupportsImplScrolling() const override;
flackrf54e9b42016-05-31 15:20:1084 void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override;
khushalsagar0a226af2015-12-09 10:30:2085 bool MainFrameWillHappenForTesting() override;
danakjc7afae52017-06-20 21:12:4186 void ReleaseLayerTreeFrameSink() override;
mdjones2ee41afd2016-10-27 16:50:2087 void UpdateBrowserControlsState(BrowserControlsState constraints,
88 BrowserControlsState current,
89 bool animate) override;
Dan Elphick95929fd2017-06-13 09:15:0790 void RequestBeginMainFrameNotExpected(bool new_state) override;
khushalsagar0a226af2015-12-09 10:30:2091
khushalsagar0a226af2015-12-09 10:30:2092 // 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;
khushalsagar12020cd42016-11-21 09:22:4897 bool IsImplThread() const;
98 base::SingleThreadTaskRunner* ImplThreadTaskRunner();
99
100 void InitializeOnImplThread(CompletionEvent* completion_event);
101 void DestroyProxyImplOnImplThread(CompletionEvent* completion_event);
khushalsagar0a226af2015-12-09 10:30:20102
khushalsagare0e4486e2017-01-25 03:15:03103 LayerTreeHost* layer_tree_host_;
khushalsagar0a226af2015-12-09 10:30:20104
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
khushalsagar12020cd42016-11-21 09:22:48127 // 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
samans44b6dfc2017-04-19 16:50:53134 // WeakPtrs generated by this factory will be invalidated when
danakjc7afae52017-06-20 21:12:41135 // LayerTreeFrameSink is released.
samans44b6dfc2017-04-19 16:50:53136 base::WeakPtrFactory<ProxyMain> frame_sink_bound_weak_factory_;
137
khushalsagar12020cd42016-11-21 09:22:48138 base::WeakPtrFactory<ProxyMain> weak_factory_;
khushalsagar0a226af2015-12-09 10:30:20139
140 DISALLOW_COPY_AND_ASSIGN(ProxyMain);
khushalsagar5d6eb982015-09-25 22:44:56141};
142
143} // namespace cc
144
145#endif // CC_TREES_PROXY_MAIN_H_