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
|
/*
* Copyright (c) 2008-2009 Intel Corporation. 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 PRECISION INSIGHT 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.
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <va/va_x11.h>
static Window window_thread0, window_thread1;
static GC context_thread0, context_thread1;
static pthread_mutex_t gmutex;
static void *open_display(void);
static void close_display(void *win_display);
static int create_window(void *win_display, int x, int y, int width, int height);
static int check_window_event(void *x11_display, void *drawable, int *width, int *height, int *quit);
#define CAST_DRAWABLE(a) (Drawable)(a)
#include "putsurface_common.c"
static void *open_display(void)
{
return XOpenDisplay(NULL);
}
static void close_display(void *win_display)
{
XCloseDisplay(win_display);
}
static Pixmap create_pixmap(void *win_display, int width, int height)
{
Display *x11_display = (Display *)win_display;
int screen = DefaultScreen(x11_display);
Window root;
Pixmap pixmap;
XWindowAttributes attr;
root = RootWindow(x11_display, screen);
XGetWindowAttributes (x11_display, root, &attr);
printf("Create a pixmap from ROOT window %dx%d, pixmap size %dx%d\n\n", attr.width, attr.height, width, height);
pixmap = XCreatePixmap(x11_display, root, width, height,
DefaultDepth(x11_display, DefaultScreen(x11_display)));
return pixmap;
}
static int create_window(void *win_display, int x, int y, int width, int height)
{
Display *x11_display = (Display *)win_display;
int screen = DefaultScreen(x11_display);
Window root, win;
root = RootWindow(x11_display, screen);
printf("Create window0 for thread0\n");
drawable_thread0 = (void *)XCreateSimpleWindow(x11_display, root, x, y, width, height,
0, 0, WhitePixel(x11_display, 0));
win = (Window)drawable_thread0;
if (drawable_thread0) {
XSizeHints sizehints;
sizehints.width = width;
sizehints.height = height;
sizehints.flags = USSize;
XSetNormalHints(x11_display, win, &sizehints);
XSetStandardProperties(x11_display, win, "Thread 0", "Thread 0",
None, (char **)NULL, 0, &sizehints);
XMapWindow(x11_display, win);
}
context_thread0 = XCreateGC(x11_display, win, 0, 0);
XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
XSync(x11_display, False);
if (put_pixmap) {
window_thread0 = (Window)drawable_thread0;
drawable_thread0 = (void *)create_pixmap(x11_display, width, height);
}
if (multi_thread == 0)
return 0;
printf("Create window1 for thread1\n");
drawable_thread1 = (void *)XCreateSimpleWindow(x11_display, root, width, 0, width, height,
0, 0, WhitePixel(x11_display, 0));
win = (Window)drawable_thread1;
if (drawable_thread1) {
XSizeHints sizehints;
sizehints.width = width;
sizehints.height = height;
sizehints.flags = USSize;
XSetNormalHints(x11_display, win, &sizehints);
XSetStandardProperties(x11_display, win, "Thread 1", "Thread 1",
None, (char **)NULL, 0, &sizehints);
XMapWindow(x11_display, win);
}
if (put_pixmap) {
window_thread1 = (Window)drawable_thread1;
drawable_thread1 = (void *)create_pixmap(x11_display, width, height);
}
context_thread1 = XCreateGC(x11_display, win, 0, 0);
XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
XSync(x11_display, False);
return 0;
}
static int check_window_event(void *win_display, void *drawable, int *width, int *height, int *quit)
{
int is_event = 0;
XEvent event;
Window win = (Window)drawable;
Display *x11_display = (Display *)win_display;
if (check_event == 0)
return 0;
pthread_mutex_lock(&gmutex);
is_event = XCheckWindowEvent(x11_display, win, StructureNotifyMask|KeyPressMask,&event);
pthread_mutex_unlock(&gmutex);
if (is_event == 0)
return 0;
/* bail on any focused key press */
if(event.type == KeyPress) {
*quit = 1;
return 0;
}
#if 0
/* rescale the video to fit the window */
if(event.type == ConfigureNotify) {
*width = event.xconfigure.width;
*height = event.xconfigure.height;
printf("Scale window to %dx%d\n", width, height);
}
#endif
return 0;
}
|