desktop_resizer_x11.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2020 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 REMOTING_HOST_DESKTOP_RESIZER_X11_H_
  5. #define REMOTING_HOST_DESKTOP_RESIZER_X11_H_
  6. #include <string.h>
  7. #include "base/command_line.h"
  8. #include "base/memory/ptr_util.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "remoting/base/logging.h"
  11. #include "remoting/host/desktop_resizer.h"
  12. #include "remoting/host/linux/x11_util.h"
  13. #include "ui/gfx/x/randr.h"
  14. namespace remoting {
  15. // Wrapper class for the XRRScreenResources struct.
  16. class ScreenResources {
  17. public:
  18. ScreenResources();
  19. ~ScreenResources();
  20. bool Refresh(x11::RandR* randr, x11::Window window);
  21. x11::RandR::Mode GetIdForMode(const std::string& name);
  22. x11::RandR::GetScreenResourcesCurrentReply* get();
  23. private:
  24. std::unique_ptr<x11::RandR::GetScreenResourcesCurrentReply> resources_;
  25. };
  26. class DesktopResizerX11 : public DesktopResizer {
  27. public:
  28. DesktopResizerX11();
  29. DesktopResizerX11(const DesktopResizerX11&) = delete;
  30. DesktopResizerX11& operator=(const DesktopResizerX11&) = delete;
  31. ~DesktopResizerX11() override;
  32. // DesktopResizer interface
  33. ScreenResolution GetCurrentResolution(webrtc::ScreenId screen_id) override;
  34. std::list<ScreenResolution> GetSupportedResolutions(
  35. const ScreenResolution& preferred,
  36. webrtc::ScreenId screen_id) override;
  37. void SetResolution(const ScreenResolution& resolution,
  38. webrtc::ScreenId screen_id) override;
  39. void RestoreResolution(const ScreenResolution& original,
  40. webrtc::ScreenId screen_id) override;
  41. private:
  42. // Add a mode matching the specified resolution and switch to it.
  43. void SetResolutionNewMode(x11::RandR::Output output,
  44. const ScreenResolution& resolution);
  45. // Attempt to switch to an existing mode matching the specified resolution
  46. // using RandR, if such a resolution exists. Otherwise, do nothing.
  47. void SetResolutionExistingMode(const ScreenResolution& resolution);
  48. // Create a mode, and attach it to the output. If the mode already exists, it
  49. // is left unchanged. Returns the new mode ID, or None (0) on failure.
  50. x11::RandR::Mode CreateMode(x11::RandR::Output output,
  51. const std::string& name,
  52. int width,
  53. int height);
  54. // Remove the specified mode from the output, and delete it. If the mode is in
  55. // use, it is not deleted.
  56. void DeleteMode(x11::RandR::Output output, const std::string& name);
  57. raw_ptr<x11::Connection> connection_;
  58. const raw_ptr<x11::RandR> randr_ = nullptr;
  59. const raw_ptr<const x11::Screen> screen_ = nullptr;
  60. x11::Window root_;
  61. ScreenResources resources_;
  62. bool exact_resize_;
  63. bool has_randr_;
  64. };
  65. } // namespace remoting
  66. #endif // REMOTING_HOST_DESKTOP_RESIZER_X11_H_