1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
/**************************************************************************
* Copyright © 2016 VMware, Inc., Palo Alto, CA., USA
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_LIBUDEV
#include "vmwgfx_driver.h"
#include <xf86Crtc.h>
#include "vmwgfx_rr_inlines.h"
/**
* struct vmwgfx_layout_box - Struct representing a GUI layout rect
*
* @x: X value of the origin.
* @y: Y value of the origin.
* @width: Width of the rect.
* @height: Height of the rect.
*/
struct vmwgfx_layout_box {
int x, y, width, height;
};
/**
* struct vmwgfx_layout - Struct representing a complete GUI layout
*
* @connected: Number of connected outputs.
* @root_width: Width of full desktop.
* @root_height: Height of full desktop.
* @boxes: Array of GUI layout rects.
*/
struct vmwgfx_layout {
int connected;
int root_width;
int root_height;
struct vmwgfx_layout_box boxes[];
};
/**
* vmwgfx_layout_debug - Log debug info of a layout struct.
*
* @pScrn: ScrnInfoPtr: Pointer to the ScrnInfo struct for the screen the
* layout should be logged for.
* @l1: Pointer to a valid struct vmwgfx_layout.
*/
static void
vmwgfx_layout_debug(ScrnInfoPtr pScrn, const struct vmwgfx_layout *l1)
{
int i;
xf86DrvMsg(pScrn->scrnIndex, X_DEBUG, "New layout.\n");
for (i = 0; i < l1->connected; ++i)
xf86DrvMsg(pScrn->scrnIndex, X_DEBUG,
"%d: %d %d %d %d\n", i, l1->boxes[i].x,
l1->boxes[i].y, l1->boxes[i].width, l1->boxes[i].height);
xf86DrvMsg(pScrn->scrnIndex, X_DEBUG, "\n");
}
/**
* vmwgfx_layouts_equal - Determine whether two layouts are equal.
*
* @l1: Pointer to the first struct vmwgfx_layout.
* @l2: Pointer to the second struct vmwgfx_layout.
*
* Returns: TRUE if the layouts are equal. FALSE otherwise.
*/
static Bool
vmwgfx_layouts_equal(const struct vmwgfx_layout *l1,
const struct vmwgfx_layout *l2)
{
if (l1->connected != l2->connected)
return FALSE;
if (!l1->connected)
return TRUE;
return !memcmp(l1->boxes, l2->boxes,
l1->connected*sizeof(struct vmwgfx_layout_box));
}
/**
* vmwgfx_layout_from_kms - Construct a struct vmwgfx_layout from KMS info.
*
* @pScrn: Pointer to a ScrnInfo struct.
*
* Returns: A pointer to a newly allocated struct vmwgfx_layout if
* successful. NULL otherwise.
*/
struct vmwgfx_layout *
vmwgfx_layout_from_kms(ScrnInfoPtr pScrn)
{
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
int i, connected;
struct vmwgfx_layout *layout;
size_t size;
int min_x = INT_MAX, max_x = INT_MIN, min_y = INT_MAX, max_y = INT_MIN;
for (i = 0; i < config->num_output; ++i) {
xf86OutputPtr output = config->output[i];
if (!vmwgfx_output_has_origin(output))
return NULL;
if (output->status != XF86OutputStatusConnected)
break;
}
connected = i;
size = offsetof(struct vmwgfx_layout, boxes) +
connected * sizeof(struct vmwgfx_layout_box);
layout = calloc(1, size);
if (!layout)
return NULL;
layout->connected = connected;
for (i = 0; i < connected; ++i) {
struct vmwgfx_layout_box *box = &layout->boxes[i];
xf86OutputPtr output = config->output[i];
DisplayModePtr mode = output->probed_modes;
if (mode == NULL) {
free(layout);
return NULL;
}
vmwgfx_output_origin(output, &box->x, &box->y);
box->width = output->probed_modes->HDisplay;
box->height = output->probed_modes->VDisplay;
min_x = min(min_x, box->x);
min_y = min(min_y, box->y);
max_x = max(max_x, box->x + box->width);
max_y = max(max_y, box->y + box->height);
}
layout->root_width = max_x;
layout->root_height = max_y;
return layout;
}
/**
* vmwgfx_layout_configuration - Set up the screen modesetting configuration
* from a struct vmwgfx_layout.
*
* @pScrn: Pointer to a ScrnInfo struct.
* @layout: Layout to use for the new configuration.
*
* Sets up a new modesetting configuration. Note that the configuration needs
* to be committed using xf86SetDesiredModes().
*/
void
vmwgfx_layout_configuration(ScrnInfoPtr pScrn, struct vmwgfx_layout *layout)
{
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
struct vmwgfx_layout_box *box;
xf86OutputPtr output;
xf86CrtcPtr crtc;
int i, j;
for (j = 0; j < config->num_crtc; ++j) {
crtc = config->crtc[j];
crtc->enabled = FALSE;
}
for (i = 0, box = layout->boxes; i < config->num_output; ++i, ++box) {
output = config->output[i];
output->crtc = NULL;
if (i >= layout->connected)
continue;
for (j = 0; j < config->num_crtc; ++j) {
crtc = config->crtc[j];
if (!crtc->enabled && (output->possible_crtcs & (1 << j))) {
crtc->enabled = TRUE;
output->crtc = crtc;
break;
}
}
if (!output->crtc)
continue;
crtc = output->crtc;
xf86SaveModeContents(&crtc->desiredMode, output->probed_modes);
crtc->desiredRotation = RR_Rotate_0;
crtc->desiredX = box->x;
crtc->desiredY = box->y;
crtc->desiredTransformPresent = FALSE;
}
}
/**
* vmwgfx_layout_handler - Obtain and set a new layout.
*
* @pScrn: Pointer to a ScrnInfo struct.
*
* Obtains a new layout from DRM. If the layout differs from the current one,
* Try to set the new layout. If that fails, (typically due to root pixmap
* resizing issues) try hard to revert to the old layout. Finally
* update RandR in a way that tries to block racing display managers
* from setting up the layout in a different way.
*/
void
vmwgfx_layout_handler(ScrnInfoPtr pScrn)
{
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
modesettingPtr ms = modesettingPTR(pScrn);
struct vmwgfx_layout *layout;
if (!pScreen)
return;
/*
* Construct a layout from the new information and determine whether we
* need to take action
*/
layout = vmwgfx_layout_from_kms(pScrn);
if (layout && (!ms->layout || !vmwgfx_layouts_equal(ms->layout, layout))) {
vmwgfx_layout_debug(pScrn, layout);
vmwgfx_outputs_off(pScrn);
xf86DisableUnusedFunctions(pScrn);
if (!vmwgfx_rr_screen_set_size(pScreen, layout->root_width,
layout->root_height)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Resizing screen failed.\n");
vmwgfx_outputs_on(pScrn);
free(layout);
} else {
vmwgfx_layout_configuration(pScrn, layout);
if (ms->layout)
free(ms->layout);
ms->layout = layout;
}
xf86SetDesiredModes(pScrn);
vmwgfx_notify_rr(pScreen);
} else if (layout) {
free(layout);
}
}
#endif /* HAVE_LIBUDEV */
|