window: Allocate and flush the window surface in window.c
No need to push this to the toolkit users.
This commit is contained in:
parent
75bc667a70
commit
5d12990dbe
|
@ -341,7 +341,7 @@ background_draw(struct window *window, int width, int height, const char *path)
|
|||
double sx, sy;
|
||||
|
||||
window_set_child_size(window, width, height);
|
||||
window_draw(window);
|
||||
window_create_surface(window);
|
||||
surface = window_get_surface(window);
|
||||
|
||||
cr = cairo_create(surface);
|
||||
|
@ -388,8 +388,6 @@ unlock_dialog_draw(struct unlock_dialog *dialog)
|
|||
cairo_pattern_t *pat;
|
||||
double cx, cy, r, f;
|
||||
|
||||
window_draw(dialog->window);
|
||||
|
||||
surface = window_get_surface(dialog->window);
|
||||
cr = cairo_create(surface);
|
||||
window_get_child_allocation(dialog->window, &allocation);
|
||||
|
@ -428,7 +426,6 @@ unlock_dialog_draw(struct unlock_dialog *dialog)
|
|||
cairo_paint(cr);
|
||||
cairo_destroy(cr);
|
||||
|
||||
window_flush(dialog->window);
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
|
||||
|
|
|
@ -167,8 +167,6 @@ dnd_draw(struct dnd *dnd)
|
|||
cairo_surface_t *surface;
|
||||
int i;
|
||||
|
||||
window_draw(dnd->window);
|
||||
|
||||
surface = window_get_surface(dnd->window);
|
||||
cr = cairo_create(surface);
|
||||
window_get_child_allocation(dnd->window, &allocation);
|
||||
|
@ -191,7 +189,6 @@ dnd_draw(struct dnd *dnd)
|
|||
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(surface);
|
||||
window_flush(dnd->window);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -103,7 +103,6 @@ eventdemo_draw(struct eventdemo *e) {
|
|||
cairo_t *cr;
|
||||
struct rectangle rect;
|
||||
|
||||
window_draw(e->window);
|
||||
window_get_child_allocation(e->window, &rect);
|
||||
surface = window_get_surface(e->window);
|
||||
|
||||
|
@ -120,7 +119,6 @@ eventdemo_draw(struct eventdemo *e) {
|
|||
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(surface);
|
||||
window_flush(e->window);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -329,7 +327,7 @@ eventdemo_create(struct display *d)
|
|||
}
|
||||
|
||||
/* Initial drawing of the window */
|
||||
eventdemo_draw(e);
|
||||
window_schedule_redraw(e->window);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
window_set_title(flower.window, "flower");
|
||||
window_set_decoration(flower.window, 0);
|
||||
window_draw(flower.window);
|
||||
window_create_surface(flower.window);
|
||||
s = window_get_surface(flower.window);
|
||||
if (s == NULL || cairo_surface_status (s) != CAIRO_STATUS_SUCCESS) {
|
||||
fprintf(stderr, "failed to create cairo egl surface\n");
|
||||
|
|
|
@ -195,13 +195,30 @@ make_gear(const struct gear_template *t)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_gears(struct gears *gears)
|
||||
frame_callback(void *data, struct wl_callback *callback, uint32_t time)
|
||||
{
|
||||
struct gears *gears = data;
|
||||
|
||||
gears->angle = (GLfloat) (time % 8192) * 360 / 8192.0;
|
||||
|
||||
window_schedule_redraw(gears->window);
|
||||
|
||||
if (callback)
|
||||
wl_callback_destroy(callback);
|
||||
}
|
||||
|
||||
static const struct wl_callback_listener listener = {
|
||||
frame_callback
|
||||
};
|
||||
|
||||
static void
|
||||
redraw_handler(struct window *window, void *data)
|
||||
{
|
||||
GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
|
||||
struct rectangle window_allocation;
|
||||
struct rectangle allocation;
|
||||
|
||||
window_draw(gears->window);
|
||||
struct wl_callback *callback;
|
||||
struct gears *gears = data;
|
||||
|
||||
window_get_child_allocation(gears->window, &allocation);
|
||||
window_get_allocation(gears->window, &window_allocation);
|
||||
|
@ -254,7 +271,9 @@ draw_gears(struct gears *gears)
|
|||
glFlush();
|
||||
|
||||
display_release_window_surface(gears->d, gears->window);
|
||||
window_flush(gears->window);
|
||||
|
||||
callback = wl_surface_frame(window_get_wl_surface(gears->window));
|
||||
wl_callback_add_listener(callback, &listener, gears);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -287,25 +306,6 @@ keyboard_focus_handler(struct window *window,
|
|||
resize_handler(window, allocation.width, allocation.height, gears);
|
||||
}
|
||||
|
||||
static void
|
||||
frame_callback(void *data, struct wl_callback *callback, uint32_t time)
|
||||
{
|
||||
static const struct wl_callback_listener listener = {
|
||||
frame_callback
|
||||
};
|
||||
struct gears *gears = data;
|
||||
|
||||
gears->angle = (GLfloat) (time % 8192) * 360 / 8192.0;
|
||||
|
||||
draw_gears(gears);
|
||||
|
||||
if (callback)
|
||||
wl_callback_destroy(callback);
|
||||
|
||||
callback = wl_surface_frame(window_get_wl_surface(gears->window));
|
||||
wl_callback_add_listener(callback, &listener, gears);
|
||||
}
|
||||
|
||||
static struct gears *
|
||||
gears_create(struct display *display)
|
||||
{
|
||||
|
@ -359,6 +359,7 @@ gears_create(struct display *display)
|
|||
|
||||
window_set_user_data(gears->window, gears);
|
||||
window_set_resize_handler(gears->window, resize_handler);
|
||||
window_set_redraw_handler(gears->window, redraw_handler);
|
||||
window_set_keyboard_focus_handler(gears->window, keyboard_focus_handler);
|
||||
|
||||
frame_callback(gears, NULL, 0);
|
||||
|
|
|
@ -140,8 +140,6 @@ image_draw(struct image *image)
|
|||
cairo_t *cr;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
window_draw(image->window);
|
||||
|
||||
window_get_child_allocation(image->window, &allocation);
|
||||
|
||||
pb = gdk_pixbuf_new_from_file_at_size(image->filename,
|
||||
|
@ -175,7 +173,6 @@ image_draw(struct image *image)
|
|||
cairo_paint(cr);
|
||||
cairo_destroy(cr);
|
||||
|
||||
window_flush(image->window);
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
|
||||
|
@ -223,7 +220,7 @@ image_create(struct display *display, const char *filename)
|
|||
window_set_keyboard_focus_handler(image->window,
|
||||
keyboard_focus_handler);
|
||||
|
||||
image_draw(image);
|
||||
window_schedule_redraw(image->window);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
|
|
@ -104,8 +104,6 @@ resizor_draw(struct resizor *resizor)
|
|||
cairo_t *cr;
|
||||
struct rectangle allocation;
|
||||
|
||||
window_draw(resizor->window);
|
||||
|
||||
window_get_child_allocation(resizor->window, &allocation);
|
||||
|
||||
surface = window_get_surface(resizor->window);
|
||||
|
@ -122,8 +120,6 @@ resizor_draw(struct resizor *resizor)
|
|||
cairo_destroy(cr);
|
||||
|
||||
cairo_surface_destroy(surface);
|
||||
|
||||
window_flush(resizor->window);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -236,7 +232,7 @@ resizor_create(struct display *display)
|
|||
window_set_child_size(resizor->window, resizor->width, height);
|
||||
widget_set_button_handler(resizor->widget, button_handler);
|
||||
|
||||
resizor_draw(resizor);
|
||||
window_schedule_redraw(resizor->window);
|
||||
|
||||
return resizor;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ homescreen_draw(struct tablet_shell *shell)
|
|||
const int rows = 4, columns = 5, icon_width = 128, icon_height = 128;
|
||||
int x, y, i, width, height, vmargin, hmargin, vpadding, hpadding;
|
||||
|
||||
window_draw(shell->homescreen);
|
||||
window_create_surface(shell->homescreen);
|
||||
window_get_child_allocation(shell->homescreen, &allocation);
|
||||
surface = window_get_surface(shell->homescreen);
|
||||
cr = cairo_create(surface);
|
||||
|
@ -175,7 +175,7 @@ lockscreen_draw(struct tablet_shell *shell)
|
|||
cairo_t *cr;
|
||||
int width, height;
|
||||
|
||||
window_draw(shell->lockscreen);
|
||||
window_create_surface(shell->lockscreen);
|
||||
window_get_child_allocation(shell->lockscreen, &allocation);
|
||||
surface = window_get_surface(shell->lockscreen);
|
||||
cr = cairo_create(surface);
|
||||
|
|
|
@ -1029,20 +1029,12 @@ resize_handler(struct window *window,
|
|||
terminal_resize(terminal, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
terminal_draw(struct terminal *terminal)
|
||||
{
|
||||
window_draw(terminal->window);
|
||||
terminal_draw_contents(terminal);
|
||||
window_flush(terminal->window);
|
||||
}
|
||||
|
||||
static void
|
||||
redraw_handler(struct window *window, void *data)
|
||||
{
|
||||
struct terminal *terminal = data;
|
||||
|
||||
terminal_draw(terminal);
|
||||
terminal_draw_contents(terminal);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2371,7 +2363,7 @@ terminal_run(struct terminal *terminal, const char *path)
|
|||
if (!terminal->fullscreen)
|
||||
terminal_resize(terminal, 80, 24);
|
||||
|
||||
terminal_draw(terminal);
|
||||
window_schedule_redraw(terminal->window);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -965,8 +965,6 @@ window_draw_decorations(struct window *window)
|
|||
cairo_surface_t *frame;
|
||||
int width, height, shadow_dx = 3, shadow_dy = 3;
|
||||
|
||||
window_create_surface(window);
|
||||
|
||||
width = window->allocation.width;
|
||||
height = window->allocation.height;
|
||||
|
||||
|
@ -1134,15 +1132,6 @@ widget_schedule_redraw(struct widget *widget)
|
|||
window_schedule_redraw(widget->window);
|
||||
}
|
||||
|
||||
void
|
||||
window_draw(struct window *window)
|
||||
{
|
||||
if (!window->decoration)
|
||||
window_create_surface(window);
|
||||
else
|
||||
window_draw_decorations(window);
|
||||
}
|
||||
|
||||
cairo_surface_t *
|
||||
window_get_surface(struct window *window)
|
||||
{
|
||||
|
@ -1966,8 +1955,16 @@ idle_redraw(struct task *task, uint32_t events)
|
|||
struct window *window =
|
||||
container_of(task, struct window, redraw_task);
|
||||
|
||||
window_create_surface(window);
|
||||
if (window->decoration)
|
||||
window_draw_decorations(window);
|
||||
|
||||
window->redraw_handler(window, window->user_data);
|
||||
|
||||
window_flush(window);
|
||||
|
||||
window->redraw_scheduled = 0;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2256,8 +2253,6 @@ menu_redraw_handler(struct window *window, void *data)
|
|||
struct menu *menu = data;
|
||||
int32_t width, height, i;
|
||||
|
||||
window_create_surface(window);
|
||||
|
||||
cr = cairo_create(window->cairo_surface);
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
||||
|
@ -2287,7 +2282,6 @@ menu_redraw_handler(struct window *window, void *data)
|
|||
}
|
||||
|
||||
cairo_destroy(cr);
|
||||
window_flush(window);
|
||||
}
|
||||
|
||||
struct window *
|
||||
|
|
|
@ -73,8 +73,6 @@ draw_instance(struct ModeInfo *mi)
|
|||
|
||||
mi->swap_buffers = 0;
|
||||
|
||||
window_draw(mi->window);
|
||||
|
||||
window_get_child_allocation(mi->window, &drawarea);
|
||||
window_get_allocation(mi->window, &winarea);
|
||||
|
||||
|
@ -103,7 +101,6 @@ draw_instance(struct ModeInfo *mi)
|
|||
fprintf(stderr, "%s: swapBuffers not called\n", progname);
|
||||
|
||||
display_release_window_surface(wscr->display, mi->window);
|
||||
window_flush(mi->window);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue