Merge pull request #437 from emersion/fullscreen

Fullscreen support
This commit is contained in:
Tony Crisci 2017-11-30 03:25:05 -05:00 committed by GitHub
commit 5d7eb438d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 555 additions and 261 deletions

View file

@ -251,6 +251,42 @@ void wlr_output_make_current(struct wlr_output *output) {
output->impl->make_current(output);
}
static void output_fullscreen_surface_render(struct wlr_output *output,
struct wlr_surface *surface, const struct timespec *when) {
int width, height;
wlr_output_effective_resolution(output, &width, &height);
int x = (width - surface->current->width) / 2;
int y = (height - surface->current->height) / 2;
int render_x = x * output->scale;
int render_y = y * output->scale;
int render_width = surface->current->width * output->scale;
int render_height = surface->current->height * output->scale;
glViewport(0, 0, output->width, output->height);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
if (!wlr_surface_has_buffer(surface)) {
return;
}
float translate[16];
wlr_matrix_translate(&translate, render_x, render_y, 0);
float scale[16];
wlr_matrix_scale(&scale, render_width, render_height, 1);
float matrix[16];
wlr_matrix_mul(&translate, &scale, &matrix);
wlr_matrix_mul(&output->transform_matrix, &matrix, &matrix);
wlr_render_with_matrix(surface->renderer, surface->texture, &matrix);
wlr_surface_send_frame_done(surface, when);
}
static void output_cursor_get_box(struct wlr_output_cursor *cursor,
struct wlr_box *box) {
box->x = cursor->x - cursor->hotspot_x;
@ -259,7 +295,8 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor,
box->height = cursor->height;
}
static void output_cursor_render(struct wlr_output_cursor *cursor) {
static void output_cursor_render(struct wlr_output_cursor *cursor,
const struct timespec *when) {
struct wlr_texture *texture = cursor->texture;
struct wlr_renderer *renderer = cursor->renderer;
if (cursor->surface != NULL) {
@ -302,17 +339,29 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) {
wlr_texture_get_matrix(texture, &matrix, &cursor->output->transform_matrix,
x, y);
wlr_render_with_matrix(renderer, texture, &matrix);
if (cursor->surface != NULL) {
wlr_surface_send_frame_done(cursor->surface, when);
}
}
void wlr_output_swap_buffers(struct wlr_output *output) {
wl_signal_emit(&output->events.swap_buffers, &output);
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if (output->fullscreen_surface != NULL) {
output_fullscreen_surface_render(output, output->fullscreen_surface,
&now);
}
struct wlr_output_cursor *cursor;
wl_list_for_each(cursor, &output->cursors, link) {
if (!cursor->enabled || output->hardware_cursor == cursor) {
continue;
}
output_cursor_render(cursor);
output_cursor_render(cursor, &now);
}
output->impl->swap_buffers(output);
@ -333,6 +382,56 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) {
return output->impl->get_gamma_size(output);
}
static void output_fullscreen_surface_reset(struct wlr_output *output) {
if (output->fullscreen_surface != NULL) {
wl_list_remove(&output->fullscreen_surface_commit.link);
wl_list_remove(&output->fullscreen_surface_destroy.link);
output->fullscreen_surface = NULL;
output->needs_swap = true;
}
}
static void output_fullscreen_surface_handle_commit(
struct wl_listener *listener, void *data) {
struct wlr_output *output = wl_container_of(listener, output,
fullscreen_surface_commit);
output->needs_swap = true;
}
static void output_fullscreen_surface_handle_destroy(
struct wl_listener *listener, void *data) {
struct wlr_output *output = wl_container_of(listener, output,
fullscreen_surface_destroy);
output_fullscreen_surface_reset(output);
}
void wlr_output_set_fullscreen_surface(struct wlr_output *output,
struct wlr_surface *surface) {
// TODO: hardware fullscreen
if (output->fullscreen_surface == surface) {
return;
}
output_fullscreen_surface_reset(output);
output->fullscreen_surface = surface;
output->needs_swap = true;
if (surface == NULL) {
return;
}
output->fullscreen_surface_commit.notify =
output_fullscreen_surface_handle_commit;
wl_signal_add(&surface->events.commit, &output->fullscreen_surface_commit);
output->fullscreen_surface_destroy.notify =
output_fullscreen_surface_handle_destroy;
wl_signal_add(&surface->events.destroy,
&output->fullscreen_surface_destroy);
}
static void output_cursor_reset(struct wlr_output_cursor *cursor) {
if (cursor->output->hardware_cursor != cursor) {
cursor->output->needs_swap = true;
@ -404,30 +503,18 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor) {
cursor->output->needs_swap = true;
} else {
// TODO: upload pixels
}
}
static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
wlr_surface_send_frame_done(cursor->surface, &now);
}
}
static void output_cursor_handle_commit(struct wl_listener *listener,
void *data) {
struct wlr_output_cursor *cursor = wl_container_of(listener, cursor,
surface_commit);
struct wlr_surface *surface = data;
output_cursor_commit(cursor);
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list,
link) {
wl_callback_send_done(cb->resource, timespec_to_msec(&now));
wl_resource_destroy(cb->resource);
}
}
static void output_cursor_handle_destroy(struct wl_listener *listener,

View file

@ -929,3 +929,17 @@ void wlr_surface_send_leave(struct wlr_surface *surface,
}
}
}
static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
}
void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when) {
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list,
link) {
wl_callback_send_done(cb->resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource);
}
}

View file

@ -108,25 +108,17 @@ static void shell_surface_protocol_pong(struct wl_client *client,
static void shell_surface_protocol_move(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) {
wlr_log(L_DEBUG, "got shell surface move");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_seat_client *seat =
wl_resource_get_user_data(seat_resource);
struct wlr_wl_shell_surface_move_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_move_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
struct wlr_wl_shell_surface_move_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
};
wl_signal_emit(&surface->events.request_move, event);
free(event);
wl_signal_emit(&surface->events.request_move, &event);
}
static struct wlr_wl_shell_popup_grab *shell_popup_grab_from_seat(
@ -174,26 +166,18 @@ static void shell_surface_destroy_popup_state(
static void shell_surface_protocol_resize(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, enum wl_shell_surface_resize edges) {
wlr_log(L_DEBUG, "got shell surface resize");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_seat_client *seat =
wl_resource_get_user_data(seat_resource);
struct wlr_wl_shell_surface_resize_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_resize_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
event->edges = edges;
struct wlr_wl_shell_surface_resize_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
.edges = edges,
};
wl_signal_emit(&surface->events.request_resize, event);
free(event);
wl_signal_emit(&surface->events.request_resize, &event);
}
static void shell_surface_set_state(struct wlr_wl_shell_surface *surface,
@ -279,7 +263,6 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client,
struct wl_resource *resource,
enum wl_shell_surface_fullscreen_method method, uint32_t framerate,
struct wl_resource *output_resource) {
wlr_log(L_DEBUG, "got shell surface fullscreen");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_output *output = NULL;
if (output_resource != NULL) {
@ -289,24 +272,16 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client,
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_FULLSCREEN,
NULL, NULL);
struct wlr_wl_shell_surface_set_fullscreen_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_set_fullscreen_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->method = method;
event->framerate = framerate;
event->output = output;
struct wlr_wl_shell_surface_set_fullscreen_event event = {
.surface = surface,
.method = method,
.framerate = framerate,
.output = output,
};
wl_signal_emit(&surface->events.request_set_fullscreen, event);
free(event);
wl_signal_emit(&surface->events.request_fullscreen, &event);
}
static void shell_surface_protocol_set_popup(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, struct wl_resource *parent_resource, int32_t x,
@ -368,7 +343,6 @@ static void shell_surface_protocol_set_popup(struct wl_client *client,
static void shell_surface_protocol_set_maximized(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) {
wlr_log(L_DEBUG, "got shell surface maximized");
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_output *output = NULL;
if (output_resource != NULL) {
@ -378,19 +352,12 @@ static void shell_surface_protocol_set_maximized(struct wl_client *client,
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_MAXIMIZED,
NULL, NULL);
struct wlr_wl_shell_surface_set_maximized_event *event =
calloc(1, sizeof(struct wlr_wl_shell_surface_set_maximized_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
event->client = client;
event->surface = surface;
event->output = output;
struct wlr_wl_shell_surface_maximize_event event = {
.surface = surface,
.output = output,
};
wl_signal_emit(&surface->events.request_set_maximized, event);
free(event);
wl_signal_emit(&surface->events.request_maximize, &event);
}
static void shell_surface_protocol_set_title(struct wl_client *client,
@ -545,8 +512,8 @@ static void shell_protocol_get_shell_surface(struct wl_client *client,
wl_signal_init(&wl_surface->events.ping_timeout);
wl_signal_init(&wl_surface->events.request_move);
wl_signal_init(&wl_surface->events.request_resize);
wl_signal_init(&wl_surface->events.request_set_fullscreen);
wl_signal_init(&wl_surface->events.request_set_maximized);
wl_signal_init(&wl_surface->events.request_fullscreen);
wl_signal_init(&wl_surface->events.request_maximize);
wl_signal_init(&wl_surface->events.set_state);
wl_signal_init(&wl_surface->events.set_title);
wl_signal_init(&wl_surface->events.set_class);

View file

@ -564,23 +564,15 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
return;
}
struct wlr_xdg_toplevel_v6_show_window_menu_event *event =
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_show_window_menu_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
struct wlr_xdg_toplevel_v6_show_window_menu_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
.x = x,
.y = y,
};
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
event->x = x;
event->y = y;
wl_signal_emit(&surface->events.request_show_window_menu, event);
free(event);
wl_signal_emit(&surface->events.request_show_window_menu, &event);
}
static void xdg_toplevel_protocol_move(struct wl_client *client,
@ -597,21 +589,13 @@ static void xdg_toplevel_protocol_move(struct wl_client *client,
return;
}
struct wlr_xdg_toplevel_v6_move_event *event =
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_move_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
struct wlr_xdg_toplevel_v6_move_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
};
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
wl_signal_emit(&surface->events.request_move, event);
free(event);
wl_signal_emit(&surface->events.request_move, &event);
}
static void xdg_toplevel_protocol_resize(struct wl_client *client,
@ -628,22 +612,14 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client,
return;
}
struct wlr_xdg_toplevel_v6_resize_event *event =
calloc(1, sizeof(struct wlr_xdg_toplevel_v6_resize_event));
if (event == NULL) {
wl_client_post_no_memory(client);
return;
}
struct wlr_xdg_toplevel_v6_resize_event event = {
.surface = surface,
.seat = seat,
.serial = serial,
.edges = edges,
};
event->client = client;
event->surface = surface;
event->seat = seat;
event->serial = serial;
event->edges = edges;
wl_signal_emit(&surface->events.request_resize, event);
free(event);
wl_signal_emit(&surface->events.request_resize, &event);
}
static void xdg_toplevel_protocol_set_max_size(struct wl_client *client,
@ -677,15 +653,36 @@ static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client,
static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
struct wlr_output *output = NULL;
if (output_resource != NULL) {
output = wl_resource_get_user_data(output_resource);
}
surface->toplevel_state->next.fullscreen = true;
wl_signal_emit(&surface->events.request_fullscreen, surface);
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
.surface = surface,
.fullscreen = true,
.output = output,
};
wl_signal_emit(&surface->events.request_fullscreen, &event);
}
static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
surface->toplevel_state->next.fullscreen = false;
wl_signal_emit(&surface->events.request_fullscreen, surface);
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
.surface = surface,
.fullscreen = false,
.output = NULL,
};
wl_signal_emit(&surface->events.request_fullscreen, &event);
}
static void xdg_toplevel_protocol_set_minimized(struct wl_client *client,