<commit_before>/*
 * GStreamer
 * Copyright (C) 2008 <NAME> <<EMAIL>>
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 *
 * 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

#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,
    GST_GL_TYPE_WINDOW);

static guintptr gst_gl_window_android_egl_get_gl_context (GstGLWindow * window);
static gboolean gst_gl_window_android_egl_activate (GstGLWindow * window,
    gboolean activate);
static void gst_gl_window_android_egl_set_window_handle (GstGLWindow * window,
    guintptr handle);
static void gst_gl_window_android_egl_draw (GstGLWindow * window, guint width,
    guint height);
static void gst_gl_window_android_egl_run (GstGLWindow * window);
static void gst_gl_window_android_egl_quit (GstGLWindow * window,
    GstGLWindowCB callback, gpointer data);
static void gst_gl_window_android_egl_send_message (GstGLWindow * window,
    GstGLWindowCB callback, gpointer data);
static void gst_gl_window_android_egl_destroy_context (GstGLWindowAndroidEGL *
    window_egl);
static gboolean gst_gl_window_android_egl_create_context (GstGLWindow
    * window, GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
static GstGLAPI gst_gl_window_android_egl_get_gl_api (GstGLWindow * window);
static gpointer gst_gl_window_android_egl_get_proc_address (GstGLWindow *
    window, const gchar * name);
static void gst_gl_window_android_egl_close (GstGLWindow * window);

static void
gst_gl_window_android_egl_class_init (GstGLWindowAndroidEGLClass * klass)
{
  GstGLWindowClass *window_class = (GstGLWindowClass *) klass;

  window_class->create_context =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_create_context);
  window_class->get_gl_context =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_gl_context);
  window_class->activate =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_activate);
  window_class->set_window_handle =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_set_window_handle);
  window_class->draw_unlocked =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_draw);
  window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_draw);
  window_class->run = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_run);
  window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_quit);
  window_class->send_message =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_send_message);
  window_class->get_gl_api =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_gl_api);
  window_class->get_proc_address =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_proc_address);
  window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_close);
}

static void
gst_gl_window_android_egl_init (GstGLWindowAndroidEGL * window)
{
}

/* Must be called in the gl thread */
GstGLWindowAndroidEGL *
gst_gl_window_android_egl_new (void)
{
  GstGLWindowAndroidEGL *window;

  GST_DEBUG ("creating Android EGL window");

  window = g_object_new (GST_GL_TYPE_WINDOW_ANDROID_EGL, NULL);

  gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);

  return window;
}

static void
gst_gl_window_android_egl_close (GstGLWindow * window)
{
  GstGLWindowAndroidEGL *window_egl;

  window_egl = GST_GL_WINDOW_ANDROID_EGL (window);

  gst_gl_window_android_egl_destroy_context (window_egl);
}

gboolean
gst_gl_window_android_egl_create_context (GstGLWindow * window,
    GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{
  GstGLWindowAndroidEGL *window_egl = GST_GL_WINDOW_ANDROID_EGL (window);

  if (!window_egl->native_window) {
    g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_CONFIG,
        "No native window set");
    return FALSE;
  }

  window_egl->main_context = g_main_context_new ();
  window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE);

  window_egl->egl =
      gst_gl_egl_create_context (eglGetDisplay (EGL_DEFAULT_DISPLAY),
      window_egl->native_window, gl_api, external_gl_context, error);
  if (!window_egl->egl)
    goto failure;

  return TRUE;

failure:
  return FALSE;
}

static void
gst_gl_window_android_egl_destroy_context (GstGLWindowAndroidEGL * window_egl)
{
  gst_gl_egl_activate (window_egl->egl, FALSE);
  gst_gl_egl_destroy_context (window_egl->egl);
  window_egl->egl = NULL;<commit_msg>android: Don't require a window to be set<commit_after>/*
 * GStreamer
 * Copyright (C) 2008 <NAME> <<EMAIL>>
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 * Copyright (C) 2013 <NAME> <<EMAIL>>
 *
 * 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

#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,
    GST_GL_TYPE_WINDOW);

static guintptr gst_gl_window_android_egl_get_gl_context (GstGLWindow * window);
static gboolean gst_gl_window_android_egl_activate (GstGLWindow * window,
    gboolean activate);
static void gst_gl_window_android_egl_set_window_handle (GstGLWindow * window,
    guintptr handle);
static void gst_gl_window_android_egl_draw (GstGLWindow * window, guint width,
    guint height);
static void gst_gl_window_android_egl_run (GstGLWindow * window);
static void gst_gl_window_android_egl_quit (GstGLWindow * window,
    GstGLWindowCB callback, gpointer data);
static void gst_gl_window_android_egl_send_message (GstGLWindow * window,
    GstGLWindowCB callback, gpointer data);
static void gst_gl_window_android_egl_destroy_context (GstGLWindowAndroidEGL *
    window_egl);
static gboolean gst_gl_window_android_egl_create_context (GstGLWindow
    * window, GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
static GstGLAPI gst_gl_window_android_egl_get_gl_api (GstGLWindow * window);
static gpointer gst_gl_window_android_egl_get_proc_address (GstGLWindow *
    window, const gchar * name);
static void gst_gl_window_android_egl_close (GstGLWindow * window);

static void
gst_gl_window_android_egl_class_init (GstGLWindowAndroidEGLClass * klass)
{
  GstGLWindowClass *window_class = (GstGLWindowClass *) klass;

  window_class->create_context =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_create_context);
  window_class->get_gl_context =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_gl_context);
  window_class->activate =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_activate);
  window_class->set_window_handle =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_set_window_handle);
  window_class->draw_unlocked =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_draw);
  window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_draw);
  window_class->run = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_run);
  window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_quit);
  window_class->send_message =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_send_message);
  window_class->get_gl_api =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_gl_api);
  window_class->get_proc_address =
      GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_proc_address);
  window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_close);
}

static void
gst_gl_window_android_egl_init (GstGLWindowAndroidEGL * window)
{
}

/* Must be called in the gl thread */
GstGLWindowAndroidEGL *
gst_gl_window_android_egl_new (void)
{
  GstGLWindowAndroidEGL *window;

  GST_DEBUG ("creating Android EGL window");

  window = g_object_new (GST_GL_TYPE_WINDOW_ANDROID_EGL, NULL);

  gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);

  return window;
}

static void
gst_gl_window_android_egl_close (GstGLWindow * window)
{
  GstGLWindowAndroidEGL *window_egl;

  window_egl = GST_GL_WINDOW_ANDROID_EGL (window);

  gst_gl_window_android_egl_destroy_context (window_egl);
}

gboolean
gst_gl_window_android_egl_create_context (GstGLWindow * window,
    GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{
  GstGLWindowAndroidEGL *window_egl = GST_GL_WINDOW_ANDROID_EGL (window);

  window_egl->main_context = g_main_context_new ();
  window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE);

  window_egl->egl =
      gst_gl_egl_create_context (eglGetDisplay (EGL_DEFAULT_DISPLAY),
      window_egl->native_window, gl_api, external_gl_context, error);
  if (!window_egl->egl)
    goto failure;

  return TRUE;

failure:
  return FALSE;
}

static void
gst_gl_window_android_egl_destroy_context (GstGLWindowAndroidEGL * window_egl)
{
  gst_gl_egl_activate (window_egl->egl, FALSE);
  gst_gl_egl_destroy_context (window_egl->egl);
  window_egl->egl = NULL;
{'fraction_non_alphanumeric': 0.07106598984771574, 'fraction_numerical': 0.004597260798774064, 'mean_word_length': 6.055405405405406, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3011617', 'n_tokens_mistral': 3817, 'n_tokens_neox': 3725, 'n_words': 782}