[vlc-commits] opengl: converters: change chroma directly in fmt

Thomas Guillem git at videolan.org
Wed May 17 15:04:35 CEST 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed May 17 13:59:43 2017 +0200| [c45ece9738348df00f5e4663c3e35fb5be2fff7d] | committer: Thomas Guillem

opengl: converters: change chroma directly in fmt

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c45ece9738348df00f5e4663c3e35fb5be2fff7d
---

 modules/video_output/opengl/converter_android.c |  4 +--
 modules/video_output/opengl/converter_cvpx.c    |  4 +--
 modules/video_output/opengl/converters.c        | 41 +++++++++++++++++--------
 modules/video_output/opengl/internal.h          | 14 ++++-----
 modules/video_output/opengl/vout_helper.c       | 28 ++++-------------
 5 files changed, 43 insertions(+), 48 deletions(-)

diff --git a/modules/video_output/opengl/converter_android.c b/modules/video_output/opengl/converter_android.c
index 3e0f03c0da..6814e2c359 100644
--- a/modules/video_output/opengl/converter_android.c
+++ b/modules/video_output/opengl/converter_android.c
@@ -193,8 +193,7 @@ tc_anop_release(const opengl_tex_converter_t *tc)
 }
 
 GLuint
-opengl_tex_converter_anop_init(const video_format_t *fmt,
-                               opengl_tex_converter_t *tc)
+opengl_tex_converter_anop_init(video_format_t *fmt, opengl_tex_converter_t *tc)
 {
     if (fmt->i_chroma != VLC_CODEC_ANDROID_OPAQUE
      || !tc->gl->surface->handle.anativewindow)
@@ -219,7 +218,6 @@ opengl_tex_converter_anop_init(const video_format_t *fmt,
     tc->tex_count = 1;
     tc->texs[0] = (struct opengl_tex_cfg) { { 1, 1 }, { 1, 1 } };
 
-    tc->chroma       = VLC_CODEC_ANDROID_OPAQUE;
     tc->tex_target   = GL_TEXTURE_EXTERNAL_OES;
 
     /* The transform Matrix (uSTMatrix) given by the SurfaceTexture is not
diff --git a/modules/video_output/opengl/converter_cvpx.c b/modules/video_output/opengl/converter_cvpx.c
index 6823d922c3..bf070054e0 100644
--- a/modules/video_output/opengl/converter_cvpx.c
+++ b/modules/video_output/opengl/converter_cvpx.c
@@ -229,8 +229,7 @@ tc_cvpx_release(const opengl_tex_converter_t *tc)
 }
 
 GLuint
-opengl_tex_converter_cvpx_init(const video_format_t *fmt,
-                               opengl_tex_converter_t *tc)
+opengl_tex_converter_cvpx_init(video_format_t *fmt, opengl_tex_converter_t *tc)
 {
     if (fmt->i_chroma != VLC_CODEC_CVPX_UYVY
      && fmt->i_chroma != VLC_CODEC_CVPX_NV12
@@ -308,7 +307,6 @@ opengl_tex_converter_cvpx_init(const video_format_t *fmt,
     }
 
     tc->priv              = priv;
-    tc->chroma            = fmt->i_chroma;
     tc->pf_get_pool       = tc_cvpx_get_pool;
     tc->pf_update         = tc_cvpx_update;
     tc->pf_release        = tc_cvpx_release;
diff --git a/modules/video_output/opengl/converters.c b/modules/video_output/opengl/converters.c
index 72195eeefe..e4b4e48e4c 100644
--- a/modules/video_output/opengl/converters.c
+++ b/modules/video_output/opengl/converters.c
@@ -264,7 +264,6 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
             tc->yuv_coefficients[i*4+j] = j < 3 ? correction * matrix[j*4+i] : 0.f;
     }
 
-    tc->chroma = chroma;
     tc->yuv_color = true;
 
     *swap_uv = chroma == VLC_CODEC_YV12 || chroma == VLC_CODEC_YV9 ||
@@ -273,15 +272,14 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
 }
 
 static int
-tc_rgba_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
-                  vlc_fourcc_t chroma)
+tc_rgb_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
+                 vlc_fourcc_t chroma)
 {
     (void) tex_target;
 
-    if (chroma != VLC_CODEC_RGBA && chroma != VLC_CODEC_RGB32)
+    if (chroma != VLC_CODEC_RGB32)
         return VLC_EGENERIC;
 
-    tc->chroma = VLC_CODEC_RGBA;
     tc->tex_count = 1;
     tc->texs[0] = (struct opengl_tex_cfg) {
         { 1, 1 }, { 1, 1 }, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE
@@ -361,7 +359,7 @@ opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target,
         ret = tc_yuv_base_init(tc, tex_target, chroma, yuv_space,
                                &yuv_swap_uv, swizzle_per_tex);
     else
-        ret = tc_rgba_base_init(tc, tex_target, chroma);
+        ret = tc_rgb_base_init(tc, tex_target, chroma);
 
     if (ret != VLC_SUCCESS)
         return 0;
@@ -993,7 +991,6 @@ tc_xyz12_prepare_shader(const opengl_tex_converter_t *tc,
 static GLuint
 xyz12_shader_init(opengl_tex_converter_t *tc)
 {
-    tc->chroma  = VLC_CODEC_XYZ12;
     tc->tex_count = 1;
     tc->tex_target = GL_TEXTURE_2D;
     tc->texs[0] = (struct opengl_tex_cfg) {
@@ -1044,8 +1041,7 @@ xyz12_shader_init(opengl_tex_converter_t *tc)
 }
 
 static GLuint
-generic_init(const video_format_t *fmt, opengl_tex_converter_t *tc,
-             bool allow_dr)
+generic_init(video_format_t *fmt, opengl_tex_converter_t *tc, bool allow_dr)
 {
     const vlc_chroma_description_t *desc =
         vlc_fourcc_GetChromaDescription(fmt->i_chroma);
@@ -1077,10 +1073,29 @@ generic_init(const video_format_t *fmt, opengl_tex_converter_t *tc,
         }
 
         const vlc_fourcc_t *list = get_fallback(fmt->i_chroma);
-        while (*list && fragment_shader == 0)
+        while (*list)
         {
             fragment_shader =
                 opengl_fragment_shader_init(tc, GL_TEXTURE_2D, *list, space);
+            if (fragment_shader != 0)
+            {
+                fmt->i_chroma = *list;
+
+                if (fmt->i_chroma == VLC_CODEC_RGB32)
+                {
+#if defined(WORDS_BIGENDIAN)
+                    fmt->i_rmask  = 0xff000000;
+                    fmt->i_gmask  = 0x00ff0000;
+                    fmt->i_bmask  = 0x0000ff00;
+#else
+                    fmt->i_rmask  = 0x000000ff;
+                    fmt->i_gmask  = 0x0000ff00;
+                    fmt->i_bmask  = 0x00ff0000;
+#endif
+                    video_format_FixRgb(fmt);
+                }
+                break;
+            }
             list++;
         }
     }
@@ -1151,11 +1166,13 @@ GLuint
 opengl_tex_converter_subpictures_init(const video_format_t *fmt,
                                       opengl_tex_converter_t *tc)
 {
-    return generic_init(fmt, tc, false);
+    video_format_t sub_fmt = *fmt;
+    sub_fmt.i_chroma = VLC_CODEC_RGB32;
+    return generic_init(&sub_fmt, tc, false);
 }
 
 GLuint
-opengl_tex_converter_generic_init(const video_format_t *fmt,
+opengl_tex_converter_generic_init(video_format_t *fmt,
                                   opengl_tex_converter_t *tc)
 {
     return generic_init(fmt, tc, true);
diff --git a/modules/video_output/opengl/internal.h b/modules/video_output/opengl/internal.h
index b54f188a1b..bd990c2d5d 100644
--- a/modules/video_output/opengl/internal.h
+++ b/modules/video_output/opengl/internal.h
@@ -159,11 +159,12 @@ typedef struct opengl_tex_converter_t opengl_tex_converter_t;
  * The implementation should initialize every members of the struct in regards
  * of the video format.
  *
- * \param fmt video format
+ * \param fmt video format, fmt->i_chroma can be modified in order to match a
+ * shader
  * \param fc OpenGL tex converter that needs to be filled on success
  * \return VLC_SUCCESS or a VLC error
  */
-typedef GLuint (*opengl_tex_converter_init_cb)(const video_format_t *fmt,
+typedef GLuint (*opengl_tex_converter_init_cb)(video_format_t *fmt,
                                                opengl_tex_converter_t *fc);
 
 /*
@@ -180,9 +181,6 @@ struct opengl_tex_converter_t
     /* Set it to request a special orientation (by default = fmt.orientation) */
     video_orientation_t orientation;
 
-    /* Video chroma used by this configuration, cannot be 0 */
-    vlc_fourcc_t chroma;
-
     /* Number of textures, cannot be 0 */
     unsigned tex_count;
 
@@ -330,18 +328,18 @@ opengl_tex_converter_subpictures_init(const video_format_t *,
                                       opengl_tex_converter_t *);
 
 GLuint
-opengl_tex_converter_generic_init(const video_format_t *,
+opengl_tex_converter_generic_init(video_format_t *,
                                   opengl_tex_converter_t *);
 
 #ifdef __ANDROID__
 GLuint
-opengl_tex_converter_anop_init(const video_format_t *,
+opengl_tex_converter_anop_init(video_format_t *,
                                opengl_tex_converter_t *);
 #endif
 
 #ifdef VLCGL_CONV_CVPX
 GLuint
-opengl_tex_converter_cvpx_init(const video_format_t *fmt,
+opengl_tex_converter_cvpx_init(video_format_t *fmt,
                                opengl_tex_converter_t *tc);
 #endif
 
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index f345c5d1e5..69da628812 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -479,8 +479,7 @@ opengl_link_program(struct prgm *prgm, GLuint fragment_shader)
             int charsWritten;
             tc->api->GetProgramInfoLog(prgm->id, infoLength, &charsWritten,
                                        infolog);
-            msg_Err(tc->gl, "shader program %4.4s: %s",
-                    (const char *) &tc->chroma, infolog);
+            msg_Err(tc->gl, "shader program: %s", infolog);
             free(infolog);
         }
 
@@ -489,8 +488,7 @@ opengl_link_program(struct prgm *prgm, GLuint fragment_shader)
         tc->api->GetProgramiv(prgm->id, GL_LINK_STATUS, &link_status);
         if (link_status == GL_FALSE)
         {
-            msg_Err(tc->gl, "Unable to use program %4.4s\n",
-                    (const char *) &tc->chroma);
+            msg_Err(tc->gl, "Unable to use program");
             goto error;
         }
     }
@@ -531,8 +529,7 @@ opengl_link_program(struct prgm *prgm, GLuint fragment_shader)
     assert(ret == VLC_SUCCESS);
     if (ret != VLC_SUCCESS)
     {
-        msg_Err(tc->gl, "Unable to get locations from %4.4s tex_conv\n",
-                (const char *) &tc->chroma);
+        msg_Err(tc->gl, "Unable to get locations from tex_conv");
         goto error;
     }
 
@@ -651,19 +648,6 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
                          HasExtension(extensions, "GL_APPLE_texture_2D_limited_npot");
 #endif
 
-    /* Initialize with default chroma */
-    vgl->fmt = *fmt;
-    vgl->fmt.i_chroma = VLC_CODEC_RGB32;
-#   if defined(WORDS_BIGENDIAN)
-    vgl->fmt.i_rmask  = 0xff000000;
-    vgl->fmt.i_gmask  = 0x00ff0000;
-    vgl->fmt.i_bmask  = 0x0000ff00;
-#   else
-    vgl->fmt.i_rmask  = 0x000000ff;
-    vgl->fmt.i_gmask  = 0x0000ff00;
-    vgl->fmt.i_bmask  = 0x00ff0000;
-#   endif
-
     vgl->prgm = &vgl->prgms[0];
     vgl->sub_prgm = &vgl->prgms[1];
 
@@ -675,7 +659,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
     };
 
     /* RGBA is needed for subpictures or for non YUV pictures */
-    GLuint fshader = opengl_tex_converter_subpictures_init(&vgl->fmt,
+    GLuint fshader = opengl_tex_converter_subpictures_init(fmt,
                                                            &vgl->sub_prgm->tc);
     int ret = opengl_link_program(vgl->sub_prgm, fshader);
     if (ret != VLC_SUCCESS)
@@ -698,12 +682,12 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
         ret = opengl_link_program(vgl->prgm, fshader);
         if (ret == VLC_SUCCESS)
         {
-            assert(vgl->prgm->tc.chroma != 0 && vgl->prgm->tc.tex_target != 0 &&
+            assert(vgl->prgm->tc.tex_target != 0 &&
                    vgl->prgm->tc.tex_count > 0 &&  vgl->prgm->tc.pf_update != NULL &&
                    vgl->prgm->tc.pf_fetch_locations != NULL &&
                    vgl->prgm->tc.pf_prepare_shader != NULL);
+
             vgl->fmt = *fmt;
-            vgl->fmt.i_chroma = vgl->prgm->tc.chroma;
             break;
         }
     }



More information about the vlc-commits mailing list