| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 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_LAYER_TREE_HOST_IN_PROCESS_H_ | |
| 6 #define CC_TREES_LAYER_TREE_HOST_IN_PROCESS_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <limits> | |
| 12 #include <memory> | |
| 13 #include <set> | |
| 14 #include <string> | |
| 15 #include <unordered_map> | |
| 16 #include <vector> | |
| 17 | |
| 18 #include "base/cancelable_callback.h" | |
| 19 #include "base/macros.h" | |
| 20 #include "base/memory/ref_counted.h" | |
| 21 #include "base/memory/weak_ptr.h" | |
| 22 #include "base/time/time.h" | |
| 23 #include "cc/base/cc_export.h" | |
| 24 #include "cc/debug/micro_benchmark.h" | |
| 25 #include "cc/debug/micro_benchmark_controller.h" | |
| 26 #include "cc/input/browser_controls_state.h" | |
| 27 #include "cc/input/event_listener_properties.h" | |
| 28 #include "cc/input/input_handler.h" | |
| 29 #include "cc/input/layer_selection_bound.h" | |
| 30 #include "cc/input/scrollbar.h" | |
| 31 #include "cc/layers/layer_collections.h" | |
| 32 #include "cc/layers/layer_list_iterator.h" | |
| 33 #include "cc/output/compositor_frame_sink.h" | |
| 34 #include "cc/output/swap_promise.h" | |
| 35 #include "cc/resources/resource_format.h" | |
| 36 #include "cc/surfaces/surface_sequence_generator.h" | |
| 37 #include "cc/trees/compositor_mode.h" | |
| 38 #include "cc/trees/layer_tree.h" | |
| 39 #include "cc/trees/layer_tree_host.h" | |
| 40 #include "cc/trees/layer_tree_host_client.h" | |
| 41 #include "cc/trees/layer_tree_settings.h" | |
| 42 #include "cc/trees/proxy.h" | |
| 43 #include "cc/trees/swap_promise_manager.h" | |
| 44 #include "cc/trees/target_property.h" | |
| 45 #include "third_party/skia/include/core/SkColor.h" | |
| 46 #include "ui/gfx/geometry/rect.h" | |
| 47 | |
| 48 namespace cc { | |
| 49 class MutatorEvents; | |
| 50 class Layer; | |
| 51 class LayerTreeHostClient; | |
| 52 class LayerTreeHostImpl; | |
| 53 class LayerTreeHostImplClient; | |
| 54 class LayerTreeHostSingleThreadClient; | |
| 55 class LayerTreeMutator; | |
| 56 class MutatorHost; | |
| 57 class RenderingStatsInstrumentation; | |
| 58 class TaskGraphRunner; | |
| 59 struct RenderingStats; | |
| 60 struct ScrollAndScaleSet; | |
| 61 | |
| 62 class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { | |
| 63 public: | |
| 64 // TODO(sad): InitParams should be a movable type so that it can be | |
| 65 // std::move()d to the Create* functions. | |
| 66 struct CC_EXPORT InitParams { | |
| 67 LayerTreeHostClient* client = nullptr; | |
| 68 TaskGraphRunner* task_graph_runner = nullptr; | |
| 69 LayerTreeSettings const* settings = nullptr; | |
| 70 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner; | |
| 71 MutatorHost* mutator_host = nullptr; | |
| 72 scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner; | |
| 73 | |
| 74 InitParams(); | |
| 75 ~InitParams(); | |
| 76 }; | |
| 77 | |
| 78 static std::unique_ptr<LayerTreeHostInProcess> CreateThreaded( | |
| 79 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | |
| 80 InitParams* params); | |
| 81 | |
| 82 static std::unique_ptr<LayerTreeHostInProcess> CreateSingleThreaded( | |
| 83 LayerTreeHostSingleThreadClient* single_thread_client, | |
| 84 InitParams* params); | |
| 85 | |
| 86 ~LayerTreeHostInProcess() override; | |
| 87 | |
| 88 // LayerTreeHost implementation. | |
| 89 int GetId() const override; | |
| 90 int SourceFrameNumber() const override; | |
| 91 LayerTree* GetLayerTree() override; | |
| 92 const LayerTree* GetLayerTree() const override; | |
| 93 UIResourceManager* GetUIResourceManager() const override; | |
| 94 TaskRunnerProvider* GetTaskRunnerProvider() const override; | |
| 95 const LayerTreeSettings& GetSettings() const override; | |
| 96 void SetFrameSinkId(const FrameSinkId& frame_sink_id) override; | |
| 97 void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator) override; | |
| 98 void QueueSwapPromise(std::unique_ptr<SwapPromise> swap_promise) override; | |
| 99 SwapPromiseManager* GetSwapPromiseManager() override; | |
| 100 void SetHasGpuRasterizationTrigger(bool has_trigger) override; | |
| 101 void SetVisible(bool visible) override; | |
| 102 bool IsVisible() const override; | |
| 103 void SetCompositorFrameSink( | |
| 104 std::unique_ptr<CompositorFrameSink> compositor_frame_sink) override; | |
| 105 std::unique_ptr<CompositorFrameSink> ReleaseCompositorFrameSink() override; | |
| 106 void SetNeedsAnimate() override; | |
| 107 void SetNeedsUpdateLayers() override; | |
| 108 void SetNeedsCommit() override; | |
| 109 void SetNeedsRecalculateRasterScales() override; | |
| 110 bool CommitRequested() const override; | |
| 111 void SetDeferCommits(bool defer_commits) override; | |
| 112 void LayoutAndUpdateLayers() override; | |
| 113 void Composite(base::TimeTicks frame_begin_time) override; | |
| 114 void SetNeedsRedrawRect(const gfx::Rect& damage_rect) override; | |
| 115 void SetNextCommitForcesRedraw() override; | |
| 116 void NotifyInputThrottledUntilCommit() override; | |
| 117 void UpdateBrowserControlsState(BrowserControlsState constraints, | |
| 118 BrowserControlsState current, | |
| 119 bool animate) override; | |
| 120 const base::WeakPtr<InputHandler>& GetInputHandler() const override; | |
| 121 void DidStopFlinging() override; | |
| 122 void SetDebugState(const LayerTreeDebugState& debug_state) override; | |
| 123 const LayerTreeDebugState& GetDebugState() const override; | |
| 124 int ScheduleMicroBenchmark( | |
| 125 const std::string& benchmark_name, | |
| 126 std::unique_ptr<base::Value> value, | |
| 127 const MicroBenchmark::DoneCallback& callback) override; | |
| 128 bool SendMessageToMicroBenchmark(int id, | |
| 129 std::unique_ptr<base::Value> value) override; | |
| 130 SurfaceSequenceGenerator* GetSurfaceSequenceGenerator() override; | |
| 131 void SetNextCommitWaitsForActivation() override; | |
| 132 void ResetGpuRasterizationTracking() override; | |
| 133 | |
| 134 // LayerTreeHostInProcess interface to Proxy. | |
| 135 void WillBeginMainFrame(); | |
| 136 void DidBeginMainFrame(); | |
| 137 void BeginMainFrame(const BeginFrameArgs& args); | |
| 138 void BeginMainFrameNotExpectedSoon(); | |
| 139 void AnimateLayers(base::TimeTicks monotonic_frame_begin_time); | |
| 140 void RequestMainFrameUpdate(); | |
| 141 void FinishCommitOnImplThread(LayerTreeHostImpl* host_impl); | |
| 142 void WillCommit(); | |
| 143 void CommitComplete(); | |
| 144 void RequestNewCompositorFrameSink(); | |
| 145 void DidInitializeCompositorFrameSink(); | |
| 146 void DidFailToInitializeCompositorFrameSink(); | |
| 147 virtual std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | |
| 148 LayerTreeHostImplClient* client); | |
| 149 void DidLoseCompositorFrameSink(); | |
| 150 void DidCommitAndDrawFrame() { client_->DidCommitAndDrawFrame(); } | |
| 151 void DidReceiveCompositorFrameAck() { | |
| 152 client_->DidReceiveCompositorFrameAck(); | |
| 153 } | |
| 154 bool UpdateLayers(); | |
| 155 // Called when the compositor completed page scale animation. | |
| 156 void DidCompletePageScaleAnimation(); | |
| 157 void ApplyScrollAndScale(ScrollAndScaleSet* info); | |
| 158 | |
| 159 LayerTreeHostClient* client() { return client_; } | |
| 160 | |
| 161 bool gpu_rasterization_histogram_recorded() const { | |
| 162 return gpu_rasterization_histogram_recorded_; | |
| 163 } | |
| 164 | |
| 165 void CollectRenderingStats(RenderingStats* stats) const; | |
| 166 | |
| 167 RenderingStatsInstrumentation* rendering_stats_instrumentation() const { | |
| 168 return rendering_stats_instrumentation_.get(); | |
| 169 } | |
| 170 | |
| 171 void SetAnimationEvents(std::unique_ptr<MutatorEvents> events); | |
| 172 | |
| 173 bool has_gpu_rasterization_trigger() const { | |
| 174 return has_gpu_rasterization_trigger_; | |
| 175 } | |
| 176 | |
| 177 Proxy* proxy() const { return proxy_.get(); } | |
| 178 | |
| 179 bool IsSingleThreaded() const; | |
| 180 bool IsThreaded() const; | |
| 181 | |
| 182 protected: | |
| 183 // Allow tests to inject the LayerTree. | |
| 184 LayerTreeHostInProcess(InitParams* params, | |
| 185 CompositorMode mode, | |
| 186 std::unique_ptr<LayerTree> layer_tree); | |
| 187 LayerTreeHostInProcess(InitParams* params, CompositorMode mode); | |
| 188 | |
| 189 void InitializeThreaded( | |
| 190 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 191 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); | |
| 192 void InitializeSingleThreaded( | |
| 193 LayerTreeHostSingleThreadClient* single_thread_client, | |
| 194 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); | |
| 195 void InitializeForTesting( | |
| 196 std::unique_ptr<TaskRunnerProvider> task_runner_provider, | |
| 197 std::unique_ptr<Proxy> proxy_for_testing); | |
| 198 void SetTaskRunnerProviderForTesting( | |
| 199 std::unique_ptr<TaskRunnerProvider> task_runner_provider); | |
| 200 void SetUIResourceManagerForTesting( | |
| 201 std::unique_ptr<UIResourceManager> ui_resource_manager); | |
| 202 | |
| 203 // task_graph_runner() returns a valid value only until the LayerTreeHostImpl | |
| 204 // is created in CreateLayerTreeHostImpl(). | |
| 205 TaskGraphRunner* task_graph_runner() const { return task_graph_runner_; } | |
| 206 | |
| 207 void OnCommitForSwapPromises(); | |
| 208 | |
| 209 void RecordGpuRasterizationHistogram(); | |
| 210 | |
| 211 MicroBenchmarkController micro_benchmark_controller_; | |
| 212 | |
| 213 std::unique_ptr<LayerTree> layer_tree_; | |
| 214 | |
| 215 base::WeakPtr<InputHandler> input_handler_weak_ptr_; | |
| 216 | |
| 217 private: | |
| 218 friend class LayerTreeHostSerializationTest; | |
| 219 | |
| 220 // This is the number of consecutive frames in which we want the content to be | |
| 221 // suitable for GPU rasterization before re-enabling it. | |
| 222 enum { kNumFramesToConsiderBeforeGpuRasterization = 60 }; | |
| 223 | |
| 224 void ApplyViewportDeltas(ScrollAndScaleSet* info); | |
| 225 void ApplyPageScaleDeltaFromImplSide(float page_scale_delta); | |
| 226 void InitializeProxy(std::unique_ptr<Proxy> proxy); | |
| 227 | |
| 228 bool DoUpdateLayers(Layer* root_layer); | |
| 229 void UpdateHudLayer(); | |
| 230 | |
| 231 bool AnimateLayersRecursive(Layer* current, base::TimeTicks time); | |
| 232 | |
| 233 void CalculateLCDTextMetricsCallback(Layer* layer); | |
| 234 | |
| 235 void SetPropertyTreesNeedRebuild(); | |
| 236 | |
| 237 const CompositorMode compositor_mode_; | |
| 238 | |
| 239 std::unique_ptr<UIResourceManager> ui_resource_manager_; | |
| 240 | |
| 241 LayerTreeHostClient* client_; | |
| 242 std::unique_ptr<Proxy> proxy_; | |
| 243 std::unique_ptr<TaskRunnerProvider> task_runner_provider_; | |
| 244 | |
| 245 int source_frame_number_; | |
| 246 std::unique_ptr<RenderingStatsInstrumentation> | |
| 247 rendering_stats_instrumentation_; | |
| 248 | |
| 249 SwapPromiseManager swap_promise_manager_; | |
| 250 | |
| 251 // |current_compositor_frame_sink_| can't be updated until we've successfully | |
| 252 // initialized a new CompositorFrameSink. |new_compositor_frame_sink_| | |
| 253 // contains the new CompositorFrameSink that is currently being initialized. | |
| 254 // If initialization is successful then |new_compositor_frame_sink_| replaces | |
| 255 // |current_compositor_frame_sink_|. | |
| 256 std::unique_ptr<CompositorFrameSink> new_compositor_frame_sink_; | |
| 257 std::unique_ptr<CompositorFrameSink> current_compositor_frame_sink_; | |
| 258 | |
| 259 const LayerTreeSettings settings_; | |
| 260 LayerTreeDebugState debug_state_; | |
| 261 | |
| 262 bool visible_; | |
| 263 | |
| 264 bool has_gpu_rasterization_trigger_; | |
| 265 bool content_is_suitable_for_gpu_rasterization_; | |
| 266 bool gpu_rasterization_histogram_recorded_; | |
| 267 | |
| 268 // If set, then page scale animation has completed, but the client hasn't been | |
| 269 // notified about it yet. | |
| 270 bool did_complete_scale_animation_; | |
| 271 | |
| 272 int id_; | |
| 273 bool next_commit_forces_redraw_ = false; | |
| 274 bool next_commit_forces_recalculate_raster_scales_ = false; | |
| 275 // Track when we're inside a main frame to see if compositor is being | |
| 276 // destroyed midway which causes a crash. crbug.com/654672 | |
| 277 bool inside_main_frame_ = false; | |
| 278 | |
| 279 TaskGraphRunner* task_graph_runner_; | |
| 280 | |
| 281 SurfaceSequenceGenerator surface_sequence_generator_; | |
| 282 uint32_t num_consecutive_frames_suitable_for_gpu_ = 0; | |
| 283 | |
| 284 scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner_; | |
| 285 | |
| 286 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostInProcess); | |
| 287 }; | |
| 288 | |
| 289 } // namespace cc | |
| 290 | |
| 291 #endif // CC_TREES_LAYER_TREE_HOST_IN_PROCESS_H_ | |
| OLD | NEW |