3 * Copyright (C) 2014 Matthew Waters <ystreet00@gmail.com>
4 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * SECTION:gstgldisplay_egl_device
24 * @short_description: EGL EGLDeviceEXT object
25 * @title: GstGLDisplayEGLDevice
26 * @see_also: #GstGLDisplay, #GstGLDisplayEGL
28 * #GstGLDisplayEGLDevice represents a `EGLDeviceEXT` handle created internally
29 * (gst_gl_display_egl_device_new()) or wrapped by the application
30 * (gst_gl_display_egl_device_new_with_egl_device())
37 #include "gstgldisplay_egl.h"
38 #include "gstgldisplay_egl_device.h"
40 #include <gst/gl/gstglfeature.h>
43 #include "gstglmemoryegl.h"
45 #ifndef EGL_DEVICE_EXT
46 typedef void *EGLDeviceEXT;
49 GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
50 #define GST_CAT_DEFAULT gst_gl_display_debug
52 typedef EGLBoolean (*eglQueryDevicesEXT_type) (EGLint max_devices,
53 EGLDeviceEXT * devices, EGLint * num_devices);
55 G_DEFINE_TYPE (GstGLDisplayEGLDevice, gst_gl_display_egl_device,
58 static guintptr gst_gl_display_egl_device_get_handle (GstGLDisplay * display);
61 gst_gl_display_egl_device_class_init (GstGLDisplayEGLDeviceClass * klass)
63 GstGLDisplayClass *display_class = GST_GL_DISPLAY_CLASS (klass);
65 display_class->get_handle =
66 GST_DEBUG_FUNCPTR (gst_gl_display_egl_device_get_handle);
70 gst_gl_display_egl_device_init (GstGLDisplayEGLDevice * self)
72 GstGLDisplay *display = GST_GL_DISPLAY (self);
74 display->type = GST_GL_DISPLAY_TYPE_EGL_DEVICE;
76 gst_gl_memory_egl_init_once ();
80 gst_gl_display_egl_device_get_handle (GstGLDisplay * display)
82 GstGLDisplayEGLDevice *self = GST_GL_DISPLAY_EGL_DEVICE (display);
84 return (guintptr) self->device;
88 * gst_gl_display_egl_device_new:
89 * @device_index: the index of device to use
91 * Create a new #GstGLDisplayEGLDevice with an EGLDevice supported device
93 * Returns: (transfer full): a new #GstGLDisplayEGLDevice or %NULL
97 GstGLDisplayEGLDevice *
98 gst_gl_display_egl_device_new (guint device_index)
100 GstGLDisplayEGLDevice *ret;
101 eglQueryDevicesEXT_type query_device_func;
102 EGLint num_devices = 0;
103 EGLDeviceEXT *device_list;
105 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
108 (eglQueryDevicesEXT_type) eglGetProcAddress ("eglQueryDevicesEXT");
110 if (!query_device_func) {
111 GST_ERROR ("eglQueryDevicesEXT is unavailable");
115 if (query_device_func (0, NULL, &num_devices) == EGL_FALSE) {
116 GST_ERROR ("eglQueryDevicesEXT fail");
118 } else if (num_devices < 1) {
119 GST_ERROR ("no EGLDevice supported device");
123 if (num_devices <= device_index) {
124 GST_ERROR ("requested index %d exceeds the number of devices %d",
125 device_index, num_devices);
129 device_list = g_alloca (sizeof (EGLDeviceEXT) * num_devices);
130 query_device_func (num_devices, device_list, &num_devices);
132 ret = g_object_new (GST_TYPE_GL_DISPLAY_EGL_DEVICE, NULL);
133 gst_object_ref_sink (ret);
135 ret->device = device_list[device_index];
141 * gst_gl_display_egl_device_new_with_egl_device:
142 * @device: an existing EGLDeviceEXT
144 * Creates a new #GstGLDisplayEGLDevice with EGLDeviceEXT .
145 * The @device must be created using EGLDevice enumeration.
147 * Returns: (transfer full): a new #GstGLDisplayEGLDevice
151 GstGLDisplayEGLDevice *
152 gst_gl_display_egl_device_new_with_egl_device (gpointer device)
154 GstGLDisplayEGLDevice *ret;
156 g_return_val_if_fail (device != NULL, NULL);
158 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
160 ret = g_object_new (GST_TYPE_GL_DISPLAY_EGL_DEVICE, NULL);
161 gst_object_ref_sink (ret);
163 ret->device = device;