mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-02 09:01:39 -05:00
Consolidate redraw scheduling in window.c
This commit is contained in:
parent
0953162db8
commit
80d746f6e3
5 changed files with 57 additions and 89 deletions
|
|
@ -46,9 +46,6 @@ struct image {
|
||||||
struct window *window;
|
struct window *window;
|
||||||
struct display *display;
|
struct display *display;
|
||||||
uint32_t key;
|
uint32_t key;
|
||||||
|
|
||||||
gboolean redraw_scheduled;
|
|
||||||
|
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -149,8 +146,6 @@ image_draw(struct image *image)
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
cairo_surface_t *wsurface, *surface;
|
cairo_surface_t *wsurface, *surface;
|
||||||
|
|
||||||
image->redraw_scheduled = 0;
|
|
||||||
|
|
||||||
window_draw(image->window);
|
window_draw(image->window);
|
||||||
|
|
||||||
window_get_child_rectangle(image->window, &rectangle);
|
window_get_child_rectangle(image->window, &rectangle);
|
||||||
|
|
@ -186,31 +181,12 @@ image_draw(struct image *image)
|
||||||
cairo_surface_destroy(surface);
|
cairo_surface_destroy(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
image_idle_redraw(void *data)
|
redraw_handler(struct window *window, void *data)
|
||||||
{
|
{
|
||||||
struct image *image = data;
|
struct image *image = data;
|
||||||
|
|
||||||
image_draw(image);
|
image_draw(image);
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
image_schedule_redraw(struct image *image)
|
|
||||||
{
|
|
||||||
if (!image->redraw_scheduled) {
|
|
||||||
image->redraw_scheduled = 1;
|
|
||||||
g_idle_add(image_idle_redraw, image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
resize_handler(struct window *window, void *data)
|
|
||||||
{
|
|
||||||
struct image *image = data;
|
|
||||||
|
|
||||||
image_schedule_redraw(image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -219,7 +195,7 @@ keyboard_focus_handler(struct window *window,
|
||||||
{
|
{
|
||||||
struct image *image = data;
|
struct image *image = data;
|
||||||
|
|
||||||
image_schedule_redraw(image);
|
window_schedule_redraw(image->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct image *
|
static struct image *
|
||||||
|
|
@ -247,7 +223,7 @@ image_create(struct display *display, uint32_t key, const char *filename)
|
||||||
* allocation scheme here. Or maybe just a real toolkit. */
|
* allocation scheme here. Or maybe just a real toolkit. */
|
||||||
image->key = key + 100;
|
image->key = key + 100;
|
||||||
|
|
||||||
window_set_resize_handler(image->window, resize_handler, image);
|
window_set_redraw_handler(image->window, redraw_handler, image);
|
||||||
window_set_keyboard_focus_handler(image->window, keyboard_focus_handler, image);
|
window_set_keyboard_focus_handler(image->window, keyboard_focus_handler, image);
|
||||||
|
|
||||||
image_draw(image);
|
image_draw(image);
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ static int option_fullscreen;
|
||||||
struct terminal {
|
struct terminal {
|
||||||
struct window *window;
|
struct window *window;
|
||||||
struct display *display;
|
struct display *display;
|
||||||
int redraw_scheduled;
|
|
||||||
char *data;
|
char *data;
|
||||||
int width, height, start, row, column;
|
int width, height, start, row, column;
|
||||||
int fd, master;
|
int fd, master;
|
||||||
|
|
@ -219,15 +218,12 @@ terminal_draw(struct terminal *terminal)
|
||||||
window_commit(terminal->window, 0);
|
window_commit(terminal->window, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
idle_redraw(void *data)
|
redraw_handler(struct window *window, void *data)
|
||||||
{
|
{
|
||||||
struct terminal *terminal = data;
|
struct terminal *terminal = data;
|
||||||
|
|
||||||
terminal_draw(terminal);
|
terminal_draw(terminal);
|
||||||
terminal->redraw_scheduled = 0;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STATE_NORMAL 0
|
#define STATE_NORMAL 0
|
||||||
|
|
@ -236,15 +232,6 @@ idle_redraw(void *data)
|
||||||
static void
|
static void
|
||||||
terminal_data(struct terminal *terminal, const char *data, size_t length);
|
terminal_data(struct terminal *terminal, const char *data, size_t length);
|
||||||
|
|
||||||
static void
|
|
||||||
terminal_schedule_redraw(struct terminal *terminal)
|
|
||||||
{
|
|
||||||
if (!terminal->redraw_scheduled) {
|
|
||||||
g_idle_add(idle_redraw, terminal);
|
|
||||||
terminal->redraw_scheduled = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_escape(struct terminal *terminal)
|
handle_escape(struct terminal *terminal)
|
||||||
{
|
{
|
||||||
|
|
@ -396,15 +383,7 @@ terminal_data(struct terminal *terminal, const char *data, size_t length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal_schedule_redraw(terminal);
|
window_schedule_redraw(terminal->window);
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
resize_handler(struct window *window, void *data)
|
|
||||||
{
|
|
||||||
struct terminal *terminal = data;
|
|
||||||
|
|
||||||
terminal_schedule_redraw(terminal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -420,7 +399,7 @@ key_handler(struct window *window, uint32_t key, uint32_t unicode,
|
||||||
break;
|
break;
|
||||||
terminal->fullscreen ^= 1;
|
terminal->fullscreen ^= 1;
|
||||||
window_set_fullscreen(window, terminal->fullscreen);
|
window_set_fullscreen(window, terminal->fullscreen);
|
||||||
terminal_schedule_redraw(terminal);
|
window_schedule_redraw(terminal->window);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (state && unicode)
|
if (state && unicode)
|
||||||
|
|
@ -436,7 +415,7 @@ keyboard_focus_handler(struct window *window,
|
||||||
struct terminal *terminal = data;
|
struct terminal *terminal = data;
|
||||||
|
|
||||||
terminal->focused = (device != NULL);
|
terminal->focused = (device != NULL);
|
||||||
terminal_schedule_redraw(terminal);
|
window_schedule_redraw(terminal->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct terminal *
|
static struct terminal *
|
||||||
|
|
@ -459,7 +438,8 @@ terminal_create(struct display *display, int fullscreen)
|
||||||
terminal->margin = 5;
|
terminal->margin = 5;
|
||||||
|
|
||||||
window_set_fullscreen(terminal->window, terminal->fullscreen);
|
window_set_fullscreen(terminal->window, terminal->fullscreen);
|
||||||
window_set_resize_handler(terminal->window, resize_handler, terminal);
|
window_set_redraw_handler(terminal->window,
|
||||||
|
redraw_handler, terminal);
|
||||||
|
|
||||||
window_set_key_handler(terminal->window, key_handler, terminal);
|
window_set_key_handler(terminal->window, key_handler, terminal);
|
||||||
window_set_keyboard_focus_handler(terminal->window,
|
window_set_keyboard_focus_handler(terminal->window,
|
||||||
|
|
@ -475,7 +455,6 @@ terminal_create(struct display *display, int fullscreen)
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
cairo_surface_destroy(surface);
|
cairo_surface_destroy(surface);
|
||||||
|
|
||||||
|
|
||||||
terminal_draw(terminal);
|
terminal_draw(terminal);
|
||||||
|
|
||||||
return terminal;
|
return terminal;
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,6 @@ struct view {
|
||||||
struct display *display;
|
struct display *display;
|
||||||
uint32_t key;
|
uint32_t key;
|
||||||
|
|
||||||
gboolean redraw_scheduled;
|
|
||||||
|
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
PopplerDocument *document;
|
PopplerDocument *document;
|
||||||
int page;
|
int page;
|
||||||
|
|
@ -69,8 +67,6 @@ view_draw(struct view *view)
|
||||||
PopplerPage *page;
|
PopplerPage *page;
|
||||||
double width, height, doc_aspect, window_aspect, scale;
|
double width, height, doc_aspect, window_aspect, scale;
|
||||||
|
|
||||||
view->redraw_scheduled = 0;
|
|
||||||
|
|
||||||
window_draw(view->window);
|
window_draw(view->window);
|
||||||
|
|
||||||
window_get_child_rectangle(view->window, &rectangle);
|
window_get_child_rectangle(view->window, &rectangle);
|
||||||
|
|
@ -110,23 +106,12 @@ view_draw(struct view *view)
|
||||||
window_commit(view->window, 0);
|
window_commit(view->window, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
view_idle_redraw(void *data)
|
redraw_handler(struct window *window, void *data)
|
||||||
{
|
{
|
||||||
struct view *view = data;
|
struct view *view = data;
|
||||||
|
|
||||||
view_draw(view);
|
view_draw(view);
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
view_schedule_redraw(struct view *view)
|
|
||||||
{
|
|
||||||
if (!view->redraw_scheduled) {
|
|
||||||
view->redraw_scheduled = 1;
|
|
||||||
g_idle_add(view_idle_redraw, view);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -141,35 +126,27 @@ key_handler(struct window *window, uint32_t key, uint32_t unicode,
|
||||||
break;
|
break;
|
||||||
view->fullscreen ^= 1;
|
view->fullscreen ^= 1;
|
||||||
window_set_fullscreen(window, view->fullscreen);
|
window_set_fullscreen(window, view->fullscreen);
|
||||||
view_schedule_redraw(view);
|
window_schedule_redraw(view->window);
|
||||||
break;
|
break;
|
||||||
case KEY_SPACE:
|
case KEY_SPACE:
|
||||||
case KEY_PAGEDOWN:
|
case KEY_PAGEDOWN:
|
||||||
if (!state)
|
if (!state)
|
||||||
break;
|
break;
|
||||||
view->page++;
|
view->page++;
|
||||||
view_schedule_redraw(view);
|
window_schedule_redraw(view->window);
|
||||||
break;
|
break;
|
||||||
case KEY_BACKSPACE:
|
case KEY_BACKSPACE:
|
||||||
case KEY_PAGEUP:
|
case KEY_PAGEUP:
|
||||||
if (!state)
|
if (!state)
|
||||||
break;
|
break;
|
||||||
view->page--;
|
view->page--;
|
||||||
view_schedule_redraw(view);
|
window_schedule_redraw(view->window);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
resize_handler(struct window *window, void *data)
|
|
||||||
{
|
|
||||||
struct view *view = data;
|
|
||||||
|
|
||||||
view_schedule_redraw(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
keyboard_focus_handler(struct window *window,
|
keyboard_focus_handler(struct window *window,
|
||||||
struct wl_input_device *device, void *data)
|
struct wl_input_device *device, void *data)
|
||||||
|
|
@ -177,7 +154,7 @@ keyboard_focus_handler(struct window *window,
|
||||||
struct view *view = data;
|
struct view *view = data;
|
||||||
|
|
||||||
view->focused = (device != NULL);
|
view->focused = (device != NULL);
|
||||||
view_schedule_redraw(view);
|
window_schedule_redraw(view->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct view *
|
static struct view *
|
||||||
|
|
@ -206,9 +183,8 @@ view_create(struct display *display, uint32_t key, const char *filename)
|
||||||
/* FIXME: Window uses key 1 for moves, need some kind of
|
/* FIXME: Window uses key 1 for moves, need some kind of
|
||||||
* allocation scheme here. Or maybe just a real toolkit. */
|
* allocation scheme here. Or maybe just a real toolkit. */
|
||||||
view->key = key + 100;
|
view->key = key + 100;
|
||||||
view->redraw_scheduled = 1;
|
|
||||||
|
|
||||||
window_set_resize_handler(view->window, resize_handler, view);
|
window_set_redraw_handler(view->window, redraw_handler, view);
|
||||||
window_set_key_handler(view->window, key_handler, view);
|
window_set_key_handler(view->window, key_handler, view);
|
||||||
window_set_keyboard_focus_handler(view->window,
|
window_set_keyboard_focus_handler(view->window,
|
||||||
keyboard_focus_handler, view);
|
keyboard_focus_handler, view);
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ struct window {
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
const char *title;
|
const char *title;
|
||||||
struct rectangle allocation, saved_allocation, surface_allocation;
|
struct rectangle allocation, saved_allocation, surface_allocation;
|
||||||
|
int redraw_scheduled;
|
||||||
int minimum_width, minimum_height;
|
int minimum_width, minimum_height;
|
||||||
int margin;
|
int margin;
|
||||||
int drag_x, drag_y;
|
int drag_x, drag_y;
|
||||||
|
|
@ -83,6 +84,7 @@ struct window {
|
||||||
cairo_surface_t *cairo_surface, *pending_surface;
|
cairo_surface_t *cairo_surface, *pending_surface;
|
||||||
|
|
||||||
window_resize_handler_t resize_handler;
|
window_resize_handler_t resize_handler;
|
||||||
|
window_redraw_handler_t redraw_handler;
|
||||||
window_key_handler_t key_handler;
|
window_key_handler_t key_handler;
|
||||||
window_keyboard_focus_handler_t keyboard_focus_handler;
|
window_keyboard_focus_handler_t keyboard_focus_handler;
|
||||||
window_acknowledge_handler_t acknowledge_handler;
|
window_acknowledge_handler_t acknowledge_handler;
|
||||||
|
|
@ -396,7 +398,8 @@ window_handle_motion(void *data, struct wl_input_device *input_device,
|
||||||
if (window->resize_handler)
|
if (window->resize_handler)
|
||||||
(*window->resize_handler)(window,
|
(*window->resize_handler)(window,
|
||||||
window->user_data);
|
window->user_data);
|
||||||
|
else if (window->redraw_handler)
|
||||||
|
window_schedule_redraw(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -685,6 +688,26 @@ window_copy_surface(struct window *window,
|
||||||
cairo_destroy (cr);
|
cairo_destroy (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
idle_redraw(void *data)
|
||||||
|
{
|
||||||
|
struct window *window = data;
|
||||||
|
|
||||||
|
window->redraw_handler(window, window->user_data);
|
||||||
|
window->redraw_scheduled = 0;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
window_schedule_redraw(struct window *window)
|
||||||
|
{
|
||||||
|
if (!window->redraw_scheduled) {
|
||||||
|
g_idle_add(idle_redraw, window);
|
||||||
|
window->redraw_scheduled = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
window_set_fullscreen(struct window *window, int fullscreen)
|
window_set_fullscreen(struct window *window, int fullscreen)
|
||||||
{
|
{
|
||||||
|
|
@ -711,6 +734,14 @@ window_set_resize_handler(struct window *window,
|
||||||
window->user_data = data;
|
window->user_data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
window_set_redraw_handler(struct window *window,
|
||||||
|
window_redraw_handler_t handler, void *data)
|
||||||
|
{
|
||||||
|
window->redraw_handler = handler;
|
||||||
|
window->user_data = data;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
window_set_key_handler(struct window *window,
|
window_set_key_handler(struct window *window,
|
||||||
window_key_handler_t handler, void *data)
|
window_key_handler_t handler, void *data)
|
||||||
|
|
@ -804,7 +835,6 @@ display_handle_acknowledge(void *data,
|
||||||
{
|
{
|
||||||
struct display *d = data;
|
struct display *d = data;
|
||||||
struct window *window;
|
struct window *window;
|
||||||
cairo_surface_t *pending;
|
|
||||||
|
|
||||||
/* The acknowledge event means that the server processed our
|
/* The acknowledge event means that the server processed our
|
||||||
* last commit request and we can now safely free the old
|
* last commit request and we can now safely free the old
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*window_resize_handler_t)(struct window *window, void *data);
|
typedef void (*window_resize_handler_t)(struct window *window, void *data);
|
||||||
|
typedef void (*window_redraw_handler_t)(struct window *window, void *data);
|
||||||
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
|
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
|
||||||
typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, uint32_t frame, void *data);
|
typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, uint32_t frame, void *data);
|
||||||
typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t unicode,
|
typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t unicode,
|
||||||
|
|
@ -80,6 +81,8 @@ void
|
||||||
window_copy_image(struct window *window,
|
window_copy_image(struct window *window,
|
||||||
struct rectangle *rectangle,
|
struct rectangle *rectangle,
|
||||||
void *image);
|
void *image);
|
||||||
|
void
|
||||||
|
window_schedule_redraw(struct window *window);
|
||||||
|
|
||||||
void
|
void
|
||||||
window_move(struct window *window, int32_t x, int32_t y);
|
window_move(struct window *window, int32_t x, int32_t y);
|
||||||
|
|
@ -99,6 +102,10 @@ window_copy_surface(struct window *window,
|
||||||
void
|
void
|
||||||
window_set_fullscreen(struct window *window, int fullscreen);
|
window_set_fullscreen(struct window *window, int fullscreen);
|
||||||
|
|
||||||
|
void
|
||||||
|
window_set_redraw_handler(struct window *window,
|
||||||
|
window_redraw_handler_t handler, void *data);
|
||||||
|
|
||||||
void
|
void
|
||||||
window_set_decoration(struct window *window, int decoration);
|
window_set_decoration(struct window *window, int decoration);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue