Merge video_coord_array.c into video_driver.c

This commit is contained in:
libretroadmin 2023-08-15 16:02:12 +02:00
parent 40a0ced947
commit 2d2cb04589
19 changed files with 1590 additions and 1652 deletions

View File

@ -321,7 +321,6 @@ OBJ += \
gfx/gfx_animation.o \
gfx/gfx_thumbnail_path.o \
gfx/gfx_thumbnail.o \
gfx/video_coord_array.o \
configuration.o \
$(LIBRETRO_COMM_DIR)/dynamic/dylib.o \
cores/dynamic_dummy.o \

View File

@ -32,7 +32,6 @@
#include <formats/image.h>
#include "../video_driver.h"
#include "../video_coord_array.h"
RETRO_BEGIN_DECLS

View File

@ -33,7 +33,6 @@
#include <formats/image.h>
#include "../video_driver.h"
#include "../video_coord_array.h"
#include "../drivers_shader/shader_gl3.h"
RETRO_BEGIN_DECLS

View File

@ -31,7 +31,6 @@
#include "../../driver.h"
#include "../../retroarch.h"
#include "../video_coord_array.h"
#define RSX_MAX_BUFFERS 2
#define RSX_MAX_MENU_BUFFERS 2

View File

@ -24,9 +24,9 @@
#include <gfx/math/matrix_4x4.h>
#include <defines/psp_defines.h>
#include "../../driver.h"
#include "../../retroarch.h"
#include "../video_coord_array.h"
typedef struct vita_menu_frame
{

View File

@ -41,7 +41,6 @@
#include <defines/d3d_defines.h>
#include "../common/d3d8_defines.h"
#include "../common/d3d_common.h"
#include "../video_coord_array.h"
#include "../../configuration.h"
#include "../../retroarch.h"
#include "../../dynamic.h"

View File

@ -48,7 +48,7 @@
#include "../common/d3d9_common.h"
#include "../include/Cg/cg.h"
#include "../include/Cg/cgD3D9.h"
#include "../video_coord_array.h"
#include "../video_driver.h"
#include "../../configuration.h"
#include "../../dynamic.h"
#include "../../frontend/frontend_driver.h"

View File

@ -54,7 +54,7 @@
#include <defines/d3d_defines.h>
#include "../common/d3d_common.h"
#include "../common/d3d9_common.h"
#include "../video_coord_array.h"
#include "../video_driver.h"
#include "../../configuration.h"
#include "../../dynamic.h"
#include "../../frontend/frontend_driver.h"

View File

@ -48,6 +48,7 @@
#endif
#include "../font_driver.h"
#include "../video_driver.h"
#include "../common/metal_common.h"
@ -60,8 +61,6 @@
#endif
#include "../../verbosity.h"
#include "../video_coord_array.h"
#include "../../ui/drivers/cocoa/apple_platform.h"
#include "../../ui/drivers/cocoa/cocoa_common.h"

View File

@ -33,10 +33,10 @@
#endif
#include "../font_driver.h"
#include "../video_driver.h"
#include "../common/vita2d_defines.h"
#include "../../driver.h"
#include "../video_coord_array.h"
#include "../../verbosity.h"
#include "../../configuration.h"

View File

@ -42,6 +42,7 @@
#endif
#include "../font_driver.h"
#include "../video_driver.h"
#include "../common/vulkan_common.h"
@ -50,11 +51,9 @@
#include "../../state_manager.h"
#endif
#include "../../record/record_driver.h"
#include "../../retroarch.h"
#include "../../verbosity.h"
#include "../../record/record_driver.h"
#include "../video_coord_array.h"
#define VK_REMAP_TO_TEXFMT(fmt) ((fmt == VK_FORMAT_R5G6B5_UNORM_PACK16) ? VK_FORMAT_R8G8B8A8_UNORM : fmt)

View File

@ -16,7 +16,6 @@
*/
#include "gfx_display.h"
#include "video_coord_array.h"
#include "../configuration.h"
#include "../verbosity.h"

View File

@ -1,120 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* 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 <stdlib.h>
#include <retro_inline.h>
#include <retro_math.h>
#include "video_coord_array.h"
static INLINE bool realloc_checked(void **ptr, size_t size)
{
void *nptr = NULL;
if (*ptr)
nptr = realloc(*ptr, size);
else
nptr = malloc(size);
if (nptr)
*ptr = nptr;
return *ptr == nptr;
}
static bool video_coord_array_resize(video_coord_array_t *ca,
unsigned cap)
{
size_t base_size = sizeof(float) * cap;
if (!realloc_checked((void**)&ca->coords.vertex,
2 * base_size))
return false;
if (!realloc_checked((void**)&ca->coords.color,
4 * base_size))
return false;
if (!realloc_checked((void**)&ca->coords.tex_coord,
2 * base_size))
return false;
if (!realloc_checked((void**)&ca->coords.lut_tex_coord,
2 * base_size))
return false;
ca->allocated = cap;
return true;
}
bool video_coord_array_append(video_coord_array_t *ca,
const video_coords_t *coords, unsigned count)
{
size_t base_size, offset;
count = MIN(count, coords->vertices);
if (ca->coords.vertices + count >= ca->allocated)
{
unsigned cap = next_pow2(ca->coords.vertices + count);
if (!video_coord_array_resize(ca, cap))
return false;
}
base_size = count * sizeof(float);
offset = ca->coords.vertices;
/* XXX: I wish we used interlaced arrays so
* we could call memcpy only once. */
memcpy(ca->coords.vertex + offset * 2,
coords->vertex, base_size * 2);
memcpy(ca->coords.color + offset * 4,
coords->color, base_size * 4);
memcpy(ca->coords.tex_coord + offset * 2,
coords->tex_coord, base_size * 2);
memcpy(ca->coords.lut_tex_coord + offset * 2,
coords->lut_tex_coord, base_size * 2);
ca->coords.vertices += count;
return true;
}
void video_coord_array_free(video_coord_array_t *ca)
{
if (!ca->allocated)
return;
if (ca->coords.vertex)
free(ca->coords.vertex);
ca->coords.vertex = NULL;
if (ca->coords.color)
free(ca->coords.color);
ca->coords.color = NULL;
if (ca->coords.tex_coord)
free(ca->coords.tex_coord);
ca->coords.tex_coord = NULL;
if (ca->coords.lut_tex_coord)
free(ca->coords.lut_tex_coord);
ca->coords.lut_tex_coord = NULL;
ca->coords.vertices = 0;
ca->allocated = 0;
}

View File

@ -1,97 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* 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/>.
*/
#ifndef __VIDEO_COORD_ARRAY_H
#define __VIDEO_COORD_ARRAY_H
#include <stdint.h>
#include <string.h>
#include <boolean.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
struct video_fbo_rect
{
unsigned img_width;
unsigned img_height;
unsigned max_img_width;
unsigned max_img_height;
unsigned width;
unsigned height;
};
struct video_ortho
{
float left;
float right;
float bottom;
float top;
float znear;
float zfar;
};
struct video_tex_info
{
unsigned int tex;
float input_size[2];
float tex_size[2];
float coord[8];
};
typedef struct video_coords
{
const float *vertex;
const float *color;
const float *tex_coord;
const float *lut_tex_coord;
const unsigned *index;
unsigned vertices;
unsigned indexes;
} video_coords_t;
typedef struct video_mut_coords
{
float *vertex;
float *color;
float *tex_coord;
float *lut_tex_coord;
unsigned *index;
unsigned vertices;
unsigned indexes;
} video_mut_coords_t;
typedef struct video_coord_array
{
video_mut_coords_t coords; /* ptr alignment */
unsigned allocated;
} video_coord_array_t;
typedef struct video_font_raster_block
{
video_coord_array_t carr; /* ptr alignment */
bool fullscreen;
} video_font_raster_block_t;
bool video_coord_array_append(video_coord_array_t *ca,
const video_coords_t *coords, unsigned count);
void video_coord_array_free(video_coord_array_t *ca);
RETRO_END_DECLS
#endif

View File

@ -315,6 +315,69 @@ struct font_line_metrics
float descender;
};
struct video_fbo_rect
{
unsigned img_width;
unsigned img_height;
unsigned max_img_width;
unsigned max_img_height;
unsigned width;
unsigned height;
};
struct video_ortho
{
float left;
float right;
float bottom;
float top;
float znear;
float zfar;
};
struct video_tex_info
{
unsigned int tex;
float input_size[2];
float tex_size[2];
float coord[8];
};
typedef struct video_coords
{
const float *vertex;
const float *color;
const float *tex_coord;
const float *lut_tex_coord;
const unsigned *index;
unsigned vertices;
unsigned indexes;
} video_coords_t;
typedef struct video_mut_coords
{
float *vertex;
float *color;
float *tex_coord;
float *lut_tex_coord;
unsigned *index;
unsigned vertices;
unsigned indexes;
} video_mut_coords_t;
typedef struct video_coord_array
{
video_mut_coords_t coords; /* ptr alignment */
unsigned allocated;
} video_coord_array_t;
typedef struct video_font_raster_block
{
video_coord_array_t carr; /* ptr alignment */
bool fullscreen;
} video_font_raster_block_t;
RETRO_END_DECLS
#endif

View File

@ -14,7 +14,10 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <math.h>
#include <retro_inline.h>
#include <string/stdstring.h>
#include <retro_math.h>
@ -194,6 +197,104 @@ struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = {
{ 4.0f / 3.0f , "" } /* full - initialized in video_driver_init_internal */
};
static INLINE bool realloc_checked(void **ptr, size_t size)
{
void *nptr = NULL;
if (*ptr)
nptr = realloc(*ptr, size);
else
nptr = malloc(size);
if (nptr)
*ptr = nptr;
return *ptr == nptr;
}
static bool video_coord_array_resize(video_coord_array_t *ca,
unsigned cap)
{
size_t base_size = sizeof(float) * cap;
if (!realloc_checked((void**)&ca->coords.vertex,
2 * base_size))
return false;
if (!realloc_checked((void**)&ca->coords.color,
4 * base_size))
return false;
if (!realloc_checked((void**)&ca->coords.tex_coord,
2 * base_size))
return false;
if (!realloc_checked((void**)&ca->coords.lut_tex_coord,
2 * base_size))
return false;
ca->allocated = cap;
return true;
}
bool video_coord_array_append(video_coord_array_t *ca,
const video_coords_t *coords, unsigned count)
{
size_t base_size, offset;
count = MIN(count, coords->vertices);
if (ca->coords.vertices + count >= ca->allocated)
{
unsigned cap = next_pow2(ca->coords.vertices + count);
if (!video_coord_array_resize(ca, cap))
return false;
}
base_size = count * sizeof(float);
offset = ca->coords.vertices;
/* XXX: I wish we used interlaced arrays so
* we could call memcpy only once. */
memcpy(ca->coords.vertex + offset * 2,
coords->vertex, base_size * 2);
memcpy(ca->coords.color + offset * 4,
coords->color, base_size * 4);
memcpy(ca->coords.tex_coord + offset * 2,
coords->tex_coord, base_size * 2);
memcpy(ca->coords.lut_tex_coord + offset * 2,
coords->lut_tex_coord, base_size * 2);
ca->coords.vertices += count;
return true;
}
void video_coord_array_free(video_coord_array_t *ca)
{
if (!ca->allocated)
return;
if (ca->coords.vertex)
free(ca->coords.vertex);
ca->coords.vertex = NULL;
if (ca->coords.color)
free(ca->coords.color);
ca->coords.color = NULL;
if (ca->coords.tex_coord)
free(ca->coords.tex_coord);
ca->coords.tex_coord = NULL;
if (ca->coords.lut_tex_coord)
free(ca->coords.lut_tex_coord);
ca->coords.lut_tex_coord = NULL;
ca->coords.vertices = 0;
ca->allocated = 0;
}
static void *video_null_init(const video_info_t *video,
input_driver_t **input, void **input_data)
{

View File

@ -44,7 +44,6 @@
#include "video_crt_switch.h"
#endif
#include "video_coord_array.h"
#include "video_shader_parse.h"
#include "video_filter.h"
@ -1274,6 +1273,11 @@ void video_driver_frame(const void *data, unsigned width,
void video_driver_update_title(void *data);
bool video_coord_array_append(video_coord_array_t *ca,
const video_coords_t *coords, unsigned count);
void video_coord_array_free(video_coord_array_t *ca);
extern const video_driver_t *video_drivers[];
extern video_driver_t video_gl3;

View File

@ -938,7 +938,6 @@ DRIVERS
#include "../gfx/gfx_display.c"
#include "../gfx/gfx_thumbnail_path.c"
#include "../gfx/gfx_thumbnail.c"
#include "../gfx/video_coord_array.c"
#ifdef HAVE_AUDIOMIXER
#include "../libretro-common/audio/audio_mixer.c"
#endif

View File

@ -388,7 +388,6 @@
05A8C67720DB72F000FF7857 /* video_crt_switch.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_crt_switch.c; sourceTree = "<group>"; };
05A8C70E20DB72F000FF7857 /* video_shader_parse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_shader_parse.h; sourceTree = "<group>"; };
05A8C71320DB72F000FF7857 /* video_filter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_filter.h; sourceTree = "<group>"; };
05A8C73820DB72F100FF7857 /* video_coord_array.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_coord_array.h; sourceTree = "<group>"; };
05A8C73920DB72F100FF7857 /* font_driver.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = font_driver.c; sourceTree = "<group>"; };
05A8C73C20DB72F100FF7857 /* vulkan_common.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = vulkan_common.c; sourceTree = "<group>"; };
05A8C74420DB72F100FF7857 /* metal_common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = metal_common.h; sourceTree = "<group>"; };
@ -427,7 +426,6 @@
05A8C7A020DB72F100FF7857 /* video_thread_wrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_thread_wrapper.h; sourceTree = "<group>"; };
05A8C7A720DB72F100FF7857 /* font_driver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = font_driver.h; sourceTree = "<group>"; };
05A8C7A820DB72F100FF7857 /* video_defines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_defines.h; sourceTree = "<group>"; };
05A8C7A920DB72F100FF7857 /* video_coord_array.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_coord_array.c; sourceTree = "<group>"; };
05A8C7AB20DB72F100FF7857 /* freetype.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = freetype.c; sourceTree = "<group>"; };
05A8C7AC20DB72F100FF7857 /* bitmap.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = bitmap.bmp; sourceTree = "<group>"; };
05A8C7AD20DB72F100FF7857 /* coretext.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = coretext.c; sourceTree = "<group>"; };
@ -982,8 +980,6 @@
05A8C78E20DB72F100FF7857 /* drivers_shader */,
05A8C73920DB72F100FF7857 /* font_driver.c */,
05A8C7A720DB72F100FF7857 /* font_driver.h */,
05A8C7A920DB72F100FF7857 /* video_coord_array.c */,
05A8C73820DB72F100FF7857 /* video_coord_array.h */,
05A8C67720DB72F000FF7857 /* video_crt_switch.c */,
05A8C79D20DB72F100FF7857 /* video_crt_switch.h */,
05A8C7A820DB72F100FF7857 /* video_defines.h */,