emulator: Add TREZOR_OLED_SCALE variable

This commit is contained in:
Saleem Rashid 2018-02-18 19:34:56 +00:00 committed by Pavol Rusnak
parent b4e3cd3e0c
commit 7376b97ee6
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
1 changed files with 26 additions and 1 deletions

View File

@ -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();