From 7c978470c2f160372736d61e6ccbb93ba351ab39 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Mon, 6 Dec 2021 22:48:50 +0100 Subject: [PATCH] Add brightness support for the emulator --- platform/targets/linux/emulator/sdl_engine.c | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/platform/targets/linux/emulator/sdl_engine.c b/platform/targets/linux/emulator/sdl_engine.c index 69847d1a..bee5cf4d 100644 --- a/platform/targets/linux/emulator/sdl_engine.c +++ b/platform/targets/linux/emulator/sdl_engine.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -39,6 +40,8 @@ pthread_mutex_t mu; bool ready = false; /* Signal if the main loop is ready */ keyboard_t sdl_keys; /* Store the keyboard status */ +extern state_t state; + bool sdk_key_code_to_key(SDL_Keycode sym, keyboard_t *key) { switch (sym) @@ -272,6 +275,23 @@ keyboard_t sdl_getKeys() return keys; } +bool set_brightness(uint8_t brightness) +{ + /* + * When this texture is rendered, during the copy operation each source + * color channel is modulated by the appropriate color value according to + * the following formula: + * srcC = srcC * (color / 255) + * + * Color modulation is not always supported by the renderer; + * it will return -1 if color modulation is not supported. + */ + return SDL_SetTextureColorMod(displayTexture, + brightness, + brightness, + brightness) == 0; +} + /* * SDL main loop. Due to macOS restrictions, this must run on the Main Thread. */ @@ -333,6 +353,7 @@ void sdl_task() } chan_send(&fb_sync, pixels); + set_brightness(state.settings.brightness); chan_recv(&fb_sync, NULL); SDL_UnlockTexture(displayTexture); @@ -374,6 +395,12 @@ void init_sdl() SCREEN_WIDTH, SCREEN_HEIGHT); SDL_RenderClear(renderer); + + if(!set_brightness(state.settings.brightness)) + { + SDL_Log("Cannot apply brightness: %s", SDL_GetError()); + } + SDL_RenderCopy(renderer, displayTexture, NULL, NULL); SDL_RenderPresent(renderer); }