static void _set_window_handle_cb (GstSetWindowHandleCb * data) { GstGLContext *context = gst_gl_window_get_context (data->window); GstGLWindowClass *window_class = GST_GL_WINDOW_GET_CLASS (data->window); GThread *thread = NULL; /* deactivate if necessary */ if (context) { thread = gst_gl_context_get_thread (context); if (thread) { /* This is only thread safe iff the context thread == g_thread_self() */ g_assert (thread == g_thread_self ()); gst_gl_context_activate (context, FALSE); } } window_class->set_window_handle (data->window, data->handle); /* reactivate */ if (context && thread) gst_gl_context_activate (context, TRUE); if (context) gst_object_unref (context); if (thread) g_thread_unref (thread); }
static void check_wrapped (gpointer data) { GstGLContext *wrapped_context = data; GError *error = NULL; gint i = 0; gboolean ret; /* check that scheduling on an unactivated wrapped context asserts */ ASSERT_CRITICAL (gst_gl_context_thread_add (wrapped_context, (GstGLContextThreadFunc) accum_true, &i)); fail_if (i != 0); /* check that scheduling on an activated context succeeds */ gst_gl_context_activate (wrapped_context, TRUE); gst_gl_context_thread_add (wrapped_context, (GstGLContextThreadFunc) accum_true, &i); fail_if (i != 1); /* check filling out the wrapped context's info */ fail_if (wrapped_context->gl_vtable->TexImage2D != NULL); ret = gst_gl_context_fill_info (wrapped_context, &error); fail_if (!ret, "error received %s\n", error ? error->message : "Unknown error"); fail_if (wrapped_context->gl_vtable->TexImage2D == NULL); gst_gl_context_activate (wrapped_context, FALSE); }
GstGLContext * gst_gl_context_gpu_process_new (GstGLDisplay * display, GstGLAPI gl_api, GstGLProcAddrFunc proc_addr) { GstGLContext *context = NULL; GstGLContextGPUProcess *gpu_context = NULL; GstGLContextClass *context_class = NULL; GstGLWindow *window = NULL; GError *error = NULL; g_return_val_if_fail ((gst_gl_display_get_gl_api (display) & gl_api) != GST_GL_API_NONE, NULL); gpu_context = g_object_new (GST_GL_TYPE_CONTEXT_GPU_PROCESS, NULL); gpu_context->priv->gl_api = gl_api; context = GST_GL_CONTEXT (gpu_context); context->display = display; gst_gl_display_add_context (display, context); context_class = GST_GL_CONTEXT_GET_CLASS (context); context_class->get_current_context = NULL; context_class->get_proc_address = GST_DEBUG_FUNCPTR (proc_addr); gst_gl_context_activate (context, TRUE); gst_gl_context_fill_info (context, &error); if (error) { GST_ERROR_OBJECT (context, "Failed to create gpu process context: %s", error->message); g_error_free (error); gst_object_unref (context); return NULL; } window = GST_GL_WINDOW (gst_gl_window_gpu_process_new (display)); gst_gl_context_set_window (context, window); GST_GL_WINDOW_GET_CLASS (window)->open (window, NULL); gst_object_unref (window); return context; }
//gboolean //gst_gl_context_create (GstGLContext * context, GstGLContext * other_context, GError ** error) static gpointer gst_gl_context_create_thread (GstGLContext * context) { GstGLContextClass *context_class; GstGLWindowClass *window_class; GstGLFuncs *gl; GstGLAPI compiled_api, user_api, gl_api, display_api; gchar *api_string; gchar *compiled_api_s; gchar *user_api_s; gchar *display_api_s; const gchar *user_choice; GError **error; GstGLContext *other_context; g_mutex_lock (&context->priv->render_lock); GST_DEBUG_OBJECT (context, "Creating thread"); error = context->priv->error; other_context = g_weak_ref_get (&context->priv->other_context_ref); context_class = GST_GL_CONTEXT_GET_CLASS (context); window_class = GST_GL_WINDOW_GET_CLASS (context->window); display_api = gst_gl_display_get_gl_api_unlocked (context->display); if (display_api == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "Cannot create context with satisfying requested apis " "(display has no GL api!)"); goto failure; } if (window_class->open) { if (!window_class->open (context->window, error)) { GST_WARNING_OBJECT (context, "Failed to open window"); g_assert (error == NULL || *error != NULL); goto failure; } } gl = context->gl_vtable; compiled_api = _compiled_api (); compiled_api_s = gst_gl_api_to_string (compiled_api); user_choice = g_getenv ("GST_GL_API"); user_api = gst_gl_api_from_string (user_choice); user_api_s = gst_gl_api_to_string (user_api); display_api_s = gst_gl_api_to_string (display_api); if ((user_api & compiled_api & display_api) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "Cannot create context with the user requested api (%s). " "We have support for (%s), display api (%s)", user_api_s, compiled_api_s, display_api_s); g_free (user_api_s); g_free (compiled_api_s); g_free (display_api_s); goto failure; } if (context_class->choose_format && !context_class->choose_format (context, error)) { GST_WARNING_OBJECT (context, "Failed to choose format"); g_assert (error == NULL || *error != NULL); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } GST_INFO_OBJECT (context, "Attempting to create opengl context. user chosen api(s) (%s), " "compiled api support (%s) display api (%s)", user_api_s, compiled_api_s, display_api_s); if (!context_class->create_context (context, compiled_api & user_api & display_api, other_context, error)) { GST_WARNING_OBJECT (context, "Failed to create context"); g_assert (error == NULL || *error != NULL); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } GST_INFO_OBJECT (context, "created context"); if (!gst_gl_context_activate (context, TRUE)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Failed to activate the GL Context"); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } gl_api = gst_gl_context_get_gl_api (context); g_assert (gl_api != GST_GL_API_NONE && gl_api != GST_GL_API_ANY); api_string = gst_gl_api_to_string (gl_api); GST_INFO_OBJECT (context, "available GL APIs: %s", api_string); if (((compiled_api & gl_api & display_api) & user_api) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "failed to create context, context " "could not provide correct api. user (%s), compiled (%s), context (%s)", user_api_s, compiled_api_s, api_string); g_free (api_string); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } g_free (api_string); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); GST_DEBUG_OBJECT (context, "Filling info"); if (!gst_gl_context_fill_info (context, error)) { g_assert (error == NULL || *error != NULL); goto failure; } context->priv->alive = TRUE; if (gl->DebugMessageCallback) { #if !defined(GST_DISABLE_GST_DEBUG) GST_INFO_OBJECT (context, "Enabling GL context debugging"); /* enable them all */ gl->DebugMessageControl (GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE); gl->DebugMessageCallback (_gst_gl_debug_callback, context); #endif } if (other_context) { GST_DEBUG_OBJECT (context, "Unreffing other_context %" GST_PTR_FORMAT, other_context); gst_object_unref (other_context); } g_cond_signal (&context->priv->create_cond); // g_mutex_unlock (&context->priv->render_lock); gst_gl_window_send_message_async (context->window, (GstGLWindowCB) _unlock_create_thread, context, NULL); gst_gl_window_run (context->window); GST_INFO_OBJECT (context, "loop exited"); g_mutex_lock (&context->priv->render_lock); context->priv->alive = FALSE; gst_gl_context_activate (context, FALSE); context_class->destroy_context (context); /* User supplied callback */ if (context->window->close) context->window->close (context->window->close_data); /* window specific shutdown */ if (window_class->close) { window_class->close (context->window); } g_cond_signal (&context->priv->destroy_cond); g_mutex_unlock (&context->priv->render_lock); return NULL; failure: { if (other_context) gst_object_unref (other_context); g_cond_signal (&context->priv->create_cond); g_mutex_unlock (&context->priv->render_lock); return NULL; } }