[vlc-devel] [PATCH 07/17] opengl: extract sampler creation and destruction
Romain Vimont
rom1v at videolabs.io
Thu Apr 2 14:24:20 CEST 2020
Extract sampler creation and destruction to separate functions.
---
modules/video_output/Makefile.am | 1 +
modules/video_output/opengl/renderer.c | 57 +------------
modules/video_output/opengl/sampler.c | 111 +++++++++++++++++++++++++
modules/video_output/opengl/sampler.h | 16 ++++
4 files changed, 130 insertions(+), 55 deletions(-)
create mode 100644 modules/video_output/opengl/sampler.c
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 1d25ea91a8..5e4b052bf8 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -15,6 +15,7 @@ OPENGL_COMMONSOURCES = video_output/opengl/vout_helper.c \
video_output/opengl/interop.c video_output/opengl/interop_sw.c \
video_output/opengl/renderer.c \
video_output/opengl/renderer.h \
+ video_output/opengl/sampler.c \
video_output/opengl/sampler.h \
video_output/opengl/sub_renderer.c \
video_output/opengl/sub_renderer.h
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 874490ac96..1295e9f237 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -404,27 +404,17 @@ error:
void
vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer)
{
- struct vlc_gl_interop *interop = renderer->interop;
- struct vlc_gl_sampler *sampler = renderer->sampler;
const opengl_vtable_t *vt = renderer->vt;
vt->DeleteBuffers(1, &renderer->vertex_buffer_object);
vt->DeleteBuffers(1, &renderer->index_buffer_object);
vt->DeleteBuffers(1, &renderer->texture_buffer_object);
- if (!interop->handle_texs_gen)
- vt->DeleteTextures(interop->tex_count, sampler->textures);
+ vlc_gl_sampler_Delete(renderer->sampler);
if (renderer->program_id != 0)
vt->DeleteProgram(renderer->program_id);
-#ifdef HAVE_LIBPLACEBO
- FREENULL(sampler->uloc.pl_vars);
- if (sampler->pl_ctx)
- pl_context_destroy(&sampler->pl_ctx);
-#endif
-
- free(renderer->sampler);
free(renderer);
}
@@ -437,12 +427,10 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
const opengl_vtable_t *vt = &api->vt;
const video_format_t *fmt = &interop->fmt;
- struct vlc_gl_sampler *sampler = calloc(1, sizeof(*sampler));
+ struct vlc_gl_sampler *sampler = vlc_gl_sampler_New(interop);
if (!sampler)
return NULL;
- sampler->interop = interop;
-
struct vlc_gl_renderer *renderer = calloc(1, sizeof(*renderer));
if (!renderer)
{
@@ -465,20 +453,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
renderer->glsl_precision_header = "";
#endif
-#ifdef HAVE_LIBPLACEBO
- // Create the main libplacebo context
- sampler->pl_ctx = vlc_placebo_Create(VLC_OBJECT(gl));
- if (sampler->pl_ctx) {
-# if PL_API_VER >= 20
- sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL);
-# elif PL_API_VER >= 6
- sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0);
-# else
- sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0, 0);
-# endif
- }
-#endif
-
int ret = opengl_link_program(renderer);
if (ret != VLC_SUCCESS)
{
@@ -494,33 +468,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
renderer->fmt = *fmt;
- /* Texture size */
- for (unsigned j = 0; j < interop->tex_count; j++) {
- const GLsizei w = renderer->fmt.i_visible_width * interop->texs[j].w.num
- / interop->texs[j].w.den;
- const GLsizei h = renderer->fmt.i_visible_height * interop->texs[j].h.num
- / interop->texs[j].h.den;
- if (api->supports_npot) {
- sampler->tex_width[j] = w;
- sampler->tex_height[j] = h;
- } else {
- sampler->tex_width[j] = vlc_align_pot(w);
- sampler->tex_height[j] = vlc_align_pot(h);
- }
- }
-
- if (!interop->handle_texs_gen)
- {
- ret = vlc_gl_interop_GenerateTextures(interop, sampler->tex_width,
- sampler->tex_height,
- sampler->textures);
- if (ret != VLC_SUCCESS)
- {
- vlc_gl_renderer_Delete(renderer);
- return NULL;
- }
- }
-
/* */
vt->Disable(GL_BLEND);
vt->Disable(GL_DEPTH_TEST);
diff --git a/modules/video_output/opengl/sampler.c b/modules/video_output/opengl/sampler.c
new file mode 100644
index 0000000000..5ae4eae018
--- /dev/null
+++ b/modules/video_output/opengl/sampler.c
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * sampler.c
+ *****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "sampler.h"
+
+#include <vlc_common.h>
+#include <vlc_es.h>
+#include <vlc_opengl.h>
+
+#ifdef HAVE_LIBPLACEBO
+#include <libplacebo/shaders.h>
+#include <libplacebo/shaders/colorspace.h>
+#include "../placebo_utils.h"
+#endif
+
+#include "gl_api.h"
+#include "gl_common.h"
+#include "gl_util.h"
+#include "interop.h"
+
+struct vlc_gl_sampler *
+vlc_gl_sampler_New(struct vlc_gl_interop *interop)
+{
+ struct vlc_gl_sampler *sampler = calloc(1, sizeof(*sampler));
+ if (!sampler)
+ return NULL;
+
+ sampler->interop = interop;
+
+#ifdef HAVE_LIBPLACEBO
+ // Create the main libplacebo context
+ sampler->pl_ctx = vlc_placebo_Create(VLC_OBJECT(interop->gl));
+ if (sampler->pl_ctx) {
+# if PL_API_VER >= 20
+ sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL);
+# elif PL_API_VER >= 6
+ sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0);
+# else
+ sampler->pl_sh = pl_shader_alloc(sampler->pl_ctx, NULL, 0, 0);
+# endif
+ }
+#endif
+
+ /* Texture size */
+ for (unsigned j = 0; j < interop->tex_count; j++) {
+ const GLsizei w = interop->fmt.i_visible_width * interop->texs[j].w.num
+ / interop->texs[j].w.den;
+ const GLsizei h = interop->fmt.i_visible_height * interop->texs[j].h.num
+ / interop->texs[j].h.den;
+ if (interop->api->supports_npot) {
+ sampler->tex_width[j] = w;
+ sampler->tex_height[j] = h;
+ } else {
+ sampler->tex_width[j] = vlc_align_pot(w);
+ sampler->tex_height[j] = vlc_align_pot(h);
+ }
+ }
+
+ if (!interop->handle_texs_gen)
+ {
+ int ret = vlc_gl_interop_GenerateTextures(interop, sampler->tex_width,
+ sampler->tex_height,
+ sampler->textures);
+ if (ret != VLC_SUCCESS)
+ {
+ free(sampler);
+ return NULL;
+ }
+ }
+
+ return sampler;
+}
+
+void
+vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler)
+{
+ struct vlc_gl_interop *interop = sampler->interop;
+ const opengl_vtable_t *vt = interop->vt;
+
+ if (!interop->handle_texs_gen)
+ vt->DeleteTextures(interop->tex_count, sampler->textures);
+
+#ifdef HAVE_LIBPLACEBO
+ FREENULL(sampler->uloc.pl_vars);
+ if (sampler->pl_ctx)
+ pl_context_destroy(&sampler->pl_ctx);
+#endif
+
+ free(sampler);
+}
diff --git a/modules/video_output/opengl/sampler.h b/modules/video_output/opengl/sampler.h
index 88cf7b4b2f..64e5e30e1f 100644
--- a/modules/video_output/opengl/sampler.h
+++ b/modules/video_output/opengl/sampler.h
@@ -89,4 +89,20 @@ struct vlc_gl_sampler {
struct vlc_gl_interop *interop;
};
+/**
+ * Create a new sampler
+ *
+ * \param interop the interop
+ */
+struct vlc_gl_sampler *
+vlc_gl_sampler_New(struct vlc_gl_interop *interop);
+
+/**
+ * Delete a sampler
+ *
+ * \param sampler the sampler
+ */
+void
+vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler);
+
#endif
--
2.26.0
More information about the vlc-devel
mailing list