2019-10-31 17:24:24 +00:00
|
|
|
/* Copyright (C) 2010-2019 The RetroArch team
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------------------------------------------
|
2020-02-16 15:38:17 +00:00
|
|
|
* The following license statement only applies to this file (gfx_thumbnail.c).
|
2019-10-31 17:24:24 +00:00
|
|
|
* ---------------------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <features/features_cpu.h>
|
|
|
|
#include <file/file_path.h>
|
2019-11-08 16:25:36 +00:00
|
|
|
#include <string/stdstring.h>
|
2019-10-31 17:24:24 +00:00
|
|
|
|
2020-02-16 15:38:17 +00:00
|
|
|
#include "gfx_display.h"
|
|
|
|
#include "gfx_animation.h"
|
2019-10-31 17:24:24 +00:00
|
|
|
|
2020-02-16 15:38:17 +00:00
|
|
|
#include "gfx_thumbnail.h"
|
2019-10-31 17:24:24 +00:00
|
|
|
|
2020-01-04 11:38:33 +00:00
|
|
|
#include "../tasks/tasks_internal.h"
|
|
|
|
|
2020-03-06 15:47:12 +00:00
|
|
|
#define DEFAULT_GFX_THUMBNAIL_STREAM_DELAY 83.333333f
|
2020-02-16 15:38:17 +00:00
|
|
|
#define DEFAULT_GFX_THUMBNAIL_FADE_DURATION 166.66667f
|
2020-03-06 15:47:12 +00:00
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* Utility structure, sent as userdata when pushing
|
|
|
|
* an image load */
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-08-05 08:55:06 +00:00
|
|
|
uint64_t list_id;
|
2020-08-15 21:02:01 +00:00
|
|
|
gfx_thumbnail_t *thumbnail;
|
2020-02-16 15:38:17 +00:00
|
|
|
} gfx_thumbnail_tag_t;
|
2019-10-31 17:24:24 +00:00
|
|
|
|
2024-11-19 02:03:13 +00:00
|
|
|
static gfx_thumbnail_state_t gfx_thumb_st = {0}; /* uint64_t alignment */
|
2021-09-30 16:05:00 +00:00
|
|
|
|
|
|
|
gfx_thumbnail_state_t *gfx_thumb_get_ptr(void)
|
|
|
|
{
|
|
|
|
return &gfx_thumb_st;
|
|
|
|
}
|
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* Setters */
|
|
|
|
|
|
|
|
/* When streaming thumbnails, sets time in ms that an
|
|
|
|
* entry must be on screen before an image load is
|
2020-03-06 15:47:12 +00:00
|
|
|
* requested
|
|
|
|
* > if 'delay' is negative, default value is set */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_set_stream_delay(float delay)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
2021-09-30 16:05:00 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-03-06 15:47:12 +00:00
|
|
|
|
|
|
|
p_gfx_thumb->stream_delay = (delay >= 0.0f) ?
|
2020-02-16 15:38:17 +00:00
|
|
|
delay : DEFAULT_GFX_THUMBNAIL_STREAM_DELAY;
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets duration in ms of the thumbnail 'fade in'
|
2020-03-06 15:47:12 +00:00
|
|
|
* animation
|
|
|
|
* > If 'duration' is negative, default value is set */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_set_fade_duration(float duration)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
2021-09-30 16:05:00 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-03-06 15:47:12 +00:00
|
|
|
|
|
|
|
p_gfx_thumb->fade_duration = (duration >= 0.0f) ?
|
2020-02-16 15:38:17 +00:00
|
|
|
duration : DEFAULT_GFX_THUMBNAIL_FADE_DURATION;
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 13:30:49 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
2021-09-30 16:05:00 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-05-09 13:30:49 +00:00
|
|
|
|
|
|
|
p_gfx_thumb->fade_missing = fade_missing;
|
|
|
|
}
|
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* Callbacks */
|
|
|
|
|
2020-05-19 12:48:05 +00:00
|
|
|
/* Fade animation callback - simply resets thumbnail
|
|
|
|
* 'fade_active' status */
|
|
|
|
static void gfx_thumbnail_fade_cb(void *userdata)
|
|
|
|
{
|
|
|
|
gfx_thumbnail_t *thumbnail = (gfx_thumbnail_t*)userdata;
|
2022-10-08 20:52:18 +00:00
|
|
|
if (thumbnail)
|
|
|
|
thumbnail->flags |= GFX_THUMB_FLAG_FADE_ACTIVE;
|
2020-05-19 12:48:05 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 13:30:49 +00:00
|
|
|
/* Initialises thumbnail 'fade in' animation */
|
2020-06-08 03:57:47 +00:00
|
|
|
static void gfx_thumbnail_init_fade(
|
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb,
|
|
|
|
gfx_thumbnail_t *thumbnail)
|
2020-05-09 13:30:49 +00:00
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
if (!thumbnail)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* A 'fade in' animation is triggered if:
|
|
|
|
* - Thumbnail is available
|
|
|
|
* - Thumbnail is missing and 'fade_missing' is enabled */
|
2023-07-18 14:46:54 +00:00
|
|
|
if ( (thumbnail->status == GFX_THUMBNAIL_STATUS_AVAILABLE)
|
|
|
|
|| (p_gfx_thumb->fade_missing
|
|
|
|
&& (thumbnail->status == GFX_THUMBNAIL_STATUS_MISSING)))
|
2020-05-09 13:30:49 +00:00
|
|
|
{
|
|
|
|
if (p_gfx_thumb->fade_duration > 0.0f)
|
|
|
|
{
|
|
|
|
gfx_animation_ctx_entry_t animation_entry;
|
|
|
|
|
2020-05-19 12:48:05 +00:00
|
|
|
thumbnail->alpha = 0.0f;
|
2022-10-08 20:52:18 +00:00
|
|
|
thumbnail->flags |= GFX_THUMB_FLAG_FADE_ACTIVE;
|
2020-05-09 13:30:49 +00:00
|
|
|
|
|
|
|
animation_entry.easing_enum = EASING_OUT_QUAD;
|
|
|
|
animation_entry.tag = (uintptr_t)&thumbnail->alpha;
|
|
|
|
animation_entry.duration = p_gfx_thumb->fade_duration;
|
|
|
|
animation_entry.target_value = 1.0f;
|
|
|
|
animation_entry.subject = &thumbnail->alpha;
|
2020-05-19 12:48:05 +00:00
|
|
|
animation_entry.cb = gfx_thumbnail_fade_cb;
|
|
|
|
animation_entry.userdata = thumbnail;
|
2020-05-09 13:30:49 +00:00
|
|
|
|
|
|
|
gfx_animation_push(&animation_entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
thumbnail->alpha = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* Used to process thumbnail data following completion
|
|
|
|
* of image load task */
|
2020-02-16 15:38:17 +00:00
|
|
|
static void gfx_thumbnail_handle_upload(
|
2019-10-31 17:24:24 +00:00
|
|
|
retro_task_t *task, void *task_data, void *user_data, const char *err)
|
|
|
|
{
|
2021-09-30 16:05:00 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-03-06 15:47:12 +00:00
|
|
|
struct texture_image *img = (struct texture_image*)task_data;
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_tag_t *thumbnail_tag = (gfx_thumbnail_tag_t*)user_data;
|
2020-05-09 13:30:49 +00:00
|
|
|
bool fade_enabled = false;
|
2019-10-31 17:24:24 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (!thumbnail_tag)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Ensure that we are operating on the correct
|
|
|
|
* thumbnail... */
|
2020-03-06 15:47:12 +00:00
|
|
|
if (thumbnail_tag->list_id != p_gfx_thumb->list_id)
|
2019-10-31 17:24:24 +00:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Only process image if we are waiting for it */
|
2020-02-16 15:38:17 +00:00
|
|
|
if (thumbnail_tag->thumbnail->status != GFX_THUMBNAIL_STATUS_PENDING)
|
2019-10-31 17:24:24 +00:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Sanity check: if thumbnail already has a texture,
|
|
|
|
* we're in some kind of weird error state - in this
|
|
|
|
* case, the best course of action is to just reset
|
|
|
|
* the thumbnail... */
|
|
|
|
if (thumbnail_tag->thumbnail->texture)
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(thumbnail_tag->thumbnail);
|
2019-10-31 17:24:24 +00:00
|
|
|
|
|
|
|
/* Set thumbnail 'missing' status by default
|
|
|
|
* (saves a number of checks later) */
|
2020-02-16 15:38:17 +00:00
|
|
|
thumbnail_tag->thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
2019-10-31 17:24:24 +00:00
|
|
|
|
2020-05-09 13:30:49 +00:00
|
|
|
/* If we reach this stage, thumbnail 'fade in'
|
|
|
|
* animations should be applied (based on current
|
|
|
|
* thumbnail status and global configuration) */
|
|
|
|
fade_enabled = true;
|
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* Check we have a valid image */
|
2020-08-18 14:53:19 +00:00
|
|
|
if (!img || (img->width < 1) || (img->height < 1))
|
2019-10-31 17:24:24 +00:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Upload texture to GPU */
|
2019-11-08 16:25:36 +00:00
|
|
|
if (!video_driver_texture_load(
|
2020-08-18 14:53:19 +00:00
|
|
|
img, TEXTURE_FILTER_MIPMAP_LINEAR,
|
|
|
|
&thumbnail_tag->thumbnail->texture))
|
2019-11-08 16:25:36 +00:00
|
|
|
goto end;
|
2019-10-31 17:24:24 +00:00
|
|
|
|
|
|
|
/* Cache dimensions */
|
|
|
|
thumbnail_tag->thumbnail->width = img->width;
|
|
|
|
thumbnail_tag->thumbnail->height = img->height;
|
|
|
|
|
|
|
|
/* Update thumbnail status */
|
2020-02-16 15:38:17 +00:00
|
|
|
thumbnail_tag->thumbnail->status = GFX_THUMBNAIL_STATUS_AVAILABLE;
|
2019-10-31 17:24:24 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
/* Clean up */
|
|
|
|
if (img)
|
|
|
|
{
|
|
|
|
image_texture_free(img);
|
|
|
|
free(img);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thumbnail_tag)
|
2020-05-09 13:30:49 +00:00
|
|
|
{
|
|
|
|
/* Trigger 'fade in' animation, if required */
|
|
|
|
if (fade_enabled)
|
2020-06-08 03:57:47 +00:00
|
|
|
gfx_thumbnail_init_fade(p_gfx_thumb,
|
|
|
|
thumbnail_tag->thumbnail);
|
2020-05-09 13:30:49 +00:00
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
free(thumbnail_tag);
|
2020-05-09 13:30:49 +00:00
|
|
|
}
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Core interface */
|
|
|
|
|
|
|
|
/* When called, prevents the handling of any pending
|
|
|
|
* thumbnail load requests
|
2020-02-16 15:38:17 +00:00
|
|
|
* >> **MUST** be called before deleting any gfx_thumbnail_t
|
|
|
|
* objects passed to gfx_thumbnail_request() or
|
|
|
|
* gfx_thumbnail_process_stream(), otherwise
|
2019-10-31 17:24:24 +00:00
|
|
|
* heap-use-after-free errors *will* occur */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_cancel_pending_requests(void)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
2021-09-30 16:05:00 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-03-06 15:47:12 +00:00
|
|
|
|
|
|
|
p_gfx_thumb->list_id++;
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Requests loading of the specified thumbnail
|
|
|
|
* - If operation fails, 'thumbnail->status' will be set to
|
2020-02-16 15:38:17 +00:00
|
|
|
* GFX_THUMBNAIL_STATUS_MISSING
|
2019-10-31 17:24:24 +00:00
|
|
|
* - If operation is successful, 'thumbnail->status' will be
|
2020-02-16 15:38:17 +00:00
|
|
|
* set to GFX_THUMBNAIL_STATUS_PENDING
|
2019-10-31 17:24:24 +00:00
|
|
|
* 'thumbnail' will be populated with texture info/metadata
|
|
|
|
* once the image load is complete
|
2020-02-16 15:38:17 +00:00
|
|
|
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
|
|
|
|
* and gfx_thumbnail_set_content*()
|
2019-10-31 17:24:24 +00:00
|
|
|
* NOTE 2: 'playlist' and 'idx' are only required here for
|
|
|
|
* on-demand thumbnail download support
|
2023-09-03 15:37:00 +00:00
|
|
|
* (an annoyance...) */
|
2020-02-16 15:38:17 +00:00
|
|
|
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,
|
2022-05-19 15:40:21 +00:00
|
|
|
bool network_on_demand_thumbnails)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
2022-05-19 15:40:21 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2023-09-03 15:37:00 +00:00
|
|
|
|
2020-01-04 11:38:33 +00:00
|
|
|
if (!path_data || !thumbnail)
|
2019-10-31 17:24:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Reset thumbnail, then set 'missing' status by default
|
|
|
|
* (saves a number of checks later) */
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(thumbnail);
|
|
|
|
thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
2019-10-31 17:24:24 +00:00
|
|
|
|
|
|
|
/* Update/extract thumbnail path */
|
2020-02-16 15:38:17 +00:00
|
|
|
if (gfx_thumbnail_is_enabled(path_data, thumbnail_id))
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
2023-09-03 15:37:00 +00:00
|
|
|
if (gfx_thumbnail_update_path(path_data, thumbnail_id))
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
2023-09-03 15:37:00 +00:00
|
|
|
const char *thumbnail_path = NULL;
|
|
|
|
if (gfx_thumbnail_get_path(path_data, thumbnail_id, &thumbnail_path))
|
|
|
|
{
|
|
|
|
/* Load thumbnail, if required */
|
|
|
|
if (path_is_valid(thumbnail_path))
|
|
|
|
{
|
|
|
|
gfx_thumbnail_tag_t *thumbnail_tag =
|
|
|
|
(gfx_thumbnail_tag_t*)malloc(sizeof(gfx_thumbnail_tag_t));
|
|
|
|
|
|
|
|
if (!thumbnail_tag)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Configure user data */
|
|
|
|
thumbnail_tag->thumbnail = thumbnail;
|
|
|
|
thumbnail_tag->list_id = p_gfx_thumb->list_id;
|
|
|
|
|
|
|
|
/* Would like to cancel any existing image load tasks
|
|
|
|
* here, but can't see how to do it... */
|
|
|
|
if (task_push_image_load(
|
|
|
|
thumbnail_path, video_driver_supports_rgba(),
|
|
|
|
gfx_thumbnail_upscale_threshold,
|
|
|
|
gfx_thumbnail_handle_upload, thumbnail_tag))
|
|
|
|
thumbnail->status = GFX_THUMBNAIL_STATUS_PENDING;
|
|
|
|
}
|
2019-10-31 17:24:24 +00:00
|
|
|
#ifdef HAVE_NETWORKING
|
2023-09-03 15:37:00 +00:00
|
|
|
/* Handle on demand thumbnail downloads */
|
|
|
|
else if (network_on_demand_thumbnails)
|
|
|
|
{
|
2024-09-09 13:22:08 +00:00
|
|
|
enum playlist_thumbnail_name_flags curr_flag;
|
2023-09-03 15:37:00 +00:00
|
|
|
const char *system = NULL;
|
|
|
|
const char *img_name = NULL;
|
2024-11-19 02:03:13 +00:00
|
|
|
static char last_img_name[NAME_MAX_LENGTH] = {0};
|
2024-01-29 16:42:39 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2023-09-03 15:37:00 +00:00
|
|
|
if (!playlist)
|
|
|
|
goto end;
|
|
|
|
|
2023-12-27 10:26:46 +00:00
|
|
|
/* Validate entry */
|
|
|
|
if (!gfx_thumbnail_get_img_name(path_data, &img_name, PLAYLIST_THUMBNAIL_FLAG_STD_NAME))
|
2023-09-03 15:37:00 +00:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Only trigger a thumbnail download if image
|
|
|
|
* name has changed since the last call of
|
|
|
|
* gfx_thumbnail_request()
|
|
|
|
* > Allows gfx_thumbnail_request() to be used
|
|
|
|
* for successive right/left thumbnail requests
|
|
|
|
* with minimal duplication of effort
|
|
|
|
* (i.e. task_push_pl_entry_thumbnail_download()
|
|
|
|
* will automatically cancel if a download for the
|
|
|
|
* existing playlist entry is pending, but the
|
|
|
|
* checks required for this involve significant
|
|
|
|
* overheads. We can avoid this entirely with
|
|
|
|
* a simple string comparison) */
|
|
|
|
if (string_is_equal(img_name, last_img_name))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
strlcpy(last_img_name, img_name, sizeof(last_img_name));
|
|
|
|
|
|
|
|
/* Get system name */
|
|
|
|
if (!gfx_thumbnail_get_system(path_data, &system))
|
|
|
|
goto end;
|
|
|
|
|
2024-01-07 15:57:39 +00:00
|
|
|
/* Since task_push_pl_entry_download will shift the flag, do not attempt if it is already
|
|
|
|
* at second to last option. */
|
|
|
|
curr_flag = playlist_get_curr_thumbnail_name_flag(playlist,idx);
|
|
|
|
if (curr_flag & PLAYLIST_THUMBNAIL_FLAG_NONE || curr_flag & PLAYLIST_THUMBNAIL_FLAG_SHORT_NAME)
|
2023-12-27 10:26:46 +00:00
|
|
|
goto end;
|
2024-01-29 16:42:39 +00:00
|
|
|
/* Do not try to fetch full names here, if it is not explicitly wanted */
|
2024-09-09 13:22:08 +00:00
|
|
|
if (!settings->bools.playlist_use_filename &&
|
2024-01-29 16:42:39 +00:00
|
|
|
!playlist_thumbnail_match_with_filename(playlist) &&
|
|
|
|
curr_flag == PLAYLIST_THUMBNAIL_FLAG_INVALID)
|
|
|
|
playlist_update_thumbnail_name_flag(playlist, idx, PLAYLIST_THUMBNAIL_FLAG_FULL_NAME);
|
2023-12-27 10:26:46 +00:00
|
|
|
|
|
|
|
/* Trigger thumbnail download *
|
|
|
|
* Note: download will grab all 3 possible thumbnails, no matter
|
|
|
|
* what left/right thumbnails are set at the moment */
|
2023-09-03 15:37:00 +00:00
|
|
|
task_push_pl_entry_thumbnail_download(
|
|
|
|
system, playlist, (unsigned)idx,
|
|
|
|
false, true);
|
|
|
|
}
|
2019-10-31 17:24:24 +00:00
|
|
|
#endif
|
2023-09-03 15:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
2020-05-09 13:30:49 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
/* Trigger 'fade in' animation, if required */
|
|
|
|
if (thumbnail->status != GFX_THUMBNAIL_STATUS_PENDING)
|
2020-06-08 03:57:47 +00:00
|
|
|
gfx_thumbnail_init_fade(p_gfx_thumb,
|
|
|
|
thumbnail);
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 17:01:52 +00:00
|
|
|
/* 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 */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_request_file(
|
|
|
|
const char *file_path, gfx_thumbnail_t *thumbnail,
|
2022-05-19 15:40:21 +00:00
|
|
|
unsigned gfx_thumbnail_upscale_threshold)
|
2019-12-10 17:01:52 +00:00
|
|
|
{
|
2021-09-30 16:05:00 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_tag_t *thumbnail_tag = NULL;
|
2019-12-10 17:01:52 +00:00
|
|
|
|
2020-01-04 11:38:33 +00:00
|
|
|
if (!thumbnail)
|
2019-12-10 17:01:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Reset thumbnail, then set 'missing' status by default
|
|
|
|
* (saves a number of checks later) */
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(thumbnail);
|
|
|
|
thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
2019-12-10 17:01:52 +00:00
|
|
|
|
|
|
|
/* Check if file path is valid */
|
2022-07-10 16:13:25 +00:00
|
|
|
if ( string_is_empty(file_path)
|
|
|
|
|| !path_is_valid(file_path))
|
2019-12-10 17:01:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Load thumbnail */
|
2022-07-10 16:13:25 +00:00
|
|
|
if (!(thumbnail_tag = (gfx_thumbnail_tag_t*)malloc(sizeof(gfx_thumbnail_tag_t))))
|
2019-12-10 17:01:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Configure user data */
|
|
|
|
thumbnail_tag->thumbnail = thumbnail;
|
2020-03-06 15:47:12 +00:00
|
|
|
thumbnail_tag->list_id = p_gfx_thumb->list_id;
|
2019-12-10 17:01:52 +00:00
|
|
|
|
|
|
|
/* Would like to cancel any existing image load tasks
|
|
|
|
* here, but can't see how to do it... */
|
2020-02-10 12:18:27 +00:00
|
|
|
if (task_push_image_load(
|
2019-12-10 17:01:52 +00:00
|
|
|
file_path, video_driver_supports_rgba(),
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_upscale_threshold,
|
|
|
|
gfx_thumbnail_handle_upload, thumbnail_tag))
|
|
|
|
thumbnail->status = GFX_THUMBNAIL_STATUS_PENDING;
|
2019-12-10 17:01:52 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* Resets (and free()s the current texture of) the
|
|
|
|
* specified thumbnail */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_reset(gfx_thumbnail_t *thumbnail)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
|
|
|
if (!thumbnail)
|
|
|
|
return;
|
|
|
|
|
2020-05-19 12:48:05 +00:00
|
|
|
/* Unload texture */
|
2019-10-31 17:24:24 +00:00
|
|
|
if (thumbnail->texture)
|
|
|
|
video_driver_texture_unload(&thumbnail->texture);
|
|
|
|
|
2020-05-19 12:48:05 +00:00
|
|
|
/* Ensure any 'fade in' animation is killed */
|
2022-10-08 20:52:18 +00:00
|
|
|
if (thumbnail->flags & GFX_THUMB_FLAG_FADE_ACTIVE)
|
2020-05-19 12:48:05 +00:00
|
|
|
{
|
2020-06-08 02:09:12 +00:00
|
|
|
uintptr_t tag = (uintptr_t)&thumbnail->alpha;
|
2020-02-16 13:01:34 +00:00
|
|
|
gfx_animation_kill_by_tag(&tag);
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset all parameters */
|
2020-02-16 15:38:17 +00:00
|
|
|
thumbnail->status = GFX_THUMBNAIL_STATUS_UNKNOWN;
|
2019-10-31 17:24:24 +00:00
|
|
|
thumbnail->texture = 0;
|
|
|
|
thumbnail->width = 0;
|
|
|
|
thumbnail->height = 0;
|
|
|
|
thumbnail->alpha = 0.0f;
|
|
|
|
thumbnail->delay_timer = 0.0f;
|
2022-10-08 20:52:18 +00:00
|
|
|
thumbnail->flags &= ~(GFX_THUMB_FLAG_FADE_ACTIVE
|
|
|
|
| GFX_THUMB_FLAG_CORE_ASPECT);
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Stream processing */
|
|
|
|
|
2022-05-19 15:40:21 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
|
|
|
|
|
|
|
/* Only process request if current status
|
|
|
|
* is GFX_THUMBNAIL_STATUS_UNKNOWN */
|
2023-07-18 14:46:54 +00:00
|
|
|
if ( !thumbnail
|
|
|
|
|| (thumbnail->status != GFX_THUMBNAIL_STATUS_UNKNOWN))
|
2022-05-19 15:40:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check if stream delay timer has elapsed */
|
|
|
|
thumbnail->delay_timer += p_anim->delta_time;
|
|
|
|
|
|
|
|
if (thumbnail->delay_timer > p_gfx_thumb->stream_delay)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
if (!path_data)
|
|
|
|
{
|
|
|
|
/* No path information
|
|
|
|
* > Reset thumbnail and set missing status
|
|
|
|
* to prevent repeated load attempts */
|
|
|
|
gfx_thumbnail_reset(thumbnail);
|
|
|
|
thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
|
|
|
thumbnail->alpha = 1.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request image load */
|
|
|
|
gfx_thumbnail_request(
|
|
|
|
path_data, thumbnail_id, playlist, idx, thumbnail,
|
|
|
|
gfx_thumbnail_upscale_threshold,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
bool process_right = false;
|
|
|
|
bool process_left = false;
|
|
|
|
|
|
|
|
if (!right_thumbnail || !left_thumbnail)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Only process request if current status
|
|
|
|
* is GFX_THUMBNAIL_STATUS_UNKNOWN */
|
|
|
|
process_right = (right_thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN);
|
|
|
|
process_left = (left_thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN);
|
|
|
|
|
|
|
|
if (process_right || process_left)
|
|
|
|
{
|
|
|
|
/* Check if stream delay timer has elapsed */
|
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
|
|
|
float delta_time = p_anim->delta_time;
|
|
|
|
bool request_right = false;
|
|
|
|
bool request_left = false;
|
|
|
|
|
|
|
|
if (process_right)
|
|
|
|
{
|
|
|
|
right_thumbnail->delay_timer += delta_time;
|
|
|
|
request_right =
|
|
|
|
(right_thumbnail->delay_timer > p_gfx_thumb->stream_delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process_left)
|
|
|
|
{
|
|
|
|
left_thumbnail->delay_timer += delta_time;
|
|
|
|
request_left =
|
|
|
|
(left_thumbnail->delay_timer > p_gfx_thumb->stream_delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if one or more thumbnails should be requested */
|
|
|
|
if (request_right || request_left)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
if (!path_data)
|
|
|
|
{
|
|
|
|
/* No path information
|
|
|
|
* > Reset thumbnail and set missing status
|
|
|
|
* to prevent repeated load attempts */
|
|
|
|
if (request_right)
|
|
|
|
{
|
|
|
|
gfx_thumbnail_reset(right_thumbnail);
|
|
|
|
right_thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
|
|
|
right_thumbnail->alpha = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request_left)
|
|
|
|
{
|
|
|
|
gfx_thumbnail_reset(left_thumbnail);
|
|
|
|
left_thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
|
|
|
left_thumbnail->alpha = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request image load */
|
|
|
|
if (request_right)
|
|
|
|
gfx_thumbnail_request(
|
|
|
|
path_data, GFX_THUMBNAIL_RIGHT, playlist, idx, right_thumbnail,
|
|
|
|
gfx_thumbnail_upscale_threshold,
|
|
|
|
network_on_demand_thumbnails);
|
|
|
|
|
|
|
|
if (request_left)
|
|
|
|
gfx_thumbnail_request(
|
|
|
|
path_data, GFX_THUMBNAIL_LEFT, playlist, idx, left_thumbnail,
|
|
|
|
gfx_thumbnail_upscale_threshold,
|
|
|
|
network_on_demand_thumbnails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* 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
|
2019-11-08 16:25:36 +00:00
|
|
|
* (or can be called each frame - overheads are small)
|
2020-02-16 15:38:17 +00:00
|
|
|
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
|
|
|
|
* NOTE 2: This function calls gfx_thumbnail_set_content*()
|
2019-11-08 16:25:36 +00:00
|
|
|
* 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
|
2020-02-16 15:38:17 +00:00
|
|
|
* gfx_thumbnail_process_streams() for improved
|
2019-11-08 16:25:36 +00:00
|
|
|
* performance */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_process_stream(
|
2021-04-07 23:30:42 +00:00
|
|
|
gfx_thumbnail_path_data_t *path_data,
|
|
|
|
gfx_animation_t *p_anim,
|
|
|
|
enum gfx_thumbnail_id thumbnail_id,
|
2022-05-19 15:40:21 +00:00
|
|
|
playlist_t *playlist, size_t idx,
|
2021-04-07 23:30:42 +00:00
|
|
|
gfx_thumbnail_t *thumbnail,
|
|
|
|
bool on_screen,
|
2020-02-16 15:38:17 +00:00
|
|
|
unsigned gfx_thumbnail_upscale_threshold,
|
2022-05-19 15:40:21 +00:00
|
|
|
bool network_on_demand_thumbnails)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
|
|
|
if (!thumbnail)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (on_screen)
|
|
|
|
{
|
|
|
|
/* Entry is on-screen
|
|
|
|
* > Only process if current status is
|
2020-02-16 15:38:17 +00:00
|
|
|
* GFX_THUMBNAIL_STATUS_UNKNOWN */
|
|
|
|
if (thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
2022-05-19 15:40:21 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-03-06 15:47:12 +00:00
|
|
|
|
2019-10-31 17:24:24 +00:00
|
|
|
/* Check if stream delay timer has elapsed */
|
2022-05-19 15:40:21 +00:00
|
|
|
thumbnail->delay_timer += p_anim->delta_time;
|
2019-10-31 17:24:24 +00:00
|
|
|
|
2020-03-06 15:47:12 +00:00
|
|
|
if (thumbnail->delay_timer > p_gfx_thumb->stream_delay)
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
|
|
|
/* Update thumbnail content */
|
2023-07-18 14:46:54 +00:00
|
|
|
if ( !path_data
|
|
|
|
|| !playlist
|
|
|
|
|| !gfx_thumbnail_set_content_playlist(path_data, playlist, idx))
|
2019-10-31 17:24:24 +00:00
|
|
|
{
|
|
|
|
/* Content is invalid
|
|
|
|
* > Reset thumbnail and set missing status */
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(thumbnail);
|
|
|
|
thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
2020-07-31 14:13:43 +00:00
|
|
|
thumbnail->alpha = 1.0f;
|
2019-10-31 17:24:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request image load */
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_request(
|
2020-01-04 11:38:33 +00:00
|
|
|
path_data, thumbnail_id, playlist, idx, thumbnail,
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_upscale_threshold,
|
2022-05-19 15:40:21 +00:00
|
|
|
network_on_demand_thumbnails);
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Entry is off-screen
|
2020-02-16 15:38:17 +00:00
|
|
|
* > If status is GFX_THUMBNAIL_STATUS_UNKNOWN,
|
2019-11-15 14:51:54 +00:00
|
|
|
* thumbnail is already in a blank state - but we
|
|
|
|
* must ensure that delay timer is set to zero */
|
2020-02-16 15:38:17 +00:00
|
|
|
if (thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN)
|
2019-11-15 14:51:54 +00:00
|
|
|
thumbnail->delay_timer = 0.0f;
|
|
|
|
/* In all other cases, reset thumbnail */
|
|
|
|
else
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(thumbnail);
|
2019-10-31 17:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-08 16:25:36 +00:00
|
|
|
|
|
|
|
/* 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)
|
2020-02-16 15:38:17 +00:00
|
|
|
* NOTE 1: Must be called *after* gfx_thumbnail_set_system()
|
|
|
|
* NOTE 2: This function calls gfx_thumbnail_set_content*()
|
2019-11-08 16:25:36 +00:00
|
|
|
* 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
|
2020-02-16 15:38:17 +00:00
|
|
|
* gfx_thumbnail_process_stream() for improved
|
2019-11-08 16:25:36 +00:00
|
|
|
* performance */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_process_streams(
|
|
|
|
gfx_thumbnail_path_data_t *path_data,
|
2021-04-07 23:30:42 +00:00
|
|
|
gfx_animation_t *p_anim,
|
2019-11-08 16:25:36 +00:00
|
|
|
playlist_t *playlist, size_t idx,
|
2021-04-07 23:30:42 +00:00
|
|
|
gfx_thumbnail_t *right_thumbnail,
|
|
|
|
gfx_thumbnail_t *left_thumbnail,
|
2020-01-04 11:38:33 +00:00
|
|
|
bool on_screen,
|
2020-02-16 15:38:17 +00:00
|
|
|
unsigned gfx_thumbnail_upscale_threshold,
|
2022-05-19 15:40:21 +00:00
|
|
|
bool network_on_demand_thumbnails)
|
2019-11-08 16:25:36 +00:00
|
|
|
{
|
|
|
|
if (!right_thumbnail || !left_thumbnail)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (on_screen)
|
|
|
|
{
|
|
|
|
/* Entry is on-screen
|
|
|
|
* > Only process if current status is
|
2020-02-16 15:38:17 +00:00
|
|
|
* GFX_THUMBNAIL_STATUS_UNKNOWN */
|
|
|
|
bool process_right = (right_thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN);
|
|
|
|
bool process_left = (left_thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN);
|
2019-11-08 16:25:36 +00:00
|
|
|
|
|
|
|
if (process_right || process_left)
|
|
|
|
{
|
|
|
|
/* Check if stream delay timer has elapsed */
|
2022-05-19 15:40:21 +00:00
|
|
|
gfx_thumbnail_state_t *p_gfx_thumb = &gfx_thumb_st;
|
2020-09-24 04:14:04 +00:00
|
|
|
float delta_time = p_anim->delta_time;
|
2020-03-06 15:47:12 +00:00
|
|
|
bool request_right = false;
|
|
|
|
bool request_left = false;
|
2019-11-08 16:25:36 +00:00
|
|
|
|
|
|
|
if (process_right)
|
|
|
|
{
|
|
|
|
right_thumbnail->delay_timer += delta_time;
|
|
|
|
request_right =
|
2020-03-06 15:47:12 +00:00
|
|
|
(right_thumbnail->delay_timer > p_gfx_thumb->stream_delay);
|
2019-11-08 16:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process_left)
|
|
|
|
{
|
|
|
|
left_thumbnail->delay_timer += delta_time;
|
|
|
|
request_left =
|
2020-03-06 15:47:12 +00:00
|
|
|
(left_thumbnail->delay_timer > p_gfx_thumb->stream_delay);
|
2019-11-08 16:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if one or more thumbnails should be requested */
|
|
|
|
if (request_right || request_left)
|
|
|
|
{
|
|
|
|
/* Update thumbnail content */
|
2023-07-18 14:46:54 +00:00
|
|
|
if ( !path_data
|
|
|
|
|| !playlist
|
|
|
|
|| !gfx_thumbnail_set_content_playlist(path_data, playlist, idx))
|
2019-11-08 16:25:36 +00:00
|
|
|
{
|
|
|
|
/* Content is invalid
|
|
|
|
* > Reset thumbnail and set missing status */
|
|
|
|
if (request_right)
|
|
|
|
{
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(right_thumbnail);
|
|
|
|
right_thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
2020-07-31 14:13:43 +00:00
|
|
|
right_thumbnail->alpha = 1.0f;
|
2019-11-08 16:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (request_left)
|
|
|
|
{
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(left_thumbnail);
|
|
|
|
left_thumbnail->status = GFX_THUMBNAIL_STATUS_MISSING;
|
2020-07-31 14:13:43 +00:00
|
|
|
left_thumbnail->alpha = 1.0f;
|
2019-11-08 16:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request image load */
|
|
|
|
if (request_right)
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_request(
|
|
|
|
path_data, GFX_THUMBNAIL_RIGHT, playlist, idx, right_thumbnail,
|
|
|
|
gfx_thumbnail_upscale_threshold,
|
2020-01-04 11:38:33 +00:00
|
|
|
network_on_demand_thumbnails);
|
2019-11-08 16:25:36 +00:00
|
|
|
|
|
|
|
if (request_left)
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_request(
|
|
|
|
path_data, GFX_THUMBNAIL_LEFT, playlist, idx, left_thumbnail,
|
|
|
|
gfx_thumbnail_upscale_threshold,
|
2020-01-04 11:38:33 +00:00
|
|
|
network_on_demand_thumbnails);
|
2019-11-08 16:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Entry is off-screen
|
2020-02-16 15:38:17 +00:00
|
|
|
* > If status is GFX_THUMBNAIL_STATUS_UNKNOWN,
|
2019-11-15 14:51:54 +00:00
|
|
|
* thumbnail is already in a blank state - but we
|
|
|
|
* must ensure that delay timer is set to zero
|
|
|
|
* > In all other cases, reset thumbnail */
|
2020-02-16 15:38:17 +00:00
|
|
|
if (right_thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN)
|
2019-11-15 14:51:54 +00:00
|
|
|
right_thumbnail->delay_timer = 0.0f;
|
|
|
|
else
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(right_thumbnail);
|
2019-11-08 16:25:36 +00:00
|
|
|
|
2020-02-16 15:38:17 +00:00
|
|
|
if (left_thumbnail->status == GFX_THUMBNAIL_STATUS_UNKNOWN)
|
2019-11-15 14:51:54 +00:00
|
|
|
left_thumbnail->delay_timer = 0.0f;
|
|
|
|
else
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_reset(left_thumbnail);
|
2019-11-08 16:25:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Thumbnail rendering */
|
|
|
|
|
2019-11-20 18:09:02 +00:00
|
|
|
/* Determines the actual screen dimensions of a
|
|
|
|
* thumbnail when centred with aspect correct
|
|
|
|
* scaling within a rectangle of (width x height) */
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_get_draw_dimensions(
|
|
|
|
gfx_thumbnail_t *thumbnail,
|
2019-11-20 18:09:02 +00:00
|
|
|
unsigned width, unsigned height, float scale_factor,
|
|
|
|
float *draw_width, float *draw_height)
|
|
|
|
{
|
2022-07-10 16:13:25 +00:00
|
|
|
float core_aspect;
|
2019-11-20 18:09:02 +00:00
|
|
|
float display_aspect;
|
|
|
|
float thumbnail_aspect;
|
2022-07-10 16:13:25 +00:00
|
|
|
video_driver_state_t *video_st = video_state_get_ptr();
|
2019-11-20 18:09:02 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
2023-09-03 15:37:00 +00:00
|
|
|
if ( !thumbnail
|
|
|
|
|| (width < 1)
|
2022-07-10 16:13:25 +00:00
|
|
|
|| (height < 1)
|
2023-09-03 15:37:00 +00:00
|
|
|
|| (thumbnail->width < 1)
|
2022-07-10 16:13:25 +00:00
|
|
|
|| (thumbnail->height < 1))
|
|
|
|
{
|
|
|
|
*draw_width = 0.0f;
|
|
|
|
*draw_height = 0.0f;
|
|
|
|
return;
|
|
|
|
}
|
2019-11-20 18:09:02 +00:00
|
|
|
|
2022-07-03 14:14:51 +00:00
|
|
|
/* Account for display/thumbnail/core aspect ratio
|
2019-11-20 18:09:02 +00:00
|
|
|
* differences */
|
|
|
|
display_aspect = (float)width / (float)height;
|
|
|
|
thumbnail_aspect = (float)thumbnail->width / (float)thumbnail->height;
|
2023-09-03 15:37:00 +00:00
|
|
|
core_aspect = ((thumbnail->flags & GFX_THUMB_FLAG_CORE_ASPECT)
|
2023-01-09 03:13:11 +00:00
|
|
|
&& video_st && video_st->av_info.geometry.aspect_ratio > 0)
|
|
|
|
? video_st->av_info.geometry.aspect_ratio
|
|
|
|
: thumbnail_aspect;
|
2019-11-20 18:09:02 +00:00
|
|
|
|
|
|
|
if (thumbnail_aspect > display_aspect)
|
|
|
|
{
|
|
|
|
*draw_width = (float)width;
|
|
|
|
*draw_height = (float)thumbnail->height * (*draw_width / (float)thumbnail->width);
|
2022-07-03 14:14:51 +00:00
|
|
|
|
2022-10-08 20:52:18 +00:00
|
|
|
if (thumbnail->flags & GFX_THUMB_FLAG_CORE_ASPECT)
|
2022-07-03 14:14:51 +00:00
|
|
|
{
|
2022-07-05 10:01:21 +00:00
|
|
|
*draw_height = *draw_height * (thumbnail_aspect / core_aspect);
|
|
|
|
|
|
|
|
if (*draw_height > height)
|
|
|
|
{
|
|
|
|
*draw_height = (float)height;
|
|
|
|
*draw_width = (float)thumbnail->width * (*draw_height / (float)thumbnail->height);
|
|
|
|
*draw_width = *draw_width / (thumbnail_aspect / core_aspect);
|
|
|
|
}
|
2022-07-03 14:14:51 +00:00
|
|
|
}
|
2019-11-20 18:09:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*draw_height = (float)height;
|
|
|
|
*draw_width = (float)thumbnail->width * (*draw_height / (float)thumbnail->height);
|
2022-07-05 10:01:21 +00:00
|
|
|
|
2022-10-08 20:52:18 +00:00
|
|
|
if (thumbnail->flags & GFX_THUMB_FLAG_CORE_ASPECT)
|
2022-07-05 10:01:21 +00:00
|
|
|
*draw_width = *draw_width / (thumbnail_aspect / core_aspect);
|
2019-11-20 18:09:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Account for scale factor
|
2020-02-16 14:10:07 +00:00
|
|
|
* > Side note: We cannot use the gfx_display_ctx_draw_t
|
2019-11-20 18:09:02 +00:00
|
|
|
* 'scale_factor' parameter for scaling thumbnails,
|
|
|
|
* since this clips off any part of the expanded image
|
|
|
|
* that extends beyond the bounding box. But even if
|
|
|
|
* it didn't, we can't get real screen dimensions
|
|
|
|
* without scaling manually... */
|
|
|
|
*draw_width *= scale_factor;
|
|
|
|
*draw_height *= scale_factor;
|
|
|
|
}
|
|
|
|
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Draws specified thumbnail with specified alignment
|
|
|
|
* (and aspect correct scaling) within a rectangle of
|
2019-12-10 17:01:52 +00:00
|
|
|
* (width x height).
|
|
|
|
* 'shadow' defines an optional shadow effect (may be
|
|
|
|
* set to NULL if a shadow effect is not required).
|
2019-11-08 16:25:36 +00:00
|
|
|
* NOTE: Setting scale_factor > 1.0f will increase the
|
|
|
|
* size of the thumbnail beyond the limits of the
|
2019-11-25 13:14:25 +00:00
|
|
|
* (width x height) rectangle (alignment + aspect
|
2019-11-08 16:25:36 +00:00
|
|
|
* correct scaling is preserved). Use with caution */
|
2020-03-09 01:15:44 +00:00
|
|
|
|
2020-02-16 15:38:17 +00:00
|
|
|
void gfx_thumbnail_draw(
|
2020-03-09 01:15:44 +00:00
|
|
|
void *userdata,
|
|
|
|
unsigned video_width,
|
|
|
|
unsigned video_height,
|
|
|
|
gfx_thumbnail_t *thumbnail,
|
2019-11-08 16:25:36 +00:00
|
|
|
float x, float y, unsigned width, unsigned height,
|
2020-02-16 15:38:17 +00:00
|
|
|
enum gfx_thumbnail_alignment alignment,
|
2019-12-10 17:01:52 +00:00
|
|
|
float alpha, float scale_factor,
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_shadow_t *shadow)
|
2019-11-08 16:25:36 +00:00
|
|
|
{
|
2020-10-05 19:44:13 +00:00
|
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
|
|
gfx_display_ctx_driver_t *dispctx = p_disp->dispctx;
|
2019-11-08 16:25:36 +00:00
|
|
|
/* Sanity check */
|
2022-07-10 16:13:25 +00:00
|
|
|
if (
|
|
|
|
!thumbnail
|
|
|
|
|| !dispctx
|
|
|
|
|| (width < 1)
|
|
|
|
|| (height < 1)
|
|
|
|
|| (alpha <= 0.0f)
|
|
|
|
|| (scale_factor <= 0.0f)
|
|
|
|
)
|
2020-10-05 19:44:13 +00:00
|
|
|
return;
|
2019-11-08 16:25:36 +00:00
|
|
|
|
|
|
|
/* Only draw thumbnail if it is available... */
|
2020-02-16 15:38:17 +00:00
|
|
|
if (thumbnail->status == GFX_THUMBNAIL_STATUS_AVAILABLE)
|
2019-11-08 16:25:36 +00:00
|
|
|
{
|
2020-02-16 14:10:07 +00:00
|
|
|
gfx_display_ctx_draw_t draw;
|
2019-11-08 16:25:36 +00:00
|
|
|
struct video_coords coords;
|
|
|
|
math_matrix_4x4 mymat;
|
|
|
|
float draw_width;
|
|
|
|
float draw_height;
|
2019-12-10 17:01:52 +00:00
|
|
|
float draw_x;
|
|
|
|
float draw_y;
|
2019-11-08 16:25:36 +00:00
|
|
|
float thumbnail_alpha = thumbnail->alpha * alpha;
|
|
|
|
float thumbnail_color[16] = {
|
|
|
|
1.0f, 1.0f, 1.0f, 1.0f,
|
|
|
|
1.0f, 1.0f, 1.0f, 1.0f,
|
|
|
|
1.0f, 1.0f, 1.0f, 1.0f,
|
|
|
|
1.0f, 1.0f, 1.0f, 1.0f
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Set thumbnail opacity */
|
|
|
|
if (thumbnail_alpha <= 0.0f)
|
|
|
|
return;
|
2020-10-05 19:44:13 +00:00
|
|
|
if (thumbnail_alpha < 1.0f)
|
2020-02-16 14:10:07 +00:00
|
|
|
gfx_display_set_alpha(thumbnail_color, thumbnail_alpha);
|
2019-11-08 16:25:36 +00:00
|
|
|
|
|
|
|
/* Get thumbnail dimensions */
|
2020-02-16 15:38:17 +00:00
|
|
|
gfx_thumbnail_get_draw_dimensions(
|
2019-11-20 18:09:02 +00:00
|
|
|
thumbnail, width, height, scale_factor,
|
|
|
|
&draw_width, &draw_height);
|
2019-11-08 16:25:36 +00:00
|
|
|
|
2020-10-05 19:44:13 +00:00
|
|
|
if (dispctx->blend_begin)
|
2020-09-23 07:32:42 +00:00
|
|
|
dispctx->blend_begin(userdata);
|
2019-11-08 16:25:36 +00:00
|
|
|
|
2022-07-05 15:20:01 +00:00
|
|
|
if (!p_disp->dispctx->handles_transform)
|
|
|
|
{
|
|
|
|
/* Perform 'rotation' step
|
|
|
|
* > Note that rotation does not actually work...
|
|
|
|
* > It rotates the image all right, but distorts it
|
|
|
|
* to fit the aspect of the bounding box while clipping
|
|
|
|
* off any 'corners' that extend beyond the bounding box
|
|
|
|
* > Since the result is visual garbage, we disable
|
|
|
|
* rotation entirely
|
|
|
|
* > But we still have to call gfx_display_rotate_z(),
|
|
|
|
* or nothing will be drawn...
|
2022-07-05 18:50:01 +00:00
|
|
|
*/
|
2022-07-06 09:03:15 +00:00
|
|
|
float cosine = 1.0f; /* cos(rad) = cos(0) = 1.0f */
|
|
|
|
float sine = 0.0f; /* sine(rad) = sine(0) = 0.0f */
|
|
|
|
gfx_display_rotate_z(p_disp, &mymat, cosine, sine, userdata);
|
2022-07-05 15:20:01 +00:00
|
|
|
}
|
2019-11-08 16:25:36 +00:00
|
|
|
|
2019-12-10 17:01:52 +00:00
|
|
|
/* Configure draw object
|
|
|
|
* > Note: Colour, width/height and position must
|
|
|
|
* be set *after* drawing any shadow effects */
|
2019-11-08 16:25:36 +00:00
|
|
|
coords.vertices = 4;
|
|
|
|
coords.vertex = NULL;
|
|
|
|
coords.tex_coord = NULL;
|
|
|
|
coords.lut_tex_coord = NULL;
|
|
|
|
|
|
|
|
draw.scale_factor = 1.0f;
|
|
|
|
draw.rotation = 0.0f;
|
|
|
|
draw.coords = &coords;
|
|
|
|
draw.matrix_data = &mymat;
|
|
|
|
draw.texture = thumbnail->texture;
|
2020-02-16 14:10:07 +00:00
|
|
|
draw.prim_type = GFX_DISPLAY_PRIM_TRIANGLESTRIP;
|
2020-08-14 13:58:43 +00:00
|
|
|
draw.pipeline_id = 0;
|
2019-11-08 16:25:36 +00:00
|
|
|
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Set thumbnail alignment within bounding box */
|
|
|
|
switch (alignment)
|
|
|
|
{
|
2020-02-16 15:38:17 +00:00
|
|
|
case GFX_THUMBNAIL_ALIGN_TOP:
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Centred horizontally */
|
2019-12-10 17:01:52 +00:00
|
|
|
draw_x = x + ((float)width - draw_width) / 2.0f;
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Drawn at top of bounding box */
|
2020-03-07 20:18:12 +00:00
|
|
|
draw_y = (float)video_height - y - draw_height;
|
2019-11-25 13:14:25 +00:00
|
|
|
break;
|
2020-02-16 15:38:17 +00:00
|
|
|
case GFX_THUMBNAIL_ALIGN_BOTTOM:
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Centred horizontally */
|
2019-12-10 17:01:52 +00:00
|
|
|
draw_x = x + ((float)width - draw_width) / 2.0f;
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Drawn at bottom of bounding box */
|
2020-03-07 20:18:12 +00:00
|
|
|
draw_y = (float)video_height - y - (float)height;
|
2019-11-25 13:14:25 +00:00
|
|
|
break;
|
2020-02-16 15:38:17 +00:00
|
|
|
case GFX_THUMBNAIL_ALIGN_LEFT:
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Drawn at left side of bounding box */
|
2019-12-10 17:01:52 +00:00
|
|
|
draw_x = x;
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Centred vertically */
|
2020-03-07 20:18:12 +00:00
|
|
|
draw_y = (float)video_height - y - draw_height - ((float)height - draw_height) / 2.0f;
|
2019-11-25 13:14:25 +00:00
|
|
|
break;
|
2020-02-16 15:38:17 +00:00
|
|
|
case GFX_THUMBNAIL_ALIGN_RIGHT:
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Drawn at right side of bounding box */
|
2019-12-10 17:01:52 +00:00
|
|
|
draw_x = x + (float)width - draw_width;
|
2019-11-25 13:14:25 +00:00
|
|
|
/* Centred vertically */
|
2020-03-07 20:18:12 +00:00
|
|
|
draw_y = (float)video_height - y - draw_height - ((float)height - draw_height) / 2.0f;
|
2019-11-25 13:14:25 +00:00
|
|
|
break;
|
2020-02-16 15:38:17 +00:00
|
|
|
case GFX_THUMBNAIL_ALIGN_CENTRE:
|
2019-11-25 13:14:25 +00:00
|
|
|
default:
|
|
|
|
/* Centred both horizontally and vertically */
|
2019-12-10 17:01:52 +00:00
|
|
|
draw_x = x + ((float)width - draw_width) / 2.0f;
|
2020-03-07 20:18:12 +00:00
|
|
|
draw_y = (float)video_height - y - draw_height - ((float)height - draw_height) / 2.0f;
|
2019-11-25 13:14:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-11-08 16:25:36 +00:00
|
|
|
|
2019-12-10 17:01:52 +00:00
|
|
|
/* Draw shadow effect, if required */
|
|
|
|
if (shadow)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
2023-07-18 14:46:54 +00:00
|
|
|
if ( (shadow->type != GFX_THUMBNAIL_SHADOW_NONE)
|
|
|
|
&& (shadow->alpha > 0.0f))
|
2019-12-10 17:01:52 +00:00
|
|
|
{
|
|
|
|
float shadow_width;
|
|
|
|
float shadow_height;
|
|
|
|
float shadow_x;
|
|
|
|
float shadow_y;
|
|
|
|
float shadow_color[16] = {
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f
|
|
|
|
};
|
|
|
|
float shadow_alpha = thumbnail_alpha;
|
|
|
|
|
|
|
|
/* Set shadow opacity */
|
|
|
|
if (shadow->alpha < 1.0f)
|
|
|
|
shadow_alpha *= shadow->alpha;
|
|
|
|
|
2020-02-16 14:10:07 +00:00
|
|
|
gfx_display_set_alpha(shadow_color, shadow_alpha);
|
2019-12-10 17:01:52 +00:00
|
|
|
|
|
|
|
/* Configure shadow based on effect type
|
|
|
|
* > Not using a switch() here, since we've
|
2020-02-16 15:38:17 +00:00
|
|
|
* already eliminated GFX_THUMBNAIL_SHADOW_NONE */
|
|
|
|
if (shadow->type == GFX_THUMBNAIL_SHADOW_OUTLINE)
|
2019-12-10 17:01:52 +00:00
|
|
|
{
|
|
|
|
shadow_width = draw_width + (float)(shadow->outline.width * 2);
|
|
|
|
shadow_height = draw_height + (float)(shadow->outline.width * 2);
|
|
|
|
shadow_x = draw_x - (float)shadow->outline.width;
|
|
|
|
shadow_y = draw_y - (float)shadow->outline.width;
|
|
|
|
}
|
2020-02-16 15:38:17 +00:00
|
|
|
/* Default: GFX_THUMBNAIL_SHADOW_DROP */
|
2019-12-10 17:01:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
shadow_width = draw_width;
|
|
|
|
shadow_height = draw_height;
|
|
|
|
shadow_x = draw_x + shadow->drop.x_offset;
|
|
|
|
shadow_y = draw_y - shadow->drop.y_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply shadow draw object configuration */
|
|
|
|
coords.color = (const float*)shadow_color;
|
|
|
|
draw.width = (unsigned)shadow_width;
|
|
|
|
draw.height = (unsigned)shadow_height;
|
|
|
|
draw.x = shadow_x;
|
|
|
|
draw.y = shadow_y;
|
|
|
|
|
|
|
|
/* Draw shadow */
|
2020-09-23 20:14:30 +00:00
|
|
|
if (draw.height > 0 && draw.width > 0)
|
2020-10-05 19:44:13 +00:00
|
|
|
if (dispctx->draw)
|
2020-09-23 20:14:30 +00:00
|
|
|
dispctx->draw(&draw, userdata, video_width, video_height);
|
2019-12-10 17:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Final thumbnail draw object configuration */
|
|
|
|
coords.color = (const float*)thumbnail_color;
|
|
|
|
draw.width = (unsigned)draw_width;
|
|
|
|
draw.height = (unsigned)draw_height;
|
|
|
|
draw.x = draw_x;
|
|
|
|
draw.y = draw_y;
|
|
|
|
|
2019-11-08 16:25:36 +00:00
|
|
|
/* Draw thumbnail */
|
2020-10-05 19:44:13 +00:00
|
|
|
if (draw.height > 0 && draw.width > 0)
|
2020-09-23 20:14:30 +00:00
|
|
|
if (dispctx->draw)
|
2020-10-05 19:44:13 +00:00
|
|
|
dispctx->draw(&draw, userdata, video_width, video_height);
|
|
|
|
|
|
|
|
if (dispctx->blend_end)
|
|
|
|
dispctx->blend_end(userdata);
|
2019-11-08 16:25:36 +00:00
|
|
|
}
|
|
|
|
}
|