fix_disabling_background_throttling_in_compositor.patch 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 64775be482d47143fb56d815d390bd56875e8493..347f135c75c226faec33199909cc5ee4a8924a24 100644
  13. --- a/ui/compositor/compositor.cc
  14. +++ b/ui/compositor/compositor.cc
  15. @@ -338,7 +338,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. @@ -530,8 +531,11 @@ void Compositor::SetVisible(bool visible) {
  26. host_->SetVisible(visible);
  27. // Visibility is reset when the output surface is lost, so this must also be
  28. // updated then.
  29. - if (display_private_)
  30. - display_private_->SetDisplayVisible(visible);
  31. + if (display_private_) {
  32. + // Invisible display is throttling itself.
  33. + display_private_->SetDisplayVisible(
  34. + background_throttling_ ? visible : true);
  35. + }
  36. }
  37. bool Compositor::IsVisible() {
  38. @@ -958,4 +962,13 @@ const cc::LayerTreeSettings& Compositor::GetLayerTreeSettings() const {
  39. return host_->GetSettings();
  40. }
  41. +void Compositor::SetBackgroundThrottling(bool background_throttling_enabled) {
  42. + background_throttling_ = background_throttling_enabled;
  43. + if (display_private_) {
  44. + // Invisible display is throttling itself.
  45. + display_private_->SetDisplayVisible(
  46. + background_throttling_ ? host_->IsVisible() : true);
  47. + }
  48. +}
  49. +
  50. } // namespace ui
  51. diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
  52. index e1781e682f2e1217fe4cc7ab26cd82e7bcc352e7..2cd96e3518b9a62091a69782b65ef61a8e798022 100644
  53. --- a/ui/compositor/compositor.h
  54. +++ b/ui/compositor/compositor.h
  55. @@ -522,6 +522,10 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  56. return host_->saved_events_metrics_count_for_testing();
  57. }
  58. + // Sets |background_throttling_| responsible for suspending drawing
  59. + // and switching frames.
  60. + void SetBackgroundThrottling(bool background_throttling_enabled);
  61. +
  62. private:
  63. friend class base::RefCounted<Compositor>;
  64. friend class TotalAnimationThroughputReporter;
  65. @@ -628,6 +632,12 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  66. // See go/report-ux-metrics-at-painting for details.
  67. bool animation_started_ = false;
  68. + // Background throttling is a default Chromium behaviour. It occurs
  69. + // when the |display_private_| is not visible by prevent drawing and swapping
  70. + // frames. When it is disabled we are keeping |display_private_| always
  71. + // visible in order to keep generating frames.
  72. + bool background_throttling_ = true;
  73. +
  74. TrackerId next_throughput_tracker_id_ = 1u;
  75. struct TrackerState {
  76. TrackerState();