GCC Code Coverage Report


Directory: ./
File: lib/output_p.h
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 29 30 96.7%
Branches: 14 16 87.5%

Line Branch Exec Source
1 /*************************************************************************
2 Copyright © 2020 Roman Gilg <subdiff@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 **************************************************************************/
18 #ifndef OUTPUT_P_H
19 #define OUTPUT_P_H
20
21 #include "output.h"
22
23 #include <QRectF>
24 #include <QScopedPointer>
25
26 namespace Disman
27 {
28
29 class Q_DECL_HIDDEN Output::Private
30 {
31 public:
32 Private();
33 Private(const Private& other);
34
35 ModePtr mode(QSize const& resolution, int refresh_rate) const;
36
37 template<typename M>
38 ModePtr get_mode(M const& mode) const
39 {
40 return mode;
41 }
42
43 template<typename List>
44 818 QSize best_resolution(const List& modes) const
45 {
46 818 QSize best_size{0, 0};
47
48
2/2
✓ Branch 8 taken 1006 times.
✓ Branch 9 taken 409 times.
2830 for (auto _mode : modes) {
49 2012 auto mode = get_mode(_mode);
50 2012 auto mode_size = mode->size();
51
2/2
✓ Branch 4 taken 465 times.
✓ Branch 5 taken 541 times.
2012 if (best_size.width() * best_size.height() < mode_size.width() * mode_size.height()) {
52 930 best_size = mode_size;
53 }
54 }
55 818 return best_size;
56 }
57
58 template<typename List>
59 818 int best_refresh_rate(const List& modes, QSize const& resolution) const
60 {
61 818 ModePtr best_mode;
62 818 int best_refresh = 0;
63
64
6/6
✓ Branch 5 taken 408 times.
✓ Branch 6 taken 598 times.
✓ Branch 8 taken 408 times.
✓ Branch 9 taken 598 times.
✓ Branch 12 taken 1006 times.
✓ Branch 13 taken 409 times.
6038 for (auto _mode : modes) {
65 2012 auto mode = get_mode(_mode);
66
2/2
✓ Branch 3 taken 598 times.
✓ Branch 4 taken 408 times.
2012 if (resolution != mode->size()) {
67 1196 continue;
68 }
69
1/2
✓ Branch 2 taken 408 times.
✗ Branch 3 not taken.
816 if (best_refresh < mode->refresh()) {
70 816 best_mode = mode;
71 816 best_refresh = mode->refresh();
72 }
73 }
74
75 1636 return best_refresh;
76 818 }
77
78 template<typename List>
79 818 ModePtr best_mode(const List& modes) const
80 {
81 818 auto const resolution = best_resolution(modes);
82 818 auto const refresh_rate = best_refresh_rate(modes, resolution);
83
84 818 return mode(resolution, refresh_rate);
85 }
86
87 bool compareModeMap(const ModeMap& before, const ModeMap& after);
88 void apply_global();
89
90 int id;
91 std::string name;
92 std::string description;
93 std::string hash;
94 Type type;
95 ModeMap modeList;
96 int replication_source;
97
98 QSize resolution;
99 int refresh_rate{0};
100 bool adapt_sync{false};
101
102 std::string preferredMode;
103 std::vector<std::string> preferred_modes;
104 QSize physical_size;
105 QPointF position;
106 QRectF enforced_geometry;
107 Rotation rotation;
108 qreal scale;
109 bool enabled;
110 bool supports_adapt_sync_toggle{false};
111 bool follow_preferred_mode = false;
112
113 bool auto_resolution{false};
114 bool auto_refresh_rate{false};
115 bool auto_rotate{true};
116 bool auto_rotate_only_in_tablet_mode{true};
117
118 Retention retention{Retention::Undefined};
119
120 GlobalData global;
121 };
122
123 template<>
124 658 inline ModePtr Output::Private::get_mode(std::string const& modeId) const
125 {
126
1/2
✓ Branch 3 taken 658 times.
✗ Branch 4 not taken.
658 if (auto mode = modeList.find(modeId); mode != modeList.end()) {
127 658 return mode->second;
128 }
129 return ModePtr();
130 }
131
132 template<>
133 inline ModePtr
134 1354 Output::Private::get_mode(std::pair<std::string const, std::shared_ptr<Mode>> const& mode) const
135 {
136 1354 return mode.second;
137 }
138
139 }
140
141 #endif
142