Move rendering from sc_display to sc_screen

Three components are involved in displaying device content on screen:
 - a window
 - a renderer
 - a texture

Originally, all three were handled by sc_screen.

Commit 051b74c883 later extracted the
renderer and texture into a separate component, sc_display.

However, the split was a bit awkward because the window size and
rendering location were managed by separate components.

Move rendering back to sc_screen, keeping only texture management
separated.
This commit is contained in:
Romain Vimont
2026-01-25 11:57:31 +01:00
parent 7720d32357
commit 342d8c31f0
3 changed files with 61 additions and 63 deletions

View File

@@ -6,7 +6,6 @@
#include <libavutil/pixfmt.h>
#include "util/log.h"
#include "util/sdl.h"
static bool
sc_display_init_novideo_icon(struct sc_display *display,
@@ -233,54 +232,3 @@ sc_display_update_texture(struct sc_display *display, const AVFrame *frame) {
return true;
}
bool
sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
enum sc_orientation orientation) {
sc_sdl_render_clear(display->renderer);
bool ok = false;
SDL_Renderer *renderer = display->renderer;
SDL_Texture *texture = display->texture;
if (!texture) {
LOGW("No texture to render");
goto end;
}
if (orientation == SC_ORIENTATION_0) {
SDL_FRect frect;
SDL_FRect *fgeometry = NULL;
if (geometry) {
SDL_RectToFRect(geometry, &frect);
fgeometry = &frect;
}
ok = SDL_RenderTexture(renderer, texture, NULL, fgeometry);
} else {
unsigned cw_rotation = sc_orientation_get_rotation(orientation);
double angle = 90 * cw_rotation;
SDL_FRect frect;
if (sc_orientation_is_swap(orientation)) {
frect.x = geometry->x + (geometry->w - geometry->h) / 2.f;
frect.y = geometry->y + (geometry->h - geometry->w) / 2.f;
frect.w = geometry->h;
frect.h = geometry->w;
} else {
SDL_RectToFRect(geometry, &frect);
}
SDL_FlipMode flip = sc_orientation_is_mirror(orientation)
? SDL_FLIP_HORIZONTAL : 0;
ok = SDL_RenderTextureRotated(renderer, texture, NULL, &frect, angle,
NULL, flip);
}
if (!ok) {
LOGE("Could not render texture: %s", SDL_GetError());
}
end:
sc_sdl_render_present(display->renderer);
return ok;
}

View File

@@ -10,7 +10,6 @@
#include "coords.h"
#include "opengl.h"
#include "options.h"
struct sc_display {
SDL_Renderer *renderer; // owned by the caller
@@ -37,8 +36,4 @@ sc_display_prepare_texture(struct sc_display *display, struct sc_size size,
bool
sc_display_update_texture(struct sc_display *display, const AVFrame *frame);
bool
sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
enum sc_orientation orientation);
#endif

View File

@@ -192,16 +192,71 @@ sc_screen_render(struct sc_screen *screen, bool update_content_rect) {
sc_screen_update_content_rect(screen);
}
bool ok =
sc_display_render(&screen->display, &screen->rect, screen->orientation);
(void) ok; // any error already logged
SDL_Renderer *renderer = screen->renderer;
sc_sdl_render_clear(renderer);
bool ok = false;
SDL_Texture *texture = screen->display.texture;
if (!texture) {
LOGW("No texture to render");
goto end;
}
SDL_Rect *geometry = &screen->rect;
enum sc_orientation orientation = screen->orientation;
if (orientation == SC_ORIENTATION_0) {
SDL_FRect frect;
SDL_FRect *fgeometry = NULL;
if (geometry) {
SDL_RectToFRect(geometry, &frect);
fgeometry = &frect;
}
ok = SDL_RenderTexture(renderer, texture, NULL, fgeometry);
} else {
unsigned cw_rotation = sc_orientation_get_rotation(orientation);
double angle = 90 * cw_rotation;
SDL_FRect frect;
if (sc_orientation_is_swap(orientation)) {
frect.x = geometry->x + (geometry->w - geometry->h) / 2.f;
frect.y = geometry->y + (geometry->h - geometry->w) / 2.f;
frect.w = geometry->h;
frect.h = geometry->w;
} else {
SDL_RectToFRect(geometry, &frect);
}
SDL_FlipMode flip = sc_orientation_is_mirror(orientation)
? SDL_FLIP_HORIZONTAL : 0;
ok = SDL_RenderTextureRotated(renderer, texture, NULL, &frect, angle,
NULL, flip);
}
if (!ok) {
LOGE("Could not render texture: %s", SDL_GetError());
}
end:
sc_sdl_render_present(renderer);
}
static void
sc_screen_render_novideo(struct sc_screen *screen) {
bool ok =
sc_display_render(&screen->display, NULL, SC_ORIENTATION_0);
(void) ok; // any error already logged
SDL_Renderer *renderer = screen->renderer;
sc_sdl_render_clear(renderer);
SDL_Texture *texture = screen->display.texture;
assert(texture);
bool ok = SDL_RenderTexture(renderer, texture, NULL, NULL);
if (!ok) {
LOGE("Could not render texture: %s", SDL_GetError());
}
sc_sdl_render_present(renderer);
}
#if defined(__APPLE__) || defined(_WIN32)