From 23a8889f9b5e00879bdbe2b3d49571c7714db5ba Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 19 Mar 2014 10:12:16 +0000 Subject: [PATCH] improve SDL performance by only flipping when idle --- libs/graphics/lcd_sdl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/graphics/lcd_sdl.c b/libs/graphics/lcd_sdl.c index a746c16f3..b3c0764ab 100644 --- a/libs/graphics/lcd_sdl.c +++ b/libs/graphics/lcd_sdl.c @@ -21,6 +21,7 @@ #define DEPTH 32 SDL_Surface *screen = 0; +bool needsFlip = false; unsigned int lcdGetPixel_SDL(JsGraphics *gfx, short x, short y) { if (!screen) return 0; @@ -43,7 +44,7 @@ void lcdSetPixel_SDL(JsGraphics *gfx, short x, short y, unsigned int col) { unsigned int *pixmem32 = ((unsigned int*)screen->pixels) + y*gfx->data.width + x; *pixmem32 = col; if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); - SDL_Flip(screen); + needsFlip = true; } void lcdInit_SDL(JsGraphics *gfx) { @@ -60,6 +61,10 @@ void lcdInit_SDL(JsGraphics *gfx) { } void lcdIdle_SDL() { + if (needsFlip) { + needsFlip = false; + SDL_Flip(screen); + } } void lcdSetCallbacks_SDL(JsGraphics *gfx) {