2 * test-windows.c - Test GstVaapiWindow
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6 * Copyright (C) 2012-2013 Intel Corporation
7 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA
25 #include "gst/vaapi/sysdeps.h"
26 #include <gst/vaapi/gstvaapisurface.h>
27 #include <gst/vaapi/gstvaapiimage.h>
29 # include <gst/vaapi/gstvaapidisplay_drm.h>
30 # include <gst/vaapi/gstvaapiwindow_drm.h>
33 # include <gst/vaapi/gstvaapidisplay_x11.h>
34 # include <gst/vaapi/gstvaapiwindow_x11.h>
37 # include <gst/vaapi/gstvaapidisplay_wayland.h>
38 # include <gst/vaapi/gstvaapiwindow_wayland.h>
45 g_print("Press any key to continue...\n");
49 static GstVaapiSurface *
50 create_test_surface(GstVaapiDisplay *display, guint width, guint height)
52 GstVaapiImage *image = NULL;
53 GstVaapiSurface *surface;
56 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
57 static const GstVideoFormat image_formats[] = {
58 GST_VIDEO_FORMAT_NV12,
59 GST_VIDEO_FORMAT_YV12,
60 GST_VIDEO_FORMAT_I420,
61 GST_VIDEO_FORMAT_AYUV,
62 GST_VIDEO_FORMAT_ARGB,
63 GST_VIDEO_FORMAT_BGRA,
64 GST_VIDEO_FORMAT_RGBA,
65 GST_VIDEO_FORMAT_ABGR,
66 GST_VIDEO_FORMAT_UNKNOWN
69 surface = gst_vaapi_surface_new(display, chroma_type, width, height);
71 g_error("could not create Gst/VA surface");
73 for (i = 0; image_formats[i] != GST_VIDEO_FORMAT_UNKNOWN; i++) {
74 const GstVideoFormat format = image_formats[i];
76 image = image_generate(display, format, width, height);
79 if (image_upload(image, surface))
83 g_error("could not create Gst/VA image");
85 if (!gst_vaapi_surface_sync(surface))
86 g_error("could not complete image upload");
88 gst_vaapi_object_unref(image);
93 main(int argc, char *argv[])
95 GstVaapiDisplay *display;
96 GstVaapiWindow *window;
97 GstVaapiSurface *surface;
98 guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
100 static const guint width = 320;
101 static const guint height = 240;
102 static const guint win_width = 640;
103 static const guint win_height = 480;
105 gst_init(&argc, &argv);
108 display = gst_vaapi_display_drm_new(NULL);
110 g_error("could not create Gst/VA (DRM) display");
112 surface = create_test_surface(display, width, height);
114 g_error("could not create Gst/VA surface");
117 g_print("# Create window with gst_vaapi_window_drm_new()\n");
120 window = gst_vaapi_window_drm_new(display, win_width, win_height);
122 g_error("could not create dummy window");
124 gst_vaapi_window_show(window);
126 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
127 g_error("could not render surface");
130 gst_vaapi_window_unref(window);
133 gst_vaapi_object_unref(surface);
134 gst_vaapi_display_unref(display);
138 display = gst_vaapi_display_x11_new(NULL);
140 g_error("could not create Gst/VA display");
142 surface = create_test_surface(display, width, height);
144 g_error("could not create Gst/VA surface");
147 g_print("# Create window with gst_vaapi_window_x11_new()\n");
150 window = gst_vaapi_window_x11_new(display, win_width, win_height);
152 g_error("could not create window");
154 gst_vaapi_window_show(window);
156 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
157 g_error("could not render surface");
160 gst_vaapi_window_unref(window);
164 g_print("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
167 Display * const dpy = gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
170 unsigned long white_pixel, black_pixel;
172 screen = DefaultScreen(dpy);
173 rootwin = RootWindow(dpy, screen);
174 white_pixel = WhitePixel(dpy, screen);
175 black_pixel = BlackPixel(dpy, screen);
177 win = XCreateSimpleWindow(
180 0, 0, win_width, win_height,
185 g_error("could not create X window");
187 window = gst_vaapi_window_x11_new_with_xid(display, win);
189 g_error("could not create window");
191 gst_vaapi_window_show(window);
193 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
194 g_error("could not render surface");
197 gst_vaapi_window_unref(window);
198 XUnmapWindow(dpy, win);
199 XDestroyWindow(dpy, win);
202 gst_vaapi_object_unref(surface);
203 gst_vaapi_display_unref(display);
207 display = gst_vaapi_display_wayland_new(NULL);
209 g_error("could not create Gst/VA (Wayland) display");
211 surface = create_test_surface(display, width, height);
213 g_error("could not create Gst/VA surface");
216 g_print("# Create window with gst_vaapi_window_wayland_new()\n");
219 window = gst_vaapi_window_wayland_new(display, win_width, win_height);
221 g_error("could not create window");
223 gst_vaapi_window_show(window);
225 if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
226 g_error("could not render surface");
229 gst_vaapi_window_unref(window);
232 gst_vaapi_object_unref(surface);
233 gst_vaapi_display_unref(display);