mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-04-21 01:33:36 +00:00
Expose specific resize_display() control
Store resize display events separately so that only the most recent pending value is sent.
This commit is contained in:
parent
5b8025cb96
commit
fcdd3091ae
2 changed files with 49 additions and 2 deletions
|
|
@ -59,6 +59,9 @@ sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
|||
controller->control_socket = control_socket;
|
||||
controller->stopped = false;
|
||||
|
||||
controller->resize_display.width = 0;
|
||||
controller->resize_display.height = 0;
|
||||
|
||||
assert(cbs && cbs->on_ended);
|
||||
controller->cbs = cbs;
|
||||
controller->cbs_userdata = cbs_userdata;
|
||||
|
|
@ -92,6 +95,9 @@ sc_controller_destroy(struct sc_controller *controller) {
|
|||
bool
|
||||
sc_controller_push_msg(struct sc_controller *controller,
|
||||
const struct sc_control_msg *msg) {
|
||||
// RESIZE_DISPLAY messages are handled separately
|
||||
assert(msg->type != SC_CONTROL_MSG_TYPE_RESIZE_DISPLAY);
|
||||
|
||||
bool pushed = false;
|
||||
|
||||
sc_mutex_lock(&controller->mutex);
|
||||
|
|
@ -119,6 +125,20 @@ sc_controller_push_msg(struct sc_controller *controller,
|
|||
return pushed;
|
||||
}
|
||||
|
||||
void
|
||||
sc_controller_resize_display(struct sc_controller *controller,
|
||||
uint16_t width, uint16_t height) {
|
||||
assert(width && height);
|
||||
sc_mutex_lock(&controller->mutex);
|
||||
bool was_set = controller->resize_display.width;
|
||||
controller->resize_display.width = width;
|
||||
controller->resize_display.height = height;
|
||||
if (!was_set) {
|
||||
sc_cond_signal(&controller->msg_cond);
|
||||
}
|
||||
sc_mutex_unlock(&controller->mutex);
|
||||
}
|
||||
|
||||
static bool
|
||||
process_msg(struct sc_controller *controller,
|
||||
const struct sc_control_msg *msg, bool *eos) {
|
||||
|
|
@ -148,6 +168,7 @@ run_controller(void *data) {
|
|||
for (;;) {
|
||||
sc_mutex_lock(&controller->mutex);
|
||||
while (!controller->stopped
|
||||
&& !controller->resize_display.width
|
||||
&& sc_vecdeque_is_empty(&controller->queue)) {
|
||||
sc_cond_wait(&controller->msg_cond, &controller->mutex);
|
||||
}
|
||||
|
|
@ -158,8 +179,20 @@ run_controller(void *data) {
|
|||
break;
|
||||
}
|
||||
|
||||
assert(!sc_vecdeque_is_empty(&controller->queue));
|
||||
struct sc_control_msg msg = sc_vecdeque_pop(&controller->queue);
|
||||
bool has_resize_display = controller->resize_display.width;
|
||||
assert(has_resize_display || !sc_vecdeque_is_empty(&controller->queue));
|
||||
|
||||
struct sc_control_msg msg;
|
||||
|
||||
if (has_resize_display) {
|
||||
msg.type = SC_CONTROL_MSG_TYPE_RESIZE_DISPLAY;
|
||||
msg.resize_display.width = controller->resize_display.width;
|
||||
msg.resize_display.height = controller->resize_display.height;
|
||||
controller->resize_display.width = 0;
|
||||
controller->resize_display.height = 0;
|
||||
} else {
|
||||
msg = sc_vecdeque_pop(&controller->queue);
|
||||
}
|
||||
sc_mutex_unlock(&controller->mutex);
|
||||
|
||||
if (sc_get_log_level() <= SC_LOG_LEVEL_VERBOSE) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,17 @@ struct sc_controller {
|
|||
sc_mutex mutex;
|
||||
sc_cond msg_cond;
|
||||
bool stopped;
|
||||
|
||||
struct sc_control_msg_queue queue;
|
||||
|
||||
// The RESIZE_DISPLAY control message is never enqueued, it has top priority
|
||||
// and a new request overwrites any previous one
|
||||
struct {
|
||||
// enabled if width != 0
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
} resize_display;
|
||||
|
||||
struct sc_receiver receiver;
|
||||
|
||||
const struct sc_controller_callbacks *cbs;
|
||||
|
|
@ -58,4 +68,8 @@ bool
|
|||
sc_controller_push_msg(struct sc_controller *controller,
|
||||
const struct sc_control_msg *msg);
|
||||
|
||||
void
|
||||
sc_controller_resize_display(struct sc_controller *controller,
|
||||
uint16_t width, uint16_t height);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue