[vlc-devel] [PATCH 13/18] opengl: make importer a vlc_object_t

Thomas Guillem thomas at gllm.fr
Mon Dec 23 11:56:14 CET 2019


In that case, opengl_tex_converter_t don't have to be an object anymore, right ?

On Fri, Dec 20, 2019, at 15:48, Romain Vimont wrote:
> In order to pass importer instance to "glconv" modules, they must
> "inherit" vlc_object_t.
> ---
>  modules/video_output/opengl/converter.h       |  2 +-
>  modules/video_output/opengl/converter_vaapi.c |  6 +--
>  modules/video_output/opengl/converter_vdpau.c |  4 +-
>  .../video_output/opengl/fragment_shaders.c    |  8 ++--
>  modules/video_output/opengl/importer.h        |  1 +
>  modules/video_output/opengl/vout_helper.c     | 46 +++++++++++--------
>  6 files changed, 37 insertions(+), 30 deletions(-)
> 
> diff --git a/modules/video_output/opengl/converter.h 
> b/modules/video_output/opengl/converter.h
> index aa6649c816..08616a4e3d 100644
> --- a/modules/video_output/opengl/converter.h
> +++ b/modules/video_output/opengl/converter.h
> @@ -87,7 +87,7 @@ struct opengl_tex_converter_t
>      struct pl_shader *pl_sh;
>      const struct pl_shader_res *pl_sh_res;
>  
> -    struct vlc_gl_importer importer;
> +    struct vlc_gl_importer *importer;
>  
>      /**
>       * Callback to fetch locations of uniform or attributes variables
> diff --git a/modules/video_output/opengl/converter_vaapi.c 
> b/modules/video_output/opengl/converter_vaapi.c
> index 5ff3c7f24e..27313d986c 100644
> --- a/modules/video_output/opengl/converter_vaapi.c
> +++ b/modules/video_output/opengl/converter_vaapi.c
> @@ -289,10 +289,10 @@ static void
>  Close(vlc_object_t *obj)
>  {
>      opengl_tex_converter_t *tc = (void *)obj;
> -    struct priv *priv = tc->importer.priv;
> +    struct priv *priv = tc->importer->priv;
>  
>      if (priv->last.pic != NULL)
> -        vaegl_release_last_pic(&tc->importer, priv);
> +        vaegl_release_last_pic(tc->importer, priv);
>  
>      free(priv);
>  }
> @@ -356,7 +356,7 @@ static int
>  Open(vlc_object_t *obj)
>  {
>      opengl_tex_converter_t *tc = (void *) obj;
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = tc->importer;
>  
>      if (imp->vctx == NULL)
>          return VLC_EGENERIC;
> diff --git a/modules/video_output/opengl/converter_vdpau.c 
> b/modules/video_output/opengl/converter_vdpau.c
> index 6a18090c68..6f7dbae143 100644
> --- a/modules/video_output/opengl/converter_vdpau.c
> +++ b/modules/video_output/opengl/converter_vdpau.c
> @@ -118,7 +118,7 @@ Close(vlc_object_t *obj)
>  {
>      opengl_tex_converter_t *tc = (void *)obj;
>      _glVDPAUFiniNV(); assert(tc->vt->GetError() == GL_NO_ERROR);
> -    converter_sys_t *sys = tc->importer.priv;
> +    converter_sys_t *sys = tc->importer->priv;
>      vlc_decoder_device *dec_device = sys->dec_device;
>      vlc_decoder_device_Release(dec_device);
>  }
> @@ -127,7 +127,7 @@ static int
>  Open(vlc_object_t *obj)
>  {
>      opengl_tex_converter_t *tc = (void *) obj;
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = tc->importer;
>  
>      if (imp->vctx == NULL)
>          return VLC_EGENERIC;
> diff --git a/modules/video_output/opengl/fragment_shaders.c 
> b/modules/video_output/opengl/fragment_shaders.c
> index f639397d90..043a582144 100644
> --- a/modules/video_output/opengl/fragment_shaders.c
> +++ b/modules/video_output/opengl/fragment_shaders.c
> @@ -303,7 +303,7 @@ importer_rgb_base_init(struct vlc_gl_importer *imp, 
> GLenum tex_target,
>  static int
>  tc_base_fetch_locations(opengl_tex_converter_t *tc, GLuint program)
>  {
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = tc->importer;
>  
>      if (tc->yuv_color)
>      {
> @@ -350,7 +350,7 @@ tc_base_prepare_shader(const opengl_tex_converter_t *tc,
>                         float alpha)
>  {
>      (void) tex_width; (void) tex_height;
> -    const struct vlc_gl_importer *imp = &tc->importer;
> +    const struct vlc_gl_importer *imp = tc->importer;
>  
>      if (tc->yuv_color)
>          tc->vt->Uniform4fv(tc->uloc.Coefficients, 4, 
> tc->yuv_coefficients);
> @@ -567,7 +567,7 @@ GLuint
>  opengl_fragment_shader_init_impl(opengl_tex_converter_t *tc, GLenum 
> tex_target,
>                                   vlc_fourcc_t chroma, 
> video_color_space_t yuv_space)
>  {
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = tc->importer;
>  
>      const char *swizzle_per_tex[PICTURE_PLANE_MAX] = { NULL, };
>      const bool is_yuv = vlc_fourcc_IsYUV(chroma);
> @@ -586,7 +586,7 @@ 
> opengl_fragment_shader_init_impl(opengl_tex_converter_t *tc, GLenum 
> tex_target,
>          ret = tc_yuv_base_init(tc, chroma, desc, yuv_space, 
> &yuv_swap_uv);
>          if (ret != VLC_SUCCESS)
>              return 0;
> -        ret = opengl_init_swizzle(&tc->importer, swizzle_per_tex, 
> chroma, desc);
> +        ret = opengl_init_swizzle(tc->importer, swizzle_per_tex, 
> chroma, desc);
>          if (ret != VLC_SUCCESS)
>              return 0;
>      }
> diff --git a/modules/video_output/opengl/importer.h 
> b/modules/video_output/opengl/importer.h
> index b18384fd96..75ee3f514d 100644
> --- a/modules/video_output/opengl/importer.h
> +++ b/modules/video_output/opengl/importer.h
> @@ -109,6 +109,7 @@ struct vlc_gl_importer_ops {
>  };
>  
>  struct vlc_gl_importer {
> +    vlc_object_t obj;
>      vlc_gl_t *gl;
>      const opengl_vtable_t *vt;
>      GLenum tex_target;
> diff --git a/modules/video_output/opengl/vout_helper.c 
> b/modules/video_output/opengl/vout_helper.c
> index 1f60dab058..cd2ca02eb1 100644
> --- a/modules/video_output/opengl/vout_helper.c
> +++ b/modules/video_output/opengl/vout_helper.c
> @@ -346,7 +346,7 @@ static GLuint BuildVertexShader(const 
> opengl_tex_converter_t *tc,
>      tc->vt->ShaderSource(shader, 1, (const char **) &code, NULL);
>      if (tc->b_dump_shaders)
>          msg_Dbg(tc->gl, "\n=== Vertex shader for fourcc: %4.4s 
> ===\n%s\n",
> -                (const char *)&tc->importer.fmt.i_chroma, code);
> +                (const char *)&tc->importer->fmt.i_chroma, code);
>      tc->vt->CompileShader(shader);
>      free(code);
>      return shader;
> @@ -399,7 +399,7 @@ static int
>  opengl_link_program(struct prgm *prgm)
>  {
>      opengl_tex_converter_t *tc = prgm->tc;
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = tc->importer;
>  
>      GLuint vertex_shader = BuildVertexShader(tc, imp->tex_count);
>      GLuint shaders[] = { tc->fshader, vertex_shader };
> @@ -506,11 +506,12 @@ static void
>  opengl_deinit_program(vout_display_opengl_t *vgl, struct prgm *prgm)
>  {
>      opengl_tex_converter_t *tc = prgm->tc;
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = tc->importer;
>      if (tc->p_module != NULL)
>          module_unneed(tc, tc->p_module);
>      else if (imp->priv != NULL)
>          opengl_importer_generic_deinit(imp);
> +    vlc_object_delete(tc->importer);
>      if (prgm->id != 0)
>          vgl->vt.DeleteProgram(prgm->id);
>  
> @@ -534,7 +535,14 @@ opengl_init_program(vout_display_opengl_t *vgl, 
> vlc_video_context *context,
>      if (tc == NULL)
>          return VLC_ENOMEM;
>  
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = vlc_object_create(tc, sizeof(*imp));
> +    if (!imp)
> +    {
> +        vlc_object_delete(tc);
> +        return VLC_ENOMEM;
> +    }
> +
> +    tc->importer = imp;
>  
>      tc->gl = vgl->gl;
>      tc->vt = &vgl->vt;
> @@ -865,7 +873,7 @@ vout_display_opengl_t 
> *vout_display_opengl_New(video_format_t *fmt,
>      }
>      GL_ASSERT_NOERROR();
>  
> -    const struct vlc_gl_importer *imp = &vgl->prgm->tc->importer;
> +    const struct vlc_gl_importer *imp = vgl->prgm->tc->importer;
>      /* Update the fmt to main program one */
>      vgl->fmt = imp->fmt;
>      /* The orientation is handled by the orientation matrix */
> @@ -887,11 +895,11 @@ vout_display_opengl_t 
> *vout_display_opengl_New(video_format_t *fmt,
>      }
>  
>      /* Allocates our textures */
> -    assert(!vgl->sub_prgm->tc->importer.handle_texs_gen);
> +    assert(!vgl->sub_prgm->tc->importer->handle_texs_gen);
>  
>      if (!imp->handle_texs_gen)
>      {
> -        ret = GenTextures(&vgl->prgm->tc->importer, vgl->tex_width, 
> vgl->tex_height,
> +        ret = GenTextures(vgl->prgm->tc->importer, vgl->tex_width, 
> vgl->tex_height,
>                            vgl->texture);
>          if (ret != VLC_SUCCESS)
>          {
> @@ -951,7 +959,7 @@ void 
> vout_display_opengl_Delete(vout_display_opengl_t *vgl)
>      vgl->vt.Finish();
>      vgl->vt.Flush();
>  
> -    const struct vlc_gl_importer *imp = &vgl->prgm->tc->importer;
> +    const struct vlc_gl_importer *imp = vgl->prgm->tc->importer;
>      const size_t main_tex_count = imp->tex_count;
>      const bool main_del_texs = !imp->handle_texs_gen;
>  
> @@ -1058,8 +1066,7 @@ void 
> vout_display_opengl_Viewport(vout_display_opengl_t *vgl, int x, int y,
>  
>  bool vout_display_opengl_HasPool(const vout_display_opengl_t *vgl)
>  {
> -    opengl_tex_converter_t *tc = vgl->prgm->tc;
> -    struct vlc_gl_importer *imp = &tc->importer;
> +    struct vlc_gl_importer *imp = vgl->prgm->tc->importer;
>      return imp->ops->get_pool != NULL;
>  }
>  
> @@ -1070,8 +1077,7 @@ picture_pool_t 
> *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned
>      if (vgl->pool)
>          return vgl->pool;
>  
> -    opengl_tex_converter_t *tc = vgl->prgm->tc;
> -    const struct vlc_gl_importer *imp = &tc->importer;
> +    const struct vlc_gl_importer *imp = vgl->prgm->tc->importer;
>      requested_count = __MIN(VLCGL_PICTURE_MAX, requested_count);
>      /* Allocate with tex converter pool callback if it exists */
>      assert(imp->ops->get_pool != NULL);
> @@ -1091,7 +1097,7 @@ int 
> vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
>      GL_ASSERT_NOERROR();
>  
>      opengl_tex_converter_t *tc = vgl->prgm->tc;
> -    const struct vlc_gl_importer *imp = &tc->importer;
> +    const struct vlc_gl_importer *imp = tc->importer;
>  
>      /* Update the texture */
>      int ret = imp->ops->update_textures(imp, vgl->texture, 
> vgl->tex_width, vgl->tex_height,
> @@ -1106,7 +1112,7 @@ int 
> vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
>      vgl->region       = NULL;
>  
>      tc = vgl->sub_prgm->tc;
> -    imp = &tc->importer;
> +    imp = tc->importer;
>      if (subpicture) {
>  
>          int count = 0;
> @@ -1453,7 +1459,7 @@ static int SetupCoords(vout_display_opengl_t *vgl,
>                         const float *left, const float *top,
>                         const float *right, const float *bottom)
>  {
> -    const struct vlc_gl_importer *imp = &vgl->prgm->tc->importer;
> +    const struct vlc_gl_importer *imp = vgl->prgm->tc->importer;
>  
>      GLfloat *vertexCoord, *textureCoord;
>      GLushort *indices;
> @@ -1517,7 +1523,7 @@ static int SetupCoords(vout_display_opengl_t *vgl,
>  static void DrawWithShaders(vout_display_opengl_t *vgl, struct prgm *prgm)
>  {
>      opengl_tex_converter_t *tc = prgm->tc;
> -    const struct vlc_gl_importer *imp = &tc->importer;
> +    const struct vlc_gl_importer *imp = tc->importer;
>      tc->pf_prepare_shader(tc, vgl->tex_width, vgl->tex_height, 1.0f);
>  
>      for (unsigned j = 0; j < imp->tex_count; j++) {
> @@ -1581,7 +1587,7 @@ static void 
> TextureCropForStereo(vout_display_opengl_t *vgl,
>                                   float *left, float *top,
>                                   float *right, float *bottom)
>  {
> -    const struct vlc_gl_importer *imp = &vgl->prgm->tc->importer;
> +    const struct vlc_gl_importer *imp = vgl->prgm->tc->importer;
>  
>      float stereoCoefs[2];
>      float stereoOffsets[2];
> @@ -1631,8 +1637,8 @@ int 
> vout_display_opengl_Display(vout_display_opengl_t *vgl,
>          float right[PICTURE_PLANE_MAX];
>          float bottom[PICTURE_PLANE_MAX];
>          const opengl_tex_converter_t *tc = vgl->prgm->tc;
> -        const struct vlc_gl_importer *imp = &tc->importer;
> -        for (unsigned j = 0; j < tc->importer.tex_count; j++)
> +        const struct vlc_gl_importer *imp = tc->importer;
> +        for (unsigned j = 0; j < imp->tex_count; j++)
>          {
>              float scale_w = (float)imp->texs[j].w.num / 
> imp->texs[j].w.den
>                            / vgl->tex_width[j];
> @@ -1673,7 +1679,7 @@ int 
> vout_display_opengl_Display(vout_display_opengl_t *vgl,
>      struct prgm *prgm = vgl->sub_prgm;
>      GLuint program = prgm->id;
>      opengl_tex_converter_t *tc = prgm->tc;
> -    const struct vlc_gl_importer *imp = &tc->importer;
> +    const struct vlc_gl_importer *imp = tc->importer;
>      vgl->vt.UseProgram(program);
>  
>      vgl->vt.Enable(GL_BLEND);
> -- 
> 2.24.1
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list