Refactors pt3 (#12124)

* Remove video_pixel_get_alignment - move it to video
drivers that use it

* Rewrite video_driver_pixel_converter_{init/free} - get rid of
p_rarch dependency

* Replace some variables

* (Menu) Get rid of cbs_refresh - was never set to any other
function callback implementation
This commit is contained in:
Autechre 2021-03-11 02:03:37 +01:00 committed by GitHub
parent cb5fba6b2a
commit a2ed065f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 88 additions and 151 deletions

View File

@ -1032,7 +1032,6 @@ ifeq ($(HAVE_MENU_COMMON), 1)
menu/cbs/menu_cbs_select.o \
menu/cbs/menu_cbs_start.o \
menu/cbs/menu_cbs_info.o \
menu/cbs/menu_cbs_refresh.o \
menu/cbs/menu_cbs_left.o \
menu/cbs/menu_cbs_right.o \
menu/cbs/menu_cbs_deferred_push.o \

View File

@ -243,6 +243,17 @@ void glkitview_bind_fbo(void);
#define gl2_renderchain_bind_backbuffer() gl2_bind_fb(0)
#endif
static unsigned gl2_get_alignment(unsigned pitch)
{
if (pitch & 1)
return 1;
if (pitch & 2)
return 2;
if (pitch & 4)
return 4;
return 8;
}
static bool gl2_shader_info(gl_t *gl,
video_shader_ctx_info_t *shader_info)
{
@ -1439,7 +1450,7 @@ static void gl2_renderchain_copy_frame(
#endif
{
glPixelStorei(GL_UNPACK_ALIGNMENT,
video_pixel_get_alignment(width * gl->base_size));
gl2_get_alignment(width * gl->base_size));
/* Fallback for GLES devices without GL_BGRA_EXT. */
if (gl->base_size == 4 && use_rgba)
@ -1492,7 +1503,7 @@ static void gl2_renderchain_copy_frame(
#else
{
const GLvoid *data_buf = frame;
glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(pitch));
glPixelStorei(GL_UNPACK_ALIGNMENT, gl2_get_alignment(pitch));
if (gl->base_size == 2 && !gl->have_es2_compat)
{
@ -2124,7 +2135,7 @@ static void gl2_update_input_size(gl_t *gl, unsigned width,
if (clear)
{
glPixelStorei(GL_UNPACK_ALIGNMENT,
video_pixel_get_alignment(width * sizeof(uint32_t)));
gl2_get_alignment(width * sizeof(uint32_t)));
#if defined(HAVE_PSGL)
glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE,
gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size,
@ -2261,7 +2272,7 @@ static void gl2_set_texture_frame(void *data,
gl_load_texture_data(gl->menu_texture,
RARCH_WRAP_EDGE, menu_filter,
video_pixel_get_alignment(width * base_size),
gl2_get_alignment(width * base_size),
width, height, frame,
base_size);
@ -2486,7 +2497,7 @@ static void gl2_pbo_async_readback(gl_t *gl)
gl->pbo_readback_valid[gl->pbo_readback_index] = true;
gl2_renderchain_readback(gl, gl->renderchain_data,
video_pixel_get_alignment(gl->vp.width * sizeof(uint32_t)),
gl2_get_alignment(gl->vp.width * sizeof(uint32_t)),
fmt, type, NULL);
gl2_renderchain_unbind_pbo();
}
@ -2618,11 +2629,8 @@ static void gl2_video_layout_free(gl_t *gl)
static void *gl2_video_layout_take_image(void *video_driver_data, struct texture_image image)
{
unsigned alignment;
GLuint tex;
tex = 0;
alignment = video_pixel_get_alignment(image.width * sizeof(uint32_t));
GLuint tex = 0;
unsigned alignment = gl2_get_alignment(image.width * sizeof(uint32_t));
glGenTextures(1, &tex);
@ -4294,7 +4302,7 @@ static bool gl2_overlay_load(void *data,
for (i = 0; i < num_images; i++)
{
unsigned alignment = video_pixel_get_alignment(images[i].width
unsigned alignment = gl2_get_alignment(images[i].width
* sizeof(uint32_t));
gl_load_texture_data(gl->overlay_tex[i],

View File

@ -1477,6 +1477,17 @@ static void gl1_gfx_set_viewport_wrapper(void *data, unsigned viewport_width,
}
#ifdef HAVE_OVERLAY
static unsigned gl1_get_alignment(unsigned pitch)
{
if (pitch & 1)
return 1;
if (pitch & 2)
return 2;
if (pitch & 4)
return 4;
return 8;
}
static bool gl1_overlay_load(void *data,
const void *image_data, unsigned num_images)
{
@ -1517,7 +1528,7 @@ static bool gl1_overlay_load(void *data,
for (i = 0; i < num_images; i++)
{
unsigned alignment = video_pixel_get_alignment(images[i].width
unsigned alignment = gl1_get_alignment(images[i].width
* sizeof(uint32_t));
gl1_load_texture_data(gl->overlay_tex[i],

View File

@ -1380,7 +1380,6 @@ MENU
#include "../menu/cbs/menu_cbs_select.c"
#include "../menu/cbs/menu_cbs_start.c"
#include "../menu/cbs/menu_cbs_info.c"
#include "../menu/cbs/menu_cbs_refresh.c"
#include "../menu/cbs/menu_cbs_left.c"
#include "../menu/cbs/menu_cbs_right.c"
#include "../menu/cbs/menu_cbs_title.c"

View File

@ -24,6 +24,7 @@ static int deferred_push_content_list(void *data, void *userdata,
const char *path,
const char *label, unsigned type)
{
menu_displaylist_ctx_entry_t entry;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
/* Must clear any existing menu search terms
@ -35,7 +36,12 @@ static int deferred_push_content_list(void *data, void *userdata,
menu_driver_search_clear();
menu_navigation_set_selection(0);
return action_refresh_default((file_list_t*)data, selection_buf);
entry.list = (file_list_t*)data;
entry.stack = selection_buf;
if (!menu_displaylist_push(&entry))
return -1;
return 0;
}
int menu_cbs_init_bind_content_list_switch(menu_file_list_cbs_t *cbs,

View File

@ -1,46 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - 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 "../menu_driver.h"
#include "../menu_cbs.h"
#ifndef BIND_ACTION_REFRESH
#define BIND_ACTION_REFRESH(cbs, name) (cbs)->action_refresh = (name)
#endif
int action_refresh_default(file_list_t *list, file_list_t *menu_list)
{
menu_displaylist_ctx_entry_t entry;
if (!menu_list)
return -1;
entry.list = list;
entry.stack = menu_list;
if (!menu_displaylist_push(&entry))
return -1;
return 0;
}
int menu_cbs_init_bind_refresh(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx)
{
if (!cbs)
return -1;
BIND_ACTION_REFRESH(cbs, action_refresh_default);
return -1;
}

View File

@ -221,8 +221,6 @@ int action_cb_push_dropdown_item_resolution(const char *path,
int action_cancel_pop_default(const char *path,
const char *label, unsigned type, size_t idx);
int action_refresh_default(file_list_t *list, file_list_t *menu_list);
int shader_action_parameter_right(unsigned type, const char *label, bool wraparound);
int shader_action_preset_parameter_right(unsigned type, const char *label, bool wraparound);
@ -265,9 +263,6 @@ int menu_cbs_init_bind_right(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx,
const char *menu_label);
int menu_cbs_init_bind_refresh(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);
int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx);

View File

@ -112,7 +112,6 @@ typedef struct menu_file_list_cbs
*path, const char *label, unsigned type);
int (*action_left)(unsigned type, const char *label, bool wraparound);
int (*action_right)(unsigned type, const char *label, bool wraparound);
int (*action_refresh)(file_list_t *list, file_list_t *menu_list);
int (*action_up)(unsigned type, const char *label);
int (*action_label)(file_list_t *list,
unsigned type, unsigned i,

View File

@ -1676,10 +1676,6 @@ static void menu_cbs_init(
* menu_cbs_deferred_push.c, then map this callback to the entry. */
menu_cbs_init_bind_deferred_push(cbs, path, label, type, idx);
/* It will try to find a corresponding callback function inside
* menu_cbs_refresh.c, then map this callback to the entry. */
menu_cbs_init_bind_refresh(cbs, path, label, type, idx);
/* It will try to find a corresponding callback function inside
* menu_cbs_get_string_representation.c, then map this callback to the entry. */
menu_cbs_init_bind_get_string_representation(cbs, path, label, type, idx);
@ -2280,20 +2276,20 @@ int generic_menu_entry_action(
cbs = selection_buf ? (menu_file_list_cbs_t*)
selection_buf->list[i].actiondata : NULL;
if (cbs && cbs->action_refresh)
if (MENU_ENTRIES_NEEDS_REFRESH(menu_st))
{
if (MENU_ENTRIES_NEEDS_REFRESH(menu_st))
{
bool refresh = false;
struct menu_state
*menu_st = &p_rarch->menu_driver_state;
menu_list_t *menu_list = menu_st->entries.list;
file_list_t *menu_stack = menu_list ? MENU_LIST_GET(menu_list, (unsigned)0) : NULL;
menu_displaylist_ctx_entry_t entry;
bool refresh = false;
struct menu_state
*menu_st = &p_rarch->menu_driver_state;
menu_list_t *menu_list = menu_st->entries.list;
file_list_t *menu_stack = menu_list ? MENU_LIST_GET(menu_list, (unsigned)0) : NULL;
cbs->action_refresh(selection_buf, menu_stack);
menu_entries_ctl(MENU_ENTRIES_CTL_UNSET_REFRESH, &refresh);
}
entry.list = selection_buf;
entry.stack = menu_stack;
menu_displaylist_push(&entry);
menu_entries_ctl(MENU_ENTRIES_CTL_UNSET_REFRESH, &refresh);
}
#ifdef HAVE_ACCESSIBILITY
@ -3010,7 +3006,6 @@ void menu_entries_append(
cbs->action_content_list_switch = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_refresh = NULL;
cbs->action_up = NULL;
cbs->action_label = NULL;
cbs->action_sublabel = NULL;
@ -3098,7 +3093,6 @@ bool menu_entries_append_enum(
cbs->action_content_list_switch = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_refresh = NULL;
cbs->action_up = NULL;
cbs->action_label = NULL;
cbs->action_sublabel = NULL;
@ -3186,7 +3180,6 @@ void menu_entries_prepend(file_list_t *list,
cbs->action_content_list_switch = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_refresh = NULL;
cbs->action_up = NULL;
cbs->action_label = NULL;
cbs->action_sublabel = NULL;
@ -29665,22 +29658,23 @@ static void video_driver_monitor_compute_fps_statistics(void)
}
static void video_driver_pixel_converter_free(
struct rarch_state *p_rarch)
video_pixel_scaler_t *scalr)
{
if (p_rarch->video_driver_scaler_ptr->scaler)
if (!scalr)
return;
if (scalr->scaler)
{
scaler_ctx_gen_reset(p_rarch->video_driver_scaler_ptr->scaler);
free(p_rarch->video_driver_scaler_ptr->scaler);
scaler_ctx_gen_reset(scalr->scaler);
free(scalr->scaler);
}
if (p_rarch->video_driver_scaler_ptr->scaler_out)
free(p_rarch->video_driver_scaler_ptr->scaler_out);
if (scalr->scaler_out)
free(scalr->scaler_out);
p_rarch->video_driver_scaler_ptr->scaler = NULL;
p_rarch->video_driver_scaler_ptr->scaler_out = NULL;
scalr->scaler = NULL;
scalr->scaler_out = NULL;
free(p_rarch->video_driver_scaler_ptr);
p_rarch->video_driver_scaler_ptr = NULL;
free(scalr);
}
static void video_driver_free_hw_context(struct rarch_state *p_rarch)
@ -29735,8 +29729,9 @@ static void video_driver_free_internal(void)
&& p_rarch->current_video->free)
p_rarch->current_video->free(p_rarch->video_driver_data);
if (p_rarch && p_rarch->video_driver_scaler_ptr)
video_driver_pixel_converter_free(p_rarch);
if (p_rarch->video_driver_scaler_ptr)
video_driver_pixel_converter_free(p_rarch->video_driver_scaler_ptr);
p_rarch->video_driver_scaler_ptr = NULL;
#ifdef HAVE_VIDEO_FILTER
video_driver_filter_free();
#endif
@ -29750,73 +29745,59 @@ static void video_driver_free_internal(void)
video_driver_monitor_compute_fps_statistics();
}
static bool video_driver_pixel_converter_init(
struct rarch_state *p_rarch,
static video_pixel_scaler_t *video_driver_pixel_converter_init(
const enum retro_pixel_format video_driver_pix_fmt,
struct retro_hw_render_callback *hwr,
unsigned size)
{
struct retro_hw_render_callback *hwr =
VIDEO_DRIVER_GET_HW_CONTEXT_INTERNAL(p_rarch);
void *scalr_out = NULL;
video_pixel_scaler_t *scalr = NULL;
struct scaler_ctx *scalr_ctx = NULL;
const enum retro_pixel_format
video_driver_pix_fmt = p_rarch->video_driver_pix_fmt;
/* If pixel format is not 0RGB1555, we don't need to do
* any internal pixel conversion. */
if (video_driver_pix_fmt != RETRO_PIXEL_FORMAT_0RGB1555)
return true;
return NULL;
/* No need to perform pixel conversion for HW rendering contexts. */
if (hwr && hwr->context_type != RETRO_HW_CONTEXT_NONE)
return true;
return NULL;
RARCH_WARN("[Video]: 0RGB1555 pixel format is deprecated,"
" and will be slower. For 15/16-bit, RGB565"
" format is preferred.\n");
scalr = (video_pixel_scaler_t*)malloc(sizeof(*scalr));
if (!scalr)
if (!(scalr = (video_pixel_scaler_t*)malloc(sizeof(*scalr))))
goto error;
scalr->scaler = NULL;
scalr->scaler_out = NULL;
p_rarch->video_driver_scaler_ptr = scalr;
scalr_ctx = (struct scaler_ctx*)calloc(1, sizeof(*scalr_ctx));
if (!scalr_ctx)
if (!(scalr_ctx = (struct scaler_ctx*)calloc(1, sizeof(*scalr_ctx))))
goto error;
p_rarch->video_driver_scaler_ptr->scaler = scalr_ctx;
p_rarch->video_driver_scaler_ptr->scaler->scaler_type = SCALER_TYPE_POINT;
p_rarch->video_driver_scaler_ptr->scaler->in_fmt = SCALER_FMT_0RGB1555;
/* TODO: Pick either ARGB8888 or RGB565 depending on driver. */
p_rarch->video_driver_scaler_ptr->scaler->out_fmt = SCALER_FMT_RGB565;
scalr->scaler = scalr_ctx;
scalr->scaler->scaler_type = SCALER_TYPE_POINT;
scalr->scaler->in_fmt = SCALER_FMT_0RGB1555;
/* TODO/FIXME: Pick either ARGB8888 or RGB565 depending on driver. */
scalr->scaler->out_fmt = SCALER_FMT_RGB565;
if (!scaler_ctx_gen_filter(scalr_ctx))
goto error;
scalr_out = calloc(sizeof(uint16_t), size * size);
if (!scalr_out)
if (!(scalr_out = calloc(sizeof(uint16_t), size * size)))
goto error;
p_rarch->video_driver_scaler_ptr->scaler_out = scalr_out;
scalr->scaler_out = scalr_out;
return true;
return scalr;
error:
if (p_rarch && p_rarch->video_driver_scaler_ptr)
video_driver_pixel_converter_free(p_rarch);
video_driver_pixel_converter_free(scalr);
#ifdef HAVE_VIDEO_FILTER
video_driver_filter_free();
#endif
return false;
return NULL;
}
static void video_driver_set_viewport_config(struct retro_game_geometry *geom,
@ -29913,9 +29894,9 @@ static bool video_driver_init_internal(bool *video_is_threaded)
#endif
/* Update core-dependent aspect ratio values. */
video_driver_set_viewport_square_pixel(&p_rarch->video_driver_av_info.geometry);
video_driver_set_viewport_square_pixel(geom);
video_driver_set_viewport_core();
video_driver_set_viewport_config(&p_rarch->video_driver_av_info.geometry, p_rarch->configuration_settings);
video_driver_set_viewport_config(geom, settings);
/* Update CUSTOM viewport. */
custom_vp = video_viewport_get_custom();
@ -29979,12 +29960,10 @@ static bool video_driver_init_internal(bool *video_is_threaded)
video_driver_display_userdata_set(0);
video_driver_window_set(0);
if (!video_driver_pixel_converter_init(p_rarch,
RARCH_SCALE_BASE * scale))
{
RARCH_ERR("[Video]: Failed to initialize pixel converter.\n");
goto error;
}
p_rarch->video_driver_scaler_ptr = video_driver_pixel_converter_init(
p_rarch->video_driver_pix_fmt,
VIDEO_DRIVER_GET_HW_CONTEXT_INTERNAL(p_rarch),
RARCH_SCALE_BASE * scale);
video.width = width;
video.height = height;
@ -31120,17 +31099,6 @@ struct video_viewport *video_viewport_get_custom(void)
return &settings->video_viewport_custom;
}
unsigned video_pixel_get_alignment(unsigned pitch)
{
if (pitch & 1)
return 1;
if (pitch & 2)
return 2;
if (pitch & 4)
return 4;
return 8;
}
/**
* video_driver_frame:
* @data : pointer to data of the video frame.

View File

@ -1676,8 +1676,6 @@ void video_monitor_set_refresh_rate(float hz);
bool video_monitor_fps_statistics(double *refresh_rate,
double *deviation, unsigned *sample_points);
unsigned video_pixel_get_alignment(unsigned pitch);
void crt_switch_driver_reinit(void);
#define video_driver_translate_coord_viewport_wrap(vp, mouse_x, mouse_y, res_x, res_y, res_screen_x, res_screen_y) \