forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
menu_display.c
304 lines (250 loc) · 7.67 KB
/
menu_display.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* 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 <time.h>
#include "menu.h"
#include "menu_display.h"
#include "menu_animation.h"
#include "../dynamic.h"
#include "../../retroarch.h"
#include "../../config.def.h"
#include "../gfx/video_context_driver.h"
#include "../gfx/video_thread_wrapper.h"
#include "menu_list.h"
menu_display_t *menu_display_get_ptr(void)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return NULL;
return &menu->display;
}
menu_framebuf_t *menu_display_fb_get_ptr(void)
{
menu_display_t *disp = menu_display_get_ptr();
if (!disp)
return NULL;
return &disp->frame_buf;
}
static bool menu_display_fb_in_use(menu_framebuf_t *frame_buf)
{
if (!frame_buf)
return false;
return (frame_buf->data != NULL);
}
void menu_display_fb_set_dirty(void)
{
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
if (!menu_display_fb_in_use(frame_buf))
return;
frame_buf->dirty = true;
}
void menu_display_fb_unset_dirty(void)
{
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
if (!menu_display_fb_in_use(frame_buf))
return;
frame_buf->dirty = false;
}
/**
** menu_display_fb:
*
* Draws menu graphics onscreen.
**/
void menu_display_fb(void)
{
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
video_driver_set_texture_enable(true, false);
if (!settings->menu.pause_libretro)
{
if (global->main_is_init && (global->core_type != CORE_TYPE_DUMMY))
{
bool block_libretro_input = driver->block_libretro_input;
driver->block_libretro_input = true;
pretro_run();
driver->block_libretro_input = block_libretro_input;
return;
}
}
video_driver_cached_frame();
}
bool menu_display_update_pending(void)
{
menu_animation_t *anim = menu_animation_get_ptr();
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
if ((anim && anim->is_active) || (anim && anim->label.is_updated))
return true;
if (frame_buf && frame_buf->dirty)
return true;
return false;
}
static void menu_display_fb_free(menu_framebuf_t *frame_buf)
{
if (!frame_buf)
return;
if (frame_buf->data)
free(frame_buf->data);
frame_buf->data = NULL;
}
void menu_display_free(void *data)
{
menu_handle_t *menu = (menu_handle_t*)data;
menu_display_t *disp = menu ? &menu->display : NULL;
if (!disp)
return;
if (disp->msg_queue)
msg_queue_free(disp->msg_queue);
disp->msg_queue = NULL;
menu_animation_free(disp->animation);
disp->animation = NULL;
menu_display_fb_free(&disp->frame_buf);
}
bool menu_display_init(void *data)
{
menu_handle_t *menu = (menu_handle_t*)data;
if (!menu)
return false;
menu->display.animation = (menu_animation_t*)calloc
(1, sizeof(menu_animation_t));
if (!menu->display.animation)
return false;
return true;
}
float menu_display_get_dpi(void)
{
float dpi = menu_dpi_override_value;
settings_t *settings = config_get_ptr();
if (!settings)
return dpi;
if (settings->menu.dpi.override_enable)
dpi = settings->menu.dpi.override_value;
#if defined(HAVE_OPENGL) || defined(HAVE_GLES)
else if (!gfx_ctx_get_metrics(DISPLAY_METRIC_DPI, &dpi))
dpi = menu_dpi_override_value;
#endif
return dpi;
}
bool menu_display_font_init_first(const void **font_driver,
void **font_handle, void *video_data, const char *font_path,
float font_size)
{
settings_t *settings = config_get_ptr();
const struct retro_hw_render_callback *hw_render =
(const struct retro_hw_render_callback*)video_driver_callback();
if (settings->video.threaded && !hw_render->context_type)
{
thread_packet_t pkt;
driver_t *driver = driver_get_ptr();
thread_video_t *thr = (thread_video_t*)driver->video_data;
if (!thr)
return false;
pkt.type = CMD_FONT_INIT;
pkt.data.font_init.method = font_init_first;
pkt.data.font_init.font_driver = (const void**)font_driver;
pkt.data.font_init.font_handle = font_handle;
pkt.data.font_init.video_data = video_data;
pkt.data.font_init.font_path = font_path;
pkt.data.font_init.font_size = font_size;
pkt.data.font_init.api = FONT_DRIVER_RENDER_OPENGL_API;
thr->send_and_wait(thr, &pkt);
return pkt.data.font_init.return_value;
}
return font_init_first(font_driver, font_handle, video_data,
font_path, font_size, FONT_DRIVER_RENDER_OPENGL_API);
}
bool menu_display_font_bind_block(void *data,
const struct font_renderer *font_driver, void *userdata)
{
menu_display_t *disp = menu_display_get_ptr();
if (!disp || !font_driver || !font_driver->bind_block)
return false;
font_driver->bind_block(disp->font.buf, userdata);
return true;
}
bool menu_display_font_flush_block(void *data,
const struct font_renderer *font_driver)
{
menu_handle_t *menu = (menu_handle_t*)data;
if (!font_driver || !font_driver->flush)
return false;
font_driver->flush(menu->display.font.buf);
return menu_display_font_bind_block(menu,
font_driver, NULL);
}
void menu_display_free_main_font(void *data)
{
driver_t *driver = driver_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
if (disp && disp->font.buf)
{
driver->font_osd_driver->free(disp->font.buf);
disp->font.buf = NULL;
}
}
bool menu_display_init_main_font(void *data,
const char *font_path, float font_size)
{
bool ret;
menu_handle_t *menu = (menu_handle_t*)data;
driver_t *driver = driver_get_ptr();
void *video = video_driver_get_ptr(NULL);
menu_display_t *disp = menu ? &menu->display : NULL;
if (!disp)
return false;
if (disp->font.buf)
menu_display_free_main_font(menu);
ret = menu_display_font_init_first(
(const void**)&driver->font_osd_driver,
&disp->font.buf, video,
font_path, font_size);
if (ret)
disp->font.size = font_size;
else
disp->font.buf = NULL;
return ret;
}
void menu_display_set_viewport(void)
{
unsigned width, height;
video_driver_get_size(&width, &height);
video_driver_set_viewport(width, height, true, false);
}
void menu_display_unset_viewport(void)
{
unsigned width, height;
video_driver_get_size(&width, &height);
video_driver_set_viewport(width,
height, false, true);
}
void menu_display_timedate(char *s, size_t len, unsigned time_mode)
{
time_t time_;
time(&time_);
switch (time_mode)
{
case 0: /* Date and time */
strftime(s, len, "%Y-%m-%d %H:%M:%S", localtime(&time_));
break;
case 1: /* Date */
strftime(s, len, "%Y-%m-%d", localtime(&time_));
break;
case 2: /* Time */
strftime(s, len, "%H:%M:%S", localtime(&time_));
break;
case 3: /* Time (hours-minutes) */
strftime(s, len, "%H:%M", localtime(&time_));
break;
}
}