Debian Codegraph @

xbmc/windowing/wayland/Output.h

raw
1 /*
2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #pragma once
10
11 #include "threads/CriticalSection.h"
12 #include "utils/Geometry.h"
13
14 #include <atomic>
15 #include <cstdint>
16 #include <mutex>
17 #include <set>
18 #include <tuple>
19
20 #include <wayland-client-protocol.hpp>
21
22 namespace KODI
23 {
24 namespace WINDOWING
25 {
26 namespace WAYLAND
27 {
28
29 /**
30 * wl_output handler that collects information from the compositor and then
31 * passes it on when everything is available
32 */
33 class COutput
34 {
35 public:
36 COutput(std::uint32_t globalName, wayland::output_t const & output, std::function<void()> doneHandler);
37 ~COutput() noexcept;
38
39 wayland::output_t const& GetWaylandOutput() const
40 {
41 return m_output;
42 }
43 std::uint32_t GetGlobalName() const
44 {
45 return m_globalName;
46 }
47 /**
48 * Get output position in compositor coordinate space
49 * \return (x, y) tuple of output position
50 */
51 CPointInt GetPosition() const
52 {
53 std::unique_lock<CCriticalSection> lock(m_geometryCriticalSection);
54 return m_position;
55 }
56 /**
57 * Get output physical size in millimeters
58 * \return (width, height) tuple of output physical size in millimeters
59 */
60 CSizeInt GetPhysicalSize() const
61 {
62 std::unique_lock<CCriticalSection> lock(m_geometryCriticalSection);
63 return m_physicalSize;
64 }
65 std::string const& GetMake() const
66 {
67 std::unique_lock<CCriticalSection> lock(m_geometryCriticalSection);
68 return m_make;
69 }
70 std::string const& GetModel() const
71 {
72 std::unique_lock<CCriticalSection> lock(m_geometryCriticalSection);
73 return m_model;
74 }
75 std::int32_t GetScale() const
76 {
77 return m_scale;
78 }
79
80 struct Mode
81 {
82 CSizeInt size;
83 std::int32_t refreshMilliHz;
84 Mode(CSizeInt size, std::int32_t refreshMilliHz)
85 : size{size}, refreshMilliHz(refreshMilliHz)
86 {}
87
88 float GetRefreshInHz() const
89 {
90 return refreshMilliHz / 1000.0f;
91 }
92
93 std::tuple<std::int32_t, std::int32_t, std::int32_t> AsTuple() const
94 {
95 return std::make_tuple(size.Width(), size.Height(), refreshMilliHz);
96 }
97
98 // Comparison operator needed for std::set
99 bool operator<(const Mode& right) const
100 {
101 return AsTuple() < right.AsTuple();
102 }
103
104 bool operator==(const Mode& right) const
105 {
106 return AsTuple() == right.AsTuple();
107 }
108
109 bool operator!=(const Mode& right) const
110 {
111 return !(*this == right);
112 }
113 };
114
115 std::set<Mode> const& GetModes() const
116 {
117 return m_modes;
118 }
119 Mode const& GetCurrentMode() const;
120 Mode const& GetPreferredMode() const;
121
122 float GetPixelRatioForMode(Mode const& mode) const;
123 float GetDpiForMode(Mode const& mode) const;
124 float GetCurrentDpi() const;
125
126 private:
127 COutput(COutput const& other) = delete;
128 COutput& operator=(COutput const& other) = delete;
129
130 std::uint32_t m_globalName;
131 wayland::output_t m_output;
132 std::function<void()> m_doneHandler;
133
134 mutable CCriticalSection m_geometryCriticalSection;
135 mutable CCriticalSection m_iteratorCriticalSection;
136
137 CPointInt m_position;
138 CSizeInt m_physicalSize;
139 std::string m_make, m_model;
140 std::atomic<std::int32_t> m_scale{1}; // default scale of 1 if no wl_output::scale is sent
141
142 std::set<Mode> m_modes;
143 // For std::set, insertion never invalidates existing iterators, and modes are
144 // never removed, so the usage of iterators is safe
145 std::set<Mode>::iterator m_currentMode{m_modes.end()};
146 std::set<Mode>::iterator m_preferredMode{m_modes.end()};
147 };
148
149
150 }
151 }
152 }