2008-11-05 01:06:33 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2012-11-14 09:36:16 +00:00
|
|
|
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
|
2008-11-05 01:06:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-11-05 01:06:33 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-05 09:10:19 +00:00
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
#include <gst/gst.h>
|
2008-11-29 21:16:44 +00:00
|
|
|
#include <locale.h>
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
#include "gstglwindow_x11.h"
|
2013-11-27 06:52:46 +00:00
|
|
|
#include "gstgldisplay_x11.h"
|
2017-08-14 08:33:38 +00:00
|
|
|
|
|
|
|
#include "../gstglwindow_private.h"
|
|
|
|
|
2014-07-24 09:25:36 +00:00
|
|
|
/* for XkbKeycodeToKeysym */
|
|
|
|
#include <X11/XKBlib.h>
|
2012-11-13 11:12:20 +00:00
|
|
|
|
2012-12-08 22:30:48 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_debug
|
2008-11-25 00:01:01 +00:00
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
G_GNUC_INTERNAL
|
|
|
|
gboolean gst_gl_window_x11_handle_event (GstGLWindowX11 * window_x11,
|
2016-06-30 14:07:23 +00:00
|
|
|
xcb_generic_event_t * event);
|
|
|
|
|
2013-06-03 08:15:45 +00:00
|
|
|
/* X error trap */
|
|
|
|
static int TrappedErrorCode = 0;
|
|
|
|
static int (*old_error_handler) (Display *, XErrorEvent *);
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_DISPLAY
|
|
|
|
};
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
struct _GstGLWindowX11Private
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
gboolean activate;
|
|
|
|
gboolean activate_result;
|
2015-01-23 03:11:48 +00:00
|
|
|
|
|
|
|
gint preferred_width;
|
|
|
|
gint preferred_height;
|
2015-06-11 14:30:58 +00:00
|
|
|
|
|
|
|
gboolean handle_events;
|
2017-07-14 15:24:52 +00:00
|
|
|
|
|
|
|
GstVideoRectangle render_rect;
|
2008-11-05 01:06:33 +00:00
|
|
|
};
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
#define gst_gl_window_x11_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstGLWindowX11, gst_gl_window_x11,
|
|
|
|
GST_TYPE_GL_WINDOW);
|
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
static guintptr gst_gl_window_x11_get_display (GstGLWindow * window);
|
2012-11-13 11:12:20 +00:00
|
|
|
guintptr gst_gl_window_x11_get_gl_context (GstGLWindow * window);
|
|
|
|
gboolean gst_gl_window_x11_activate (GstGLWindow * window, gboolean activate);
|
2017-08-11 17:38:41 +00:00
|
|
|
static void gst_gl_window_x11_set_window_handle (GstGLWindow * window,
|
2012-11-13 11:12:20 +00:00
|
|
|
guintptr handle);
|
2017-07-14 15:24:52 +00:00
|
|
|
static gboolean gst_gl_window_x11_set_render_rectangle (GstGLWindow * window,
|
|
|
|
int x, int y, int width, int height);
|
2017-08-11 17:38:41 +00:00
|
|
|
static guintptr gst_gl_window_x11_get_window_handle (GstGLWindow * window);
|
2015-01-23 03:11:48 +00:00
|
|
|
static void gst_gl_window_x11_set_preferred_size (GstGLWindow * window,
|
|
|
|
gint width, gint height);
|
2017-08-11 17:38:41 +00:00
|
|
|
static void gst_gl_window_x11_show (GstGLWindow * window);
|
|
|
|
static void gst_gl_window_x11_draw (GstGLWindow * window);
|
2013-02-12 12:48:36 +00:00
|
|
|
gboolean gst_gl_window_x11_create_context (GstGLWindow * window,
|
|
|
|
GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
|
2017-08-11 17:38:41 +00:00
|
|
|
static gboolean gst_gl_window_x11_open (GstGLWindow * window, GError ** error);
|
|
|
|
static void gst_gl_window_x11_close (GstGLWindow * window);
|
|
|
|
static void gst_gl_window_x11_handle_events (GstGLWindow * window,
|
2014-10-29 11:24:16 +00:00
|
|
|
gboolean handle_events);
|
2012-11-13 11:12:20 +00:00
|
|
|
|
2013-07-16 11:28:19 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_x11_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
static void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_class_init (GstGLWindowX11Class * klass)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
|
|
|
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-07-16 11:28:19 +00:00
|
|
|
obj_class->finalize = gst_gl_window_x11_finalize;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
window_class->get_display = GST_DEBUG_FUNCPTR (gst_gl_window_x11_get_display);
|
2012-11-13 11:12:20 +00:00
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_set_window_handle);
|
2017-07-14 15:24:52 +00:00
|
|
|
window_class->set_render_rectangle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_set_render_rectangle);
|
2013-08-15 07:09:04 +00:00
|
|
|
window_class->get_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_get_window_handle);
|
2012-11-13 11:12:20 +00:00
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_x11_draw);
|
2013-06-13 06:04:40 +00:00
|
|
|
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_x11_open);
|
|
|
|
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_x11_close);
|
2014-10-29 11:24:16 +00:00
|
|
|
window_class->handle_events =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_handle_events);
|
2015-01-23 03:11:48 +00:00
|
|
|
window_class->set_preferred_size =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_set_preferred_size);
|
2015-01-29 11:25:00 +00:00
|
|
|
window_class->show = GST_DEBUG_FUNCPTR (gst_gl_window_x11_show);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_init (GstGLWindowX11 * window)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2018-06-23 19:33:16 +00:00
|
|
|
window->priv = gst_gl_window_x11_get_instance_private (window);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *
|
2013-11-27 06:52:46 +00:00
|
|
|
gst_gl_window_x11_new (GstGLDisplay * display)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2017-05-15 17:31:31 +00:00
|
|
|
GstGLWindowX11 *window;
|
|
|
|
|
2015-07-24 07:00:27 +00:00
|
|
|
if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_X11)
|
|
|
|
== GST_GL_DISPLAY_TYPE_NONE) {
|
2013-11-27 06:52:46 +00:00
|
|
|
GST_INFO ("Wrong display type %u for this window type %u", display->type,
|
|
|
|
GST_GL_DISPLAY_TYPE_X11);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-15 17:31:31 +00:00
|
|
|
window = g_object_new (GST_TYPE_GL_WINDOW_X11, NULL);
|
|
|
|
gst_object_ref_sink (window);
|
|
|
|
|
|
|
|
return window;
|
2012-11-13 11:12:20 +00:00
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
static gboolean
|
2013-06-13 06:04:40 +00:00
|
|
|
gst_gl_window_x11_open (GstGLWindow * window, GError ** error)
|
2012-11-13 11:12:20 +00:00
|
|
|
{
|
2013-02-12 12:48:36 +00:00
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
2013-11-27 06:52:46 +00:00
|
|
|
GstGLDisplayX11 *display_x11 = (GstGLDisplayX11 *) window->display;
|
2012-11-13 11:12:20 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
window_x11->device = display_x11->display;
|
|
|
|
// window_x11->device = XOpenDisplay (display_x11->name);
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window_x11->device == NULL) {
|
2012-12-08 22:30:48 +00:00
|
|
|
g_set_error (error, GST_GL_WINDOW_ERROR,
|
|
|
|
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
|
|
|
|
"Failed to connect to X display server");
|
2012-04-13 13:08:00 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("gl device id: %ld", (gulong) window_x11->device);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->screen = DefaultScreenOfDisplay (window_x11->device);
|
|
|
|
window_x11->screen_num = DefaultScreen (window_x11->device);
|
|
|
|
window_x11->visual =
|
|
|
|
DefaultVisual (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->root = DefaultRootWindow (window_x11->device);
|
|
|
|
window_x11->white = XWhitePixel (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->black = XBlackPixel (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->depth = DefaultDepthOfScreen (window_x11->screen);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("gl root id: %lud", (gulong) window_x11->root);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->device_width =
|
|
|
|
DisplayWidth (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->device_height =
|
|
|
|
DisplayHeight (window_x11->device, window_x11->screen_num);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
window_x11->allow_extra_expose_events = TRUE;
|
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
return GST_GL_WINDOW_CLASS (parent_class)->open (window, error);
|
2013-08-15 07:09:04 +00:00
|
|
|
|
|
|
|
failure:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_create_window (GstGLWindowX11 * window_x11)
|
|
|
|
{
|
|
|
|
XSetWindowAttributes win_attr;
|
|
|
|
XTextProperty text_property;
|
|
|
|
XWMHints wm_hints;
|
|
|
|
unsigned long mask;
|
|
|
|
const gchar *title = "OpenGL renderer";
|
2013-07-02 12:06:03 +00:00
|
|
|
Atom wm_atoms[1];
|
2013-07-11 19:15:41 +00:00
|
|
|
gint x = 0, y = 0, width = 1, height = 1;
|
2008-11-18 23:07:22 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window_x11->visual_info->visual != window_x11->visual)
|
|
|
|
GST_LOG ("selected visual is different from the default");
|
|
|
|
|
2013-01-08 06:36:18 +00:00
|
|
|
GST_LOG ("visual XID:%d, screen:%d, visualid:%d, depth:%d, class:%d, "
|
|
|
|
"red_mask:%ld, green_mask:%ld, blue_mask:%ld bpp:%d",
|
|
|
|
(gint) XVisualIDFromVisual (window_x11->visual_info->visual),
|
|
|
|
window_x11->visual_info->screen, (gint) window_x11->visual_info->visualid,
|
|
|
|
window_x11->visual_info->depth, window_x11->visual_info->class,
|
|
|
|
window_x11->visual_info->red_mask, window_x11->visual_info->green_mask,
|
|
|
|
window_x11->visual_info->blue_mask,
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->visual_info->bits_per_rgb);
|
2008-11-18 23:07:22 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
win_attr.event_mask =
|
2014-10-29 11:24:16 +00:00
|
|
|
StructureNotifyMask | ExposureMask | VisibilityChangeMask;
|
2008-11-21 23:51:30 +00:00
|
|
|
win_attr.do_not_propagate_mask = NoEventMask;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
win_attr.background_pixmap = None;
|
|
|
|
win_attr.background_pixel = 0;
|
|
|
|
win_attr.border_pixel = 0;
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
win_attr.colormap =
|
2012-11-13 11:12:20 +00:00
|
|
|
XCreateColormap (window_x11->device, window_x11->root,
|
|
|
|
window_x11->visual_info->visual, AllocNone);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->internal_win_id =
|
2013-07-11 19:15:41 +00:00
|
|
|
XCreateWindow (window_x11->device,
|
|
|
|
window_x11->parent_win ? window_x11->parent_win : window_x11->root,
|
|
|
|
x, y, width, height, 0,
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->visual_info->depth, InputOutput,
|
|
|
|
window_x11->visual_info->visual, mask, &win_attr);
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2015-06-11 14:30:58 +00:00
|
|
|
gst_gl_window_x11_handle_events (GST_GL_WINDOW (window_x11),
|
|
|
|
window_x11->priv->handle_events);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSync (window_x11->device, FALSE);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2013-11-27 06:52:46 +00:00
|
|
|
XSetWindowBackgroundPixmap (window_x11->device,
|
|
|
|
window_x11->internal_win_id, None);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("gl window id: %lud", (gulong) window_x11->internal_win_id);
|
|
|
|
GST_LOG ("gl window props: x:%d y:%d", x, y);
|
2008-12-07 02:25:59 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
wm_atoms[0] = XInternAtom (window_x11->device, "WM_DELETE_WINDOW", True);
|
2008-11-21 00:31:19 +00:00
|
|
|
if (wm_atoms[0] == None)
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_DEBUG ("Cannot create WM_DELETE_WINDOW");
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2013-11-27 06:52:46 +00:00
|
|
|
XSetWMProtocols (window_x11->device, window_x11->internal_win_id,
|
|
|
|
wm_atoms, 1);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
wm_hints.flags = StateHint;
|
|
|
|
wm_hints.initial_state = NormalState;
|
2008-11-15 22:32:04 +00:00
|
|
|
wm_hints.input = False;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
XStringListToTextProperty ((char **) &title, 1, &text_property);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSetWMProperties (window_x11->device, window_x11->internal_win_id,
|
|
|
|
&text_property, &text_property, 0, 0, NULL, &wm_hints, NULL);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
XFree (text_property.value);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
return TRUE;
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
static void
|
2013-06-13 06:04:40 +00:00
|
|
|
gst_gl_window_x11_close (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
|
|
|
|
if (window_x11->device) {
|
2016-06-30 14:07:23 +00:00
|
|
|
if (window_x11->internal_win_id) {
|
2013-06-13 06:04:40 +00:00
|
|
|
XUnmapWindow (window_x11->device, window_x11->internal_win_id);
|
|
|
|
|
|
|
|
XDestroyWindow (window_x11->device, window_x11->internal_win_id);
|
|
|
|
}
|
2016-06-30 14:07:23 +00:00
|
|
|
XFree (window_x11->visual_info);
|
2013-06-13 06:04:40 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("display receiver closed");
|
|
|
|
}
|
|
|
|
|
2013-07-11 18:58:36 +00:00
|
|
|
window_x11->running = FALSE;
|
2015-05-27 13:10:16 +00:00
|
|
|
|
|
|
|
GST_GL_WINDOW_CLASS (parent_class)->close (window);
|
2014-04-24 16:33:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 04:31:18 +00:00
|
|
|
/* called by the gl thread */
|
2017-08-11 17:38:41 +00:00
|
|
|
static void
|
2015-03-06 04:31:18 +00:00
|
|
|
gst_gl_window_x11_set_window_handle (GstGLWindow * window, guintptr id)
|
2014-04-24 16:33:03 +00:00
|
|
|
{
|
2015-03-06 04:31:18 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
2017-07-14 15:24:52 +00:00
|
|
|
gint x, y, width, height;
|
2014-04-24 16:33:03 +00:00
|
|
|
|
2015-03-06 04:31:18 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
|
|
|
|
window_x11->parent_win = (Window) id;
|
|
|
|
|
2017-07-14 15:24:52 +00:00
|
|
|
if (window_x11->priv->render_rect.w > 0 &&
|
|
|
|
window_x11->priv->render_rect.h > 0) {
|
|
|
|
x = window_x11->priv->render_rect.x;
|
|
|
|
y = window_x11->priv->render_rect.y;
|
|
|
|
width = window_x11->priv->render_rect.w;
|
|
|
|
height = window_x11->priv->render_rect.h;
|
2016-06-30 14:07:23 +00:00
|
|
|
} else {
|
2017-07-14 15:24:52 +00:00
|
|
|
x = y = 0;
|
|
|
|
if (window_x11->parent_win) {
|
|
|
|
XWindowAttributes attr;
|
|
|
|
|
|
|
|
XGetWindowAttributes (window_x11->device, window_x11->parent_win, &attr);
|
|
|
|
width = attr.width;
|
|
|
|
height = attr.height;
|
|
|
|
} else {
|
|
|
|
width = window_x11->priv->preferred_width;
|
|
|
|
height = window_x11->priv->preferred_height;
|
|
|
|
}
|
2016-06-30 14:07:23 +00:00
|
|
|
}
|
2014-04-24 16:33:03 +00:00
|
|
|
|
|
|
|
XResizeWindow (window_x11->device, window_x11->internal_win_id,
|
2016-06-30 14:07:23 +00:00
|
|
|
width, height);
|
2014-04-24 16:33:03 +00:00
|
|
|
|
|
|
|
XReparentWindow (window_x11->device, window_x11->internal_win_id,
|
2017-07-14 15:24:52 +00:00
|
|
|
window_x11->parent_win, x, y);
|
2013-07-11 18:58:36 +00:00
|
|
|
|
2014-04-24 16:33:03 +00:00
|
|
|
XSync (window_x11->device, FALSE);
|
2013-06-13 06:04:40 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 15:24:52 +00:00
|
|
|
struct SetRenderRectangle
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11;
|
|
|
|
GstVideoRectangle rect;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_free_set_render_rectangle (struct SetRenderRectangle *render)
|
|
|
|
{
|
|
|
|
if (render) {
|
|
|
|
if (render->window_x11)
|
|
|
|
gst_object_unref (render->window_x11);
|
|
|
|
g_free (render);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_set_render_rectangle (gpointer data)
|
|
|
|
{
|
|
|
|
struct SetRenderRectangle *render = data;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (render->window_x11, "setting render rectangle %i,%i+%ix%i",
|
|
|
|
render->rect.x, render->rect.y, render->rect.w, render->rect.h);
|
|
|
|
|
|
|
|
if (render->window_x11->internal_win_id)
|
|
|
|
XMoveResizeWindow (render->window_x11->device,
|
|
|
|
render->window_x11->internal_win_id, render->rect.x, render->rect.y,
|
|
|
|
render->rect.w, render->rect.h);
|
|
|
|
|
|
|
|
if (render->window_x11->device)
|
|
|
|
XSync (render->window_x11->device, FALSE);
|
|
|
|
|
|
|
|
render->window_x11->priv->render_rect = render->rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_window_x11_set_render_rectangle (GstGLWindow * window,
|
|
|
|
int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
struct SetRenderRectangle *render;
|
|
|
|
|
|
|
|
render = g_new0 (struct SetRenderRectangle, 1);
|
|
|
|
render->window_x11 = gst_object_ref (window_x11);
|
|
|
|
render->rect.x = x;
|
|
|
|
render->rect.y = y;
|
|
|
|
render->rect.w = width;
|
|
|
|
render->rect.h = height;
|
|
|
|
|
|
|
|
gst_gl_window_send_message_async (window,
|
|
|
|
(GstGLWindowCB) _set_render_rectangle, render,
|
|
|
|
(GDestroyNotify) _free_set_render_rectangle);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
static guintptr
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_window_x11_get_window_handle (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11;
|
|
|
|
|
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
|
|
|
|
return window_x11->internal_win_id;
|
|
|
|
}
|
|
|
|
|
2015-01-23 03:11:48 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_x11_set_preferred_size (GstGLWindow * window, gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
|
|
|
|
window_x11->priv->preferred_width = width;
|
|
|
|
window_x11->priv->preferred_height = height;
|
|
|
|
}
|
|
|
|
|
2015-01-29 11:25:00 +00:00
|
|
|
static void
|
|
|
|
_show_window (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
guint width = window_x11->priv->preferred_width;
|
|
|
|
guint height = window_x11->priv->preferred_height;
|
|
|
|
|
|
|
|
if (!window_x11->visible) {
|
|
|
|
if (!window_x11->parent_win) {
|
|
|
|
XResizeWindow (window_x11->device, window_x11->internal_win_id,
|
2016-06-30 14:07:23 +00:00
|
|
|
width, height);
|
2018-12-19 02:59:09 +00:00
|
|
|
|
|
|
|
gst_gl_window_resize (window, width, height);
|
2015-01-29 11:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XMapWindow (window_x11->device, window_x11->internal_win_id);
|
2016-06-30 14:07:23 +00:00
|
|
|
XSync (window_x11->device, FALSE);
|
2015-01-29 11:25:00 +00:00
|
|
|
window_x11->visible = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
static void
|
2015-01-29 11:25:00 +00:00
|
|
|
gst_gl_window_x11_show (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
gst_gl_window_send_message (window, (GstGLWindowCB) _show_window, window);
|
|
|
|
}
|
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
static void
|
|
|
|
_context_draw (GstGLContext * context, GstGLWindow * window)
|
|
|
|
{
|
|
|
|
window->draw (window->draw_data);
|
2017-05-21 10:03:01 +00:00
|
|
|
gst_gl_context_swap_buffers (context);
|
2016-06-30 14:07:23 +00:00
|
|
|
|
|
|
|
gst_object_unref (context);
|
|
|
|
}
|
|
|
|
|
2014-04-24 16:28:34 +00:00
|
|
|
static void
|
|
|
|
draw_cb (gpointer data)
|
|
|
|
{
|
2015-01-23 03:11:48 +00:00
|
|
|
GstGLWindowX11 *window_x11 = data;
|
2015-09-26 09:19:50 +00:00
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_x11);
|
2016-10-26 05:30:43 +00:00
|
|
|
guint width, height;
|
|
|
|
XWindowAttributes attr;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
if (window_x11->internal_win_id) {
|
2017-07-14 15:24:52 +00:00
|
|
|
gboolean need_resize = FALSE;
|
|
|
|
|
2014-04-24 16:28:34 +00:00
|
|
|
XGetWindowAttributes (window_x11->device, window_x11->internal_win_id,
|
2012-11-13 11:12:20 +00:00
|
|
|
&attr);
|
2016-06-30 14:07:23 +00:00
|
|
|
GST_TRACE_OBJECT (window, "window size %ux%u", attr.width, attr.height);
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2017-07-14 15:24:52 +00:00
|
|
|
if (window_x11->parent_win &&
|
2020-06-11 22:21:56 +00:00
|
|
|
(window_x11->priv->render_rect.w <= 0 ||
|
|
|
|
window_x11->priv->render_rect.h <= 0)) {
|
2012-11-13 11:12:20 +00:00
|
|
|
XWindowAttributes attr_parent;
|
2014-04-24 16:28:34 +00:00
|
|
|
XGetWindowAttributes (window_x11->device, window_x11->parent_win,
|
2012-11-13 11:12:20 +00:00
|
|
|
&attr_parent);
|
2016-06-30 14:07:23 +00:00
|
|
|
GST_TRACE_OBJECT (window, "parent window size %ux%u", attr_parent.width,
|
|
|
|
attr_parent.height);
|
2008-11-21 23:51:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (attr.width != attr_parent.width || attr.height != attr_parent.height) {
|
2014-04-24 16:28:34 +00:00
|
|
|
XMoveResizeWindow (window_x11->device, window_x11->internal_win_id,
|
2012-11-13 11:12:20 +00:00
|
|
|
0, 0, attr_parent.width, attr_parent.height);
|
2014-04-24 16:28:34 +00:00
|
|
|
XSync (window_x11->device, FALSE);
|
2008-12-07 02:25:59 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
attr.width = attr_parent.width;
|
|
|
|
attr.height = attr_parent.height;
|
2008-11-21 23:51:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("parent resize: %d, %d",
|
|
|
|
attr_parent.width, attr_parent.height);
|
2017-07-14 15:24:52 +00:00
|
|
|
need_resize = TRUE;
|
2012-11-13 11:12:20 +00:00
|
|
|
}
|
2008-11-13 00:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 02:55:01 +00:00
|
|
|
gst_gl_window_get_surface_dimensions (window, &width, &height);
|
2017-07-14 15:24:52 +00:00
|
|
|
if (attr.width != width || attr.height != height)
|
|
|
|
need_resize = TRUE;
|
|
|
|
|
|
|
|
if (need_resize)
|
2016-07-27 02:55:01 +00:00
|
|
|
gst_gl_window_queue_resize (window);
|
2015-09-26 09:19:50 +00:00
|
|
|
|
2016-07-27 02:55:01 +00:00
|
|
|
if (window_x11->allow_extra_expose_events) {
|
|
|
|
if (window->queue_resize)
|
2015-09-26 09:19:50 +00:00
|
|
|
gst_gl_window_resize (window, width, height);
|
|
|
|
|
|
|
|
if (window->draw) {
|
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
_context_draw (context, window);
|
2015-09-26 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-13 00:23:51 +00:00
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 16:28:34 +00:00
|
|
|
/* Not called by the gl thread */
|
2017-08-11 17:38:41 +00:00
|
|
|
static void
|
2015-01-23 03:11:48 +00:00
|
|
|
gst_gl_window_x11_draw (GstGLWindow * window)
|
2014-04-24 16:28:34 +00:00
|
|
|
{
|
2015-01-23 03:11:48 +00:00
|
|
|
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, window);
|
2014-04-24 16:28:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
static void
|
2014-10-29 11:24:16 +00:00
|
|
|
gst_gl_window_x11_handle_events (GstGLWindow * window, gboolean handle_events)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11;
|
|
|
|
|
|
|
|
g_return_if_fail (window != NULL);
|
|
|
|
|
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
|
2015-06-11 14:30:58 +00:00
|
|
|
window_x11->priv->handle_events = handle_events;
|
|
|
|
|
|
|
|
if (window_x11->internal_win_id) {
|
|
|
|
if (handle_events) {
|
|
|
|
XSelectInput (window_x11->device, window_x11->internal_win_id,
|
|
|
|
StructureNotifyMask | ExposureMask | VisibilityChangeMask |
|
2016-01-14 05:57:40 +00:00
|
|
|
PointerMotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
|
|
|
ButtonReleaseMask);
|
2015-06-11 14:30:58 +00:00
|
|
|
} else {
|
|
|
|
XSelectInput (window_x11->device, window_x11->internal_win_id,
|
|
|
|
StructureNotifyMask | ExposureMask | VisibilityChangeMask);
|
|
|
|
}
|
2014-10-29 11:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 15:29:12 +00:00
|
|
|
gboolean
|
2016-06-30 14:07:23 +00:00
|
|
|
gst_gl_window_x11_handle_event (GstGLWindowX11 * window_x11,
|
|
|
|
xcb_generic_event_t * event)
|
2013-07-02 12:06:03 +00:00
|
|
|
{
|
2016-06-30 14:07:23 +00:00
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_x11);
|
|
|
|
GstGLDisplayX11 *display_x11 = GST_GL_DISPLAY_X11 (window->display);
|
|
|
|
xcb_connection_t *connection = display_x11->xcb_connection;
|
|
|
|
uint8_t event_code = event->response_type & 0x7f;
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
switch (event_code) {
|
|
|
|
case XCB_CLIENT_MESSAGE:{
|
|
|
|
xcb_client_message_event_t *client_event;
|
|
|
|
xcb_intern_atom_cookie_t cookie;
|
|
|
|
xcb_intern_atom_reply_t *reply;
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
client_event = (xcb_client_message_event_t *) event;
|
|
|
|
cookie = xcb_intern_atom (connection, 0, 16, "WM_DELETE_WINDOW");
|
|
|
|
reply = xcb_intern_atom_reply (connection, cookie, 0);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
if (client_event->data.data32[0] == reply->atom) {
|
|
|
|
GST_INFO_OBJECT (window_x11, "Close requested");
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
if (window->close)
|
|
|
|
window->close (window->close_data);
|
2013-08-16 15:29:12 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
gst_gl_display_remove_window (GST_GL_DISPLAY (display_x11),
|
|
|
|
GST_GL_WINDOW (window_x11));
|
2008-11-15 17:51:44 +00:00
|
|
|
}
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
g_free (reply);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XCB_CONFIGURE_NOTIFY:{
|
|
|
|
xcb_configure_notify_event_t *configure_event;
|
2008-11-15 17:51:44 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
configure_event = (xcb_configure_notify_event_t *) event;
|
2008-11-15 17:51:44 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
gst_gl_window_resize (window, configure_event->width,
|
|
|
|
configure_event->height);
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
gst_gl_window_draw (window);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XCB_EXPOSE:{
|
|
|
|
xcb_expose_event_t *expose_event = (xcb_expose_event_t *) event;
|
|
|
|
/* non-zero means that other Expose follows
|
|
|
|
* so just wait for the last one
|
|
|
|
* in theory we should not receive non-zero because
|
|
|
|
* we have no sub areas here but just in case */
|
|
|
|
if (expose_event->count != 0)
|
2014-07-24 09:25:36 +00:00
|
|
|
break;
|
2014-09-09 10:01:47 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
gst_gl_window_draw (window);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XCB_KEY_PRESS:
|
|
|
|
case XCB_KEY_RELEASE:{
|
|
|
|
xcb_key_press_event_t *kp = (xcb_key_press_event_t *) event;
|
|
|
|
const gchar *event_type_str;
|
|
|
|
gchar *key_str;
|
|
|
|
KeySym keysym;
|
|
|
|
|
|
|
|
keysym = XkbKeycodeToKeysym (window_x11->device, kp->detail, 0, 0);
|
|
|
|
key_str = XKeysymToString (keysym);
|
|
|
|
|
|
|
|
if (event_code == XCB_KEY_PRESS)
|
|
|
|
event_type_str = "key-press";
|
|
|
|
else
|
|
|
|
event_type_str = "key-release";
|
|
|
|
|
|
|
|
gst_gl_window_send_key_event (window, event_type_str, key_str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XCB_BUTTON_PRESS:
|
|
|
|
case XCB_BUTTON_RELEASE:{
|
|
|
|
xcb_button_press_event_t *bp = (xcb_button_press_event_t *) event;
|
|
|
|
const gchar *event_type_str;
|
|
|
|
|
|
|
|
if (event_code == XCB_BUTTON_PRESS)
|
|
|
|
event_type_str = "mouse-button-press";
|
|
|
|
else
|
|
|
|
event_type_str = "mouse-button-release";
|
|
|
|
|
|
|
|
gst_gl_window_send_mouse_event (window, event_type_str, bp->detail,
|
|
|
|
(double) bp->event_x, (double) bp->event_y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XCB_MOTION_NOTIFY:{
|
|
|
|
xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *) event;
|
2015-12-21 10:27:09 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
gst_gl_window_send_mouse_event (window, "mouse-move", 0,
|
|
|
|
(double) motion->event_x, (double) motion->event_y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
GST_TRACE ("unhandled XCB event: %u", event_code);
|
|
|
|
break;
|
|
|
|
}
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2016-06-30 14:07:23 +00:00
|
|
|
return TRUE;
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 08:15:45 +00:00
|
|
|
static int
|
|
|
|
error_handler (Display * xdpy, XErrorEvent * error)
|
|
|
|
{
|
|
|
|
TrappedErrorCode = error->error_code;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_window_x11_trap_x_errors:
|
|
|
|
*
|
|
|
|
* Traps every X error until gst_gl_window_x11_untrap_x_errors() is called.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_window_x11_trap_x_errors (void)
|
|
|
|
{
|
|
|
|
TrappedErrorCode = 0;
|
|
|
|
old_error_handler = XSetErrorHandler (error_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_window_x11_untrap_x_errors:
|
|
|
|
*
|
|
|
|
* Removes the X error trap and returns the current status.
|
|
|
|
*
|
|
|
|
* Return value: the trapped error code, or 0 for success
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gst_gl_window_x11_untrap_x_errors (void)
|
|
|
|
{
|
|
|
|
XSetErrorHandler (old_error_handler);
|
|
|
|
|
|
|
|
return TrappedErrorCode;
|
|
|
|
}
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2017-08-11 17:38:41 +00:00
|
|
|
static guintptr
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_window_x11_get_display (GstGLWindow * window)
|
|
|
|
{
|
2013-11-27 06:52:46 +00:00
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
2013-08-15 07:09:04 +00:00
|
|
|
|
|
|
|
return (guintptr) window_x11->device;
|
|
|
|
}
|