2013-07-10 09:31:17 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
|
|
|
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
|
|
|
|
* Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: - Window resize handling
|
|
|
|
* - Event handling input event handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-10-01 13:47:54 +00:00
|
|
|
#include <gst/gst.h>
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-04-13 14:40:58 +00:00
|
|
|
#include <gst/gl/egl/gstglcontext_egl.h>
|
2013-07-10 09:31:17 +00:00
|
|
|
#include "gstglwindow_android_egl.h"
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_debug
|
|
|
|
|
|
|
|
#define gst_gl_window_android_egl_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstGLWindowAndroidEGL, gst_gl_window_android_egl,
|
2016-10-05 01:19:12 +00:00
|
|
|
GST_TYPE_GL_WINDOW);
|
2013-07-10 09:31:17 +00:00
|
|
|
|
2013-10-01 13:47:54 +00:00
|
|
|
static guintptr gst_gl_window_android_egl_get_display (GstGLWindow * window);
|
2013-08-21 03:57:56 +00:00
|
|
|
static guintptr gst_gl_window_android_egl_get_window_handle (GstGLWindow *
|
|
|
|
window);
|
2013-07-10 09:31:17 +00:00
|
|
|
static void gst_gl_window_android_egl_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle);
|
2015-01-23 03:11:48 +00:00
|
|
|
static void gst_gl_window_android_egl_draw (GstGLWindow * window);
|
2013-07-10 09:31:17 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_class_init (GstGLWindowAndroidEGLClass * klass)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
|
|
|
|
2013-10-01 13:47:54 +00:00
|
|
|
window_class->get_display =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_display);
|
2013-08-21 03:57:56 +00:00
|
|
|
window_class->get_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_window_handle);
|
2013-07-10 09:31:17 +00:00
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_set_window_handle);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_draw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_init (GstGLWindowAndroidEGL * window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
|
|
|
GstGLWindowAndroidEGL *
|
2015-07-24 07:00:27 +00:00
|
|
|
gst_gl_window_android_egl_new (GstGLDisplay * display)
|
2013-07-10 09:31:17 +00:00
|
|
|
{
|
2015-07-24 07:00:27 +00:00
|
|
|
if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_EGL) == 0)
|
|
|
|
/* we require an egl display to create android windows */
|
|
|
|
return NULL;
|
2013-07-10 09:31:17 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("creating Android EGL window");
|
|
|
|
|
2016-10-05 01:19:12 +00:00
|
|
|
return g_object_new (GST_TYPE_GL_WINDOW_ANDROID_EGL, NULL);
|
2013-07-10 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle)
|
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
|
|
|
window_egl->native_window = (EGLNativeWindowType) handle;
|
|
|
|
}
|
|
|
|
|
2013-08-21 03:57:56 +00:00
|
|
|
static guintptr
|
|
|
|
gst_gl_window_android_egl_get_window_handle (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
|
|
|
return (guintptr) window_egl->native_window;
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:31:17 +00:00
|
|
|
static void
|
|
|
|
draw_cb (gpointer data)
|
|
|
|
{
|
2015-01-23 03:11:48 +00:00
|
|
|
GstGLWindowAndroidEGL *window_egl = data;
|
2013-07-10 09:31:17 +00:00
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_egl);
|
2013-10-01 13:47:54 +00:00
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
2014-04-13 14:40:58 +00:00
|
|
|
GstGLContextEGL *context_egl = GST_GL_CONTEXT_EGL (context);
|
2013-10-01 13:47:54 +00:00
|
|
|
GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
2013-07-10 09:31:17 +00:00
|
|
|
|
2014-04-13 14:40:58 +00:00
|
|
|
if (context_egl->egl_surface) {
|
|
|
|
gint width, height;
|
2016-01-21 22:13:36 +00:00
|
|
|
guint window_width, window_height;
|
2015-09-17 07:06:37 +00:00
|
|
|
|
|
|
|
gst_gl_window_get_surface_dimensions (window, &window_width,
|
|
|
|
&window_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)
|
|
|
|
&& (window->queue_resize || width != window_egl->window_width
|
2014-04-13 14:40:58 +00:00
|
|
|
|| height != window_egl->window_height)) {
|
2015-09-17 07:06:37 +00:00
|
|
|
gst_gl_window_resize (window, width, height);
|
2014-04-13 14:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:31:17 +00:00
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
|
|
|
|
2013-08-21 03:57:56 +00:00
|
|
|
context_class->swap_buffers (context);
|
2013-10-01 13:47:54 +00:00
|
|
|
|
|
|
|
gst_object_unref (context);
|
2013-07-10 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-23 03:11:48 +00:00
|
|
|
gst_gl_window_android_egl_draw (GstGLWindow * window)
|
2013-07-10 09:31:17 +00:00
|
|
|
{
|
2015-01-23 03:11:48 +00:00
|
|
|
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, window);
|
2013-07-10 09:31:17 +00:00
|
|
|
}
|
2013-10-01 13:47:54 +00:00
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_window_android_egl_get_display (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|