opengl: expose opengl_interop_init()
[vlc.git] / modules / video_output / opengl / interop.h
blob069bc623ef371eded9aff50c047c1248843fb793
1 /*****************************************************************************
2 * interop.h
3 *****************************************************************************
4 * Copyright (C) 2019 Videolabs
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifndef VLC_GL_INTEROP_H
22 #define VLC_GL_INTEROP_H
24 #include <vlc_common.h>
25 #include <vlc_opengl.h>
26 #include <vlc_picture.h>
27 #include <vlc_picture_pool.h>
29 #include "gl_common.h"
31 struct vlc_gl_interop;
33 struct vlc_gl_interop_ops {
34 /**
35 * Callback to allocate data for bound textures
37 * This function pointer can be NULL. Software converters should call
38 * glTexImage2D() to allocate textures data (it will be deallocated by the
39 * caller when calling glDeleteTextures()). Won't be called if
40 * handle_texs_gen is true.
42 * \param interop the OpenGL interop
43 * \param textures array of textures to bind (one per plane)
44 * \param tex_width array of tex width (one per plane)
45 * \param tex_height array of tex height (one per plane)
46 * \return VLC_SUCCESS or a VLC error
48 int
49 (*allocate_textures)(const struct vlc_gl_interop *interoporter,
50 GLuint textures[], const GLsizei tex_width[],
51 const GLsizei tex_height[]);
53 /**
54 * Callback to update a picture
56 * This function pointer cannot be NULL. The implementation should upload
57 * every planes of the picture.
59 * \param interop the OpenGL interop
60 * \param textures array of textures to bind (one per plane)
61 * \param tex_width array of tex width (one per plane)
62 * \param tex_height array of tex height (one per plane)
63 * \param pic picture to update
64 * \param plane_offset offsets of each picture planes to read data from
65 * (one per plane, can be NULL)
66 * \return VLC_SUCCESS or a VLC error
68 int
69 (*update_textures)(const struct vlc_gl_interop *interoporter,
70 GLuint textures[], const GLsizei tex_width[],
71 const GLsizei tex_height[], picture_t *pic,
72 const size_t plane_offsets[]);
74 /**
75 * Callback to retrieve the transform matrix to apply to texture coordinates
77 * This function pointer can be NULL. If it is set, it may return NULL.
79 * Otherwise, it must return a 4x4 matrix, as an array of 16 floats in
80 * column-major order.
82 * This transform matrix maps 2D homogeneous texture coordinates of the
83 * form (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the
84 * texture coordinate that should be used to sample that location from the
85 * texture.
87 * The returned pointer is owned by the converter module, and must not be
88 * freed before the module is closed.
90 * \param interop the OpenGL interop
91 * \return a 4x4 transformatoin matrix (possibly NULL)
93 const float *
94 (*get_transform_matrix)(const struct vlc_gl_interop *interoporter);
97 struct vlc_gl_interop {
98 vlc_gl_t *gl;
99 const opengl_vtable_t *vt;
100 GLenum tex_target;
102 /* True if the current API is OpenGL ES, set by the caller */
103 bool is_gles;
105 /* Available gl extensions (from GL_EXTENSIONS) */
106 const char *glexts;
108 /* Can only be changed from the module open function */
109 video_format_t fmt;
111 /* Software format (useful if fmt only exposes opaque chroma) */
112 video_format_t sw_fmt;
114 /* Pointer to decoder video context, set by the caller (can be NULL) */
115 vlc_video_context *vctx;
117 /* Set to true if textures are generated from pf_update() */
118 bool handle_texs_gen;
120 /* Initialized by the interop */
121 struct vlc_gl_tex_cfg {
123 * Texture scale factor, cannot be 0.
124 * In 4:2:0, 1/1 for the Y texture and 1/2 for the UV texture(s)
126 vlc_rational_t w;
127 vlc_rational_t h;
129 GLint internal;
130 GLenum format;
131 GLenum type;
132 } texs[PICTURE_PLANE_MAX];
133 unsigned tex_count;
135 void *priv;
136 const struct vlc_gl_interop_ops *ops;
138 /* Set by the caller to opengl_interop_init_impl().
139 * This avoids each module to link against opengl_interop_init_impl()
140 * directly. */
142 (*init)(struct vlc_gl_interop *interop, GLenum tex_target,
143 vlc_fourcc_t chroma, video_color_space_t yuv_space);
146 static inline int
147 opengl_interop_init(struct vlc_gl_interop *interop, GLenum tex_target,
148 vlc_fourcc_t chroma, video_color_space_t yuv_space)
150 return interop->init(interop, tex_target, chroma, yuv_space);
153 #endif