diff --git a/app/src/display.c b/app/src/display.c index 7f16ad1f..a1f57ffe 100644 --- a/app/src/display.c +++ b/app/src/display.c @@ -6,7 +6,6 @@ #include #include "util/log.h" -#include "util/sdl.h" static bool sc_display_init_novideo_icon(struct sc_display *display, @@ -259,50 +258,7 @@ 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); - - SDL_Renderer *renderer = display->renderer; - SDL_Texture *texture = display->texture; - if (!texture) { - return false; - } - - bool ok; - 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()); - } - sc_sdl_render_present(display->renderer); - return ok; +SDL_Texture * +sc_display_get_current_texture(struct sc_display *display) { + return display->texture; } diff --git a/app/src/display.h b/app/src/display.h index 71ee2f20..dc9d6834 100644 --- a/app/src/display.h +++ b/app/src/display.h @@ -10,7 +10,6 @@ #include "coords.h" #include "opengl.h" -#include "options.h" #ifdef __APPLE__ # define SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE @@ -44,8 +43,7 @@ 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); +SDL_Texture * +sc_display_get_current_texture(struct sc_display *display); #endif diff --git a/app/src/screen.c b/app/src/screen.c index c5ab63de..b2e759d9 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -192,16 +192,68 @@ 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); + + SDL_Rect *geometry = &screen->rect; + enum sc_orientation orientation = screen->orientation; + + SDL_Texture *texture = sc_display_get_current_texture(&screen->display); + if (!texture) { + return; + } + + bool ok; + 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()); + } + 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 = sc_display_get_current_texture(&screen->display); + 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)