|
|
@ -31,7 +31,6 @@ |
|
|
|
#include <signal.h> |
|
|
|
#include <signal.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <wayland-client.h> |
|
|
|
#include <wayland-client.h> |
|
|
|
#include <wayland-egl.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct display { |
|
|
|
struct display { |
|
|
|
struct wl_display *display; |
|
|
|
struct wl_display *display; |
|
|
@ -101,6 +100,17 @@ create_window(struct display *display, int width, int height) |
|
|
|
struct window *window; |
|
|
|
struct window *window; |
|
|
|
|
|
|
|
|
|
|
|
window = malloc(sizeof *window); |
|
|
|
window = malloc(sizeof *window); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window->buffer = create_shm_buffer(display, |
|
|
|
|
|
|
|
width, height, |
|
|
|
|
|
|
|
WL_SHM_FORMAT_XRGB8888, |
|
|
|
|
|
|
|
&window->shm_data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!window->buffer) { |
|
|
|
|
|
|
|
free(window); |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window->callback = NULL; |
|
|
|
window->callback = NULL; |
|
|
|
window->display = display; |
|
|
|
window->display = display; |
|
|
|
window->width = width; |
|
|
|
window->width = width; |
|
|
@ -108,10 +118,6 @@ create_window(struct display *display, int width, int height) |
|
|
|
window->surface = wl_compositor_create_surface(display->compositor); |
|
|
|
window->surface = wl_compositor_create_surface(display->compositor); |
|
|
|
window->shell_surface = wl_shell_get_shell_surface(display->shell, |
|
|
|
window->shell_surface = wl_shell_get_shell_surface(display->shell, |
|
|
|
window->surface); |
|
|
|
window->surface); |
|
|
|
window->buffer = create_shm_buffer(display, |
|
|
|
|
|
|
|
width, height, |
|
|
|
|
|
|
|
WL_SHM_FORMAT_XRGB8888, |
|
|
|
|
|
|
|
&window->shm_data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_shell_surface_set_toplevel(window->shell_surface); |
|
|
|
wl_shell_surface_set_toplevel(window->shell_surface); |
|
|
|
|
|
|
|
|
|
|
@ -130,21 +136,56 @@ destroy_window(struct window *window) |
|
|
|
free(window); |
|
|
|
free(window); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
|
|
|
paint_pixels(void *image, int width, int height, uint32_t time) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const int halfh = height / 2; |
|
|
|
|
|
|
|
const int halfw = width / 2; |
|
|
|
|
|
|
|
int ir, or; |
|
|
|
|
|
|
|
uint32_t *pixel = image; |
|
|
|
|
|
|
|
int y; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* squared radii thresholds */ |
|
|
|
|
|
|
|
or = (halfw < halfh ? halfw : halfh) - 8; |
|
|
|
|
|
|
|
ir = or - 32; |
|
|
|
|
|
|
|
or *= or; |
|
|
|
|
|
|
|
ir *= ir; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) { |
|
|
|
|
|
|
|
int x; |
|
|
|
|
|
|
|
int y2 = (y - halfh) * (y - halfh); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++) { |
|
|
|
|
|
|
|
uint32_t v; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* squared distance from center */ |
|
|
|
|
|
|
|
int r2 = (x - halfw) * (x - halfw) + y2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (r2 < ir) |
|
|
|
|
|
|
|
v = (r2 / 32 + time / 64) * 0x0080401; |
|
|
|
|
|
|
|
else if (r2 < or) |
|
|
|
|
|
|
|
v = (y + time / 32) * 0x0080401; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
v = (x + time / 16) * 0x0080401; |
|
|
|
|
|
|
|
v &= 0x00ffffff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* cross if compositor uses X from XRGB as alpha */ |
|
|
|
|
|
|
|
if (abs(x - y) > 6 && abs(x + y - height) > 6) |
|
|
|
|
|
|
|
v |= 0xff000000; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*pixel++ = v; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener; |
|
|
|
static const struct wl_callback_listener frame_listener; |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
redraw(void *data, struct wl_callback *callback, uint32_t time) |
|
|
|
redraw(void *data, struct wl_callback *callback, uint32_t time) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct window *window = data; |
|
|
|
struct window *window = data; |
|
|
|
uint32_t *p; |
|
|
|
|
|
|
|
int i, end, offset; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p = window->shm_data; |
|
|
|
|
|
|
|
end = window->width * window->height; |
|
|
|
|
|
|
|
offset = time >> 4; |
|
|
|
|
|
|
|
for (i = 0; i < end; i++) |
|
|
|
|
|
|
|
p[i] = (i + offset) * 0x0080401; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
paint_pixels(window->shm_data, window->width, window->height, time); |
|
|
|
wl_surface_attach(window->surface, window->buffer, 0, 0); |
|
|
|
wl_surface_attach(window->surface, window->buffer, 0, 0); |
|
|
|
wl_surface_damage(window->surface, |
|
|
|
wl_surface_damage(window->surface, |
|
|
|
0, 0, window->width, window->height); |
|
|
|
0, 0, window->width, window->height); |
|
|
@ -258,6 +299,8 @@ main(int argc, char **argv) |
|
|
|
|
|
|
|
|
|
|
|
display = create_display(); |
|
|
|
display = create_display(); |
|
|
|
window = create_window(display, 250, 250); |
|
|
|
window = create_window(display, 250, 250); |
|
|
|
|
|
|
|
if (!window) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
sigint.sa_handler = signal_int; |
|
|
|
sigint.sa_handler = signal_int; |
|
|
|
sigemptyset(&sigint.sa_mask); |
|
|
|
sigemptyset(&sigint.sa_mask); |
|
|
|