1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 
3 /*
4  * Copyright (C) 2017 Red Hat, Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef MONITOR_TEST_UTILS_H
21 #define MONITOR_TEST_UTILS_H
22 
23 #include <glib.h>
24 
25 #include "tests/meta-monitor-manager-test.h"
26 #include "tests/meta-test-utils.h"
27 #include "backends/meta-crtc.h"
28 #include "backends/meta-monitor.h"
29 #include "backends/meta-output.h"
30 
31 #define MAX_N_MODES 25
32 #define MAX_N_OUTPUTS 10
33 #define MAX_N_CRTCS 10
34 #define MAX_N_MONITORS 10
35 #define MAX_N_LOGICAL_MONITORS 10
36 #define MAX_N_SCALES 20
37 
38 /*
39  * The following structures are used to define test cases.
40  *
41  * Each test case consists of a test case setup and a test case expectaction.
42  * and a expected result, consisting
43  * of an array of monitors, logical monitors and a screen size.
44  *
45  * TEST CASE SETUP:
46  *
47  * A test case setup consists of an array of modes, an array of outputs and an
48  * array of CRTCs.
49  *
50  * A mode has a width and height in pixels, and a refresh rate in updates per
51  * second.
52  *
53  * An output has an array of available modes, and a preferred mode. Modes are
54  * defined as indices into the modes array of the test case setup.
55  *
56  * It also has CRTc and an array of possible CRTCs. Crtcs are defined as indices
57  * into the CRTC array. The CRTC value -1 means no CRTC.
58  *
59  * It also has various meta data, such as physical dimension, tile info and
60  * scale.
61  *
62  * A CRTC only has a current mode. A mode is defined as an index into the modes
63  * array.
64  *
65  *
66  * TEST CASE EXPECTS:
67  *
68  * A test case expects consists of an array of monitors, an array of logical
69  * monitors, a output and crtc count, and a screen width.
70  *
71  * A monitor represents a physical monitor (such as an external monitor, or a
72  * laptop panel etc). A monitor consists of an array of outputs, defined by
73  * indices into the setup output array, an array of monitor modes, and the
74  * current mode, defined by an index into the monitor modes array, and the
75  * physical dimensions.
76  *
77  * A logical monitor represents a region of the total screen area. It contains
78  * the expected layout and a scale.
79  */
80 
81 typedef enum _MonitorTestFlag
82 {
83   MONITOR_TEST_FLAG_NONE,
84   MONITOR_TEST_FLAG_NO_STORED
85 } MonitorTestFlag;
86 
87 typedef struct _MonitorTestCaseMode
88 {
89   int width;
90   int height;
91   float refresh_rate;
92   MetaCrtcModeFlag flags;
93 } MonitorTestCaseMode;
94 
95 typedef struct _MonitorTestCaseOutput
96 {
97   int crtc;
98   int modes[MAX_N_MODES];
99   int n_modes;
100   int preferred_mode;
101   int possible_crtcs[MAX_N_CRTCS];
102   int n_possible_crtcs;
103   int width_mm;
104   int height_mm;
105   MetaTileInfo tile_info;
106   float scale;
107   gboolean is_laptop_panel;
108   gboolean is_underscanning;
109   const char *serial;
110   MetaMonitorTransform panel_orientation_transform;
111   gboolean hotplug_mode;
112   int suggested_x;
113   int suggested_y;
114 } MonitorTestCaseOutput;
115 
116 typedef struct _MonitorTestCaseCrtc
117 {
118   int current_mode;
119 } MonitorTestCaseCrtc;
120 
121 typedef struct _MonitorTestCaseSetup
122 {
123   MonitorTestCaseMode modes[MAX_N_MODES];
124   int n_modes;
125 
126   MonitorTestCaseOutput outputs[MAX_N_OUTPUTS];
127   int n_outputs;
128 
129   MonitorTestCaseCrtc crtcs[MAX_N_CRTCS];
130   int n_crtcs;
131 } MonitorTestCaseSetup;
132 
133 typedef struct _MonitorTestCaseMonitorCrtcMode
134 {
135   uint64_t output;
136   int crtc_mode;
137 } MetaTestCaseMonitorCrtcMode;
138 
139 typedef struct _MonitorTestCaseMonitorMode
140 {
141   int width;
142   int height;
143   float refresh_rate;
144   int n_scales;
145   float scales[MAX_N_SCALES];
146   MetaCrtcModeFlag flags;
147   MetaTestCaseMonitorCrtcMode crtc_modes[MAX_N_CRTCS];
148 } MetaMonitorTestCaseMonitorMode;
149 
150 typedef struct _MonitorTestCaseMonitor
151 {
152   uint64_t outputs[MAX_N_OUTPUTS];
153   int n_outputs;
154   MetaMonitorTestCaseMonitorMode modes[MAX_N_MODES];
155   int n_modes;
156   int current_mode;
157   int width_mm;
158   int height_mm;
159   gboolean is_underscanning;
160 } MonitorTestCaseMonitor;
161 
162 typedef struct _MonitorTestCaseLogicalMonitor
163 {
164   MetaRectangle layout;
165   float scale;
166   int monitors[MAX_N_MONITORS];
167   int n_monitors;
168   MetaMonitorTransform transform;
169 } MonitorTestCaseLogicalMonitor;
170 
171 typedef struct _MonitorTestCaseCrtcExpect
172 {
173   MetaMonitorTransform transform;
174   int current_mode;
175   float x;
176   float y;
177 } MonitorTestCaseCrtcExpect;
178 
179 typedef struct _MonitorTestCaseExpect
180 {
181   MonitorTestCaseMonitor monitors[MAX_N_MONITORS];
182   int n_monitors;
183   MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS];
184   int n_logical_monitors;
185   int primary_logical_monitor;
186   int n_outputs;
187   MonitorTestCaseCrtcExpect crtcs[MAX_N_CRTCS];
188   int n_crtcs;
189   int n_tiled_monitors;
190   int screen_width;
191   int screen_height;
192 } MonitorTestCaseExpect;
193 
194 struct _MonitorTestCase
195 {
196   MonitorTestCaseSetup setup;
197   MonitorTestCaseExpect expect;
198 };
199 
200 MetaGpu * test_get_gpu (void);
201 
202 void set_custom_monitor_config (const char *filename);
203 
204 char * read_file (const char *file_path);
205 
206 void check_monitor_configuration (MonitorTestCaseExpect *expect);
207 void check_monitor_scales (MonitorTestCaseExpect       *expect,
208                            MetaMonitorScalesConstraint  scales_constraints);
209 
210 MetaMonitorTestSetup * create_monitor_test_setup (MonitorTestCaseSetup *setup,
211                                                   MonitorTestFlag       flags);
212 
213 #endif /* MONITOR_TEST_UTILS_H */
214