From 7376b97ee69394fece22b52c598baf020669908c Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Sun, 18 Feb 2018 19:34:56 +0000 Subject: [PATCH] emulator: Add TREZOR_OLED_SCALE variable --- emulator/oled.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/emulator/oled.c b/emulator/oled.c index 8f58759..26babdb 100644 --- a/emulator/oled.c +++ b/emulator/oled.c @@ -32,6 +32,20 @@ void emulatorPoll(void) {} static SDL_Renderer *renderer = NULL; static SDL_Texture *texture = NULL; +#define ENV_OLED_SCALE "TREZOR_OLED_SCALE" + +static int emulatorScale(void) { + const char *variable = getenv(ENV_OLED_SCALE); + if (!variable) { + return 1; + } + int scale = atoi(variable); + if (scale >= 1 && scale <= 16) { + return scale; + } + return 1; +} + void oledInit(void) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError()); @@ -39,7 +53,15 @@ void oledInit(void) { } atexit(SDL_Quit); - SDL_Window *window = SDL_CreateWindow("TREZOR", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, OLED_WIDTH, OLED_HEIGHT, 0); + int scale = emulatorScale(); + + SDL_Window *window = SDL_CreateWindow("TREZOR", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + OLED_WIDTH * scale, + OLED_HEIGHT * scale, + 0); + if (window == NULL) { fprintf(stderr, "Failed to create window: %s\n", SDL_GetError()); exit(1); @@ -51,6 +73,9 @@ void oledInit(void) { exit(1); } + /* Use unscaled coordinate system */ + SDL_RenderSetLogicalSize(renderer, OLED_WIDTH, OLED_HEIGHT); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, OLED_WIDTH, OLED_HEIGHT); oledClear();