/** * gst_gl_memory_egl_get_display: * @mem: a #GstGLMemoryEGL * * Returns: The EGLDisplay @mem is associated with * * Since: 1.10 */ EGLDisplay gst_gl_memory_egl_get_display (GstGLMemoryEGL * mem) { g_return_val_if_fail (gst_is_gl_memory_egl (GST_MEMORY_CAST (mem)), NULL); return GST_GL_CONTEXT_EGL (_gl_mem_get_parent (mem)->mem.mem. context)->egl_display; }
static void draw_cb (gpointer data) { GstGLWindowAndroidEGL *window_egl = data; GstGLWindow *window = GST_GL_WINDOW (window_egl); GstGLContext *context = gst_gl_window_get_context (window); GstGLContextEGL *context_egl = GST_GL_CONTEXT_EGL (context); GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context); if (context_egl->egl_surface) { gint width, height; if (eglQuerySurface (context_egl->egl_display, context_egl->egl_surface, EGL_WIDTH, &width) && eglQuerySurface (context_egl->egl_display, context_egl->egl_surface, EGL_HEIGHT, &height) && (width != window_egl->window_width || height != window_egl->window_height)) { window_egl->window_width = width; window_egl->window_height = height; if (window->resize) window->resize (window->resize_data, width, height); } } if (window->draw) window->draw (window->draw_data); context_class->swap_buffers (context); gst_object_unref (context); }
static void gst_gl_context_egl_destroy_context (GstGLContext * context) { GstGLContextEGL *egl; egl = GST_GL_CONTEXT_EGL (context); gst_gl_context_egl_activate (context, FALSE); if (egl->egl_surface) { eglDestroySurface (egl->egl_display, egl->egl_surface); egl->egl_surface = EGL_NO_SURFACE; } if (egl->egl_context) { eglDestroyContext (egl->egl_display, egl->egl_context); egl->egl_context = NULL; } egl->window_handle = 0; eglReleaseThread (); if (egl->display_egl) { gst_object_unref (egl->display_egl); egl->display_egl = NULL; } }
static void gst_gl_context_egl_swap_buffers (GstGLContext * context) { GstGLContextEGL *egl; egl = GST_GL_CONTEXT_EGL (context); eglSwapBuffers (egl->egl_display, egl->egl_surface); }
GstEGLImage * gst_egl_image_from_dmabuf (GstGLContext * context, gint dmabuf, GstVideoInfo * in_info, gint plane, gsize offset) { GstGLContextEGL *ctx_egl = GST_GL_CONTEXT_EGL (context); gint fourcc; gint atti = 0; EGLint attribs[13]; EGLImageKHR img = EGL_NO_IMAGE_KHR; GstVideoGLTextureType type; fourcc = _drm_fourcc_from_info (in_info, plane); type = gst_gl_texture_type_from_format (context, GST_VIDEO_INFO_FORMAT (in_info), plane); GST_DEBUG ("fourcc %.4s (%d) plane %d (%dx%d)", (char *) &fourcc, fourcc, plane, GST_VIDEO_INFO_COMP_WIDTH (in_info, plane), GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane)); attribs[atti++] = EGL_WIDTH; attribs[atti++] = GST_VIDEO_INFO_COMP_WIDTH (in_info, plane); attribs[atti++] = EGL_HEIGHT; attribs[atti++] = GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane); attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT; attribs[atti++] = fourcc; attribs[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT; attribs[atti++] = dmabuf; attribs[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT; attribs[atti++] = offset; attribs[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT; attribs[atti++] = GST_VIDEO_INFO_PLANE_STRIDE (in_info, plane); attribs[atti] = EGL_NONE; for (int i = 0; i < atti; i++) GST_LOG ("attr %i: %08X", i, attribs[i]); g_assert (atti == 12); img = ctx_egl->eglCreateImage (ctx_egl->egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attribs); if (!img) { GST_WARNING ("eglCreateImage failed: %s", gst_gl_context_egl_get_error_string (eglGetError ())); return NULL; } return gst_egl_image_new_wrapped (context, img, type, GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL, (GstEGLImageDestroyNotify) _destroy_egl_image, NULL); }
static void gst_gl_context_egl_get_gl_platform_version (GstGLContext * context, gint * major, gint * minor) { GstGLContextEGL *context_egl = GST_GL_CONTEXT_EGL (context); *major = context_egl->egl_major; *minor = context_egl->egl_minor; }
static gboolean gst_gl_context_egl_activate (GstGLContext * context, gboolean activate) { GstGLContextEGL *egl; gboolean result; egl = GST_GL_CONTEXT_EGL (context); if (activate) { GstGLWindow *window = gst_gl_context_get_window (context); EGLNativeWindowType handle = 0; /* Check if the backing handle changed */ if (window) { handle = (EGLNativeWindowType) gst_gl_window_get_window_handle (window); gst_object_unref (window); } if (handle && handle != egl->window_handle) { GST_DEBUG_OBJECT (context, "Handle changed (have:%p, now:%p), switching surface", (void *) egl->window_handle, (void *) handle); if (egl->egl_surface) { result = eglDestroySurface (egl->egl_display, egl->egl_surface); egl->egl_surface = EGL_NO_SURFACE; if (!result) { GST_ERROR_OBJECT (context, "Failed to destroy old window surface: %s", gst_egl_get_error_string (eglGetError ())); goto done; } } egl->egl_surface = eglCreateWindowSurface (egl->egl_display, egl->egl_config, handle, NULL); egl->window_handle = handle; if (egl->egl_surface == EGL_NO_SURFACE) { GST_ERROR_OBJECT (context, "Failed to create window surface: %s", gst_egl_get_error_string (eglGetError ())); result = FALSE; goto done; } } result = eglMakeCurrent (egl->egl_display, egl->egl_surface, egl->egl_surface, egl->egl_context); } else { result = eglMakeCurrent (egl->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } if (!result) { GST_ERROR_OBJECT (context, "Failed to bind context to the current rendering thread: %s", gst_egl_get_error_string (eglGetError ())); } done: return result; }
GstMemory * gst_egl_image_memory_from_dmabuf (GstGLContext * context, gint dmabuf, GstVideoInfo * in_info, gint plane, gsize offset) { GstGLContextEGL *ctx_egl = GST_GL_CONTEXT_EGL (context); GstEGLImageAllocator *allocator; gint fourcc; gint atti = 0; EGLint attribs[13]; EGLImageKHR img = EGL_NO_IMAGE_KHR; allocator = gst_egl_image_allocator_obtain (); fourcc = _drm_fourcc_from_info (in_info, plane); GST_DEBUG ("fourcc %.4s (%d) plane %d (%dx%d)", (char *) &fourcc, fourcc, plane, GST_VIDEO_INFO_COMP_WIDTH (in_info, plane), GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane)); attribs[atti++] = EGL_WIDTH; attribs[atti++] = GST_VIDEO_INFO_COMP_WIDTH (in_info, plane); attribs[atti++] = EGL_HEIGHT; attribs[atti++] = GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane); attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT; attribs[atti++] = fourcc; attribs[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT; attribs[atti++] = dmabuf; attribs[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT; attribs[atti++] = offset; attribs[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT; attribs[atti++] = GST_VIDEO_INFO_PLANE_STRIDE (in_info, plane); attribs[atti] = EGL_NONE; for (int i = 0; i < atti; i++) GST_LOG ("attr %i: %08X", i, attribs[i]); g_assert (atti == 12); img = ctx_egl->eglCreateImage (ctx_egl->egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attribs); if (!img) { GST_WARNING_OBJECT (allocator, "eglCreateImage failed: %s", gst_gl_context_egl_get_error_string ()); return NULL; } return gst_egl_image_allocator_wrap (allocator, ctx_egl, img, 0, 0, in_info->size, NULL, NULL); }
static void gst_gl_context_egl_destroy_context (GstGLContext * context) { GstGLContextEGL *egl; egl = GST_GL_CONTEXT_EGL (context); gst_gl_context_egl_activate (context, FALSE); if (egl->egl_surface) eglDestroySurface (egl->egl_display, egl->egl_surface); if (egl->egl_context) eglDestroyContext (egl->egl_display, egl->egl_context); eglReleaseThread (); }
static gboolean gst_gl_context_egl_activate (GstGLContext * context, gboolean activate) { GstGLContextEGL *egl; gboolean result; egl = GST_GL_CONTEXT_EGL (context); if (activate) result = eglMakeCurrent (egl->egl_display, egl->egl_surface, egl->egl_surface, egl->egl_context); else result = eglMakeCurrent (egl->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); return result; }
static gboolean _gl_mem_create (GstGLMemoryEGL * gl_mem, GError ** error) { GstGLContext *context = gl_mem->mem.mem.context; GstGLContextEGL *ctx_egl = GST_GL_CONTEXT_EGL (context); const GstGLFuncs *gl = context->gl_vtable; GstGLBaseMemoryAllocatorClass *alloc_class; if (!gst_gl_context_check_feature (GST_GL_CONTEXT (context), "EGL_KHR_image_base")) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "EGL_KHR_image_base is not supported"); return FALSE; } alloc_class = GST_GL_BASE_MEMORY_ALLOCATOR_CLASS (parent_class); if (!alloc_class->create ((GstGLBaseMemory *) gl_mem, error)) return FALSE; if (gl_mem->image == NULL) { EGLImageKHR image = ctx_egl->eglCreateImageKHR (ctx_egl->egl_display, ctx_egl->egl_context, EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer) (guintptr) gl_mem->mem.tex_id, NULL); GST_TRACE ("Generating EGLImage handle:%p from a texture:%u", gl_mem->image, gl_mem->mem.tex_id); if (eglGetError () != EGL_SUCCESS) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to create EGLImage"); return FALSE; } gl_mem->image = gst_egl_image_new_wrapped (context, image, 0, 0, NULL, (GstEGLImageDestroyNotify) _destroy_egl_image); } else { gl->ActiveTexture (GL_TEXTURE0 + gl_mem->mem.plane); gl->BindTexture (GL_TEXTURE_2D, gl_mem->mem.tex_id); gl->EGLImageTargetTexture2D (GL_TEXTURE_2D, gst_egl_image_get_image (GST_EGL_IMAGE (gl_mem->image))); } return TRUE; }
gpointer gst_gl_context_egl_get_proc_address (GstGLContext * context, const gchar * name) { gpointer result = NULL; static GOnce g_once = G_ONCE_INIT; GstGLAPI gl_api = gst_gl_context_get_gl_api (context); result = gst_gl_context_default_get_proc_address (gl_api, name); g_once (&g_once, load_egl_module, NULL); if (!result && module_egl) { g_module_symbol (module_egl, name, &result); } /* FIXME: On Android this returns wrong addresses for non-EGL functions */ #if GST_GL_HAVE_WINDOW_ANDROID if (!result && g_str_has_prefix (name, "egl")) { #else if (!result) { result = eglGetProcAddress (name); #endif } return result; } static gboolean gst_gl_context_egl_check_feature (GstGLContext * context, const gchar * feature) { GstGLContextEGL *context_egl = GST_GL_CONTEXT_EGL (context); if (g_strcmp0 (feature, "EGL_KHR_image_base") == 0) { return context_egl->eglCreateImage != NULL && context_egl->eglDestroyImage != NULL; } return FALSE; }
gboolean gst_egl_image_memory_setup_buffer (GstGLContext * ctx, GstVideoInfo * info, GstBuffer * buffer) { gint i = 0; gint stride[3]; gsize offset[3]; GstMemory *mem[3] = { NULL, NULL, NULL }; guint n_mem = 0; GstMemoryFlags flags = 0; EGLImageKHR image = EGL_NO_IMAGE_KHR; EGLClientBuffer client_buffer_tex[3] = { 0, 0, 0 }; GstVideoGLTextureType texture_types[] = { 0, 0, 0, 0 }; GstEGLImageAllocator *allocator = gst_egl_image_allocator_obtain (); GstGLContextEGL *context = GST_GL_CONTEXT_EGL (ctx); g_return_val_if_fail (ctx, FALSE); g_return_val_if_fail (info, FALSE); g_return_val_if_fail (buffer, FALSE); g_return_val_if_fail (gst_gl_context_check_feature (ctx, "EGL_KHR_image_base"), FALSE); memset (stride, 0, sizeof (stride)); memset (offset, 0, sizeof (offset)); flags |= GST_MEMORY_FLAG_NOT_MAPPABLE; flags |= GST_MEMORY_FLAG_NO_SHARE; switch (GST_VIDEO_INFO_FORMAT (info)) { case GST_VIDEO_FORMAT_RGB: case GST_VIDEO_FORMAT_BGR: case GST_VIDEO_FORMAT_RGB16: case GST_VIDEO_FORMAT_RGBA: case GST_VIDEO_FORMAT_BGRA: case GST_VIDEO_FORMAT_ARGB: case GST_VIDEO_FORMAT_ABGR: case GST_VIDEO_FORMAT_RGBx: case GST_VIDEO_FORMAT_BGRx: case GST_VIDEO_FORMAT_xRGB: case GST_VIDEO_FORMAT_xBGR: case GST_VIDEO_FORMAT_AYUV: { gsize size = 0; switch (GST_VIDEO_INFO_FORMAT (info)) { case GST_VIDEO_FORMAT_RGB: case GST_VIDEO_FORMAT_BGR: case GST_VIDEO_FORMAT_RGB16: { texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_RGB; break; } case GST_VIDEO_FORMAT_RGBA: case GST_VIDEO_FORMAT_BGRA: case GST_VIDEO_FORMAT_ARGB: case GST_VIDEO_FORMAT_ABGR: case GST_VIDEO_FORMAT_RGBx: case GST_VIDEO_FORMAT_BGRx: case GST_VIDEO_FORMAT_xRGB: case GST_VIDEO_FORMAT_xBGR: case GST_VIDEO_FORMAT_AYUV: { texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_RGBA; break; } default: g_assert_not_reached (); break; } #if 0 mem[0] = gst_egl_image_allocator_alloc (allocator, context, texture_types[0], GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info), size); if (mem[0]) { stride[0] = size / GST_VIDEO_INFO_HEIGHT (info); n_mem = 1; GST_MINI_OBJECT_FLAG_SET (mem[0], GST_MEMORY_FLAG_NO_SHARE); } else #endif { gst_gl_generate_texture_full (GST_GL_CONTEXT (context), info, 0, stride, offset, &size, (GLuint *) & client_buffer_tex[0]); image = context->eglCreateImage (context->egl_display, context->egl_context, EGL_GL_TEXTURE_2D_KHR, client_buffer_tex[0], NULL); if (eglGetError () != EGL_SUCCESS) goto mem_error; mem[0] = gst_egl_image_allocator_wrap (allocator, context, image, texture_types[0], flags, size, client_buffer_tex[0], (GstEGLImageDestroyNotify) gst_egl_image_memory_del_gl_texture); n_mem = 1; } break; } case GST_VIDEO_FORMAT_NV12: case GST_VIDEO_FORMAT_NV21: { gsize size[2]; texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE; texture_types[1] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA; #if 0 mem[0] = gst_egl_image_allocator_alloc (allocator, context, texture_types[0], GST_VIDEO_INFO_COMP_WIDTH (info, 0), GST_VIDEO_INFO_COMP_HEIGHT (info, 0), size[0]); mem[1] = gst_egl_image_allocator_alloc (allocator, context, texture_types[1], GST_VIDEO_INFO_COMP_WIDTH (info, 1), GST_VIDEO_INFO_COMP_HEIGHT (info, 1), size[1]); if (mem[0] && mem[1]) { stride[0] = size[0] / GST_VIDEO_INFO_HEIGHT (info); offset[1] = size[0]; stride[1] = size[1] / GST_VIDEO_INFO_HEIGHT (info); n_mem = 2; GST_MINI_OBJECT_FLAG_SET (mem[0], GST_MEMORY_FLAG_NO_SHARE); GST_MINI_OBJECT_FLAG_SET (mem[1], GST_MEMORY_FLAG_NO_SHARE); } else { if (mem[0]) gst_memory_unref (mem[0]); if (mem[1]) gst_memory_unref (mem[1]); mem[0] = mem[1] = NULL; } #endif { for (i = 0; i < 2; i++) { gst_gl_generate_texture_full (GST_GL_CONTEXT (context), info, 0, stride, offset, size, (GLuint *) & client_buffer_tex[i]); image = context->eglCreateImage (context->egl_display, context->egl_context, EGL_GL_TEXTURE_2D_KHR, client_buffer_tex[i], NULL); if (eglGetError () != EGL_SUCCESS) goto mem_error; mem[i] = gst_egl_image_allocator_wrap (allocator, context, image, texture_types[i], flags, size[i], client_buffer_tex[i], (GstEGLImageDestroyNotify) gst_egl_image_memory_del_gl_texture); } n_mem = 2; } break; } case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_YV12: case GST_VIDEO_FORMAT_Y444: case GST_VIDEO_FORMAT_Y42B: case GST_VIDEO_FORMAT_Y41B: { gsize size[3]; texture_types[0] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE; texture_types[1] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE; texture_types[2] = GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE; #if 0 mem[0] = gst_egl_image_allocator_alloc (allocator, context, texture_types[0], GST_VIDEO_INFO_COMP_WIDTH (info, 0), GST_VIDEO_INFO_COMP_HEIGHT (info, 0), size[0]); mem[1] = gst_egl_image_allocator_alloc (allocator, context, texture_types[1], GST_VIDEO_INFO_COMP_WIDTH (info, 1), GST_VIDEO_INFO_COMP_HEIGHT (info, 1), size[1]); mem[2] = gst_egl_image_allocator_alloc (allocator, context, texture_types[2], GST_VIDEO_INFO_COMP_WIDTH (info, 2), GST_VIDEO_INFO_COMP_HEIGHT (info, 2), size[2]); if (mem[0] && mem[1] && mem[2]) { stride[0] = size[0] / GST_VIDEO_INFO_HEIGHT (info); offset[1] = size[0]; stride[1] = size[1] / GST_VIDEO_INFO_HEIGHT (info); offset[2] = size[1]; stride[2] = size[2] / GST_VIDEO_INFO_HEIGHT (info); n_mem = 3; GST_MINI_OBJECT_FLAG_SET (mem[0], GST_MEMORY_FLAG_NO_SHARE); GST_MINI_OBJECT_FLAG_SET (mem[1], GST_MEMORY_FLAG_NO_SHARE); GST_MINI_OBJECT_FLAG_SET (mem[2], GST_MEMORY_FLAG_NO_SHARE); } else { if (mem[0]) gst_memory_unref (mem[0]); if (mem[1]) gst_memory_unref (mem[1]); if (mem[2]) gst_memory_unref (mem[2]); mem[0] = mem[1] = mem[2] = NULL; } #endif { for (i = 0; i < 3; i++) { gst_gl_generate_texture_full (GST_GL_CONTEXT (context), info, i, stride, offset, size, (GLuint *) & client_buffer_tex[i]); image = context->eglCreateImage (context->egl_display, context->egl_context, EGL_GL_TEXTURE_2D_KHR, client_buffer_tex[i], NULL); if (eglGetError () != EGL_SUCCESS) goto mem_error; mem[i] = gst_egl_image_allocator_wrap (allocator, context, image, texture_types[i], flags, size[i], client_buffer_tex[i], (GstEGLImageDestroyNotify) gst_egl_image_memory_del_gl_texture); } n_mem = 3; } break; } default: g_assert_not_reached (); break; } gst_buffer_add_video_meta_full (buffer, 0, GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info), offset, stride); gst_buffer_add_video_gl_texture_upload_meta (buffer, gst_egl_image_memory_get_orientation (mem[0]), n_mem, texture_types, gst_eglimage_to_gl_texture_upload_meta, NULL, NULL, NULL); for (i = 0; i < n_mem; i++) gst_buffer_append_memory (buffer, mem[i]); return TRUE; mem_error: { GST_CAT_ERROR (GST_CAT_DEFAULT, "Failed to create EGLImage"); for (i = 0; i < 3; i++) { if (client_buffer_tex[i]) gst_gl_context_del_texture (ctx, (GLuint *) & client_buffer_tex[i]); if (mem[i]) gst_memory_unref (mem[i]); } return FALSE; } }
static GstGLAPI gst_gl_context_egl_get_gl_api (GstGLContext * context) { return GST_GL_CONTEXT_EGL (context)->gl_api; }
static guintptr gst_gl_context_egl_get_gl_context (GstGLContext * context) { return (guintptr) GST_GL_CONTEXT_EGL (context)->egl_context; }
static gboolean gst_gl_context_egl_create_context (GstGLContext * context, GstGLAPI gl_api, GstGLContext * other_context, GError ** error) { GstGLContextEGL *egl; GstGLWindow *window = NULL; EGLNativeWindowType window_handle; gint i = 0; EGLint context_attrib[3]; EGLint majorVersion; EGLint minorVersion; const gchar *egl_exts; gboolean need_surface = TRUE; guintptr external_gl_context = 0; egl = GST_GL_CONTEXT_EGL (context); window = gst_gl_context_get_window (context); if (other_context) { if (!GST_GL_IS_CONTEXT_EGL (other_context)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Cannot share context with non-EGL context"); goto failure; } external_gl_context = gst_gl_context_get_gl_context (other_context); } if ((gl_api & (GST_GL_API_OPENGL | GST_GL_API_GLES2)) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "EGL supports opengl or gles2"); goto failure; } if (other_context) { GstGLContextEGL *other_egl = (GstGLContextEGL *) other_context; egl->egl_display = other_egl->egl_display; } else { egl->egl_display = eglGetDisplay ((EGLNativeDisplayType) gst_gl_window_get_display (window)); } if (eglInitialize (egl->egl_display, &majorVersion, &minorVersion)) { GST_INFO ("egl initialized, version: %d.%d", majorVersion, minorVersion); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Failed to initialize egl: %s", gst_gl_context_egl_get_error_string ()); goto failure; } if (gl_api & GST_GL_API_OPENGL) { /* egl + opengl only available with EGL 1.4+ */ if (majorVersion == 1 && minorVersion <= 3) { if ((gl_api & ~GST_GL_API_OPENGL) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_OLD_LIBS, "EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)", majorVersion, minorVersion); goto failure; } else { GST_WARNING ("EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)", majorVersion, minorVersion); if (gl_api & GST_GL_API_GLES2) { goto try_gles2; } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Failed to choose a suitable OpenGL API"); goto failure; } } } if (!eglBindAPI (EGL_OPENGL_API)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to bind OpenGL API: %s", gst_gl_context_egl_get_error_string ()); goto failure; } GST_INFO ("Using OpenGL"); egl->gl_api = GST_GL_API_OPENGL; } else if (gl_api & GST_GL_API_GLES2) { try_gles2: if (!eglBindAPI (EGL_OPENGL_ES_API)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to bind OpenGL|ES API: %s", gst_gl_context_egl_get_error_string ()); goto failure; } GST_INFO ("Using OpenGL|ES 2.0"); egl->gl_api = GST_GL_API_GLES2; } if (!gst_gl_context_egl_choose_config (egl, other_context, error)) { g_assert (error == NULL || *error != NULL); goto failure; } GST_DEBUG ("about to create gl context\n"); if (egl->gl_api & GST_GL_API_GLES2) { context_attrib[i++] = EGL_CONTEXT_CLIENT_VERSION; context_attrib[i++] = 2; } context_attrib[i++] = EGL_NONE; egl->egl_context = eglCreateContext (egl->egl_display, egl->egl_config, (EGLContext) external_gl_context, context_attrib); if (egl->egl_context != EGL_NO_CONTEXT) { GST_INFO ("gl context created: %" G_GUINTPTR_FORMAT, (guintptr) egl->egl_context); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_CREATE_CONTEXT, "Failed to create a OpenGL context: %s", gst_gl_context_egl_get_error_string ()); goto failure; } egl_exts = eglQueryString (egl->egl_display, EGL_EXTENSIONS); if (other_context == NULL) { /* FIXME do we want a window vfunc ? */ #if GST_GL_HAVE_WINDOW_X11 if (GST_GL_IS_WINDOW_X11 (context->window)) { gst_gl_window_x11_create_window ((GstGLWindowX11 *) context->window); } #endif #if GST_GL_HAVE_WINDOW_WIN32 if (GST_GL_IS_WINDOW_WIN32 (context->window)) { gst_gl_window_win32_create_window ((GstGLWindowWin32 *) context->window); } #endif } window_handle = (EGLNativeWindowType) gst_gl_window_get_window_handle (window); if (window_handle) { egl->egl_surface = eglCreateWindowSurface (egl->egl_display, egl->egl_config, window_handle, NULL); } else if (!gst_gl_check_extension ("EGL_KHR_surfaceless_context", egl_exts)) { EGLint surface_attrib[7]; gint j = 0; /* FIXME: Width/height doesn't seem to matter but we can't leave them * at 0, otherwise X11 complains about BadValue */ surface_attrib[j++] = EGL_WIDTH; surface_attrib[j++] = 1; surface_attrib[j++] = EGL_HEIGHT; surface_attrib[j++] = 1; surface_attrib[j++] = EGL_LARGEST_PBUFFER; surface_attrib[j++] = EGL_TRUE; surface_attrib[j++] = EGL_NONE; egl->egl_surface = eglCreatePbufferSurface (egl->egl_display, egl->egl_config, surface_attrib); } else { egl->egl_surface = EGL_NO_SURFACE; need_surface = FALSE; } if (need_surface) { if (egl->egl_surface != EGL_NO_SURFACE) { GST_INFO ("surface created"); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to create window surface: %s", gst_gl_context_egl_get_error_string ()); goto failure; } } gst_object_unref (window); return TRUE; failure: if (window) gst_object_unref (window); return FALSE; }
static gboolean gst_gl_context_egl_create_context (GstGLContext * context, GstGLAPI gl_api, GstGLContext * other_context, GError ** error) { GstGLContextEGL *egl; GstGLWindow *window = NULL; EGLNativeWindowType window_handle = (EGLNativeWindowType) 0; EGLint egl_major; EGLint egl_minor; gboolean need_surface = TRUE; guintptr external_gl_context = 0; guintptr egl_display; egl = GST_GL_CONTEXT_EGL (context); window = gst_gl_context_get_window (context); GST_DEBUG_OBJECT (context, "Creating EGL context"); if (other_context) { if (gst_gl_context_get_gl_platform (other_context) != GST_GL_PLATFORM_EGL) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Cannot share context with non-EGL context"); goto failure; } external_gl_context = gst_gl_context_get_gl_context (other_context); } if ((gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2)) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "EGL supports opengl or gles2"); goto failure; } if (!egl->display_egl) { GstGLDisplay *display = gst_gl_context_get_display (context); egl->display_egl = gst_gl_display_egl_from_gl_display (display); if (!egl->display_egl) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Failed to create EGLDisplay from native display"); goto failure; } gst_object_unref (display); } egl_display = gst_gl_display_get_handle (GST_GL_DISPLAY (egl->display_egl)); egl->egl_display = (EGLDisplay) egl_display; if (eglInitialize (egl->egl_display, &egl_major, &egl_minor)) { GST_INFO ("egl initialized, version: %d.%d", egl_major, egl_minor); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Failed to initialize egl: %s", gst_egl_get_error_string (eglGetError ())); goto failure; } egl->egl_exts = eglQueryString (egl->egl_display, EGL_EXTENSIONS); if (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3)) { GstGLAPI chosen_gl_api = 0; gint i; /* egl + opengl only available with EGL 1.4+ */ if (egl_major == 1 && egl_minor <= 3) { if ((gl_api & ~GST_GL_API_OPENGL) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_OLD_LIBS, "EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)", egl_major, egl_minor); goto failure; } else { GST_WARNING ("EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)", egl_major, egl_minor); if (gl_api & GST_GL_API_GLES2) { goto try_gles2; } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Failed to choose a suitable OpenGL API"); goto failure; } } } if (!eglBindAPI (EGL_OPENGL_API)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to bind OpenGL API: %s", gst_egl_get_error_string (eglGetError ())); goto failure; } GST_INFO ("Bound OpenGL"); /* api, version only matters for gles */ if (!gst_gl_context_egl_choose_config (egl, GST_GL_API_OPENGL, 0, error)) { g_assert (error == NULL || *error != NULL); goto failure; } for (i = 0; i < G_N_ELEMENTS (opengl_versions); i++) { gint profileMask = 0; gint contextFlags = 0; if (GST_GL_CHECK_GL_VERSION (opengl_versions[i].major, opengl_versions[i].minor, 3, 2)) { /* skip gl3 contexts if requested */ if ((gl_api & GST_GL_API_OPENGL3) == 0) continue; chosen_gl_api = GST_GL_API_OPENGL3; #if defined(EGL_KHR_create_context) profileMask |= EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; contextFlags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; #endif } else if (opengl_versions[i].major == 3 && opengl_versions[i].minor == 1) { /* skip 3.1, the implementation is free to give us either a core or a * compatibility context (we have no say) */ continue; } else { /* skip legacy contexts if requested */ if ((gl_api & GST_GL_API_OPENGL) == 0) continue; chosen_gl_api = GST_GL_API_OPENGL; } egl->egl_context = _create_context_with_flags (egl, (EGLContext) external_gl_context, chosen_gl_api, opengl_versions[i].major, opengl_versions[i].minor, contextFlags, profileMask); if (egl->egl_context) break; #if defined(EGL_KHR_create_context) profileMask &= ~EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; egl->egl_context = _create_context_with_flags (egl, (EGLContext) external_gl_context, chosen_gl_api, opengl_versions[i].major, opengl_versions[i].minor, contextFlags, profileMask); if (egl->egl_context) break; #endif } egl->gl_api = chosen_gl_api; } else if (gl_api & GST_GL_API_GLES2) { gint i; try_gles2: if (!eglBindAPI (EGL_OPENGL_ES_API)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to bind OpenGL|ES API: %s", gst_egl_get_error_string (eglGetError ())); goto failure; } GST_INFO ("Bound OpenGL|ES"); for (i = 0; i < G_N_ELEMENTS (gles2_versions); i++) { gint profileMask = 0; gint contextFlags = 0; if (!gst_gl_context_egl_choose_config (egl, GST_GL_API_GLES2, gles2_versions[i].major, error)) { continue; } #if defined(EGL_KHR_create_context) /* try a debug context */ contextFlags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; egl->egl_context = _create_context_with_flags (egl, (EGLContext) external_gl_context, GST_GL_API_GLES2, gles2_versions[i].major, gles2_versions[i].minor, contextFlags, profileMask); if (egl->egl_context) break; /* try without a debug context */ contextFlags &= ~EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; #endif egl->egl_context = _create_context_with_flags (egl, (EGLContext) external_gl_context, GST_GL_API_GLES2, gles2_versions[i].major, gles2_versions[i].minor, contextFlags, profileMask); if (egl->egl_context) break; } egl->gl_api = GST_GL_API_GLES2; } if (egl->egl_context != EGL_NO_CONTEXT) { GST_INFO ("gl context created: %" G_GUINTPTR_FORMAT, (guintptr) egl->egl_context); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_CREATE_CONTEXT, "Failed to create a OpenGL context: %s", gst_egl_get_error_string (eglGetError ())); goto failure; } /* FIXME do we want a window vfunc ? */ #if GST_GL_HAVE_WINDOW_X11 if (GST_IS_GL_WINDOW_X11 (context->window)) { gst_gl_window_x11_create_window ((GstGLWindowX11 *) context->window); } #endif if (other_context == NULL) { /* FIXME: fails to show two outputs at all. We need a property/option for * glimagesink to say its a visible context */ #if GST_GL_HAVE_WINDOW_WAYLAND if (GST_IS_GL_WINDOW_WAYLAND_EGL (context->window)) { gst_gl_window_wayland_egl_create_window ((GstGLWindowWaylandEGL *) context->window); } #endif #if GST_GL_HAVE_WINDOW_WIN32 if (GST_IS_GL_WINDOW_WIN32 (context->window)) { gst_gl_window_win32_create_window ((GstGLWindowWin32 *) context->window); } #endif #if GST_GL_HAVE_WINDOW_DISPMANX if (GST_IS_GL_WINDOW_DISPMANX_EGL (context->window)) { gst_gl_window_dispmanx_egl_create_window ((GstGLWindowDispmanxEGL *) context->window); } #endif } if (window) window_handle = (EGLNativeWindowType) gst_gl_window_get_window_handle (window); if (window_handle) { GST_DEBUG ("Creating EGLSurface from window_handle %p", (void *) window_handle); egl->egl_surface = eglCreateWindowSurface (egl->egl_display, egl->egl_config, window_handle, NULL); /* Store window handle for later comparision */ egl->window_handle = window_handle; } else if (!gst_gl_check_extension ("EGL_KHR_surfaceless_context", egl->egl_exts)) { EGLint surface_attrib[7]; gint j = 0; GST_DEBUG ("Surfaceless context, creating PBufferSurface"); /* FIXME: Width/height doesn't seem to matter but we can't leave them * at 0, otherwise X11 complains about BadValue */ surface_attrib[j++] = EGL_WIDTH; surface_attrib[j++] = 1; surface_attrib[j++] = EGL_HEIGHT; surface_attrib[j++] = 1; surface_attrib[j++] = EGL_LARGEST_PBUFFER; surface_attrib[j++] = EGL_TRUE; surface_attrib[j++] = EGL_NONE; egl->egl_surface = eglCreatePbufferSurface (egl->egl_display, egl->egl_config, surface_attrib); } else { GST_DEBUG ("No surface/handle !"); egl->egl_surface = EGL_NO_SURFACE; need_surface = FALSE; } if (need_surface) { if (egl->egl_surface != EGL_NO_SURFACE) { GST_INFO ("surface created"); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to create window surface: %s", gst_egl_get_error_string (eglGetError ())); goto failure; } } egl->egl_major = egl_major; egl->egl_minor = egl_minor; if (window) gst_object_unref (window); return TRUE; failure: if (window) gst_object_unref (window); return FALSE; }
static gboolean gst_gl_context_egl_create_context (GstGLContext * context, GstGLAPI gl_api, GstGLContext * other_context, GError ** error) { GstGLContextEGL *egl; GstGLWindow *window = NULL; EGLNativeWindowType window_handle = (EGLNativeWindowType) 0; gint i = 0; EGLint context_attrib[5]; EGLint majorVersion; EGLint minorVersion; const gchar *egl_exts; gboolean need_surface = TRUE; guintptr external_gl_context = 0; GstGLDisplay *display; egl = GST_GL_CONTEXT_EGL (context); window = gst_gl_context_get_window (context); if (other_context) { if (gst_gl_context_get_gl_platform (other_context) != GST_GL_PLATFORM_EGL) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Cannot share context with non-EGL context"); goto failure; } external_gl_context = gst_gl_context_get_gl_context (other_context); } if ((gl_api & (GST_GL_API_OPENGL | GST_GL_API_GLES2)) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "EGL supports opengl or gles2"); goto failure; } display = gst_gl_context_get_display (context); if (display->type == GST_GL_DISPLAY_TYPE_EGL) { egl->egl_display = (EGLDisplay) gst_gl_display_get_handle (display); } else { guintptr native_display = gst_gl_display_get_handle (display); if (!native_display) { GstGLWindow *window = NULL; GST_WARNING ("Failed to get a global display handle, falling back to " "per-window display handles. Context sharing may not work"); if (other_context) window = gst_gl_context_get_window (other_context); if (!window) window = gst_gl_context_get_window (context); if (window) { native_display = gst_gl_window_get_display (window); gst_object_unref (window); } } egl->egl_display = eglGetDisplay ((EGLNativeDisplayType) native_display); } gst_object_unref (display); if (eglInitialize (egl->egl_display, &majorVersion, &minorVersion)) { GST_INFO ("egl initialized, version: %d.%d", majorVersion, minorVersion); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Failed to initialize egl: %s", gst_gl_context_egl_get_error_string ()); goto failure; } if (gl_api & GST_GL_API_OPENGL) { /* egl + opengl only available with EGL 1.4+ */ if (majorVersion == 1 && minorVersion <= 3) { if ((gl_api & ~GST_GL_API_OPENGL) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_OLD_LIBS, "EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)", majorVersion, minorVersion); goto failure; } else { GST_WARNING ("EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)", majorVersion, minorVersion); if (gl_api & GST_GL_API_GLES2) { goto try_gles2; } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Failed to choose a suitable OpenGL API"); goto failure; } } } if (!eglBindAPI (EGL_OPENGL_API)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to bind OpenGL API: %s", gst_gl_context_egl_get_error_string ()); goto failure; } GST_INFO ("Using OpenGL"); egl->gl_api = GST_GL_API_OPENGL; } else if (gl_api & GST_GL_API_GLES2) { try_gles2: if (!eglBindAPI (EGL_OPENGL_ES_API)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to bind OpenGL|ES API: %s", gst_gl_context_egl_get_error_string ()); goto failure; } GST_INFO ("Using OpenGL|ES 2.0"); egl->gl_api = GST_GL_API_GLES2; } if (!gst_gl_context_egl_choose_config (egl, other_context, error)) { g_assert (error == NULL || *error != NULL); goto failure; } egl_exts = eglQueryString (egl->egl_display, EGL_EXTENSIONS); GST_DEBUG ("about to create gl context\n"); if (egl->gl_api & GST_GL_API_GLES2) { context_attrib[i++] = EGL_CONTEXT_CLIENT_VERSION; context_attrib[i++] = 2; } #if !defined(GST_DISABLE_GST_DEBUG) && defined(EGL_KHR_create_context) if (gst_gl_check_extension ("EGL_KHR_create_context", egl_exts)) { context_attrib[i++] = EGL_CONTEXT_FLAGS_KHR; context_attrib[i++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; } #endif context_attrib[i++] = EGL_NONE; egl->egl_context = eglCreateContext (egl->egl_display, egl->egl_config, (EGLContext) external_gl_context, context_attrib); #ifdef EGL_KHR_create_context if (egl->egl_context == EGL_NO_CONTEXT && egl->gl_api & GST_GL_API_GLES2 && eglGetError () != EGL_SUCCESS) { /* try without EGL_CONTEXT_FLAGS flags as it was added to * EGL_KHR_create_context for gles contexts */ int i; for (i = 0; i < G_N_ELEMENTS (context_attrib); i++) { if (context_attrib[i] == EGL_CONTEXT_FLAGS_KHR || context_attrib[i] == EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) context_attrib[i] = EGL_NONE; } egl->egl_context = eglCreateContext (egl->egl_display, egl->egl_config, (EGLContext) external_gl_context, context_attrib); } #endif if (egl->egl_context != EGL_NO_CONTEXT) { GST_INFO ("gl context created: %" G_GUINTPTR_FORMAT, (guintptr) egl->egl_context); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_CREATE_CONTEXT, "Failed to create a OpenGL context: %s", gst_gl_context_egl_get_error_string ()); goto failure; } if (other_context == NULL) { /* FIXME do we want a window vfunc ? */ #if GST_GL_HAVE_WINDOW_X11 if (GST_GL_IS_WINDOW_X11 (context->window)) { gst_gl_window_x11_create_window ((GstGLWindowX11 *) context->window); } #endif #if GST_GL_HAVE_WINDOW_WIN32 if (GST_GL_IS_WINDOW_WIN32 (context->window)) { gst_gl_window_win32_create_window ((GstGLWindowWin32 *) context->window); } #endif } if (window) window_handle = (EGLNativeWindowType) gst_gl_window_get_window_handle (window); if (window_handle) { egl->egl_surface = eglCreateWindowSurface (egl->egl_display, egl->egl_config, window_handle, NULL); } else if (!gst_gl_check_extension ("EGL_KHR_surfaceless_context", egl_exts)) { EGLint surface_attrib[7]; gint j = 0; /* FIXME: Width/height doesn't seem to matter but we can't leave them * at 0, otherwise X11 complains about BadValue */ surface_attrib[j++] = EGL_WIDTH; surface_attrib[j++] = 1; surface_attrib[j++] = EGL_HEIGHT; surface_attrib[j++] = 1; surface_attrib[j++] = EGL_LARGEST_PBUFFER; surface_attrib[j++] = EGL_TRUE; surface_attrib[j++] = EGL_NONE; egl->egl_surface = eglCreatePbufferSurface (egl->egl_display, egl->egl_config, surface_attrib); } else { egl->egl_surface = EGL_NO_SURFACE; need_surface = FALSE; } if (need_surface) { if (egl->egl_surface != EGL_NO_SURFACE) { GST_INFO ("surface created"); } else { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED, "Failed to create window surface: %s", gst_gl_context_egl_get_error_string ()); goto failure; } } /* EGLImage functions */ if (GST_GL_CHECK_GL_VERSION (majorVersion, minorVersion, 1, 5)) { egl->eglCreateImage = gst_gl_context_get_proc_address (context, "eglCreateImage"); egl->eglDestroyImage = gst_gl_context_get_proc_address (context, "eglDestroyImage"); } else if (gst_gl_check_extension ("EGL_KHR_image_base", egl_exts)) { egl->eglCreateImage = gst_gl_context_get_proc_address (context, "eglCreateImageKHR"); egl->eglDestroyImage = gst_gl_context_get_proc_address (context, "eglDestroyImageKHR"); } if (egl->eglCreateImage == NULL || egl->eglDestroyImage == NULL) { egl->eglCreateImage = NULL; egl->eglDestroyImage = NULL; } if (window) gst_object_unref (window); return TRUE; failure: if (window) gst_object_unref (window); return FALSE; }
gpointer gst_gl_context_egl_get_proc_address (GstGLAPI gl_api, const gchar * name) { gpointer result = NULL; static GOnce g_once = G_ONCE_INIT; #ifdef __APPLE__ #if GST_GL_HAVE_OPENGL && !defined(GST_GL_LIBGL_MODULE_NAME) if (!result && (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3))) { static GModule *module_opengl = NULL; if (g_once_init_enter (&module_opengl)) { GModule *setup_module_opengl = g_module_open ("libGL.dylib", G_MODULE_BIND_LAZY); g_once_init_leave (&module_opengl, setup_module_opengl); } if (module_opengl) g_module_symbol (module_opengl, name, &result); } #endif #if GST_GL_HAVE_GLES2 && !defined(GST_GL_LIBGLESV2_MODULE_NAME) if (!result && (gl_api & (GST_GL_API_GLES2))) { static GModule *module_gles2 = NULL; if (g_once_init_enter (&module_gles2)) { GModule *setup_module_gles2 = g_module_open ("libGLESv2.dylib", G_MODULE_BIND_LAZY); g_once_init_leave (&module_gles2, setup_module_gles2); } if (module_gles2) g_module_symbol (module_gles2, name, &result); } #endif #endif // __APPLE__ if (!result) result = gst_gl_context_default_get_proc_address (gl_api, name); g_once (&g_once, load_egl_module, NULL); if (!result && module_egl) { g_module_symbol (module_egl, name, &result); } /* FIXME: On Android this returns wrong addresses for non-EGL functions */ #if GST_GL_HAVE_WINDOW_ANDROID if (!result && g_str_has_prefix (name, "egl")) { #else if (!result) { result = eglGetProcAddress (name); #endif } return result; } static gboolean gst_gl_context_egl_check_feature (GstGLContext * context, const gchar * feature) { GstGLContextEGL *context_egl = GST_GL_CONTEXT_EGL (context); return gst_gl_check_extension (feature, context_egl->egl_exts); }