[vlc-devel] [PATCH] opengl: replace GetAlignSize() by vlc_align_pot()

Romain Vimont rom1v at videolabs.io
Wed Jan 29 12:10:18 CET 2020


This function is very general, and will be called from other files.
---
 include/vlc_common.h                      |  8 ++++++++
 modules/video_output/opengl/vout_helper.c | 15 ++++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index e4c5cd85c9..875c3df0cf 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -740,6 +740,14 @@ VLC_USED static inline int vlc_popcount(unsigned long long x)
 }
 #endif
 
+/** Return the smallest larger or equal power of 2 */
+VLC_USED
+static inline int vlc_align_pot(unsigned x)
+{
+    unsigned align = 1 << (8 * sizeof (unsigned) - vlc_clz(x));
+    return ((align >> 1) == x) ? x : align;
+}
+
 /** Byte swap (16 bits) */
 VLC_USED
 static inline uint16_t vlc_bswap16(uint16_t x)
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index a375c9f99a..8d1cd97bc2 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -264,13 +264,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)
 {
@@ -787,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);
         }
     }
 
@@ -987,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.25.0



More information about the vlc-devel mailing list