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