OSDN Git Service

1) test/*: enable/refine the test/* for both X11 and Android
[android-x86/hardware-intel-libva.git] / test / putsurface / putsurface_x11.c
1 /*
2  * Copyright (c) 2008-2009 Intel Corporation. All Rights Reserved.
3  *
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:
11  * 
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  * 
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.
23  */
24
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <va/va_x11.h>
28
29 static  Window win_thread0, win_thread1;
30 static  int multi_thread = 0;
31 static  Pixmap pixmap_thread0, pixmap_thread1;
32 static  GC context_thread0, context_thread1;
33 static pthread_mutex_t gmutex;
34
35 #include "putsurface_common.c"
36
37 static Pixmap create_pixmap(int width, int height)
38 {
39     int screen = DefaultScreen(x11_display);
40     Window root;
41     Pixmap pixmap;
42     XWindowAttributes attr;
43     
44     root = RootWindow(x11_display, screen);
45
46     XGetWindowAttributes (x11_display, root, &attr);
47     
48     printf("Create a pixmap from ROOT window %dx%d, pixmap size %dx%d\n\n", attr.width, attr.height, width, height);
49     pixmap = XCreatePixmap(x11_display, root, width, height,
50                            DefaultDepth(x11_display, DefaultScreen(x11_display)));
51
52     return pixmap;
53 }
54
55 static int create_window(int width, int height)
56 {
57     int screen = DefaultScreen(x11_display);
58     Window root, win;
59
60     root = RootWindow(x11_display, screen);
61
62     printf("Create window0 for thread0\n");
63     win_thread0 = win = XCreateSimpleWindow(x11_display, root, 0, 0, width, height,
64                                             0, 0, WhitePixel(x11_display, 0));
65     if (win) {
66         XSizeHints sizehints;
67         sizehints.width  = width;
68         sizehints.height = height;
69         sizehints.flags = USSize;
70         XSetNormalHints(x11_display, win, &sizehints);
71         XSetStandardProperties(x11_display, win, "Thread 0", "Thread 0",
72                                None, (char **)NULL, 0, &sizehints);
73
74         XMapWindow(x11_display, win);
75     }
76     context_thread0 = XCreateGC(x11_display, win, 0, 0);
77     XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
78     XSync(x11_display, False);
79
80     if (put_pixmap)
81         pixmap_thread0 = create_pixmap(width, height);
82     
83     if (multi_thread == 0)
84         return 0;
85
86     printf("Create window1 for thread1\n");
87     
88     win_thread1 = win = XCreateSimpleWindow(x11_display, root, width, 0, width, height,
89                                             0, 0, WhitePixel(x11_display, 0));
90     if (win) {
91         XSizeHints sizehints;
92         sizehints.width  = width;
93         sizehints.height = height;
94         sizehints.flags = USSize;
95         XSetNormalHints(x11_display, win, &sizehints);
96         XSetStandardProperties(x11_display, win, "Thread 1", "Thread 1",
97                                None, (char **)NULL, 0, &sizehints);
98
99         XMapWindow(x11_display, win);
100     }
101     if (put_pixmap)
102         pixmap_thread1 = create_pixmap(width, height);
103
104     context_thread1 = XCreateGC(x11_display, win, 0, 0);
105     XSelectInput(x11_display, win, KeyPressMask | StructureNotifyMask);
106     XSync(x11_display, False);
107     
108     return 0;
109 }