Compare commits
2 Commits
icon_decod
...
fix_minimi
Author | SHA1 | Date | |
---|---|---|---|
dec09432e1 | |||
ac39648426 |
@ -62,11 +62,17 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps) {
|
|||||||
LOGD("Trilinear filtering disabled (not an OpenGL renderer");
|
LOGD("Trilinear filtering disabled (not an OpenGL renderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
display->pending.flags = 0;
|
||||||
|
display->pending.frame = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_display_destroy(struct sc_display *display) {
|
sc_display_destroy(struct sc_display *display) {
|
||||||
|
if (display->pending.frame) {
|
||||||
|
av_frame_free(&display->pending.frame);
|
||||||
|
}
|
||||||
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
|
#ifdef SC_DISPLAY_FORCE_OPENGL_CORE_PROFILE
|
||||||
SDL_GL_DeleteContext(display->gl_context);
|
SDL_GL_DeleteContext(display->gl_context);
|
||||||
#endif
|
#endif
|
||||||
@ -84,7 +90,7 @@ sc_display_create_texture(struct sc_display *display,
|
|||||||
SDL_TEXTUREACCESS_STREAMING,
|
SDL_TEXTUREACCESS_STREAMING,
|
||||||
size.width, size.height);
|
size.width, size.height);
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
LOGE("Could not create texture: %s", SDL_GetError());
|
LOGD("Could not create texture: %s", SDL_GetError());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +110,66 @@ sc_display_create_texture(struct sc_display *display,
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static inline void
|
||||||
sc_display_set_texture_size(struct sc_display *display, struct sc_size size) {
|
sc_display_set_pending_size(struct sc_display *display, struct sc_size size) {
|
||||||
|
assert(!display->texture);
|
||||||
|
display->pending.size = size;
|
||||||
|
display->pending.flags |= SC_DISPLAY_PENDING_FLAG_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_display_set_pending_frame(struct sc_display *display, const AVFrame *frame) {
|
||||||
|
if (!display->pending.frame) {
|
||||||
|
display->pending.frame = av_frame_alloc();
|
||||||
|
if (!display->pending.frame) {
|
||||||
|
LOG_OOM();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int r = av_frame_ref(display->pending.frame, frame);
|
||||||
|
if (r) {
|
||||||
|
LOGE("Could not ref frame: %d", r);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
display->pending.flags |= SC_DISPLAY_PENDING_FLAG_FRAME;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_display_apply_pending(struct sc_display *display) {
|
||||||
|
if (display->pending.flags & SC_DISPLAY_PENDING_FLAG_SIZE) {
|
||||||
|
assert(!display->texture);
|
||||||
|
display->texture =
|
||||||
|
sc_display_create_texture(display, display->pending.size);
|
||||||
|
if (!display->texture) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
display->pending.flags &= ~SC_DISPLAY_PENDING_FLAG_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (display->pending.flags & SC_DISPLAY_PENDING_FLAG_FRAME) {
|
||||||
|
assert(display->pending.frame);
|
||||||
|
bool ok = sc_display_update_texture(display, display->pending.frame);
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
av_frame_unref(display->pending.frame);
|
||||||
|
display->pending.flags &= ~SC_DISPLAY_PENDING_FLAG_FRAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_display_set_texture_size_internal(struct sc_display *display,
|
||||||
|
struct sc_size size) {
|
||||||
|
assert(size.width && size.height);
|
||||||
|
|
||||||
if (display->texture) {
|
if (display->texture) {
|
||||||
SDL_DestroyTexture(display->texture);
|
SDL_DestroyTexture(display->texture);
|
||||||
}
|
}
|
||||||
@ -119,14 +183,27 @@ sc_display_set_texture_size(struct sc_display *display, struct sc_size size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
enum sc_display_result
|
||||||
sc_display_update_texture(struct sc_display *display, const AVFrame *frame) {
|
sc_display_set_texture_size(struct sc_display *display, struct sc_size size) {
|
||||||
|
bool ok = sc_display_set_texture_size_internal(display, size);
|
||||||
|
if (!ok) {
|
||||||
|
sc_display_set_pending_size(display, size);
|
||||||
|
return SC_DISPLAY_RESULT_PENDING;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return SC_DISPLAY_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
sc_display_update_texture_internal(struct sc_display *display,
|
||||||
|
const AVFrame *frame) {
|
||||||
int ret = SDL_UpdateYUVTexture(display->texture, NULL,
|
int ret = SDL_UpdateYUVTexture(display->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],
|
||||||
frame->data[2], frame->linesize[2]);
|
frame->data[2], frame->linesize[2]);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
LOGE("Could not update texture: %s", SDL_GetError());
|
LOGD("Could not update texture: %s", SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,11 +216,32 @@ sc_display_update_texture(struct sc_display *display, const AVFrame *frame) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
enum sc_display_result
|
||||||
|
sc_display_update_texture(struct sc_display *display, const AVFrame *frame) {
|
||||||
|
bool ok = sc_display_update_texture_internal(display, frame);
|
||||||
|
if (!ok) {
|
||||||
|
ok = sc_display_set_pending_frame(display, frame);
|
||||||
|
if (!ok) {
|
||||||
|
LOGE("Could not set pending frame");
|
||||||
|
return SC_DISPLAY_RESULT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SC_DISPLAY_RESULT_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SC_DISPLAY_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum sc_display_result
|
||||||
sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
|
sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
|
||||||
unsigned rotation) {
|
unsigned rotation) {
|
||||||
SDL_RenderClear(display->renderer);
|
SDL_RenderClear(display->renderer);
|
||||||
|
|
||||||
|
bool ok = sc_display_apply_pending(display);
|
||||||
|
if (!ok) {
|
||||||
|
return SC_DISPLAY_RESULT_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Renderer *renderer = display->renderer;
|
SDL_Renderer *renderer = display->renderer;
|
||||||
SDL_Texture *texture = display->texture;
|
SDL_Texture *texture = display->texture;
|
||||||
|
|
||||||
@ -151,7 +249,7 @@ sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
|
|||||||
int ret = SDL_RenderCopy(renderer, texture, NULL, geometry);
|
int ret = SDL_RenderCopy(renderer, texture, NULL, geometry);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
LOGE("Could not render texture: %s", SDL_GetError());
|
LOGE("Could not render texture: %s", SDL_GetError());
|
||||||
return false;
|
return SC_DISPLAY_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// rotation in RenderCopyEx() is clockwise, while screen->rotation is
|
// rotation in RenderCopyEx() is clockwise, while screen->rotation is
|
||||||
@ -176,10 +274,10 @@ sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
|
|||||||
NULL, 0);
|
NULL, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
LOGE("Could not render texture: %s", SDL_GetError());
|
LOGE("Could not render texture: %s", SDL_GetError());
|
||||||
return false;
|
return SC_DISPLAY_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderPresent(display->renderer);
|
SDL_RenderPresent(display->renderer);
|
||||||
return true;
|
return SC_DISPLAY_RESULT_OK;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,20 @@ struct sc_display {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool mipmaps;
|
bool mipmaps;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
#define SC_DISPLAY_PENDING_FLAG_SIZE 1
|
||||||
|
#define SC_DISPLAY_PENDING_FLAG_FRAME 2
|
||||||
|
int8_t flags;
|
||||||
|
struct sc_size size;
|
||||||
|
AVFrame *frame;
|
||||||
|
} pending;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum sc_display_result {
|
||||||
|
SC_DISPLAY_RESULT_OK,
|
||||||
|
SC_DISPLAY_RESULT_PENDING,
|
||||||
|
SC_DISPLAY_RESULT_ERROR,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -32,13 +46,13 @@ sc_display_init(struct sc_display *display, SDL_Window *window, bool mipmaps);
|
|||||||
void
|
void
|
||||||
sc_display_destroy(struct sc_display *display);
|
sc_display_destroy(struct sc_display *display);
|
||||||
|
|
||||||
bool
|
enum sc_display_result
|
||||||
sc_display_set_texture_size(struct sc_display *display, struct sc_size size);
|
sc_display_set_texture_size(struct sc_display *display, struct sc_size size);
|
||||||
|
|
||||||
bool
|
enum sc_display_result
|
||||||
sc_display_update_texture(struct sc_display *display, const AVFrame *frame);
|
sc_display_update_texture(struct sc_display *display, const AVFrame *frame);
|
||||||
|
|
||||||
bool
|
enum sc_display_result
|
||||||
sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
|
sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
|
||||||
unsigned rotation);
|
unsigned rotation);
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ static void
|
|||||||
set_window_size(struct sc_screen *screen, struct sc_size new_size) {
|
set_window_size(struct sc_screen *screen, struct sc_size new_size) {
|
||||||
assert(!screen->fullscreen);
|
assert(!screen->fullscreen);
|
||||||
assert(!screen->maximized);
|
assert(!screen->maximized);
|
||||||
|
assert(!screen->minimized);
|
||||||
SDL_SetWindowSize(screen->window, new_size.width, new_size.height);
|
SDL_SetWindowSize(screen->window, new_size.width, new_size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,9 +250,9 @@ sc_screen_render(struct sc_screen *screen, bool update_content_rect) {
|
|||||||
sc_screen_update_content_rect(screen);
|
sc_screen_update_content_rect(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok = sc_display_render(&screen->display, &screen->rect,
|
enum sc_display_result res =
|
||||||
screen->rotation);
|
sc_display_render(&screen->display, &screen->rect, screen->rotation);
|
||||||
(void) ok; // error already logged
|
(void) res; // any error already logged
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__WINDOWS__)
|
#if defined(__APPLE__) || defined(__WINDOWS__)
|
||||||
@ -359,6 +360,7 @@ sc_screen_init(struct sc_screen *screen,
|
|||||||
screen->has_frame = false;
|
screen->has_frame = false;
|
||||||
screen->fullscreen = false;
|
screen->fullscreen = false;
|
||||||
screen->maximized = false;
|
screen->maximized = false;
|
||||||
|
screen->minimized = false;
|
||||||
screen->mouse_capture_key_pressed = 0;
|
screen->mouse_capture_key_pressed = 0;
|
||||||
|
|
||||||
screen->req.x = params->window_x;
|
screen->req.x = params->window_x;
|
||||||
@ -531,11 +533,11 @@ resize_for_content(struct sc_screen *screen, struct sc_size old_content_size,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
set_content_size(struct sc_screen *screen, struct sc_size new_content_size) {
|
set_content_size(struct sc_screen *screen, struct sc_size new_content_size) {
|
||||||
if (!screen->fullscreen && !screen->maximized) {
|
if (!screen->fullscreen && !screen->maximized && !screen->minimized) {
|
||||||
resize_for_content(screen, screen->content_size, new_content_size);
|
resize_for_content(screen, screen->content_size, new_content_size);
|
||||||
} else if (!screen->resize_pending) {
|
} else if (!screen->resize_pending) {
|
||||||
// Store the windowed size to be able to compute the optimal size once
|
// Store the windowed size to be able to compute the optimal size once
|
||||||
// fullscreen and maximized are disabled
|
// fullscreen/maximized/minimized are disabled
|
||||||
screen->windowed_content_size = screen->content_size;
|
screen->windowed_content_size = screen->content_size;
|
||||||
screen->resize_pending = true;
|
screen->resize_pending = true;
|
||||||
}
|
}
|
||||||
@ -547,6 +549,7 @@ static void
|
|||||||
apply_pending_resize(struct sc_screen *screen) {
|
apply_pending_resize(struct sc_screen *screen) {
|
||||||
assert(!screen->fullscreen);
|
assert(!screen->fullscreen);
|
||||||
assert(!screen->maximized);
|
assert(!screen->maximized);
|
||||||
|
assert(!screen->minimized);
|
||||||
if (screen->resize_pending) {
|
if (screen->resize_pending) {
|
||||||
resize_for_content(screen, screen->windowed_content_size,
|
resize_for_content(screen, screen->windowed_content_size,
|
||||||
screen->content_size);
|
screen->content_size);
|
||||||
@ -583,15 +586,17 @@ sc_screen_init_size(struct sc_screen *screen) {
|
|||||||
get_rotated_size(screen->frame_size, screen->rotation);
|
get_rotated_size(screen->frame_size, screen->rotation);
|
||||||
screen->content_size = content_size;
|
screen->content_size = content_size;
|
||||||
|
|
||||||
return sc_display_set_texture_size(&screen->display, screen->frame_size);
|
enum sc_display_result res =
|
||||||
|
sc_display_set_texture_size(&screen->display, screen->frame_size);
|
||||||
|
return res != SC_DISPLAY_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// recreate the texture and resize the window if the frame size has changed
|
// recreate the texture and resize the window if the frame size has changed
|
||||||
static bool
|
static enum sc_display_result
|
||||||
prepare_for_frame(struct sc_screen *screen, struct sc_size new_frame_size) {
|
prepare_for_frame(struct sc_screen *screen, struct sc_size new_frame_size) {
|
||||||
if (screen->frame_size.width == new_frame_size.width
|
if (screen->frame_size.width == new_frame_size.width
|
||||||
&& screen->frame_size.height == new_frame_size.height) {
|
&& screen->frame_size.height == new_frame_size.height) {
|
||||||
return true;
|
return SC_DISPLAY_RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// frame dimension changed
|
// frame dimension changed
|
||||||
@ -615,13 +620,23 @@ sc_screen_update_frame(struct sc_screen *screen) {
|
|||||||
sc_fps_counter_add_rendered_frame(&screen->fps_counter);
|
sc_fps_counter_add_rendered_frame(&screen->fps_counter);
|
||||||
|
|
||||||
struct sc_size new_frame_size = {frame->width, frame->height};
|
struct sc_size new_frame_size = {frame->width, frame->height};
|
||||||
if (!prepare_for_frame(screen, new_frame_size)) {
|
enum sc_display_result res = prepare_for_frame(screen, new_frame_size);
|
||||||
|
if (res == SC_DISPLAY_RESULT_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (res == SC_DISPLAY_RESULT_PENDING) {
|
||||||
|
// Not an error, but do not continue
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!sc_display_update_texture(&screen->display, frame)) {
|
res = sc_display_update_texture(&screen->display, frame);
|
||||||
|
if (res == SC_DISPLAY_RESULT_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (res == SC_DISPLAY_RESULT_PENDING) {
|
||||||
|
// Not an error, but do not continue
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!screen->has_frame) {
|
if (!screen->has_frame) {
|
||||||
screen->has_frame = true;
|
screen->has_frame = true;
|
||||||
@ -647,7 +662,7 @@ sc_screen_switch_fullscreen(struct sc_screen *screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
screen->fullscreen = !screen->fullscreen;
|
screen->fullscreen = !screen->fullscreen;
|
||||||
if (!screen->fullscreen && !screen->maximized) {
|
if (!screen->fullscreen && !screen->maximized && !screen->minimized) {
|
||||||
apply_pending_resize(screen);
|
apply_pending_resize(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,7 +672,7 @@ sc_screen_switch_fullscreen(struct sc_screen *screen) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
sc_screen_resize_to_fit(struct sc_screen *screen) {
|
sc_screen_resize_to_fit(struct sc_screen *screen) {
|
||||||
if (screen->fullscreen || screen->maximized) {
|
if (screen->fullscreen || screen->maximized || screen->minimized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,7 +696,7 @@ sc_screen_resize_to_fit(struct sc_screen *screen) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
sc_screen_resize_to_pixel_perfect(struct sc_screen *screen) {
|
sc_screen_resize_to_pixel_perfect(struct sc_screen *screen) {
|
||||||
if (screen->fullscreen) {
|
if (screen->fullscreen || screen->minimized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,6 +753,9 @@ sc_screen_handle_event(struct sc_screen *screen, const SDL_Event *event) {
|
|||||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||||
screen->maximized = true;
|
screen->maximized = true;
|
||||||
break;
|
break;
|
||||||
|
case SDL_WINDOWEVENT_MINIMIZED:
|
||||||
|
screen->minimized = true;
|
||||||
|
break;
|
||||||
case SDL_WINDOWEVENT_RESTORED:
|
case SDL_WINDOWEVENT_RESTORED:
|
||||||
if (screen->fullscreen) {
|
if (screen->fullscreen) {
|
||||||
// On Windows, in maximized+fullscreen, disabling
|
// On Windows, in maximized+fullscreen, disabling
|
||||||
@ -748,6 +766,7 @@ sc_screen_handle_event(struct sc_screen *screen, const SDL_Event *event) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
screen->maximized = false;
|
screen->maximized = false;
|
||||||
|
screen->minimized = false;
|
||||||
apply_pending_resize(screen);
|
apply_pending_resize(screen);
|
||||||
sc_screen_render(screen, true);
|
sc_screen_render(screen, true);
|
||||||
break;
|
break;
|
||||||
|
@ -56,6 +56,7 @@ struct sc_screen {
|
|||||||
bool has_frame;
|
bool has_frame;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
bool maximized;
|
bool maximized;
|
||||||
|
bool minimized;
|
||||||
|
|
||||||
// To enable/disable mouse capture, a mouse capture key (LALT, LGUI or
|
// To enable/disable mouse capture, a mouse capture key (LALT, LGUI or
|
||||||
// RGUI) must be pressed. This variable tracks the pressed capture key.
|
// RGUI) must be pressed. This variable tracks the pressed capture key.
|
||||||
|
Reference in New Issue
Block a user