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; |
285 | 297 |
286 LayerAnimatorCollection* layer_animator_collection() { | 298 LayerAnimatorCollection* layer_animator_collection() { |
287 return &layer_animator_collection_; | 299 return &layer_animator_collection_; |
288 } | 300 } |
289 | 301 |
290 cc::SurfaceIdAllocator* surface_id_allocator() { | 302 cc::SurfaceIdAllocator* surface_id_allocator() { |
291 return surface_id_allocator_.get(); | 303 return surface_id_allocator_.get(); |
292 } | 304 } |
293 | 305 |
| 306 // Exposed for testing. |
| 307 cc::BeginFrameArgs MissedBeginFrameArgsForTesting() { |
| 308 return missed_begin_frame_args_; |
| 309 } |
| 310 |
294 private: | 311 private: |
295 friend class base::RefCounted<Compositor>; | 312 friend class base::RefCounted<Compositor>; |
296 friend class CompositorLock; | 313 friend class CompositorLock; |
297 | 314 |
298 // Called by CompositorLock. | 315 // Called by CompositorLock. |
299 void UnlockCompositor(); | 316 void UnlockCompositor(); |
300 | 317 |
301 // Called to release any pending CompositorLock | 318 // Called to release any pending CompositorLock |
302 void CancelCompositorLock(); | 319 void CancelCompositorLock(); |
303 | 320 |
304 gfx::Size size_; | 321 gfx::Size size_; |
305 | 322 |
306 ui::ContextFactory* context_factory_; | 323 ui::ContextFactory* context_factory_; |
307 | 324 |
308 // The root of the Layer tree drawn by this compositor. | 325 // The root of the Layer tree drawn by this compositor. |
309 Layer* root_layer_; | 326 Layer* root_layer_; |
310 | 327 |
311 ObserverList<CompositorObserver, true> observer_list_; | 328 ObserverList<CompositorObserver, true> observer_list_; |
312 ObserverList<CompositorAnimationObserver> animation_observer_list_; | 329 ObserverList<CompositorAnimationObserver> animation_observer_list_; |
| 330 std::list<CompositorBeginFrameObserver*> begin_frame_observer_list_; |
313 | 331 |
314 gfx::AcceleratedWidget widget_; | 332 gfx::AcceleratedWidget widget_; |
315 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 333 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
316 scoped_refptr<cc::Layer> root_web_layer_; | 334 scoped_refptr<cc::Layer> root_web_layer_; |
317 scoped_ptr<cc::LayerTreeHost> host_; | 335 scoped_ptr<cc::LayerTreeHost> host_; |
318 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 336 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
319 | 337 |
320 // The manager of vsync parameters for this compositor. | 338 // The manager of vsync parameters for this compositor. |
321 scoped_refptr<CompositorVSyncManager> vsync_manager_; | 339 scoped_refptr<CompositorVSyncManager> vsync_manager_; |
322 | 340 |
323 // The device scale factor of the monitor that this compositor is compositing | 341 // The device scale factor of the monitor that this compositor is compositing |
324 // layers on. | 342 // layers on. |
325 float device_scale_factor_; | 343 float device_scale_factor_; |
326 | 344 |
327 int last_started_frame_; | 345 int last_started_frame_; |
328 int last_ended_frame_; | 346 int last_ended_frame_; |
329 | 347 |
330 bool locks_will_time_out_; | 348 bool locks_will_time_out_; |
331 CompositorLock* compositor_lock_; | 349 CompositorLock* compositor_lock_; |
332 | 350 |
333 LayerAnimatorCollection layer_animator_collection_; | 351 LayerAnimatorCollection layer_animator_collection_; |
334 | 352 |
| 353 // Used to send to any new CompositorBeginFrameObserver immediately. |
| 354 cc::BeginFrameArgs missed_begin_frame_args_; |
| 355 |
335 base::WeakPtrFactory<Compositor> weak_ptr_factory_; | 356 base::WeakPtrFactory<Compositor> weak_ptr_factory_; |
336 | 357 |
337 DISALLOW_COPY_AND_ASSIGN(Compositor); | 358 DISALLOW_COPY_AND_ASSIGN(Compositor); |
338 }; | 359 }; |
339 | 360 |
340 } // namespace ui | 361 } // namespace ui |
341 | 362 |
342 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 363 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |