window: move toysurface and allocation to struct surface
Fields 'allocation' and 'server_allocation' are surface specific. Fields 'saved_allocation', 'min_allocation', and 'pending_allocation' are window specific, and will not be moved. Field 'toysurface' is naturally surface specific, since it provides the backing storage for the wl_surface. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
4e37374875
commit
811ec4ff31
+60
-40
@@ -193,6 +193,10 @@ struct surface {
|
|||||||
struct window *window;
|
struct window *window;
|
||||||
|
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
|
struct toysurface *toysurface;
|
||||||
|
|
||||||
|
struct rectangle allocation;
|
||||||
|
struct rectangle server_allocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct window {
|
struct window {
|
||||||
@@ -202,7 +206,7 @@ struct window {
|
|||||||
struct wl_region *input_region;
|
struct wl_region *input_region;
|
||||||
struct wl_region *opaque_region;
|
struct wl_region *opaque_region;
|
||||||
char *title;
|
char *title;
|
||||||
struct rectangle allocation, saved_allocation, server_allocation;
|
struct rectangle saved_allocation;
|
||||||
struct rectangle min_allocation;
|
struct rectangle min_allocation;
|
||||||
struct rectangle pending_allocation;
|
struct rectangle pending_allocation;
|
||||||
int x, y;
|
int x, y;
|
||||||
@@ -217,7 +221,6 @@ struct window {
|
|||||||
|
|
||||||
enum window_buffer_type buffer_type;
|
enum window_buffer_type buffer_type;
|
||||||
enum wl_output_transform buffer_transform;
|
enum wl_output_transform buffer_transform;
|
||||||
struct toysurface *toysurface;
|
|
||||||
cairo_surface_t *cairo_surface;
|
cairo_surface_t *cairo_surface;
|
||||||
|
|
||||||
int resizing;
|
int resizing;
|
||||||
@@ -1143,20 +1146,30 @@ display_get_pointer_image(struct display *display, int pointer)
|
|||||||
static void
|
static void
|
||||||
window_get_resize_dx_dy(struct window *window, int *x, int *y)
|
window_get_resize_dx_dy(struct window *window, int *x, int *y)
|
||||||
{
|
{
|
||||||
|
struct surface *surface = window->main_surface;
|
||||||
|
|
||||||
if (window->resize_edges & WINDOW_RESIZING_LEFT)
|
if (window->resize_edges & WINDOW_RESIZING_LEFT)
|
||||||
*x = window->server_allocation.width - window->allocation.width;
|
*x = surface->server_allocation.width -
|
||||||
|
surface->allocation.width;
|
||||||
else
|
else
|
||||||
*x = 0;
|
*x = 0;
|
||||||
|
|
||||||
if (window->resize_edges & WINDOW_RESIZING_TOP)
|
if (window->resize_edges & WINDOW_RESIZING_TOP)
|
||||||
*y = window->server_allocation.height -
|
*y = surface->server_allocation.height -
|
||||||
window->allocation.height;
|
surface->allocation.height;
|
||||||
else
|
else
|
||||||
*y = 0;
|
*y = 0;
|
||||||
|
|
||||||
window->resize_edges = 0;
|
window->resize_edges = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
surface_attach_surface(struct surface *surface)
|
||||||
|
{
|
||||||
|
surface->toysurface->swap(surface->toysurface,
|
||||||
|
&surface->server_allocation);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_attach_surface(struct window *window)
|
window_attach_surface(struct window *window)
|
||||||
{
|
{
|
||||||
@@ -1182,8 +1195,7 @@ window_attach_surface(struct window *window)
|
|||||||
window->input_region = NULL;
|
window->input_region = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->toysurface->swap(window->toysurface,
|
surface_attach_surface(window->main_surface);
|
||||||
&window->server_allocation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -1212,7 +1224,8 @@ window_get_display(struct window *window)
|
|||||||
static void
|
static void
|
||||||
window_create_surface(struct window *window)
|
window_create_surface(struct window *window)
|
||||||
{
|
{
|
||||||
struct rectangle allocation = window->allocation;
|
struct surface *surface = window->main_surface;
|
||||||
|
struct rectangle allocation = surface->allocation;
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
int dx, dy;
|
int dx, dy;
|
||||||
|
|
||||||
@@ -1224,26 +1237,26 @@ window_create_surface(struct window *window)
|
|||||||
case WL_OUTPUT_TRANSFORM_270:
|
case WL_OUTPUT_TRANSFORM_270:
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||||
allocation.width = window->allocation.height;
|
allocation.width = surface->allocation.height;
|
||||||
allocation.height = window->allocation.width;
|
allocation.height = surface->allocation.width;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!window->toysurface &&
|
if (!surface->toysurface &&
|
||||||
window->buffer_type == WINDOW_BUFFER_TYPE_EGL_WINDOW &&
|
window->buffer_type == WINDOW_BUFFER_TYPE_EGL_WINDOW &&
|
||||||
window->display->dpy) {
|
window->display->dpy) {
|
||||||
window->toysurface =
|
surface->toysurface =
|
||||||
egl_window_surface_create(window->display,
|
egl_window_surface_create(window->display,
|
||||||
window->main_surface->surface,
|
surface->surface,
|
||||||
flags,
|
flags,
|
||||||
&allocation);
|
&allocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!window->toysurface)
|
if (!surface->toysurface)
|
||||||
window->toysurface = shm_surface_create(window->display,
|
surface->toysurface = shm_surface_create(window->display,
|
||||||
window->main_surface->surface,
|
surface->surface,
|
||||||
flags, &allocation);
|
flags, &allocation);
|
||||||
|
|
||||||
if (window->resizing)
|
if (window->resizing)
|
||||||
@@ -1253,7 +1266,7 @@ window_create_surface(struct window *window)
|
|||||||
|
|
||||||
window_get_resize_dx_dy(window, &dx, &dy);
|
window_get_resize_dx_dy(window, &dx, &dy);
|
||||||
window->cairo_surface =
|
window->cairo_surface =
|
||||||
window->toysurface->prepare(window->toysurface, dx, dy,
|
surface->toysurface->prepare(surface->toysurface, dx, dy,
|
||||||
allocation.width,
|
allocation.width,
|
||||||
allocation.height,
|
allocation.height,
|
||||||
flags);
|
flags);
|
||||||
@@ -1280,6 +1293,10 @@ static void
|
|||||||
surface_destroy(struct surface *surface)
|
surface_destroy(struct surface *surface)
|
||||||
{
|
{
|
||||||
wl_surface_destroy(surface->surface);
|
wl_surface_destroy(surface->surface);
|
||||||
|
|
||||||
|
if (surface->toysurface)
|
||||||
|
surface->toysurface->destroy(surface->toysurface);
|
||||||
|
|
||||||
free(surface);
|
free(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1324,9 +1341,6 @@ window_destroy(struct window *window)
|
|||||||
|
|
||||||
wl_list_remove(&window->link);
|
wl_list_remove(&window->link);
|
||||||
|
|
||||||
if (window->toysurface)
|
|
||||||
window->toysurface->destroy(window->toysurface);
|
|
||||||
|
|
||||||
if (window->frame_cb)
|
if (window->frame_cb)
|
||||||
wl_callback_destroy(window->frame_cb);
|
wl_callback_destroy(window->frame_cb);
|
||||||
free(window->title);
|
free(window->title);
|
||||||
@@ -1363,7 +1377,7 @@ widget_create(struct window *window, void *data)
|
|||||||
memset(widget, 0, sizeof *widget);
|
memset(widget, 0, sizeof *widget);
|
||||||
widget->window = window;
|
widget->window = window;
|
||||||
widget->user_data = data;
|
widget->user_data = data;
|
||||||
widget->allocation = window->allocation;
|
widget->allocation = window->main_surface->allocation;
|
||||||
wl_list_init(&widget->child_list);
|
wl_list_init(&widget->child_list);
|
||||||
widget->opaque = 0;
|
widget->opaque = 0;
|
||||||
widget->tooltip = NULL;
|
widget->tooltip = NULL;
|
||||||
@@ -1538,8 +1552,8 @@ tooltip_redraw_handler(struct widget *widget, void *data)
|
|||||||
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
||||||
cairo_paint(cr);
|
cairo_paint(cr);
|
||||||
|
|
||||||
width = window->allocation.width;
|
width = window->main_surface->allocation.width;
|
||||||
height = window->allocation.height;
|
height = window->main_surface->allocation.height;
|
||||||
rounded_rect(cr, 0, 0, width, height, r);
|
rounded_rect(cr, 0, 0, width, height, r);
|
||||||
|
|
||||||
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
||||||
@@ -3157,6 +3171,16 @@ window_move(struct window *window, struct input *input, uint32_t serial)
|
|||||||
wl_shell_surface_move(window->shell_surface, input->seat, serial);
|
wl_shell_surface_move(window->shell_surface, input->seat, serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
surface_resize(struct surface *surface, struct widget *widget)
|
||||||
|
{
|
||||||
|
if (surface->allocation.width != widget->allocation.width ||
|
||||||
|
surface->allocation.height != widget->allocation.height) {
|
||||||
|
surface->allocation = widget->allocation;
|
||||||
|
window_schedule_redraw(surface->window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
idle_resize(struct window *window)
|
idle_resize(struct window *window)
|
||||||
{
|
{
|
||||||
@@ -3187,11 +3211,7 @@ idle_resize(struct window *window)
|
|||||||
widget->allocation.height,
|
widget->allocation.height,
|
||||||
widget->user_data);
|
widget->user_data);
|
||||||
|
|
||||||
if (window->allocation.width != widget->allocation.width ||
|
surface_resize(window->main_surface, widget);
|
||||||
window->allocation.height != widget->allocation.height) {
|
|
||||||
window->allocation = widget->allocation;
|
|
||||||
window_schedule_redraw(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (widget->opaque)
|
if (widget->opaque)
|
||||||
wl_region_add(window->opaque_region, 0, 0,
|
wl_region_add(window->opaque_region, 0, 0,
|
||||||
@@ -3275,7 +3295,7 @@ void
|
|||||||
window_get_allocation(struct window *window,
|
window_get_allocation(struct window *window,
|
||||||
struct rectangle *allocation)
|
struct rectangle *allocation)
|
||||||
{
|
{
|
||||||
*allocation = window->allocation;
|
*allocation = window->main_surface->allocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -3352,7 +3372,7 @@ window_set_fullscreen(struct window *window, int fullscreen)
|
|||||||
|
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
window->type = TYPE_FULLSCREEN;
|
window->type = TYPE_FULLSCREEN;
|
||||||
window->saved_allocation = window->allocation;
|
window->saved_allocation = window->main_surface->allocation;
|
||||||
wl_shell_surface_set_fullscreen(window->shell_surface,
|
wl_shell_surface_set_fullscreen(window->shell_surface,
|
||||||
window->fullscreen_method,
|
window->fullscreen_method,
|
||||||
0, NULL);
|
0, NULL);
|
||||||
@@ -3388,7 +3408,7 @@ window_set_maximized(struct window *window, int maximized)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (window->type == TYPE_TOPLEVEL) {
|
if (window->type == TYPE_TOPLEVEL) {
|
||||||
window->saved_allocation = window->allocation;
|
window->saved_allocation = window->main_surface->allocation;
|
||||||
wl_shell_surface_set_maximized(window->shell_surface, NULL);
|
wl_shell_surface_set_maximized(window->shell_surface, NULL);
|
||||||
window->type = TYPE_MAXIMIZED;
|
window->type = TYPE_MAXIMIZED;
|
||||||
} else {
|
} else {
|
||||||
@@ -3592,11 +3612,7 @@ window_create_internal(struct display *display,
|
|||||||
wl_shell_get_shell_surface(display->shell,
|
wl_shell_get_shell_surface(display->shell,
|
||||||
window->main_surface->surface);
|
window->main_surface->surface);
|
||||||
}
|
}
|
||||||
window->allocation.x = 0;
|
|
||||||
window->allocation.y = 0;
|
|
||||||
window->allocation.width = 0;
|
|
||||||
window->allocation.height = 0;
|
|
||||||
window->saved_allocation = window->allocation;
|
|
||||||
window->transparent = 1;
|
window->transparent = 1;
|
||||||
window->type = type;
|
window->type = type;
|
||||||
window->input_region = NULL;
|
window->input_region = NULL;
|
||||||
@@ -3756,8 +3772,8 @@ menu_redraw_handler(struct widget *widget, void *data)
|
|||||||
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
||||||
cairo_paint(cr);
|
cairo_paint(cr);
|
||||||
|
|
||||||
width = window->allocation.width;
|
width = window->main_surface->allocation.width;
|
||||||
height = window->allocation.height;
|
height = window->main_surface->allocation.height;
|
||||||
rounded_rect(cr, 0, 0, width, height, r);
|
rounded_rect(cr, 0, 0, width, height, r);
|
||||||
|
|
||||||
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
||||||
@@ -4481,20 +4497,24 @@ display_acquire_window_surface(struct display *display,
|
|||||||
struct window *window,
|
struct window *window,
|
||||||
EGLContext ctx)
|
EGLContext ctx)
|
||||||
{
|
{
|
||||||
|
struct surface *surface = window->main_surface;
|
||||||
|
|
||||||
if (window->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW)
|
if (window->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return window->toysurface->acquire(window->toysurface, ctx);
|
return surface->toysurface->acquire(surface->toysurface, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
display_release_window_surface(struct display *display,
|
display_release_window_surface(struct display *display,
|
||||||
struct window *window)
|
struct window *window)
|
||||||
{
|
{
|
||||||
|
struct surface *surface = window->main_surface;
|
||||||
|
|
||||||
if (window->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW)
|
if (window->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window->toysurface->release(window->toysurface);
|
surface->toysurface->release(surface->toysurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user