Fix make dist.
[profile/ivi/gstreamer-vaapi.git] / tests / test-windows.c
1 /*
2  *  test-windows.c - Test GstVaapiWindow
3  *
4  *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20
21 #include <gst/vaapi/gstvaapidisplay_x11.h>
22 #include <gst/vaapi/gstvaapiwindow_x11.h>
23 #include <gst/vaapi/gstvaapisurface.h>
24 #include <gst/vaapi/gstvaapiimage.h>
25 #include "image.h"
26
27 static inline void pause(void)
28 {
29     g_print("Press any key to continue...\n");
30     getchar();
31 }
32
33 int
34 main(int argc, char *argv[])
35 {
36     GstVaapiDisplay    *display;
37     GstVaapiWindow     *window;
38     GstVaapiSurface    *surface;
39     GstVaapiImage      *image   = NULL;
40     guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
41     guint i;
42
43     static const GstVaapiImageFormat image_formats[] = {
44         GST_VAAPI_IMAGE_NV12,
45         GST_VAAPI_IMAGE_YV12,
46         GST_VAAPI_IMAGE_I420,
47         GST_VAAPI_IMAGE_AYUV,
48         GST_VAAPI_IMAGE_ARGB,
49         GST_VAAPI_IMAGE_BGRA,
50         GST_VAAPI_IMAGE_RGBA,
51         GST_VAAPI_IMAGE_ABGR,
52         0
53     };
54
55     static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
56     static const guint              width       = 320;
57     static const guint              height      = 240;
58     static const guint              win_width   = 640;
59     static const guint              win_height  = 480;
60
61     gst_init(&argc, &argv);
62
63     display = gst_vaapi_display_x11_new(NULL);
64     if (!display)
65         g_error("could not create Gst/VA display");
66
67     surface = gst_vaapi_surface_new(display, chroma_type, width, height);
68     if (!surface)
69         g_error("could not create Gst/VA surface");
70
71     for (i = 0; image_formats[i]; i++) {
72         const GstVaapiImageFormat format = image_formats[i];
73
74         image = image_generate(display, format, width, height);
75         if (image) {
76             if (image_upload(image, surface))
77                 break;
78             g_object_unref(image);
79         }
80     }
81     if (!image)
82         g_error("could not create Gst/VA image");
83
84     if (!gst_vaapi_surface_sync(surface))
85         g_error("could not complete image upload");
86
87     g_print("#\n");
88     g_print("# Create window with gst_vaapi_window_x11_new()\n");
89     g_print("#\n");
90     {
91         window = gst_vaapi_window_x11_new(display, win_width, win_height);
92         if (!window)
93             g_error("could not create window");
94
95         gst_vaapi_window_show(window);
96
97         if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
98             g_error("could not render surface");
99
100         pause();
101         g_object_unref(window);
102     }
103
104     g_print("#\n");
105     g_print("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
106     g_print("#\n");
107     {
108         Display * const dpy = gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
109         Window rootwin, win;
110         int screen;
111         unsigned long white_pixel, black_pixel;
112
113         screen      = DefaultScreen(dpy);
114         rootwin     = RootWindow(dpy, screen);
115         white_pixel = WhitePixel(dpy, screen);
116         black_pixel = BlackPixel(dpy, screen);
117
118         win = XCreateSimpleWindow(
119             dpy,
120             rootwin,
121             0, 0, win_width, win_height,
122             0, black_pixel,
123             white_pixel
124         );
125         if (!win)
126             g_error("could not create X window");
127
128         window = gst_vaapi_window_x11_new_with_xid(display, win);
129         if (!window)
130             g_error("could not create window");
131
132         gst_vaapi_window_show(window);
133
134         if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
135             g_error("could not render surface");
136
137         pause();
138         g_object_unref(window);
139         XUnmapWindow(dpy, win);
140         XDestroyWindow(dpy, win);
141     }
142
143     g_object_unref(image);
144     g_object_unref(surface);
145     g_object_unref(display);
146     gst_deinit();
147     return 0;
148 }