xine-lib 1.2.13-20230125hg15249
xine_gl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2022 the xine project
3 * Copyright (C) 2018-2021 Petri Hintukainen <phintuka@users.sourceforge.net>
4 *
5 * This file is part of xine, a free video player.
6 *
7 * xine is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * xine is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 * xine_gl.h, Interface between OpenGL and native windowing system
22 *
23 * GL provider API, used in vo drivers
24 *
25 */
26
27#ifndef XINE_GL_H_
28#define XINE_GL_H_
29
30#include <stdlib.h>
31#include <string.h>
32
33#include <xine.h>
34#include <xine/sorted_array.h>
35
36typedef struct xine_gl xine_gl_t;
37
38struct xine_gl {
42
43 /* resize is needed only with WAYLAND visual */
44 void (*resize) (xine_gl_t *, int width, int height);
45 /* set_native_window is used only with X11 */
46 void (*set_native_window)(xine_gl_t *, void *);
47
48 void (*dispose) (xine_gl_t **);
49
50 void *(*get_proc_address)(xine_gl_t *, const char *);
51 const char * (*query_extensions)(xine_gl_t *);
52
53 /* EGL */
54 void * (*eglCreateImageKHR) (xine_gl_t *,
55 unsigned /* EGLenum target */,
56 void * /* EGLClientBuffer buffer */,
57 const int32_t * /*const EGLint * attrib_list */);
58 int (*eglDestroyImageKHR) (xine_gl_t *, void *);
59};
60
61xine_gl_t *_x_load_gl(xine_t *xine, unsigned visual_type, const void *visual, unsigned flags);
62
63
64static inline int _x_gl_has_extension(const char *extensions, const char * const ext) {
65 if (extensions)
66 while (*extensions) {
67 const char *p = ext;
68 while (*extensions == ' ') extensions++;
69 while (*p && *p == *extensions) p++, extensions++;
70 if (*p == 0 && (*extensions == 0 || *extensions == ' '))
71 return 1;
72 while (*extensions && *extensions != ' ')
73 extensions++;
74 }
75 return 0;
76}
77
78/* flags */
79#define XINE_GL_API_OPENGL 0x0001
80#define XINE_GL_API_OPENGLES 0x0002
81
82typedef struct {
84 unsigned char *buf;
86
89 free (e->buf);
90 e->list = NULL;
91 e->buf = NULL;
92}
93
94static inline void xine_gl_extensions_load (xine_gl_extensions_t *e, const char *list) {
95 size_t llen;
96 unsigned char *p, *d;
97
98 e->list = NULL;
99 e->buf = NULL;
100 if (!list)
101 return;
102
103 llen = strlen (list);
104 e->buf = malloc (llen + 2);
105 /* TJ. I got 298 strings here :-) */
106 e->list = xine_sarray_new (1024, (xine_sarray_comparator_t)strcmp);
107 if (!e->list || !e->buf) {
109 return;
110 }
111
112 p = e->buf;
113 memcpy (p, list, llen + 1);
114 /* safe end plug */
115 d = p + llen;
116 memcpy (d, " 0", 2);
117 while (1) {
118 unsigned char *q;
119 /* skip spaces (simple, there should be just 1). */
120 while (*p <= ' ')
121 p++;
122 /* are we done? */
123 if (p >= d)
124 break;
125 q = p;
126 /* find next spc (fast). */
127 {
128 const union {
129 unsigned char *b;
130 uint32_t *u;
131 } u = { p - ((uintptr_t)p & 3) };
132 uint32_t *s = u.u;
133 static const union {
134 uint8_t b[4];
135 uint32_t v;
136 } mask[4] = {
137 {{0xff, 0xff, 0xff, 0xff}},
138 {{0x00, 0xff, 0xff, 0xff}},
139 {{0x00, 0x00, 0xff, 0xff}},
140 {{0x00, 0x00, 0x00, 0xff}},
141 };
142 static const uint8_t rest[32] = {
143 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, /* big wndian */
144 0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4 /* little endian */
145 };
146 const union {
147 uint32_t v;
148 uint8_t b[4];
149 } endian = {16};
150 uint32_t w = (~(*s++)) & mask[(uintptr_t)p & 3].v;
151 while (1) {
152 w = w & 0x80808080 & ((w & 0x7f7f7f7f) + 0x21212121);
153 if (w)
154 break;
155 w = ~(*s++);
156 }
157 /* bits 31, 23, 15, 7 -> 3, 2, 1, 0 */
158 w = (w * 0x00204081) & 0xffffffff;
159 w >>= 28;
160 p = (unsigned char *)s - rest[endian.b[0] + w];
161 }
162 *p++ = 0;
163 xine_sarray_add (e->list, q);
164 }
165}
166
167static inline int xine_gl_extensions_test (xine_gl_extensions_t *e, const char *name) {
168 return xine_sarray_binary_search (e->list, (void *)name) >= 0;
169}
170
171#endif /* XINE_GL_H_ */
unsigned int height
Definition gfontrle.c:5
unsigned int width
Definition gfontrle.c:4
int xine_sarray_binary_search(xine_sarray_t *sarray, void *key)
Definition sorted_array.c:176
void xine_sarray_delete(xine_sarray_t *sarray)
Definition sorted_array.c:228
int xine_sarray_add(xine_sarray_t *sarray, void *value)
Definition sorted_array.c:410
xine_sarray_t * xine_sarray_new(size_t initial_size, xine_sarray_comparator_t comparator)
Definition sorted_array.c:191
int(* xine_sarray_comparator_t)(void *item1, void *item2)
Definition sorted_array.h:67
Definition xine_gl.h:82
unsigned char * buf
Definition xine_gl.h:84
xine_sarray_t * list
Definition xine_gl.h:83
Definition xine_gl.h:38
void(* resize)(xine_gl_t *, int width, int height)
Definition xine_gl.h:44
int(* make_current)(xine_gl_t *)
Definition xine_gl.h:39
void(* swap_buffers)(xine_gl_t *)
Definition xine_gl.h:41
void(* release_current)(xine_gl_t *)
Definition xine_gl.h:40
int(* eglDestroyImageKHR)(xine_gl_t *, void *)
Definition xine_gl.h:58
void(* set_native_window)(xine_gl_t *, void *)
Definition xine_gl.h:46
void(* dispose)(xine_gl_t **)
Definition xine_gl.h:48
Definition xine_internal.h:80
Definition sorted_array.c:35
uint32_t v
Definition utils.c:1157
const char * name
Definition xine.c:1575
xine_gl_t * _x_load_gl(xine_t *xine, unsigned visual_type, const void *visual, unsigned flags)
Definition xine_gl.c:56
static int xine_gl_extensions_test(xine_gl_extensions_t *e, const char *name)
Definition xine_gl.h:167
static void xine_gl_extensions_load(xine_gl_extensions_t *e, const char *list)
Definition xine_gl.h:94
static void xine_gl_extensions_unload(xine_gl_extensions_t *e)
Definition xine_gl.h:87
static int _x_gl_has_extension(const char *extensions, const char *const ext)
Definition xine_gl.h:64
NULL
Definition xine_plugin.c:78