OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_COMPOSITOR_COMPOSITOR_H_ | 5 #ifndef UI_COMPOSITOR_COMPOSITOR_H_ |
6 #define UI_COMPOSITOR_COMPOSITOR_H_ | 6 #define UI_COMPOSITOR_COMPOSITOR_H_ |
7 | 7 |
| 8 #include <list> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "cc/output/begin_frame_args.h" |
16 #include "cc/surfaces/surface_sequence.h" | 18 #include "cc/surfaces/surface_sequence.h" |
17 #include "cc/trees/layer_tree_host_client.h" | 19 #include "cc/trees/layer_tree_host_client.h" |
18 #include "cc/trees/layer_tree_host_single_thread_client.h" | 20 #include "cc/trees/layer_tree_host_single_thread_client.h" |
19 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
20 #include "ui/compositor/compositor_animation_observer.h" | 22 #include "ui/compositor/compositor_animation_observer.h" |
21 #include "ui/compositor/compositor_export.h" | 23 #include "ui/compositor/compositor_export.h" |
22 #include "ui/compositor/compositor_observer.h" | 24 #include "ui/compositor/compositor_observer.h" |
23 #include "ui/compositor/layer_animator_collection.h" | 25 #include "ui/compositor/layer_animator_collection.h" |
24 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
25 #include "ui/gfx/geometry/vector2d.h" | 27 #include "ui/gfx/geometry/vector2d.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 127 |
126 explicit CompositorLock(Compositor* compositor); | 128 explicit CompositorLock(Compositor* compositor); |
127 ~CompositorLock(); | 129 ~CompositorLock(); |
128 | 130 |
129 void CancelLock(); | 131 void CancelLock(); |
130 | 132 |
131 Compositor* compositor_; | 133 Compositor* compositor_; |
132 DISALLOW_COPY_AND_ASSIGN(CompositorLock); | 134 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
133 }; | 135 }; |
134 | 136 |
| 137 // This class observes BeginFrame notification from LayerTreeHost. |
| 138 class COMPOSITOR_EXPORT CompositorBeginFrameObserver { |
| 139 public: |
| 140 virtual void OnSendBeginFrame(const cc::BeginFrameArgs& args) = 0; |
| 141 }; |
| 142 |
135 // Compositor object to take care of GPU painting. | 143 // Compositor object to take care of GPU painting. |
136 // A Browser compositor object is responsible for generating the final | 144 // A Browser compositor object is responsible for generating the final |
137 // displayable form of pixels comprising a single widget's contents. It draws an | 145 // displayable form of pixels comprising a single widget's contents. It draws an |
138 // appropriately transformed texture for each transformed view in the widget's | 146 // appropriately transformed texture for each transformed view in the widget's |
139 // view hierarchy. | 147 // view hierarchy. |
140 class COMPOSITOR_EXPORT Compositor | 148 class COMPOSITOR_EXPORT Compositor |
141 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), | 149 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), |
142 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { | 150 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { |
143 public: | 151 public: |
144 Compositor(gfx::AcceleratedWidget widget, | 152 Compositor(gfx::AcceleratedWidget widget, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // Compositor does not own observers. It is the responsibility of the | 228 // Compositor does not own observers. It is the responsibility of the |
221 // observer to remove itself when it is done observing. | 229 // observer to remove itself when it is done observing. |
222 void AddObserver(CompositorObserver* observer); | 230 void AddObserver(CompositorObserver* observer); |
223 void RemoveObserver(CompositorObserver* observer); | 231 void RemoveObserver(CompositorObserver* observer); |
224 bool HasObserver(const CompositorObserver* observer) const; | 232 bool HasObserver(const CompositorObserver* observer) const; |
225 | 233 |
226 void AddAnimationObserver(CompositorAnimationObserver* observer); | 234 void AddAnimationObserver(CompositorAnimationObserver* observer); |
227 void RemoveAnimationObserver(CompositorAnimationObserver* observer); | 235 void RemoveAnimationObserver(CompositorAnimationObserver* observer); |
228 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; | 236 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; |
229 | 237 |
| 238 void AddBeginFrameObserver(CompositorBeginFrameObserver* observer); |
| 239 void RemoveBeginFrameObserver(CompositorBeginFrameObserver* observer); |
| 240 |
230 // Change the timeout behavior for all future locks that are created. Locks | 241 // Change the timeout behavior for all future locks that are created. Locks |
231 // should time out if there is an expectation that the compositor will be | 242 // should time out if there is an expectation that the compositor will be |
232 // responsive. | 243 // responsive. |
233 void SetLocksWillTimeOut(bool locks_will_time_out) { | 244 void SetLocksWillTimeOut(bool locks_will_time_out) { |
234 locks_will_time_out_ = locks_will_time_out; | 245 locks_will_time_out_ = locks_will_time_out; |
235 } | 246 } |
236 | 247 |
237 // Creates a compositor lock. Returns NULL if it is not possible to lock at | 248 // Creates a compositor lock. Returns NULL if it is not possible to lock at |
238 // this time (i.e. we're waiting to complete a previous unlock). | 249 // this time (i.e. we're waiting to complete a previous unlock). |
239 scoped_refptr<CompositorLock> GetCompositorLock(); | 250 scoped_refptr<CompositorLock> GetCompositorLock(); |
(...skipping 25 matching lines...) Expand all Loading... |
265 float page_scale, | 276 float page_scale, |
266 float top_controls_delta) override {} | 277 float top_controls_delta) override {} |
267 void RequestNewOutputSurface() override; | 278 void RequestNewOutputSurface() override; |
268 void DidInitializeOutputSurface() override; | 279 void DidInitializeOutputSurface() override; |
269 void DidFailToInitializeOutputSurface() override; | 280 void DidFailToInitializeOutputSurface() override; |
270 void WillCommit() override {} | 281 void WillCommit() override {} |
271 void DidCommit() override; | 282 void DidCommit() override; |
272 void DidCommitAndDrawFrame() override; | 283 void DidCommitAndDrawFrame() override; |
273 void DidCompleteSwapBuffers() override; | 284 void DidCompleteSwapBuffers() override; |
274 void DidCompletePageScaleAnimation() override {} | 285 void DidCompletePageScaleAnimation() override {} |
| 286 void SendBeginFramesToChildren(const cc::BeginFrameArgs& args) override; |
275 | 287 |
276 // cc::LayerTreeHostSingleThreadClient implementation. | 288 // cc::LayerTreeHostSingleThreadClient implementation. |
277 void DidPostSwapBuffers() override; | 289 void DidPostSwapBuffers() override; |
278 void DidAbortSwapBuffers() override; | 290 void DidAbortSwapBuffers() override; |
279 | 291 |
280 bool IsLocked() { return compositor_lock_ != NULL; } | 292 bool IsLocked() { return compositor_lock_ != NULL; } |
281 | 293 |
282 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; | 294 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; |
283 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); | 295 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); |
284 const cc::RendererSettings& GetRendererSettings() const; | 296 const cc::RendererSettings& GetRendererSettings() const; |
(...skipping 18 matching lines...) Expand all Loading... |
303 | 315 |
304 gfx::Size size_; | 316 gfx::Size size_; |
305 | 317 |
306 ui::ContextFactory* context_factory_; | 318 ui::ContextFactory* context_factory_; |
307 | 319 |
308 // The root of the Layer tree drawn by this compositor. | 320 // The root of the Layer tree drawn by this compositor. |
309 Layer* root_layer_; | 321 Layer* root_layer_; |
310 | 322 |
311 ObserverList<CompositorObserver, true> observer_list_; | 323 ObserverList<CompositorObserver, true> observer_list_; |
312 ObserverList<CompositorAnimationObserver> animation_observer_list_; | 324 ObserverList<CompositorAnimationObserver> animation_observer_list_; |
| 325 std::list<CompositorBeginFrameObserver*> begin_frame_observer_list_; |
313 | 326 |
314 gfx::AcceleratedWidget widget_; | 327 gfx::AcceleratedWidget widget_; |
315 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 328 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
316 scoped_refptr<cc::Layer> root_web_layer_; | 329 scoped_refptr<cc::Layer> root_web_layer_; |
317 scoped_ptr<cc::LayerTreeHost> host_; | 330 scoped_ptr<cc::LayerTreeHost> host_; |
318 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 331 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
319 | 332 |
320 // The manager of vsync parameters for this compositor. | 333 // The manager of vsync parameters for this compositor. |
321 scoped_refptr<CompositorVSyncManager> vsync_manager_; | 334 scoped_refptr<CompositorVSyncManager> vsync_manager_; |
322 | 335 |
323 // The device scale factor of the monitor that this compositor is compositing | 336 // The device scale factor of the monitor that this compositor is compositing |
324 // layers on. | 337 // layers on. |
325 float device_scale_factor_; | 338 float device_scale_factor_; |
326 | 339 |
327 int last_started_frame_; | 340 int last_started_frame_; |
328 int last_ended_frame_; | 341 int last_ended_frame_; |
329 | 342 |
330 bool locks_will_time_out_; | 343 bool locks_will_time_out_; |
331 CompositorLock* compositor_lock_; | 344 CompositorLock* compositor_lock_; |
332 | 345 |
333 LayerAnimatorCollection layer_animator_collection_; | 346 LayerAnimatorCollection layer_animator_collection_; |
334 | 347 |
| 348 // Used to send to any new CompositorBeginFrameObserver immediately. |
| 349 cc::BeginFrameArgs missed_begin_frame_args_; |
| 350 |
335 base::WeakPtrFactory<Compositor> weak_ptr_factory_; | 351 base::WeakPtrFactory<Compositor> weak_ptr_factory_; |
336 | 352 |
337 DISALLOW_COPY_AND_ASSIGN(Compositor); | 353 DISALLOW_COPY_AND_ASSIGN(Compositor); |
338 }; | 354 }; |
339 | 355 |
340 } // namespace ui | 356 } // namespace ui |
341 | 357 |
342 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 358 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |