1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

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

View File

@ -32,6 +32,20 @@ void emulatorPoll(void) {}
static SDL_Renderer *renderer = NULL; static SDL_Renderer *renderer = NULL;
static SDL_Texture *texture = 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) { void oledInit(void) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError()); fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
@ -39,7 +53,15 @@ void oledInit(void) {
} }
atexit(SDL_Quit); 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) { if (window == NULL) {
fprintf(stderr, "Failed to create window: %s\n", SDL_GetError()); fprintf(stderr, "Failed to create window: %s\n", SDL_GetError());
exit(1); exit(1);
@ -51,6 +73,9 @@ void oledInit(void) {
exit(1); 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); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, OLED_WIDTH, OLED_HEIGHT);
oledClear(); oledClear();