fix_disabling_background_throttling_in_compositor.patch 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 12cf38959be01d05cd43a9635ac87538c4f5e5ad..1a2a1bb5480085432c9575a90fb6959b9d0eac87 100644
  13. --- a/ui/compositor/compositor.cc
  14. +++ b/ui/compositor/compositor.cc
  15. @@ -350,7 +350,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. @@ -570,7 +571,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. observer_list_.Notify(&CompositorObserver::OnCompositorVisibilityChanged,
  35. @@ -1023,6 +1026,15 @@ 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. #if BUILDFLAG(IS_CHROMEOS)
  48. void Compositor::SetSeamlessRefreshRates(
  49. const std::vector<float>& seamless_refresh_rates) {
  50. diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
  51. index 8e1e8c3eb1c23a6b8dcb006154ab36b91e6bcc04..962e807c07365015b964c9b6361035d27ec8e4ae 100644
  52. --- a/ui/compositor/compositor.h
  53. +++ b/ui/compositor/compositor.h
  54. @@ -511,6 +511,10 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  55. const cc::LayerTreeSettings& GetLayerTreeSettings() const;
  56. + // Sets |background_throttling_| responsible for suspending drawing
  57. + // and switching frames.
  58. + void SetBackgroundThrottling(bool background_throttling_enabled);
  59. +
  60. size_t saved_events_metrics_count_for_testing() const {
  61. return host_->saved_events_metrics_count_for_testing();
  62. }
  63. @@ -684,6 +688,12 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  64. // See go/report-ux-metrics-at-painting for details.
  65. bool animation_started_ = false;
  66. + // Background throttling is a default Chromium behaviour. It occurs
  67. + // when the |display_private_| is not visible by prevent drawing and swapping
  68. + // frames. When it is disabled we are keeping |display_private_| always
  69. + // visible in order to keep generating frames.
  70. + bool background_throttling_ = true;
  71. +
  72. TrackerId next_compositor_metrics_tracker_id_ = 1u;
  73. struct TrackerState {
  74. TrackerState();