*/
struct vout_window_t;
+struct vout_window_cfg_t;
/**
* A VLC GL context (and its underlying surface)
return (gl->getProcAddress != NULL) ? gl->getProcAddress(gl, name) : NULL;
}
+VLC_API vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *,
+ const struct vout_window_cfg_t *,
+ struct vout_window_t **) VLC_USED;
+VLC_API bool vlc_gl_surface_CheckSize(vlc_gl_t *, unsigned *w, unsigned *h);
+VLC_API void vlc_gl_surface_Destroy(vlc_gl_t *);
+
#endif /* VLC_GL_H */
# include <config.h>
#endif
+#include <assert.h>
+#include <stdlib.h>
+
#include <vlc_common.h>
#include <vlc_opengl.h>
#include "libvlc.h"
module_unneed(gl, gl->module);
vlc_object_release(gl);
}
+
+#include <vlc_vout_window.h>
+
+typedef struct vlc_gl_surface
+{
+ int width;
+ int height;
+ vlc_mutex_t lock;
+} vlc_gl_surface_t;
+
+static void vlc_gl_surface_ResizeNotify(vout_window_t *surface,
+ unsigned width, unsigned height)
+{
+ vlc_gl_surface_t *sys = surface->owner.sys;
+
+ msg_Dbg(surface, "resized to %ux%u", width, height);
+
+ vlc_mutex_lock(&sys->lock);
+ sys->width = width;
+ sys->height = height;
+ vlc_mutex_unlock(&sys->lock);
+}
+
+vlc_gl_t *vlc_gl_surface_Create(vlc_object_t *obj,
+ const vout_window_cfg_t *cfg,
+ struct vout_window_t **restrict wp)
+{
+ vlc_gl_surface_t *sys = malloc(sizeof (*sys));
+ if (unlikely(sys == NULL))
+ return NULL;
+
+ sys->width = cfg->width;
+ sys->height = cfg->height;
+ vlc_mutex_init(&sys->lock);
+
+ vout_window_owner_t owner = {
+ .sys = sys,
+ .resized = vlc_gl_surface_ResizeNotify,
+ };
+
+ vout_window_t *surface = vout_window_New(obj, "$window", cfg, &owner);
+ if (surface == NULL)
+ goto error;
+ if (wp != NULL)
+ *wp = surface;
+
+ /* TODO: support ES? */
+ vlc_gl_t *gl = vlc_gl_Create(surface, VLC_OPENGL, "glx");
+ if (gl == NULL) {
+ vout_window_Delete(surface);
+ goto error;
+ }
+ return gl;
+
+error:
+ vlc_mutex_destroy(&sys->lock);
+ free(sys);
+ return NULL;
+}
+
+/**
+ * Checks if the dimensions of the surface used by the OpenGL context have
+ * changed (since the previous call), and the OpenGL viewport should be
+ * updated.
+ * \return true if at least one dimension has changed, false otherwise
+ * \warning This function is intrinsically race-prone.
+ * The dimensions can change asynchronously.
+ */
+bool vlc_gl_surface_CheckSize(vlc_gl_t *gl, unsigned *restrict width,
+ unsigned *restrict height)
+{
+ vout_window_t *surface = gl->surface;
+ vlc_gl_surface_t *sys = surface->owner.sys;
+ bool ret = false;
+
+ vlc_mutex_lock(&sys->lock);
+ if (sys->width >= 0 && sys->height >= 0)
+ {
+ *width = sys->width;
+ *height = sys->height;
+ sys->width = -1;
+ sys->height = -1;
+ ret = true;
+ }
+ vlc_mutex_unlock(&sys->lock);
+ return ret;
+}
+
+void vlc_gl_surface_Destroy(vlc_gl_t *gl)
+{
+ vout_window_t *surface = gl->surface;
+ vlc_gl_surface_t *sys = surface->owner.sys;
+
+ vlc_gl_Destroy(gl);
+ vout_window_Delete(surface);
+ vlc_mutex_destroy(&sys->lock);
+ free(sys);
+}