gstvaapidisplay_glx.c 4.01 KB
Newer Older
gb's avatar
gb committed
1 2 3
/*
 *  gstvaapidisplay_glx.c - VA/GLX display abstraction
 *
4
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6
 *  Copyright (C) 2011-2012 Intel Corporation
7
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
gb's avatar
gb committed
8
 *
gb's avatar
gb committed
9 10 11 12
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
gb's avatar
gb committed
13
 *
gb's avatar
gb committed
14
 *  This library is distributed in the hope that it will be useful,
gb's avatar
gb committed
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
gb's avatar
gb committed
16 17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
gb's avatar
gb committed
18
 *
gb's avatar
gb committed
19 20 21 22
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
gb's avatar
gb committed
23 24 25 26 27 28 29
 */

/**
 * SECTION:gstvaapidisplay_glx
 * @short_description: VA/GLX display abstraction
 */

30
#include "sysdeps.h"
31
#include "gstvaapicompat.h"
gb's avatar
gb committed
32
#include "gstvaapiutils.h"
33
#include "gstvaapiutils_glx.h"
34
#include "gstvaapidisplay_priv.h"
35 36 37
#include "gstvaapidisplay_x11_priv.h"
#include "gstvaapidisplay_glx.h"
#include "gstvaapidisplay_glx_priv.h"
gb's avatar
gb committed
38 39 40 41

#define DEBUG 1
#include "gstvaapidebug.h"

42 43
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_GLX;

44 45 46 47 48
static gboolean
gst_vaapi_display_glx_get_display_info(
    GstVaapiDisplay     *display,
    GstVaapiDisplayInfo *info
)
gb's avatar
gb committed
49
{
50 51
    const GstVaapiDisplayGLXClass * const klass =
        GST_VAAPI_DISPLAY_GLX_GET_CLASS(display);
52 53 54 55

    info->va_display = vaGetDisplayGLX(GST_VAAPI_DISPLAY_XDISPLAY(display));
    if (!info->va_display)
        return FALSE;
56
    info->display_type = GST_VAAPI_DISPLAY_TYPE_GLX;
57
    return klass->parent_get_display(display, info);
gb's avatar
gb committed
58 59 60 61 62
}

static void
gst_vaapi_display_glx_class_init(GstVaapiDisplayGLXClass *klass)
{
63 64
    GstVaapiMiniObjectClass * const object_class =
        GST_VAAPI_MINI_OBJECT_CLASS(klass);
gb's avatar
gb committed
65 66
    GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);

67 68 69 70
    gst_vaapi_display_x11_class_init(&klass->parent_class);

    object_class->size          = sizeof(GstVaapiDisplayGLX);
    klass->parent_get_display   = dpy_class->get_display;
71
    dpy_class->display_types    = g_display_types;
72
    dpy_class->get_display      = gst_vaapi_display_glx_get_display_info;
gb's avatar
gb committed
73 74
}

75 76
static inline const GstVaapiDisplayClass *
gst_vaapi_display_glx_class(void)
gb's avatar
gb committed
77
{
78 79 80 81 82 83 84 85
    static GstVaapiDisplayGLXClass g_class;
    static gsize g_class_init = FALSE;

    if (g_once_init_enter(&g_class_init)) {
        gst_vaapi_display_glx_class_init(&g_class);
        g_once_init_leave(&g_class_init, TRUE);
    }
    return GST_VAAPI_DISPLAY_CLASS(&g_class);
gb's avatar
gb committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
}

/**
 * gst_vaapi_display_glx_new:
 * @display_name: the X11 display name
 *
 * Opens an X11 #Display using @display_name and returns a newly
 * allocated #GstVaapiDisplay object. The X11 display will be cloed
 * when the reference count of the object reaches zero.
 *
 * Return value: a newly allocated #GstVaapiDisplay object
 */
GstVaapiDisplay *
gst_vaapi_display_glx_new(const gchar *display_name)
{
101 102
    return gst_vaapi_display_new(gst_vaapi_display_glx_class(),
        GST_VAAPI_DISPLAY_INIT_FROM_DISPLAY_NAME, (gpointer)display_name);
gb's avatar
gb committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
}

/**
 * gst_vaapi_display_glx_new_with_display:
 * @x11_display: an X11 #Display
 *
 * Creates a #GstVaapiDisplay based on the X11 @x11_display
 * display. The caller still owns the display and must call
 * XCloseDisplay() when all #GstVaapiDisplay references are
 * released. Doing so too early can yield undefined behaviour.
 *
 * Return value: a newly allocated #GstVaapiDisplay object
 */
GstVaapiDisplay *
gst_vaapi_display_glx_new_with_display(Display *x11_display)
{
119 120 121 122
    g_return_val_if_fail(x11_display != NULL, NULL);

    return gst_vaapi_display_new(gst_vaapi_display_glx_class(),
        GST_VAAPI_DISPLAY_INIT_FROM_NATIVE_DISPLAY, x11_display);
gb's avatar
gb committed
123
}