2 * test-windows.c - Test GstVaapiWindow
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
23 #include <gst/vaapi/gstvaapisurface.h>
24 #include <gst/vaapi/gstvaapiimage.h>
26 # include <gst/vaapi/gstvaapidisplay_drm.h>
27 # include <gst/vaapi/gstvaapiwindow_drm.h>
30 # include <gst/vaapi/gstvaapidisplay_x11.h>
31 # include <gst/vaapi/gstvaapiwindow_x11.h>
34 # include <gst/vaapi/gstvaapidisplay_wayland.h>
35 # include <gst/vaapi/gstvaapiwindow_wayland.h>
42 g_print("Press any key to continue...\n");
46 static GstVaapiSurface *
47 create_test_surface(GstVaapiDisplay *display, guint width, guint height)
49 GstVaapiImage *image = NULL;
50 GstVaapiSurface *surface;
53 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
54 static const GstVaapiImageFormat image_formats[] = {
66 surface = gst_vaapi_surface_new(display, chroma_type, width, height);
68 g_error("could not create Gst/VA surface");
70 for (i = 0; image_formats[i]; i++) {
71 const GstVaapiImageFormat format = image_formats[i];
73 image = image_generate(display, format, width, height);
76 if (image_upload(image, surface))
80 g_error("could not create Gst/VA image");
82 if (!gst_vaapi_surface_sync(surface))
83 g_error("could not complete image upload");
85 g_object_unref(image);
90 main(int argc, char *argv[])
92 GstVaapiDisplay *display;
93 GstVaapiWindow *window;
94 GstVaapiSurface *surface;
95 guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
97 static const guint width = 320;
98 static const guint height = 240;
99 static const guint win_width = 640;
100 static const guint win_height = 480;
102 gst_init(&argc, &argv);
105 display = gst_vaapi_display_drm_new(NULL);
107 g_error("could not create Gst/VA (DRM) display");
109 surface = create_test_surface(display, width, height);
111 g_error("could not create Gst/VA surface");
114 g_print("# Create window with gst_vaapi_window_drm_new()\n");
117 window = gst_vaapi_window_drm_new(display, win_width, win_height);
119 g_error("could not create dummy window");
121 gst_vaapi_window_show(window);
123 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
124 g_error("could not render surface");
127 g_object_unref(window);
130 g_object_unref(surface);
131 g_object_unref(display);
135 display = gst_vaapi_display_x11_new(NULL);
137 g_error("could not create Gst/VA display");
139 surface = create_test_surface(display, width, height);
141 g_error("could not create Gst/VA surface");
144 g_print("# Create window with gst_vaapi_window_x11_new()\n");
147 window = gst_vaapi_window_x11_new(display, win_width, win_height);
149 g_error("could not create window");
151 gst_vaapi_window_show(window);
153 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
154 g_error("could not render surface");
157 g_object_unref(window);
161 g_print("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
164 Display * const dpy = gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
167 unsigned long white_pixel, black_pixel;
169 screen = DefaultScreen(dpy);
170 rootwin = RootWindow(dpy, screen);
171 white_pixel = WhitePixel(dpy, screen);
172 black_pixel = BlackPixel(dpy, screen);
174 win = XCreateSimpleWindow(
177 0, 0, win_width, win_height,
182 g_error("could not create X window");
184 window = gst_vaapi_window_x11_new_with_xid(display, win);
186 g_error("could not create window");
188 gst_vaapi_window_show(window);
190 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
191 g_error("could not render surface");
194 g_object_unref(window);
195 XUnmapWindow(dpy, win);
196 XDestroyWindow(dpy, win);
199 g_object_unref(surface);
200 g_object_unref(display);
204 display = gst_vaapi_display_wayland_new(NULL);
206 g_error("could not create Gst/VA (Wayland) display");
208 surface = create_test_surface(display, width, height);
210 g_error("could not create Gst/VA surface");
213 g_print("# Create window with gst_vaapi_window_wayland_new()\n");
216 window = gst_vaapi_window_wayland_new(display, win_width, win_height);
218 g_error("could not create window");
220 gst_vaapi_window_show(window);
222 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
223 g_error("could not render surface");
226 g_object_unref(window);
229 g_object_unref(surface);
230 g_object_unref(display);