From 5a164fe2ab0aff6ce7064f8888f7b8030501038f Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 17 Jan 2024 01:24:37 +0100 Subject: [PATCH] Removed framebuffer from SDL display driver --- platform/drivers/display/display_libSDL.c | 64 +++++------------------ 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/platform/drivers/display/display_libSDL.c b/platform/drivers/display/display_libSDL.c index b660969b..bbd6797f 100644 --- a/platform/drivers/display/display_libSDL.c +++ b/platform/drivers/display/display_libSDL.c @@ -32,7 +32,6 @@ #include #include -static void *frameBuffer = NULL; /* Pointer to framebuffer */ static bool inProgress; /* Flag to signal when rendering is in progress */ /* @@ -49,7 +48,7 @@ extern Uint32 SDL_Backlight_Event; * Internal helper function which fetches pixel at position (x, y) from framebuffer * and returns it in SDL-compatible format, which is ARGB8888. */ -static uint32_t fetchPixelFromFb(unsigned int x, unsigned int y) +static uint32_t fetchPixelFromFb(unsigned int x, unsigned int y, void *fb) { (void) x; (void) y; @@ -60,10 +59,10 @@ static uint32_t fetchPixelFromFb(unsigned int x, unsigned int y) * Black and white 1bpp format: framebuffer is an array of uint8_t, where * each cell contains the values of eight pixels, one per bit. */ - uint8_t *fb = (uint8_t *)(frameBuffer); + uint8_t *buf = (uint8_t *)(fb); unsigned int cell = (x + y*CONFIG_SCREEN_WIDTH) / 8; unsigned int elem = (x + y*CONFIG_SCREEN_WIDTH) % 8; - if(fb[cell] & (1 << elem)) pixel = 0xFFFFFFFF; + if(buf[cell] & (1 << elem)) pixel = 0xFFFFFFFF; #endif #ifdef PIX_FMT_GRAYSC @@ -71,8 +70,8 @@ static uint32_t fetchPixelFromFb(unsigned int x, unsigned int y) * Convert from 8bpp grayscale to ARGB8888, we have to do nothing more that * replicating the pixel value for the three components */ - uint8_t *fb = (uint8_t *)(frameBuffer); - uint8_t px = fb[x + y*CONFIG_SCREEN_WIDTH]; + uint8_t *buf = (uint8_t *)(fb); + uint8_t px = buf[x + y*CONFIG_SCREEN_WIDTH]; pixel = 0xFF000000 | (px << 16) | (px << 8) | px; #endif @@ -83,36 +82,6 @@ static uint32_t fetchPixelFromFb(unsigned int x, unsigned int y) void display_init() { - /* - * Black and white pixel format: framebuffer type is uint8_t where each - * bit represents a pixel. We have to allocate - * (CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH)/8 elements - */ - #ifdef CONFIG_PIX_FMT_BW - unsigned int fbSize = (CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH)/8; - /* Compensate for eventual truncation error in division */ - if((fbSize * 8) < (CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH)) fbSize += 1; - fbSize *= sizeof(uint8_t); - #endif - - /* - * Grayscale pixel format: framebuffer type is uint8_t where each element - * controls one pixel - */ - #ifdef PIX_FMT_GRAYSC - unsigned int fbSize = CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH * sizeof(uint8_t); - #endif - - /* - * RGB565 pixel format: framebuffer type is uint16_t where each element - * controls one pixel - */ - #ifdef CONFIG_PIX_FMT_RGB565 - unsigned int fbSize = CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH * sizeof(uint16_t); - #endif - - frameBuffer = malloc(fbSize); - memset(frameBuffer, 0xFFFF, fbSize); inProgress = false; } @@ -121,11 +90,9 @@ void display_terminate() while (inProgress){ } /* Wait until current render finishes */ chan_close(&fb_sync); chan_terminate(&fb_sync); - if(frameBuffer != NULL) free(frameBuffer); - frameBuffer = NULL; } -void display_renderRows(uint8_t startRow, uint8_t endRow) +void display_renderRows(uint8_t startRow, uint8_t endRow, void *fb) { (void) startRow; (void) endRow; @@ -138,17 +105,17 @@ void display_renderRows(uint8_t startRow, uint8_t endRow) if(sdl_ready) { // receive a texture pixel map - void *fb; - chan_recv(&fb_sync, &fb); + void *pixelMap; + chan_recv(&fb_sync, &pixelMap); #ifdef CONFIG_PIX_FMT_RGB565 - memcpy(fb, frameBuffer, sizeof(PIXEL_SIZE) * CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH); + memcpy(pixelMap, fb, sizeof(PIXEL_SIZE) * CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH); #else - uint32_t *pixels = (uint32_t *) fb; + uint32_t *pixels = (uint32_t *) pixelMap; for (unsigned int x = 0; x < CONFIG_SCREEN_WIDTH; x++) { for (unsigned int y = startRow; y < endRow; y++) { - pixels[x + y * CONFIG_SCREEN_WIDTH] = fetchPixelFromFb(x, y); + pixels[x + y * CONFIG_SCREEN_WIDTH] = fetchPixelFromFb(x, y, fb); } } #endif @@ -160,14 +127,9 @@ void display_renderRows(uint8_t startRow, uint8_t endRow) inProgress = false; } -void display_render() +void display_render(void *fb) { - display_renderRows(0, CONFIG_SCREEN_HEIGHT); -} - -void *display_getFrameBuffer() -{ - return (void *) (frameBuffer); + display_renderRows(0, CONFIG_SCREEN_HEIGHT, fb); } void display_setContrast(uint8_t contrast)