2018-02-08 10:14:13 +00:00
|
|
|
#include "screen.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2019-03-02 22:52:22 +00:00
|
|
|
#include <SDL2/SDL.h>
|
2018-02-08 10:14:13 +00:00
|
|
|
|
2019-03-02 22:52:22 +00:00
|
|
|
#include "common.h"
|
2019-02-16 14:04:32 +00:00
|
|
|
#include "compat.h"
|
2018-02-08 10:14:13 +00:00
|
|
|
#include "icon.xpm"
|
2018-08-15 15:01:54 +00:00
|
|
|
#include "lock_util.h"
|
2018-02-13 09:10:18 +00:00
|
|
|
#include "log.h"
|
2018-08-15 15:01:54 +00:00
|
|
|
#include "tiny_xpm.h"
|
2019-03-02 14:16:55 +00:00
|
|
|
#include "video_buffer.h"
|
2018-02-08 10:14:13 +00:00
|
|
|
|
|
|
|
#define DISPLAY_MARGINS 96
|
|
|
|
|
|
|
|
// get the window size in a struct size
|
2019-03-02 19:09:56 +00:00
|
|
|
static struct size
|
|
|
|
get_native_window_size(SDL_Window *window) {
|
2018-02-08 10:14:13 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
SDL_GetWindowSize(window, &width, &height);
|
|
|
|
|
|
|
|
struct size size;
|
|
|
|
size.width = width;
|
|
|
|
size.height = height;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the windowed window size
|
2019-03-02 19:09:56 +00:00
|
|
|
static struct size
|
|
|
|
get_window_size(const struct screen *screen) {
|
2018-02-08 10:14:13 +00:00
|
|
|
if (screen->fullscreen) {
|
|
|
|
return screen->windowed_window_size;
|
|
|
|
}
|
|
|
|
return get_native_window_size(screen->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the window size to be applied when fullscreen is disabled
|
2019-03-02 19:09:56 +00:00
|
|
|
static void
|
|
|
|
set_window_size(struct screen *screen, struct size new_size) {
|
2018-02-08 10:14:13 +00:00
|
|
|
// setting the window size during fullscreen is implementation defined,
|
|
|
|
// so apply the resize only after fullscreen is disabled
|
|
|
|
if (screen->fullscreen) {
|
|
|
|
// SDL_SetWindowSize will be called when fullscreen will be disabled
|
|
|
|
screen->windowed_window_size = new_size;
|
|
|
|
} else {
|
|
|
|
SDL_SetWindowSize(screen->window, new_size.width, new_size.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the preferred display bounds (i.e. the screen bounds with some margins)
|
2019-03-02 22:52:22 +00:00
|
|
|
static bool
|
2019-03-02 19:09:56 +00:00
|
|
|
get_preferred_display_bounds(struct size *bounds) {
|
2018-02-08 10:14:13 +00:00
|
|
|
SDL_Rect rect;
|
2019-02-16 14:04:32 +00:00
|
|
|
#ifdef SCRCPY_SDL_HAS_GET_DISPLAY_USABLE_BOUNDS
|
2018-02-08 10:14:13 +00:00
|
|
|
# define GET_DISPLAY_BOUNDS(i, r) SDL_GetDisplayUsableBounds((i), (r))
|
|
|
|
#else
|
|
|
|
# define GET_DISPLAY_BOUNDS(i, r) SDL_GetDisplayBounds((i), (r))
|
|
|
|
#endif
|
|
|
|
if (GET_DISPLAY_BOUNDS(0, &rect)) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGW("Could not get display usable bounds: %s", SDL_GetError());
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bounds->width = MAX(0, rect.w - DISPLAY_MARGINS);
|
|
|
|
bounds->height = MAX(0, rect.h - DISPLAY_MARGINS);
|
2019-03-02 22:52:22 +00:00
|
|
|
return true;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return the optimal size of the window, with the following constraints:
|
2019-03-02 19:09:56 +00:00
|
|
|
// - it attempts to keep at least one dimension of the current_size (i.e. it
|
|
|
|
// crops the black borders)
|
2018-02-08 10:14:13 +00:00
|
|
|
// - it keeps the aspect ratio
|
|
|
|
// - it scales down to make it fit in the display_size
|
2019-03-02 19:09:56 +00:00
|
|
|
static struct size
|
|
|
|
get_optimal_size(struct size current_size, struct size frame_size) {
|
2018-02-15 22:50:38 +00:00
|
|
|
if (frame_size.width == 0 || frame_size.height == 0) {
|
|
|
|
// avoid division by 0
|
|
|
|
return current_size;
|
|
|
|
}
|
|
|
|
|
2018-02-08 10:14:13 +00:00
|
|
|
struct size display_size;
|
|
|
|
// 32 bits because we need to multiply two 16 bits values
|
2019-03-02 22:52:22 +00:00
|
|
|
uint32_t w;
|
|
|
|
uint32_t h;
|
2018-02-08 10:14:13 +00:00
|
|
|
|
|
|
|
if (!get_preferred_display_bounds(&display_size)) {
|
|
|
|
// cannot get display bounds, do not constraint the size
|
|
|
|
w = current_size.width;
|
|
|
|
h = current_size.height;
|
|
|
|
} else {
|
|
|
|
w = MIN(current_size.width, display_size.width);
|
|
|
|
h = MIN(current_size.height, display_size.height);
|
|
|
|
}
|
|
|
|
|
2019-03-02 22:52:22 +00:00
|
|
|
bool keep_width = frame_size.width * h > frame_size.height * w;
|
2018-02-08 10:14:13 +00:00
|
|
|
if (keep_width) {
|
|
|
|
// remove black borders on top and bottom
|
|
|
|
h = frame_size.height * w / frame_size.width;
|
|
|
|
} else {
|
2019-03-02 19:09:56 +00:00
|
|
|
// remove black borders on left and right (or none at all if it already
|
|
|
|
// fits)
|
2018-02-08 10:14:13 +00:00
|
|
|
w = frame_size.width * h / frame_size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// w and h must fit into 16 bits
|
|
|
|
SDL_assert_release(w < 0x10000 && h < 0x10000);
|
|
|
|
return (struct size) {w, h};
|
|
|
|
}
|
|
|
|
|
|
|
|
// same as get_optimal_size(), but read the current size from the window
|
2019-03-02 19:09:56 +00:00
|
|
|
static inline struct size
|
|
|
|
get_optimal_window_size(const struct screen *screen, struct size frame_size) {
|
2018-02-08 10:14:13 +00:00
|
|
|
struct size current_size = get_window_size(screen);
|
|
|
|
return get_optimal_size(current_size, frame_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// initially, there is no current size, so use the frame size as current size
|
2019-03-02 19:09:56 +00:00
|
|
|
static inline struct size
|
|
|
|
get_initial_optimal_size(struct size frame_size) {
|
2018-02-08 10:14:13 +00:00
|
|
|
return get_optimal_size(frame_size, frame_size);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
screen_init(struct screen *screen) {
|
2018-02-08 10:14:13 +00:00
|
|
|
*screen = (struct screen) SCREEN_INITIALIZER;
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
static inline SDL_Texture *
|
|
|
|
create_texture(SDL_Renderer *renderer, struct size frame_size) {
|
|
|
|
return SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
|
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
2018-03-27 09:01:40 +00:00
|
|
|
frame_size.width, frame_size.height);
|
|
|
|
}
|
|
|
|
|
2019-03-02 22:52:22 +00:00
|
|
|
bool
|
2019-03-02 19:09:56 +00:00
|
|
|
screen_init_rendering(struct screen *screen, const char *device_name,
|
2019-03-02 22:52:22 +00:00
|
|
|
struct size frame_size, bool always_on_top) {
|
2018-02-08 10:14:13 +00:00
|
|
|
screen->frame_size = frame_size;
|
|
|
|
|
|
|
|
struct size window_size = get_initial_optimal_size(frame_size);
|
2019-03-02 22:52:22 +00:00
|
|
|
uint32_t window_flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
2018-03-07 09:53:39 +00:00
|
|
|
#ifdef HIDPI_SUPPORT
|
|
|
|
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
|
|
|
#endif
|
2019-01-27 11:04:22 +00:00
|
|
|
if (always_on_top) {
|
2019-02-16 14:21:14 +00:00
|
|
|
#ifdef SCRCPY_SDL_HAS_WINDOW_ALWAYS_ON_TOP
|
2019-01-27 11:04:22 +00:00
|
|
|
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
|
2019-02-16 14:21:14 +00:00
|
|
|
#else
|
|
|
|
LOGW("The 'always on top' flag is not available "
|
|
|
|
"(compile with SDL >= 2.0.5 to enable it)");
|
|
|
|
#endif
|
2019-01-27 11:04:22 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
screen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
window_size.width, window_size.height,
|
|
|
|
window_flags);
|
2018-02-08 10:14:13 +00:00
|
|
|
if (!screen->window) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGC("Could not create window: %s", SDL_GetError());
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
screen->renderer = SDL_CreateRenderer(screen->window, -1,
|
|
|
|
SDL_RENDERER_ACCELERATED);
|
2018-02-08 10:14:13 +00:00
|
|
|
if (!screen->renderer) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGC("Could not create renderer: %s", SDL_GetError());
|
2018-02-08 10:14:13 +00:00
|
|
|
screen_destroy(screen);
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
if (SDL_RenderSetLogicalSize(screen->renderer, frame_size.width,
|
|
|
|
frame_size.height)) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
2018-02-08 10:14:13 +00:00
|
|
|
screen_destroy(screen);
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *icon = read_xpm(icon_xpm);
|
2019-05-23 18:58:08 +00:00
|
|
|
if (icon) {
|
|
|
|
SDL_SetWindowIcon(screen->window, icon);
|
|
|
|
SDL_FreeSurface(icon);
|
|
|
|
} else {
|
|
|
|
LOGW("Could not load icon");
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
LOGI("Initial texture: %" PRIu16 "x%" PRIu16, frame_size.width,
|
|
|
|
frame_size.height);
|
2018-03-27 09:01:40 +00:00
|
|
|
screen->texture = create_texture(screen->renderer, frame_size);
|
2018-02-08 10:14:13 +00:00
|
|
|
if (!screen->texture) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGC("Could not create texture: %s", SDL_GetError());
|
2018-02-08 10:14:13 +00:00
|
|
|
screen_destroy(screen);
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 22:52:22 +00:00
|
|
|
return true;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
screen_show_window(struct screen *screen) {
|
Improve startup time
On startup, the client has to:
1. listen on a port
2. push and start the server to the device
3. wait for the server to connect (accept)
4. read device name and size
5. initialize SDL
6. initialize the window and renderer
7. show the window
From the execution of the app_process command to start the server on the
device, to the execution of the java main method, it takes ~800ms. As a
consequence, step 3 also takes ~800ms on the client.
Once complete, the client initializes SDL, which takes ~500ms.
These two expensive actions are executed sequentially:
HOST DEVICE
listen on port | |
push/start the server |----------------->|| app_process loads the jar
accept the connection . ^ ||
. | ||
. | WASTE ||
. | OF ||
. | TIME ||
. | ||
. | ||
. v X execution of our java main
connection accepted |<-----------------| connect to the host
init SDL || |
|| ,----------------| send frames
|| |,---------------|
|| ||,--------------|
|| |||,-------------|
|| ||||,------------|
init window/renderer | |||||,-----------|
display frames |<++++++-----------|
(many frames skipped)
The rationale for step 3 occuring before step 5 is that initializing
SDL replaces the SIGTERM handler to receive the event in the event loop,
so pressing Ctrl+C during step 5 would not work (since it blocks the
event loop).
But this is not so important; let's parallelize the SDL initialization
with the app_process execution (we'll just add a timeout to the
connection):
HOST DEVICE
listen on port | |
push/start the server |----------------->||app_process loads the jar
init SDL || ||
|| ||
|| ||
|| ||
|| ||
|| ||
accept the connection . ||
. X execution of our java main
connection accepted |<-----------------| connect to the host
init window/renderer | |
display frames |<-----------------| send frames
|<-----------------|
In addition, show the window only once the first frame is available to
avoid flickering (opening a black window for 100~200ms).
Note: the window and renderer are initialized after the connection is
accepted because they use the device information received from the
device.
2018-02-09 12:50:54 +00:00
|
|
|
SDL_ShowWindow(screen->window);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
screen_destroy(struct screen *screen) {
|
2018-02-08 10:14:13 +00:00
|
|
|
if (screen->texture) {
|
|
|
|
SDL_DestroyTexture(screen->texture);
|
|
|
|
}
|
|
|
|
if (screen->renderer) {
|
2018-02-09 14:20:03 +00:00
|
|
|
SDL_DestroyRenderer(screen->renderer);
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
if (screen->window) {
|
2018-02-09 14:20:03 +00:00
|
|
|
SDL_DestroyWindow(screen->window);
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// recreate the texture and resize the window if the frame size has changed
|
2019-03-02 22:52:22 +00:00
|
|
|
static bool
|
2019-03-02 19:09:56 +00:00
|
|
|
prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
|
|
|
if (screen->frame_size.width != new_frame_size.width
|
|
|
|
|| screen->frame_size.height != new_frame_size.height) {
|
|
|
|
if (SDL_RenderSetLogicalSize(screen->renderer, new_frame_size.width,
|
|
|
|
new_frame_size.height)) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// frame dimension changed, destroy texture
|
|
|
|
SDL_DestroyTexture(screen->texture);
|
|
|
|
|
|
|
|
struct size current_size = get_window_size(screen);
|
|
|
|
struct size target_size = {
|
2019-03-02 22:52:22 +00:00
|
|
|
(uint32_t) current_size.width * new_frame_size.width
|
2019-03-02 19:09:56 +00:00
|
|
|
/ screen->frame_size.width,
|
2019-03-02 22:52:22 +00:00
|
|
|
(uint32_t) current_size.height * new_frame_size.height
|
2019-03-02 19:09:56 +00:00
|
|
|
/ screen->frame_size.height,
|
2018-02-08 10:14:13 +00:00
|
|
|
};
|
|
|
|
target_size = get_optimal_size(target_size, new_frame_size);
|
|
|
|
set_window_size(screen, target_size);
|
|
|
|
|
|
|
|
screen->frame_size = new_frame_size;
|
|
|
|
|
2019-03-07 19:17:09 +00:00
|
|
|
LOGI("New texture: %" PRIu16 "x%" PRIu16,
|
2018-02-08 10:14:13 +00:00
|
|
|
screen->frame_size.width, screen->frame_size.height);
|
2018-03-27 09:01:40 +00:00
|
|
|
screen->texture = create_texture(screen->renderer, new_frame_size);
|
2018-02-08 10:14:13 +00:00
|
|
|
if (!screen->texture) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGC("Could not create texture: %s", SDL_GetError());
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 22:52:22 +00:00
|
|
|
return true;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// write the frame into the texture
|
2019-03-02 19:09:56 +00:00
|
|
|
static void
|
|
|
|
update_texture(struct screen *screen, const AVFrame *frame) {
|
2018-02-08 10:14:13 +00:00
|
|
|
SDL_UpdateYUVTexture(screen->texture, NULL,
|
|
|
|
frame->data[0], frame->linesize[0],
|
|
|
|
frame->data[1], frame->linesize[1],
|
|
|
|
frame->data[2], frame->linesize[2]);
|
|
|
|
}
|
|
|
|
|
2019-03-02 22:52:22 +00:00
|
|
|
bool
|
2019-03-02 19:09:56 +00:00
|
|
|
screen_update_frame(struct screen *screen, struct video_buffer *vb) {
|
2019-03-02 14:16:55 +00:00
|
|
|
mutex_lock(vb->mutex);
|
|
|
|
const AVFrame *frame = video_buffer_consume_rendered_frame(vb);
|
2018-02-08 10:14:13 +00:00
|
|
|
struct size new_frame_size = {frame->width, frame->height};
|
|
|
|
if (!prepare_for_frame(screen, new_frame_size)) {
|
2019-03-02 14:16:55 +00:00
|
|
|
mutex_unlock(vb->mutex);
|
2019-03-02 22:52:22 +00:00
|
|
|
return false;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
update_texture(screen, frame);
|
2019-03-02 14:16:55 +00:00
|
|
|
mutex_unlock(vb->mutex);
|
2018-02-09 10:14:47 +00:00
|
|
|
|
|
|
|
screen_render(screen);
|
2019-03-02 22:52:22 +00:00
|
|
|
return true;
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
screen_render(struct screen *screen) {
|
2018-02-08 10:14:13 +00:00
|
|
|
SDL_RenderClear(screen->renderer);
|
Improve startup time
On startup, the client has to:
1. listen on a port
2. push and start the server to the device
3. wait for the server to connect (accept)
4. read device name and size
5. initialize SDL
6. initialize the window and renderer
7. show the window
From the execution of the app_process command to start the server on the
device, to the execution of the java main method, it takes ~800ms. As a
consequence, step 3 also takes ~800ms on the client.
Once complete, the client initializes SDL, which takes ~500ms.
These two expensive actions are executed sequentially:
HOST DEVICE
listen on port | |
push/start the server |----------------->|| app_process loads the jar
accept the connection . ^ ||
. | ||
. | WASTE ||
. | OF ||
. | TIME ||
. | ||
. | ||
. v X execution of our java main
connection accepted |<-----------------| connect to the host
init SDL || |
|| ,----------------| send frames
|| |,---------------|
|| ||,--------------|
|| |||,-------------|
|| ||||,------------|
init window/renderer | |||||,-----------|
display frames |<++++++-----------|
(many frames skipped)
The rationale for step 3 occuring before step 5 is that initializing
SDL replaces the SIGTERM handler to receive the event in the event loop,
so pressing Ctrl+C during step 5 would not work (since it blocks the
event loop).
But this is not so important; let's parallelize the SDL initialization
with the app_process execution (we'll just add a timeout to the
connection):
HOST DEVICE
listen on port | |
push/start the server |----------------->||app_process loads the jar
init SDL || ||
|| ||
|| ||
|| ||
|| ||
|| ||
accept the connection . ||
. X execution of our java main
connection accepted |<-----------------| connect to the host
init window/renderer | |
display frames |<-----------------| send frames
|<-----------------|
In addition, show the window only once the first frame is available to
avoid flickering (opening a black window for 100~200ms).
Note: the window and renderer are initialized after the connection is
accepted because they use the device information received from the
device.
2018-02-09 12:50:54 +00:00
|
|
|
SDL_RenderCopy(screen->renderer, screen->texture, NULL, NULL);
|
2018-02-08 10:14:13 +00:00
|
|
|
SDL_RenderPresent(screen->renderer);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
screen_switch_fullscreen(struct screen *screen) {
|
2018-02-08 10:14:13 +00:00
|
|
|
if (!screen->fullscreen) {
|
|
|
|
// going to fullscreen, store the current windowed window size
|
|
|
|
screen->windowed_window_size = get_native_window_size(screen->window);
|
|
|
|
}
|
2019-03-02 22:52:22 +00:00
|
|
|
uint32_t new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
2018-02-08 10:14:13 +00:00
|
|
|
if (SDL_SetWindowFullscreen(screen->window, new_mode)) {
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGW("Could not switch fullscreen mode: %s", SDL_GetError());
|
2018-02-08 10:14:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen->fullscreen = !screen->fullscreen;
|
|
|
|
if (!screen->fullscreen) {
|
|
|
|
// fullscreen disabled, restore expected windowed window size
|
2019-03-02 19:09:56 +00:00
|
|
|
SDL_SetWindowSize(screen->window, screen->windowed_window_size.width,
|
|
|
|
screen->windowed_window_size.height);
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGD("Switched to %s mode", screen->fullscreen ? "fullscreen" : "windowed");
|
2018-02-08 10:14:13 +00:00
|
|
|
screen_render(screen);
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
screen_resize_to_fit(struct screen *screen) {
|
2018-02-08 10:14:13 +00:00
|
|
|
if (!screen->fullscreen) {
|
2019-03-02 19:09:56 +00:00
|
|
|
struct size optimal_size = get_optimal_window_size(screen,
|
|
|
|
screen->frame_size);
|
|
|
|
SDL_SetWindowSize(screen->window, optimal_size.width,
|
|
|
|
optimal_size.height);
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGD("Resized to optimal size");
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
void
|
|
|
|
screen_resize_to_pixel_perfect(struct screen *screen) {
|
2018-02-08 10:14:13 +00:00
|
|
|
if (!screen->fullscreen) {
|
2019-03-02 19:09:56 +00:00
|
|
|
SDL_SetWindowSize(screen->window, screen->frame_size.width,
|
|
|
|
screen->frame_size.height);
|
2018-02-13 09:10:18 +00:00
|
|
|
LOGD("Resized to pixel-perfect");
|
2018-02-08 10:14:13 +00:00
|
|
|
}
|
|
|
|
}
|