Move frame updating to screen.c

Replace screen_update() by a higher-level screen_update_frame() handling
the whole frame updating, so that scrcpy.c just call it without managing
implementation details.
This commit is contained in:
Romain Vimont 2018-02-09 11:14:47 +01:00
parent 7458d8271e
commit fe21d9dfb5
3 changed files with 12 additions and 17 deletions

View file

@ -46,19 +46,6 @@ static void count_frame(void) {
} }
} }
static SDL_bool handle_new_frame(void) {
mutex_lock(frames.mutex);
const AVFrame *frame = frames_consume_rendered_frame(&frames);
if (!screen_update(&screen, frame)){
mutex_unlock(frames.mutex);
return SDL_FALSE;
}
mutex_unlock(frames.mutex);
screen_render(&screen);
return SDL_TRUE;
}
static void event_loop(void) { static void event_loop(void) {
SDL_Event event; SDL_Event event;
while (SDL_WaitEvent(&event)) { while (SDL_WaitEvent(&event)) {
@ -70,7 +57,7 @@ static void event_loop(void) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "User requested to quit"); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "User requested to quit");
return; return;
case EVENT_NEW_FRAME: case EVENT_NEW_FRAME:
if (!handle_new_frame()) { if (!screen_update_frame(&screen, &frames)) {
return; return;
} }
count_frame(); // display fps for debug count_frame(); // display fps for debug

View file

@ -4,6 +4,7 @@
#include <string.h> #include <string.h>
#include "icon.xpm" #include "icon.xpm"
#include "lockutil.h"
#include "tinyxpm.h" #include "tinyxpm.h"
#define DISPLAY_MARGINS 96 #define DISPLAY_MARGINS 96
@ -237,12 +238,18 @@ static void update_texture(struct screen *screen, const AVFrame *frame) {
frame->data[2], frame->linesize[2]); frame->data[2], frame->linesize[2]);
} }
SDL_bool screen_update(struct screen *screen, const AVFrame *frame) { SDL_bool screen_update_frame(struct screen *screen, struct frames *frames) {
mutex_lock(frames->mutex);
const AVFrame *frame = frames_consume_rendered_frame(frames);
struct size new_frame_size = {frame->width, frame->height}; struct size new_frame_size = {frame->width, frame->height};
if (!prepare_for_frame(screen, new_frame_size)) { if (!prepare_for_frame(screen, new_frame_size)) {
mutex_unlock(frames->mutex);
return SDL_FALSE; return SDL_FALSE;
} }
update_texture(screen, frame); update_texture(screen, frame);
mutex_unlock(frames->mutex);
screen_render(screen);
return SDL_TRUE; return SDL_TRUE;
} }

View file

@ -5,6 +5,7 @@
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include "common.h" #include "common.h"
#include "frames.h"
struct screen { struct screen {
SDL_Window *window; SDL_Window *window;
@ -47,8 +48,8 @@ SDL_bool screen_init_rendering(struct screen *screen,
// destroy window, renderer and texture (if any) // destroy window, renderer and texture (if any)
void screen_destroy(struct screen *screen); void screen_destroy(struct screen *screen);
// resize if necessary and write the frame into the texture // resize if necessary and write the rendered frame into the texture
SDL_bool screen_update(struct screen *screen, const AVFrame *frame); SDL_bool screen_update_frame(struct screen *screen, struct frames *frames);
// render the texture to the renderer // render the texture to the renderer
void screen_render(struct screen *screen); void screen_render(struct screen *screen);