mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 10:41:04 +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:
|
||||
* @display: an X11 #Display
|
||||
* @width: the requested width, in pixels
|
||||
* @height: the requested height, in pixels
|
||||
* @dpy: an X11 #Display
|
||||
* @w: the requested width, in pixels
|
||||
* @h: the requested height, in pixels
|
||||
* @vis: the request visual
|
||||
* @cmap: the request colormap
|
||||
*
|
||||
* Creates a border-less window with the specified dimensions. If @vis
|
||||
* is %NULL, the default visual for @display will be used. The default
|
||||
* background color is black.
|
||||
* is %NULL, the default visual for @display will be used. If @cmap is
|
||||
* %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.
|
||||
*/
|
||||
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;
|
||||
XSetWindowAttributes xswa;
|
||||
unsigned long xswa_mask;
|
||||
XWindowAttributes wattr;
|
||||
unsigned long black_pixel, white_pixel;
|
||||
|
||||
screen = DefaultScreen(display);
|
||||
root_window = RootWindow(display, screen);
|
||||
black_pixel = BlackPixel(display, screen);
|
||||
white_pixel = WhitePixel(display, screen);
|
||||
screen = DefaultScreen(dpy);
|
||||
rootwin = RootWindow(dpy, screen);
|
||||
black_pixel = BlackPixel(dpy, screen);
|
||||
white_pixel = WhitePixel(dpy, screen);
|
||||
|
||||
if (!vis)
|
||||
vis = DefaultVisual(display, screen);
|
||||
vis = DefaultVisual(dpy, screen);
|
||||
|
||||
XGetWindowAttributes(display, root_window, &wattr);
|
||||
XGetWindowAttributes(dpy, rootwin, &wattr);
|
||||
depth = wattr.depth;
|
||||
if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
|
||||
depth = 24;
|
||||
|
@ -95,21 +97,26 @@ x11_create_window(Display *display, guint width, guint height, Visual *vis)
|
|||
xswa.border_pixel = black_pixel;
|
||||
xswa.background_pixel = black_pixel;
|
||||
|
||||
window = XCreateWindow(
|
||||
display,
|
||||
root_window,
|
||||
0, 0, width, height,
|
||||
if (cmap) {
|
||||
xswa_mask |= CWColormap;
|
||||
xswa.colormap = cmap;
|
||||
}
|
||||
|
||||
win = XCreateWindow(
|
||||
dpy,
|
||||
rootwin,
|
||||
0, 0, w, h,
|
||||
0,
|
||||
depth,
|
||||
InputOutput,
|
||||
vis,
|
||||
xswa_mask, &xswa
|
||||
);
|
||||
if (!window)
|
||||
if (!win)
|
||||
return None;
|
||||
|
||||
XSelectInput(display, window, x11_event_mask);
|
||||
return window;
|
||||
XSelectInput(dpy, win, x11_event_mask);
|
||||
return win;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
|
@ -32,7 +32,7 @@ int x11_untrap_errors(void)
|
|||
attribute_hidden;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
Display * const dpy = GST_VAAPI_OBJECT_XDISPLAY(window);
|
||||
Window xid = GST_VAAPI_OBJECT_ID(window);
|
||||
Visual *vis = NULL;
|
||||
Colormap cmap = None;
|
||||
GstVaapiWindowX11Class *klass;
|
||||
XWindowAttributes wattr;
|
||||
Atom atoms[2];
|
||||
gboolean ok;
|
||||
|
@ -236,12 +239,25 @@ gst_vaapi_window_x11_create(GstVaapiWindow *window, guint *width, guint *height)
|
|||
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);
|
||||
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_FULLSCREEN = atoms[1];
|
||||
|
||||
xid = x11_create_window(dpy, *width, *height, NULL);
|
||||
xid = x11_create_window(dpy, *width, *height, vis, cmap);
|
||||
if (xid)
|
||||
XRaiseWindow(dpy, xid);
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -78,12 +78,19 @@ struct _GstVaapiWindowX11 {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
struct _GstVaapiWindowX11Class {
|
||||
/*< private >*/
|
||||
GstVaapiWindowClass parent_class;
|
||||
|
||||
Visual * (*get_visual) (GstVaapiWindow *window);
|
||||
Colormap (*get_colormap) (GstVaapiWindow *window);
|
||||
};
|
||||
|
||||
GType
|
||||
|
|
Loading…
Reference in a new issue