summaryrefslogtreecommitdiff
path: root/hw/xfree86/xwayland/xwayland-output.c
blob: f48000107e653d8d54b7ace11d9dfc8746a3b4a2 (plain)
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
 * Copyright © 2011 Intel Corporation
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of the
 * copyright holders not be used in advertising or publicity
 * pertaining to distribution of the software without specific,
 * written prior permission.  The copyright holders make no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#ifdef HAVE_XORG_CONFIG_H
#include "xorg-config.h"
#endif

#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <wayland-client.h>

#include <xorg-server.h>
#include <cursorstr.h>
#include <xf86Crtc.h>
#include <mipointrst.h>

#include "xwayland.h"
#include "xwayland-private.h"
#include "xserver-client-protocol.h"

static void
crtc_dpms(xf86CrtcPtr drmmode_crtc, int mode)
{
}

static Bool
crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
		    Rotation rotation, int x, int y)
{
	return TRUE;
}

static void
crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
{
}

static void
crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
{
}

static void
crtc_show_cursor (xf86CrtcPtr crtc)
{
}

static void
crtc_hide_cursor (xf86CrtcPtr crtc)
{
}

static void
crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
{
}

static PixmapPtr
crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
{
	return NULL;
}

static void *
crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
{
	return NULL;
}

static void
crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
{
}

static const xf86CrtcFuncsRec crtc_funcs = {
    .dpms                = crtc_dpms,
    .set_mode_major      = crtc_set_mode_major,
    .set_cursor_colors   = crtc_set_cursor_colors,
    .set_cursor_position = crtc_set_cursor_position,
    .show_cursor         = crtc_show_cursor,
    .hide_cursor         = crtc_hide_cursor,
    .load_cursor_argb    = crtc_load_cursor_argb,
    .shadow_create       = crtc_shadow_create,
    .shadow_allocate     = crtc_shadow_allocate,
    .shadow_destroy      = crtc_shadow_destroy,
    .destroy		 = NULL, /* XXX */
};

static void
output_dpms(xf86OutputPtr output, int mode)
{
	return;
}

static xf86OutputStatus
output_detect(xf86OutputPtr output)
{
	return XF86OutputStatusConnected;
}

static Bool
output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
{
	return MODE_OK;
}

static DisplayModePtr
output_get_modes(xf86OutputPtr xf86output)
{
    struct xwl_output *output = xf86output->driver_private;
    struct monitor_ranges *ranges;
    DisplayModePtr modes;

    modes = xf86CVTMode(output->width, output->height, 60, TRUE, FALSE);
    output->xf86monitor.det_mon[0].type = DS_RANGES;
    ranges = &output->xf86monitor.det_mon[0].section.ranges;
    ranges->min_h = modes->HSync - 10;
    ranges->max_h = modes->HSync + 10;
    ranges->min_v = modes->VRefresh - 10;
    ranges->max_v = modes->VRefresh + 10;
    ranges->max_clock = modes->Clock + 100;
    output->xf86monitor.det_mon[1].type = DT;
    output->xf86monitor.det_mon[2].type = DT;
    output->xf86monitor.det_mon[3].type = DT;
    output->xf86monitor.no_sections = 0;

    xf86output->MonInfo = &output->xf86monitor;

    return modes;
}

static void
output_destroy(xf86OutputPtr xf86output)
{
    struct xwl_output *output = xf86output->driver_private;

    free(output);
}

static const xf86OutputFuncsRec output_funcs = {
    .dpms	= output_dpms,
    .detect	= output_detect,
    .mode_valid	= output_mode_valid,
    .get_modes	= output_get_modes,
    .destroy	= output_destroy
};

struct xwl_output *
xwl_output_create(struct xwl_screen *xwl_screen)
{
    struct xwl_output *xwl_output;
    xf86OutputPtr xf86output;
    xf86CrtcPtr xf86crtc;

    xwl_output = calloc(sizeof *xwl_output, 1);
    if (xwl_output == NULL) {
	ErrorF("create_output ENOMEM");
	return NULL;
    }

    xwl_output->xwl_screen = xwl_screen;

    xf86output = xf86OutputCreate(xwl_screen->scrninfo,
				  &output_funcs, "XWAYLAND-1");
    xf86output->driver_private = xwl_output;
    xf86output->possible_crtcs = 1;
    xf86output->possible_clones = 1;

    xf86crtc = xf86CrtcCreate(xwl_screen->scrninfo, &crtc_funcs);
    xf86crtc->driver_private = xwl_output;

    xwl_output->xf86output = xf86output;
    xwl_output->xf86crtc = xf86crtc;

    return xwl_output;
}

static Bool
resize(ScrnInfoPtr scrn, int width, int height)
{
    if (scrn->virtualX == width && scrn->virtualY == height)
	return TRUE;
    /* We don't handle resize at all, we must match the compositor size */
    return FALSE;
}

static const xf86CrtcConfigFuncsRec config_funcs = {
    resize
};

static void
display_handle_geometry(void *data,
			struct wl_output *wl_output,
			int x, int y,
			int physical_width,
			int physical_height,
			int subpixel,
			const char *make,
			const char *model)
{
    struct xwl_output *xwl_output = data;
    struct xwl_screen *xwl_screen = xwl_output->xwl_screen;

    xwl_output->xf86output->mm_width = physical_width;
    xwl_output->xf86output->mm_height = physical_height;

    switch (subpixel) {
    case WL_OUTPUT_SUBPIXEL_UNKNOWN:
	xwl_output->xf86output->subpixel_order = SubPixelUnknown;
	break;
    case WL_OUTPUT_SUBPIXEL_NONE:
	xwl_output->xf86output->subpixel_order = SubPixelNone;
	break;
    case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
	xwl_output->xf86output->subpixel_order = SubPixelHorizontalRGB;
	break;
    case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
	xwl_output->xf86output->subpixel_order = SubPixelHorizontalBGR;
	break;
    case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
	xwl_output->xf86output->subpixel_order = SubPixelVerticalRGB;
	break;
    case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
	xwl_output->xf86output->subpixel_order = SubPixelVerticalBGR;
	break;
    }

    xwl_output->x = x;
    xwl_output->y = y;

    xwl_screen->xwl_output = xwl_output;
}

static void
display_handle_mode(void *data,
		    struct wl_output *wl_output,
		    uint32_t flags,
		    int width,
		    int height,
		    int refresh)
{
    struct xwl_output *xwl_output = data;

    xwl_output->width = width;
    xwl_output->height = height;

    xwl_output->xwl_screen->width = width;
    xwl_output->xwl_screen->height = height;
}

static const struct wl_output_listener output_listener = {
    display_handle_geometry,
    display_handle_mode
};

static void
global_handler(struct wl_display *display,
	       uint32_t id,
	       const char *interface,
	       uint32_t version,
	       void *data)
{
    struct xwl_screen *xwl_screen = data;
    struct xwl_output *xwl_output;

    if (strcmp (interface, "wl_output") == 0) {
	xwl_output = xwl_output_create(xwl_screen);

	xwl_output->output = wl_display_bind(xwl_screen->display,
					     id, &wl_output_interface);
	wl_output_add_listener(xwl_output->output,
			       &output_listener, xwl_output);
    }
}

void
xwayland_screen_preinit_output(struct xwl_screen *xwl_screen, ScrnInfoPtr scrninfo)
{
    xf86CrtcConfigInit(scrninfo, &config_funcs);

    xf86CrtcSetSizeRange(scrninfo, 320, 200, 8192, 8192);

    xwl_screen->global_listener =
	wl_display_add_global_listener(xwl_screen->display,
				       global_handler, xwl_screen);

    wl_display_flush(xwl_screen->display);
    while (xwl_screen->xwl_output == NULL)
	wl_display_iterate(xwl_screen->display, WL_DISPLAY_READABLE);
    
    xf86InitialConfiguration(scrninfo, TRUE);
}