| File: | hw/kdrive/ephyr/hostx.c |
| Location: | line 935, column 27 |
| Description: | Access to field 'stride' results in a dereference of a null pointer (loaded from field 'ximg') |
| 1 | /* | |||
| 2 | * Xephyr - A kdrive X server thats runs in a host X window. | |||
| 3 | * Authored by Matthew Allum <mallum@o-hand.com> | |||
| 4 | * | |||
| 5 | * Copyright © 2004 Nokia | |||
| 6 | * | |||
| 7 | * Permission to use, copy, modify, distribute, and sell this software and its | |||
| 8 | * documentation for any purpose is hereby granted without fee, provided that | |||
| 9 | * the above copyright notice appear in all copies and that both that | |||
| 10 | * copyright notice and this permission notice appear in supporting | |||
| 11 | * documentation, and that the name of Nokia not be used in | |||
| 12 | * advertising or publicity pertaining to distribution of the software without | |||
| 13 | * specific, written prior permission. Nokia makes no | |||
| 14 | * representations about the suitability of this software for any purpose. It | |||
| 15 | * is provided "as is" without express or implied warranty. | |||
| 16 | * | |||
| 17 | * NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |||
| 18 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |||
| 19 | * EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |||
| 20 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | |||
| 21 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | |||
| 22 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |||
| 23 | * PERFORMANCE OF THIS SOFTWARE. | |||
| 24 | */ | |||
| 25 | ||||
| 26 | #ifdef HAVE_CONFIG_H1 | |||
| 27 | #include <kdrive-config.h> | |||
| 28 | #endif | |||
| 29 | ||||
| 30 | #include "hostx.h" | |||
| 31 | #include "input.h" | |||
| 32 | ||||
| 33 | #include <stdlib.h> | |||
| 34 | #include <stdio.h> | |||
| 35 | #include <unistd.h> | |||
| 36 | #include <string.h> /* for memset */ | |||
| 37 | #include <errno(*__error()).h> | |||
| 38 | #include <time.h> | |||
| 39 | #include <err.h> | |||
| 40 | ||||
| 41 | #include <sys/ipc.h> | |||
| 42 | #include <sys/shm.h> | |||
| 43 | #include <sys/time.h> | |||
| 44 | ||||
| 45 | #include <X11/keysym.h> | |||
| 46 | #include <xcb/xcb.h> | |||
| 47 | #include <xcb/xproto.h> | |||
| 48 | #include <xcb/xcb_icccm.h> | |||
| 49 | #include <xcb/xcb_aux.h> | |||
| 50 | #include <xcb/shm.h> | |||
| 51 | #include <xcb/xcb_image.h> | |||
| 52 | #include <xcb/shape.h> | |||
| 53 | #include <xcb/xcb_keysyms.h> | |||
| 54 | #include <xcb/randr.h> | |||
| 55 | #ifdef XF86DRI | |||
| 56 | #include <xcb/xf86dri.h> | |||
| 57 | #include <xcb/glx.h> | |||
| 58 | #endif /* XF86DRI */ | |||
| 59 | #ifdef GLAMOR | |||
| 60 | #include <epoxy/gl.h> | |||
| 61 | #include "glamor.h" | |||
| 62 | #include "ephyr_glamor_glx.h" | |||
| 63 | #endif | |||
| 64 | #include "ephyrlog.h" | |||
| 65 | #include "ephyr.h" | |||
| 66 | ||||
| 67 | struct EphyrHostXVars { | |||
| 68 | char *server_dpy_name; | |||
| 69 | xcb_connection_t *conn; | |||
| 70 | int screen; | |||
| 71 | xcb_visualtype_t *visual; | |||
| 72 | Window winroot; | |||
| 73 | xcb_gcontext_t gc; | |||
| 74 | xcb_render_pictformat_t argb_format; | |||
| 75 | xcb_cursor_t empty_cursor; | |||
| 76 | int depth; | |||
| 77 | Bool use_sw_cursor; | |||
| 78 | Bool use_fullscreen; | |||
| 79 | Bool have_shm; | |||
| 80 | ||||
| 81 | int n_screens; | |||
| 82 | KdScreenInfo **screens; | |||
| 83 | ||||
| 84 | long damage_debug_msec; | |||
| 85 | }; | |||
| 86 | ||||
| 87 | /* memset ( missing> ) instead of below */ | |||
| 88 | /*static EphyrHostXVars HostX = { "?", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};*/ | |||
| 89 | static EphyrHostXVars HostX; | |||
| 90 | ||||
| 91 | static int HostXWantDamageDebug = 0; | |||
| 92 | ||||
| 93 | extern EphyrKeySyms ephyrKeySyms; | |||
| 94 | ||||
| 95 | extern Bool EphyrWantResize; | |||
| 96 | ||||
| 97 | char *ephyrResName = NULL((void*)0); | |||
| 98 | int ephyrResNameFromCmd = 0; | |||
| 99 | char *ephyrTitle = NULL((void*)0); | |||
| 100 | Bool ephyr_glamor = FALSE0; | |||
| 101 | ||||
| 102 | Bool | |||
| 103 | hostx_has_extension(xcb_extension_t *extension) | |||
| 104 | { | |||
| 105 | const xcb_query_extension_reply_t *rep; | |||
| 106 | ||||
| 107 | rep = xcb_get_extension_data(HostX.conn, extension); | |||
| 108 | ||||
| 109 | return rep && rep->present; | |||
| 110 | } | |||
| 111 | ||||
| 112 | static void | |||
| 113 | hostx_set_fullscreen_hint(void); | |||
| 114 | ||||
| 115 | #define host_depth_matches_server(_vars)(HostX.depth == (_vars)->server_depth) (HostX.depth == (_vars)->server_depth) | |||
| 116 | ||||
| 117 | int | |||
| 118 | hostx_want_screen_geometry(KdScreenInfo *screen, int *width, int *height, int *x, int *y) | |||
| 119 | { | |||
| 120 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 121 | ||||
| 122 | if (scrpriv && (scrpriv->win_pre_existing != None0L || | |||
| 123 | scrpriv->output != NULL((void*)0) || | |||
| 124 | HostX.use_fullscreen == TRUE1)) { | |||
| 125 | *x = scrpriv->win_x; | |||
| 126 | *y = scrpriv->win_y; | |||
| 127 | *width = scrpriv->win_width; | |||
| 128 | *height = scrpriv->win_height; | |||
| 129 | return 1; | |||
| 130 | } | |||
| 131 | ||||
| 132 | return 0; | |||
| 133 | } | |||
| 134 | ||||
| 135 | void | |||
| 136 | hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry, const char *output) | |||
| 137 | { | |||
| 138 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 139 | int index = HostX.n_screens; | |||
| 140 | ||||
| 141 | HostX.n_screens += 1; | |||
| 142 | HostX.screens = reallocarrayxreallocarray(HostX.screens, | |||
| 143 | HostX.n_screens, sizeof(HostX.screens[0])); | |||
| 144 | HostX.screens[index] = screen; | |||
| 145 | ||||
| 146 | scrpriv->screen = screen; | |||
| 147 | scrpriv->win_pre_existing = win_id; | |||
| 148 | scrpriv->win_explicit_position = use_geometry; | |||
| 149 | scrpriv->output = output; | |||
| 150 | } | |||
| 151 | ||||
| 152 | void | |||
| 153 | hostx_set_display_name(char *name) | |||
| 154 | { | |||
| 155 | HostX.server_dpy_name = strdup(name); | |||
| 156 | } | |||
| 157 | ||||
| 158 | void | |||
| 159 | hostx_set_screen_number(KdScreenInfo *screen, int number) | |||
| 160 | { | |||
| 161 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 162 | ||||
| 163 | if (scrpriv) { | |||
| 164 | scrpriv->mynum = number; | |||
| 165 | hostx_set_win_title(screen, ""); | |||
| 166 | } | |||
| 167 | } | |||
| 168 | ||||
| 169 | void | |||
| 170 | hostx_set_win_title(KdScreenInfo *screen, const char *extra_text) | |||
| 171 | { | |||
| 172 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 173 | ||||
| 174 | if (!scrpriv) | |||
| 175 | return; | |||
| 176 | ||||
| 177 | if (ephyrTitle) { | |||
| 178 | xcb_icccm_set_wm_name(HostX.conn, | |||
| 179 | scrpriv->win, | |||
| 180 | XCB_ATOM_STRING, | |||
| 181 | 8, | |||
| 182 | strlen(ephyrTitle), | |||
| 183 | ephyrTitle); | |||
| 184 | } else { | |||
| 185 | #define BUF_LEN256 256 | |||
| 186 | char buf[BUF_LEN256 + 1]; | |||
| 187 | ||||
| 188 | memset(buf, 0, BUF_LEN + 1)__builtin___memset_chk (buf, 0, 256 + 1, __builtin_object_size (buf, 0)); | |||
| 189 | snprintf(buf, BUF_LEN, "Xephyr on %s.%d %s",__builtin___snprintf_chk (buf, 256, 0, __builtin_object_size ( buf, 2 > 1 ? 1 : 0), "Xephyr on %s.%d %s", HostX.server_dpy_name ? HostX.server_dpy_name : ":0", scrpriv->mynum, (extra_text != ((void*)0)) ? extra_text : "") | |||
| 190 | HostX.server_dpy_name ? HostX.server_dpy_name : ":0",__builtin___snprintf_chk (buf, 256, 0, __builtin_object_size ( buf, 2 > 1 ? 1 : 0), "Xephyr on %s.%d %s", HostX.server_dpy_name ? HostX.server_dpy_name : ":0", scrpriv->mynum, (extra_text != ((void*)0)) ? extra_text : "") | |||
| 191 | scrpriv->mynum, (extra_text != NULL) ? extra_text : "")__builtin___snprintf_chk (buf, 256, 0, __builtin_object_size ( buf, 2 > 1 ? 1 : 0), "Xephyr on %s.%d %s", HostX.server_dpy_name ? HostX.server_dpy_name : ":0", scrpriv->mynum, (extra_text != ((void*)0)) ? extra_text : ""); | |||
| 192 | ||||
| 193 | xcb_icccm_set_wm_name(HostX.conn, | |||
| 194 | scrpriv->win, | |||
| 195 | XCB_ATOM_STRING, | |||
| 196 | 8, | |||
| 197 | strlen(buf), | |||
| 198 | buf); | |||
| 199 | xcb_flush(HostX.conn); | |||
| 200 | } | |||
| 201 | } | |||
| 202 | ||||
| 203 | int | |||
| 204 | hostx_want_host_cursor(void) | |||
| 205 | { | |||
| 206 | return !HostX.use_sw_cursor; | |||
| 207 | } | |||
| 208 | ||||
| 209 | void | |||
| 210 | hostx_use_sw_cursor(void) | |||
| 211 | { | |||
| 212 | HostX.use_sw_cursor = TRUE1; | |||
| 213 | } | |||
| 214 | ||||
| 215 | xcb_cursor_t | |||
| 216 | hostx_get_empty_cursor(void) | |||
| 217 | { | |||
| 218 | return HostX.empty_cursor; | |||
| 219 | } | |||
| 220 | ||||
| 221 | int | |||
| 222 | hostx_want_preexisting_window(KdScreenInfo *screen) | |||
| 223 | { | |||
| 224 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 225 | ||||
| 226 | if (scrpriv && scrpriv->win_pre_existing) { | |||
| 227 | return 1; | |||
| 228 | } | |||
| 229 | else { | |||
| 230 | return 0; | |||
| 231 | } | |||
| 232 | } | |||
| 233 | ||||
| 234 | void | |||
| 235 | hostx_get_output_geometry(const char *output, | |||
| 236 | int *x, int *y, | |||
| 237 | int *width, int *height) | |||
| 238 | { | |||
| 239 | int i, name_len = 0, output_found = FALSE0; | |||
| 240 | char *name = NULL((void*)0); | |||
| 241 | xcb_generic_error_t *error; | |||
| 242 | xcb_randr_query_version_cookie_t version_c; | |||
| 243 | xcb_randr_query_version_reply_t *version_r; | |||
| 244 | xcb_randr_get_screen_resources_cookie_t screen_resources_c; | |||
| 245 | xcb_randr_get_screen_resources_reply_t *screen_resources_r; | |||
| 246 | xcb_randr_output_t *randr_outputs; | |||
| 247 | xcb_randr_get_output_info_cookie_t output_info_c; | |||
| 248 | xcb_randr_get_output_info_reply_t *output_info_r; | |||
| 249 | xcb_randr_get_crtc_info_cookie_t crtc_info_c; | |||
| 250 | xcb_randr_get_crtc_info_reply_t *crtc_info_r; | |||
| 251 | ||||
| 252 | /* First of all, check for extension */ | |||
| 253 | if (!hostx_has_extension(&xcb_randr_id)) | |||
| 254 | { | |||
| 255 | fprintf(stderr__stderrp, "\nHost X server does not support RANDR extension (or it's disabled).\n"); | |||
| 256 | exit(1); | |||
| 257 | } | |||
| 258 | ||||
| 259 | /* Check RandR version */ | |||
| 260 | version_c = xcb_randr_query_version(HostX.conn, 1, 2); | |||
| 261 | version_r = xcb_randr_query_version_reply(HostX.conn, | |||
| 262 | version_c, | |||
| 263 | &error); | |||
| 264 | ||||
| 265 | if (error != NULL((void*)0) || version_r == NULL((void*)0)) | |||
| 266 | { | |||
| 267 | fprintf(stderr__stderrp, "\nFailed to get RandR version supported by host X server.\n"); | |||
| 268 | exit(1); | |||
| 269 | } | |||
| 270 | else if (version_r->major_version < 1 || version_r->minor_version < 2) | |||
| 271 | { | |||
| 272 | free(version_r); | |||
| 273 | fprintf(stderr__stderrp, "\nHost X server doesn't support RandR 1.2, needed for -output usage.\n"); | |||
| 274 | exit(1); | |||
| 275 | } | |||
| 276 | ||||
| 277 | free(version_r); | |||
| 278 | ||||
| 279 | /* Get list of outputs from screen resources */ | |||
| 280 | screen_resources_c = xcb_randr_get_screen_resources(HostX.conn, | |||
| 281 | HostX.winroot); | |||
| 282 | screen_resources_r = xcb_randr_get_screen_resources_reply(HostX.conn, | |||
| 283 | screen_resources_c, | |||
| 284 | NULL((void*)0)); | |||
| 285 | randr_outputs = xcb_randr_get_screen_resources_outputs(screen_resources_r); | |||
| 286 | ||||
| 287 | for (i = 0; !output_found && i < screen_resources_r->num_outputs; i++) | |||
| 288 | { | |||
| 289 | /* Get info on the output */ | |||
| 290 | output_info_c = xcb_randr_get_output_info(HostX.conn, | |||
| 291 | randr_outputs[i], | |||
| 292 | XCB_CURRENT_TIME0L); | |||
| 293 | output_info_r = xcb_randr_get_output_info_reply(HostX.conn, | |||
| 294 | output_info_c, | |||
| 295 | NULL((void*)0)); | |||
| 296 | ||||
| 297 | /* Get output name */ | |||
| 298 | name_len = xcb_randr_get_output_info_name_length(output_info_r); | |||
| 299 | name = malloc(name_len + 1); | |||
| 300 | strncpy(name, (char*)xcb_randr_get_output_info_name(output_info_r), name_len)__builtin___strncpy_chk (name, (char*)xcb_randr_get_output_info_name (output_info_r), name_len, __builtin_object_size (name, 2 > 1 ? 1 : 0)); | |||
| 301 | name[name_len] = '\0'; | |||
| 302 | ||||
| 303 | if (!strcmp(name, output)) | |||
| 304 | { | |||
| 305 | output_found = TRUE1; | |||
| 306 | ||||
| 307 | /* Check if output is connected */ | |||
| 308 | if (output_info_r->crtc == XCB_NONE0L) | |||
| 309 | { | |||
| 310 | free(name); | |||
| 311 | free(output_info_r); | |||
| 312 | free(screen_resources_r); | |||
| 313 | fprintf(stderr__stderrp, "\nOutput %s is currently disabled (or not connected).\n", output); | |||
| 314 | exit(1); | |||
| 315 | } | |||
| 316 | ||||
| 317 | /* Get CRTC from output info */ | |||
| 318 | crtc_info_c = xcb_randr_get_crtc_info(HostX.conn, | |||
| 319 | output_info_r->crtc, | |||
| 320 | XCB_CURRENT_TIME0L); | |||
| 321 | crtc_info_r = xcb_randr_get_crtc_info_reply(HostX.conn, | |||
| 322 | crtc_info_c, | |||
| 323 | NULL((void*)0)); | |||
| 324 | ||||
| 325 | /* Get CRTC geometry */ | |||
| 326 | *x = crtc_info_r->x; | |||
| 327 | *y = crtc_info_r->y; | |||
| 328 | *width = crtc_info_r->width; | |||
| 329 | *height = crtc_info_r->height; | |||
| 330 | ||||
| 331 | free(crtc_info_r); | |||
| 332 | } | |||
| 333 | ||||
| 334 | free(name); | |||
| 335 | free(output_info_r); | |||
| 336 | } | |||
| 337 | ||||
| 338 | free(screen_resources_r); | |||
| 339 | ||||
| 340 | if (!output_found) | |||
| 341 | { | |||
| 342 | fprintf(stderr__stderrp, "\nOutput %s not available in host X server.\n", output); | |||
| 343 | exit(1); | |||
| 344 | } | |||
| 345 | } | |||
| 346 | ||||
| 347 | void | |||
| 348 | hostx_use_fullscreen(void) | |||
| 349 | { | |||
| 350 | HostX.use_fullscreen = TRUE1; | |||
| 351 | } | |||
| 352 | ||||
| 353 | int | |||
| 354 | hostx_want_fullscreen(void) | |||
| 355 | { | |||
| 356 | return HostX.use_fullscreen; | |||
| 357 | } | |||
| 358 | ||||
| 359 | static xcb_intern_atom_cookie_t cookie_WINDOW_STATE, | |||
| 360 | cookie_WINDOW_STATE_FULLSCREEN; | |||
| 361 | ||||
| 362 | static void | |||
| 363 | hostx_set_fullscreen_hint(void) | |||
| 364 | { | |||
| 365 | xcb_atom_t atom_WINDOW_STATE, atom_WINDOW_STATE_FULLSCREEN; | |||
| 366 | int index; | |||
| 367 | xcb_intern_atom_reply_t *reply; | |||
| 368 | ||||
| 369 | reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE, NULL((void*)0)); | |||
| 370 | atom_WINDOW_STATE = reply->atom; | |||
| 371 | free(reply); | |||
| 372 | ||||
| 373 | reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE_FULLSCREEN, | |||
| 374 | NULL((void*)0)); | |||
| 375 | atom_WINDOW_STATE_FULLSCREEN = reply->atom; | |||
| 376 | free(reply); | |||
| 377 | ||||
| 378 | for (index = 0; index < HostX.n_screens; index++) { | |||
| 379 | EphyrScrPriv *scrpriv = HostX.screens[index]->driver; | |||
| 380 | xcb_change_property(HostX.conn, | |||
| 381 | PropModeReplace0, | |||
| 382 | scrpriv->win, | |||
| 383 | atom_WINDOW_STATE, | |||
| 384 | XCB_ATOM_ATOM, | |||
| 385 | 32, | |||
| 386 | 1, | |||
| 387 | &atom_WINDOW_STATE_FULLSCREEN); | |||
| 388 | } | |||
| 389 | } | |||
| 390 | ||||
| 391 | static void | |||
| 392 | hostx_toggle_damage_debug(void) | |||
| 393 | { | |||
| 394 | HostXWantDamageDebug ^= 1; | |||
| 395 | } | |||
| 396 | ||||
| 397 | void | |||
| 398 | hostx_handle_signal(int signum) | |||
| 399 | { | |||
| 400 | hostx_toggle_damage_debug(); | |||
| 401 | EPHYR_DBG("Signal caught. Damage Debug:%i\n", HostXWantDamageDebug)do {} while (0); | |||
| 402 | } | |||
| 403 | ||||
| 404 | void | |||
| 405 | hostx_use_resname(char *name, int fromcmd) | |||
| 406 | { | |||
| 407 | ephyrResName = name; | |||
| 408 | ephyrResNameFromCmd = fromcmd; | |||
| 409 | } | |||
| 410 | ||||
| 411 | void | |||
| 412 | hostx_set_title(char *title) | |||
| 413 | { | |||
| 414 | ephyrTitle = title; | |||
| 415 | } | |||
| 416 | ||||
| 417 | #ifdef __SUNPRO_C | |||
| 418 | /* prevent "Function has no return statement" error for x_io_error_handler */ | |||
| 419 | #pragma does_not_return(exit) | |||
| 420 | #endif | |||
| 421 | ||||
| 422 | int | |||
| 423 | hostx_init(void) | |||
| 424 | { | |||
| 425 | uint32_t attrs[2]; | |||
| 426 | uint32_t attr_mask = 0; | |||
| 427 | xcb_pixmap_t cursor_pxm; | |||
| 428 | xcb_gcontext_t cursor_gc; | |||
| 429 | uint16_t red, green, blue; | |||
| 430 | uint32_t pixel; | |||
| 431 | int index; | |||
| 432 | char *tmpstr; | |||
| 433 | char *class_hint; | |||
| 434 | size_t class_len; | |||
| 435 | xcb_screen_t *xscreen; | |||
| 436 | xcb_rectangle_t rect = { 0, 0, 1, 1 }; | |||
| 437 | ||||
| 438 | attrs[0] = | |||
| 439 | XCB_EVENT_MASK_BUTTON_PRESS | |||
| 440 | | XCB_EVENT_MASK_BUTTON_RELEASE | |||
| 441 | | XCB_EVENT_MASK_POINTER_MOTION | |||
| 442 | | XCB_EVENT_MASK_KEY_PRESS | |||
| 443 | | XCB_EVENT_MASK_KEY_RELEASE | |||
| 444 | | XCB_EVENT_MASK_EXPOSURE | |||
| 445 | | XCB_EVENT_MASK_STRUCTURE_NOTIFY; | |||
| 446 | attr_mask |= XCB_CW_EVENT_MASK; | |||
| 447 | ||||
| 448 | EPHYR_DBG("mark")do {} while (0); | |||
| 449 | #ifdef GLAMOR | |||
| 450 | if (ephyr_glamor) | |||
| 451 | HostX.conn = ephyr_glamor_connect(); | |||
| 452 | else | |||
| 453 | #endif | |||
| 454 | HostX.conn = xcb_connect(NULL((void*)0), &HostX.screen); | |||
| 455 | if (!HostX.conn || xcb_connection_has_error(HostX.conn)) { | |||
| 456 | fprintf(stderr__stderrp, "\nXephyr cannot open host display. Is DISPLAY set?\n"); | |||
| 457 | exit(1); | |||
| 458 | } | |||
| 459 | ||||
| 460 | xscreen = xcb_aux_get_screen(HostX.conn, HostX.screen); | |||
| 461 | HostX.winroot = xscreen->root; | |||
| 462 | HostX.gc = xcb_generate_id(HostX.conn); | |||
| 463 | HostX.depth = xscreen->root_depth; | |||
| 464 | #ifdef GLAMOR | |||
| 465 | if (ephyr_glamor) { | |||
| 466 | HostX.visual = ephyr_glamor_get_visual(); | |||
| 467 | if (HostX.visual->visual_id != xscreen->root_visual) { | |||
| 468 | attrs[1] = xcb_generate_id(HostX.conn); | |||
| 469 | attr_mask |= XCB_CW_COLORMAP; | |||
| 470 | xcb_create_colormap(HostX.conn, | |||
| 471 | XCB_COLORMAP_ALLOC_NONE, | |||
| 472 | attrs[1], | |||
| 473 | HostX.winroot, | |||
| 474 | HostX.visual->visual_id); | |||
| 475 | } | |||
| 476 | } else | |||
| 477 | #endif | |||
| 478 | HostX.visual = xcb_aux_find_visual_by_id(xscreen,xscreen->root_visual); | |||
| 479 | ||||
| 480 | xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL((void*)0)); | |||
| 481 | cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, FALSE0, | |||
| 482 | strlen("_NET_WM_STATE"), | |||
| 483 | "_NET_WM_STATE"); | |||
| 484 | cookie_WINDOW_STATE_FULLSCREEN = | |||
| 485 | xcb_intern_atom(HostX.conn, FALSE0, | |||
| 486 | strlen("_NET_WM_STATE_FULLSCREEN"), | |||
| 487 | "_NET_WM_STATE_FULLSCREEN"); | |||
| 488 | ||||
| 489 | for (index = 0; index < HostX.n_screens; index++) { | |||
| 490 | KdScreenInfo *screen = HostX.screens[index]; | |||
| 491 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 492 | ||||
| 493 | scrpriv->win = xcb_generate_id(HostX.conn); | |||
| 494 | scrpriv->server_depth = HostX.depth; | |||
| 495 | scrpriv->ximg = NULL((void*)0); | |||
| 496 | scrpriv->win_x = 0; | |||
| 497 | scrpriv->win_y = 0; | |||
| 498 | ||||
| 499 | if (scrpriv->win_pre_existing != XCB_WINDOW_NONE) { | |||
| 500 | xcb_get_geometry_reply_t *prewin_geom; | |||
| 501 | xcb_get_geometry_cookie_t cookie; | |||
| 502 | xcb_generic_error_t *e = NULL((void*)0); | |||
| 503 | ||||
| 504 | /* Get screen size from existing window */ | |||
| 505 | cookie = xcb_get_geometry(HostX.conn, | |||
| 506 | scrpriv->win_pre_existing); | |||
| 507 | prewin_geom = xcb_get_geometry_reply(HostX.conn, cookie, &e); | |||
| 508 | ||||
| 509 | if (e) { | |||
| 510 | free(e); | |||
| 511 | free(prewin_geom); | |||
| 512 | fprintf (stderr__stderrp, "\nXephyr -parent window' does not exist!\n"); | |||
| 513 | exit (1); | |||
| 514 | } | |||
| 515 | ||||
| 516 | scrpriv->win_width = prewin_geom->width; | |||
| 517 | scrpriv->win_height = prewin_geom->height; | |||
| 518 | ||||
| 519 | free(prewin_geom); | |||
| 520 | ||||
| 521 | xcb_create_window(HostX.conn, | |||
| 522 | XCB_COPY_FROM_PARENT0L, | |||
| 523 | scrpriv->win, | |||
| 524 | scrpriv->win_pre_existing, | |||
| 525 | 0,0, | |||
| 526 | scrpriv->win_width, | |||
| 527 | scrpriv->win_height, | |||
| 528 | 0, | |||
| 529 | XCB_WINDOW_CLASS_COPY_FROM_PARENT, | |||
| 530 | HostX.visual->visual_id, | |||
| 531 | attr_mask, | |||
| 532 | attrs); | |||
| 533 | } | |||
| 534 | else { | |||
| 535 | xcb_create_window(HostX.conn, | |||
| 536 | XCB_COPY_FROM_PARENT0L, | |||
| 537 | scrpriv->win, | |||
| 538 | HostX.winroot, | |||
| 539 | 0,0,100,100, /* will resize */ | |||
| 540 | 0, | |||
| 541 | XCB_WINDOW_CLASS_COPY_FROM_PARENT, | |||
| 542 | HostX.visual->visual_id, | |||
| 543 | attr_mask, | |||
| 544 | attrs); | |||
| 545 | ||||
| 546 | hostx_set_win_title(screen, | |||
| 547 | "(ctrl+shift grabs mouse and keyboard)"); | |||
| 548 | ||||
| 549 | if (HostX.use_fullscreen) { | |||
| 550 | scrpriv->win_width = xscreen->width_in_pixels; | |||
| 551 | scrpriv->win_height = xscreen->height_in_pixels; | |||
| 552 | ||||
| 553 | hostx_set_fullscreen_hint(); | |||
| 554 | } | |||
| 555 | else if (scrpriv->output) { | |||
| 556 | hostx_get_output_geometry(scrpriv->output, | |||
| 557 | &scrpriv->win_x, | |||
| 558 | &scrpriv->win_y, | |||
| 559 | &scrpriv->win_width, | |||
| 560 | &scrpriv->win_height); | |||
| 561 | ||||
| 562 | HostX.use_fullscreen = TRUE1; | |||
| 563 | hostx_set_fullscreen_hint(); | |||
| 564 | } | |||
| 565 | ||||
| 566 | ||||
| 567 | tmpstr = getenv("RESOURCE_NAME"); | |||
| 568 | if (tmpstr && (!ephyrResNameFromCmd)) | |||
| 569 | ephyrResName = tmpstr; | |||
| 570 | class_len = strlen(ephyrResName) + 1 + strlen("Xephyr") + 1; | |||
| 571 | class_hint = malloc(class_len); | |||
| 572 | if (class_hint) { | |||
| 573 | strcpy(class_hint, ephyrResName)__builtin___strcpy_chk (class_hint, ephyrResName, __builtin_object_size (class_hint, 2 > 1 ? 1 : 0)); | |||
| 574 | strcpy(class_hint + strlen(ephyrResName) + 1, "Xephyr")__builtin___strcpy_chk (class_hint + strlen(ephyrResName) + 1 , "Xephyr", __builtin_object_size (class_hint + strlen(ephyrResName ) + 1, 2 > 1 ? 1 : 0)); | |||
| 575 | xcb_change_property(HostX.conn, | |||
| 576 | XCB_PROP_MODE_REPLACE, | |||
| 577 | scrpriv->win, | |||
| 578 | XCB_ATOM_WM_CLASS, | |||
| 579 | XCB_ATOM_STRING, | |||
| 580 | 8, | |||
| 581 | class_len, | |||
| 582 | class_hint); | |||
| 583 | free(class_hint); | |||
| 584 | } | |||
| 585 | } | |||
| 586 | } | |||
| 587 | ||||
| 588 | if (!xcb_aux_parse_color("red", &red, &green, &blue)) { | |||
| 589 | xcb_lookup_color_cookie_t c = | |||
| 590 | xcb_lookup_color(HostX.conn, xscreen->default_colormap, 3, "red"); | |||
| 591 | xcb_lookup_color_reply_t *reply = | |||
| 592 | xcb_lookup_color_reply(HostX.conn, c, NULL((void*)0)); | |||
| 593 | red = reply->exact_red; | |||
| 594 | green = reply->exact_green; | |||
| 595 | blue = reply->exact_blue; | |||
| 596 | free(reply); | |||
| 597 | } | |||
| 598 | ||||
| 599 | { | |||
| 600 | xcb_alloc_color_cookie_t c = xcb_alloc_color(HostX.conn, | |||
| 601 | xscreen->default_colormap, | |||
| 602 | red, green, blue); | |||
| 603 | xcb_alloc_color_reply_t *r = xcb_alloc_color_reply(HostX.conn, c, NULL((void*)0)); | |||
| 604 | red = r->red; | |||
| 605 | green = r->green; | |||
| 606 | blue = r->blue; | |||
| 607 | pixel = r->pixel; | |||
| 608 | free(r); | |||
| 609 | } | |||
| 610 | ||||
| 611 | xcb_change_gc(HostX.conn, HostX.gc, XCB_GC_FOREGROUND, &pixel); | |||
| 612 | ||||
| 613 | cursor_pxm = xcb_generate_id(HostX.conn); | |||
| 614 | xcb_create_pixmap(HostX.conn, 1, cursor_pxm, HostX.winroot, 1, 1); | |||
| 615 | cursor_gc = xcb_generate_id(HostX.conn); | |||
| 616 | pixel = 0; | |||
| 617 | xcb_create_gc(HostX.conn, cursor_gc, cursor_pxm, | |||
| 618 | XCB_GC_FOREGROUND, &pixel); | |||
| 619 | xcb_poly_fill_rectangle(HostX.conn, cursor_pxm, cursor_gc, 1, &rect); | |||
| 620 | xcb_free_gc(HostX.conn, cursor_gc); | |||
| 621 | HostX.empty_cursor = xcb_generate_id(HostX.conn); | |||
| 622 | xcb_create_cursor(HostX.conn, | |||
| 623 | HostX.empty_cursor, | |||
| 624 | cursor_pxm, cursor_pxm, | |||
| 625 | 0,0,0, | |||
| 626 | 0,0,0, | |||
| 627 | 1,1); | |||
| 628 | xcb_free_pixmap(HostX.conn, cursor_pxm); | |||
| 629 | if (!hostx_want_host_cursor ()) { | |||
| 630 | CursorVisible = TRUE1; | |||
| 631 | /* Ditch the cursor, we provide our 'own' */ | |||
| 632 | for (index = 0; index < HostX.n_screens; index++) { | |||
| 633 | KdScreenInfo *screen = HostX.screens[index]; | |||
| 634 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 635 | ||||
| 636 | xcb_change_window_attributes(HostX.conn, | |||
| 637 | scrpriv->win, | |||
| 638 | XCB_CW_CURSOR, | |||
| 639 | &HostX.empty_cursor); | |||
| 640 | } | |||
| 641 | } | |||
| 642 | ||||
| 643 | /* Try to get share memory ximages for a little bit more speed */ | |||
| 644 | if (!hostx_has_extension(&xcb_shm_id) || getenv("XEPHYR_NO_SHM")) { | |||
| 645 | fprintf(stderr__stderrp, "\nXephyr unable to use SHM XImages\n"); | |||
| 646 | HostX.have_shm = FALSE0; | |||
| 647 | } | |||
| 648 | else { | |||
| 649 | /* Really really check we have shm - better way ?*/ | |||
| 650 | xcb_shm_segment_info_t shminfo; | |||
| 651 | xcb_generic_error_t *e; | |||
| 652 | xcb_void_cookie_t cookie; | |||
| 653 | xcb_shm_seg_t shmseg; | |||
| 654 | ||||
| 655 | HostX.have_shm = TRUE1; | |||
| 656 | ||||
| 657 | shminfo.shmid = shmget(IPC_PRIVATE((key_t)0), 1, IPC_CREAT001000|0777); | |||
| 658 | shminfo.shmaddr = shmat(shminfo.shmid,0,0); | |||
| 659 | ||||
| 660 | shmseg = xcb_generate_id(HostX.conn); | |||
| 661 | cookie = xcb_shm_attach_checked(HostX.conn, shmseg, shminfo.shmid, | |||
| 662 | TRUE1); | |||
| 663 | e = xcb_request_check(HostX.conn, cookie); | |||
| 664 | ||||
| 665 | if (e) { | |||
| 666 | fprintf(stderr__stderrp, "\nXephyr unable to use SHM XImages\n"); | |||
| 667 | HostX.have_shm = FALSE0; | |||
| 668 | free(e); | |||
| 669 | } | |||
| 670 | ||||
| 671 | shmdt(shminfo.shmaddr); | |||
| 672 | shmctl(shminfo.shmid, IPC_RMID0, 0); | |||
| 673 | } | |||
| 674 | ||||
| 675 | xcb_flush(HostX.conn); | |||
| 676 | ||||
| 677 | /* Setup the pause time between paints when debugging updates */ | |||
| 678 | ||||
| 679 | HostX.damage_debug_msec = 20000; /* 1/50 th of a second */ | |||
| 680 | ||||
| 681 | if (getenv("XEPHYR_PAUSE")) { | |||
| 682 | HostX.damage_debug_msec = strtol(getenv("XEPHYR_PAUSE"), NULL((void*)0), 0); | |||
| 683 | EPHYR_DBG("pause is %li\n", HostX.damage_debug_msec)do {} while (0); | |||
| 684 | } | |||
| 685 | ||||
| 686 | return 1; | |||
| 687 | } | |||
| 688 | ||||
| 689 | int | |||
| 690 | hostx_get_depth(void) | |||
| 691 | { | |||
| 692 | return HostX.depth; | |||
| 693 | } | |||
| 694 | ||||
| 695 | int | |||
| 696 | hostx_get_server_depth(KdScreenInfo *screen) | |||
| 697 | { | |||
| 698 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 699 | ||||
| 700 | return scrpriv ? scrpriv->server_depth : 0; | |||
| 701 | } | |||
| 702 | ||||
| 703 | int | |||
| 704 | hostx_get_bpp(KdScreenInfo *screen) | |||
| 705 | { | |||
| 706 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 707 | ||||
| 708 | if (!scrpriv) | |||
| 709 | return 0; | |||
| 710 | ||||
| 711 | if (host_depth_matches_server(scrpriv)(HostX.depth == (scrpriv)->server_depth)) | |||
| 712 | return HostX.visual->bits_per_rgb_value; | |||
| 713 | else | |||
| 714 | return scrpriv->server_depth; /*XXX correct ?*/ | |||
| 715 | } | |||
| 716 | ||||
| 717 | void | |||
| 718 | hostx_get_visual_masks(KdScreenInfo *screen, | |||
| 719 | CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk) | |||
| 720 | { | |||
| 721 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 722 | ||||
| 723 | if (!scrpriv) | |||
| 724 | return; | |||
| 725 | ||||
| 726 | if (host_depth_matches_server(scrpriv)(HostX.depth == (scrpriv)->server_depth)) { | |||
| 727 | *rmsk = HostX.visual->red_mask; | |||
| 728 | *gmsk = HostX.visual->green_mask; | |||
| 729 | *bmsk = HostX.visual->blue_mask; | |||
| 730 | } | |||
| 731 | else if (scrpriv->server_depth == 16) { | |||
| 732 | /* Assume 16bpp 565 */ | |||
| 733 | *rmsk = 0xf800; | |||
| 734 | *gmsk = 0x07e0; | |||
| 735 | *bmsk = 0x001f; | |||
| 736 | } | |||
| 737 | else { | |||
| 738 | *rmsk = 0x0; | |||
| 739 | *gmsk = 0x0; | |||
| 740 | *bmsk = 0x0; | |||
| 741 | } | |||
| 742 | } | |||
| 743 | ||||
| 744 | static int | |||
| 745 | hostx_calculate_color_shift(unsigned long mask) | |||
| 746 | { | |||
| 747 | int shift = 1; | |||
| 748 | ||||
| 749 | /* count # of bits in mask */ | |||
| 750 | while ((mask = (mask >> 1))) | |||
| 751 | shift++; | |||
| 752 | /* cmap entry is an unsigned char so adjust it by size of that */ | |||
| 753 | shift = shift - sizeof(unsigned char) * 8; | |||
| 754 | if (shift < 0) | |||
| 755 | shift = 0; | |||
| 756 | return shift; | |||
| 757 | } | |||
| 758 | ||||
| 759 | void | |||
| 760 | hostx_set_cmap_entry(ScreenPtr pScreen, unsigned char idx, | |||
| 761 | unsigned char r, unsigned char g, unsigned char b) | |||
| 762 | { | |||
| 763 | KdScreenPriv(pScreen)KdPrivScreenPtr pScreenPriv = ((KdPrivScreenPtr) dixLookupPrivate (&(pScreen)->devPrivates, (&kdScreenPrivateKeyRec) )); | |||
| 764 | KdScreenInfo *screen = pScreenPriv->screen; | |||
| 765 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 766 | /* need to calculate the shifts for RGB because server could be BGR. */ | |||
| 767 | /* XXX Not sure if this is correct for 8 on 16, but this works for 8 on 24.*/ | |||
| 768 | static int rshift, bshift, gshift = 0; | |||
| 769 | static int first_time = 1; | |||
| 770 | ||||
| 771 | if (first_time) { | |||
| 772 | first_time = 0; | |||
| 773 | rshift = hostx_calculate_color_shift(HostX.visual->red_mask); | |||
| 774 | gshift = hostx_calculate_color_shift(HostX.visual->green_mask); | |||
| 775 | bshift = hostx_calculate_color_shift(HostX.visual->blue_mask); | |||
| 776 | } | |||
| 777 | scrpriv->cmap[idx] = ((r << rshift) & HostX.visual->red_mask) | | |||
| 778 | ((g << gshift) & HostX.visual->green_mask) | | |||
| 779 | ((b << bshift) & HostX.visual->blue_mask); | |||
| 780 | } | |||
| 781 | ||||
| 782 | /** | |||
| 783 | * hostx_screen_init creates the XImage that will contain the front buffer of | |||
| 784 | * the ephyr screen, and possibly offscreen memory. | |||
| 785 | * | |||
| 786 | * @param width width of the screen | |||
| 787 | * @param height height of the screen | |||
| 788 | * @param buffer_height height of the rectangle to be allocated. | |||
| 789 | * | |||
| 790 | * hostx_screen_init() creates an XImage, using MIT-SHM if it's available. | |||
| 791 | * buffer_height can be used to create a larger offscreen buffer, which is used | |||
| 792 | * by fakexa for storing offscreen pixmap data. | |||
| 793 | */ | |||
| 794 | void * | |||
| 795 | hostx_screen_init(KdScreenInfo *screen, | |||
| 796 | int x, int y, | |||
| 797 | int width, int height, int buffer_height, | |||
| 798 | int *bytes_per_line, int *bits_per_pixel) | |||
| 799 | { | |||
| 800 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 801 | Bool shm_success = FALSE0; | |||
| 802 | ||||
| 803 | if (!scrpriv) { | |||
| ||||
| 804 | fprintf(stderr__stderrp, "%s: Error in accessing hostx data\n", __func__); | |||
| 805 | exit(1); | |||
| 806 | } | |||
| 807 | ||||
| 808 | EPHYR_DBG("host_screen=%p x=%d, y=%d, wxh=%dx%d, buffer_height=%d",do {} while (0) | |||
| 809 | screen, x, y, width, height, buffer_height)do {} while (0); | |||
| 810 | ||||
| 811 | if (scrpriv->ximg != NULL((void*)0)) { | |||
| 812 | /* Free up the image data if previously used | |||
| 813 | * i.ie called by server reset | |||
| 814 | */ | |||
| 815 | ||||
| 816 | if (HostX.have_shm) { | |||
| 817 | xcb_shm_detach(HostX.conn, scrpriv->shminfo.shmseg); | |||
| 818 | xcb_image_destroy(scrpriv->ximg); | |||
| 819 | shmdt(scrpriv->shminfo.shmaddr); | |||
| 820 | shmctl(scrpriv->shminfo.shmid, IPC_RMID0, 0); | |||
| 821 | } | |||
| 822 | else { | |||
| 823 | free(scrpriv->ximg->data); | |||
| 824 | scrpriv->ximg->data = NULL((void*)0); | |||
| 825 | ||||
| 826 | xcb_image_destroy(scrpriv->ximg); | |||
| 827 | } | |||
| 828 | } | |||
| 829 | ||||
| 830 | if (!ephyr_glamor && HostX.have_shm) { | |||
| 831 | scrpriv->ximg = xcb_image_create_native(HostX.conn, | |||
| 832 | width, | |||
| 833 | buffer_height, | |||
| 834 | XCB_IMAGE_FORMAT_Z_PIXMAP, | |||
| 835 | HostX.depth, | |||
| 836 | NULL((void*)0), | |||
| 837 | ~0, | |||
| 838 | NULL((void*)0)); | |||
| 839 | ||||
| 840 | scrpriv->shminfo.shmid = | |||
| 841 | shmget(IPC_PRIVATE((key_t)0), | |||
| 842 | scrpriv->ximg->stride * buffer_height, | |||
| 843 | IPC_CREAT001000 | 0777); | |||
| 844 | scrpriv->ximg->data = shmat(scrpriv->shminfo.shmid, 0, 0); | |||
| 845 | scrpriv->shminfo.shmaddr = scrpriv->ximg->data; | |||
| 846 | ||||
| 847 | if (scrpriv->ximg->data == (uint8_t *) -1) { | |||
| 848 | EPHYR_DBGdo {} while (0) | |||
| 849 | ("Can't attach SHM Segment, falling back to plain XImages")do {} while (0); | |||
| 850 | HostX.have_shm = FALSE0; | |||
| 851 | xcb_image_destroy (scrpriv->ximg); | |||
| 852 | shmctl(scrpriv->shminfo.shmid, IPC_RMID0, 0); | |||
| 853 | } | |||
| 854 | else { | |||
| 855 | EPHYR_DBG("SHM segment attached %p", scrpriv->shminfo.shmaddr)do {} while (0); | |||
| 856 | scrpriv->shminfo.shmseg = xcb_generate_id(HostX.conn); | |||
| 857 | xcb_shm_attach(HostX.conn, | |||
| 858 | scrpriv->shminfo.shmseg, | |||
| 859 | scrpriv->shminfo.shmid, | |||
| 860 | FALSE0); | |||
| 861 | shm_success = TRUE1; | |||
| 862 | } | |||
| 863 | } | |||
| 864 | ||||
| 865 | if (!ephyr_glamor && !shm_success) { | |||
| 866 | EPHYR_DBG("Creating image %dx%d for screen scrpriv=%p\n",do {} while (0) | |||
| 867 | width, buffer_height, scrpriv)do {} while (0); | |||
| 868 | scrpriv->ximg = xcb_image_create_native(HostX.conn, | |||
| 869 | width, | |||
| 870 | buffer_height, | |||
| 871 | XCB_IMAGE_FORMAT_Z_PIXMAP, | |||
| 872 | HostX.depth, | |||
| 873 | NULL((void*)0), | |||
| 874 | ~0, | |||
| 875 | NULL((void*)0)); | |||
| 876 | ||||
| 877 | /* Match server byte order so that the image can be converted to | |||
| 878 | * the native byte order by xcb_image_put() before drawing */ | |||
| 879 | if (host_depth_matches_server(scrpriv)(HostX.depth == (scrpriv)->server_depth)) | |||
| 880 | scrpriv->ximg->byte_order = IMAGE_BYTE_ORDER0; | |||
| 881 | ||||
| 882 | scrpriv->ximg->data = | |||
| 883 | xallocarray(scrpriv->ximg->stride, buffer_height)xreallocarray(((void*)0), (scrpriv->ximg->stride), (buffer_height )); | |||
| 884 | } | |||
| 885 | ||||
| 886 | { | |||
| 887 | uint32_t mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; | |||
| 888 | uint32_t values[2] = {width, height}; | |||
| 889 | xcb_configure_window(HostX.conn, scrpriv->win, mask, values); | |||
| 890 | } | |||
| 891 | ||||
| 892 | if (scrpriv->win_pre_existing == None0L && !EphyrWantResize) { | |||
| 893 | /* Ask the WM to keep our size static */ | |||
| 894 | xcb_size_hints_t size_hints = {0}; | |||
| 895 | size_hints.max_width = size_hints.min_width = width; | |||
| 896 | size_hints.max_height = size_hints.min_height = height; | |||
| 897 | size_hints.flags = (XCB_ICCCM_SIZE_HINT_P_MIN_SIZE | | |||
| 898 | XCB_ICCCM_SIZE_HINT_P_MAX_SIZE); | |||
| 899 | xcb_icccm_set_wm_normal_hints(HostX.conn, scrpriv->win, | |||
| 900 | &size_hints); | |||
| 901 | } | |||
| 902 | ||||
| 903 | xcb_map_window(HostX.conn, scrpriv->win); | |||
| 904 | ||||
| 905 | /* Set explicit window position if it was informed in | |||
| 906 | * -screen option (WxH+X or WxH+X+Y). Otherwise, accept the | |||
| 907 | * position set by WM. | |||
| 908 | * The trick here is putting this code after xcb_map_window() call, | |||
| 909 | * so these values won't be overriden by WM. */ | |||
| 910 | if (scrpriv->win_explicit_position) | |||
| 911 | { | |||
| 912 | uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y; | |||
| 913 | uint32_t values[2] = {x, y}; | |||
| 914 | xcb_configure_window(HostX.conn, scrpriv->win, mask, values); | |||
| 915 | } | |||
| 916 | ||||
| 917 | ||||
| 918 | xcb_aux_sync(HostX.conn); | |||
| 919 | ||||
| 920 | scrpriv->win_width = width; | |||
| 921 | scrpriv->win_height = height; | |||
| 922 | scrpriv->win_x = x; | |||
| 923 | scrpriv->win_y = y; | |||
| 924 | ||||
| 925 | #ifdef GLAMOR | |||
| 926 | if (ephyr_glamor) { | |||
| 927 | *bytes_per_line = 0; | |||
| 928 | *bits_per_pixel = 0; | |||
| 929 | ephyr_glamor_set_window_size(scrpriv->glamor, | |||
| 930 | scrpriv->win_width, scrpriv->win_height); | |||
| 931 | return NULL((void*)0); | |||
| 932 | } else | |||
| 933 | #endif | |||
| 934 | if (host_depth_matches_server(scrpriv)(HostX.depth == (scrpriv)->server_depth)) { | |||
| 935 | *bytes_per_line = scrpriv->ximg->stride; | |||
| ||||
| 936 | *bits_per_pixel = scrpriv->ximg->bpp; | |||
| 937 | ||||
| 938 | EPHYR_DBG("Host matches server")do {} while (0); | |||
| 939 | return scrpriv->ximg->data; | |||
| 940 | } | |||
| 941 | else { | |||
| 942 | int bytes_per_pixel = scrpriv->server_depth >> 3; | |||
| 943 | int stride = (width * bytes_per_pixel + 0x3) & ~0x3; | |||
| 944 | ||||
| 945 | *bytes_per_line = stride; | |||
| 946 | *bits_per_pixel = scrpriv->server_depth; | |||
| 947 | ||||
| 948 | EPHYR_DBG("server bpp %i", bytes_per_pixel)do {} while (0); | |||
| 949 | scrpriv->fb_data = xallocarray (stride, buffer_height)xreallocarray(((void*)0), (stride), (buffer_height)); | |||
| 950 | return scrpriv->fb_data; | |||
| 951 | } | |||
| 952 | } | |||
| 953 | ||||
| 954 | static void hostx_paint_debug_rect(KdScreenInfo *screen, | |||
| 955 | int x, int y, int width, int height); | |||
| 956 | ||||
| 957 | void | |||
| 958 | hostx_paint_rect(KdScreenInfo *screen, | |||
| 959 | int sx, int sy, int dx, int dy, int width, int height) | |||
| 960 | { | |||
| 961 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 962 | ||||
| 963 | EPHYR_DBG("painting in screen %d\n", scrpriv->mynum)do {} while (0); | |||
| 964 | ||||
| 965 | #ifdef GLAMOR | |||
| 966 | if (ephyr_glamor) { | |||
| 967 | BoxRec box; | |||
| 968 | RegionRec region; | |||
| 969 | ||||
| 970 | box.x1 = dx; | |||
| 971 | box.y1 = dy; | |||
| 972 | box.x2 = dx + width; | |||
| 973 | box.y2 = dy + height; | |||
| 974 | ||||
| 975 | RegionInit(®ion, &box, 1); | |||
| 976 | ephyr_glamor_damage_redisplay(scrpriv->glamor, ®ion); | |||
| 977 | RegionUninit(®ion); | |||
| 978 | return; | |||
| 979 | } | |||
| 980 | #endif | |||
| 981 | ||||
| 982 | /* | |||
| 983 | * Copy the image data updated by the shadow layer | |||
| 984 | * on to the window | |||
| 985 | */ | |||
| 986 | ||||
| 987 | if (HostXWantDamageDebug) { | |||
| 988 | hostx_paint_debug_rect(screen, dx, dy, width, height); | |||
| 989 | } | |||
| 990 | ||||
| 991 | /* | |||
| 992 | * If the depth of the ephyr server is less than that of the host, | |||
| 993 | * the kdrive fb does not point to the ximage data but to a buffer | |||
| 994 | * ( fb_data ), we shift the various bits from this onto the XImage | |||
| 995 | * so they match the host. | |||
| 996 | * | |||
| 997 | * Note, This code is pretty new ( and simple ) so may break on | |||
| 998 | * endian issues, 32 bpp host etc. | |||
| 999 | * Not sure if 8bpp case is right either. | |||
| 1000 | * ... and it will be slower than the matching depth case. | |||
| 1001 | */ | |||
| 1002 | ||||
| 1003 | if (!host_depth_matches_server(scrpriv)(HostX.depth == (scrpriv)->server_depth)) { | |||
| 1004 | int x, y, idx, bytes_per_pixel = (scrpriv->server_depth >> 3); | |||
| 1005 | int stride = (scrpriv->win_width * bytes_per_pixel + 0x3) & ~0x3; | |||
| 1006 | unsigned char r, g, b; | |||
| 1007 | unsigned long host_pixel; | |||
| 1008 | ||||
| 1009 | EPHYR_DBG("Unmatched host depth scrpriv=%p\n", scrpriv)do {} while (0); | |||
| 1010 | for (y = sy; y < sy + height; y++) | |||
| 1011 | for (x = sx; x < sx + width; x++) { | |||
| 1012 | idx = y * stride + x * bytes_per_pixel; | |||
| 1013 | ||||
| 1014 | switch (scrpriv->server_depth) { | |||
| 1015 | case 16: | |||
| 1016 | { | |||
| 1017 | unsigned short pixel = | |||
| 1018 | *(unsigned short *) (scrpriv->fb_data + idx); | |||
| 1019 | ||||
| 1020 | r = ((pixel & 0xf800) >> 8); | |||
| 1021 | g = ((pixel & 0x07e0) >> 3); | |||
| 1022 | b = ((pixel & 0x001f) << 3); | |||
| 1023 | ||||
| 1024 | host_pixel = (r << 16) | (g << 8) | (b); | |||
| 1025 | ||||
| 1026 | xcb_image_put_pixel(scrpriv->ximg, x, y, host_pixel); | |||
| 1027 | break; | |||
| 1028 | } | |||
| 1029 | case 8: | |||
| 1030 | { | |||
| 1031 | unsigned char pixel = | |||
| 1032 | *(unsigned char *) (scrpriv->fb_data + idx); | |||
| 1033 | xcb_image_put_pixel(scrpriv->ximg, x, y, | |||
| 1034 | scrpriv->cmap[pixel]); | |||
| 1035 | break; | |||
| 1036 | } | |||
| 1037 | default: | |||
| 1038 | break; | |||
| 1039 | } | |||
| 1040 | } | |||
| 1041 | } | |||
| 1042 | ||||
| 1043 | if (HostX.have_shm) { | |||
| 1044 | xcb_image_shm_put(HostX.conn, scrpriv->win, | |||
| 1045 | HostX.gc, scrpriv->ximg, | |||
| 1046 | scrpriv->shminfo, | |||
| 1047 | sx, sy, dx, dy, width, height, FALSE0); | |||
| 1048 | } | |||
| 1049 | else { | |||
| 1050 | xcb_image_t *subimg = xcb_image_subimage(scrpriv->ximg, sx, sy, | |||
| 1051 | width, height, 0, 0, 0); | |||
| 1052 | xcb_image_t *img = xcb_image_native(HostX.conn, subimg, 1); | |||
| 1053 | xcb_image_put(HostX.conn, scrpriv->win, HostX.gc, img, dx, dy, 0); | |||
| 1054 | if (subimg != img) | |||
| 1055 | xcb_image_destroy(img); | |||
| 1056 | xcb_image_destroy(subimg); | |||
| 1057 | } | |||
| 1058 | ||||
| 1059 | xcb_aux_sync(HostX.conn); | |||
| 1060 | } | |||
| 1061 | ||||
| 1062 | static void | |||
| 1063 | hostx_paint_debug_rect(KdScreenInfo *screen, | |||
| 1064 | int x, int y, int width, int height) | |||
| 1065 | { | |||
| 1066 | EphyrScrPriv *scrpriv = screen->driver; | |||
| 1067 | struct timespec tspec; | |||
| 1068 | xcb_rectangle_t rect = { .x = x, .y = y, .width = width, .height = height }; | |||
| 1069 | xcb_void_cookie_t cookie; | |||
| 1070 | xcb_generic_error_t *e; | |||
| 1071 | ||||
| 1072 | tspec.tv_sec = HostX.damage_debug_msec / (1000000); | |||
| 1073 | tspec.tv_nsec = (HostX.damage_debug_msec % 1000000) * 1000; | |||
| 1074 | ||||
| 1075 | EPHYR_DBG("msec: %li tv_sec %li, tv_msec %li",do {} while (0) | |||
| 1076 | HostX.damage_debug_msec, tspec.tv_sec, tspec.tv_nsec)do {} while (0); | |||
| 1077 | ||||
| 1078 | /* fprintf(stderr, "Xephyr updating: %i+%i %ix%i\n", x, y, width, height); */ | |||
| 1079 | ||||
| 1080 | cookie = xcb_poly_fill_rectangle_checked(HostX.conn, scrpriv->win, | |||
| 1081 | HostX.gc, 1, &rect); | |||
| 1082 | e = xcb_request_check(HostX.conn, cookie); | |||
| 1083 | free(e); | |||
| 1084 | ||||
| 1085 | /* nanosleep seems to work better than usleep for me... */ | |||
| 1086 | nanosleep(&tspec, NULL((void*)0)); | |||
| 1087 | } | |||
| 1088 | ||||
| 1089 | void | |||
| 1090 | hostx_load_keymap(void) | |||
| 1091 | { | |||
| 1092 | int min_keycode, max_keycode; | |||
| 1093 | ||||
| 1094 | min_keycode = xcb_get_setup(HostX.conn)->min_keycode; | |||
| 1095 | max_keycode = xcb_get_setup(HostX.conn)->max_keycode; | |||
| 1096 | ||||
| 1097 | EPHYR_DBG("min: %d, max: %d", min_keycode, max_keycode)do {} while (0); | |||
| 1098 | ||||
| 1099 | ephyrKeySyms.minKeyCode = min_keycode; | |||
| 1100 | ephyrKeySyms.maxKeyCode = max_keycode; | |||
| 1101 | } | |||
| 1102 | ||||
| 1103 | xcb_connection_t * | |||
| 1104 | hostx_get_xcbconn(void) | |||
| 1105 | { | |||
| 1106 | return HostX.conn; | |||
| 1107 | } | |||
| 1108 | ||||
| 1109 | int | |||
| 1110 | hostx_get_screen(void) | |||
| 1111 | { | |||
| 1112 | return HostX.screen; | |||
| 1113 | } | |||
| 1114 | ||||
| 1115 | int | |||
| 1116 | hostx_get_window(int a_screen_number) | |||
| 1117 | { | |||
| 1118 | EphyrScrPriv *scrpriv; | |||
| 1119 | if (a_screen_number < 0 || a_screen_number >= HostX.n_screens) { | |||
| 1120 | EPHYR_LOG_ERROR("bad screen number:%d\n", a_screen_number); | |||
| 1121 | return 0; | |||
| 1122 | } | |||
| 1123 | scrpriv = HostX.screens[a_screen_number]->driver; | |||
| 1124 | return scrpriv->win; | |||
| 1125 | } | |||
| 1126 | ||||
| 1127 | int | |||
| 1128 | hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attrs) | |||
| 1129 | { | |||
| 1130 | xcb_get_geometry_cookie_t geom_cookie; | |||
| 1131 | xcb_get_window_attributes_cookie_t attr_cookie; | |||
| 1132 | xcb_get_geometry_reply_t *geom_reply; | |||
| 1133 | xcb_get_window_attributes_reply_t *attr_reply; | |||
| 1134 | ||||
| 1135 | geom_cookie = xcb_get_geometry(HostX.conn, a_window); | |||
| 1136 | attr_cookie = xcb_get_window_attributes(HostX.conn, a_window); | |||
| 1137 | geom_reply = xcb_get_geometry_reply(HostX.conn, geom_cookie, NULL((void*)0)); | |||
| 1138 | attr_reply = xcb_get_window_attributes_reply(HostX.conn, attr_cookie, NULL((void*)0)); | |||
| 1139 | ||||
| 1140 | a_attrs->x = geom_reply->x; | |||
| 1141 | a_attrs->y = geom_reply->y; | |||
| 1142 | a_attrs->width = geom_reply->width; | |||
| 1143 | a_attrs->height = geom_reply->height; | |||
| 1144 | a_attrs->visualid = attr_reply->visual; | |||
| 1145 | ||||
| 1146 | free(geom_reply); | |||
| 1147 | free(attr_reply); | |||
| 1148 | return TRUE1; | |||
| 1149 | } | |||
| 1150 | ||||
| 1151 | int | |||
| 1152 | hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries) | |||
| 1153 | { | |||
| 1154 | Bool is_ok = FALSE0; | |||
| 1155 | EphyrHostVisualInfo *host_visuals = NULL((void*)0); | |||
| 1156 | int nb_items = 0, i = 0, screen_num; | |||
| 1157 | xcb_screen_iterator_t screens; | |||
| 1158 | xcb_depth_iterator_t depths; | |||
| 1159 | ||||
| 1160 | EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries, FALSE)if (!(a_visuals && a_num_entries)) {;return 0;}; | |||
| 1161 | EPHYR_LOG("enter\n"); | |||
| 1162 | ||||
| 1163 | screens = xcb_setup_roots_iterator(xcb_get_setup(HostX.conn)); | |||
| 1164 | for (screen_num = 0; screens.rem; screen_num++, xcb_screen_next(&screens)) { | |||
| 1165 | depths = xcb_screen_allowed_depths_iterator(screens.data); | |||
| 1166 | for (; depths.rem; xcb_depth_next(&depths)) { | |||
| 1167 | xcb_visualtype_t *visuals = xcb_depth_visuals(depths.data); | |||
| 1168 | EphyrHostVisualInfo *tmp_visuals = | |||
| 1169 | reallocarrayxreallocarray(host_visuals, | |||
| 1170 | nb_items + depths.data->visuals_len, | |||
| 1171 | sizeof(EphyrHostVisualInfo)); | |||
| 1172 | if (!tmp_visuals) { | |||
| 1173 | goto out; | |||
| 1174 | } | |||
| 1175 | host_visuals = tmp_visuals; | |||
| 1176 | for (i = 0; i < depths.data->visuals_len; i++) { | |||
| 1177 | host_visuals[nb_items + i].visualid = visuals[i].visual_id; | |||
| 1178 | host_visuals[nb_items + i].screen = screen_num; | |||
| 1179 | host_visuals[nb_items + i].depth = depths.data->depth; | |||
| 1180 | host_visuals[nb_items + i].class = visuals[i]._class; | |||
| 1181 | host_visuals[nb_items + i].red_mask = visuals[i].red_mask; | |||
| 1182 | host_visuals[nb_items + i].green_mask = visuals[i].green_mask; | |||
| 1183 | host_visuals[nb_items + i].blue_mask = visuals[i].blue_mask; | |||
| 1184 | host_visuals[nb_items + i].colormap_size = visuals[i].colormap_entries; | |||
| 1185 | host_visuals[nb_items + i].bits_per_rgb = visuals[i].bits_per_rgb_value; | |||
| 1186 | } | |||
| 1187 | nb_items += depths.data->visuals_len; | |||
| 1188 | } | |||
| 1189 | } | |||
| 1190 | ||||
| 1191 | EPHYR_LOG("host advertises %d visuals\n", nb_items); | |||
| 1192 | *a_visuals = host_visuals; | |||
| 1193 | *a_num_entries = nb_items; | |||
| 1194 | host_visuals = NULL((void*)0); | |||
| 1195 | ||||
| 1196 | is_ok = TRUE1; | |||
| 1197 | out: | |||
| 1198 | free(host_visuals); | |||
| 1199 | host_visuals = NULL((void*)0); | |||
| 1200 | EPHYR_LOG("leave\n"); | |||
| 1201 | return is_ok; | |||
| 1202 | ||||
| 1203 | } | |||
| 1204 | ||||
| 1205 | int | |||
| 1206 | hostx_create_window(int a_screen_number, | |||
| 1207 | EphyrBox * a_geometry, | |||
| 1208 | int a_visual_id, int *a_host_peer /*out parameter */ ) | |||
| 1209 | { | |||
| 1210 | Bool is_ok = FALSE0; | |||
| 1211 | xcb_window_t win; | |||
| 1212 | int winmask = 0; | |||
| 1213 | uint32_t attrs[2]; | |||
| 1214 | xcb_screen_t *screen = xcb_aux_get_screen(HostX.conn, hostx_get_screen()); | |||
| 1215 | xcb_visualtype_t *visual; | |||
| 1216 | int depth = 0; | |||
| 1217 | EphyrScrPriv *scrpriv = HostX.screens[a_screen_number]->driver; | |||
| 1218 | ||||
| 1219 | EPHYR_RETURN_VAL_IF_FAIL(screen && a_geometry, FALSE)if (!(screen && a_geometry)) {;return 0;}; | |||
| 1220 | ||||
| 1221 | EPHYR_LOG("enter\n"); | |||
| 1222 | ||||
| 1223 | visual = xcb_aux_find_visual_by_id(screen, a_visual_id); | |||
| 1224 | if (!visual) { | |||
| 1225 | EPHYR_LOG_ERROR ("argh, could not find a remote visual with id:%d\n", | |||
| 1226 | a_visual_id); | |||
| 1227 | goto out; | |||
| 1228 | } | |||
| 1229 | depth = xcb_aux_get_depth_of_visual(screen, a_visual_id); | |||
| 1230 | ||||
| 1231 | winmask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; | |||
| 1232 | attrs[0] = XCB_EVENT_MASK_BUTTON_PRESS | |||
| 1233 | |XCB_EVENT_MASK_BUTTON_RELEASE | |||
| 1234 | |XCB_EVENT_MASK_POINTER_MOTION | |||
| 1235 | |XCB_EVENT_MASK_KEY_PRESS | |||
| 1236 | |XCB_EVENT_MASK_KEY_RELEASE | |||
| 1237 | |XCB_EVENT_MASK_EXPOSURE; | |||
| 1238 | attrs[1] = xcb_generate_id(HostX.conn); | |||
| 1239 | xcb_create_colormap(HostX.conn, | |||
| 1240 | XCB_COLORMAP_ALLOC_NONE, | |||
| 1241 | attrs[1], | |||
| 1242 | hostx_get_window(a_screen_number), | |||
| 1243 | a_visual_id); | |||
| 1244 | ||||
| 1245 | win = xcb_generate_id(HostX.conn); | |||
| 1246 | xcb_create_window(HostX.conn, | |||
| 1247 | depth, | |||
| 1248 | win, | |||
| 1249 | hostx_get_window (a_screen_number), | |||
| 1250 | a_geometry->x, a_geometry->y, | |||
| 1251 | a_geometry->width, a_geometry->height, 0, | |||
| 1252 | XCB_WINDOW_CLASS_COPY_FROM_PARENT, | |||
| 1253 | a_visual_id, winmask, attrs); | |||
| 1254 | ||||
| 1255 | if (scrpriv->peer_win == XCB_NONE0L) { | |||
| 1256 | scrpriv->peer_win = win; | |||
| 1257 | } | |||
| 1258 | else { | |||
| 1259 | EPHYR_LOG_ERROR("multiple peer windows created for same screen\n"); | |||
| 1260 | } | |||
| 1261 | xcb_flush(HostX.conn); | |||
| 1262 | xcb_map_window(HostX.conn, win); | |||
| 1263 | *a_host_peer = win; | |||
| 1264 | is_ok = TRUE1; | |||
| 1265 | out: | |||
| 1266 | EPHYR_LOG("leave\n"); | |||
| 1267 | return is_ok; | |||
| 1268 | } | |||
| 1269 | ||||
| 1270 | int | |||
| 1271 | hostx_destroy_window(int a_win) | |||
| 1272 | { | |||
| 1273 | xcb_destroy_window(HostX.conn, a_win); | |||
| 1274 | xcb_flush(HostX.conn); | |||
| 1275 | return TRUE1; | |||
| 1276 | } | |||
| 1277 | ||||
| 1278 | int | |||
| 1279 | hostx_set_window_geometry(int a_win, EphyrBox * a_geo) | |||
| 1280 | { | |||
| 1281 | uint32_t mask = XCB_CONFIG_WINDOW_X | |||
| 1282 | | XCB_CONFIG_WINDOW_Y | |||
| 1283 | | XCB_CONFIG_WINDOW_WIDTH | |||
| 1284 | | XCB_CONFIG_WINDOW_HEIGHT; | |||
| 1285 | uint32_t values[4]; | |||
| 1286 | ||||
| 1287 | EPHYR_RETURN_VAL_IF_FAIL(a_geo, FALSE)if (!(a_geo)) {;return 0;}; | |||
| 1288 | ||||
| 1289 | EPHYR_LOG("enter. x,y,w,h:(%d,%d,%d,%d)\n", | |||
| 1290 | a_geo->x, a_geo->y, a_geo->width, a_geo->height); | |||
| 1291 | ||||
| 1292 | values[0] = a_geo->x; | |||
| 1293 | values[1] = a_geo->y; | |||
| 1294 | values[2] = a_geo->width; | |||
| 1295 | values[3] = a_geo->height; | |||
| 1296 | xcb_configure_window(HostX.conn, a_win, mask, values); | |||
| 1297 | ||||
| 1298 | EPHYR_LOG("leave\n"); | |||
| 1299 | return TRUE1; | |||
| 1300 | } | |||
| 1301 | ||||
| 1302 | int | |||
| 1303 | hostx_set_window_bounding_rectangles(int a_window, | |||
| 1304 | EphyrRect * a_rects, int a_num_rects) | |||
| 1305 | { | |||
| 1306 | Bool is_ok = FALSE0; | |||
| 1307 | int i = 0; | |||
| 1308 | xcb_rectangle_t *rects = NULL((void*)0); | |||
| 1309 | ||||
| 1310 | EPHYR_RETURN_VAL_IF_FAIL(a_rects, FALSE)if (!(a_rects)) {;return 0;}; | |||
| 1311 | ||||
| 1312 | EPHYR_LOG("enter. num rects:%d\n", a_num_rects); | |||
| 1313 | ||||
| 1314 | rects = calloc(a_num_rects, sizeof (xcb_rectangle_t)); | |||
| 1315 | if (!rects) | |||
| 1316 | goto out; | |||
| 1317 | for (i = 0; i < a_num_rects; i++) { | |||
| 1318 | rects[i].x = a_rects[i].x1; | |||
| 1319 | rects[i].y = a_rects[i].y1; | |||
| 1320 | rects[i].width = abs(a_rects[i].x2 - a_rects[i].x1); | |||
| 1321 | rects[i].height = abs(a_rects[i].y2 - a_rects[i].y1); | |||
| 1322 | EPHYR_LOG("borders clipped to rect[x:%d,y:%d,w:%d,h:%d]\n", | |||
| 1323 | rects[i].x, rects[i].y, rects[i].width, rects[i].height); | |||
| 1324 | } | |||
| 1325 | xcb_shape_rectangles(HostX.conn, | |||
| 1326 | XCB_SHAPE_SO_SET, | |||
| 1327 | XCB_SHAPE_SK_BOUNDING, | |||
| 1328 | XCB_CLIP_ORDERING_YX_BANDED, | |||
| 1329 | a_window, | |||
| 1330 | 0, 0, | |||
| 1331 | a_num_rects, | |||
| 1332 | rects); | |||
| 1333 | is_ok = TRUE1; | |||
| 1334 | ||||
| 1335 | out: | |||
| 1336 | free(rects); | |||
| 1337 | rects = NULL((void*)0); | |||
| 1338 | EPHYR_LOG("leave\n"); | |||
| 1339 | return is_ok; | |||
| 1340 | } | |||
| 1341 | ||||
| 1342 | #ifdef XF86DRI | |||
| 1343 | typedef struct { | |||
| 1344 | int is_valid; | |||
| 1345 | int local_id; | |||
| 1346 | int remote_id; | |||
| 1347 | } ResourcePair; | |||
| 1348 | ||||
| 1349 | #define RESOURCE_PEERS_SIZE 1024*10 | |||
| 1350 | static ResourcePair resource_peers[RESOURCE_PEERS_SIZE]; | |||
| 1351 | ||||
| 1352 | int | |||
| 1353 | hostx_allocate_resource_id_peer(int a_local_resource_id, | |||
| 1354 | int *a_remote_resource_id) | |||
| 1355 | { | |||
| 1356 | int i = 0; | |||
| 1357 | ResourcePair *peer = NULL((void*)0); | |||
| 1358 | ||||
| 1359 | /* | |||
| 1360 | * first make sure a resource peer | |||
| 1361 | * does not exist already for | |||
| 1362 | * a_local_resource_id | |||
| 1363 | */ | |||
| 1364 | for (i = 0; i < RESOURCE_PEERS_SIZE; i++) { | |||
| 1365 | if (resource_peers[i].is_valid | |||
| 1366 | && resource_peers[i].local_id == a_local_resource_id) { | |||
| 1367 | peer = &resource_peers[i]; | |||
| 1368 | break; | |||
| 1369 | } | |||
| 1370 | } | |||
| 1371 | /* | |||
| 1372 | * find one free peer entry, an feed it with | |||
| 1373 | */ | |||
| 1374 | if (!peer) { | |||
| 1375 | for (i = 0; i < RESOURCE_PEERS_SIZE; i++) { | |||
| 1376 | if (!resource_peers[i].is_valid) { | |||
| 1377 | peer = &resource_peers[i]; | |||
| 1378 | break; | |||
| 1379 | } | |||
| 1380 | } | |||
| 1381 | if (peer) { | |||
| 1382 | peer->remote_id = xcb_generate_id(HostX.conn); | |||
| 1383 | peer->local_id = a_local_resource_id; | |||
| 1384 | peer->is_valid = TRUE1; | |||
| 1385 | } | |||
| 1386 | } | |||
| 1387 | if (peer) { | |||
| 1388 | *a_remote_resource_id = peer->remote_id; | |||
| 1389 | return TRUE1; | |||
| 1390 | } | |||
| 1391 | return FALSE0; | |||
| 1392 | } | |||
| 1393 | ||||
| 1394 | int | |||
| 1395 | hostx_get_resource_id_peer(int a_local_resource_id, int *a_remote_resource_id) | |||
| 1396 | { | |||
| 1397 | int i = 0; | |||
| 1398 | ResourcePair *peer = NULL((void*)0); | |||
| 1399 | ||||
| 1400 | for (i = 0; i < RESOURCE_PEERS_SIZE; i++) { | |||
| 1401 | if (resource_peers[i].is_valid | |||
| 1402 | && resource_peers[i].local_id == a_local_resource_id) { | |||
| 1403 | peer = &resource_peers[i]; | |||
| 1404 | break; | |||
| 1405 | } | |||
| 1406 | } | |||
| 1407 | if (peer) { | |||
| 1408 | *a_remote_resource_id = peer->remote_id; | |||
| 1409 | return TRUE1; | |||
| 1410 | } | |||
| 1411 | return FALSE0; | |||
| 1412 | } | |||
| 1413 | ||||
| 1414 | #endif /* XF86DRI */ | |||
| 1415 | ||||
| 1416 | #ifdef GLAMOR | |||
| 1417 | Bool | |||
| 1418 | ephyr_glamor_init(ScreenPtr screen) | |||
| 1419 | { | |||
| 1420 | KdScreenPriv(screen)KdPrivScreenPtr pScreenPriv = ((KdPrivScreenPtr) dixLookupPrivate (&(screen)->devPrivates, (&kdScreenPrivateKeyRec)) ); | |||
| 1421 | KdScreenInfo *kd_screen = pScreenPriv->screen; | |||
| 1422 | EphyrScrPriv *scrpriv = kd_screen->driver; | |||
| 1423 | ||||
| 1424 | scrpriv->glamor = ephyr_glamor_glx_screen_init(scrpriv->win); | |||
| 1425 | ephyr_glamor_set_window_size(scrpriv->glamor, | |||
| 1426 | scrpriv->win_width, scrpriv->win_height); | |||
| 1427 | ||||
| 1428 | if (!glamor_init(screen, 0)) { | |||
| 1429 | FatalError("Failed to initialize glamor\n"); | |||
| 1430 | return FALSE0; | |||
| 1431 | } | |||
| 1432 | ||||
| 1433 | return TRUE1; | |||
| 1434 | } | |||
| 1435 | ||||
| 1436 | Bool | |||
| 1437 | ephyr_glamor_create_screen_resources(ScreenPtr pScreen) | |||
| 1438 | { | |||
| 1439 | KdScreenPriv(pScreen)KdPrivScreenPtr pScreenPriv = ((KdPrivScreenPtr) dixLookupPrivate (&(pScreen)->devPrivates, (&kdScreenPrivateKeyRec) )); | |||
| 1440 | KdScreenInfo *kd_screen = pScreenPriv->screen; | |||
| 1441 | EphyrScrPriv *scrpriv = kd_screen->driver; | |||
| 1442 | PixmapPtr screen_pixmap; | |||
| 1443 | uint32_t tex; | |||
| 1444 | ||||
| 1445 | if (!ephyr_glamor) | |||
| 1446 | return TRUE1; | |||
| 1447 | ||||
| 1448 | /* kdrive's fbSetupScreen() told mi to have | |||
| 1449 | * miCreateScreenResources() (which is called before this) make a | |||
| 1450 | * scratch pixmap wrapping ephyr-glamor's NULL | |||
| 1451 | * KdScreenInfo->fb.framebuffer. | |||
| 1452 | * | |||
| 1453 | * We want a real (texture-based) screen pixmap at this point. | |||
| 1454 | * This is what glamor will render into, and we'll then texture | |||
| 1455 | * out of that into the host's window to present the results. | |||
| 1456 | * | |||
| 1457 | * Thus, delete the current screen pixmap, and put a fresh one in. | |||
| 1458 | */ | |||
| 1459 | screen_pixmap = pScreen->GetScreenPixmap(pScreen); | |||
| 1460 | pScreen->DestroyPixmap(screen_pixmap); | |||
| 1461 | ||||
| 1462 | screen_pixmap = pScreen->CreatePixmap(pScreen, | |||
| 1463 | pScreen->width, | |||
| 1464 | pScreen->height, | |||
| 1465 | pScreen->rootDepth, | |||
| 1466 | GLAMOR_CREATE_NO_LARGE); | |||
| 1467 | ||||
| 1468 | pScreen->SetScreenPixmap(screen_pixmap); | |||
| 1469 | ||||
| 1470 | /* Tell the GLX code what to GL texture to read from. */ | |||
| 1471 | tex = glamor_get_pixmap_texture(screen_pixmap); | |||
| 1472 | ephyr_glamor_set_texture(scrpriv->glamor, tex); | |||
| 1473 | ||||
| 1474 | return TRUE1; | |||
| 1475 | } | |||
| 1476 | ||||
| 1477 | void | |||
| 1478 | ephyr_glamor_enable(ScreenPtr screen) | |||
| 1479 | { | |||
| 1480 | } | |||
| 1481 | ||||
| 1482 | void | |||
| 1483 | ephyr_glamor_disable(ScreenPtr screen) | |||
| 1484 | { | |||
| 1485 | } | |||
| 1486 | ||||
| 1487 | void | |||
| 1488 | ephyr_glamor_fini(ScreenPtr screen) | |||
| 1489 | { | |||
| 1490 | KdScreenPriv(screen)KdPrivScreenPtr pScreenPriv = ((KdPrivScreenPtr) dixLookupPrivate (&(screen)->devPrivates, (&kdScreenPrivateKeyRec)) ); | |||
| 1491 | KdScreenInfo *kd_screen = pScreenPriv->screen; | |||
| 1492 | EphyrScrPriv *scrpriv = kd_screen->driver; | |||
| 1493 | ||||
| 1494 | glamor_fini(screen); | |||
| 1495 | ephyr_glamor_glx_screen_fini(scrpriv->glamor); | |||
| 1496 | scrpriv->glamor = NULL((void*)0); | |||
| 1497 | } | |||
| 1498 | #endif |