mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-02-23 06:44:28 +01:00
set_texture_from_surface
This commit is contained in:
@@ -7,24 +7,9 @@
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
static bool
|
||||
sc_display_init_novideo_icon(struct sc_display *display,
|
||||
SDL_Surface *icon_novideo) {
|
||||
assert(icon_novideo);
|
||||
|
||||
display->texture = SDL_CreateTextureFromSurface(display->renderer,
|
||||
icon_novideo);
|
||||
if (!display->texture) {
|
||||
LOGE("Could not create texture: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
|
||||
SDL_Surface *icon_novideo, bool mipmaps) {
|
||||
bool mipmaps) {
|
||||
const char *renderer_name = SDL_GetRendererName(renderer);
|
||||
LOGI("Renderer: %s", renderer_name ? renderer_name : "(unknown)");
|
||||
|
||||
@@ -80,18 +65,6 @@ sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
|
||||
|
||||
display->renderer = renderer;
|
||||
display->texture = NULL;
|
||||
|
||||
if (icon_novideo) {
|
||||
// Without video, set a static scrcpy icon as window content
|
||||
bool ok = sc_display_init_novideo_icon(display, icon_novideo);
|
||||
if (!ok) {
|
||||
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
|
||||
SDL_GL_DestroyContext(display->gl_context);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -249,6 +222,22 @@ sc_display_update_texture(struct sc_display *display, const AVFrame *frame) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
sc_display_set_texture_from_surface(struct sc_display *display,
|
||||
SDL_Surface *surface) {
|
||||
if (display->texture) {
|
||||
SDL_DestroyTexture(display->texture);
|
||||
}
|
||||
|
||||
display->texture = SDL_CreateTextureFromSurface(display->renderer, surface);
|
||||
if (!display->texture) {
|
||||
LOGE("Could not create texture: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SDL_Texture *
|
||||
sc_display_get_current_texture(struct sc_display *display) {
|
||||
return display->texture;
|
||||
|
||||
@@ -30,7 +30,7 @@ struct sc_display {
|
||||
|
||||
bool
|
||||
sc_display_init(struct sc_display *display, SDL_Renderer *renderer,
|
||||
SDL_Surface *icon_novideo, bool mipmaps);
|
||||
bool mipmaps);
|
||||
|
||||
void
|
||||
sc_display_destroy(struct sc_display *display);
|
||||
@@ -43,6 +43,10 @@ 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_set_texture_from_surface(struct sc_display *display,
|
||||
SDL_Surface *surface);
|
||||
|
||||
SDL_Texture *
|
||||
sc_display_get_current_texture(struct sc_display *display);
|
||||
|
||||
|
||||
@@ -411,10 +411,22 @@ sc_screen_init(struct sc_screen *screen,
|
||||
goto error_destroy_fps_counter;
|
||||
}
|
||||
|
||||
screen->renderer = SDL_CreateRenderer(screen->window, NULL);
|
||||
if (!screen->renderer) {
|
||||
LOGE("Could not create renderer: %s", SDL_GetError());
|
||||
goto error_destroy_window;
|
||||
}
|
||||
|
||||
bool mipmaps = params->video;
|
||||
ok = sc_display_init(&screen->display, screen->renderer, mipmaps);
|
||||
if (!ok) {
|
||||
goto error_destroy_renderer;
|
||||
}
|
||||
|
||||
ok = SDL_StartTextInput(screen->window);
|
||||
if (!ok) {
|
||||
LOGE("Could not enable text input: %s", SDL_GetError());
|
||||
goto error_destroy_window;
|
||||
goto error_destroy_display;
|
||||
}
|
||||
|
||||
SDL_Surface *icon = sc_icon_load_scrcpy();
|
||||
@@ -428,34 +440,23 @@ sc_screen_init(struct sc_screen *screen,
|
||||
} else {
|
||||
// without video, the icon is used as window content, it must be present
|
||||
LOGE("Could not load icon");
|
||||
goto error_destroy_window;
|
||||
goto error_destroy_display;
|
||||
}
|
||||
|
||||
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;
|
||||
bool mipmaps;
|
||||
if (params->video) {
|
||||
icon_novideo = NULL;
|
||||
mipmaps = params->mipmaps;
|
||||
} else {
|
||||
icon_novideo = icon;
|
||||
mipmaps = false;
|
||||
if (!params->video) {
|
||||
assert(icon);
|
||||
screen->content_size.width = icon->w;
|
||||
screen->content_size.height = icon->h;
|
||||
ok = sc_display_set_texture_from_surface(&screen->display, icon);
|
||||
if (!ok) {
|
||||
sc_icon_destroy(icon);
|
||||
goto error_destroy_display;
|
||||
}
|
||||
}
|
||||
ok = sc_display_init(&screen->display, screen->renderer, icon_novideo,
|
||||
mipmaps);
|
||||
|
||||
if (icon) {
|
||||
sc_icon_destroy(icon);
|
||||
}
|
||||
if (!ok) {
|
||||
goto error_destroy_renderer;
|
||||
}
|
||||
|
||||
screen->frame = av_frame_alloc();
|
||||
if (!screen->frame) {
|
||||
|
||||
Reference in New Issue
Block a user