From: gb Date: Tue, 16 Mar 2010 09:12:47 +0000 (+0000) Subject: Move X11 utilties to gstvaapiutils_x11.[ch]. X-Git-Tag: accepted/trunk/20120822.173359~722 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ca21f9e417895b4d7f47f8525d0053a64d573e5;p=profile%2Fivi%2Fgstreamer-vaapi.git Move X11 utilties to gstvaapiutils_x11.[ch]. --- diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index cf3749a..5c4c58f 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -57,11 +57,13 @@ libgstvaapi_@GST_MAJORMINOR@_la_LIBADD = \ libgstvaapi_@GST_MAJORMINOR@_la_SOURCES += \ gstvaapidisplay_x11.c \ + gstvaapiutils_x11.c \ gstvaapiwindow_x11.c \ $(NULL) libgstvaapi_@GST_MAJORMINOR@include_HEADERS += \ gstvaapidisplay_x11.h \ + gstvaapiutils_x11.h \ gstvaapiwindow_x11.h \ $(NULL) diff --git a/gst-libs/gst/vaapi/gstvaapiutils_x11.c b/gst-libs/gst/vaapi/gstvaapiutils_x11.c new file mode 100644 index 0000000..dcc95b5 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapiutils_x11.c @@ -0,0 +1,139 @@ +/* + * gstvaapiutils_x11.c - X11 utilties + * + * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" +#include +#include +#include "gstvaapiutils_x11.h" + +// X error trap +static int x11_error_code = 0; +static int (*old_error_handler)(Display *, XErrorEvent *); + +static int error_handler(Display *dpy, XErrorEvent *error) +{ + x11_error_code = error->error_code; + return 0; +} + +void x11_trap_errors(void) +{ + x11_error_code = 0; + old_error_handler = XSetErrorHandler(error_handler); +} + +int x11_untrap_errors(void) +{ + XSetErrorHandler(old_error_handler); + return x11_error_code; +} + +// X window management +static const int x11_event_mask = (KeyPressMask | + KeyReleaseMask | + ButtonPressMask | + ButtonReleaseMask | + PointerMotionMask | + EnterWindowMask | + ExposureMask | + StructureNotifyMask); + +Window +x11_create_window(Display *display, unsigned int width, unsigned int height) +{ + Window root_window, window; + int screen, depth; + Visual *vis; + XSetWindowAttributes xswa; + unsigned long xswa_mask; + XWindowAttributes wattr; + unsigned long black_pixel, white_pixel; + + screen = DefaultScreen(display); + vis = DefaultVisual(display, screen); + root_window = RootWindow(display, screen); + black_pixel = BlackPixel(display, screen); + white_pixel = WhitePixel(display, screen); + + XGetWindowAttributes(display, root_window, &wattr); + depth = wattr.depth; + if (depth != 15 && depth != 16 && depth != 24 && depth != 32) + depth = 24; + + xswa_mask = CWBorderPixel | CWBackPixel; + xswa.border_pixel = black_pixel; + xswa.background_pixel = white_pixel; + + window = XCreateWindow( + display, + root_window, + 0, 0, width, height, + 0, + depth, + InputOutput, + vis, + xswa_mask, &xswa + ); + if (!window) + return None; + + XSelectInput(display, window, x11_event_mask); + return window; +} + +gboolean +x11_get_geometry( + Display *dpy, + Drawable drawable, + gint *px, + gint *py, + guint *pwidth, + guint *pheight +) +{ + Window rootwin; + int x, y; + unsigned int width, height, border_width, depth; + + x11_trap_errors(); + XGetGeometry( + dpy, + drawable, + &rootwin, + &x, &y, &width, &height, + &border_width, + &depth + ); + if (x11_untrap_errors()) + return FALSE; + + if (px) *px = x; + if (py) *py = y; + if (pwidth) *pwidth = width; + if (pheight) *pheight = height; + return TRUE; +} + +void x11_wait_event(Display *dpy, Window w, int type) +{ + XEvent e; + while (!XCheckTypedWindowEvent(dpy, w, type, &e)) + g_usleep(10); +} diff --git a/gst-libs/gst/vaapi/gstvaapiutils_x11.h b/gst-libs/gst/vaapi/gstvaapiutils_x11.h new file mode 100644 index 0000000..ab06ab3 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapiutils_x11.h @@ -0,0 +1,52 @@ +/* + * gstvaapiutils_x11.h - X11 utilties + * + * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef GST_VAAPI_UTILS_X11_H +#define GST_VAAPI_UTILS_X11_H + +#include "config.h" +#include +#include + +void x11_trap_errors(void) + attribute_hidden; + +int x11_untrap_errors(void) + attribute_hidden; + + +Window +x11_create_window(Display *display, unsigned int width, unsigned int height) + attribute_hidden; + +gboolean +x11_get_geometry( + Display *dpy, + Drawable drawable, + gint *px, + gint *py, + guint *pwidth, + guint *pheight +) attribute_hidden; + +void x11_wait_event(Display *dpy, Window w, int type) + attribute_hidden; + +#endif /* GST_VAAPI_UTILS_X11_H */ diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_x11.c b/gst-libs/gst/vaapi/gstvaapiwindow_x11.c index ad5cc3a..eb648d8 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_x11.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_x11.c @@ -21,6 +21,7 @@ #include "config.h" #include "gstvaapiwindow_x11.h" #include "gstvaapidisplay_x11.h" +#include "gstvaapiutils_x11.h" #define DEBUG 1 #include "vaapi_debug.h" @@ -45,121 +46,6 @@ enum { PROP_XID, }; -// X error trap -static int x11_error_code = 0; -static int (*old_error_handler)(Display *, XErrorEvent *); - -static int error_handler(Display *dpy, XErrorEvent *error) -{ - x11_error_code = error->error_code; - return 0; -} - -static void x11_trap_errors(void) -{ - x11_error_code = 0; - old_error_handler = XSetErrorHandler(error_handler); -} - -static int x11_untrap_errors(void) -{ - XSetErrorHandler(old_error_handler); - return x11_error_code; -} - -// X window management -static const int x11_event_mask = (KeyPressMask | - KeyReleaseMask | - ButtonPressMask | - ButtonReleaseMask | - PointerMotionMask | - EnterWindowMask | - ExposureMask | - StructureNotifyMask); - -static Window -x11_create_window(Display *display, unsigned int width, unsigned int height) -{ - Window root_window, window; - int screen, depth; - Visual *vis; - XSetWindowAttributes xswa; - unsigned long xswa_mask; - XWindowAttributes wattr; - unsigned long black_pixel, white_pixel; - - screen = DefaultScreen(display); - vis = DefaultVisual(display, screen); - root_window = RootWindow(display, screen); - black_pixel = BlackPixel(display, screen); - white_pixel = WhitePixel(display, screen); - - XGetWindowAttributes(display, root_window, &wattr); - depth = wattr.depth; - if (depth != 15 && depth != 16 && depth != 24 && depth != 32) - depth = 24; - - xswa_mask = CWBorderPixel | CWBackPixel; - xswa.border_pixel = black_pixel; - xswa.background_pixel = white_pixel; - - window = XCreateWindow( - display, - root_window, - 0, 0, width, height, - 0, - depth, - InputOutput, - vis, - xswa_mask, &xswa - ); - if (!window) - return None; - - XSelectInput(display, window, x11_event_mask); - return window; -} - -static gboolean -x11_get_geometry( - Display *dpy, - Drawable drawable, - gint *px, - gint *py, - guint *pwidth, - guint *pheight -) -{ - Window rootwin; - int x, y; - unsigned int width, height, border_width, depth; - - x11_trap_errors(); - XGetGeometry( - dpy, - drawable, - &rootwin, - &x, &y, &width, &height, - &border_width, - &depth - ); - if (x11_untrap_errors()) - return FALSE; - - if (px) *px = x; - if (py) *py = y; - if (pwidth) *pwidth = width; - if (pheight) *pheight = height; - return TRUE; -} - -static void x11_wait_event(Display *dpy, Window w, int type) -{ - XEvent e; - while (!XCheckTypedWindowEvent(dpy, w, type, &e)) - g_usleep(10); -} - static gboolean gst_vaapi_window_x11_show(GstVaapiWindow *window) {