-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathgfx_thumbnail.h
More file actions
356 lines (314 loc) · 12.8 KB
/
gfx_thumbnail.h
File metadata and controls
356 lines (314 loc) · 12.8 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/* Copyright (C) 2010-2019 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (gfx_thumbnail.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __GFX_THUMBNAIL_H
#define __GFX_THUMBNAIL_H
#include <retro_common_api.h>
#include <libretro.h>
#include <boolean.h>
#include "gfx_animation.h"
#include "gfx_thumbnail_path.h"
RETRO_BEGIN_DECLS
/* Defines the current status of an entry
* thumbnail texture */
enum gfx_thumbnail_status
{
GFX_THUMBNAIL_STATUS_UNKNOWN = 0,
GFX_THUMBNAIL_STATUS_PENDING,
GFX_THUMBNAIL_STATUS_AVAILABLE,
GFX_THUMBNAIL_STATUS_MISSING
};
/* Defines thumbnail alignment within
* gfx_thumbnail_draw() bounding box */
enum gfx_thumbnail_alignment
{
GFX_THUMBNAIL_ALIGN_CENTRE = 0,
GFX_THUMBNAIL_ALIGN_TOP,
GFX_THUMBNAIL_ALIGN_BOTTOM,
GFX_THUMBNAIL_ALIGN_LEFT,
GFX_THUMBNAIL_ALIGN_RIGHT
};
/* Defines all possible thumbnail shadow
* effect types */
enum gfx_thumbnail_shadow_type
{
GFX_THUMBNAIL_SHADOW_NONE = 0,
GFX_THUMBNAIL_SHADOW_DROP,
GFX_THUMBNAIL_SHADOW_OUTLINE
};
enum gfx_thumbnail_flags
{
GFX_THUMB_FLAG_FADE_ACTIVE = (1 << 0),
GFX_THUMB_FLAG_CORE_ASPECT = (1 << 1)
};
/* Holds all runtime parameters associated with
* an entry thumbnail */
typedef struct
{
uintptr_t texture;
unsigned width;
unsigned height;
float alpha;
float delay_timer;
enum gfx_thumbnail_status status;
uint8_t flags;
} gfx_thumbnail_t;
/* Holds all configuration parameters associated
* with a thumbnail shadow effect */
typedef struct
{
struct
{
unsigned width;
} outline;
float alpha;
struct
{
float x_offset;
float y_offset;
} drop;
enum gfx_thumbnail_shadow_type type;
} gfx_thumbnail_shadow_t;
/* Structure containing all gfx_thumbnail
* variables */
struct gfx_thumbnail_state
{
/* Due to the asynchronous nature of thumbnail
* loading, it is quite possible to trigger a load
* then navigate to a different menu list before
* the load is complete/handled. As an additional
* safety check, we therefore tag the current menu
* list with counter value that is incremented whenever
* a list is cleared/set. This is sent as userdata when
* requesting a thumbnail, and the upload is only
* handled if the tag matches the most recent value
* at the time when the load completes */
uint64_t list_id;
/* When streaming thumbnails, to minimise the processing
* of unnecessary images (i.e. when scrolling rapidly through
* playlists), we delay loading until an entry has been on screen
* for at least gfx_thumbnail_delay ms */
float stream_delay;
/* Duration in ms of the thumbnail 'fade in' animation */
float fade_duration;
/* When true, 'fade in' animation will also be
* triggered for missing thumbnails */
bool fade_missing;
/* LOW-MEMORY FIX: Maximum number of concurrent thumbnail load tasks
* Helps prevent memory exhaustion on low-memory devices (RPi, Switch, etc.) */
unsigned max_concurrent_loads;
unsigned current_loads;
};
typedef struct gfx_thumbnail_state gfx_thumbnail_state_t;
/* Setters */
/* When streaming thumbnails, sets time in ms that an
* entry must be on screen before an image load is
* requested
* > if 'delay' is negative, default value is set */
void gfx_thumbnail_set_stream_delay(float delay);
/* Sets duration in ms of the thumbnail 'fade in'
* animation
* > If 'duration' is negative, default value is set */
void gfx_thumbnail_set_fade_duration(float duration);
/* Specifies whether 'fade in' animation should be
* triggered for missing thumbnails
* > When 'true', allows menu driver to animate
* any 'thumbnail unavailable' notifications */
void gfx_thumbnail_set_fade_missing(bool fade_missing);
/* LOW-MEMORY FIX: Concurrent load management API */
/* Sets maximum number of concurrent thumbnail load tasks
* allowed at any time. Helps prevent memory exhaustion on
* low-memory devices.
* > Use 0 for unlimited (default behavior) */
void gfx_thumbnail_set_max_concurrent_loads(unsigned max_loads);
/* Returns current number of active thumbnail load tasks */
unsigned gfx_thumbnail_get_concurrent_loads(void);
/* Returns whether a new thumbnail load can be started */
bool gfx_thumbnail_can_start_load(void);
/* Core interface */
/* When called, prevents the handling of any pending
* thumbnail load requests
* >> **MUST** be called before deleting any gfx_thumbnail_t
* objects passed to gfx_thumbnail_request() or
* gfx_thumbnail_process_stream(), otherwise
* heap-use-after-free errors *will* occur */
void gfx_thumbnail_cancel_pending_requests(void);
/* Requests loading of the specified thumbnail
* - If operation fails, 'thumbnail->status' will be set to
* MUI_THUMBNAIL_STATUS_MISSING
* - If operation is successful, 'thumbnail->status' will be
* set to MUI_THUMBNAIL_STATUS_PENDING
* 'thumbnail' will be populated with texture info/metadata
* once the image load is complete
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
* and gfx_thumbnail_set_content*()
* NOTE 2: 'playlist' and 'idx' are only required here for
* on-demand thumbnail download support
* (an annoyance...) */
void gfx_thumbnail_request(
gfx_thumbnail_path_data_t *path_data, enum gfx_thumbnail_id thumbnail_id,
playlist_t *playlist, size_t idx, gfx_thumbnail_t *thumbnail,
unsigned gfx_thumbnail_upscale_threshold,
bool network_on_demand_thumbnails);
/* Requests loading of a specific thumbnail image file
* (may be used, for example, to load savestate images)
* - If operation fails, 'thumbnail->status' will be set to
* MUI_THUMBNAIL_STATUS_MISSING
* - If operation is successful, 'thumbnail->status' will be
* set to MUI_THUMBNAIL_STATUS_PENDING
* 'thumbnail' will be populated with texture info/metadata
* once the image load is complete */
void gfx_thumbnail_request_file(
const char *file_path, gfx_thumbnail_t *thumbnail,
unsigned gfx_thumbnail_upscale_threshold);
/* Resets (and free()s the current texture of) the
* specified thumbnail */
void gfx_thumbnail_reset(gfx_thumbnail_t *thumbnail);
/* Stream processing */
/* Requests loading of the specified thumbnail via
* the stream interface
* - Must be called on each frame for the duration
* that specified thumbnail is on-screen
* - Actual load request is deferred by currently
* set stream delay
* - Function becomes a no-op once load request is
* made
* - Thumbnails loaded via this function must be
* deleted manually via gfx_thumbnail_reset()
* when they move off-screen
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
* and gfx_thumbnail_set_content*()
* NOTE 2: 'playlist' and 'idx' are only required here for
* on-demand thumbnail download support
* (an annoyance...)
* NOTE 3: This function is intended for use in situations
* where each menu entry has a *single* thumbnail.
* If each entry has two thumbnails, use
* gfx_thumbnail_request_streams() for improved
* performance */
void gfx_thumbnail_request_stream(
gfx_thumbnail_path_data_t *path_data,
gfx_animation_t *p_anim,
enum gfx_thumbnail_id thumbnail_id,
playlist_t *playlist, size_t idx,
gfx_thumbnail_t *thumbnail,
unsigned gfx_thumbnail_upscale_threshold,
bool network_on_demand_thumbnails);
/* Requests loading of the specified thumbnails via
* the stream interface
* - Must be called on each frame for the duration
* that specified thumbnails are on-screen
* - Actual load request is deferred by currently
* set stream delay
* - Function becomes a no-op once load request is
* made
* - Thumbnails loaded via this function must be
* deleted manually via gfx_thumbnail_reset()
* when they move off-screen
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
* and gfx_thumbnail_set_content*()
* NOTE 2: 'playlist' and 'idx' are only required here for
* on-demand thumbnail download support
* (an annoyance...)
* NOTE 3: This function is intended for use in situations
* where each menu entry has *two* thumbnails.
* If each entry only has a single thumbnail, use
* gfx_thumbnail_request_stream() for improved
* performance */
void gfx_thumbnail_request_streams(
gfx_thumbnail_path_data_t *path_data,
gfx_animation_t *p_anim,
playlist_t *playlist, size_t idx,
gfx_thumbnail_t *right_thumbnail,
gfx_thumbnail_t *left_thumbnail,
unsigned gfx_thumbnail_upscale_threshold,
bool network_on_demand_thumbnails);
/* Handles streaming of the specified thumbnail as it moves
* on/off screen
* - Must be called each frame for every on-screen entry
* - Must be called once for each entry as it moves off-screen
* (or can be called each frame - overheads are small)
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
* NOTE 2: This function calls gfx_thumbnail_set_content*()
* NOTE 3: This function is intended for use in situations
* where each menu entry has a *single* thumbnail.
* If each entry has two thumbnails, use
* gfx_thumbnail_process_streams() for improved
* performance */
void gfx_thumbnail_process_stream(
gfx_thumbnail_path_data_t *path_data,
gfx_animation_t *p_anim,
enum gfx_thumbnail_id thumbnail_id,
playlist_t *playlist, size_t idx,
gfx_thumbnail_t *thumbnail,
bool on_screen,
unsigned gfx_thumbnail_upscale_threshold,
bool network_on_demand_thumbnails);
/* Handles streaming of the specified thumbnails as they move
* on/off screen
* - Must be called each frame for every on-screen entry
* - Must be called once for each entry as it moves off-screen
* (or can be called each frame - overheads are small)
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
* NOTE 2: This function calls gfx_thumbnail_set_content*()
* NOTE 3: This function is intended for use in situations
* where each menu entry has *two* thumbnails.
* If each entry only has a single thumbnail, use
* gfx_thumbnail_process_stream() for improved
* performance */
void gfx_thumbnail_process_streams(
gfx_thumbnail_path_data_t *path_data,
gfx_animation_t *p_anim,
playlist_t *playlist, size_t idx,
gfx_thumbnail_t *right_thumbnail,
gfx_thumbnail_t *left_thumbnail,
bool on_screen,
unsigned gfx_thumbnail_upscale_threshold,
bool network_on_demand_thumbnails);
/* Thumbnail rendering */
/* Determines the actual screen dimensions of a
* thumbnail when centred with aspect correct
* scaling within a rectangle of (width x height) */
void gfx_thumbnail_get_draw_dimensions(
gfx_thumbnail_t *thumbnail,
unsigned width, unsigned height, float scale_factor,
float *draw_width, float *draw_height);
/* Draws specified thumbnail with specified alignment
* (and aspect correct scaling) within a rectangle of
* (width x height).
* 'shadow' defines an optional shadow effect (may be
* set to NULL if a shadow effect is not required).
* NOTE: Setting scale_factor > 1.0f will increase the
* size of the thumbnail beyond the limits of the
* (width x height) rectangle (alignment + aspect
* correct scaling is preserved). Use with caution */
void gfx_thumbnail_draw(
void *userdata,
unsigned video_width,
unsigned video_height,
gfx_thumbnail_t *thumbnail,
float x, float y, unsigned width, unsigned height,
enum gfx_thumbnail_alignment alignment,
float alpha, float scale_factor,
gfx_thumbnail_shadow_t *shadow);
gfx_thumbnail_state_t *gfx_thumb_get_ptr(void);
RETRO_END_DECLS
#endif