forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopendingux_fbdev_ctx.c
284 lines (241 loc) · 6.49 KB
/
opendingux_fbdev_ctx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2014 2015 - Jean-Andre Santoni
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <signal.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#ifdef HAVE_EGL
#include "../common/egl_common.h"
#endif
#if defined(HAVE_OPENGLES)
#include "../common/gl_common.h"
#endif
#include "../../frontend/frontend_driver.h"
typedef struct
{
#ifdef HAVE_EGL
egl_ctx_data_t egl;
EGLNativeWindowType native_window;
#endif
bool resize;
unsigned width, height;
} opendingux_ctx_data_t;
static void gfx_ctx_opendingux_destroy(void *data)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
if (viv)
{
#ifdef HAVE_EGL
egl_destroy(&viv->egl);
#endif
viv->resize = false;
free(viv);
}
}
static void *gfx_ctx_opendingux_init(video_frame_info_t *video_info, void *video_driver)
{
#ifdef HAVE_EGL
EGLint n;
EGLint major, minor;
EGLint format;
static const EGLint attribs[] = {
#if 0
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
#endif
EGL_BLUE_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_RED_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_SAMPLES, 0,
EGL_NONE
};
#endif
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)
calloc(1, sizeof(*viv));
if (!viv)
return NULL;
#ifdef HAVE_EGL
frontend_driver_install_signal_handler();
if (!egl_init_context(&viv->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
&major, &minor,
&n, attribs))
{
egl_report_error();
goto error;
}
#endif
return viv;
error:
#ifdef HAVE_EGL
RARCH_ERR("[opendingux fbdev]: EGL error: %d.\n", eglGetError());
#endif
gfx_ctx_opendingux_destroy(viv);
return NULL;
}
static void gfx_ctx_opendingux_get_video_size(void *data,
unsigned *width, unsigned *height)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
*width = viv->width;
*height = viv->height;
}
static void gfx_ctx_opendingux_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, bool is_shutdown)
{
unsigned new_width, new_height;
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_get_video_size(&viv->egl, &new_width, &new_height);
#endif
if (new_width != *width || new_height != *height)
{
*width = new_width;
*height = new_height;
*resize = true;
}
*quit = (bool)frontend_driver_get_signal_handler_state();
}
static bool gfx_ctx_opendingux_set_video_mode(void *data,
video_frame_info_t *video_info,
unsigned width, unsigned height,
bool fullscreen)
{
#ifdef HAVE_EGL
static const EGLint attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2, /* Use version 2, even for GLES3. */
EGL_NONE
};
#endif
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
/* Pick some arbitrary default. */
if (!width || !fullscreen)
width = 1280;
if (!height || !fullscreen)
height = 1024;
viv->width = width;
viv->height = height;
#ifdef HAVE_EGL
if (!egl_create_context(&viv->egl, attribs))
{
egl_report_error();
goto error;
}
viv->native_window = 0;
if (!egl_create_surface(&viv->egl, viv->native_window))
goto error;
#endif
return true;
error:
#ifdef HAVE_EGL
RARCH_ERR("[opendingux fbdev]: EGL error: %d.\n", eglGetError());
#endif
gfx_ctx_opendingux_destroy(data);
return false;
}
static void gfx_ctx_opendingux_input_driver(void *data,
const char *name,
const input_driver_t **input, void **input_data)
{
*input = NULL;
*input_data = NULL;
}
static bool gfx_ctx_opendingux_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
{
(void)data;
return api == GFX_CTX_OPENGL_ES_API;
}
static bool gfx_ctx_opendingux_has_focus(void *data)
{
(void)data;
return true;
}
static bool gfx_ctx_opendingux_suppress_screensaver(void *data, bool enable)
{
(void)data;
(void)enable;
return false;
}
static void gfx_ctx_opendingux_swap_buffers(void *data, void *data2)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_swap_buffers(&viv->egl);
#endif
}
static void gfx_ctx_opendingux_set_swap_interval(
void *data, unsigned swap_interval)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_set_swap_interval(&viv->egl, swap_interval);
#endif
}
static gfx_ctx_proc_t gfx_ctx_opendingux_get_proc_address(const char *symbol)
{
#ifdef HAVE_EGL
return egl_get_proc_address(symbol);
#endif
}
static void gfx_ctx_opendingux_bind_hw_render(void *data, bool enable)
{
opendingux_ctx_data_t *viv = (opendingux_ctx_data_t*)data;
#ifdef HAVE_EGL
egl_bind_hw_render(&viv->egl, enable);
#endif
}
static uint32_t gfx_ctx_opendingux_get_flags(void *data)
{
uint32_t flags = 0;
BIT32_SET(flags, GFX_CTX_FLAGS_NONE);
return flags;
}
static void gfx_ctx_opendingux_set_flags(void *data, uint32_t flags)
{
(void)data;
}
const gfx_ctx_driver_t gfx_ctx_opendingux_fbdev = {
gfx_ctx_opendingux_init,
gfx_ctx_opendingux_destroy,
gfx_ctx_opendingux_bind_api,
gfx_ctx_opendingux_set_swap_interval,
gfx_ctx_opendingux_set_video_mode,
gfx_ctx_opendingux_get_video_size,
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
NULL, /* get_metrics */
NULL,
NULL, /* update_title */
gfx_ctx_opendingux_check_window,
NULL, /* set_resize */
gfx_ctx_opendingux_has_focus,
gfx_ctx_opendingux_suppress_screensaver,
NULL, /* has_windowed */
gfx_ctx_opendingux_swap_buffers,
gfx_ctx_opendingux_input_driver,
gfx_ctx_opendingux_get_proc_address,
NULL,
NULL,
NULL,
"opendingux-fbdev",
gfx_ctx_opendingux_get_flags,
gfx_ctx_opendingux_set_flags,
gfx_ctx_opendingux_bind_hw_render,
NULL,
NULL
};