Chromium Code Reviews| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "cc/output/begin_frame_args.h" | 20 #include "cc/output/begin_frame_args.h" |
| 21 #include "cc/surfaces/surface_sequence.h" | 21 #include "cc/surfaces/surface_sequence.h" |
| 22 #include "cc/trees/layer_tree_host_client.h" | 22 #include "cc/trees/layer_tree_host_client.h" |
| 23 #include "cc/trees/layer_tree_host_single_thread_client.h" | 23 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 24 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
| 25 #include "ui/compositor/compositor_animation_observer.h" | 25 #include "ui/compositor/compositor_animation_observer.h" |
| 26 #include "ui/compositor/compositor_export.h" | 26 #include "ui/compositor/compositor_export.h" |
| 27 #include "ui/compositor/compositor_lock.h" | |
| 27 #include "ui/compositor/compositor_observer.h" | 28 #include "ui/compositor/compositor_observer.h" |
| 28 #include "ui/compositor/layer_animator_collection.h" | 29 #include "ui/compositor/layer_animator_collection.h" |
| 29 #include "ui/gfx/color_space.h" | 30 #include "ui/gfx/color_space.h" |
| 30 #include "ui/gfx/geometry/size.h" | 31 #include "ui/gfx/geometry/size.h" |
| 31 #include "ui/gfx/geometry/vector2d.h" | 32 #include "ui/gfx/geometry/vector2d.h" |
| 32 #include "ui/gfx/gpu_memory_buffer.h" | 33 #include "ui/gfx/gpu_memory_buffer.h" |
| 33 #include "ui/gfx/native_widget_types.h" | 34 #include "ui/gfx/native_widget_types.h" |
| 34 | 35 |
| 35 namespace base { | 36 namespace base { |
| 36 class SingleThreadTaskRunner; | 37 class SingleThreadTaskRunner; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 61 | 62 |
| 62 namespace ui { | 63 namespace ui { |
| 63 | 64 |
| 64 class Compositor; | 65 class Compositor; |
| 65 class CompositorVSyncManager; | 66 class CompositorVSyncManager; |
| 66 class LatencyInfo; | 67 class LatencyInfo; |
| 67 class Layer; | 68 class Layer; |
| 68 class Reflector; | 69 class Reflector; |
| 69 class ScopedAnimationDurationScaleMode; | 70 class ScopedAnimationDurationScaleMode; |
| 70 | 71 |
| 71 const int kCompositorLockTimeoutMs = 67; | 72 constexpr int kCompositorLockTimeoutMs = 67; |
| 72 | 73 |
| 73 class COMPOSITOR_EXPORT ContextFactoryObserver { | 74 class COMPOSITOR_EXPORT ContextFactoryObserver { |
| 74 public: | 75 public: |
| 75 virtual ~ContextFactoryObserver() {} | 76 virtual ~ContextFactoryObserver() {} |
| 76 | 77 |
| 77 // Notifies that the ContextProvider returned from | 78 // Notifies that the ContextProvider returned from |
| 78 // ui::ContextFactory::SharedMainThreadContextProvider was lost. When this | 79 // ui::ContextFactory::SharedMainThreadContextProvider was lost. When this |
| 79 // is called, the old resources (e.g. shared context, GL helper) still | 80 // is called, the old resources (e.g. shared context, GL helper) still |
| 80 // exist, but are about to be destroyed. Getting a reference to those | 81 // exist, but are about to be destroyed. Getting a reference to those |
| 81 // resources from the ContextFactory (e.g. through | 82 // resources from the ContextFactory (e.g. through |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; | 161 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; |
| 161 | 162 |
| 162 // Gets the task graph runner. | 163 // Gets the task graph runner. |
| 163 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; | 164 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; |
| 164 | 165 |
| 165 virtual void AddObserver(ContextFactoryObserver* observer) = 0; | 166 virtual void AddObserver(ContextFactoryObserver* observer) = 0; |
| 166 | 167 |
| 167 virtual void RemoveObserver(ContextFactoryObserver* observer) = 0; | 168 virtual void RemoveObserver(ContextFactoryObserver* observer) = 0; |
| 168 }; | 169 }; |
| 169 | 170 |
| 170 // This class represents a lock on the compositor, that can be used to prevent | |
| 171 // commits to the compositor tree while we're waiting for an asynchronous | |
| 172 // event. The typical use case is when waiting for a renderer to produce a frame | |
| 173 // at the right size. The caller keeps a reference on this object, and drops the | |
| 174 // reference once it desires to release the lock. | |
| 175 // By default, the lock will be cancelled after a short timeout to ensure | |
| 176 // responsiveness of the UI, so the compositor tree should be kept in a | |
| 177 // "reasonable" state while the lock is held. If the compositor sets | |
| 178 // locks to not time out, then the lock will remain in effect until destroyed. | |
| 179 // Don't instantiate this class directly, use Compositor::GetCompositorLock. | |
| 180 class COMPOSITOR_EXPORT CompositorLock | |
| 181 : public base::RefCounted<CompositorLock>, | |
| 182 public base::SupportsWeakPtr<CompositorLock> { | |
| 183 private: | |
| 184 friend class base::RefCounted<CompositorLock>; | |
| 185 friend class Compositor; | |
| 186 | |
| 187 explicit CompositorLock(Compositor* compositor); | |
| 188 ~CompositorLock(); | |
| 189 | |
| 190 void CancelLock(); | |
| 191 | |
| 192 Compositor* compositor_; | |
| 193 DISALLOW_COPY_AND_ASSIGN(CompositorLock); | |
| 194 }; | |
| 195 | |
| 196 // Compositor object to take care of GPU painting. | 171 // Compositor object to take care of GPU painting. |
| 197 // A Browser compositor object is responsible for generating the final | 172 // A Browser compositor object is responsible for generating the final |
| 198 // displayable form of pixels comprising a single widget's contents. It draws an | 173 // displayable form of pixels comprising a single widget's contents. It draws an |
| 199 // appropriately transformed texture for each transformed view in the widget's | 174 // appropriately transformed texture for each transformed view in the widget's |
| 200 // view hierarchy. | 175 // view hierarchy. |
| 201 class COMPOSITOR_EXPORT Compositor | 176 class COMPOSITOR_EXPORT Compositor |
| 202 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), | 177 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), |
| 203 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { | 178 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient), |
| 179 NON_EXPORTED_BASE(public CompositorLockDelegate) { | |
| 204 public: | 180 public: |
| 205 Compositor(const cc::FrameSinkId& frame_sink_id, | 181 Compositor(const cc::FrameSinkId& frame_sink_id, |
| 206 ui::ContextFactory* context_factory, | 182 ui::ContextFactory* context_factory, |
| 207 ui::ContextFactoryPrivate* context_factory_private, | 183 ui::ContextFactoryPrivate* context_factory_private, |
| 208 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 184 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 209 ~Compositor() override; | 185 ~Compositor() override; |
| 210 | 186 |
| 211 ui::ContextFactory* context_factory() { return context_factory_; } | 187 ui::ContextFactory* context_factory() { return context_factory_; } |
| 212 | 188 |
| 213 ui::ContextFactoryPrivate* context_factory_private() { | 189 ui::ContextFactoryPrivate* context_factory_private() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 // Compositor does not own observers. It is the responsibility of the | 294 // Compositor does not own observers. It is the responsibility of the |
| 319 // observer to remove itself when it is done observing. | 295 // observer to remove itself when it is done observing. |
| 320 void AddObserver(CompositorObserver* observer); | 296 void AddObserver(CompositorObserver* observer); |
| 321 void RemoveObserver(CompositorObserver* observer); | 297 void RemoveObserver(CompositorObserver* observer); |
| 322 bool HasObserver(const CompositorObserver* observer) const; | 298 bool HasObserver(const CompositorObserver* observer) const; |
| 323 | 299 |
| 324 void AddAnimationObserver(CompositorAnimationObserver* observer); | 300 void AddAnimationObserver(CompositorAnimationObserver* observer); |
| 325 void RemoveAnimationObserver(CompositorAnimationObserver* observer); | 301 void RemoveAnimationObserver(CompositorAnimationObserver* observer); |
| 326 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; | 302 bool HasAnimationObserver(const CompositorAnimationObserver* observer) const; |
| 327 | 303 |
| 328 // Change the timeout behavior for all future locks that are created. Locks | |
| 329 // should time out if there is an expectation that the compositor will be | |
| 330 // responsive. | |
| 331 void SetLocksWillTimeOut(bool locks_will_time_out) { | |
| 332 locks_will_time_out_ = locks_will_time_out; | |
| 333 } | |
| 334 | |
| 335 // Creates a compositor lock. Returns NULL if it is not possible to lock at | 304 // Creates a compositor lock. Returns NULL if it is not possible to lock at |
| 336 // this time (i.e. we're waiting to complete a previous unlock). | 305 // this time (i.e. we're waiting to complete a previous unlock). If the |
| 337 scoped_refptr<CompositorLock> GetCompositorLock(); | 306 // timeout is null, then no timeout is used. |
| 307 scoped_refptr<CompositorLock> GetCompositorLock( | |
| 308 CompositorLockClient* client, | |
|
piman
2017/03/24 04:05:31
2 things.
1- I assume we want the client to outliv
danakj
2017/03/24 14:49:26
Thank you, good point.
danakj
2017/03/24 16:54:56
I've made CompositorLock a unique_ptr instead, but
| |
| 309 base::TimeDelta timeout = | |
| 310 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); | |
| 338 | 311 |
| 339 // Internal functions, called back by command-buffer contexts on swap buffer | 312 // Internal functions, called back by command-buffer contexts on swap buffer |
| 340 // events. | 313 // events. |
| 341 | 314 |
| 342 // Signals swap has been posted. | 315 // Signals swap has been posted. |
| 343 void OnSwapBuffersPosted(); | 316 void OnSwapBuffersPosted(); |
| 344 | 317 |
| 345 // Signals swap has completed. | 318 // Signals swap has completed. |
| 346 void OnSwapBuffersComplete(); | 319 void OnSwapBuffersComplete(); |
| 347 | 320 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 LayerAnimatorCollection* layer_animator_collection() { | 356 LayerAnimatorCollection* layer_animator_collection() { |
| 384 return &layer_animator_collection_; | 357 return &layer_animator_collection_; |
| 385 } | 358 } |
| 386 | 359 |
| 387 const cc::FrameSinkId& frame_sink_id() const { return frame_sink_id_; } | 360 const cc::FrameSinkId& frame_sink_id() const { return frame_sink_id_; } |
| 388 int committed_frame_number() const { return committed_frame_number_; } | 361 int committed_frame_number() const { return committed_frame_number_; } |
| 389 float refresh_rate() const { return refresh_rate_; } | 362 float refresh_rate() const { return refresh_rate_; } |
| 390 | 363 |
| 391 private: | 364 private: |
| 392 friend class base::RefCounted<Compositor>; | 365 friend class base::RefCounted<Compositor>; |
| 393 friend class CompositorLock; | |
| 394 | 366 |
| 395 // Called by CompositorLock. | 367 // CompositorLockDelegate implementation. |
| 396 void UnlockCompositor(); | 368 void DoUnlockCompositor() override; |
| 397 | |
| 398 // Called to release any pending CompositorLock | |
| 399 void CancelCompositorLock(); | |
| 400 | 369 |
| 401 gfx::Size size_; | 370 gfx::Size size_; |
| 402 | 371 |
| 403 ui::ContextFactory* context_factory_; | 372 ui::ContextFactory* context_factory_; |
| 404 ui::ContextFactoryPrivate* context_factory_private_; | 373 ui::ContextFactoryPrivate* context_factory_private_; |
| 405 | 374 |
| 406 // The root of the Layer tree drawn by this compositor. | 375 // The root of the Layer tree drawn by this compositor. |
| 407 Layer* root_layer_; | 376 Layer* root_layer_; |
| 408 | 377 |
| 409 base::ObserverList<CompositorObserver, true> observer_list_; | 378 base::ObserverList<CompositorObserver, true> observer_list_; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 426 std::unique_ptr<cc::LayerTreeHost> host_; | 395 std::unique_ptr<cc::LayerTreeHost> host_; |
| 427 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 396 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 428 | 397 |
| 429 // The manager of vsync parameters for this compositor. | 398 // The manager of vsync parameters for this compositor. |
| 430 scoped_refptr<CompositorVSyncManager> vsync_manager_; | 399 scoped_refptr<CompositorVSyncManager> vsync_manager_; |
| 431 | 400 |
| 432 // The device scale factor of the monitor that this compositor is compositing | 401 // The device scale factor of the monitor that this compositor is compositing |
| 433 // layers on. | 402 // layers on. |
| 434 float device_scale_factor_; | 403 float device_scale_factor_; |
| 435 | 404 |
| 436 bool locks_will_time_out_; | |
| 437 CompositorLock* compositor_lock_; | 405 CompositorLock* compositor_lock_; |
| 438 | 406 |
| 439 LayerAnimatorCollection layer_animator_collection_; | 407 LayerAnimatorCollection layer_animator_collection_; |
| 440 scoped_refptr<cc::AnimationTimeline> animation_timeline_; | 408 scoped_refptr<cc::AnimationTimeline> animation_timeline_; |
| 441 std::unique_ptr<ScopedAnimationDurationScaleMode> slow_animations_; | 409 std::unique_ptr<ScopedAnimationDurationScaleMode> slow_animations_; |
| 442 | 410 |
| 443 gfx::ColorSpace output_color_space_; | 411 gfx::ColorSpace output_color_space_; |
| 444 gfx::ColorSpace blending_color_space_; | 412 gfx::ColorSpace blending_color_space_; |
| 445 | 413 |
| 446 base::WeakPtrFactory<Compositor> weak_ptr_factory_; | 414 base::WeakPtrFactory<Compositor> weak_ptr_factory_; |
| 447 | 415 |
| 448 DISALLOW_COPY_AND_ASSIGN(Compositor); | 416 DISALLOW_COPY_AND_ASSIGN(Compositor); |
| 449 }; | 417 }; |
| 450 | 418 |
| 451 } // namespace ui | 419 } // namespace ui |
| 452 | 420 |
| 453 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 421 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
| OLD | NEW |