mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-10 03:19:40 +00:00
Allow derived classes to specify custom Visual and Colormap.
This commit is contained in:
parent
86954a32c5
commit
b36a2142e4
4 changed files with 55 additions and 25 deletions
|
@ -57,36 +57,38 @@ static const int x11_event_mask = (KeyPressMask |
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* x11_create_window:
|
* x11_create_window:
|
||||||
* @display: an X11 #Display
|
* @dpy: an X11 #Display
|
||||||
* @width: the requested width, in pixels
|
* @w: the requested width, in pixels
|
||||||
* @height: the requested height, in pixels
|
* @h: the requested height, in pixels
|
||||||
* @vis: the request visual
|
* @vis: the request visual
|
||||||
|
* @cmap: the request colormap
|
||||||
*
|
*
|
||||||
* Creates a border-less window with the specified dimensions. If @vis
|
* Creates a border-less window with the specified dimensions. If @vis
|
||||||
* is %NULL, the default visual for @display will be used. The default
|
* is %NULL, the default visual for @display will be used. If @cmap is
|
||||||
* background color is black.
|
* %None, no specific colormap will be bound to the window. Also note
|
||||||
|
* the default background color is black.
|
||||||
*
|
*
|
||||||
* Return value: the newly created X #Window.
|
* Return value: the newly created X #Window.
|
||||||
*/
|
*/
|
||||||
Window
|
Window
|
||||||
x11_create_window(Display *display, guint width, guint height, Visual *vis)
|
x11_create_window(Display *dpy, guint w, guint h, Visual *vis, Colormap cmap)
|
||||||
{
|
{
|
||||||
Window root_window, window;
|
Window rootwin, win;
|
||||||
int screen, depth;
|
int screen, depth;
|
||||||
XSetWindowAttributes xswa;
|
XSetWindowAttributes xswa;
|
||||||
unsigned long xswa_mask;
|
unsigned long xswa_mask;
|
||||||
XWindowAttributes wattr;
|
XWindowAttributes wattr;
|
||||||
unsigned long black_pixel, white_pixel;
|
unsigned long black_pixel, white_pixel;
|
||||||
|
|
||||||
screen = DefaultScreen(display);
|
screen = DefaultScreen(dpy);
|
||||||
root_window = RootWindow(display, screen);
|
rootwin = RootWindow(dpy, screen);
|
||||||
black_pixel = BlackPixel(display, screen);
|
black_pixel = BlackPixel(dpy, screen);
|
||||||
white_pixel = WhitePixel(display, screen);
|
white_pixel = WhitePixel(dpy, screen);
|
||||||
|
|
||||||
if (!vis)
|
if (!vis)
|
||||||
vis = DefaultVisual(display, screen);
|
vis = DefaultVisual(dpy, screen);
|
||||||
|
|
||||||
XGetWindowAttributes(display, root_window, &wattr);
|
XGetWindowAttributes(dpy, rootwin, &wattr);
|
||||||
depth = wattr.depth;
|
depth = wattr.depth;
|
||||||
if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
|
if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
|
||||||
depth = 24;
|
depth = 24;
|
||||||
|
@ -95,21 +97,26 @@ x11_create_window(Display *display, guint width, guint height, Visual *vis)
|
||||||
xswa.border_pixel = black_pixel;
|
xswa.border_pixel = black_pixel;
|
||||||
xswa.background_pixel = black_pixel;
|
xswa.background_pixel = black_pixel;
|
||||||
|
|
||||||
window = XCreateWindow(
|
if (cmap) {
|
||||||
display,
|
xswa_mask |= CWColormap;
|
||||||
root_window,
|
xswa.colormap = cmap;
|
||||||
0, 0, width, height,
|
}
|
||||||
|
|
||||||
|
win = XCreateWindow(
|
||||||
|
dpy,
|
||||||
|
rootwin,
|
||||||
|
0, 0, w, h,
|
||||||
0,
|
0,
|
||||||
depth,
|
depth,
|
||||||
InputOutput,
|
InputOutput,
|
||||||
vis,
|
vis,
|
||||||
xswa_mask, &xswa
|
xswa_mask, &xswa
|
||||||
);
|
);
|
||||||
if (!window)
|
if (!win)
|
||||||
return None;
|
return None;
|
||||||
|
|
||||||
XSelectInput(display, window, x11_event_mask);
|
XSelectInput(dpy, win, x11_event_mask);
|
||||||
return window;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
|
@ -32,7 +32,7 @@ int x11_untrap_errors(void)
|
||||||
attribute_hidden;
|
attribute_hidden;
|
||||||
|
|
||||||
Window
|
Window
|
||||||
x11_create_window(Display *display, guint width, guint height, Visual *vis)
|
x11_create_window(Display *dpy, guint w, guint h, Visual *vis, Colormap cmap)
|
||||||
attribute_hidden;
|
attribute_hidden;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
|
@ -218,6 +218,9 @@ gst_vaapi_window_x11_create(GstVaapiWindow *window, guint *width, guint *height)
|
||||||
GstVaapiWindowX11Private * const priv = GST_VAAPI_WINDOW_X11(window)->priv;
|
GstVaapiWindowX11Private * const priv = GST_VAAPI_WINDOW_X11(window)->priv;
|
||||||
Display * const dpy = GST_VAAPI_OBJECT_XDISPLAY(window);
|
Display * const dpy = GST_VAAPI_OBJECT_XDISPLAY(window);
|
||||||
Window xid = GST_VAAPI_OBJECT_ID(window);
|
Window xid = GST_VAAPI_OBJECT_ID(window);
|
||||||
|
Visual *vis = NULL;
|
||||||
|
Colormap cmap = None;
|
||||||
|
GstVaapiWindowX11Class *klass;
|
||||||
XWindowAttributes wattr;
|
XWindowAttributes wattr;
|
||||||
Atom atoms[2];
|
Atom atoms[2];
|
||||||
gboolean ok;
|
gboolean ok;
|
||||||
|
@ -236,12 +239,25 @@ gst_vaapi_window_x11_create(GstVaapiWindow *window, guint *width, guint *height)
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
klass = GST_VAAPI_WINDOW_X11_GET_CLASS(window);
|
||||||
|
if (klass) {
|
||||||
|
if (klass->get_visual)
|
||||||
|
vis = klass->get_visual(window);
|
||||||
|
if (klass->get_colormap)
|
||||||
|
cmap = klass->get_colormap(window);
|
||||||
|
}
|
||||||
|
|
||||||
GST_VAAPI_OBJECT_LOCK_DISPLAY(window);
|
GST_VAAPI_OBJECT_LOCK_DISPLAY(window);
|
||||||
XInternAtoms(dpy, (char **)atom_names, G_N_ELEMENTS(atom_names), False, atoms);
|
XInternAtoms(
|
||||||
|
dpy,
|
||||||
|
(char **)atom_names, G_N_ELEMENTS(atom_names),
|
||||||
|
False,
|
||||||
|
atoms
|
||||||
|
);
|
||||||
priv->atom_NET_WM_STATE = atoms[0];
|
priv->atom_NET_WM_STATE = atoms[0];
|
||||||
priv->atom_NET_WM_STATE_FULLSCREEN = atoms[1];
|
priv->atom_NET_WM_STATE_FULLSCREEN = atoms[1];
|
||||||
|
|
||||||
xid = x11_create_window(dpy, *width, *height, NULL);
|
xid = x11_create_window(dpy, *width, *height, vis, cmap);
|
||||||
if (xid)
|
if (xid)
|
||||||
XRaiseWindow(dpy, xid);
|
XRaiseWindow(dpy, xid);
|
||||||
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(window);
|
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(window);
|
||||||
|
@ -494,7 +510,7 @@ gst_vaapi_window_x11_new(GstVaapiDisplay *display, guint width, guint height)
|
||||||
GST_DEBUG("new window, size %ux%u", width, height);
|
GST_DEBUG("new window, size %ux%u", width, height);
|
||||||
|
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
|
||||||
g_return_val_if_fail(width > 0, NULL);
|
g_return_val_if_fail(width > 0, NULL);
|
||||||
g_return_val_if_fail(height > 0, NULL);
|
g_return_val_if_fail(height > 0, NULL);
|
||||||
|
|
||||||
return g_object_new(GST_VAAPI_TYPE_WINDOW_X11,
|
return g_object_new(GST_VAAPI_TYPE_WINDOW_X11,
|
||||||
|
@ -544,7 +560,7 @@ gst_vaapi_window_x11_new_with_xid(GstVaapiDisplay *display, Window xid)
|
||||||
Window
|
Window
|
||||||
gst_vaapi_window_x11_get_xid(GstVaapiWindowX11 *window)
|
gst_vaapi_window_x11_get_xid(GstVaapiWindowX11 *window)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(GST_VAAPI_WINDOW_X11(window), None);
|
g_return_val_if_fail(GST_VAAPI_IS_WINDOW_X11(window), None);
|
||||||
|
|
||||||
return GST_VAAPI_OBJECT_ID(window);
|
return GST_VAAPI_OBJECT_ID(window);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,12 +78,19 @@ struct _GstVaapiWindowX11 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstVaapiWindowX11Class:
|
* GstVaapiWindowX11Class:
|
||||||
|
* @get_visual: virtual function to get the desired visual used to
|
||||||
|
* create the window
|
||||||
|
* @get_colormap: virtual function to get the desired colormap used to
|
||||||
|
* create the window
|
||||||
*
|
*
|
||||||
* An X11 #Window wrapper class.
|
* An X11 #Window wrapper class.
|
||||||
*/
|
*/
|
||||||
struct _GstVaapiWindowX11Class {
|
struct _GstVaapiWindowX11Class {
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
GstVaapiWindowClass parent_class;
|
GstVaapiWindowClass parent_class;
|
||||||
|
|
||||||
|
Visual * (*get_visual) (GstVaapiWindow *window);
|
||||||
|
Colormap (*get_colormap) (GstVaapiWindow *window);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType
|
GType
|
||||||
|
|
Loading…
Reference in a new issue