display_configuration_controller.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_
  5. #define ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/display/window_tree_host_manager.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "ui/display/display.h"
  11. #include "ui/display/unified_desktop_utils.h"
  12. namespace display {
  13. class DisplayLayout;
  14. class DisplayManager;
  15. } // namespace display
  16. namespace ash {
  17. class DisplayAnimator;
  18. class ScreenRotationAnimator;
  19. // This class controls Display related configuration. Specifically it:
  20. // * Handles animated transitions where appropriate.
  21. // * Limits the frequency of certain operations.
  22. // * Provides a single interface for UI and API classes.
  23. // * TODO: Forwards display configuration changed events to UI and API classes.
  24. class ASH_EXPORT DisplayConfigurationController
  25. : public WindowTreeHostManager::Observer {
  26. public:
  27. // Use SYNC if it is important to rotate immediately after the
  28. // |SetDisplayRotation()|. As a side effect, the animation is less smooth.
  29. // ASYNC is actually slower because it takes longer to rotate the screen after
  30. // a screenshot is taken. http://crbug.com/757851.
  31. enum RotationAnimation {
  32. ANIMATION_SYNC = 0,
  33. ANIMATION_ASYNC,
  34. };
  35. DisplayConfigurationController(
  36. display::DisplayManager* display_manager,
  37. WindowTreeHostManager* window_tree_host_manager);
  38. DisplayConfigurationController(const DisplayConfigurationController&) =
  39. delete;
  40. DisplayConfigurationController& operator=(
  41. const DisplayConfigurationController&) = delete;
  42. ~DisplayConfigurationController() override;
  43. // Sets the layout for the current displays with a fade in/out
  44. // animation.
  45. void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout);
  46. // This should be called instead of SetDisplayLayout() to set the display
  47. // layout in the case of Unified Desktop mode. A fade in/out animation is
  48. // used as well.
  49. void SetUnifiedDesktopLayoutMatrix(
  50. const display::UnifiedDesktopLayoutMatrix& matrix);
  51. // Sets the mirror mode with a fade-in/fade-out animation. Affects all
  52. // displays. If |throttle| is true, this will fail if called within the
  53. // throttle time.
  54. void SetMirrorMode(bool mirror, bool throttle);
  55. // Sets the display's rotation with animation if available.
  56. void SetDisplayRotation(int64_t display_id,
  57. display::Display::Rotation rotation,
  58. display::Display::RotationSource source,
  59. RotationAnimation mode = ANIMATION_ASYNC);
  60. // Returns the rotation of the display given by |display_id|. This returns
  61. // the target rotation when the display is being rotated.
  62. display::Display::Rotation GetTargetRotation(int64_t display_id);
  63. // Sets the primary display id. If |throttle| is true, this will fail if
  64. // called within the throttle time.
  65. void SetPrimaryDisplayId(int64_t display_id, bool throttle);
  66. // In Unified Desktop mode, we consider the display in which the shelf will be
  67. // placed to be the "primary mirroring display". Note that this is different
  68. // from the "normal" primary display, which is just the single unified display
  69. // in unified mode. This display will be:
  70. // - The bottom-left in the matrix if the shelf alignment is "bottom",
  71. // - The top-left in the matrix if the shelf alignment is "left",
  72. // - The top-right in the matrix if the shelf alignment is "right".
  73. // This should only be called when Unified Desktop mode is active.
  74. display::Display GetPrimaryMirroringDisplayForUnifiedDesktop() const;
  75. // WindowTreeHostManager::Observer
  76. void OnDisplayConfigurationChanged() override;
  77. static void DisableAnimatorForTest();
  78. protected:
  79. friend class DisplayConfigurationControllerTestApi;
  80. // Allow tests to enable or disable animations.
  81. void SetAnimatorForTest(bool enable);
  82. private:
  83. class DisplayChangeLimiter;
  84. // Sets the timeout for the DisplayChangeLimiter if it exists. Call this
  85. // *before* starting any animations.
  86. void SetThrottleTimeout(int64_t throttle_ms);
  87. bool IsLimited();
  88. void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout);
  89. void SetMirrorModeImpl(bool mirror);
  90. void SetPrimaryDisplayIdImpl(int64_t display_id);
  91. void SetUnifiedDesktopLayoutMatrixImpl(
  92. const display::UnifiedDesktopLayoutMatrix& matrix);
  93. // Returns the ScreenRotationAnimator associated with the |display_id|'s
  94. // |root_window|. If there is no existing ScreenRotationAnimator for
  95. // |root_window|, it will make one and store in the |root_window| property
  96. // |kScreenRotationAnimatorKey|.
  97. ScreenRotationAnimator* GetScreenRotationAnimatorForDisplay(
  98. int64_t display_id);
  99. display::DisplayManager* display_manager_; // weak ptr
  100. WindowTreeHostManager* window_tree_host_manager_; // weak ptr
  101. std::unique_ptr<DisplayAnimator> display_animator_;
  102. std::unique_ptr<DisplayChangeLimiter> limiter_;
  103. base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_{this};
  104. };
  105. } // namespace ash
  106. #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_