Use sc_ prefix for size, position and point
This commit is contained in:
parent
db484d82db
commit
4c4381de4c
14 changed files with 75 additions and 73 deletions
|
@ -56,7 +56,7 @@ static const char *const screen_power_mode_labels[] = {
|
|||
};
|
||||
|
||||
static void
|
||||
write_position(uint8_t *buf, const struct position *position) {
|
||||
write_position(uint8_t *buf, const struct sc_position *position) {
|
||||
buffer_write32be(&buf[0], position->point.x);
|
||||
buffer_write32be(&buf[4], position->point.y);
|
||||
buffer_write16be(&buf[8], position->screen_size.width);
|
||||
|
|
|
@ -57,11 +57,11 @@ struct control_msg {
|
|||
enum android_motionevent_action action;
|
||||
enum android_motionevent_buttons buttons;
|
||||
uint64_t pointer_id;
|
||||
struct position position;
|
||||
struct sc_position position;
|
||||
float pressure;
|
||||
} inject_touch_event;
|
||||
struct {
|
||||
struct position position;
|
||||
struct sc_position position;
|
||||
int32_t hscroll;
|
||||
int32_t vscroll;
|
||||
} inject_scroll_event;
|
||||
|
|
|
@ -3,22 +3,22 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
struct size {
|
||||
struct sc_size {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
};
|
||||
|
||||
struct point {
|
||||
struct sc_point {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
|
||||
struct position {
|
||||
struct sc_position {
|
||||
// The video screen size may be different from the real device screen size,
|
||||
// so store to which size the absolute position apply, to scale it
|
||||
// accordingly.
|
||||
struct size screen_size;
|
||||
struct point point;
|
||||
struct sc_size screen_size;
|
||||
struct sc_point point;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -332,7 +332,7 @@ input_manager_process_text_input(struct input_manager *im,
|
|||
static bool
|
||||
simulate_virtual_finger(struct input_manager *im,
|
||||
enum android_motionevent_action action,
|
||||
struct point point) {
|
||||
struct sc_point point) {
|
||||
bool up = action == AMOTION_EVENT_ACTION_UP;
|
||||
|
||||
struct control_msg msg;
|
||||
|
@ -352,8 +352,8 @@ simulate_virtual_finger(struct input_manager *im,
|
|||
return true;
|
||||
}
|
||||
|
||||
static struct point
|
||||
inverse_point(struct point point, struct size size) {
|
||||
static struct sc_point
|
||||
inverse_point(struct sc_point point, struct sc_size size) {
|
||||
point.x = size.width - point.x;
|
||||
point.y = size.height - point.y;
|
||||
return point;
|
||||
|
@ -545,10 +545,10 @@ input_manager_process_mouse_motion(struct input_manager *im,
|
|||
im->mp->ops->process_mouse_motion(im->mp, event);
|
||||
|
||||
if (im->vfinger_down) {
|
||||
struct point mouse =
|
||||
struct sc_point mouse =
|
||||
screen_convert_window_to_frame_coords(im->screen, event->x,
|
||||
event->y);
|
||||
struct point vfinger = inverse_point(mouse, im->screen->frame_size);
|
||||
struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size);
|
||||
simulate_virtual_finger(im, AMOTION_EVENT_ACTION_MOVE, vfinger);
|
||||
}
|
||||
}
|
||||
|
@ -630,10 +630,10 @@ input_manager_process_mouse_button(struct input_manager *im,
|
|||
#define CTRL_PRESSED (SDL_GetModState() & (KMOD_LCTRL | KMOD_RCTRL))
|
||||
if ((down && !im->vfinger_down && CTRL_PRESSED)
|
||||
|| (!down && im->vfinger_down)) {
|
||||
struct point mouse =
|
||||
struct sc_point mouse =
|
||||
screen_convert_window_to_frame_coords(im->screen, event->x,
|
||||
event->y);
|
||||
struct point vfinger = inverse_point(mouse, im->screen->frame_size);
|
||||
struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size);
|
||||
enum android_motionevent_action action = down
|
||||
? AMOTION_EVENT_ACTION_DOWN
|
||||
: AMOTION_EVENT_ACTION_UP;
|
||||
|
|
|
@ -125,7 +125,7 @@ convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct screen *screen,
|
|||
int mouse_y;
|
||||
SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
|
||||
struct position position = {
|
||||
struct sc_position position = {
|
||||
.screen_size = screen->frame_size,
|
||||
.point = screen_convert_window_to_frame_coords(screen,
|
||||
mouse_x, mouse_y),
|
||||
|
|
|
@ -372,7 +372,7 @@ bool
|
|||
recorder_init(struct recorder *recorder,
|
||||
const char *filename,
|
||||
enum sc_record_format format,
|
||||
struct size declared_frame_size) {
|
||||
struct sc_size declared_frame_size) {
|
||||
recorder->filename = strdup(filename);
|
||||
if (!recorder->filename) {
|
||||
LOGE("Could not strdup filename");
|
||||
|
|
|
@ -25,7 +25,7 @@ struct recorder {
|
|||
char *filename;
|
||||
enum sc_record_format format;
|
||||
AVFormatContext *ctx;
|
||||
struct size declared_frame_size;
|
||||
struct sc_size declared_frame_size;
|
||||
bool header_written;
|
||||
|
||||
sc_thread thread;
|
||||
|
@ -44,7 +44,7 @@ struct recorder {
|
|||
|
||||
bool
|
||||
recorder_init(struct recorder *recorder, const char *filename,
|
||||
enum sc_record_format format, struct size declared_frame_size);
|
||||
enum sc_record_format format, struct sc_size declared_frame_size);
|
||||
|
||||
void
|
||||
recorder_destroy(struct recorder *recorder);
|
||||
|
|
|
@ -309,7 +309,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||
}
|
||||
|
||||
char device_name[DEVICE_NAME_FIELD_LENGTH];
|
||||
struct size frame_size;
|
||||
struct sc_size frame_size;
|
||||
|
||||
if (!server_connect_to(&s->server, device_name, &frame_size)) {
|
||||
goto end;
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
#define DOWNCAST(SINK) container_of(SINK, struct screen, frame_sink)
|
||||
|
||||
static inline struct size
|
||||
get_rotated_size(struct size size, int rotation) {
|
||||
struct size rotated_size;
|
||||
static inline struct sc_size
|
||||
get_rotated_size(struct sc_size size, int rotation) {
|
||||
struct sc_size rotated_size;
|
||||
if (rotation & 1) {
|
||||
rotated_size.width = size.height;
|
||||
rotated_size.height = size.width;
|
||||
|
@ -27,26 +27,26 @@ get_rotated_size(struct size size, int rotation) {
|
|||
return rotated_size;
|
||||
}
|
||||
|
||||
// get the window size in a struct size
|
||||
static struct size
|
||||
// get the window size in a struct sc_size
|
||||
static struct sc_size
|
||||
get_window_size(const struct screen *screen) {
|
||||
int width;
|
||||
int height;
|
||||
SDL_GetWindowSize(screen->window, &width, &height);
|
||||
|
||||
struct size size;
|
||||
struct sc_size size;
|
||||
size.width = width;
|
||||
size.height = height;
|
||||
return size;
|
||||
}
|
||||
|
||||
static struct point
|
||||
static struct sc_point
|
||||
get_window_position(const struct screen *screen) {
|
||||
int x;
|
||||
int y;
|
||||
SDL_GetWindowPosition(screen->window, &x, &y);
|
||||
|
||||
struct point point;
|
||||
struct sc_point point;
|
||||
point.x = x;
|
||||
point.y = y;
|
||||
return point;
|
||||
|
@ -54,7 +54,7 @@ get_window_position(const struct screen *screen) {
|
|||
|
||||
// set the window size to be applied when fullscreen is disabled
|
||||
static void
|
||||
set_window_size(struct screen *screen, struct size new_size) {
|
||||
set_window_size(struct screen *screen, struct sc_size new_size) {
|
||||
assert(!screen->fullscreen);
|
||||
assert(!screen->maximized);
|
||||
SDL_SetWindowSize(screen->window, new_size.width, new_size.height);
|
||||
|
@ -62,7 +62,7 @@ set_window_size(struct screen *screen, struct size new_size) {
|
|||
|
||||
// get the preferred display bounds (i.e. the screen bounds with some margins)
|
||||
static bool
|
||||
get_preferred_display_bounds(struct size *bounds) {
|
||||
get_preferred_display_bounds(struct sc_size *bounds) {
|
||||
SDL_Rect rect;
|
||||
#ifdef SCRCPY_SDL_HAS_GET_DISPLAY_USABLE_BOUNDS
|
||||
# define GET_DISPLAY_BOUNDS(i, r) SDL_GetDisplayUsableBounds((i), (r))
|
||||
|
@ -80,7 +80,7 @@ get_preferred_display_bounds(struct size *bounds) {
|
|||
}
|
||||
|
||||
static bool
|
||||
is_optimal_size(struct size current_size, struct size content_size) {
|
||||
is_optimal_size(struct sc_size current_size, struct sc_size content_size) {
|
||||
// The size is optimal if we can recompute one dimension of the current
|
||||
// size from the other
|
||||
return current_size.height == current_size.width * content_size.height
|
||||
|
@ -94,16 +94,16 @@ is_optimal_size(struct size current_size, struct size content_size) {
|
|||
// crops the black borders)
|
||||
// - it keeps the aspect ratio
|
||||
// - it scales down to make it fit in the display_size
|
||||
static struct size
|
||||
get_optimal_size(struct size current_size, struct size content_size) {
|
||||
static struct sc_size
|
||||
get_optimal_size(struct sc_size current_size, struct sc_size content_size) {
|
||||
if (content_size.width == 0 || content_size.height == 0) {
|
||||
// avoid division by 0
|
||||
return current_size;
|
||||
}
|
||||
|
||||
struct size window_size;
|
||||
struct sc_size window_size;
|
||||
|
||||
struct size display_size;
|
||||
struct sc_size display_size;
|
||||
if (!get_preferred_display_bounds(&display_size)) {
|
||||
// could not get display bounds, do not constraint the size
|
||||
window_size.width = current_size.width;
|
||||
|
@ -135,10 +135,10 @@ get_optimal_size(struct size current_size, struct size content_size) {
|
|||
|
||||
// initially, there is no current size, so use the frame size as current size
|
||||
// req_width and req_height, if not 0, are the sizes requested by the user
|
||||
static inline struct size
|
||||
get_initial_optimal_size(struct size content_size, uint16_t req_width,
|
||||
static inline struct sc_size
|
||||
get_initial_optimal_size(struct sc_size content_size, uint16_t req_width,
|
||||
uint16_t req_height) {
|
||||
struct size window_size;
|
||||
struct sc_size window_size;
|
||||
if (!req_width && !req_height) {
|
||||
window_size = get_optimal_size(content_size, content_size);
|
||||
} else {
|
||||
|
@ -166,9 +166,9 @@ screen_update_content_rect(struct screen *screen) {
|
|||
int dh;
|
||||
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
|
||||
|
||||
struct size content_size = screen->content_size;
|
||||
struct sc_size content_size = screen->content_size;
|
||||
// The drawable size is the window size * the HiDPI scale
|
||||
struct size drawable_size = {dw, dh};
|
||||
struct sc_size drawable_size = {dw, dh};
|
||||
|
||||
SDL_Rect *rect = &screen->rect;
|
||||
|
||||
|
@ -200,7 +200,7 @@ screen_update_content_rect(struct screen *screen) {
|
|||
static inline SDL_Texture *
|
||||
create_texture(struct screen *screen) {
|
||||
SDL_Renderer *renderer = screen->renderer;
|
||||
struct size size = screen->frame_size;
|
||||
struct sc_size size = screen->frame_size;
|
||||
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
size.width, size.height);
|
||||
|
@ -330,13 +330,13 @@ screen_init(struct screen *screen, const struct screen_params *params) {
|
|||
if (screen->rotation) {
|
||||
LOGI("Initial display rotation set to %u", screen->rotation);
|
||||
}
|
||||
struct size content_size =
|
||||
struct sc_size content_size =
|
||||
get_rotated_size(screen->frame_size, screen->rotation);
|
||||
screen->content_size = content_size;
|
||||
|
||||
struct size window_size = get_initial_optimal_size(content_size,
|
||||
params->window_width,
|
||||
params->window_height);
|
||||
struct sc_size window_size =
|
||||
get_initial_optimal_size(content_size,params->window_width,
|
||||
params->window_height);
|
||||
uint32_t window_flags = SDL_WINDOW_HIDDEN
|
||||
| SDL_WINDOW_RESIZABLE
|
||||
| SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
|
@ -508,10 +508,10 @@ screen_destroy(struct screen *screen) {
|
|||
}
|
||||
|
||||
static void
|
||||
resize_for_content(struct screen *screen, struct size old_content_size,
|
||||
struct size new_content_size) {
|
||||
struct size window_size = get_window_size(screen);
|
||||
struct size target_size = {
|
||||
resize_for_content(struct screen *screen, struct sc_size old_content_size,
|
||||
struct sc_size new_content_size) {
|
||||
struct sc_size window_size = get_window_size(screen);
|
||||
struct sc_size target_size = {
|
||||
.width = (uint32_t) window_size.width * new_content_size.width
|
||||
/ old_content_size.width,
|
||||
.height = (uint32_t) window_size.height * new_content_size.height
|
||||
|
@ -522,7 +522,7 @@ resize_for_content(struct screen *screen, struct size old_content_size,
|
|||
}
|
||||
|
||||
static void
|
||||
set_content_size(struct screen *screen, struct size new_content_size) {
|
||||
set_content_size(struct screen *screen, struct sc_size new_content_size) {
|
||||
if (!screen->fullscreen && !screen->maximized) {
|
||||
resize_for_content(screen, screen->content_size, new_content_size);
|
||||
} else if (!screen->resize_pending) {
|
||||
|
@ -553,7 +553,7 @@ screen_set_rotation(struct screen *screen, unsigned rotation) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct size new_content_size =
|
||||
struct sc_size new_content_size =
|
||||
get_rotated_size(screen->frame_size, rotation);
|
||||
|
||||
set_content_size(screen, new_content_size);
|
||||
|
@ -566,7 +566,7 @@ screen_set_rotation(struct screen *screen, unsigned rotation) {
|
|||
|
||||
// recreate the texture and resize the window if the frame size has changed
|
||||
static bool
|
||||
prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
||||
prepare_for_frame(struct screen *screen, struct sc_size new_frame_size) {
|
||||
if (screen->frame_size.width != new_frame_size.width
|
||||
|| screen->frame_size.height != new_frame_size.height) {
|
||||
// frame dimension changed, destroy texture
|
||||
|
@ -574,7 +574,7 @@ prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
|||
|
||||
screen->frame_size = new_frame_size;
|
||||
|
||||
struct size new_content_size =
|
||||
struct sc_size new_content_size =
|
||||
get_rotated_size(new_frame_size, screen->rotation);
|
||||
set_content_size(screen, new_content_size);
|
||||
|
||||
|
@ -615,7 +615,7 @@ screen_update_frame(struct screen *screen) {
|
|||
|
||||
fps_counter_add_rendered_frame(&screen->fps_counter);
|
||||
|
||||
struct 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)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -682,10 +682,10 @@ screen_resize_to_fit(struct screen *screen) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct point point = get_window_position(screen);
|
||||
struct size window_size = get_window_size(screen);
|
||||
struct sc_point point = get_window_position(screen);
|
||||
struct sc_size window_size = get_window_size(screen);
|
||||
|
||||
struct size optimal_size =
|
||||
struct sc_size optimal_size =
|
||||
get_optimal_size(window_size, screen->content_size);
|
||||
|
||||
// Center the window related to the device screen
|
||||
|
@ -711,7 +711,7 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
|||
screen->maximized = false;
|
||||
}
|
||||
|
||||
struct size content_size = screen->content_size;
|
||||
struct sc_size content_size = screen->content_size;
|
||||
SDL_SetWindowSize(screen->window, content_size.width, content_size.height);
|
||||
LOGD("Resized to pixel-perfect: %ux%u", content_size.width,
|
||||
content_size.height);
|
||||
|
@ -766,7 +766,7 @@ screen_handle_event(struct screen *screen, SDL_Event *event) {
|
|||
return false;
|
||||
}
|
||||
|
||||
struct point
|
||||
struct sc_point
|
||||
screen_convert_drawable_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y) {
|
||||
unsigned rotation = screen->rotation;
|
||||
|
@ -780,7 +780,7 @@ screen_convert_drawable_to_frame_coords(struct screen *screen,
|
|||
y = (int64_t) (y - screen->rect.y) * h / screen->rect.h;
|
||||
|
||||
// rotate
|
||||
struct point result;
|
||||
struct sc_point result;
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
result.x = x;
|
||||
|
@ -803,7 +803,7 @@ screen_convert_drawable_to_frame_coords(struct screen *screen,
|
|||
return result;
|
||||
}
|
||||
|
||||
struct point
|
||||
struct sc_point
|
||||
screen_convert_window_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y) {
|
||||
screen_hidpi_scale_coords(screen, &x, &y);
|
||||
|
|
|
@ -27,13 +27,13 @@ struct screen {
|
|||
SDL_Renderer *renderer;
|
||||
SDL_Texture *texture;
|
||||
struct sc_opengl gl;
|
||||
struct size frame_size;
|
||||
struct size content_size; // rotated frame_size
|
||||
struct sc_size frame_size;
|
||||
struct sc_size content_size; // rotated frame_size
|
||||
|
||||
bool resize_pending; // resize requested while fullscreen or maximized
|
||||
// The content size the last time the window was not maximized or
|
||||
// fullscreen (meaningful only when resize_pending is true)
|
||||
struct size windowed_content_size;
|
||||
struct sc_size windowed_content_size;
|
||||
|
||||
// client rotation: 0, 1, 2 or 3 (x90 degrees counterclockwise)
|
||||
unsigned rotation;
|
||||
|
@ -49,7 +49,7 @@ struct screen {
|
|||
|
||||
struct screen_params {
|
||||
const char *window_title;
|
||||
struct size frame_size;
|
||||
struct sc_size frame_size;
|
||||
bool always_on_top;
|
||||
|
||||
int16_t window_x;
|
||||
|
@ -120,13 +120,13 @@ screen_handle_event(struct screen *screen, SDL_Event *event);
|
|||
|
||||
// convert point from window coordinates to frame coordinates
|
||||
// x and y are expressed in pixels
|
||||
struct point
|
||||
struct sc_point
|
||||
screen_convert_window_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y);
|
||||
|
||||
// convert point from drawable coordinates to frame coordinates
|
||||
// x and y are expressed in pixels
|
||||
struct point
|
||||
struct sc_point
|
||||
screen_convert_drawable_to_frame_coords(struct screen *screen,
|
||||
int32_t x, int32_t y);
|
||||
|
||||
|
|
|
@ -427,7 +427,7 @@ error:
|
|||
|
||||
static bool
|
||||
device_read_info(sc_socket device_socket, char *device_name,
|
||||
struct size *size) {
|
||||
struct sc_size *size) {
|
||||
unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];
|
||||
ssize_t r = net_recv_all(device_socket, buf, sizeof(buf));
|
||||
if (r < DEVICE_NAME_FIELD_LENGTH + 4) {
|
||||
|
@ -447,7 +447,8 @@ device_read_info(sc_socket device_socket, char *device_name,
|
|||
}
|
||||
|
||||
bool
|
||||
server_connect_to(struct server *server, char *device_name, struct size *size) {
|
||||
server_connect_to(struct server *server, char *device_name,
|
||||
struct sc_size *size) {
|
||||
if (!server->tunnel_forward) {
|
||||
server->video_socket = net_accept(server->server_socket);
|
||||
if (server->video_socket == SC_INVALID_SOCKET) {
|
||||
|
|
|
@ -62,7 +62,8 @@ server_start(struct server *server, const struct server_params *params);
|
|||
// block until the communication with the server is established
|
||||
// device_name must point to a buffer of at least DEVICE_NAME_FIELD_LENGTH bytes
|
||||
bool
|
||||
server_connect_to(struct server *server, char *device_name, struct size *size);
|
||||
server_connect_to(struct server *server, char *device_name,
|
||||
struct sc_size *size);
|
||||
|
||||
// disconnect and kill the server process
|
||||
void
|
||||
|
|
|
@ -359,7 +359,7 @@ sc_v4l2_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) {
|
|||
|
||||
bool
|
||||
sc_v4l2_sink_init(struct sc_v4l2_sink *vs, const char *device_name,
|
||||
struct size frame_size, sc_tick buffering_time) {
|
||||
struct sc_size frame_size, sc_tick buffering_time) {
|
||||
vs->device_name = strdup(device_name);
|
||||
if (!vs->device_name) {
|
||||
LOGE("Could not strdup v4l2 device name");
|
||||
|
|
|
@ -18,7 +18,7 @@ struct sc_v4l2_sink {
|
|||
AVCodecContext *encoder_ctx;
|
||||
|
||||
char *device_name;
|
||||
struct size frame_size;
|
||||
struct sc_size frame_size;
|
||||
sc_tick buffering_time;
|
||||
|
||||
sc_thread thread;
|
||||
|
@ -34,7 +34,7 @@ struct sc_v4l2_sink {
|
|||
|
||||
bool
|
||||
sc_v4l2_sink_init(struct sc_v4l2_sink *vs, const char *device_name,
|
||||
struct size frame_size, sc_tick buffering_time);
|
||||
struct sc_size frame_size, sc_tick buffering_time);
|
||||
|
||||
void
|
||||
sc_v4l2_sink_destroy(struct sc_v4l2_sink *vs);
|
||||
|
|
Loading…
Reference in a new issue