From b2d300c68a74fbec5118e3602e8ea0f9006b5eac Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 21 Jan 2020 13:43:58 +0100 Subject: [PATCH] opengl: expose GetAlignedSize() Expose a function to align a value to the next power of 2. It will be called from other files. Signed-off-by: Jean-Baptiste Kempf --- modules/video_output/Makefile.am | 4 +++- modules/video_output/opengl/gl_util.h | 37 +++++++++++++++++++++++++++++++ modules/video_output/opengl/vout_helper.c | 16 +++++-------- 3 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 modules/video_output/opengl/gl_util.h diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am index 4b1ac77747..9ba1a9b8a8 100644 --- a/modules/video_output/Makefile.am +++ b/modules/video_output/Makefile.am @@ -4,7 +4,9 @@ vout_LTLIBRARIES = EXTRA_DIST += video_output/README OPENGL_COMMONSOURCES = video_output/opengl/vout_helper.c \ - video_output/opengl/gl_common.h video_output/opengl/interop.h \ + video_output/opengl/gl_common.h \ + video_output/opengl/gl_util.h \ + video_output/opengl/interop.h \ video_output/opengl/vout_helper.h video_output/opengl/converter.h \ video_output/opengl/internal.h video_output/opengl/fragment_shaders.c \ video_output/opengl/interop.c video_output/opengl/interop_sw.c diff --git a/modules/video_output/opengl/gl_util.h b/modules/video_output/opengl/gl_util.h new file mode 100644 index 0000000000..21734aae21 --- /dev/null +++ b/modules/video_output/opengl/gl_util.h @@ -0,0 +1,37 @@ +/***************************************************************************** + * gl_util.h + ***************************************************************************** + * 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. + *****************************************************************************/ + +#ifndef VLC_GL_UTIL_H +#define VLC_GL_UTIL_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +/** Return the smallest larger or equal power of 2 */ +static inline unsigned vlc_align_pot(unsigned x) +{ + unsigned align = 1 << (8 * sizeof (unsigned) - vlc_clz(x)); + return ((align >> 1) == x) ? x : align; +} + +#endif diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c index 71646b5dde..8a461a3443 100644 --- a/modules/video_output/opengl/vout_helper.c +++ b/modules/video_output/opengl/vout_helper.c @@ -39,6 +39,7 @@ #include #include +#include "gl_util.h" #include "vout_helper.h" #include "internal.h" @@ -264,13 +265,6 @@ static void getOrientationTransformMatrix(video_orientation_t orientation, } } -static inline GLsizei GetAlignedSize(unsigned size) -{ - /* Return the smallest larger or equal power of 2 */ - unsigned align = 1 << (8 * sizeof (unsigned) - clz(size)); - return ((align >> 1) == size) ? size : align; -} - static GLuint BuildVertexShader(const opengl_tex_converter_t *tc, unsigned plane_count) { @@ -786,8 +780,8 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt, vgl->tex_width[j] = w; vgl->tex_height[j] = h; } else { - vgl->tex_width[j] = GetAlignedSize(w); - vgl->tex_height[j] = GetAlignedSize(h); + vgl->tex_width[j] = vlc_align_pot(w); + vgl->tex_height[j] = vlc_align_pot(h); } } @@ -986,8 +980,8 @@ vout_display_opengl_PrepareSubPicture(vout_display_opengl_t *vgl, glr->width = r->fmt.i_visible_width; glr->height = r->fmt.i_visible_height; if (!vgl->supports_npot) { - glr->width = GetAlignedSize(glr->width); - glr->height = GetAlignedSize(glr->height); + glr->width = vlc_align_pot(glr->width); + glr->height = vlc_align_pot(glr->height); glr->tex_width = (float) r->fmt.i_visible_width / glr->width; glr->tex_height = (float) r->fmt.i_visible_height / glr->height; } else { -- 2.11.4.GIT