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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "cc/output/begin_frame_args.h" |
16 #include "cc/surfaces/surface_sequence.h" | 17 #include "cc/surfaces/surface_sequence.h" |
17 #include "cc/trees/layer_tree_host_client.h" | 18 #include "cc/trees/layer_tree_host_client.h" |
18 #include "cc/trees/layer_tree_host_single_thread_client.h" | 19 #include "cc/trees/layer_tree_host_single_thread_client.h" |
19 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
20 #include "ui/compositor/compositor_animation_observer.h" | 21 #include "ui/compositor/compositor_animation_observer.h" |
21 #include "ui/compositor/compositor_export.h" | 22 #include "ui/compositor/compositor_export.h" |
22 #include "ui/compositor/compositor_observer.h" | 23 #include "ui/compositor/compositor_observer.h" |
23 #include "ui/compositor/layer_animator_collection.h" | 24 #include "ui/compositor/layer_animator_collection.h" |
24 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
25 #include "ui/gfx/geometry/vector2d.h" | 26 #include "ui/gfx/geometry/vector2d.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 126 |
126 explicit CompositorLock(Compositor* compositor); | 127 explicit CompositorLock(Compositor* compositor); |
127 ~CompositorLock(); | 128 ~CompositorLock(); |
128 | 129 |
129 void CancelLock(); | 130 void CancelLock(); |
130 | 131 |
131 Compositor* compositor_; | 132 Compositor* compositor_; |
132 DISALLOW_COPY_AND_ASSIGN(CompositorLock); | 133 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
133 }; | 134 }; |
134 | 135 |
| 136 // This class observes BeginFrame notification from LayerTreeHost. |
| 137 class COMPOSITOR_EXPORT CompositorBeginFrameObserver { |
| 138 public: |
| 139 virtual void OnSendBeginFrame(const cc::BeginFrameArgs& args) = 0; |
| 140 }; |
| 141 |
135 // Compositor object to take care of GPU painting. | 142 // Compositor object to take care of GPU painting. |
136 // A Browser compositor object is responsible for generating the final | 143 // A Browser compositor object is responsible for generating the final |
137 // displayable form of pixels comprising a single widget's contents. It draws an | 144 // 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 | 145 // appropriately transformed texture for each transformed view in the widget's |
139 // view hierarchy. | 146 // view hierarchy. |
140 class COMPOSITOR_EXPORT Compositor | 147 class COMPOSITOR_EXPORT Compositor |
141 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), | 148 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), |
142 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { | 149 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { |
143 public: | 150 public: |
144 Compositor(gfx::AcceleratedWidget widget, | 151 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 | 227 // Compositor does not own observers. It is the responsibility of the |
221 // observer to remove itself when it is done observing. | 228 // observer to remove itself when it is done observing. |
222 void AddObserver(CompositorObserver* observer); | 229 void AddObserver(CompositorObserver* observer); |
223 void RemoveObserver(CompositorObserver* observer); | 230 void RemoveObserver(CompositorObserver* observer); |
224 bool HasObserver(const CompositorObserver* observer) const; | 231 bool HasObserver(const CompositorObserver* observer) const; |
225 | 232 |
226 void AddAnimationObserver(CompositorAnimationObserver* observer); | 233 void AddAnimationObserver(CompositorAnimationObserver* observer); |
227 void RemoveAnimationObserver(CompositorAnimationObserver* observer); | 234 void RemoveAnimationObserver(CompositorAnimationObserver* observer); |
228 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; | 235 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; |
229 | 236 |
| 237 void AddBeginFrameObserver( |
| 238 CompositorBeginFrameObserver* observer, |
| 239 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_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; |
285 | 298 |
286 LayerAnimatorCollection* layer_animator_collection() { | 299 LayerAnimatorCollection* layer_animator_collection() { |
287 return &layer_animator_collection_; | 300 return &layer_animator_collection_; |
288 } | 301 } |
289 | 302 |
290 cc::SurfaceIdAllocator* surface_id_allocator() { | 303 cc::SurfaceIdAllocator* surface_id_allocator() { |
291 return surface_id_allocator_.get(); | 304 return surface_id_allocator_.get(); |
292 } | 305 } |
293 | 306 |
| 307 // Exposed for testing. |
| 308 cc::BeginFrameArgs MissedBeginFrameArgsForTesting() { |
| 309 return missed_begin_frame_args_; |
| 310 } |
| 311 |
294 private: | 312 private: |
295 friend class base::RefCounted<Compositor>; | 313 friend class base::RefCounted<Compositor>; |
296 friend class CompositorLock; | 314 friend class CompositorLock; |
297 | 315 |
298 // Called by CompositorLock. | 316 // Called by CompositorLock. |
299 void UnlockCompositor(); | 317 void UnlockCompositor(); |
300 | 318 |
301 // Called to release any pending CompositorLock | 319 // Called to release any pending CompositorLock |
302 void CancelCompositorLock(); | 320 void CancelCompositorLock(); |
303 | 321 |
304 gfx::Size size_; | 322 gfx::Size size_; |
305 | 323 |
306 ui::ContextFactory* context_factory_; | 324 ui::ContextFactory* context_factory_; |
307 | 325 |
308 // The root of the Layer tree drawn by this compositor. | 326 // The root of the Layer tree drawn by this compositor. |
309 Layer* root_layer_; | 327 Layer* root_layer_; |
310 | 328 |
311 ObserverList<CompositorObserver, true> observer_list_; | 329 ObserverList<CompositorObserver, true> observer_list_; |
312 ObserverList<CompositorAnimationObserver> animation_observer_list_; | 330 ObserverList<CompositorAnimationObserver> animation_observer_list_; |
| 331 ObserverList<CompositorBeginFrameObserver> begin_frame_observer_list_; |
313 | 332 |
314 gfx::AcceleratedWidget widget_; | 333 gfx::AcceleratedWidget widget_; |
315 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 334 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
316 scoped_refptr<cc::Layer> root_web_layer_; | 335 scoped_refptr<cc::Layer> root_web_layer_; |
317 scoped_ptr<cc::LayerTreeHost> host_; | 336 scoped_ptr<cc::LayerTreeHost> host_; |
318 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 337 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
319 | 338 |
320 // The manager of vsync parameters for this compositor. | 339 // The manager of vsync parameters for this compositor. |
321 scoped_refptr<CompositorVSyncManager> vsync_manager_; | 340 scoped_refptr<CompositorVSyncManager> vsync_manager_; |
322 | 341 |
323 // The device scale factor of the monitor that this compositor is compositing | 342 // The device scale factor of the monitor that this compositor is compositing |
324 // layers on. | 343 // layers on. |
325 float device_scale_factor_; | 344 float device_scale_factor_; |
326 | 345 |
327 int last_started_frame_; | 346 int last_started_frame_; |
328 int last_ended_frame_; | 347 int last_ended_frame_; |
329 | 348 |
330 bool locks_will_time_out_; | 349 bool locks_will_time_out_; |
331 CompositorLock* compositor_lock_; | 350 CompositorLock* compositor_lock_; |
332 | 351 |
333 LayerAnimatorCollection layer_animator_collection_; | 352 LayerAnimatorCollection layer_animator_collection_; |
334 | 353 |
| 354 // Used to send to any new CompositorBeginFrameObserver immediately. |
| 355 cc::BeginFrameArgs missed_begin_frame_args_; |
| 356 |
335 base::WeakPtrFactory<Compositor> weak_ptr_factory_; | 357 base::WeakPtrFactory<Compositor> weak_ptr_factory_; |
336 | 358 |
337 DISALLOW_COPY_AND_ASSIGN(Compositor); | 359 DISALLOW_COPY_AND_ASSIGN(Compositor); |
338 }; | 360 }; |
339 | 361 |
340 } // namespace ui | 362 } // namespace ui |
341 | 363 |
342 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 364 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |