diff --git a/app/src/display.c b/app/src/display.c index b68f6f8b..c4127022 100644 --- a/app/src/display.c +++ b/app/src/display.c @@ -33,15 +33,9 @@ sc_display_init_novideo_icon(struct sc_display *display, } bool -sc_display_init(struct sc_display *display, SDL_Window *window, +sc_display_init(struct sc_display *display, SDL_Renderer *renderer, SDL_Surface *icon_novideo, bool mipmaps) { - display->renderer = SDL_CreateRenderer(window, NULL); - if (!display->renderer) { - LOGE("Could not create renderer: %s", SDL_GetError()); - return false; - } - - const char *renderer_name = SDL_GetRendererName(display->renderer); + const char *renderer_name = SDL_GetRendererName(renderer); LOGI("Renderer: %s", renderer_name ? renderer_name : "(unknown)"); display->mipmaps = false; @@ -67,7 +61,6 @@ sc_display_init(struct sc_display *display, SDL_Window *window, display->gl_context = SDL_GL_CreateContext(window); if (!display->gl_context) { LOGE("Could not create OpenGL context: %s", SDL_GetError()); - SDL_DestroyRenderer(display->renderer); return false; } #endif @@ -95,6 +88,7 @@ sc_display_init(struct sc_display *display, SDL_Window *window, LOGD("Trilinear filtering disabled (not an OpenGL renderer)"); } + display->renderer = renderer; display->texture = NULL; if (icon_novideo) { @@ -104,7 +98,6 @@ sc_display_init(struct sc_display *display, SDL_Window *window, #ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE SDL_GL_DestroyContext(display->gl_context); #endif - SDL_DestroyRenderer(display->renderer); return false; } } @@ -120,7 +113,6 @@ sc_display_destroy(struct sc_display *display) { if (display->texture) { SDL_DestroyTexture(display->texture); } - SDL_DestroyRenderer(display->renderer); } static enum SDL_Colorspace diff --git a/app/src/display.h b/app/src/display.h index dccf797f..71ee2f20 100644 --- a/app/src/display.h +++ b/app/src/display.h @@ -17,7 +17,7 @@ #endif struct sc_display { - SDL_Renderer *renderer; + SDL_Renderer *renderer; // owned by the caller SDL_Texture *texture; struct sc_opengl gl; @@ -30,7 +30,7 @@ struct sc_display { }; bool -sc_display_init(struct sc_display *display, SDL_Window *window, +sc_display_init(struct sc_display *display, SDL_Renderer *renderer, SDL_Surface *icon_novideo, bool mipmaps); void diff --git a/app/src/screen.c b/app/src/screen.c index 791d877c..c5ab63de 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -389,15 +389,21 @@ sc_screen_init(struct sc_screen *screen, goto error_destroy_window; } + screen->renderer = SDL_CreateRenderer(screen->window, NULL); + if (!screen->renderer) { + LOGE("Could not create renderer: %s", SDL_GetError()); + goto error_destroy_window; + } + SDL_Surface *icon_novideo = params->video ? NULL : icon; bool mipmaps = params->video && params->mipmaps; - ok = sc_display_init(&screen->display, screen->window, icon_novideo, + ok = sc_display_init(&screen->display, screen->renderer, icon_novideo, mipmaps); if (icon) { sc_icon_destroy(icon); } if (!ok) { - goto error_destroy_window; + goto error_destroy_renderer; } screen->frame = av_frame_alloc(); @@ -461,6 +467,8 @@ sc_screen_init(struct sc_screen *screen, error_destroy_display: sc_display_destroy(&screen->display); +error_destroy_renderer: + SDL_DestroyRenderer(screen->renderer); error_destroy_window: SDL_DestroyWindow(screen->window); error_destroy_fps_counter: @@ -524,6 +532,7 @@ sc_screen_destroy(struct sc_screen *screen) { #endif sc_display_destroy(&screen->display); av_frame_free(&screen->frame); + SDL_DestroyRenderer(screen->renderer); SDL_DestroyWindow(screen->window); sc_fps_counter_destroy(&screen->fps_counter); sc_frame_buffer_destroy(&screen->fb); diff --git a/app/src/screen.h b/app/src/screen.h index 1d8070e8..9e81cea8 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -49,6 +49,7 @@ struct sc_screen { } req; SDL_Window *window; + SDL_Renderer *renderer; struct sc_size frame_size; struct sc_size content_size; // rotated frame_size