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.
hidpi
Romain Vimont 6 years ago
parent 7458d8271e
commit fe21d9dfb5

@ -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) {
SDL_Event event;
while (SDL_WaitEvent(&event)) {
@ -70,7 +57,7 @@ static void event_loop(void) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "User requested to quit");
return;
case EVENT_NEW_FRAME:
if (!handle_new_frame()) {
if (!screen_update_frame(&screen, &frames)) {
return;
}
count_frame(); // display fps for debug

@ -4,6 +4,7 @@
#include <string.h>
#include "icon.xpm"
#include "lockutil.h"
#include "tinyxpm.h"
#define DISPLAY_MARGINS 96
@ -237,12 +238,18 @@ static void update_texture(struct screen *screen, const AVFrame *frame) {
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};
if (!prepare_for_frame(screen, new_frame_size)) {
mutex_unlock(frames->mutex);
return SDL_FALSE;
}
update_texture(screen, frame);
mutex_unlock(frames->mutex);
screen_render(screen);
return SDL_TRUE;
}

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

Loading…
Cancel
Save