(FPGA) Put static global variables into struct

This commit is contained in:
twinaphex 2020-03-07 17:28:42 +01:00
parent 3e35fb8672
commit 788ae60d12
1 changed files with 45 additions and 60 deletions

View File

@ -44,28 +44,16 @@ typedef struct RegOp
int only_munmap; int only_munmap;
} RegOp; } RegOp;
static unsigned char *fpga_menu_frame = NULL;
static unsigned fpga_menu_width = 0;
static unsigned fpga_menu_height = 0;
static unsigned fpga_menu_pitch = 0;
static unsigned fpga_video_width = 0;
static unsigned fpga_video_height = 0;
static unsigned fpga_video_pitch = 0;
static unsigned fpga_video_bits = 0;
static unsigned fpga_menu_bits = 0;
static bool fpga_rgb32 = false;
static bool fpga_menu_rgb32 = false;
static RegOp regOp; static RegOp regOp;
static unsigned int get_memory_size(void) static unsigned int get_memory_size(void)
{ {
FILE *size_fp;
unsigned int size; unsigned int size;
/* this file holds the memory range needed to map the framebuffer into /* this file holds the memory range needed to map the framebuffer into
* kernel address space, it is specified in the device tree * kernel address space, it is specified in the device tree
*/ */
size_fp = fopen("/sys/class/uio/uio0/maps/map0/size", "r"); FILE *size_fp = fopen("/sys/class/uio/uio0/maps/map0/size", "r");
if (!size_fp) if (!size_fp)
{ {
@ -138,16 +126,16 @@ static void *fpga_gfx_init(const video_info_t *video,
*input = NULL; *input = NULL;
*input_data = NULL; *input_data = NULL;
fpga_video_width = video->width; fpga->video_width = video->width;
fpga_video_height = video->height; fpga->video_height = video->height;
fpga_rgb32 = video->rgb32; fpga->rgb32 = video->rgb32;
fpga_video_bits = video->rgb32 ? 32 : 16; fpga->video_bits = video->rgb32 ? 32 : 16;
if (video->rgb32) if (video->rgb32)
fpga_video_pitch = video->width * 4; fpga->video_pitch = video->width * 4;
else else
fpga_video_pitch = video->width * 2; fpga->video_pitch = video->width * 2;
fpga_gfx_create(fpga); fpga_gfx_create(fpga);
@ -236,9 +224,9 @@ static bool fpga_gfx_frame(void *data, const void *frame,
const void *frame_to_copy = frame; const void *frame_to_copy = frame;
unsigned width = 0; unsigned width = 0;
unsigned height = 0; unsigned height = 0;
unsigned bits = fpga_video_bits;
bool draw = true; bool draw = true;
fpga_t *fpga = (fpga_t*)data; fpga_t *fpga = (fpga_t*)data;
unsigned bits = fpga->video_bits;
if (!frame || !frame_width || !frame_height) if (!frame || !frame_width || !frame_height)
return true; return true;
@ -247,29 +235,31 @@ static bool fpga_gfx_frame(void *data, const void *frame,
menu_driver_frame(video_info); menu_driver_frame(video_info);
#endif #endif
if (fpga_video_width != frame_width || fpga_video_height != frame_height || fpga_video_pitch != pitch) if ( fpga->video_width != frame_width ||
fpga->video_height != frame_height ||
fpga->video_pitch != pitch)
{ {
if (frame_width > 4 && frame_height > 4) if (frame_width > 4 && frame_height > 4)
{ {
fpga_video_width = frame_width; fpga->video_width = frame_width;
fpga_video_height = frame_height; fpga->video_height = frame_height;
fpga_video_pitch = pitch; fpga->video_pitch = pitch;
} }
} }
if (fpga_menu_frame && video_info->menu_is_alive) if (fpga->menu_frame && video_info->menu_is_alive)
{ {
frame_to_copy = fpga_menu_frame; frame_to_copy = fpga->menu_frame;
width = fpga_menu_width; width = fpga->menu_width;
height = fpga_menu_height; height = fpga->menu_height;
pitch = fpga_menu_pitch; pitch = fpga->menu_pitch;
bits = fpga_menu_bits; bits = fpga->menu_bits;
} }
else else
{ {
width = fpga_video_width; width = fpga->video_width;
height = fpga_video_height; height = fpga->video_height;
pitch = fpga_video_pitch; pitch = fpga->video_pitch;
if (frame_width == 4 && frame_height == 4 && (frame_width < width && frame_height < height)) if (frame_width == 4 && frame_height == 4 && (frame_width < width && frame_height < height))
draw = false; draw = false;
@ -284,7 +274,7 @@ static bool fpga_gfx_frame(void *data, const void *frame,
{ {
if (bits == 16) if (bits == 16)
{ {
if (frame_to_copy == fpga_menu_frame) if (frame_to_copy == fpga->menu_frame)
{ {
/* RGBX4444 color bits for RGUI */ /* RGBX4444 color bits for RGUI */
unsigned x, y; unsigned x, y;
@ -392,15 +382,13 @@ static void fpga_gfx_free(void *data)
{ {
fpga_t *fpga = (fpga_t*)data; fpga_t *fpga = (fpga_t*)data;
if (fpga_menu_frame)
{
free(fpga_menu_frame);
fpga_menu_frame = NULL;
}
if (!fpga) if (!fpga)
return; return;
if (fpga->menu_frame)
free(fpga->menu_frame);
fpga->menu_frame = NULL;
font_driver_free_osd(); font_driver_free_osd();
video_context_driver_free(); video_context_driver_free();
@ -448,28 +436,30 @@ static void fpga_set_texture_frame(void *data,
const void *frame, bool rgb32, unsigned width, unsigned height, const void *frame, bool rgb32, unsigned width, unsigned height,
float alpha) float alpha)
{ {
fpga_t *fpga = (fpga_t*)data;
unsigned pitch = width * 2; unsigned pitch = width * 2;
if (rgb32) if (fpga->rgb32)
pitch = width * 4; pitch = width * 4;
if (fpga_menu_frame) if (fpga->menu_frame)
{ free(fpga->menu_frame);
free(fpga_menu_frame); fpga->menu_frame = NULL;
fpga_menu_frame = NULL;
}
if (!fpga_menu_frame || fpga_menu_width != width || fpga_menu_height != height || fpga_menu_pitch != pitch) if ( !fpga->menu_frame ||
fpga->menu_width != width ||
fpga->menu_height != height ||
fpga->menu_pitch != pitch)
if (pitch && height) if (pitch && height)
fpga_menu_frame = (unsigned char*)malloc(pitch * height); fpga->menu_frame = (unsigned char*)malloc(pitch * height);
if (fpga_menu_frame && frame && pitch && height) if (fpga->menu_frame && frame && pitch && height)
{ {
memcpy(fpga_menu_frame, frame, pitch * height); memcpy(fpga->menu_frame, frame, pitch * height);
fpga_menu_width = width; fpga->menu_width = width;
fpga_menu_height = height; fpga->menu_height = height;
fpga_menu_pitch = pitch; fpga->menu_pitch = pitch;
fpga_menu_bits = rgb32 ? 32 : 16; fpga->menu_bits = fpga->rgb32 ? 32 : 16;
} }
} }
@ -554,11 +544,6 @@ static void fpga_gfx_set_viewport(void *data, unsigned viewport_width,
{ {
} }
bool fpga_has_menu_frame(void)
{
return (fpga_menu_frame != NULL);
}
video_driver_t video_fpga = { video_driver_t video_fpga = {
fpga_gfx_init, fpga_gfx_init,
fpga_gfx_frame, fpga_gfx_frame,