mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 14:49:29 +00:00
enable async resizing
This commit is contained in:
parent
da44fa4476
commit
6a9f3df434
1 changed files with 58 additions and 21 deletions
|
@ -206,7 +206,9 @@ static inline SDL_Texture *
|
||||||
create_texture(struct screen *screen) {
|
create_texture(struct screen *screen) {
|
||||||
SDL_Renderer *renderer = screen->renderer;
|
SDL_Renderer *renderer = screen->renderer;
|
||||||
struct size size = screen->frame_size;
|
struct size size = screen->frame_size;
|
||||||
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
|
SDL_PixelFormatEnum fmt = screen->use_swscale ? SDL_PIXELFORMAT_RGB24
|
||||||
|
: SDL_PIXELFORMAT_YV12;
|
||||||
|
SDL_Texture *texture = SDL_CreateTexture(renderer, fmt,
|
||||||
SDL_TEXTUREACCESS_STREAMING,
|
SDL_TEXTUREACCESS_STREAMING,
|
||||||
size.width, size.height);
|
size.width, size.height);
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
|
@ -214,6 +216,7 @@ create_texture(struct screen *screen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (screen->scale_filter == SC_SCALE_FILTER_TRILINEAR) {
|
if (screen->scale_filter == SC_SCALE_FILTER_TRILINEAR) {
|
||||||
|
assert(!screen->use_swscale);
|
||||||
struct sc_opengl *gl = &screen->gl;
|
struct sc_opengl *gl = &screen->gl;
|
||||||
|
|
||||||
SDL_GL_BindTexture(texture, NULL, NULL);
|
SDL_GL_BindTexture(texture, NULL, NULL);
|
||||||
|
@ -235,6 +238,19 @@ is_swscale(enum sc_scale_filter scale_filter) {
|
||||||
&& scale_filter != SC_SCALE_FILTER_TRILINEAR;
|
&& scale_filter != SC_SCALE_FILTER_TRILINEAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_resizer_frame_available(struct video_buffer *vb, void *userdata) {
|
||||||
|
(void) vb;
|
||||||
|
(void) userdata;
|
||||||
|
|
||||||
|
static SDL_Event new_frame_event = {
|
||||||
|
.type = EVENT_NEW_FRAME,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Post the event on the UI thread
|
||||||
|
SDL_PushEvent(&new_frame_event);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||||
struct size frame_size, bool always_on_top,
|
struct size frame_size, bool always_on_top,
|
||||||
|
@ -321,11 +337,23 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||||
|
|
||||||
screen->use_swscale = is_swscale(scale_filter);
|
screen->use_swscale = is_swscale(scale_filter);
|
||||||
if (screen->use_swscale) {
|
if (screen->use_swscale) {
|
||||||
bool ok = sc_resizer_init(&screen->resizer, screen->vb,
|
static const struct video_buffer_callbacks video_buffer_cbs = {
|
||||||
&screen->resizer_vb, scale_filter,
|
.on_frame_available = on_resizer_frame_available,
|
||||||
window_size);
|
};
|
||||||
|
bool ok = video_buffer_init(&screen->resizer_vb, false,
|
||||||
|
&video_buffer_cbs, NULL);
|
||||||
|
if (!ok) {
|
||||||
|
LOGE("Could not create resizer video buffer");
|
||||||
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
|
SDL_DestroyWindow(screen->window);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = sc_resizer_init(&screen->resizer, screen->vb, &screen->resizer_vb,
|
||||||
|
scale_filter, window_size);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not create resizer");
|
LOGE("Could not create resizer");
|
||||||
|
video_buffer_destroy(&screen->resizer_vb);
|
||||||
SDL_DestroyRenderer(screen->renderer);
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
SDL_DestroyWindow(screen->window);
|
SDL_DestroyWindow(screen->window);
|
||||||
return false;
|
return false;
|
||||||
|
@ -335,6 +363,7 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not start resizer");
|
LOGE("Could not start resizer");
|
||||||
sc_resizer_destroy(&screen->resizer);
|
sc_resizer_destroy(&screen->resizer);
|
||||||
|
video_buffer_destroy(&screen->resizer_vb);
|
||||||
SDL_DestroyRenderer(screen->renderer);
|
SDL_DestroyRenderer(screen->renderer);
|
||||||
SDL_DestroyWindow(screen->window);
|
SDL_DestroyWindow(screen->window);
|
||||||
}
|
}
|
||||||
|
@ -477,6 +506,10 @@ prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
||||||
// write the frame into the texture
|
// write the frame into the texture
|
||||||
static void
|
static void
|
||||||
update_texture(struct screen *screen, const AVFrame *frame) {
|
update_texture(struct screen *screen, const AVFrame *frame) {
|
||||||
|
if (screen->use_swscale) {
|
||||||
|
SDL_UpdateTexture(screen->texture, NULL, frame->data[0],
|
||||||
|
frame->linesize[0]);
|
||||||
|
} else {
|
||||||
SDL_UpdateYUVTexture(screen->texture, NULL,
|
SDL_UpdateYUVTexture(screen->texture, NULL,
|
||||||
frame->data[0], frame->linesize[0],
|
frame->data[0], frame->linesize[0],
|
||||||
frame->data[1], frame->linesize[1],
|
frame->data[1], frame->linesize[1],
|
||||||
|
@ -487,13 +520,15 @@ update_texture(struct screen *screen, const AVFrame *frame) {
|
||||||
screen->gl.GenerateMipmap(GL_TEXTURE_2D);
|
screen->gl.GenerateMipmap(GL_TEXTURE_2D);
|
||||||
SDL_GL_UnbindTexture(screen->texture);
|
SDL_GL_UnbindTexture(screen->texture);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
screen_update_frame(struct screen *screen) {
|
screen_update_frame(struct screen *screen) {
|
||||||
unsigned skipped;
|
unsigned skipped;
|
||||||
const AVFrame *frame =
|
struct video_buffer *vb = screen->use_swscale ? &screen->resizer_vb
|
||||||
video_buffer_consumer_take_frame(screen->vb, &skipped);
|
: screen->vb;
|
||||||
|
const AVFrame *frame = video_buffer_consumer_take_frame(vb, &skipped);
|
||||||
|
|
||||||
fps_counter_add_skipped_frames(screen->fps_counter, skipped);
|
fps_counter_add_skipped_frames(screen->fps_counter, skipped);
|
||||||
fps_counter_add_rendered_frame(screen->fps_counter);
|
fps_counter_add_rendered_frame(screen->fps_counter);
|
||||||
|
@ -695,12 +730,14 @@ screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y) {
|
||||||
|
|
||||||
void
|
void
|
||||||
screen_on_frame_available(struct screen *screen) {
|
screen_on_frame_available(struct screen *screen) {
|
||||||
(void) screen;
|
if (screen->use_swscale) {
|
||||||
|
sc_resizer_process_new_frame(&screen->resizer);
|
||||||
|
} else {
|
||||||
static SDL_Event new_frame_event = {
|
static SDL_Event new_frame_event = {
|
||||||
.type = EVENT_NEW_FRAME,
|
.type = EVENT_NEW_FRAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Post the event on the UI thread
|
// Post the event on the UI thread
|
||||||
SDL_PushEvent(&new_frame_event);
|
SDL_PushEvent(&new_frame_event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue