Add x11 backend for compositor

This still needs all the bells and whistles from the egl-kms mesa branch,
but it makes it a lot easier to work on wayland.
parent fc783d40
......@@ -28,6 +28,7 @@ $(libs) :
compositor : \
compositor.o \
compositor-drm.o \
compositor-x11.o \
screenshooter.o \
cairo-util.o
......
This diff is collapsed.
This diff is collapsed.
......@@ -355,8 +355,6 @@ wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs)
compositor->current_frame, msecs);
wl_event_source_timer_update(compositor->timer_source, 5);
compositor->repaint_on_timeout = 1;
compositor->current_frame++;
}
......@@ -379,13 +377,6 @@ wlsc_output_repaint(struct wlsc_output *output)
wl_list_for_each(eid, &ec->input_device_list, link)
wlsc_surface_draw(eid->sprite, output);
output->current ^= 1;
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER,
output->rbo[output->current]);
}
static void
......@@ -402,7 +393,7 @@ repaint(void *data)
wl_list_for_each(output, &ec->output_list, link)
wlsc_output_repaint(output);
wlsc_compositor_present_drm(ec);
ec->present(ec);
ec->repaint_needed = 0;
}
......@@ -628,9 +619,6 @@ notify_motion(struct wlsc_input_device *device, int x, int y)
const int hotspot_x = 16, hotspot_y = 16;
int32_t sx, sy;
if (!ec->vt_active)
return;
/* FIXME: We need some multi head love here. */
output = container_of(ec->output_list.next, struct wlsc_output, link);
if (x < output->x)
......@@ -668,8 +656,7 @@ notify_button(struct wlsc_input_device *device,
struct wlsc_compositor *compositor = device->ec;
int32_t sx, sy;
if (!compositor->vt_active)
return;
fprintf(stderr, "notify button: button %d, state %d\n", button, state);
surface = pick_surface(device, &sx, &sy);
if (surface) {
......@@ -700,9 +687,6 @@ notify_key(struct wlsc_input_device *device,
uint32_t *k, *end;
uint32_t modifier;
if (!compositor->vt_active)
return;
switch (key | compositor->modifier_state) {
case KEY_BACKSPACE | MODIFIER_CTRL | MODIFIER_ALT:
kill(0, SIGTERM);
......@@ -769,16 +753,10 @@ handle_surface_destroy(struct wlsc_listener *listener,
}
}
struct wlsc_input_device *
wlsc_input_device_create(struct wlsc_compositor *ec)
void
wlsc_input_device_init(struct wlsc_input_device *device,
struct wlsc_compositor *ec)
{
struct wlsc_input_device *device;
device = malloc(sizeof *device);
if (device == NULL)
return NULL;
memset(device, 0, sizeof *device);
device->base.interface = &wl_input_device_interface;
device->base.implementation = NULL;
wl_display_add_object(ec->wl_display, &device->base);
......@@ -786,13 +764,12 @@ wlsc_input_device_create(struct wlsc_compositor *ec)
device->x = 100;
device->y = 100;
device->ec = ec;
device->sprite = pointer_create(ec, device->x, device->y, 64, 64);
device->listener.func = handle_surface_destroy;
wl_list_insert(ec->surface_destroy_listener_list.prev,
&device->listener.link);
wl_list_insert(ec->input_device_list.prev, &device->link);
return device;
}
static void
......@@ -916,18 +893,37 @@ add_visuals(struct wlsc_compositor *ec)
wl_display_add_global(ec->wl_display, &ec->rgb_visual.base, NULL);
}
static struct wlsc_compositor *
wlsc_compositor_create(struct wl_display *display)
void
wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
int x, int y, int width, int height)
{
struct wlsc_compositor *ec;
struct wl_event_loop *loop;
struct wlsc_output *output;
output->compositor = c;
output->x = x;
output->y = y;
output->width = width;
output->height = height;
ec = malloc(sizeof *ec);
if (ec == NULL)
return NULL;
output->background =
background_create(output, option_background);
wlsc_matrix_init(&output->matrix);
wlsc_matrix_translate(&output->matrix,
-output->x - output->width / 2.0,
-output->y - output->height / 2.0, 0);
wlsc_matrix_scale(&output->matrix,
2.0 / output->width, 2.0 / output->height, 1);
output->base.interface = &wl_output_interface;
wl_display_add_object(c->wl_display, &output->base);
wl_display_add_global(c->wl_display, &output->base,
wlsc_output_post_geometry);
}
int
wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
{
struct wl_event_loop *loop;
memset(ec, 0, sizeof *ec);
ec->wl_display = display;
wl_display_set_compositor(display, &ec->base, &compositor_interface);
......@@ -941,34 +937,6 @@ wlsc_compositor_create(struct wl_display *display)
screenshooter_create(ec);
if (wlsc_compositor_init_drm(ec) < 0) {
fprintf(stderr, "failed to initialize devices\n");
return NULL;
}
/* Create the pointer and background surfaces now that we have
* a current EGL context. */
ec->input_device->sprite =
pointer_create(ec,
ec->input_device->x,
ec->input_device->y, 64, 64);
wl_list_for_each(output, &ec->output_list, link) {
output->background = background_create(output,
option_background);
wlsc_matrix_init(&output->matrix);
wlsc_matrix_translate(&output->matrix,
-output->x - output->width / 2.0,
-output->y - output->height / 2.0, 0);
wlsc_matrix_scale(&output->matrix,
2.0 / output->width, 2.0 / output->height, 1);
output->base.interface = &wl_output_interface;
wl_display_add_object(ec->wl_display, &output->base);
wl_display_add_global(ec->wl_display, &output->base,
wlsc_output_post_geometry);
}
glGenFramebuffers(1, &ec->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, ec->fbo);
glActiveTexture(GL_TEXTURE0);
......@@ -978,7 +946,7 @@ wlsc_compositor_create(struct wl_display *display)
ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec);
wlsc_compositor_schedule_repaint(ec);
return ec;
return 0;
}
/* The plan here is to generate a random anonymous socket name and
......@@ -1002,7 +970,11 @@ int main(int argc, char *argv[])
display = wl_display_create();
ec = wlsc_compositor_create(display);
if (getenv("DISPLAY"))
ec = x11_compositor_create(display);
else
ec = drm_compositor_create(display);
if (ec == NULL) {
fprintf(stderr, "failed to create compositor\n");
exit(EXIT_FAILURE);
......
......@@ -54,15 +54,6 @@ struct wlsc_output {
struct wlsc_surface *background;
struct wlsc_matrix matrix;
int32_t x, y, width, height;
drmModeModeInfo mode;
uint32_t crtc_id;
uint32_t connector_id;
GLuint rbo[2];
uint32_t fb_id[2];
EGLImageKHR image[2];
uint32_t current;
};
struct wlsc_input_device {
......@@ -87,7 +78,6 @@ struct wlsc_compositor {
EGLDisplay display;
EGLContext context;
int drm_fd;
GLuint fbo, vbo;
GLuint proj_uniform, tex_uniform;
struct wl_display *wl_display;
......@@ -101,28 +91,16 @@ struct wlsc_compositor {
struct wl_list surface_destroy_listener_list;
struct wl_event_source *term_signal_source;
/* tty handling state */
int tty_fd;
uint32_t vt_active : 1;
struct termios terminal_attributes;
struct wl_event_source *tty_input_source;
struct wl_event_source *enter_vt_source;
struct wl_event_source *leave_vt_source;
struct udev *udev;
/* Repaint state. */
struct wl_event_source *timer_source;
int repaint_needed;
int repaint_on_timeout;
struct timespec previous_swap;
uint32_t current_frame;
struct wl_event_source *drm_source;
uint32_t modifier_state;
void (*present)(struct wlsc_compositor *c);
};
#define MODIFIER_CTRL (1 << 8)
......@@ -151,15 +129,26 @@ notify_button(struct wlsc_input_device *device, int32_t button, int32_t state);
void
notify_key(struct wlsc_input_device *device, uint32_t key, uint32_t state);
void
wlsc_compositor_present_drm(struct wlsc_compositor *wlsc);
int
wlsc_compositor_init_drm(struct wlsc_compositor *ec);
void
wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
struct wlsc_input_device *
wlsc_input_device_create(struct wlsc_compositor *ec);
int
wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
void
wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
int x, int y, int width, int height);
void
wlsc_input_device_init(struct wlsc_input_device *device,
struct wlsc_compositor *ec);
struct wlsc_compositor *
x11_compositor_create(struct wl_display *display);
struct wlsc_compositor *
drm_compositor_create(struct wl_display *display);
void
screenshooter_create(struct wlsc_compositor *ec);
......
......@@ -5,7 +5,7 @@ PKG_PROG_PKG_CONFIG()
PKG_CHECK_MODULES(FFI, [libffi])
PKG_CHECK_MODULES(COMPOSITOR,
[egl gl libpng cairo gdk-pixbuf-2.0 libudev >= 136 libdrm >= 2.4.17])
[egl gl libpng cairo gdk-pixbuf-2.0 libudev >= 136 libdrm >= 2.4.17] xcb-dri2 xcb-xfixes)
PKG_CHECK_MODULES(CLIENT, [egl gl cairo-gl gdk-pixbuf-2.0 glib-2.0 gobject-2.0])
PKG_CHECK_MODULES(POPPLER, [poppler-glib gdk-2.0])
......
......@@ -342,6 +342,7 @@ wl_event_source_idle_remove(struct wl_event_source *source)
(struct wl_event_source_idle *) source;
wl_list_remove(&idle_source->link);
free(source);
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment