fix_disabling_background_throttling_in_compositor.patch 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Michal Pichlinski <[email protected]>
  3. Date: Thu, 15 Jun 2023 23:04:48 +0200
  4. Subject: allow disabling throttling in the `viz::DisplayScheduler` per
  5. `ui::Compositor`
  6. In Chromium when the `viz::DisplayScheduler` is invisible it throttles
  7. its work by dropping frame draws and swaps.
  8. This patch allows disbling this throttling by preventing transition to
  9. invisible state of the `viz::DisplayScheduler` owned
  10. by the `ui::Compositor`.
  11. diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
  12. index 56f22ef70665d66692ca9d50e6b822a6ce3740de..dfd02e5e83684aa2f6c7188598095ed09a80bd80 100644
  13. --- a/ui/compositor/compositor.cc
  14. +++ b/ui/compositor/compositor.cc
  15. @@ -342,7 +342,8 @@ void Compositor::SetLayerTreeFrameSink(
  16. if (display_private_) {
  17. disabled_swap_until_resize_ = false;
  18. display_private_->Resize(size());
  19. - display_private_->SetDisplayVisible(host_->IsVisible());
  20. + // Invisible display is throttling itself.
  21. + display_private_->SetDisplayVisible(background_throttling_ ? host_->IsVisible() : true);
  22. display_private_->SetDisplayColorSpaces(display_color_spaces_);
  23. display_private_->SetDisplayColorMatrix(
  24. gfx::SkM44ToTransform(display_color_matrix_));
  25. @@ -554,7 +555,9 @@ void Compositor::SetVisible(bool visible) {
  26. // updated then. We need to call this even if the visibility hasn't changed,
  27. // for the same reason.
  28. if (display_private_)
  29. - display_private_->SetDisplayVisible(visible);
  30. + // Invisible display is throttling itself.
  31. + display_private_->SetDisplayVisible(
  32. + background_throttling_ ? visible : true);
  33. if (changed) {
  34. for (auto& observer : observer_list_) {
  35. @@ -1016,4 +1019,13 @@ void Compositor::MaybeUpdateObserveBeginFrame() {
  36. host_begin_frame_observer_->GetBoundRemote());
  37. }
  38. +void Compositor::SetBackgroundThrottling(bool background_throttling_enabled) {
  39. + background_throttling_ = background_throttling_enabled;
  40. + if (display_private_) {
  41. + // Invisible display is throttling itself.
  42. + display_private_->SetDisplayVisible(
  43. + background_throttling_ ? host_->IsVisible() : true);
  44. + }
  45. +}
  46. +
  47. } // namespace ui
  48. diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
  49. index 7d529e1af98d8392a98a7dbf9f3faff90f02c8bd..0ca7e3a2d8009f8334caeadf944de5e8e0985be9 100644
  50. --- a/ui/compositor/compositor.h
  51. +++ b/ui/compositor/compositor.h
  52. @@ -508,6 +508,10 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  53. const cc::LayerTreeSettings& GetLayerTreeSettings() const;
  54. + // Sets |background_throttling_| responsible for suspending drawing
  55. + // and switching frames.
  56. + void SetBackgroundThrottling(bool background_throttling_enabled);
  57. +
  58. size_t saved_events_metrics_count_for_testing() const {
  59. return host_->saved_events_metrics_count_for_testing();
  60. }
  61. @@ -638,6 +642,12 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  62. // See go/report-ux-metrics-at-painting for details.
  63. bool animation_started_ = false;
  64. + // Background throttling is a default Chromium behaviour. It occurs
  65. + // when the |display_private_| is not visible by prevent drawing and swapping
  66. + // frames. When it is disabled we are keeping |display_private_| always
  67. + // visible in order to keep generating frames.
  68. + bool background_throttling_ = true;
  69. +
  70. TrackerId next_throughput_tracker_id_ = 1u;
  71. struct TrackerState {
  72. TrackerState();