VLC  4.0.0-dev
vlc_opengl.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_opengl.h: VLC GL API
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * Copyright (C) 2011 RĂ©mi Denis-Courmont
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 
24 #ifndef VLC_GL_H
25 #define VLC_GL_H 1
26 
27 /**
28  * \file
29  * This file defines GL structures and functions.
30  */
31 
32 struct vout_window_t;
33 struct vout_window_cfg_t;
34 struct vout_display_cfg;
35 
36 /**
37  * A VLC GL context (and its underlying surface)
38  */
39 typedef struct vlc_gl_t vlc_gl_t;
41 struct vlc_video_context;
42 
43 enum vlc_gl_api_type {
46 };
47 
48 struct vlc_gl_t
49 {
50  struct vlc_object_t obj;
51 
53  void *sys;
54 
55  union {
56  struct { /* on-screen */
57  void (*swap)(vlc_gl_t *);
58 
59  struct vout_window_t *surface;
60  };
61  struct { /* off-screen */
62  picture_t *(*swap_offscreen)(vlc_gl_t *);
63 
64  struct vlc_decoder_device *device;
67  /* Flag to indicate if the OpenGL implementation produces upside-down
68  * pictures */
69  bool offscreen_vflip;
70  };
71  };
72 
73  int (*make_current)(vlc_gl_t *);
75  void (*resize)(vlc_gl_t *, unsigned, unsigned);
76  void*(*get_proc_address)(vlc_gl_t *, const char *);
77  void (*destroy)(vlc_gl_t *);
78 
79  enum {
83  } ext;
84 
85  union {
86  /* if ext == VLC_GL_EXT_EGL */
87  struct {
88  /* call eglQueryString() with current display */
89  const char *(*queryString)(vlc_gl_t *, int32_t name);
90  /* call eglCreateImageKHR() with current display and context, can
91  * be NULL */
92  void *(*createImageKHR)(vlc_gl_t *, unsigned target, void *buffer,
93  const int32_t *attrib_list);
94  /* call eglDestroyImageKHR() with current display, can be NULL */
95  bool (*destroyImageKHR)(vlc_gl_t *, void *image);
96  } egl;
97  /* if ext == VLC_GL_EXT_WGL */
98  struct
99  {
100  const char *(*getExtensionsString)(vlc_gl_t *);
101  } wgl;
102  };
103 
104  /* Defined by the core for libvlc_opengl API loading. */
106 };
107 
108 /**
109  * Creates an OpenGL context (and its underlying surface).
110  *
111  * @note In most cases, you should vlc_gl_MakeCurrent() afterward.
112  *
113  * @param cfg initial configuration (including window to use as OpenGL surface)
114  * @param flags OpenGL context type
115  * @param name module name (or NULL for auto)
116  * @return a new context, or NULL on failure
117  */
119  unsigned flags, const char *name) VLC_USED;
121  struct vlc_decoder_device *device,
122  unsigned width, unsigned height,
123  unsigned flags, const char *name);
124 
127 
128 static inline int vlc_gl_MakeCurrent(vlc_gl_t *gl)
129 {
130  return gl->make_current(gl);
131 }
132 
133 static inline void vlc_gl_ReleaseCurrent(vlc_gl_t *gl)
134 {
135  gl->release_current(gl);
136 }
137 
138 static inline void vlc_gl_Resize(vlc_gl_t *gl, unsigned w, unsigned h)
139 {
140  if (gl->resize != NULL)
141  gl->resize(gl, w, h);
142 }
143 
144 static inline void vlc_gl_Swap(vlc_gl_t *gl)
145 {
146  gl->swap(gl);
147 }
148 
149 static inline picture_t *vlc_gl_SwapOffscreen(vlc_gl_t *gl)
150 {
151  return gl->swap_offscreen(gl);
152 }
153 
154 static inline void *vlc_gl_GetProcAddress(vlc_gl_t *gl, const char *name)
155 {
156  return gl->get_proc_address(gl, name);
157 }
158 
160  const struct vout_window_cfg_t *,
161  struct vout_window_t **) VLC_USED;
162 VLC_API bool vlc_gl_surface_CheckSize(vlc_gl_t *, unsigned *w, unsigned *h);
164 
165 static inline bool vlc_gl_StrHasToken(const char *apis, const char *api)
166 {
167  size_t apilen = strlen(api);
168  while (apis) {
169  while (*apis == ' ')
170  apis++;
171  if (!strncmp(apis, api, apilen) && memchr(" ", apis[apilen], 2))
172  return true;
173  apis = strchr(apis, ' ');
174  }
175  return false;
176 }
177 
178 #endif /* VLC_GL_H */
VLC_OPENGL
@ VLC_OPENGL
Definition: vlc_opengl.h:45
vlc_gl_t::offscreen_vctx_out
struct vlc_video_context * offscreen_vctx_out
Definition: vlc_opengl.h:67
VLC_API
#define VLC_API
Definition: fourcc_gen.c:31
vlc_gl_ReleaseCurrent
static void vlc_gl_ReleaseCurrent(vlc_gl_t *gl)
Definition: vlc_opengl.h:134
vlc_gl_Swap
static void vlc_gl_Swap(vlc_gl_t *gl)
Definition: vlc_opengl.h:145
vout_window_t
Window object.
Definition: vlc_vout_window.h:353
vlc_common.h
vlc_gl_t::ext
enum vlc_gl_t::@254 ext
VLC_OPENGL_ES2
@ VLC_OPENGL_ES2
Definition: vlc_opengl.h:46
vlc_gl_t::release_current
void(* release_current)(vlc_gl_t *)
Definition: vlc_opengl.h:75
vlc_gl_t::VLC_GL_EXT_DEFAULT
@ VLC_GL_EXT_DEFAULT
Definition: vlc_opengl.h:81
vlc_gl_t::sys
void * sys
Definition: vlc_opengl.h:54
vlc_gl_Resize
static void vlc_gl_Resize(vlc_gl_t *gl, unsigned w, unsigned h)
Definition: vlc_opengl.h:139
picture_t
Video picture.
Definition: vlc_picture.h:120
vlc_gl_StrHasToken
static bool vlc_gl_StrHasToken(const char *apis, const char *api)
Definition: vlc_opengl.h:166
vlc_gl_t::swap_offscreen
picture_t *(* swap_offscreen)(vlc_gl_t *)
Definition: vlc_opengl.h:63
vlc_gl_MakeCurrent
static int vlc_gl_MakeCurrent(vlc_gl_t *gl)
Definition: vlc_opengl.h:129
vlc_gl_t::swap
void(* swap)(vlc_gl_t *)
Definition: vlc_opengl.h:58
vlc_gl_t::wgl
struct vlc_gl_t::@255::@262 wgl
vlc_gl_t::module
module_t * module
Definition: vlc_opengl.h:53
module_t
Internal module descriptor.
Definition: modules.h:78
vout_display_cfg
User configuration for a video output display (vout_display_t)
Definition: vlc_vout_display.h:94
vlc_decoder_device
Decoder context struct.
Definition: vlc_codec.h:566
vlc_gl_t::offscreen_vflip
bool offscreen_vflip
Definition: vlc_opengl.h:70
vlc_gl_t::offscreen_chroma_out
vlc_fourcc_t offscreen_chroma_out
Definition: vlc_opengl.h:66
vlc_gl_t
Definition: vlc_opengl.h:49
vlc_gl_SwapOffscreen
static picture_t * vlc_gl_SwapOffscreen(vlc_gl_t *gl)
Definition: vlc_opengl.h:150
vlc_gl_surface_CheckSize
VLC_EXPORT bool vlc_gl_surface_CheckSize(vlc_gl_t *, unsigned *w, unsigned *h)
vlc_gl_t::device
struct vlc_decoder_device * device
Definition: vlc_opengl.h:65
vlc_video_context
Definition: decoder_helpers.c:228
vlc_gl_t::destroy
void(* destroy)(vlc_gl_t *)
Definition: vlc_opengl.h:78
vlc_object_t
VLC object common members.
Definition: vlc_objects.h:43
vlc_gl_GetProcAddress
static void * vlc_gl_GetProcAddress(vlc_gl_t *gl, const char *name)
Definition: vlc_opengl.h:155
vlc_gl_surface_Destroy
VLC_EXPORT void vlc_gl_surface_Destroy(vlc_gl_t *)
Definition: opengl.c:294
vlc_gl_t::egl
struct vlc_gl_t::@255::@261 egl
vlc_gl_Release
VLC_EXPORT void vlc_gl_Release(vlc_gl_t *)
Definition: opengl.c:165
vlc_gl_t::resize
void(* resize)(vlc_gl_t *, unsigned, unsigned)
Definition: vlc_opengl.h:76
VLC_USED
#define VLC_USED
Definition: fourcc_gen.c:32
vout_window_cfg_t
Window (desired) configuration.
Definition: vlc_vout_window.h:148
name
const char name[16]
Definition: httpd.c:1268
vlc_gl_surface_Create
VLC_EXPORT vlc_gl_t * vlc_gl_surface_Create(vlc_object_t *, const struct vout_window_cfg_t *, struct vout_window_t **)
vlc_gl_t::destroyImageKHR
bool(* destroyImageKHR)(vlc_gl_t *, void *image)
Definition: vlc_opengl.h:96
vlc_gl_t::VLC_GL_EXT_EGL
@ VLC_GL_EXT_EGL
Definition: vlc_opengl.h:82
vlc_gl_t::get_proc_address
void *(* get_proc_address)(vlc_gl_t *, const char *)
Definition: vlc_opengl.h:77
vlc_gl_Hold
VLC_EXPORT void vlc_gl_Hold(vlc_gl_t *)
Definition: opengl.c:159
vlc_gl_api_type
vlc_gl_api_type
Definition: vlc_opengl.h:44
vlc_gl_t::VLC_GL_EXT_WGL
@ VLC_GL_EXT_WGL
Definition: vlc_opengl.h:83
vlc_gl_t::make_current
int(* make_current)(vlc_gl_t *)
Definition: vlc_opengl.h:74
vlc_gl_t::obj
struct vlc_object_t obj
Definition: vlc_opengl.h:51
vlc_gl_t::api_type
enum vlc_gl_api_type api_type
Definition: vlc_opengl.h:106
vlc_gl_CreateOffscreen
VLC_EXPORT vlc_gl_t * vlc_gl_CreateOffscreen(vlc_object_t *parent, struct vlc_decoder_device *device, unsigned width, unsigned height, unsigned flags, const char *name)
Definition: opengl.c:100
vlc_gl_t::surface
struct vout_window_t * surface
Definition: vlc_opengl.h:60
vlc_fourcc_t
uint32_t vlc_fourcc_t
Definition: fourcc_gen.c:33
vlc_gl_Create
VLC_EXPORT vlc_gl_t * vlc_gl_Create(const struct vout_display_cfg *cfg, unsigned flags, const char *name)
Creates an OpenGL context (and its underlying surface).