Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
surface: make pending and current embedded structs
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jun 28, 2018
1 parent c2fb6d3 commit ac30d04
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 134 deletions.
12 changes: 9 additions & 3 deletions include/wlr/types/wlr_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ struct wlr_surface_state {
uint32_t committed; // enum wlr_surface_state_field

struct wl_resource *buffer;
struct wl_listener buffer_destroy_listener;
int32_t sx, sy;
pixman_region32_t surface_damage, buffer_damage;
pixman_region32_t opaque, input;
Expand All @@ -33,6 +32,8 @@ struct wlr_surface_state {

int width, height; // in surface-local coordinates
int buffer_width, buffer_height;

struct wl_listener buffer_destroy_listener;
};

struct wlr_surface {
Expand All @@ -45,7 +46,12 @@ struct wlr_surface {
* or something went wrong with uploading the buffer.
*/
struct wlr_buffer *buffer;
struct wlr_surface_state *current, *pending;
/**
* `current` contains the current, committed surface state. `pending`
* accumulates state changes from the client between commits and shouldn't
* be accessed by the compositor directly.
*/
struct wlr_surface_state current, pending;
const char *role; // the lifetime-bound role or null

struct {
Expand Down Expand Up @@ -79,7 +85,7 @@ struct wlr_subsurface {

struct wlr_subsurface_state current, pending;

struct wlr_surface_state *cached;
struct wlr_surface_state cached;
bool has_cache;

bool synchronized;
Expand Down
8 changes: 4 additions & 4 deletions rootston/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ static void roots_cursor_update_position(
case ROOTS_CURSOR_ROTATE:
view = roots_seat_get_focus(seat);
if (view != NULL) {
int ox = view->x + view->wlr_surface->current->width/2,
oy = view->y + view->wlr_surface->current->height/2;
int ox = view->x + view->wlr_surface->current.width/2,
oy = view->y + view->wlr_surface->current.height/2;
int ux = cursor->offs_x - ox,
uy = cursor->offs_y - oy;
int vx = cursor->cursor->x - ox,
Expand Down Expand Up @@ -239,12 +239,12 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
break;
case BTN_RIGHT:
edges = 0;
if (sx < view->wlr_surface->current->width/2) {
if (sx < view->wlr_surface->current.width/2) {
edges |= WLR_EDGE_LEFT;
} else {
edges |= WLR_EDGE_RIGHT;
}
if (sy < view->wlr_surface->current->height/2) {
if (sy < view->wlr_surface->current.height/2) {
edges |= WLR_EDGE_TOP;
} else {
edges |= WLR_EDGE_BOTTOM;
Expand Down
6 changes: 3 additions & 3 deletions rootston/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx,
return ROOTS_DECO_PART_NONE;
}

int sw = view->wlr_surface->current->width;
int sh = view->wlr_surface->current->height;
int sw = view->wlr_surface->current.width;
int sh = view->wlr_surface->current.height;
int bw = view->border_width;
int titlebar_h = view->titlebar_height;

Expand Down Expand Up @@ -558,7 +558,7 @@ static bool view_at(struct roots_view *view, double lx, double ly,
double view_sx = lx - view->x;
double view_sy = ly - view->y;

struct wlr_surface_state *state = view->wlr_surface->current;
struct wlr_surface_state *state = &view->wlr_surface->current;
struct wlr_box box = {
.x = 0, .y = 0,
.width = state->width, .height = state->height,
Expand Down
30 changes: 15 additions & 15 deletions rootston/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct layout_data {
static void get_layout_position(struct layout_data *data, double *lx, double *ly,
const struct wlr_surface *surface, int sx, int sy) {
double _sx = sx, _sy = sy;
rotate_child_position(&_sx, &_sy, surface->current->width,
surface->current->height, data->width, data->height, data->rotation);
rotate_child_position(&_sx, &_sy, surface->current.width,
surface->current.height, data->width, data->height, data->rotation);
*lx = data->x + _sx;
*ly = data->y + _sy;
}
Expand All @@ -55,8 +55,8 @@ static void surface_for_each_surface(struct wlr_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data) {
layout_data->x = lx;
layout_data->y = ly;
layout_data->width = surface->current->width;
layout_data->height = surface->current->height;
layout_data->width = surface->current.width;
layout_data->height = surface->current.height;
layout_data->rotation = rotation;

wlr_surface_for_each_surface(surface, iterator, user_data);
Expand All @@ -67,8 +67,8 @@ static void view_for_each_surface(struct roots_view *view,
void *user_data) {
layout_data->x = view->x;
layout_data->y = view->y;
layout_data->width = view->wlr_surface->current->width;
layout_data->height = view->wlr_surface->current->height;
layout_data->width = view->wlr_surface->current.width;
layout_data->height = view->wlr_surface->current.height;
layout_data->rotation = view->rotation;

switch (view->type) {
Expand Down Expand Up @@ -149,13 +149,13 @@ static bool surface_intersect_output(struct wlr_surface *surface,
if (box != NULL) {
box->x = ox * wlr_output->scale;
box->y = oy * wlr_output->scale;
box->width = surface->current->width * wlr_output->scale;
box->height = surface->current->height * wlr_output->scale;
box->width = surface->current.width * wlr_output->scale;
box->height = surface->current.height * wlr_output->scale;
}

struct wlr_box layout_box = {
.x = lx, .y = ly,
.width = surface->current->width, .height = surface->current->height,
.width = surface->current.width, .height = surface->current.height,
};
wlr_box_rotated_bounds(&layout_box, rotation, &layout_box);
return wlr_output_layout_intersects(output_layout, wlr_output, &layout_box);
Expand Down Expand Up @@ -223,7 +223,7 @@ static void render_surface(struct wlr_surface *surface, int sx, int sy,

float matrix[9];
enum wl_output_transform transform =
wlr_output_transform_invert(surface->current->transform);
wlr_output_transform_invert(surface->current.transform);
wlr_matrix_project_box(matrix, &box, transform, rotation,
output->wlr_output->transform_matrix);

Expand All @@ -247,8 +247,8 @@ static void get_decoration_box(struct roots_view *view,
double sx = deco_box.x - view->x;
double sy = deco_box.y - view->y;
rotate_child_position(&sx, &sy, deco_box.width, deco_box.height,
view->wlr_surface->current->width,
view->wlr_surface->current->height, view->rotation);
view->wlr_surface->current.width,
view->wlr_surface->current.height, view->rotation);
double x = sx + view->x;
double y = sy + view->y;

Expand Down Expand Up @@ -687,13 +687,13 @@ static void damage_from_surface(struct wlr_surface *surface, int sx, int sy,

pixman_region32_t damage;
pixman_region32_init(&damage);
pixman_region32_copy(&damage, &surface->current->surface_damage);
pixman_region32_copy(&damage, &surface->current.surface_damage);
wlr_region_scale(&damage, &damage, wlr_output->scale);
if (ceil(wlr_output->scale) > surface->current->scale) {
if (ceil(wlr_output->scale) > surface->current.scale) {
// When scaling up a surface, it'll become blurry so we need to
// expand the damage region
wlr_region_expand(&damage, &damage,
ceil(wlr_output->scale) - surface->current->scale);
ceil(wlr_output->scale) - surface->current.scale);
}
pixman_region32_translate(&damage, box.x, box.y);
wlr_region_rotated_bounds(&damage, &damage, rotation, center_x, center_y);
Expand Down
8 changes: 4 additions & 4 deletions rootston/wl_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {

view_apply_damage(view);

int width = wlr_surface->current->width;
int height = wlr_surface->current->height;
int width = wlr_surface->current.width;
int height = wlr_surface->current.height;
view_update_size(view, width, height);

double x = view->x;
Expand Down Expand Up @@ -236,8 +236,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
return;
}
view->type = ROOTS_WL_SHELL_VIEW;
view->width = surface->surface->current->width;
view->height = surface->surface->current->height;
view->width = surface->surface->current.width;
view->height = surface->surface->current.height;

view->wl_shell_surface = surface;
view->roots_wl_shell_surface = roots_surface;
Expand Down
8 changes: 4 additions & 4 deletions rootston/xwayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {

view_apply_damage(view);

int width = wlr_surface->current->width;
int height = wlr_surface->current->height;
int width = wlr_surface->current.width;
int height = wlr_surface->current.height;
view_update_size(view, width, height);

double x = view->x;
Expand All @@ -233,8 +233,8 @@ static void handle_map(struct wl_listener *listener, void *data) {

view->x = surface->x;
view->y = surface->y;
view->width = surface->surface->current->width;
view->height = surface->surface->current->height;
view->width = surface->surface->current.width;
view->height = surface->surface->current.height;

roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit,
Expand Down
4 changes: 2 additions & 2 deletions types/data_device/wlr_drag.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ static void drag_icon_handle_surface_destroy(struct wl_listener *listener,
static void drag_icon_handle_surface_commit(struct wlr_surface *surface,
void *role_data) {
struct wlr_drag_icon *icon = role_data;
icon->sx += icon->surface->current->sx;
icon->sy += icon->surface->current->sy;
icon->sx += icon->surface->current.sx;
icon->sy += icon->surface->current.sy;

drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface));
}
Expand Down
32 changes: 16 additions & 16 deletions types/wlr_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ static void output_fullscreen_surface_get_box(struct wlr_output *output,
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 x = (width - surface->current.width) / 2;
int y = (height - surface->current.height) / 2;

box->x = x * output->scale;
box->y = y * output->scale;
box->width = surface->current->width * output->scale;
box->height = surface->current->height * output->scale;
box->width = surface->current.width * output->scale;
box->height = surface->current.height * output->scale;
}

static void output_fullscreen_surface_render(struct wlr_output *output,
Expand All @@ -378,7 +378,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output,

float matrix[9];
enum wl_output_transform transform =
wlr_output_transform_invert(surface->current->transform);
wlr_output_transform_invert(surface->current.transform);
wlr_matrix_project_box(matrix, &box, transform, 0,
output->transform_matrix);

Expand All @@ -405,8 +405,8 @@ static void output_cursor_get_box(struct wlr_output_cursor *cursor,
box->height = cursor->height;

if (cursor->surface != NULL) {
box->x += cursor->surface->current->sx * cursor->output->scale;
box->y += cursor->surface->current->sy * cursor->output->scale;
box->x += cursor->surface->current.sx * cursor->output->scale;
box->y += cursor->surface->current.sy * cursor->output->scale;
}
}

Expand Down Expand Up @@ -602,10 +602,10 @@ static void output_fullscreen_surface_handle_commit(
fullscreen_surface_commit);
struct wlr_surface *surface = output->fullscreen_surface;

if (output->fullscreen_width != surface->current->width ||
output->fullscreen_height != surface->current->height) {
output->fullscreen_width = surface->current->width;
output->fullscreen_height = surface->current->height;
if (output->fullscreen_width != surface->current.width ||
output->fullscreen_height != surface->current.height) {
output->fullscreen_width = surface->current.width;
output->fullscreen_height = surface->current.height;
wlr_output_damage_whole(output);
return;
}
Expand All @@ -615,7 +615,7 @@ static void output_fullscreen_surface_handle_commit(

pixman_region32_t damage;
pixman_region32_init(&damage);
pixman_region32_copy(&damage, &surface->current->surface_damage);
pixman_region32_copy(&damage, &surface->current.surface_damage);
wlr_region_scale(&damage, &damage, output->scale);
pixman_region32_translate(&damage, box.x, box.y);
pixman_region32_union(&output->damage, &output->damage, &damage);
Expand Down Expand Up @@ -714,8 +714,8 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) {
struct wlr_texture *texture = cursor->texture;
if (cursor->surface != NULL) {
texture = wlr_surface_get_texture(cursor->surface);
scale = cursor->surface->current->scale;
transform = cursor->surface->current->transform;
scale = cursor->surface->current.scale;
transform = cursor->surface->current.transform;
}

struct wlr_output_cursor *hwcur = cursor->output->hardware_cursor;
Expand Down Expand Up @@ -778,8 +778,8 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor) {

// Some clients commit a cursor surface with a NULL buffer to hide it.
cursor->enabled = wlr_surface_has_buffer(cursor->surface);
cursor->width = cursor->surface->current->width * cursor->output->scale;
cursor->height = cursor->surface->current->height * cursor->output->scale;
cursor->width = cursor->surface->current.width * cursor->output->scale;
cursor->height = cursor->surface->current.height * cursor->output->scale;

if (output_cursor_attempt_hardware(cursor)) {
struct timespec now;
Expand Down
Loading

0 comments on commit ac30d04

Please sign in to comment.