OSDN Git Service

test/putsurface: more cleanup, remove #ifdef ANDROID from putsurface_common.c
[android-x86/hardware-intel-common-libva.git] / test / putsurface / putsurface_x11.c
index 3968ad3..3912d1a 100644 (file)
 #include <X11/Xutil.h>
 #include <va/va_x11.h>
 
-static  Window win_thread0, win_thread1;
-static  int multi_thread = 0;
-static  Pixmap pixmap_thread0, pixmap_thread1;
+static  Window window_thread0, window_thread1;
 static  GC context_thread0, context_thread1;
-static pthread_mutex_t gmutex;
+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 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 Pixmap create_pixmap(int width, int height)
+static void *open_display(void)
+{
+    return XOpenDisplay(":0.0");
+}
+
+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;
@@ -52,17 +68,18 @@ static Pixmap create_pixmap(int width, int height)
     return pixmap;
 }
 
-static int create_window(int width, int height)
+static int create_window(void *win_display, 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");
-    win_thread0 = win = XCreateSimpleWindow(x11_display, root, 0, 0, width, height,
-                                            0, 0, WhitePixel(x11_display, 0));
-    if (win) {
+    drawable_thread0 = (void *)XCreateSimpleWindow(x11_display, root, 0, 0, width, height,
+                                           0, 0, WhitePixel(x11_display, 0));
+    if (drawable_thread0) {
         XSizeHints sizehints;
         sizehints.width  = width;
         sizehints.height = height;
@@ -77,17 +94,19 @@ static int create_window(int width, int height)
     XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
     XSync(x11_display, False);
 
-    if (put_pixmap)
-        pixmap_thread0 = create_pixmap(width, height);
+    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");
     
-    win_thread1 = win = XCreateSimpleWindow(x11_display, root, width, 0, width, height,
+    drawable_thread1 = (void *)XCreateSimpleWindow(x11_display, root, width, 0, width, height,
                                             0, 0, WhitePixel(x11_display, 0));
-    if (win) {
+    if (drawable_thread1) {
         XSizeHints sizehints;
         sizehints.width  = width;
         sizehints.height = height;
@@ -98,8 +117,10 @@ static int create_window(int width, int height)
 
         XMapWindow(x11_display, win);
     }
-    if (put_pixmap)
-        pixmap_thread1 = create_pixmap(width, height);
+    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);
@@ -107,3 +128,40 @@ static int create_window(int width, int height)
     
     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
+}
+
+
+