wayland_display_observer.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2018 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 COMPONENTS_EXO_WAYLAND_WAYLAND_DISPLAY_OBSERVER_H_
  5. #define COMPONENTS_EXO_WAYLAND_WAYLAND_DISPLAY_OBSERVER_H_
  6. #include <stdint.h>
  7. #include <wayland-server-protocol-core.h>
  8. #include "base/observer_list.h"
  9. #include "ui/display/display.h"
  10. #include "ui/display/display_observer.h"
  11. struct wl_resource;
  12. namespace exo {
  13. namespace wayland {
  14. class WaylandDisplayOutput;
  15. // An observer that allows display information changes to be sent
  16. // via different protocols while being synced with the wl_output's
  17. // "done" event through WaylandDisplayHandler.
  18. class WaylandDisplayObserver : public base::CheckedObserver {
  19. public:
  20. WaylandDisplayObserver() {}
  21. // Returns |true| if the observer reported any changes and needs
  22. // to be followed by "done" event, |false| otherwise.
  23. virtual bool SendDisplayMetrics(const display::Display& display,
  24. uint32_t changed_metrics) = 0;
  25. // Called when wl_output is destroyed.
  26. virtual void OnOutputDestroyed() = 0;
  27. protected:
  28. ~WaylandDisplayObserver() override {}
  29. };
  30. class WaylandDisplayHandler : public display::DisplayObserver,
  31. public WaylandDisplayObserver {
  32. public:
  33. WaylandDisplayHandler(WaylandDisplayOutput* output,
  34. wl_resource* output_resource);
  35. WaylandDisplayHandler(const WaylandDisplayHandler&) = delete;
  36. WaylandDisplayHandler& operator=(const WaylandDisplayHandler&) = delete;
  37. ~WaylandDisplayHandler() override;
  38. void Initialize();
  39. void AddObserver(WaylandDisplayObserver* observer);
  40. void RemoveObserver(WaylandDisplayObserver* observer);
  41. int64_t id() const;
  42. // Overridden from display::DisplayObserver:
  43. void OnDisplayMetricsChanged(const display::Display& display,
  44. uint32_t changed_metrics) override;
  45. // Called when an xdg_output object is created through get_xdg_output()
  46. // request by the wayland client.
  47. void OnXdgOutputCreated(wl_resource* xdg_output_resource);
  48. // Unset the xdg output object.
  49. void UnsetXdgOutputResource();
  50. size_t CountObserversForTesting() const;
  51. protected:
  52. wl_resource* output_resource() const { return output_resource_; }
  53. // Overridable for testing.
  54. virtual void XdgOutputSendLogicalPosition(const gfx::Point& position);
  55. virtual void XdgOutputSendLogicalSize(const gfx::Size& size);
  56. virtual void XdgOutputSendDescription(const std::string& desc);
  57. private:
  58. // Overridden from WaylandDisplayObserver:
  59. bool SendDisplayMetrics(const display::Display& display,
  60. uint32_t changed_metrics) override;
  61. void OnOutputDestroyed() override;
  62. // Output.
  63. WaylandDisplayOutput* output_;
  64. // The output resource associated with the display.
  65. wl_resource* const output_resource_;
  66. // Resource associated with a zxdg_output_v1 object.
  67. wl_resource* xdg_output_resource_ = nullptr;
  68. base::ObserverList<WaylandDisplayObserver> observers_;
  69. display::ScopedDisplayObserver display_observer_{this};
  70. };
  71. } // namespace wayland
  72. } // namespace exo
  73. #endif // COMPONENTS_EXO_WAYLAND_WAYLAND_DISPLAY_OBSERVER_H_