Skip to content

Display and control your Android device

Move rendering from sc_display to sc_screen

Romain Vimont930169af4e8c
diff --git a/app/src/display.c b/app/src/display.c
index e7795c76..af635b06 100644
--- a/app/src/display.c
+++ b/app/src/display.c
@@ -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;
-}
diff --git a/app/src/display.h b/app/src/display.h
index a8d0141b..9ba0d0bd 100644
--- a/app/src/display.h
+++ b/app/src/display.h
@@ -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
diff --git a/app/src/screen.c b/app/src/screen.c
index 6e2bcb15..698ce2aa 100644
--- a/app/src/screen.c
+++ b/app/src/screen.c
@@ -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)