2 * Copyright (c) 2008-2009 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include <X11/Xutil.h>
27 #include <va/va_x11.h>
29 static Window window_thread0, window_thread1;
30 static GC context_thread0, context_thread1;
31 static pthread_mutex_t gmutex;
33 static void *open_display(void);
34 static void close_display(void *win_display);
35 static int create_window(void *win_display, int x, int y, int width, int height);
36 static int check_window_event(void *x11_display, void *drawable, int *width, int *height, int *quit);
38 #define CAST_DRAWABLE(a) (Drawable)(a)
40 #include "putsurface_common.c"
42 static void *open_display(void)
44 return XOpenDisplay(":0.0");
47 static void close_display(void *win_display)
49 XCloseDisplay(win_display);
52 static Pixmap create_pixmap(void *win_display, int width, int height)
54 Display *x11_display = (Display *)win_display;
55 int screen = DefaultScreen(x11_display);
58 XWindowAttributes attr;
60 root = RootWindow(x11_display, screen);
62 XGetWindowAttributes (x11_display, root, &attr);
64 printf("Create a pixmap from ROOT window %dx%d, pixmap size %dx%d\n\n", attr.width, attr.height, width, height);
65 pixmap = XCreatePixmap(x11_display, root, width, height,
66 DefaultDepth(x11_display, DefaultScreen(x11_display)));
71 static int create_window(void *win_display, int x, int y, int width, int height)
73 Display *x11_display = (Display *)win_display;
74 int screen = DefaultScreen(x11_display);
77 root = RootWindow(x11_display, screen);
79 printf("Create window0 for thread0\n");
80 drawable_thread0 = (void *)XCreateSimpleWindow(x11_display, root, x, y, width, height,
81 0, 0, WhitePixel(x11_display, 0));
83 win = (Window)drawable_thread0;
84 if (drawable_thread0) {
86 sizehints.width = width;
87 sizehints.height = height;
88 sizehints.flags = USSize;
89 XSetNormalHints(x11_display, win, &sizehints);
90 XSetStandardProperties(x11_display, win, "Thread 0", "Thread 0",
91 None, (char **)NULL, 0, &sizehints);
93 XMapWindow(x11_display, win);
95 context_thread0 = XCreateGC(x11_display, win, 0, 0);
96 XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
97 XSync(x11_display, False);
100 window_thread0 = (Window)drawable_thread0;
101 drawable_thread0 = (void *)create_pixmap(x11_display, width, height);
104 if (multi_thread == 0)
107 printf("Create window1 for thread1\n");
109 drawable_thread1 = (void *)XCreateSimpleWindow(x11_display, root, width, 0, width, height,
110 0, 0, WhitePixel(x11_display, 0));
111 win = (Window)drawable_thread1;
112 if (drawable_thread1) {
113 XSizeHints sizehints;
114 sizehints.width = width;
115 sizehints.height = height;
116 sizehints.flags = USSize;
117 XSetNormalHints(x11_display, win, &sizehints);
118 XSetStandardProperties(x11_display, win, "Thread 1", "Thread 1",
119 None, (char **)NULL, 0, &sizehints);
121 XMapWindow(x11_display, win);
124 window_thread1 = (Window)drawable_thread1;
125 drawable_thread1 = (void *)create_pixmap(x11_display, width, height);
128 context_thread1 = XCreateGC(x11_display, win, 0, 0);
129 XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
130 XSync(x11_display, False);
135 static int check_window_event(void *win_display, void *drawable, int *width, int *height, int *quit)
139 Window win = (Window)drawable;
140 Display *x11_display = (Display *)win_display;
143 if (check_event == 0)
146 pthread_mutex_lock(&gmutex);
147 is_event = XCheckWindowEvent(x11_display, win, StructureNotifyMask|KeyPressMask,&event);
148 pthread_mutex_unlock(&gmutex);
153 /* bail on any focused key press */
154 if(event.type == KeyPress) {
160 /* rescale the video to fit the window */
161 if(event.type == ConfigureNotify) {
162 *width = event.xconfigure.width;
163 *height = event.xconfigure.height;
164 printf("Scale window to %dx%d\n", width, height);