Skip to content

Commit

Permalink
Clean up SDL backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jserv committed Jul 21, 2024
1 parent 139038d commit 3d80857
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
13 changes: 5 additions & 8 deletions apps/twin-sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,27 @@
* Load the background pixmap from storage.
* @filename: File name of a PNG background.
*
* Returns the default background if @filename is NULL. Returns a default
* pattern if the load of @filename fails.
* Return a default pattern if the load of @filename fails.
*/
twin_pixmap_t *load_background(twin_screen_t *screen, const char *filename)
static twin_pixmap_t *load_background(twin_screen_t *screen,
const char *filename)
{
twin_pixmap_t *raw_background = twin_png_to_pixmap(filename, TWIN_ARGB32);
if (!raw_background) {
/* Fallback to a default pattern */
if (!raw_background) /* Fallback to a default pattern */
return twin_make_pattern();
}

if (screen->height == raw_background->height &&
screen->width == raw_background->width)
return raw_background;

/* Scale as needed. */
twin_fixed_t sx, sy;

twin_pixmap_t *scaled_background =
twin_pixmap_create(TWIN_ARGB32, screen->width, screen->height);
if (!scaled_background) {
twin_pixmap_destroy(raw_background);
return twin_make_pattern();
}
twin_fixed_t sx, sy;
sx = twin_fixed_div(twin_int_to_fixed(raw_background->width),
twin_int_to_fixed(screen->width));
sy = twin_fixed_div(twin_int_to_fixed(raw_background->height),
Expand Down
8 changes: 3 additions & 5 deletions backend/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ static void _twin_sdl_put_span(twin_coord_t left,
void *closure)
{
twin_sdl_t *tx = closure;
twin_coord_t ix;
twin_coord_t iy = top;

for (ix = left; ix < right; ix++) {
for (twin_coord_t ix = left, iy = top; ix < right; ix++) {
twin_argb32_t pixel = *pixels++;

if (tx->depth == 16)
Expand Down Expand Up @@ -105,15 +103,15 @@ static bool twin_sdl_work(void *closure)

twin_sdl_t *twin_sdl_create(int width, int height)
{
static char *argv[] = {"twin-sdl", 0};
static char *title = "twin-sdl";

twin_sdl_t *tx = malloc(sizeof(twin_sdl_t));
if (!tx)
return NULL;

if (SDL_Init(SDL_INIT_VIDEO) < 0)
printf("error : %s\n", SDL_GetError());
tx->win = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED,
tx->win = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height,
SDL_WINDOW_SHOWN);
if (!tx->win)
Expand Down

0 comments on commit 3d80857

Please sign in to comment.