int
main(int argc, char **argv)
{
- struct wl_display *display;
- pepper_compositor_t *compositor;
+ struct wl_display *display;
+ pepper_compositor_t *compositor;
- compositor = pepper_compositor_create("wayland-0");
- display = pepper_compositor_get_display(compositor);
+ compositor = pepper_compositor_create("wayland-0");
+ display = pepper_compositor_get_display(compositor);
- /* Enter main loop. */
- wl_display_run(display);
+ /* Enter main loop. */
+ wl_display_run(display);
- pepper_compositor_destroy(compositor);
+ pepper_compositor_destroy(compositor);
- return 0;
+ return 0;
}
typedef struct shell_seat shell_seat_t;
typedef struct pepper_shell pepper_shell_t;
-struct shell_seat
-{
- desktop_shell_t *shell;
- pepper_seat_t *seat;
- pepper_list_t link;
+struct shell_seat {
+ desktop_shell_t *shell;
+ pepper_seat_t *seat;
+ pepper_list_t link;
- /* Seat's logical device add/remove */
- pepper_event_listener_t *pointer_add_listener;
- pepper_event_listener_t *pointer_remove_listener;
+ /* Seat's logical device add/remove */
+ pepper_event_listener_t *pointer_add_listener;
+ pepper_event_listener_t *pointer_remove_listener;
- pepper_event_listener_t *keyboard_add_listener;
- pepper_event_listener_t *keyboard_remove_listener;
+ pepper_event_listener_t *keyboard_add_listener;
+ pepper_event_listener_t *keyboard_remove_listener;
- pepper_event_listener_t *touch_add_listener;
- pepper_event_listener_t *touch_remove_listener;
+ pepper_event_listener_t *touch_add_listener;
+ pepper_event_listener_t *touch_remove_listener;
};
-struct desktop_shell
-{
- pepper_compositor_t *compositor;
+struct desktop_shell {
+ pepper_compositor_t *compositor;
- pepper_list_t shell_client_list;
- pepper_list_t shell_surface_list;
- pepper_list_t shseat_list;
+ pepper_list_t shell_client_list;
+ pepper_list_t shell_surface_list;
+ pepper_list_t shseat_list;
- struct wl_global *pepper_shell_global;
- struct wl_list pepper_shell_list;
- pepper_surface_t *cursor_surface;
- pepper_view_t *cursor_view;
+ struct wl_global *pepper_shell_global;
+ struct wl_list pepper_shell_list;
+ pepper_surface_t *cursor_surface;
+ pepper_view_t *cursor_view;
- /* input device add/remove listeners */
- pepper_event_listener_t *input_device_add_listener;
+ /* input device add/remove listeners */
+ pepper_event_listener_t *input_device_add_listener;
- /* seat add/remove */
- pepper_event_listener_t *seat_add_listener;
- pepper_event_listener_t *seat_remove_listener;
+ /* seat add/remove */
+ pepper_event_listener_t *seat_add_listener;
+ pepper_event_listener_t *seat_remove_listener;
};
-struct shell_client
-{
- desktop_shell_t *shell;
- struct wl_resource *resource;
- struct wl_client *client;
+struct shell_client {
+ desktop_shell_t *shell;
+ struct wl_resource *resource;
+ struct wl_client *client;
- struct wl_listener client_destroy_listener;
+ struct wl_listener client_destroy_listener;
- /* Ping-Pong */
- struct wl_event_source *ping_timer;
- pepper_bool_t need_pong;
- uint32_t ping_serial;
- pepper_bool_t irresponsive;
+ /* Ping-Pong */
+ struct wl_event_source *ping_timer;
+ pepper_bool_t need_pong;
+ uint32_t ping_serial;
+ pepper_bool_t irresponsive;
- pepper_list_t link;
+ pepper_list_t link;
};
-typedef enum
-{
- SHELL_SURFACE_TYPE_NONE,
- SHELL_SURFACE_TYPE_TOPLEVEL,
- SHELL_SURFACE_TYPE_TRANSIENT,
- SHELL_SURFACE_TYPE_FULLSCREEN,
- SHELL_SURFACE_TYPE_POPUP,
- SHELL_SURFACE_TYPE_MAXIMIZED,
- SHELL_SURFACE_TYPE_MINIMIZED,
+typedef enum {
+ SHELL_SURFACE_TYPE_NONE,
+ SHELL_SURFACE_TYPE_TOPLEVEL,
+ SHELL_SURFACE_TYPE_TRANSIENT,
+ SHELL_SURFACE_TYPE_FULLSCREEN,
+ SHELL_SURFACE_TYPE_POPUP,
+ SHELL_SURFACE_TYPE_MAXIMIZED,
+ SHELL_SURFACE_TYPE_MINIMIZED,
} shell_surface_type_t;
-struct shell_surface
-{
- desktop_shell_t *shell;
-
- shell_client_t *shell_client;
-
- struct wl_client *client;
- struct wl_resource *resource;
-
- /* Hierarchy */
- pepper_surface_t *parent;
- pepper_list_t child_list; /* children surfaces of this */
- pepper_list_t parent_link;
-
- /* Contents */
- pepper_surface_t *surface;
- pepper_view_t *view;
-
- char *title, *class_;
-
- struct
- {
- double x, y;
- int32_t w,h;
- } geometry, next_geometry;
-
- pepper_bool_t has_next_geometry;
-
- const void *old_pointer_grab;
- void *old_pointer_grab_data;
-
- struct
- {
- double dx, dy; /* difference between pointer position and view position */
- } move;
-
- struct
- {
- double px, py; /* pointer x, y */
- double vx, vy; /* view x, y */
- int32_t vw, vh; /* view w, h */
- uint32_t edges;
- pepper_bool_t resizing;
- } resize;
-
- int32_t last_width, last_height;
-
- /* Data structures per surface type */
- shell_surface_type_t type; /* Current surface type */
- shell_surface_type_t next_type; /* Requested surface type */
- pepper_bool_t type_changed;
-
- struct
- {
- double x, y;
- uint32_t flags;
- pepper_seat_t *seat;
- uint32_t serial;
- pepper_bool_t button_up;
- } popup;
-
- struct
- {
- double x, y;
- uint32_t flags;
- } transient;
-
- struct
- {
- pepper_output_t *output;
- } maximized;
-
- struct
- {
- uint32_t method;
- uint32_t framerate;
- pepper_output_t *output;
- double scale;
- } fullscreen;
-
- struct
- {
- double x, y;
- int32_t w, h;
- pepper_output_mode_t mode;
- shell_surface_type_t type;
- } saved;
-
- /* map */
- void (*shell_surface_map)(shell_surface_t *shsurf);
-
- /* configure */
- void (*send_configure)(shell_surface_t *shsurf, int32_t width, int32_t height);
-
- pepper_bool_t ack_configure;
-
- /* Focus */
- pepper_bool_t has_keyboard_focus;
-
- /* Listeners */
- pepper_event_listener_t *surface_destroy_listener;
- pepper_event_listener_t *surface_commit_listener;
-
- pepper_event_listener_t *focus_enter_listener;
- pepper_event_listener_t *focus_leave_listener;
-
- pepper_list_t link;
+struct shell_surface {
+ desktop_shell_t *shell;
+
+ shell_client_t *shell_client;
+
+ struct wl_client *client;
+ struct wl_resource *resource;
+
+ /* Hierarchy */
+ pepper_surface_t *parent;
+ pepper_list_t child_list; /* children surfaces of this */
+ pepper_list_t parent_link;
+
+ /* Contents */
+ pepper_surface_t *surface;
+ pepper_view_t *view;
+
+ char *title, *class_;
+
+ struct {
+ double x, y;
+ int32_t w, h;
+ } geometry, next_geometry;
+
+ pepper_bool_t has_next_geometry;
+
+ const void *old_pointer_grab;
+ void *old_pointer_grab_data;
+
+ struct {
+ double dx,
+ dy; /* difference between pointer position and view position */
+ } move;
+
+ struct {
+ double px, py; /* pointer x, y */
+ double vx, vy; /* view x, y */
+ int32_t vw, vh; /* view w, h */
+ uint32_t edges;
+ pepper_bool_t resizing;
+ } resize;
+
+ int32_t last_width, last_height;
+
+ /* Data structures per surface type */
+ shell_surface_type_t type; /* Current surface type */
+ shell_surface_type_t next_type; /* Requested surface type */
+ pepper_bool_t type_changed;
+
+ struct {
+ double x, y;
+ uint32_t flags;
+ pepper_seat_t *seat;
+ uint32_t serial;
+ pepper_bool_t button_up;
+ } popup;
+
+ struct {
+ double x, y;
+ uint32_t flags;
+ } transient;
+
+ struct {
+ pepper_output_t *output;
+ } maximized;
+
+ struct {
+ uint32_t method;
+ uint32_t framerate;
+ pepper_output_t *output;
+ double scale;
+ } fullscreen;
+
+ struct {
+ double x, y;
+ int32_t w, h;
+ pepper_output_mode_t mode;
+ shell_surface_type_t type;
+ } saved;
+
+ /* map */
+ void (*shell_surface_map)(shell_surface_t *shsurf);
+
+ /* configure */
+ void (*send_configure)(shell_surface_t *shsurf, int32_t width, int32_t height);
+
+ pepper_bool_t ack_configure;
+
+ /* Focus */
+ pepper_bool_t has_keyboard_focus;
+
+ /* Listeners */
+ pepper_event_listener_t *surface_destroy_listener;
+ pepper_event_listener_t *surface_commit_listener;
+
+ pepper_event_listener_t *focus_enter_listener;
+ pepper_event_listener_t *focus_leave_listener;
+
+ pepper_list_t link;
};
shell_client_t *
shell_client_create(desktop_shell_t *shell, struct wl_client *client,
- const struct wl_interface *interface, const void *implementation,
- uint32_t version, uint32_t id);
+ const struct wl_interface *interface, const void *implementation,
+ uint32_t version, uint32_t id);
shell_surface_t *
-shell_surface_create(shell_client_t *shell, pepper_surface_t *surface, struct wl_client *client,
- const struct wl_interface *interface,
- const void *implemenetation, uint32_t version, uint32_t id);
+shell_surface_create(shell_client_t *shell, pepper_surface_t *surface,
+ struct wl_client *client,
+ const struct wl_interface *interface,
+ const void *implemenetation, uint32_t version, uint32_t id);
void
shell_surface_ping(shell_surface_t *shsurf);
remove_ping_timer(shell_client_t *shell_client);
void
-shell_surface_set_next_type(shell_surface_t *shsurf, shell_surface_type_t new_type);
+shell_surface_set_next_type(shell_surface_t *shsurf,
+ shell_surface_type_t new_type);
void
shell_surface_set_parent(shell_surface_t *shsurf, pepper_surface_t *parent);
set_shsurf_to_surface(pepper_surface_t *surface, shell_surface_t *shsurf);
pepper_bool_t
-shell_surface_set_title(shell_surface_t *shsurf, const char* title);
+shell_surface_set_title(shell_surface_t *shsurf, const char *title);
pepper_bool_t
-shell_surface_set_class(shell_surface_t *shsurf, const char* class_);
+shell_surface_set_class(shell_surface_t *shsurf, const char *class_);
void
shell_surface_set_toplevel(shell_surface_t *shsurf);
void
-shell_surface_set_popup(shell_surface_t *shsurf, pepper_seat_t *seat, pepper_surface_t *parent,
- double x, double y, uint32_t flags, uint32_t serial);
+shell_surface_set_popup(shell_surface_t *shsurf, pepper_seat_t *seat,
+ pepper_surface_t *parent,
+ double x, double y, uint32_t flags, uint32_t serial);
void
shell_surface_set_transient(shell_surface_t *shsurf, pepper_surface_t *parent,
- double x, double y, uint32_t flags);
+ double x, double y, uint32_t flags);
void
shell_surface_ack_configure(shell_surface_t *shsurf, uint32_t serial);
void
-shell_surface_set_geometry(shell_surface_t *shsurf, double x, double y, int32_t w, int32_t h);
+shell_surface_set_geometry(shell_surface_t *shsurf, double x, double y,
+ int32_t w, int32_t h);
void
shell_surface_set_maximized(shell_surface_t *shsurf, pepper_output_t *output);
void
shell_surface_set_fullscreen(shell_surface_t *shsurf, pepper_output_t *output,
- uint32_t method, uint32_t framerate);
+ uint32_t method, uint32_t framerate);
void
shell_surface_unset_fullscreen(shell_surface_t *shsurf);
void
shell_get_output_workarea(desktop_shell_t *shell, pepper_output_t *output,
- pixman_rectangle32_t *area);
+ pixman_rectangle32_t *area);
pepper_bool_t
fini_xdg_shell(desktop_shell_t *shell);
void
-shell_surface_move(shell_surface_t *shsurf, pepper_seat_t *seat, uint32_t serial);
+shell_surface_move(shell_surface_t *shsurf, pepper_seat_t *seat,
+ uint32_t serial);
void
-shell_surface_resize(shell_surface_t *shsurf, pepper_seat_t *seat, uint32_t serial, uint32_t edges);
+shell_surface_resize(shell_surface_t *shsurf, pepper_seat_t *seat,
+ uint32_t serial, uint32_t edges);
void
shell_surface_set_position(shell_surface_t *shsurf, double x, double y);
void
shell_surface_place_fullscreen_surface(shell_surface_t *shsurf);
-struct pepper_shell
-{
- desktop_shell_t *shell;
+struct pepper_shell {
+ desktop_shell_t *shell;
- struct wl_resource *resource;
- struct wl_client *client;
+ struct wl_resource *resource;
+ struct wl_client *client;
- pepper_surface_t *cursor;
+ pepper_surface_t *cursor;
- pepper_list_t link;
+ pepper_list_t link;
};
pepper_bool_t
static void
pepper_shell_destroy(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
static void
pepper_shell_set_cursor(struct wl_client *client, struct wl_resource *resource,
- struct wl_resource *surface_resource)
+ struct wl_resource *surface_resource)
{
- desktop_shell_t *shell = wl_resource_get_user_data(resource);
- pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
-
- if (surface != shell->cursor_surface)
- {
- if (!shell->cursor_view)
- {
- shell->cursor_view = pepper_compositor_add_view(shell->compositor);
-
- if (!shell->cursor_view)
- {
- wl_client_post_no_memory(client);
- return;
- }
- }
-
- if (!pepper_surface_set_role(surface, "pepper_cursor"))
- {
- wl_resource_post_error(resource, PEPPER_SHELL_ERROR_ROLE, "Already has a role");
- return;
- }
-
- pepper_view_set_surface(shell->cursor_view, surface);
- pepper_view_map(shell->cursor_view);
-
- /* TODO: Cursor view management. */
- }
+ desktop_shell_t *shell = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
+
+ if (surface != shell->cursor_surface) {
+ if (!shell->cursor_view) {
+ shell->cursor_view = pepper_compositor_add_view(shell->compositor);
+
+ if (!shell->cursor_view) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+ }
+
+ if (!pepper_surface_set_role(surface, "pepper_cursor")) {
+ wl_resource_post_error(resource, PEPPER_SHELL_ERROR_ROLE, "Already has a role");
+ return;
+ }
+
+ pepper_view_set_surface(shell->cursor_view, surface);
+ pepper_view_map(shell->cursor_view);
+
+ /* TODO: Cursor view management. */
+ }
}
-static const struct pepper_shell_interface pepper_shell_implementation =
-{
- pepper_shell_destroy,
- pepper_shell_set_cursor,
+static const struct pepper_shell_interface pepper_shell_implementation = {
+ pepper_shell_destroy,
+ pepper_shell_set_cursor,
};
static void
unbind_resource(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
static void
-bind_pepper_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
+bind_pepper_shell(struct wl_client *client, void *data, uint32_t version,
+ uint32_t id)
{
- desktop_shell_t *shell = data;
- struct wl_resource *resource;
-
- resource = wl_resource_create(client, &pepper_shell_interface, version, id);
- if (!resource)
- {
- wl_client_post_no_memory(client);
- return;
- }
-
- wl_list_insert(&shell->pepper_shell_list, wl_resource_get_link(resource));
- wl_resource_set_implementation(resource, &pepper_shell_implementation, shell, unbind_resource);
- wl_resource_set_user_data(resource, shell);
+ desktop_shell_t *shell = data;
+ struct wl_resource *resource;
+
+ resource = wl_resource_create(client, &pepper_shell_interface, version, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_list_insert(&shell->pepper_shell_list, wl_resource_get_link(resource));
+ wl_resource_set_implementation(resource, &pepper_shell_implementation, shell,
+ unbind_resource);
+ wl_resource_set_user_data(resource, shell);
}
pepper_bool_t
init_pepper_shell(desktop_shell_t *shell)
{
- struct wl_display *display = pepper_compositor_get_display(shell->compositor);
+ struct wl_display *display = pepper_compositor_get_display(shell->compositor);
- shell->pepper_shell_global =
- wl_global_create(display, &pepper_shell_interface, 1, shell, bind_pepper_shell);
+ shell->pepper_shell_global =
+ wl_global_create(display, &pepper_shell_interface, 1, shell, bind_pepper_shell);
- if (!shell->pepper_shell_global)
- return PEPPER_FALSE;
+ if (!shell->pepper_shell_global)
+ return PEPPER_FALSE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
void
fini_pepper_shell(desktop_shell_t *shell)
{
- struct wl_resource *res, *tmp;
+ struct wl_resource *res, *tmp;
- if (shell->pepper_shell_global)
- {
- wl_global_destroy(shell->pepper_shell_global);
- shell->pepper_shell_global = NULL;
- }
+ if (shell->pepper_shell_global) {
+ wl_global_destroy(shell->pepper_shell_global);
+ shell->pepper_shell_global = NULL;
+ }
- wl_resource_for_each_safe(res, tmp, &shell->pepper_shell_list)
- wl_resource_destroy(res);
+ wl_resource_for_each_safe(res, tmp, &shell->pepper_shell_list)
+ wl_resource_destroy(res);
}
#define CURSOR_WIDTH 32
#define CURSOR_HEIGHT 32
-struct buffer
-{
- struct wl_buffer *buffer;
- int w, h, size;
- void *data;
+struct buffer {
+ struct wl_buffer *buffer;
+ int w, h, size;
+ void *data;
};
-struct cursor
-{
- struct wl_surface *surface;
+struct cursor {
+ struct wl_surface *surface;
- struct wl_callback *frame_callback;
- int frame_done;
- int num_buffers;
- int current_buffer;
- struct buffer buffers[4];
+ struct wl_callback *frame_callback;
+ int frame_done;
+ int num_buffers;
+ int current_buffer;
+ struct buffer buffers[4];
};
-struct display
-{
- struct wl_display *display;
- struct wl_registry *registry;
+struct display {
+ struct wl_display *display;
+ struct wl_registry *registry;
- struct wl_compositor *compositor;
- struct wl_shm *shm;
- struct pepper_shell *shell;
- int run;
+ struct wl_compositor *compositor;
+ struct wl_shm *shm;
+ struct pepper_shell *shell;
+ int run;
- struct cursor cursor;
+ struct cursor cursor;
};
static void
handle_global(void *data, struct wl_registry *registry, uint32_t id,
- const char *interface, uint32_t version)
+ const char *interface, uint32_t version)
{
- struct display *display = data;
-
- if (strcmp(interface, "wl_compositor") == 0)
- display->compositor = wl_registry_bind(registry, id, &wl_compositor_interface, 1);
- else if (strcmp(interface, "wl_shm") == 0)
- display->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
- else if (strcmp(interface, "pepper_shell") == 0)
- display->shell = wl_registry_bind(registry, id, &pepper_shell_interface, 1);
+ struct display *display = data;
+
+ if (strcmp(interface, "wl_compositor") == 0)
+ display->compositor = wl_registry_bind(registry, id, &wl_compositor_interface,
+ 1);
+ else if (strcmp(interface, "wl_shm") == 0)
+ display->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
+ else if (strcmp(interface, "pepper_shell") == 0)
+ display->shell = wl_registry_bind(registry, id, &pepper_shell_interface, 1);
}
static void
{
}
-static const struct wl_registry_listener registry_listener =
-{
- handle_global,
- handle_global_remove,
+static const struct wl_registry_listener registry_listener = {
+ handle_global,
+ handle_global_remove,
};
static void
frame_done(void *data, struct wl_callback *callback, uint32_t time)
{
- struct cursor *cursor = data;
+ struct cursor *cursor = data;
- cursor->frame_done = 1;
+ cursor->frame_done = 1;
- /* TODO: Redraw cursor */
+ /* TODO: Redraw cursor */
}
-static const struct wl_callback_listener frame_listener =
-{
- frame_done
+static const struct wl_callback_listener frame_listener = {
+ frame_done
};
static int
-create_shm_buffer(struct display *display, struct buffer *buffer, int w, int h, uint32_t format)
+create_shm_buffer(struct display *display, struct buffer *buffer, int w, int h,
+ uint32_t format)
{
- struct wl_shm_pool *pool;
- int fd, size, stride;
- void *data;
-
- stride = w * 4;
- size = stride * h;
-
- fd = pepper_create_anonymous_file(size);
- if (fd < 0)
- {
- fprintf(stderr, "pepper_create_anonymous_file() failed.\n");
- return -1;
- }
-
- data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd ,0);
- if (data == MAP_FAILED)
- {
- fprintf(stderr, "mmap() failed.\n");
- close(fd);
- return -1;
- }
-
- pool = wl_shm_create_pool(display->shm, fd, size);
- buffer->buffer = wl_shm_pool_create_buffer(pool, 0, w, h, stride, format);
- wl_shm_pool_destroy(pool);
- close(fd);
-
- buffer->data = data;
- buffer->w = w;
- buffer->h = h;
- buffer->size = size;
-
- return 0;
+ struct wl_shm_pool *pool;
+ int fd, size, stride;
+ void *data;
+
+ stride = w * 4;
+ size = stride * h;
+
+ fd = pepper_create_anonymous_file(size);
+ if (fd < 0) {
+ fprintf(stderr, "pepper_create_anonymous_file() failed.\n");
+ return -1;
+ }
+
+ data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd , 0);
+ if (data == MAP_FAILED) {
+ fprintf(stderr, "mmap() failed.\n");
+ close(fd);
+ return -1;
+ }
+
+ pool = wl_shm_create_pool(display->shm, fd, size);
+ buffer->buffer = wl_shm_pool_create_buffer(pool, 0, w, h, stride, format);
+ wl_shm_pool_destroy(pool);
+ close(fd);
+
+ buffer->data = data;
+ buffer->w = w;
+ buffer->h = h;
+ buffer->size = size;
+
+ return 0;
}
static int
init_cursor(struct cursor *cursor, struct display *display)
{
- cursor->surface = wl_compositor_create_surface(display->compositor);
- if (!cursor->surface)
- {
- fprintf(stderr, "wl_compositor_create_surface() failed.\n");
- return -1;
- }
-
- if (!create_shm_buffer(display, &cursor->buffers[0],
- CURSOR_WIDTH, CURSOR_HEIGHT, WL_SHM_FORMAT_XRGB8888))
- {
- fprintf(stderr, "create_shm_buffer() failed.\n");
- return -1;
- }
-
- /* TODO: Draw the initial cursor image. */
- memset(cursor->buffers[0].data, 0xff, cursor->buffers[0].size);
-
- /* Update the surface with the initial buffer. */
- wl_surface_attach(cursor->surface, cursor->buffers[0].buffer, 0, 0);
- wl_surface_damage(cursor->surface, 0, 0, cursor->buffers[0].w, cursor->buffers[0].h);
- cursor->frame_callback = wl_surface_frame(cursor->surface);
- wl_callback_add_listener(cursor->frame_callback, &frame_listener, cursor);
- wl_surface_commit(cursor->surface);
-
- cursor->frame_done = 0;
- pepper_shell_set_cursor(display->shell, cursor->surface);
-
- return 0;
+ cursor->surface = wl_compositor_create_surface(display->compositor);
+ if (!cursor->surface) {
+ fprintf(stderr, "wl_compositor_create_surface() failed.\n");
+ return -1;
+ }
+
+ if (!create_shm_buffer(display, &cursor->buffers[0],
+ CURSOR_WIDTH, CURSOR_HEIGHT, WL_SHM_FORMAT_XRGB8888)) {
+ fprintf(stderr, "create_shm_buffer() failed.\n");
+ return -1;
+ }
+
+ /* TODO: Draw the initial cursor image. */
+ memset(cursor->buffers[0].data, 0xff, cursor->buffers[0].size);
+
+ /* Update the surface with the initial buffer. */
+ wl_surface_attach(cursor->surface, cursor->buffers[0].buffer, 0, 0);
+ wl_surface_damage(cursor->surface, 0, 0, cursor->buffers[0].w,
+ cursor->buffers[0].h);
+ cursor->frame_callback = wl_surface_frame(cursor->surface);
+ wl_callback_add_listener(cursor->frame_callback, &frame_listener, cursor);
+ wl_surface_commit(cursor->surface);
+
+ cursor->frame_done = 0;
+ pepper_shell_set_cursor(display->shell, cursor->surface);
+
+ return 0;
}
static void
fini_cursor(struct cursor *cursor)
{
- int i;
+ int i;
- wl_surface_destroy(cursor->surface);
+ wl_surface_destroy(cursor->surface);
- for (i = 0; i < cursor->num_buffers; i++)
- wl_buffer_destroy(cursor->buffers[i].buffer);
+ for (i = 0; i < cursor->num_buffers; i++)
+ wl_buffer_destroy(cursor->buffers[i].buffer);
}
int
main(int argc, char **argv)
{
- struct display display;
- int ret;
-
- memset(&display, 0x00, sizeof(struct display));
-
- if (argc != 2)
- {
- fprintf(stderr, "socket name was not given.\n");
- return -1;
- }
-
- display.display = wl_display_connect(argv[0]);
- if (!display.display)
- {
- fprintf(stderr, "wl_display_connect(%s) failed\n", argv[0]);
- return -1;
- }
-
- display.registry = wl_display_get_registry(display.display);
- wl_registry_add_listener(display.registry, ®istry_listener, &display);
- wl_display_roundtrip(display.display);
-
- if (display.shm)
- {
- fprintf(stderr, "Couldn't find wl_shm\n");
- return -1;
- }
-
- if (display.compositor)
- {
- fprintf(stderr, "Couldn't find wl_compositor\n");
- return -1;
- }
-
- if (display.shell)
- {
- fprintf(stderr, "Couldn't find pepper_shell\n");
- return -1;
- }
-
- init_cursor(&display.cursor, &display);
-
- display.run = 1;
- ret = 0;
-
- while (display.run && ret != -1)
- ret = wl_display_dispatch(display.display);
-
- fini_cursor(&display.cursor);
-
- wl_shm_destroy(display.shm);
- wl_compositor_destroy(display.compositor);
- pepper_shell_destroy(display.shell);
- wl_display_disconnect(display.display);
-
- return 0;
+ struct display display;
+ int ret;
+
+ memset(&display, 0x00, sizeof(struct display));
+
+ if (argc != 2) {
+ fprintf(stderr, "socket name was not given.\n");
+ return -1;
+ }
+
+ display.display = wl_display_connect(argv[0]);
+ if (!display.display) {
+ fprintf(stderr, "wl_display_connect(%s) failed\n", argv[0]);
+ return -1;
+ }
+
+ display.registry = wl_display_get_registry(display.display);
+ wl_registry_add_listener(display.registry, ®istry_listener, &display);
+ wl_display_roundtrip(display.display);
+
+ if (display.shm) {
+ fprintf(stderr, "Couldn't find wl_shm\n");
+ return -1;
+ }
+
+ if (display.compositor) {
+ fprintf(stderr, "Couldn't find wl_compositor\n");
+ return -1;
+ }
+
+ if (display.shell) {
+ fprintf(stderr, "Couldn't find pepper_shell\n");
+ return -1;
+ }
+
+ init_cursor(&display.cursor, &display);
+
+ display.run = 1;
+ ret = 0;
+
+ while (display.run && ret != -1)
+ ret = wl_display_dispatch(display.display);
+
+ fini_cursor(&display.cursor);
+
+ wl_shm_destroy(display.shm);
+ wl_compositor_destroy(display.compositor);
+ pepper_shell_destroy(display.shell);
+ wl_display_disconnect(display.display);
+
+ return 0;
}
void
remove_ping_timer(shell_client_t *shell_client)
{
- if (shell_client->ping_timer)
- {
- wl_event_source_remove(shell_client->ping_timer);
- shell_client->ping_timer = NULL;
- }
+ if (shell_client->ping_timer) {
+ wl_event_source_remove(shell_client->ping_timer);
+ shell_client->ping_timer = NULL;
+ }
}
static void
handle_surface_commit(pepper_event_listener_t *listener,
- pepper_object_t *surface, uint32_t id, void *info, void *data)
+ pepper_object_t *surface, uint32_t id, void *info, void *data)
{
- shell_surface_t *shsurf = data;
+ shell_surface_t *shsurf = data;
- int vw, vh;
- double sx, sy;
+ int vw, vh;
+ double sx, sy;
- if (shsurf->has_next_geometry)
- {
- shsurf->geometry = shsurf->next_geometry;
- shsurf->has_next_geometry = PEPPER_FALSE;
- }
+ if (shsurf->has_next_geometry) {
+ shsurf->geometry = shsurf->next_geometry;
+ shsurf->has_next_geometry = PEPPER_FALSE;
+ }
- if (shsurf->type_changed && shsurf->ack_configure && shsurf->shell_surface_map)
- {
- shsurf->shell_surface_map(shsurf);
+ if (shsurf->type_changed && shsurf->ack_configure &&
+ shsurf->shell_surface_map) {
+ shsurf->shell_surface_map(shsurf);
- shsurf->type_changed = PEPPER_FALSE;
- shsurf->type = shsurf->next_type;
- shsurf->next_type = SHELL_SURFACE_TYPE_NONE;
- }
+ shsurf->type_changed = PEPPER_FALSE;
+ shsurf->type = shsurf->next_type;
+ shsurf->next_type = SHELL_SURFACE_TYPE_NONE;
+ }
- pepper_view_get_size(shsurf->view, &vw, &vh);
+ pepper_view_get_size(shsurf->view, &vw, &vh);
- sx = (vw - shsurf->last_width);
- sy = (vh - shsurf->last_height);
+ sx = (vw - shsurf->last_width);
+ sy = (vh - shsurf->last_height);
- if (sx || sy)
- {
- double vx, vy;
+ if (sx || sy) {
+ double vx, vy;
- pepper_view_get_position(shsurf->view, &vx, &vy);
+ pepper_view_get_position(shsurf->view, &vx, &vy);
- if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_LEFT)
- vx = vx - sx;
+ if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_LEFT)
+ vx = vx - sx;
- if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_TOP)
- vy = vy - sy;
+ if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_TOP)
+ vy = vy - sy;
- shell_surface_set_position(shsurf, vx, vy);
+ shell_surface_set_position(shsurf, vx, vy);
- shsurf->last_width = vw;
- shsurf->last_height = vh;
- }
+ shsurf->last_width = vw;
+ shsurf->last_height = vh;
+ }
}
static void
static void
handle_surface_destroy(pepper_event_listener_t *listener,
- pepper_object_t *surface, uint32_t id, void *info, void *data)
+ pepper_object_t *surface, uint32_t id, void *info, void *data)
{
- shell_surface_t *shsurf = data;
- shell_surface_t *child, *tmp;
+ shell_surface_t *shsurf = data;
+ shell_surface_t *child, *tmp;
- if (shsurf->type == SHELL_SURFACE_TYPE_POPUP)
- {
- shell_surface_end_popup_grab(shsurf);
- }
+ if (shsurf->type == SHELL_SURFACE_TYPE_POPUP) {
+ shell_surface_end_popup_grab(shsurf);
+ }
- pepper_event_listener_remove(shsurf->surface_destroy_listener);
- pepper_event_listener_remove(shsurf->surface_commit_listener);
+ pepper_event_listener_remove(shsurf->surface_destroy_listener);
+ pepper_event_listener_remove(shsurf->surface_commit_listener);
- pepper_event_listener_remove(shsurf->focus_enter_listener);
- pepper_event_listener_remove(shsurf->focus_leave_listener);
+ pepper_event_listener_remove(shsurf->focus_enter_listener);
+ pepper_event_listener_remove(shsurf->focus_leave_listener);
- pepper_view_destroy(shsurf->view);
+ pepper_view_destroy(shsurf->view);
- if (shsurf->resource)
- wl_resource_destroy(shsurf->resource);
+ if (shsurf->resource)
+ wl_resource_destroy(shsurf->resource);
- if (shsurf->title)
- free(shsurf->title);
+ if (shsurf->title)
+ free(shsurf->title);
- if (shsurf->class_)
- free(shsurf->class_);
+ if (shsurf->class_)
+ free(shsurf->class_);
- pepper_list_for_each_safe(child, tmp, &shsurf->child_list, parent_link)
- shell_surface_set_parent(child, NULL);
+ pepper_list_for_each_safe(child, tmp, &shsurf->child_list, parent_link)
+ shell_surface_set_parent(child, NULL);
- pepper_list_remove(&shsurf->parent_link);
- pepper_list_remove(&shsurf->link);
+ pepper_list_remove(&shsurf->parent_link);
+ pepper_list_remove(&shsurf->link);
- free(shsurf);
+ free(shsurf);
}
static void
handle_resource_destroy(struct wl_resource *resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shsurf->resource = NULL;
+ shsurf->resource = NULL;
}
static void
-shsurf_wl_shell_surface_send_configure(shell_surface_t *shsurf, int32_t width, int32_t height)
+shsurf_wl_shell_surface_send_configure(shell_surface_t *shsurf, int32_t width,
+ int32_t height)
{
- uint32_t edges = 0; /* FIXME */
+ uint32_t edges = 0; /* FIXME */
- wl_shell_surface_send_configure(shsurf->resource,
- edges,
- width,
- height);
+ wl_shell_surface_send_configure(shsurf->resource,
+ edges,
+ width,
+ height);
- /* wl_shell_surface dont need this */
- shsurf->ack_configure = PEPPER_TRUE;
+ /* wl_shell_surface dont need this */
+ shsurf->ack_configure = PEPPER_TRUE;
}
static void
-shsurf_xdg_surface_send_configure(shell_surface_t *shsurf, int32_t width, int32_t height)
-{
- struct wl_display *display;
- struct wl_array states;
- uint32_t *state;
- uint32_t serial;
- shell_surface_type_t type;
-
- if (shsurf->type_changed)
- type = shsurf->next_type;
- else
- type = shsurf->type;
-
- wl_array_init(&states);
-
- if (type == SHELL_SURFACE_TYPE_MAXIMIZED)
- {
- state = wl_array_add(&states, sizeof(uint32_t));
- *state = XDG_SURFACE_STATE_MAXIMIZED;
-
- if (!width && !height)
- {
- pixman_rectangle32_t area;
- shell_get_output_workarea(shsurf->shell, shsurf->maximized.output, &area);
-
- width = area.width;
- height = area.height;
- }
- }
- else if (type == SHELL_SURFACE_TYPE_FULLSCREEN)
- {
- state = wl_array_add(&states, sizeof(uint32_t));
- *state = XDG_SURFACE_STATE_FULLSCREEN;
-
- if (!width && !height)
- {
- const pepper_output_geometry_t *geom;
-
- geom = pepper_output_get_geometry(shsurf->fullscreen.output);
- width = geom->w;
- height = geom->h;
- }
- }
-
- if (shsurf->resize.resizing )
- {
- state = wl_array_add(&states, sizeof(uint32_t));
- *state = XDG_SURFACE_STATE_RESIZING;
- }
-
- if (shsurf->has_keyboard_focus)
- {
- state = wl_array_add(&states, sizeof(uint32_t));
- *state = XDG_SURFACE_STATE_ACTIVATED;
- }
-
- /* Send configure event */
- display = pepper_compositor_get_display(shsurf->shell->compositor);
- serial = wl_display_next_serial(display);
-
- xdg_surface_send_configure(shsurf->resource,
- width,
- height,
- &states,
- serial);
-
- wl_array_release(&states);
-
- if (shsurf->type_changed && shsurf->type != SHELL_SURFACE_TYPE_NONE)
- shsurf->ack_configure = PEPPER_FALSE;
+shsurf_xdg_surface_send_configure(shell_surface_t *shsurf, int32_t width,
+ int32_t height)
+{
+ struct wl_display *display;
+ struct wl_array states;
+ uint32_t *state;
+ uint32_t serial;
+ shell_surface_type_t type;
+
+ if (shsurf->type_changed)
+ type = shsurf->next_type;
+ else
+ type = shsurf->type;
+
+ wl_array_init(&states);
+
+ if (type == SHELL_SURFACE_TYPE_MAXIMIZED) {
+ state = wl_array_add(&states, sizeof(uint32_t));
+ *state = XDG_SURFACE_STATE_MAXIMIZED;
+
+ if (!width && !height) {
+ pixman_rectangle32_t area;
+ shell_get_output_workarea(shsurf->shell, shsurf->maximized.output, &area);
+
+ width = area.width;
+ height = area.height;
+ }
+ } else if (type == SHELL_SURFACE_TYPE_FULLSCREEN) {
+ state = wl_array_add(&states, sizeof(uint32_t));
+ *state = XDG_SURFACE_STATE_FULLSCREEN;
+
+ if (!width && !height) {
+ const pepper_output_geometry_t *geom;
+
+ geom = pepper_output_get_geometry(shsurf->fullscreen.output);
+ width = geom->w;
+ height = geom->h;
+ }
+ }
+
+ if (shsurf->resize.resizing ) {
+ state = wl_array_add(&states, sizeof(uint32_t));
+ *state = XDG_SURFACE_STATE_RESIZING;
+ }
+
+ if (shsurf->has_keyboard_focus) {
+ state = wl_array_add(&states, sizeof(uint32_t));
+ *state = XDG_SURFACE_STATE_ACTIVATED;
+ }
+
+ /* Send configure event */
+ display = pepper_compositor_get_display(shsurf->shell->compositor);
+ serial = wl_display_next_serial(display);
+
+ xdg_surface_send_configure(shsurf->resource,
+ width,
+ height,
+ &states,
+ serial);
+
+ wl_array_release(&states);
+
+ if (shsurf->type_changed && shsurf->type != SHELL_SURFACE_TYPE_NONE)
+ shsurf->ack_configure = PEPPER_FALSE;
}
static void
-shsurf_xdg_popup_send_configure(shell_surface_t *shsurf, int32_t width, int32_t height)
+shsurf_xdg_popup_send_configure(shell_surface_t *shsurf, int32_t width,
+ int32_t height)
{
- /* Do nothing */
+ /* Do nothing */
}
static pepper_bool_t
shsurf_is_wl_shell_surface(shell_surface_t *shsurf)
{
- return (shsurf->send_configure == shsurf_wl_shell_surface_send_configure);
+ return (shsurf->send_configure == shsurf_wl_shell_surface_send_configure);
}
static pepper_bool_t
shsurf_is_xdg_surface(shell_surface_t *shsurf)
{
- return (shsurf->send_configure == shsurf_xdg_surface_send_configure);
+ return (shsurf->send_configure == shsurf_xdg_surface_send_configure);
}
static pepper_bool_t
shsurf_is_xdg_popup(shell_surface_t *shsurf)
{
- return (shsurf->send_configure == shsurf_xdg_popup_send_configure);
+ return (shsurf->send_configure == shsurf_xdg_popup_send_configure);
}
static void
shell_surface_focus_enter(shell_surface_t *shsurf)
{
- shsurf->has_keyboard_focus = PEPPER_TRUE;
+ shsurf->has_keyboard_focus = PEPPER_TRUE;
}
static void
shell_surface_focus_leave(shell_surface_t *shsurf)
{
- shsurf->has_keyboard_focus = PEPPER_FALSE;
+ shsurf->has_keyboard_focus = PEPPER_FALSE;
}
static void
shell_surface_handle_pointer_focus(shell_surface_t *shsurf, uint32_t id)
{
- if (id == PEPPER_EVENT_FOCUS_ENTER)
- shell_surface_ping(shsurf);
+ if (id == PEPPER_EVENT_FOCUS_ENTER)
+ shell_surface_ping(shsurf);
}
static void
shell_surface_handle_keyboard_focus(shell_surface_t *shsurf, uint32_t id)
{
- if (id == PEPPER_EVENT_FOCUS_ENTER)
- shell_surface_focus_enter(shsurf);
- else
- shell_surface_focus_leave(shsurf);
+ if (id == PEPPER_EVENT_FOCUS_ENTER)
+ shell_surface_focus_enter(shsurf);
+ else
+ shell_surface_focus_leave(shsurf);
- /* Send state changed configure */
- shsurf->send_configure(shsurf, 0, 0);
+ /* Send state changed configure */
+ shsurf->send_configure(shsurf, 0, 0);
}
static void
handle_focus(pepper_event_listener_t *listener,
- pepper_object_t *view, uint32_t id, void *info, void *data)
-{
- pepper_object_type_t type = pepper_object_get_type((pepper_object_t *)info);
-
- switch (type)
- {
- case PEPPER_OBJECT_POINTER:
- shell_surface_handle_pointer_focus(data, id);
- break;
- case PEPPER_OBJECT_KEYBOARD:
- shell_surface_handle_keyboard_focus(data, id);
- break;
- case PEPPER_OBJECT_TOUCH:
- /* TODO */
- break;
- default:
- break;
- }
+ pepper_object_t *view, uint32_t id, void *info, void *data)
+{
+ pepper_object_type_t type = pepper_object_get_type((pepper_object_t *)info);
+
+ switch (type) {
+ case PEPPER_OBJECT_POINTER:
+ shell_surface_handle_pointer_focus(data, id);
+ break;
+ case PEPPER_OBJECT_KEYBOARD:
+ shell_surface_handle_keyboard_focus(data, id);
+ break;
+ case PEPPER_OBJECT_TOUCH:
+ /* TODO */
+ break;
+ default:
+ break;
+ }
}
shell_surface_t *
shell_surface_create(shell_client_t *shell_client, pepper_surface_t *surface,
- struct wl_client *client, const struct wl_interface *interface,
- const void *implementation, uint32_t version, uint32_t id)
+ struct wl_client *client, const struct wl_interface *interface,
+ const void *implementation, uint32_t version, uint32_t id)
{
- shell_surface_t *shsurf = NULL;
- const char *role = NULL;
+ shell_surface_t *shsurf = NULL;
+ const char *role = NULL;
- shsurf = calloc(1, sizeof(shell_surface_t));
- if (!shsurf)
- {
- PEPPER_ERROR("Memory allocation faiiled\n");
- goto error;
- }
+ shsurf = calloc(1, sizeof(shell_surface_t));
+ if (!shsurf) {
+ PEPPER_ERROR("Memory allocation faiiled\n");
+ goto error;
+ }
- shsurf->resource = wl_resource_create(client, interface, version, id);
- if (!shsurf->resource)
- {
- PEPPER_ERROR("wl_resource_create failed\n");
- goto error;
- }
+ shsurf->resource = wl_resource_create(client, interface, version, id);
+ if (!shsurf->resource) {
+ PEPPER_ERROR("wl_resource_create failed\n");
+ goto error;
+ }
- shsurf->shell_client = shell_client;
- shsurf->shell = shell_client->shell;
- shsurf->client = client;
- shsurf->surface = surface;
+ shsurf->shell_client = shell_client;
+ shsurf->shell = shell_client->shell;
+ shsurf->client = client;
+ shsurf->surface = surface;
- shsurf->view = pepper_compositor_add_view(shell_client->shell->compositor);
- if (!shsurf->view)
- {
- PEPPER_ERROR("pepper_compositor_add_view failed\n");
- goto error;
- }
+ shsurf->view = pepper_compositor_add_view(shell_client->shell->compositor);
+ if (!shsurf->view) {
+ PEPPER_ERROR("pepper_compositor_add_view failed\n");
+ goto error;
+ }
- if (!pepper_view_set_surface(shsurf->view, surface))
- {
- PEPPER_ERROR("pepper_view_set_surface() failed.\n");
- goto error;
- }
+ if (!pepper_view_set_surface(shsurf->view, surface)) {
+ PEPPER_ERROR("pepper_view_set_surface() failed.\n");
+ goto error;
+ }
- pepper_list_init(&shsurf->child_list);
- pepper_list_init(&shsurf->parent_link);
- pepper_list_insert(&shsurf->shell->shell_surface_list, &shsurf->link);
+ pepper_list_init(&shsurf->child_list);
+ pepper_list_init(&shsurf->parent_link);
+ pepper_list_insert(&shsurf->shell->shell_surface_list, &shsurf->link);
- wl_resource_set_implementation(shsurf->resource, implementation, shsurf, handle_resource_destroy);
+ wl_resource_set_implementation(shsurf->resource, implementation, shsurf,
+ handle_resource_destroy);
- shsurf->surface_destroy_listener =
- pepper_object_add_event_listener((pepper_object_t *)surface, PEPPER_EVENT_OBJECT_DESTROY, 0,
- handle_surface_destroy, shsurf);
+ shsurf->surface_destroy_listener =
+ pepper_object_add_event_listener((pepper_object_t *)surface,
+ PEPPER_EVENT_OBJECT_DESTROY, 0,
+ handle_surface_destroy, shsurf);
- shsurf->surface_commit_listener =
- pepper_object_add_event_listener((pepper_object_t *)surface, PEPPER_EVENT_SURFACE_COMMIT, 0,
- handle_surface_commit, shsurf);
+ shsurf->surface_commit_listener =
+ pepper_object_add_event_listener((pepper_object_t *)surface,
+ PEPPER_EVENT_SURFACE_COMMIT, 0,
+ handle_surface_commit, shsurf);
- shsurf->focus_enter_listener =
- pepper_object_add_event_listener((pepper_object_t *)shsurf->view, PEPPER_EVENT_FOCUS_ENTER, 0,
- handle_focus, shsurf);
+ shsurf->focus_enter_listener =
+ pepper_object_add_event_listener((pepper_object_t *)shsurf->view,
+ PEPPER_EVENT_FOCUS_ENTER, 0,
+ handle_focus, shsurf);
- shsurf->focus_leave_listener =
- pepper_object_add_event_listener((pepper_object_t *)shsurf->view, PEPPER_EVENT_FOCUS_LEAVE, 0,
- handle_focus, shsurf);
+ shsurf->focus_leave_listener =
+ pepper_object_add_event_listener((pepper_object_t *)shsurf->view,
+ PEPPER_EVENT_FOCUS_LEAVE, 0,
+ handle_focus, shsurf);
- shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_NONE);
+ shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_NONE);
- set_shsurf_to_surface(surface, shsurf);
+ set_shsurf_to_surface(surface, shsurf);
- role = pepper_surface_get_role(shsurf->surface);
+ role = pepper_surface_get_role(shsurf->surface);
- if (!strcmp(role, "wl_shell_surface"))
- shsurf->send_configure = shsurf_wl_shell_surface_send_configure;
- else if (!strcmp(role, "xdg_surface"))
- shsurf->send_configure = shsurf_xdg_surface_send_configure;
- else if (!strcmp(role, "xdg_popup"))
- shsurf->send_configure = shsurf_xdg_popup_send_configure;
+ if (!strcmp(role, "wl_shell_surface"))
+ shsurf->send_configure = shsurf_wl_shell_surface_send_configure;
+ else if (!strcmp(role, "xdg_surface"))
+ shsurf->send_configure = shsurf_xdg_surface_send_configure;
+ else if (!strcmp(role, "xdg_popup"))
+ shsurf->send_configure = shsurf_xdg_popup_send_configure;
- shsurf->ack_configure = PEPPER_TRUE;
+ shsurf->ack_configure = PEPPER_TRUE;
- return shsurf;
+ return shsurf;
error:
- if (shsurf)
- free(shsurf);
+ if (shsurf)
+ free(shsurf);
- return NULL;
+ return NULL;
}
static int
handle_ping_timeout(void *data)
{
- shell_client_t *shell_client = data;
+ shell_client_t *shell_client = data;
- shell_client->irresponsive = PEPPER_TRUE;
+ shell_client->irresponsive = PEPPER_TRUE;
- /* TODO: Display wait cursor */
+ /* TODO: Display wait cursor */
- return 1;
+ return 1;
}
void
shell_surface_ping(shell_surface_t *shsurf)
{
- shell_client_t *shell_client = shsurf->shell_client;
- struct wl_display *display;
+ shell_client_t *shell_client = shsurf->shell_client;
+ struct wl_display *display;
- /* Already stucked, do not send another ping */
- if (shell_client->irresponsive)
- {
- handle_ping_timeout(shell_client);
- return ;
- }
+ /* Already stucked, do not send another ping */
+ if (shell_client->irresponsive) {
+ handle_ping_timeout(shell_client);
+ return ;
+ }
- display = pepper_compositor_get_display(shsurf->shell->compositor);
+ display = pepper_compositor_get_display(shsurf->shell->compositor);
- if (!shell_client->ping_timer)
- {
- struct wl_event_loop *loop = wl_display_get_event_loop(display);
+ if (!shell_client->ping_timer) {
+ struct wl_event_loop *loop = wl_display_get_event_loop(display);
- shell_client->ping_timer = wl_event_loop_add_timer(loop, handle_ping_timeout, shell_client);
+ shell_client->ping_timer = wl_event_loop_add_timer(loop, handle_ping_timeout,
+ shell_client);
- if (!shell_client->ping_timer)
- {
- PEPPER_ERROR("Failed to add timer event source.\n");
- return;
- }
- }
+ if (!shell_client->ping_timer) {
+ PEPPER_ERROR("Failed to add timer event source.\n");
+ return;
+ }
+ }
- wl_event_source_timer_update(shell_client->ping_timer, DESKTOP_SHELL_PING_TIMEOUT);
+ wl_event_source_timer_update(shell_client->ping_timer,
+ DESKTOP_SHELL_PING_TIMEOUT);
- shell_client->ping_serial = wl_display_next_serial(display);
- shell_client->need_pong = PEPPER_TRUE;
+ shell_client->ping_serial = wl_display_next_serial(display);
+ shell_client->need_pong = PEPPER_TRUE;
- if (shsurf_is_wl_shell_surface(shsurf))
- wl_shell_surface_send_ping(shsurf->resource, shell_client->ping_serial);
- else if (shsurf_is_xdg_surface(shsurf) || shsurf_is_xdg_popup(shsurf))
- xdg_shell_send_ping(shell_client->resource, shell_client->ping_serial);
+ if (shsurf_is_wl_shell_surface(shsurf))
+ wl_shell_surface_send_ping(shsurf->resource, shell_client->ping_serial);
+ else if (shsurf_is_xdg_surface(shsurf) || shsurf_is_xdg_popup(shsurf))
+ xdg_shell_send_ping(shell_client->resource, shell_client->ping_serial);
}
void
shell_client_handle_pong(shell_client_t *shell_client, uint32_t serial)
{
- /* Client response right ping_serial */
- if (shell_client->need_pong && shell_client->ping_serial == serial)
- {
- wl_event_source_timer_update(shell_client->ping_timer, 0); /* disarms the timer */
+ /* Client response right ping_serial */
+ if (shell_client->need_pong && shell_client->ping_serial == serial) {
+ wl_event_source_timer_update(shell_client->ping_timer,
+ 0); /* disarms the timer */
- shell_client->irresponsive = PEPPER_FALSE;
- shell_client->need_pong = PEPPER_FALSE;
- shell_client->ping_serial = 0;
+ shell_client->irresponsive = PEPPER_FALSE;
+ shell_client->need_pong = PEPPER_FALSE;
+ shell_client->ping_serial = 0;
- /* TODO: Stop displaying wait cursor */
- }
+ /* TODO: Stop displaying wait cursor */
+ }
}
void
shell_surface_handle_pong(shell_surface_t *shsurf, uint32_t serial)
{
- shell_client_handle_pong(shsurf->shell_client, serial);
+ shell_client_handle_pong(shsurf->shell_client, serial);
}
static void
switch_output_mode(pepper_output_t *output, pepper_output_mode_t *mode)
{
- pepper_output_mode_t best_mode = {.w = (uint32_t)-1,.h = (uint32_t)-1,}, tmp_mode;
- int i, mode_count;
+ pepper_output_mode_t best_mode = {.w = (uint32_t) - 1, .h = (uint32_t) - 1,},
+ tmp_mode;
+ int i, mode_count;
- /* TODO: Find the output mode to the smallest mode that can fit */
+ /* TODO: Find the output mode to the smallest mode that can fit */
- mode_count = pepper_output_get_mode_count(output);
+ mode_count = pepper_output_get_mode_count(output);
- for (i=0; i<mode_count; ++i)
- {
- pepper_output_get_mode(output, i, &tmp_mode);
+ for (i = 0; i < mode_count; ++i) {
+ pepper_output_get_mode(output, i, &tmp_mode);
- if (tmp_mode.w >= mode->w && tmp_mode.h >= mode->h)
- {
- if(best_mode.w > tmp_mode.w && best_mode.h > tmp_mode.h)
- best_mode = tmp_mode;
- }
- }
+ if (tmp_mode.w >= mode->w && tmp_mode.h >= mode->h) {
+ if (best_mode.w > tmp_mode.w && best_mode.h > tmp_mode.h)
+ best_mode = tmp_mode;
+ }
+ }
- if ( (uint32_t)best_mode.w != (uint32_t)-1)
- pepper_output_set_mode(output, &best_mode);
+ if ( (uint32_t)best_mode.w != (uint32_t) - 1)
+ pepper_output_set_mode(output, &best_mode);
}
void
shell_surface_set_toplevel(shell_surface_t *shsurf)
{
- if (shsurf->type == SHELL_SURFACE_TYPE_TOPLEVEL)
- return ;
+ if (shsurf->type == SHELL_SURFACE_TYPE_TOPLEVEL)
+ return ;
- if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN &&
- shsurf->fullscreen.method == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
- {
- switch_output_mode(shsurf->fullscreen.output, &shsurf->saved.mode);
- }
+ if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN &&
+ shsurf->fullscreen.method == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) {
+ switch_output_mode(shsurf->fullscreen.output, &shsurf->saved.mode);
+ }
- shell_surface_set_parent(shsurf, NULL);
+ shell_surface_set_parent(shsurf, NULL);
- shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_TOPLEVEL);
+ shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_TOPLEVEL);
- if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
- shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
- shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED)
- {
- shsurf->send_configure(shsurf, shsurf->saved.w, shsurf->saved.h);
- }
+ if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
+ shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
+ shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED) {
+ shsurf->send_configure(shsurf, shsurf->saved.w, shsurf->saved.h);
+ }
}
void
shell_surface_set_popup(shell_surface_t *shsurf,
- pepper_seat_t *seat,
- pepper_surface_t *parent,
- double x,
- double y,
- uint32_t flags,
- uint32_t serial)
+ pepper_seat_t *seat,
+ pepper_surface_t *parent,
+ double x,
+ double y,
+ uint32_t flags,
+ uint32_t serial)
{
- if (shsurf->type == SHELL_SURFACE_TYPE_POPUP)
- return ;
+ if (shsurf->type == SHELL_SURFACE_TYPE_POPUP)
+ return ;
- shell_surface_set_parent(shsurf, parent);
+ shell_surface_set_parent(shsurf, parent);
- shsurf->popup.x = x;
- shsurf->popup.y = y;
- shsurf->popup.flags = flags;
- shsurf->popup.seat = seat;
- shsurf->popup.serial = serial;
+ shsurf->popup.x = x;
+ shsurf->popup.y = y;
+ shsurf->popup.flags = flags;
+ shsurf->popup.seat = seat;
+ shsurf->popup.serial = serial;
- shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_POPUP);
+ shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_POPUP);
}
void
shell_surface_set_transient(shell_surface_t *shsurf,
- pepper_surface_t *parent,
- double x,
- double y,
- uint32_t flags)
+ pepper_surface_t *parent,
+ double x,
+ double y,
+ uint32_t flags)
{
- if (shsurf->type == SHELL_SURFACE_TYPE_TRANSIENT)
- return ;
+ if (shsurf->type == SHELL_SURFACE_TYPE_TRANSIENT)
+ return ;
- shell_surface_set_parent(shsurf, parent);
+ shell_surface_set_parent(shsurf, parent);
- shsurf->transient.x = x;
- shsurf->transient.y = y;
- shsurf->transient.flags = flags;
+ shsurf->transient.x = x;
+ shsurf->transient.y = y;
+ shsurf->transient.flags = flags;
- shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_TRANSIENT);
+ shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_TRANSIENT);
}
static pepper_output_t *
shell_surface_get_output(shell_surface_t *shsurf)
{
- pepper_output_t *output = NULL;
- const pepper_list_t *list;
- pepper_list_t *l;
+ pepper_output_t *output = NULL;
+ const pepper_list_t *list;
+ pepper_list_t *l;
- /* FIXME: Find the output on which the surface has the biggest surface area */
- list = pepper_compositor_get_output_list(shsurf->shell->compositor);
- pepper_list_for_each_list(l, list)
- {
- if (l->item)
- {
- output = (pepper_output_t *)l->item;
- break;
- }
- }
+ /* FIXME: Find the output on which the surface has the biggest surface area */
+ list = pepper_compositor_get_output_list(shsurf->shell->compositor);
+ pepper_list_for_each_list(l, list) {
+ if (l->item) {
+ output = (pepper_output_t *)l->item;
+ break;
+ }
+ }
- return output;
+ return output;
}
static void
-shell_surface_get_geometry(shell_surface_t *shsurf, pixman_rectangle32_t *geometry)
+shell_surface_get_geometry(shell_surface_t *shsurf,
+ pixman_rectangle32_t *geometry)
{
- double x, y;
- int w, h;
+ double x, y;
+ int w, h;
- pepper_view_get_position(shsurf->view, &x, &y);
- pepper_view_get_size(shsurf->view, &w, &h);
+ pepper_view_get_position(shsurf->view, &x, &y);
+ pepper_view_get_size(shsurf->view, &w, &h);
- geometry->x = (int32_t)x;
- geometry->y = (int32_t)y;
- geometry->width = (uint32_t)w;
- geometry->height = (uint32_t)h;
+ geometry->x = (int32_t)x;
+ geometry->y = (int32_t)y;
+ geometry->width = (uint32_t)w;
+ geometry->height = (uint32_t)h;
}
static void
shell_surface_save_current_geometry(shell_surface_t *shsurf)
{
- if (shsurf->type != SHELL_SURFACE_TYPE_MAXIMIZED &&
- shsurf->type != SHELL_SURFACE_TYPE_FULLSCREEN)
- {
- pepper_view_get_position(shsurf->view, &shsurf->saved.x, &shsurf->saved.y);
- shsurf->saved.w = shsurf->geometry.w;
- shsurf->saved.h = shsurf->geometry.h;
- }
- shsurf->saved.type = shsurf->type;
+ if (shsurf->type != SHELL_SURFACE_TYPE_MAXIMIZED &&
+ shsurf->type != SHELL_SURFACE_TYPE_FULLSCREEN) {
+ pepper_view_get_position(shsurf->view, &shsurf->saved.x, &shsurf->saved.y);
+ shsurf->saved.w = shsurf->geometry.w;
+ shsurf->saved.h = shsurf->geometry.h;
+ }
+ shsurf->saved.type = shsurf->type;
}
void
shell_surface_set_maximized(shell_surface_t *shsurf,
- pepper_output_t *output)
+ pepper_output_t *output)
{
- pixman_rectangle32_t area;
+ pixman_rectangle32_t area;
- if (shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED)
- return ;
+ if (shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED)
+ return ;
- /* XXX: If the given shell_surface has a parent, what's the corrent behavior? */
- shell_surface_set_parent(shsurf, NULL);
+ /* XXX: If the given shell_surface has a parent, what's the corrent behavior? */
+ shell_surface_set_parent(shsurf, NULL);
- /* If the client does not specify the output then the compositor will apply its policy */
- if (!output)
- output = shell_surface_get_output(shsurf);
+ /* If the client does not specify the output then the compositor will apply its policy */
+ if (!output)
+ output = shell_surface_get_output(shsurf);
- shsurf->maximized.output = output;
+ shsurf->maximized.output = output;
- shell_surface_save_current_geometry(shsurf);
+ shell_surface_save_current_geometry(shsurf);
- shell_get_output_workarea(shsurf->shell, output, &area);
+ shell_get_output_workarea(shsurf->shell, output, &area);
- shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_MAXIMIZED);
+ shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_MAXIMIZED);
- /* Send configure */
- shsurf->send_configure(shsurf, area.width, area.height);
+ /* Send configure */
+ shsurf->send_configure(shsurf, area.width, area.height);
}
void
shell_surface_unset_maximized(shell_surface_t *shsurf)
{
- if (shsurf->type != SHELL_SURFACE_TYPE_MAXIMIZED)
- return ;
+ if (shsurf->type != SHELL_SURFACE_TYPE_MAXIMIZED)
+ return ;
- shell_surface_set_toplevel(shsurf);
+ shell_surface_set_toplevel(shsurf);
}
void
shell_surface_set_fullscreen(shell_surface_t *shsurf,
- pepper_output_t *output,
- uint32_t method,
- uint32_t framerate)
+ pepper_output_t *output,
+ uint32_t method,
+ uint32_t framerate)
{
- const pepper_output_geometry_t *geom;
+ const pepper_output_geometry_t *geom;
- /* XXX: If the given shell_surface has a parent, what's the corrent behavior? */
- shell_surface_set_parent(shsurf, NULL);
+ /* XXX: If the given shell_surface has a parent, what's the corrent behavior? */
+ shell_surface_set_parent(shsurf, NULL);
- /* If the client does not specify the output then the compositor will apply its policy */
- if (!output)
- output = shell_surface_get_output(shsurf);
+ /* If the client does not specify the output then the compositor will apply its policy */
+ if (!output)
+ output = shell_surface_get_output(shsurf);
- shsurf->fullscreen.output = output;
- shsurf->fullscreen.method = method;
- shsurf->fullscreen.framerate = framerate;
+ shsurf->fullscreen.output = output;
+ shsurf->fullscreen.method = method;
+ shsurf->fullscreen.framerate = framerate;
- shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_FULLSCREEN);
+ shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_FULLSCREEN);
- shell_surface_save_current_geometry(shsurf);
+ shell_surface_save_current_geometry(shsurf);
- /* Find current output mode */
- {
- pepper_output_mode_t mode;
- int i, mode_cnt;
+ /* Find current output mode */
+ {
+ pepper_output_mode_t mode;
+ int i, mode_cnt;
- mode_cnt = pepper_output_get_mode_count(output);
- for (i=0; i<mode_cnt; ++i)
- {
- pepper_output_get_mode(output, i, &mode);
- if (mode.flags & PEPPER_OUTPUT_MODE_CURRENT)
- {
- shsurf->saved.mode = mode;
- break;
- }
- }
- }
+ mode_cnt = pepper_output_get_mode_count(output);
+ for (i = 0; i < mode_cnt; ++i) {
+ pepper_output_get_mode(output, i, &mode);
+ if (mode.flags & PEPPER_OUTPUT_MODE_CURRENT) {
+ shsurf->saved.mode = mode;
+ break;
+ }
+ }
+ }
- geom = pepper_output_get_geometry(output);
+ geom = pepper_output_get_geometry(output);
- /* Send configure */
- shsurf->send_configure(shsurf, geom->w, geom->h);
+ /* Send configure */
+ shsurf->send_configure(shsurf, geom->w, geom->h);
}
void
shell_surface_unset_fullscreen(shell_surface_t *shsurf)
{
- if (shsurf->type != SHELL_SURFACE_TYPE_FULLSCREEN)
- return ;
+ if (shsurf->type != SHELL_SURFACE_TYPE_FULLSCREEN)
+ return ;
- if (shsurf->fullscreen.method == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
- switch_output_mode(shsurf->fullscreen.output, &shsurf->saved.mode);
+ if (shsurf->fullscreen.method == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
+ switch_output_mode(shsurf->fullscreen.output, &shsurf->saved.mode);
- if (shsurf->saved.type == SHELL_SURFACE_TYPE_MAXIMIZED)
- shell_surface_set_maximized(shsurf, shsurf->maximized.output);
- else
- shell_surface_set_toplevel(shsurf);
+ if (shsurf->saved.type == SHELL_SURFACE_TYPE_MAXIMIZED)
+ shell_surface_set_maximized(shsurf, shsurf->maximized.output);
+ else
+ shell_surface_set_toplevel(shsurf);
}
void
shell_surface_set_minimized(shell_surface_t *shsurf)
{
- shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_MINIMIZED);
+ shell_surface_set_next_type(shsurf, SHELL_SURFACE_TYPE_MINIMIZED);
}
void
shell_surface_ack_configure(shell_surface_t *shsurf, uint32_t serial)
{
- shsurf->ack_configure = PEPPER_TRUE;
+ shsurf->ack_configure = PEPPER_TRUE;
}
void
shell_surface_set_position(shell_surface_t *shsurf, double x, double y)
{
- if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN)
- shell_surface_place_fullscreen_surface(shsurf);
- else
- pepper_view_set_position(shsurf->view, x, y);
+ if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN)
+ shell_surface_place_fullscreen_surface(shsurf);
+ else
+ pepper_view_set_position(shsurf->view, x, y);
}
void
shell_surface_stack_top(shell_surface_t *shsurf, pepper_bool_t subtree)
{
- pepper_view_t *cursor_view;
- pepper_pointer_t *pointer;
- shell_seat_t *shseat;
+ pepper_view_t *cursor_view;
+ pepper_pointer_t *pointer;
+ shell_seat_t *shseat;
- pepper_view_stack_top(shsurf->view, subtree);
+ pepper_view_stack_top(shsurf->view, subtree);
- pepper_list_for_each(shseat, &shsurf->shell->shseat_list, link)
- {
- pointer = pepper_seat_get_pointer(shseat->seat);
- if (pointer)
- {
- cursor_view = pepper_pointer_get_cursor_view(pointer);
- if (cursor_view)
- pepper_view_stack_top(cursor_view, PEPPER_FALSE);
- }
- }
+ pepper_list_for_each(shseat, &shsurf->shell->shseat_list, link) {
+ pointer = pepper_seat_get_pointer(shseat->seat);
+ if (pointer) {
+ cursor_view = pepper_pointer_get_cursor_view(pointer);
+ if (cursor_view)
+ pepper_view_stack_top(cursor_view, PEPPER_FALSE);
+ }
+ }
}
shell_surface_t *
get_shsurf_from_surface(pepper_surface_t *surface, desktop_shell_t *shell)
{
- return pepper_object_get_user_data((pepper_object_t *)surface, shell);
+ return pepper_object_get_user_data((pepper_object_t *)surface, shell);
}
void
set_shsurf_to_surface(pepper_surface_t *surface, shell_surface_t *shsurf)
{
- pepper_object_set_user_data((pepper_object_t *)surface, shsurf->shell, shsurf, NULL);
+ pepper_object_set_user_data((pepper_object_t *)surface, shsurf->shell, shsurf,
+ NULL);
}
void
shell_surface_set_parent(shell_surface_t *shsurf, pepper_surface_t *parent)
{
- shell_surface_t *parent_shsurf;
+ shell_surface_t *parent_shsurf;
- pepper_list_remove(&shsurf->parent_link);
- pepper_list_init(&shsurf->parent_link);
+ pepper_list_remove(&shsurf->parent_link);
+ pepper_list_init(&shsurf->parent_link);
- shsurf->parent = parent;
+ shsurf->parent = parent;
- if (parent)
- {
- parent_shsurf = get_shsurf_from_surface(parent, shsurf->shell);
+ if (parent) {
+ parent_shsurf = get_shsurf_from_surface(parent, shsurf->shell);
- if (parent_shsurf)
- {
- pepper_list_insert(&parent_shsurf->child_list, &shsurf->parent_link);
- pepper_view_set_parent(shsurf->view, parent_shsurf->view);
- }
- }
- else
- {
- pepper_view_set_parent(shsurf->view, NULL);
- }
+ if (parent_shsurf) {
+ pepper_list_insert(&parent_shsurf->child_list, &shsurf->parent_link);
+ pepper_view_set_parent(shsurf->view, parent_shsurf->view);
+ }
+ } else {
+ pepper_view_set_parent(shsurf->view, NULL);
+ }
}
void
-shell_surface_set_geometry(shell_surface_t *shsurf, double x, double y, int32_t w, int32_t h)
+shell_surface_set_geometry(shell_surface_t *shsurf, double x, double y,
+ int32_t w, int32_t h)
{
- shsurf->next_geometry.x = x;
- shsurf->next_geometry.y = y;
- shsurf->next_geometry.w = w;
- shsurf->next_geometry.h = h;
+ shsurf->next_geometry.x = x;
+ shsurf->next_geometry.y = y;
+ shsurf->next_geometry.w = w;
+ shsurf->next_geometry.h = h;
- shsurf->has_next_geometry = PEPPER_TRUE;
+ shsurf->has_next_geometry = PEPPER_TRUE;
}
pepper_bool_t
-shell_surface_set_title(shell_surface_t *shsurf, const char* title)
+shell_surface_set_title(shell_surface_t *shsurf, const char *title)
{
- if (shsurf->title)
- free(shsurf->title);
+ if (shsurf->title)
+ free(shsurf->title);
- shsurf->title = strdup(title);
+ shsurf->title = strdup(title);
- if (!shsurf->title)
- return PEPPER_FALSE;
+ if (!shsurf->title)
+ return PEPPER_FALSE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
pepper_bool_t
-shell_surface_set_class(shell_surface_t *shsurf, const char* class_)
+shell_surface_set_class(shell_surface_t *shsurf, const char *class_)
{
- if (shsurf->class_)
- free(shsurf->class_);
+ if (shsurf->class_)
+ free(shsurf->class_);
- shsurf->class_ = strdup(class_);
+ shsurf->class_ = strdup(class_);
- if (!shsurf->class_)
- return PEPPER_FALSE;
+ if (!shsurf->class_)
+ return PEPPER_FALSE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_output_t *
shell_pointer_get_output(desktop_shell_t *shell, pepper_pointer_t *pointer)
{
- pepper_output_t *output = NULL;
- pepper_output_t *tmp_output;
- const pepper_list_t *list;
- pepper_list_t *l;
- double px, py;
+ pepper_output_t *output = NULL;
+ pepper_output_t *tmp_output;
+ const pepper_list_t *list;
+ pepper_list_t *l;
+ double px, py;
- pepper_pointer_get_position(pointer, &px, &py);
+ pepper_pointer_get_position(pointer, &px, &py);
- list = pepper_compositor_get_output_list(shell->compositor);
- pepper_list_for_each_list(l, list)
- {
- tmp_output = (pepper_output_t *)l->item;
+ list = pepper_compositor_get_output_list(shell->compositor);
+ pepper_list_for_each_list(l, list) {
+ tmp_output = (pepper_output_t *)l->item;
- if (tmp_output)
- {
- const pepper_output_geometry_t *geom;
- pixman_region32_t rect;
+ if (tmp_output) {
+ const pepper_output_geometry_t *geom;
+ pixman_region32_t rect;
- if (!output)
- output = tmp_output;
+ if (!output)
+ output = tmp_output;
- geom = pepper_output_get_geometry(tmp_output);
+ geom = pepper_output_get_geometry(tmp_output);
- pixman_region32_init_rect(&rect, geom->x, geom->y, geom->w, geom->h);
+ pixman_region32_init_rect(&rect, geom->x, geom->y, geom->w, geom->h);
- if (pixman_region32_contains_point(&rect, px, py, NULL))
- {
- output = tmp_output;
- pixman_region32_fini(&rect);
- break;
- }
+ if (pixman_region32_contains_point(&rect, px, py, NULL)) {
+ output = tmp_output;
+ pixman_region32_fini(&rect);
+ break;
+ }
- pixman_region32_fini(&rect);
- }
- }
+ pixman_region32_fini(&rect);
+ }
+ }
- return output;
+ return output;
}
static void
shell_surface_set_initial_position(shell_surface_t *shsurf)
{
- pepper_pointer_t *pointer = NULL;
- shell_seat_t *shseat, *tmp;
- double vx = 0.f, vy = 0.f;
+ pepper_pointer_t *pointer = NULL;
+ shell_seat_t *shseat, *tmp;
+ double vx = 0.f, vy = 0.f;
- pepper_list_for_each_safe(shseat, tmp, &shsurf->shell->shseat_list, link)
- {
- if (shseat->seat)
- {
- pointer = pepper_seat_get_pointer(shseat->seat);
- if (pointer)
- break;
- }
- }
+ pepper_list_for_each_safe(shseat, tmp, &shsurf->shell->shseat_list, link) {
+ if (shseat->seat) {
+ pointer = pepper_seat_get_pointer(shseat->seat);
+ if (pointer)
+ break;
+ }
+ }
- if (pointer)
- {
- const pepper_output_geometry_t *geom;
- pepper_output_t *output;
+ if (pointer) {
+ const pepper_output_geometry_t *geom;
+ pepper_output_t *output;
- int32_t vw, vh;
- double px, py;
+ int32_t vw, vh;
+ double px, py;
- pepper_pointer_get_position(pointer, &px, &py);
+ pepper_pointer_get_position(pointer, &px, &py);
- output = shell_pointer_get_output(shsurf->shell, pointer);
+ output = shell_pointer_get_output(shsurf->shell, pointer);
- geom = pepper_output_get_geometry(output);
+ geom = pepper_output_get_geometry(output);
- pepper_view_get_size(shsurf->view, &vw, &vh);
+ pepper_view_get_size(shsurf->view, &vw, &vh);
- /* FIXME: consider output's origin is top-left */
- if ( px <= geom->x )
- vx = 0.f;
- else if ( px + vw > geom->x + geom->w)
- vx = geom->x + geom->w - vw;
- else
- vx = px;
+ /* FIXME: consider output's origin is top-left */
+ if ( px <= geom->x )
+ vx = 0.f;
+ else if ( px + vw > geom->x + geom->w)
+ vx = geom->x + geom->w - vw;
+ else
+ vx = px;
- if ( py <= geom->y )
- vy = 0.f;
- else if ( py + vh > geom->y + geom->h )
- vy = geom->y + geom->h - vh;
- else
- vy = py;
- }
+ if ( py <= geom->y )
+ vy = 0.f;
+ else if ( py + vh > geom->y + geom->h )
+ vy = geom->y + geom->h - vh;
+ else
+ vy = py;
+ }
- pepper_view_set_position(shsurf->view, vx, vy);
+ pepper_view_set_position(shsurf->view, vx, vy);
}
static void
shell_surface_map_toplevel(shell_surface_t *shsurf)
{
- shell_seat_t *shseat, *tmp;
- pepper_keyboard_t *keyboard;
-
- if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
- shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
- shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED)
- {
- pepper_view_set_position(shsurf->view, shsurf->saved.x, shsurf->saved.y);
- }
- else
- {
- shell_surface_set_initial_position(shsurf);
-
- pepper_list_for_each_safe(shseat, tmp, &shsurf->shell->shseat_list, link)
- {
- if (shseat->seat)
- {
- keyboard = pepper_seat_get_keyboard(shseat->seat);
- if (keyboard)
- {
- pepper_view_t *focus = pepper_keyboard_get_focus(keyboard);
- if ( focus != shsurf->view)
- {
- pepper_keyboard_send_leave(keyboard, focus);
- pepper_keyboard_set_focus(keyboard, shsurf->view);
- pepper_keyboard_send_enter(keyboard, shsurf->view);
- }
- }
- }
- }
- }
-
- pepper_view_map(shsurf->view);
+ shell_seat_t *shseat, *tmp;
+ pepper_keyboard_t *keyboard;
+
+ if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
+ shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
+ shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED) {
+ pepper_view_set_position(shsurf->view, shsurf->saved.x, shsurf->saved.y);
+ } else {
+ shell_surface_set_initial_position(shsurf);
+
+ pepper_list_for_each_safe(shseat, tmp, &shsurf->shell->shseat_list, link) {
+ if (shseat->seat) {
+ keyboard = pepper_seat_get_keyboard(shseat->seat);
+ if (keyboard) {
+ pepper_view_t *focus = pepper_keyboard_get_focus(keyboard);
+ if ( focus != shsurf->view) {
+ pepper_keyboard_send_leave(keyboard, focus);
+ pepper_keyboard_set_focus(keyboard, shsurf->view);
+ pepper_keyboard_send_enter(keyboard, shsurf->view);
+ }
+ }
+ }
+ }
+ }
+
+ pepper_view_map(shsurf->view);
}
static void
pointer_popup_grab_motion(pepper_pointer_t *pointer, void *data,
- uint32_t time, double x, double y)
+ uint32_t time, double x, double y)
{
- double vx, vy;
- pepper_compositor_t *compositor = pepper_pointer_get_compositor(pointer);
- pepper_view_t *view = pepper_compositor_pick_view(compositor, x, y, &vx, &vy);
- pepper_view_t *focus = pepper_pointer_get_focus(pointer);
+ double vx, vy;
+ pepper_compositor_t *compositor = pepper_pointer_get_compositor(pointer);
+ pepper_view_t *view = pepper_compositor_pick_view(compositor, x, y, &vx,
+ &vy);
+ pepper_view_t *focus = pepper_pointer_get_focus(pointer);
- if (focus != view)
- {
- pepper_pointer_send_leave(pointer, focus);
- pepper_pointer_set_focus(pointer, view);
- pepper_pointer_send_enter(pointer, view, vx, vy);
- }
+ if (focus != view) {
+ pepper_pointer_send_leave(pointer, focus);
+ pepper_pointer_set_focus(pointer, view);
+ pepper_pointer_send_enter(pointer, view, vx, vy);
+ }
- pepper_pointer_send_motion(pointer, view, time, vx, vy);
+ pepper_pointer_send_motion(pointer, view, time, vx, vy);
}
static struct wl_client *
pepper_view_get_client(pepper_view_t *view)
{
- pepper_surface_t *surface = pepper_view_get_surface(view);
- if (surface)
- {
- struct wl_resource *resource = pepper_surface_get_resource(surface);
- if (resource)
- return wl_resource_get_client(resource);
- }
+ pepper_surface_t *surface = pepper_view_get_surface(view);
+ if (surface) {
+ struct wl_resource *resource = pepper_surface_get_resource(surface);
+ if (resource)
+ return wl_resource_get_client(resource);
+ }
- return NULL;
+ return NULL;
}
static void
pointer_popup_grab_button(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state)
{
- shell_surface_t *shsurf = data;
- struct wl_client *client = NULL;
- pepper_view_t *focus;
+ shell_surface_t *shsurf = data;
+ struct wl_client *client = NULL;
+ pepper_view_t *focus;
- focus = pepper_pointer_get_focus(pointer);
+ focus = pepper_pointer_get_focus(pointer);
- if (focus)
- client = pepper_view_get_client(focus);
+ if (focus)
+ client = pepper_view_get_client(focus);
- /* The popup_done event is sent out when a popup grab is broken, that is, when the user
- * clicks a surface that doesn't belong to the client owning the popup surface. */
+ /* The popup_done event is sent out when a popup grab is broken, that is, when the user
+ * clicks a surface that doesn't belong to the client owning the popup surface. */
- if (client == shsurf->client)
- {
- pepper_pointer_send_button(pointer, focus, time, button, state);
- }
- else if (shsurf->popup.button_up)
- {
- shell_surface_end_popup_grab(data);
- }
+ if (client == shsurf->client) {
+ pepper_pointer_send_button(pointer, focus, time, button, state);
+ } else if (shsurf->popup.button_up) {
+ shell_surface_end_popup_grab(data);
+ }
- if (state == WL_POINTER_BUTTON_STATE_RELEASED)
- shsurf->popup.button_up = PEPPER_TRUE;
+ if (state == WL_POINTER_BUTTON_STATE_RELEASED)
+ shsurf->popup.button_up = PEPPER_TRUE;
}
static void
pointer_popup_grab_axis(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t axis, double value)
+ uint32_t time, uint32_t axis, double value)
{
- /* TODO */
+ /* TODO */
}
static void
pointer_popup_grab_cancel(pepper_pointer_t *pointer, void *data)
{
- shell_surface_end_popup_grab(data);
+ shell_surface_end_popup_grab(data);
}
-static pepper_pointer_grab_t pointer_popup_grab =
-{
- pointer_popup_grab_motion,
- pointer_popup_grab_button,
- pointer_popup_grab_axis,
- pointer_popup_grab_cancel,
+static pepper_pointer_grab_t pointer_popup_grab = {
+ pointer_popup_grab_motion,
+ pointer_popup_grab_button,
+ pointer_popup_grab_axis,
+ pointer_popup_grab_cancel,
};
static void
shell_surface_send_popup_done(shell_surface_t *shsurf)
{
- if (shsurf->resource)
- {
- if (shsurf_is_xdg_popup(shsurf))
- xdg_popup_send_popup_done(shsurf->resource);
- else if (shsurf_is_wl_shell_surface(shsurf) && shsurf->type == SHELL_SURFACE_TYPE_POPUP )
- wl_shell_surface_send_popup_done(shsurf->resource);
- }
+ if (shsurf->resource) {
+ if (shsurf_is_xdg_popup(shsurf))
+ xdg_popup_send_popup_done(shsurf->resource);
+ else if (shsurf_is_wl_shell_surface(shsurf) &&
+ shsurf->type == SHELL_SURFACE_TYPE_POPUP )
+ wl_shell_surface_send_popup_done(shsurf->resource);
+ }
}
static void
shell_surface_end_popup_grab(shell_surface_t *shsurf)
{
- pepper_pointer_t *pointer = pepper_seat_get_pointer(shsurf->popup.seat);
+ pepper_pointer_t *pointer = pepper_seat_get_pointer(shsurf->popup.seat);
- if(pointer)
- {
- const pepper_pointer_grab_t *grab = pepper_pointer_get_grab(pointer);
- if (grab == &pointer_popup_grab )
- pepper_pointer_set_grab(pointer,
- shsurf->old_pointer_grab,
- shsurf->old_pointer_grab_data);
- }
+ if (pointer) {
+ const pepper_pointer_grab_t *grab = pepper_pointer_get_grab(pointer);
+ if (grab == &pointer_popup_grab )
+ pepper_pointer_set_grab(pointer,
+ shsurf->old_pointer_grab,
+ shsurf->old_pointer_grab_data);
+ }
- shell_surface_send_popup_done(shsurf);
+ shell_surface_send_popup_done(shsurf);
}
static void
shell_surface_add_popup_grab(shell_surface_t *shsurf)
{
- pepper_pointer_t *pointer = pepper_seat_get_pointer(shsurf->popup.seat);
+ pepper_pointer_t *pointer = pepper_seat_get_pointer(shsurf->popup.seat);
- /* TODO: Find the object that serial belongs to */
+ /* TODO: Find the object that serial belongs to */
- if (pointer)
- {
- shsurf->old_pointer_grab = pepper_pointer_get_grab(pointer);
- shsurf->old_pointer_grab_data = pepper_pointer_get_grab_data(pointer);
+ if (pointer) {
+ shsurf->old_pointer_grab = pepper_pointer_get_grab(pointer);
+ shsurf->old_pointer_grab_data = pepper_pointer_get_grab_data(pointer);
- pepper_pointer_set_grab(pointer, &pointer_popup_grab, shsurf);
+ pepper_pointer_set_grab(pointer, &pointer_popup_grab, shsurf);
- shsurf->popup.button_up = PEPPER_FALSE;
- }
+ shsurf->popup.button_up = PEPPER_FALSE;
+ }
- /* TODO: touch */
+ /* TODO: touch */
}
static void
shell_surface_map_popup(shell_surface_t *shsurf)
{
- shell_surface_t *parent = get_shsurf_from_surface(shsurf->parent, shsurf->shell);
+ shell_surface_t *parent = get_shsurf_from_surface(shsurf->parent,
+ shsurf->shell);
- /* Set position as relatively */
- pepper_view_set_parent(shsurf->view, parent->view);
- shell_surface_set_position(shsurf, shsurf->popup.x, shsurf->popup.y);
+ /* Set position as relatively */
+ pepper_view_set_parent(shsurf->view, parent->view);
+ shell_surface_set_position(shsurf, shsurf->popup.x, shsurf->popup.y);
- pepper_view_map(shsurf->view);
+ pepper_view_map(shsurf->view);
- shell_surface_stack_top(shsurf, PEPPER_TRUE);
+ shell_surface_stack_top(shsurf, PEPPER_TRUE);
- shell_surface_add_popup_grab(shsurf);
+ shell_surface_add_popup_grab(shsurf);
}
static void
shell_surface_map_transient(shell_surface_t *shsurf)
{
- shell_surface_t *parent = get_shsurf_from_surface(shsurf->parent, shsurf->shell);
- double x, y;
+ shell_surface_t *parent = get_shsurf_from_surface(shsurf->parent,
+ shsurf->shell);
+ double x, y;
- pepper_view_get_position(parent->view, &x, &y);
+ pepper_view_get_position(parent->view, &x, &y);
- pepper_view_set_parent(shsurf->view, parent->view);
+ pepper_view_set_parent(shsurf->view, parent->view);
- shell_surface_set_position(shsurf,
- x + shsurf->transient.x,
- y + shsurf->transient.y);
+ shell_surface_set_position(shsurf,
+ x + shsurf->transient.x,
+ y + shsurf->transient.y);
- if (shsurf->transient.flags != WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
- {
- /* TODO: set keyboard focus to view */
- }
+ if (shsurf->transient.flags != WL_SHELL_SURFACE_TRANSIENT_INACTIVE) {
+ /* TODO: set keyboard focus to view */
+ }
- pepper_view_map(shsurf->view);
+ pepper_view_map(shsurf->view);
}
static void
shell_surface_map_maximized(shell_surface_t *shsurf)
{
- pixman_rectangle32_t area;
+ pixman_rectangle32_t area;
- shell_get_output_workarea(shsurf->shell, shsurf->maximized.output, &area);
+ shell_get_output_workarea(shsurf->shell, shsurf->maximized.output, &area);
- shell_surface_set_position(shsurf, area.x, area.y);
+ shell_surface_set_position(shsurf, area.x, area.y);
- pepper_view_map(shsurf->view);
+ pepper_view_map(shsurf->view);
- /* Set top of z-order */
- shell_surface_stack_top(shsurf, PEPPER_TRUE /*FIXME:*/);
+ /* Set top of z-order */
+ shell_surface_stack_top(shsurf, PEPPER_TRUE /*FIXME:*/);
}
static void
shell_surface_map_minimized(shell_surface_t *shsurf)
{
- /* TODO */
- pepper_view_unmap(shsurf->view);
+ /* TODO */
+ pepper_view_unmap(shsurf->view);
}
static float
get_scale(float output_w, float output_h, float view_w, float view_h)
{
- float scale, output_aspect, view_aspect;
+ float scale, output_aspect, view_aspect;
- output_aspect = output_w / output_h;
+ output_aspect = output_w / output_h;
- view_aspect = view_w / view_h;
+ view_aspect = view_w / view_h;
- if (output_aspect < view_aspect)
- scale = output_w / view_w;
- else
- scale = output_h / view_h;
+ if (output_aspect < view_aspect)
+ scale = output_w / view_w;
+ else
+ scale = output_h / view_h;
- return scale;
+ return scale;
}
static void
shell_surface_center_on_output_by_scale(shell_surface_t *shsurf,
- const pepper_output_geometry_t *output,
- pixman_rectangle32_t *surface_geom,
- float scale)
+ const pepper_output_geometry_t *output,
+ pixman_rectangle32_t *surface_geom,
+ float scale)
{
- double x, y;
+ double x, y;
- x = output->x + (output->w - surface_geom->width * scale) / 2;
- y = output->y + (output->h - surface_geom->height * scale) / 2;
+ x = output->x + (output->w - surface_geom->width * scale) / 2;
+ y = output->y + (output->h - surface_geom->height * scale) / 2;
- pepper_view_set_position(shsurf->view, x, y);
+ pepper_view_set_position(shsurf->view, x, y);
}
void
shell_surface_place_fullscreen_surface(shell_surface_t *shsurf)
{
- pepper_output_t *output;
- const pepper_output_geometry_t *output_geom;
- pixman_rectangle32_t shsurf_geom;
- float scale = 0.f;
+ pepper_output_t *output;
+ const pepper_output_geometry_t *output_geom;
+ pixman_rectangle32_t shsurf_geom;
+ float scale = 0.f;
- output = shsurf->fullscreen.output;
- output_geom = pepper_output_get_geometry(output);
+ output = shsurf->fullscreen.output;
+ output_geom = pepper_output_get_geometry(output);
- /* Get current geometry */
- shell_surface_get_geometry(shsurf, &shsurf_geom);
+ /* Get current geometry */
+ shell_surface_get_geometry(shsurf, &shsurf_geom);
- switch (shsurf->fullscreen.method)
- {
- case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
- {
- scale = get_scale(output_geom->w, output_geom->h, shsurf_geom.width, shsurf_geom.height);
- }
- break;
- case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
- {
- pepper_output_mode_t mode;
- int32_t buffer_scale;
+ switch (shsurf->fullscreen.method) {
+ case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: {
+ scale = get_scale(output_geom->w, output_geom->h, shsurf_geom.width,
+ shsurf_geom.height);
+ }
+ break;
+ case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: {
+ pepper_output_mode_t mode;
+ int32_t buffer_scale;
- buffer_scale = pepper_surface_get_buffer_scale(shsurf->surface);
+ buffer_scale = pepper_surface_get_buffer_scale(shsurf->surface);
- mode.w = shsurf_geom.width * buffer_scale;
- mode.h = shsurf_geom.height * buffer_scale;
- mode.refresh = shsurf->fullscreen.framerate;
+ mode.w = shsurf_geom.width * buffer_scale;
+ mode.h = shsurf_geom.height * buffer_scale;
+ mode.refresh = shsurf->fullscreen.framerate;
- switch_output_mode(output, &mode);
+ switch_output_mode(output, &mode);
- /* Recalculate output geometry */
- output_geom = pepper_output_get_geometry(output);
+ /* Recalculate output geometry */
+ output_geom = pepper_output_get_geometry(output);
- scale = 1.f;
- }
- break;
- case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
- case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
- {
- scale = 1.f;
- }
- break;
- default:
- PEPPER_ERROR("invalid method type = 0x%x\n", shsurf->fullscreen.method);
- break;
- }
+ scale = 1.f;
+ }
+ break;
+ case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
+ case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: {
+ scale = 1.f;
+ }
+ break;
+ default:
+ PEPPER_ERROR("invalid method type = 0x%x\n", shsurf->fullscreen.method);
+ break;
+ }
- /* Place target view */
- shell_surface_center_on_output_by_scale(shsurf, output_geom, &shsurf_geom, scale);
+ /* Place target view */
+ shell_surface_center_on_output_by_scale(shsurf, output_geom, &shsurf_geom,
+ scale);
}
static void
shell_surface_map_fullscreen(shell_surface_t *shsurf)
{
- shell_surface_place_fullscreen_surface(shsurf);
+ shell_surface_place_fullscreen_surface(shsurf);
- pepper_view_map(shsurf->view);
- shell_surface_stack_top(shsurf, PEPPER_TRUE /*FIXME*/ );
+ pepper_view_map(shsurf->view);
+ shell_surface_stack_top(shsurf, PEPPER_TRUE /*FIXME*/ );
}
void
-shell_surface_set_next_type(shell_surface_t *shsurf, shell_surface_type_t new_type)
-{
- if (shsurf->next_type == new_type)
- return ;
-
- switch (new_type)
- {
- case SHELL_SURFACE_TYPE_NONE:
- shsurf->shell_surface_map = NULL;
- break;
- case SHELL_SURFACE_TYPE_TOPLEVEL:
- shsurf->shell_surface_map = shell_surface_map_toplevel;
- break;
- case SHELL_SURFACE_TYPE_POPUP:
- shsurf->shell_surface_map = shell_surface_map_popup;
- break;
- case SHELL_SURFACE_TYPE_TRANSIENT:
- shsurf->shell_surface_map = shell_surface_map_transient;
- break;
- case SHELL_SURFACE_TYPE_MAXIMIZED:
- shsurf->shell_surface_map = shell_surface_map_maximized;
- break;
- case SHELL_SURFACE_TYPE_FULLSCREEN:
- shsurf->shell_surface_map = shell_surface_map_fullscreen;
- break;
- case SHELL_SURFACE_TYPE_MINIMIZED:
- shsurf->shell_surface_map = shell_surface_map_minimized;
- break;
- default :
- PEPPER_ERROR("invalid surface type = 0x%x\n", new_type);
- return ;
- }
-
- shsurf->next_type = new_type;
- shsurf->type_changed = PEPPER_TRUE;
+shell_surface_set_next_type(shell_surface_t *shsurf,
+ shell_surface_type_t new_type)
+{
+ if (shsurf->next_type == new_type)
+ return ;
+
+ switch (new_type) {
+ case SHELL_SURFACE_TYPE_NONE:
+ shsurf->shell_surface_map = NULL;
+ break;
+ case SHELL_SURFACE_TYPE_TOPLEVEL:
+ shsurf->shell_surface_map = shell_surface_map_toplevel;
+ break;
+ case SHELL_SURFACE_TYPE_POPUP:
+ shsurf->shell_surface_map = shell_surface_map_popup;
+ break;
+ case SHELL_SURFACE_TYPE_TRANSIENT:
+ shsurf->shell_surface_map = shell_surface_map_transient;
+ break;
+ case SHELL_SURFACE_TYPE_MAXIMIZED:
+ shsurf->shell_surface_map = shell_surface_map_maximized;
+ break;
+ case SHELL_SURFACE_TYPE_FULLSCREEN:
+ shsurf->shell_surface_map = shell_surface_map_fullscreen;
+ break;
+ case SHELL_SURFACE_TYPE_MINIMIZED:
+ shsurf->shell_surface_map = shell_surface_map_minimized;
+ break;
+ default :
+ PEPPER_ERROR("invalid surface type = 0x%x\n", new_type);
+ return ;
+ }
+
+ shsurf->next_type = new_type;
+ shsurf->type_changed = PEPPER_TRUE;
}
static void
-pointer_move_grab_motion(pepper_pointer_t *pointer, void *data, uint32_t time, double x, double y)
+pointer_move_grab_motion(pepper_pointer_t *pointer, void *data, uint32_t time,
+ double x, double y)
{
- shell_surface_t *shsurf = data;
- pepper_view_set_position(shsurf->view, shsurf->move.dx + x, shsurf->move.dy + y);
+ shell_surface_t *shsurf = data;
+ pepper_view_set_position(shsurf->view, shsurf->move.dx + x,
+ shsurf->move.dy + y);
}
static void
pointer_move_grab_button(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state)
{
- if (button == BTN_LEFT && state == PEPPER_BUTTON_STATE_RELEASED)
- {
- shell_surface_t *shsurf = data;
- pepper_pointer_set_grab(pointer, shsurf->old_pointer_grab, shsurf->old_pointer_grab_data);
- }
+ if (button == BTN_LEFT && state == PEPPER_BUTTON_STATE_RELEASED) {
+ shell_surface_t *shsurf = data;
+ pepper_pointer_set_grab(pointer, shsurf->old_pointer_grab,
+ shsurf->old_pointer_grab_data);
+ }
}
static void
pointer_move_grab_axis(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t axis, double value)
+ uint32_t time, uint32_t axis, double value)
{
- /* TODO */
+ /* TODO */
}
static void
pointer_move_grab_cancel(pepper_pointer_t *pointer, void *data)
{
- /* TODO */
+ /* TODO */
}
-static pepper_pointer_grab_t pointer_move_grab =
-{
- pointer_move_grab_motion,
- pointer_move_grab_button,
- pointer_move_grab_axis,
- pointer_move_grab_cancel,
+static pepper_pointer_grab_t pointer_move_grab = {
+ pointer_move_grab_motion,
+ pointer_move_grab_button,
+ pointer_move_grab_axis,
+ pointer_move_grab_cancel,
};
void
-shell_surface_move(shell_surface_t *shsurf, pepper_seat_t *seat, uint32_t serial)
+shell_surface_move(shell_surface_t *shsurf, pepper_seat_t *seat,
+ uint32_t serial)
{
- pepper_pointer_t *pointer = pepper_seat_get_pointer(seat);
- double vx, vy;
- double px, py;
+ pepper_pointer_t *pointer = pepper_seat_get_pointer(seat);
+ double vx, vy;
+ double px, py;
- if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
- shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
- shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED)
- {
- return ;
- }
+ if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
+ shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
+ shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED) {
+ return ;
+ }
- /* TODO: Touch driven move?? */
- if (!pointer)
- return;
+ /* TODO: Touch driven move?? */
+ if (!pointer)
+ return;
- /* TODO: Should consider view transform. */
- pepper_view_get_position(shsurf->view, &vx, &vy);
- pepper_pointer_get_position(pointer, &px, &py);
+ /* TODO: Should consider view transform. */
+ pepper_view_get_position(shsurf->view, &vx, &vy);
+ pepper_pointer_get_position(pointer, &px, &py);
- shsurf->move.dx = vx - px;
- shsurf->move.dy = vy - py;
+ shsurf->move.dx = vx - px;
+ shsurf->move.dy = vy - py;
- shsurf->old_pointer_grab = pepper_pointer_get_grab(pointer);
- shsurf->old_pointer_grab_data = pepper_pointer_get_grab_data(pointer);
- pepper_pointer_set_grab(pointer, &pointer_move_grab, shsurf);
+ shsurf->old_pointer_grab = pepper_pointer_get_grab(pointer);
+ shsurf->old_pointer_grab_data = pepper_pointer_get_grab_data(pointer);
+ pepper_pointer_set_grab(pointer, &pointer_move_grab, shsurf);
}
static void
-pointer_resize_grab_motion(pepper_pointer_t *pointer, void *data, uint32_t time, double x, double y)
+pointer_resize_grab_motion(pepper_pointer_t *pointer, void *data, uint32_t time,
+ double x, double y)
{
- shell_surface_t *shsurf = data;
- double dx = 0.f, dy = 0.f;
+ shell_surface_t *shsurf = data;
+ double dx = 0.f, dy = 0.f;
- if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_LEFT)
- {
- dx = shsurf->resize.px - x;
- }
- else if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_RIGHT)
- {
- dx = x - shsurf->resize.px;
- }
+ if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
+ dx = shsurf->resize.px - x;
+ } else if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
+ dx = x - shsurf->resize.px;
+ }
- if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_TOP)
- {
- dy = shsurf->resize.py - y;
- }
- else if(shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_BOTTOM)
- {
- dy = y - shsurf->resize.py;
- }
+ if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_TOP) {
+ dy = shsurf->resize.py - y;
+ } else if (shsurf->resize.edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
+ dy = y - shsurf->resize.py;
+ }
- shsurf->send_configure(shsurf, shsurf->resize.vw + dx, shsurf->resize.vh + dy);
+ shsurf->send_configure(shsurf, shsurf->resize.vw + dx, shsurf->resize.vh + dy);
}
static void
pointer_resize_grab_button(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state)
{
- if (button == BTN_LEFT && state == PEPPER_BUTTON_STATE_RELEASED)
- {
- shell_surface_t *shsurf = data;
+ if (button == BTN_LEFT && state == PEPPER_BUTTON_STATE_RELEASED) {
+ shell_surface_t *shsurf = data;
- pepper_pointer_set_grab(pointer, shsurf->old_pointer_grab, shsurf->old_pointer_grab_data);
- shsurf->resize.resizing = PEPPER_FALSE;
- shsurf->resize.edges = 0;
- }
+ pepper_pointer_set_grab(pointer, shsurf->old_pointer_grab,
+ shsurf->old_pointer_grab_data);
+ shsurf->resize.resizing = PEPPER_FALSE;
+ shsurf->resize.edges = 0;
+ }
}
static void
pointer_resize_grab_axis(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t axis, double value)
+ uint32_t time, uint32_t axis, double value)
{
- /* TODO */
+ /* TODO */
}
static void
pointer_resize_grab_cancel(pepper_pointer_t *pointer, void *data)
{
- /* TODO */
+ /* TODO */
}
-static pepper_pointer_grab_t pointer_resize_grab =
-{
- pointer_resize_grab_motion,
- pointer_resize_grab_button,
- pointer_resize_grab_axis,
- pointer_resize_grab_cancel,
+static pepper_pointer_grab_t pointer_resize_grab = {
+ pointer_resize_grab_motion,
+ pointer_resize_grab_button,
+ pointer_resize_grab_axis,
+ pointer_resize_grab_cancel,
};
void
-shell_surface_resize(shell_surface_t *shsurf, pepper_seat_t *seat, uint32_t serial, uint32_t edges)
+shell_surface_resize(shell_surface_t *shsurf, pepper_seat_t *seat,
+ uint32_t serial, uint32_t edges)
{
- pepper_pointer_t *pointer = pepper_seat_get_pointer(seat);
+ pepper_pointer_t *pointer = pepper_seat_get_pointer(seat);
- if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
- shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
- shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED)
- {
- return ;
- }
+ if (shsurf->type == SHELL_SURFACE_TYPE_FULLSCREEN ||
+ shsurf->type == SHELL_SURFACE_TYPE_MAXIMIZED ||
+ shsurf->type == SHELL_SURFACE_TYPE_MINIMIZED) {
+ return ;
+ }
- pepper_pointer_get_position(pointer, &shsurf->resize.px, &shsurf->resize.py);
+ pepper_pointer_get_position(pointer, &shsurf->resize.px, &shsurf->resize.py);
- pepper_view_get_position(shsurf->view, &shsurf->resize.vx, &shsurf->resize.vy);
+ pepper_view_get_position(shsurf->view, &shsurf->resize.vx, &shsurf->resize.vy);
- shsurf->resize.vw = shsurf->geometry.w;
- shsurf->resize.vh = shsurf->geometry.h;
+ shsurf->resize.vw = shsurf->geometry.w;
+ shsurf->resize.vh = shsurf->geometry.h;
- shsurf->resize.edges = edges;
- shsurf->resize.resizing = PEPPER_TRUE;
+ shsurf->resize.edges = edges;
+ shsurf->resize.resizing = PEPPER_TRUE;
- if (shsurf_is_xdg_surface(shsurf))
- {
- /* FIXME */
- shsurf->send_configure(shsurf, 0, 0);
- }
+ if (shsurf_is_xdg_surface(shsurf)) {
+ /* FIXME */
+ shsurf->send_configure(shsurf, 0, 0);
+ }
- shsurf->old_pointer_grab = pepper_pointer_get_grab(pointer);
- shsurf->old_pointer_grab_data = pepper_pointer_get_grab_data(pointer);
- pepper_pointer_set_grab(pointer, &pointer_resize_grab, shsurf);
+ shsurf->old_pointer_grab = pepper_pointer_get_grab(pointer);
+ shsurf->old_pointer_grab_data = pepper_pointer_get_grab_data(pointer);
+ pepper_pointer_set_grab(pointer, &pointer_resize_grab, shsurf);
}
void
shell_get_output_workarea(desktop_shell_t *shell,
- pepper_output_t *output,
- pixman_rectangle32_t *area)
+ pepper_output_t *output,
+ pixman_rectangle32_t *area)
{
- const pepper_output_geometry_t *geom;
-
- /**
- ** TODO: Get given output's workarea size and position in global coordinate
- ** return (output_size - (panel_size + margin + caption + ... ));
- **/
-
- geom = pepper_output_get_geometry(output);
-
- if (area)
- {
- area->x = geom->x;
- area->y = geom->y;
- area->width = geom->w;
- area->height = geom->h;
- }
+ const pepper_output_geometry_t *geom;
+
+ /**
+ ** TODO: Get given output's workarea size and position in global coordinate
+ ** return (output_size - (panel_size + margin + caption + ... ));
+ **/
+
+ geom = pepper_output_get_geometry(output);
+
+ if (area) {
+ area->x = geom->x;
+ area->y = geom->y;
+ area->width = geom->w;
+ area->height = geom->h;
+ }
}
static void
handle_shell_client_destroy(struct wl_listener *listener, void *data)
{
- shell_client_t *shell_client = pepper_container_of(listener, shell_client,
- client_destroy_listener);
+ shell_client_t *shell_client = pepper_container_of(listener, shell_client,
+ client_destroy_listener);
- remove_ping_timer(shell_client);
- pepper_list_remove(&shell_client->link);
- free(shell_client);
+ remove_ping_timer(shell_client);
+ pepper_list_remove(&shell_client->link);
+ free(shell_client);
}
shell_client_t *
shell_client_create(desktop_shell_t *shell, struct wl_client *client,
- const struct wl_interface *interface, const void *implementation,
- uint32_t version, uint32_t id)
+ const struct wl_interface *interface, const void *implementation,
+ uint32_t version, uint32_t id)
{
- shell_client_t *shell_client;
+ shell_client_t *shell_client;
- shell_client = calloc(1, sizeof(shell_client_t));
- if (!shell_client)
- {
- wl_client_post_no_memory(client);
- return NULL;
- }
+ shell_client = calloc(1, sizeof(shell_client_t));
+ if (!shell_client) {
+ wl_client_post_no_memory(client);
+ return NULL;
+ }
- shell_client->resource = wl_resource_create(client, interface, version, id);
- if (!shell_client->resource)
- {
- wl_client_post_no_memory(client);
- free(shell_client);
- return NULL;
- }
+ shell_client->resource = wl_resource_create(client, interface, version, id);
+ if (!shell_client->resource) {
+ wl_client_post_no_memory(client);
+ free(shell_client);
+ return NULL;
+ }
- shell_client->shell = shell;
- shell_client->client = client;
+ shell_client->shell = shell;
+ shell_client->client = client;
- shell_client->client_destroy_listener.notify = handle_shell_client_destroy;
- wl_client_add_destroy_listener(client, &shell_client->client_destroy_listener);
+ shell_client->client_destroy_listener.notify = handle_shell_client_destroy;
+ wl_client_add_destroy_listener(client, &shell_client->client_destroy_listener);
- pepper_list_insert(&shell->shell_client_list, &shell_client->link);
- wl_resource_set_implementation(shell_client->resource, implementation, shell_client, NULL);
+ pepper_list_insert(&shell->shell_client_list, &shell_client->link);
+ wl_resource_set_implementation(shell_client->resource, implementation,
+ shell_client, NULL);
- return shell_client;
+ return shell_client;
}
static void
shell_add_input_device(desktop_shell_t *shell, pepper_input_device_t *device)
{
- shell_seat_t *shseat;
- pepper_seat_t *seat;
- const char *target_seat_name;
- const char *seat_name;
-
- target_seat_name = pepper_input_device_get_property(device, "seat_name");
- if (!target_seat_name)
- target_seat_name = "seat0";
-
- pepper_list_for_each(shseat, &shell->shseat_list, link)
- {
- seat_name = pepper_seat_get_name(shseat->seat);
-
- /* Find seat to adding input device */
- if ( seat_name && !strcmp(seat_name, target_seat_name))
- {
- pepper_seat_add_input_device(shseat->seat, device);
- return ;
- }
- }
-
- seat = pepper_compositor_add_seat(shell->compositor, target_seat_name);
- pepper_seat_add_input_device(seat, device);
+ shell_seat_t *shseat;
+ pepper_seat_t *seat;
+ const char *target_seat_name;
+ const char *seat_name;
+
+ target_seat_name = pepper_input_device_get_property(device, "seat_name");
+ if (!target_seat_name)
+ target_seat_name = "seat0";
+
+ pepper_list_for_each(shseat, &shell->shseat_list, link) {
+ seat_name = pepper_seat_get_name(shseat->seat);
+
+ /* Find seat to adding input device */
+ if ( seat_name && !strcmp(seat_name, target_seat_name)) {
+ pepper_seat_add_input_device(shseat->seat, device);
+ return ;
+ }
+ }
+
+ seat = pepper_compositor_add_seat(shell->compositor, target_seat_name);
+ pepper_seat_add_input_device(seat, device);
}
static void
-default_pointer_grab_motion(pepper_pointer_t *pointer, void *data, uint32_t time, double x, double y)
+default_pointer_grab_motion(pepper_pointer_t *pointer, void *data,
+ uint32_t time, double x, double y)
{
- double vx, vy;
- pepper_compositor_t *compositor = pepper_pointer_get_compositor(pointer);
- pepper_view_t *view = pepper_compositor_pick_view(compositor, x, y, &vx, &vy);
- pepper_view_t *focus = pepper_pointer_get_focus(pointer);
-
- if (focus != view)
- {
- pepper_pointer_send_leave(pointer, focus);
- pepper_pointer_set_focus(pointer, view);
- pepper_pointer_send_enter(pointer, view, vx, vy);
- }
-
- pepper_pointer_send_motion(pointer, view, time, vx, vy);
+ double vx, vy;
+ pepper_compositor_t *compositor = pepper_pointer_get_compositor(pointer);
+ pepper_view_t *view = pepper_compositor_pick_view(compositor, x, y, &vx,
+ &vy);
+ pepper_view_t *focus = pepper_pointer_get_focus(pointer);
+
+ if (focus != view) {
+ pepper_pointer_send_leave(pointer, focus);
+ pepper_pointer_set_focus(pointer, view);
+ pepper_pointer_send_enter(pointer, view, vx, vy);
+ }
+
+ pepper_pointer_send_motion(pointer, view, time, vx, vy);
}
static void
default_pointer_grab_button(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state)
{
- pepper_seat_t *seat = pepper_pointer_get_seat(pointer);
- pepper_keyboard_t *keyboard = pepper_seat_get_keyboard(seat);
- pepper_view_t *pointer_focus = pepper_pointer_get_focus(pointer);
-
- if (keyboard && state == PEPPER_BUTTON_STATE_PRESSED)
- {
- pepper_view_t *keyboard_focus = pepper_keyboard_get_focus(keyboard);
-
- if (keyboard_focus != pointer_focus)
- {
- pepper_keyboard_send_leave(keyboard, keyboard_focus);
- pepper_keyboard_set_focus(keyboard, pointer_focus);
- pepper_keyboard_send_enter(keyboard, pointer_focus);
- }
-
- if (pointer_focus)
- {
- shell_seat_t *shseat = data;
- desktop_shell_t *shell = shseat->shell;
- pepper_surface_t *surface = pepper_view_get_surface(pointer_focus);
- shell_surface_t *shsurf = get_shsurf_from_surface(surface, shell);
-
- shell_surface_stack_top(shsurf, PEPPER_FALSE);
- }
- }
-
- pepper_pointer_send_button(pointer, pointer_focus, time, button, state);
+ pepper_seat_t *seat = pepper_pointer_get_seat(pointer);
+ pepper_keyboard_t *keyboard = pepper_seat_get_keyboard(seat);
+ pepper_view_t *pointer_focus = pepper_pointer_get_focus(pointer);
+
+ if (keyboard && state == PEPPER_BUTTON_STATE_PRESSED) {
+ pepper_view_t *keyboard_focus = pepper_keyboard_get_focus(keyboard);
+
+ if (keyboard_focus != pointer_focus) {
+ pepper_keyboard_send_leave(keyboard, keyboard_focus);
+ pepper_keyboard_set_focus(keyboard, pointer_focus);
+ pepper_keyboard_send_enter(keyboard, pointer_focus);
+ }
+
+ if (pointer_focus) {
+ shell_seat_t *shseat = data;
+ desktop_shell_t *shell = shseat->shell;
+ pepper_surface_t *surface = pepper_view_get_surface(pointer_focus);
+ shell_surface_t *shsurf = get_shsurf_from_surface(surface, shell);
+
+ shell_surface_stack_top(shsurf, PEPPER_FALSE);
+ }
+ }
+
+ pepper_pointer_send_button(pointer, pointer_focus, time, button, state);
}
static void
default_pointer_grab_axis(pepper_pointer_t *pointer, void *data,
- uint32_t time, uint32_t axis, double value)
+ uint32_t time, uint32_t axis, double value)
{
- pepper_pointer_send_axis(pointer, pepper_pointer_get_focus(pointer), time, axis, value);
+ pepper_pointer_send_axis(pointer, pepper_pointer_get_focus(pointer), time, axis,
+ value);
}
static void
default_pointer_grab_cancel(pepper_pointer_t *pointer, void *data)
{
- /* Nothing to do.*/
+ /* Nothing to do.*/
}
-static const pepper_pointer_grab_t default_pointer_grab =
-{
- default_pointer_grab_motion,
- default_pointer_grab_button,
- default_pointer_grab_axis,
- default_pointer_grab_cancel,
+static const pepper_pointer_grab_t default_pointer_grab = {
+ default_pointer_grab_motion,
+ default_pointer_grab_button,
+ default_pointer_grab_axis,
+ default_pointer_grab_cancel,
};
static void
-pointer_add_callback(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id,
- void *info, void *data)
+pointer_add_callback(pepper_event_listener_t *listener, pepper_object_t *object,
+ uint32_t id,
+ void *info, void *data)
{
- pepper_pointer_t *pointer = info;
- pepper_pointer_set_grab(pointer, &default_pointer_grab, data);
+ pepper_pointer_t *pointer = info;
+ pepper_pointer_set_grab(pointer, &default_pointer_grab, data);
}
static void
-pointer_remove_callback(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id,
- void *info, void *data)
+pointer_remove_callback(pepper_event_listener_t *listener,
+ pepper_object_t *object, uint32_t id,
+ void *info, void *data)
{
- /* Nothing to do. */
+ /* Nothing to do. */
}
static void
default_keyboard_grab_key(pepper_keyboard_t *keyboard, void *data,
- uint32_t time, uint32_t key, uint32_t state)
+ uint32_t time, uint32_t key, uint32_t state)
{
- pepper_keyboard_send_key(keyboard, pepper_keyboard_get_focus(keyboard), time, key, state);
+ pepper_keyboard_send_key(keyboard, pepper_keyboard_get_focus(keyboard), time,
+ key, state);
}
static void
-default_keyboard_grab_modifiers(pepper_keyboard_t *keyboard, void *data, uint32_t mods_depressed,
- uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
+default_keyboard_grab_modifiers(pepper_keyboard_t *keyboard, void *data,
+ uint32_t mods_depressed,
+ uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
{
- pepper_keyboard_send_modifiers(keyboard, pepper_keyboard_get_focus(keyboard),
- mods_depressed, mods_latched, mods_locked, group);
+ pepper_keyboard_send_modifiers(keyboard, pepper_keyboard_get_focus(keyboard),
+ mods_depressed, mods_latched, mods_locked, group);
}
static void
default_keyboard_grab_cancel(pepper_keyboard_t *keyboard, void *data)
{
- /* Nothing to do. */
+ /* Nothing to do. */
}
-static const pepper_keyboard_grab_t default_keyboard_grab =
-{
- default_keyboard_grab_key,
- default_keyboard_grab_modifiers,
- default_keyboard_grab_cancel,
+static const pepper_keyboard_grab_t default_keyboard_grab = {
+ default_keyboard_grab_key,
+ default_keyboard_grab_modifiers,
+ default_keyboard_grab_cancel,
};
static void
-keyboard_add_callback(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id,
- void *info, void *data)
+keyboard_add_callback(pepper_event_listener_t *listener,
+ pepper_object_t *object, uint32_t id,
+ void *info, void *data)
{
- pepper_keyboard_t *keyboard = info;
- pepper_keyboard_set_grab(keyboard, &default_keyboard_grab, NULL);
+ pepper_keyboard_t *keyboard = info;
+ pepper_keyboard_set_grab(keyboard, &default_keyboard_grab, NULL);
}
static void
-keyboard_remove_callback(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id,
- void *info, void *data)
+keyboard_remove_callback(pepper_event_listener_t *listener,
+ pepper_object_t *object, uint32_t id,
+ void *info, void *data)
{
- /* Nothing to do. */
+ /* Nothing to do. */
}
static void
-touch_add_callback(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id,
- void *info, void *data)
+touch_add_callback(pepper_event_listener_t *listener, pepper_object_t *object,
+ uint32_t id,
+ void *info, void *data)
{
- /* TODO: */
+ /* TODO: */
}
static void
-touch_remove_callback(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id,
- void *info, void *data)
+touch_remove_callback(pepper_event_listener_t *listener,
+ pepper_object_t *object, uint32_t id,
+ void *info, void *data)
{
- /* TODO: */
+ /* TODO: */
}
static void
shell_add_seat(desktop_shell_t *shell, pepper_seat_t *seat)
{
- shell_seat_t *shseat;
-
- pepper_list_for_each(shseat, &shell->shseat_list, link)
- {
- if (shseat->seat == seat)
- return ;
- }
-
- shseat = calloc(1, sizeof(shell_seat_t));
- if (!shseat)
- {
- PEPPER_ERROR("Memory allocation failed\n");
- return ;
- }
-
- shseat->seat = seat;
- shseat->shell = shell;
-
- pepper_list_insert(&shell->shseat_list, &shseat->link);
- pepper_object_set_user_data((pepper_object_t *)seat, shell, shseat, NULL);
-
- shseat->pointer_add_listener =
- pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_POINTER_ADD,
- 0, pointer_add_callback, shseat);
-
- shseat->pointer_remove_listener =
- pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_POINTER_REMOVE,
- 0, pointer_remove_callback, shseat);
-
- shseat->keyboard_add_listener =
- pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_KEYBOARD_ADD,
- 0, keyboard_add_callback, shseat);
-
- shseat->keyboard_remove_listener =
- pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_KEYBOARD_REMOVE,
- 0, keyboard_remove_callback, shseat);
-
- shseat->touch_add_listener =
- pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_TOUCH_ADD,
- 0, touch_add_callback, shseat);
-
- shseat->touch_remove_listener =
- pepper_object_add_event_listener((pepper_object_t *)seat, PEPPER_EVENT_SEAT_TOUCH_REMOVE,
- 0, touch_remove_callback, shseat);
+ shell_seat_t *shseat;
+
+ pepper_list_for_each(shseat, &shell->shseat_list, link) {
+ if (shseat->seat == seat)
+ return ;
+ }
+
+ shseat = calloc(1, sizeof(shell_seat_t));
+ if (!shseat) {
+ PEPPER_ERROR("Memory allocation failed\n");
+ return ;
+ }
+
+ shseat->seat = seat;
+ shseat->shell = shell;
+
+ pepper_list_insert(&shell->shseat_list, &shseat->link);
+ pepper_object_set_user_data((pepper_object_t *)seat, shell, shseat, NULL);
+
+ shseat->pointer_add_listener =
+ pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_POINTER_ADD,
+ 0, pointer_add_callback, shseat);
+
+ shseat->pointer_remove_listener =
+ pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_POINTER_REMOVE,
+ 0, pointer_remove_callback, shseat);
+
+ shseat->keyboard_add_listener =
+ pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_KEYBOARD_ADD,
+ 0, keyboard_add_callback, shseat);
+
+ shseat->keyboard_remove_listener =
+ pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_KEYBOARD_REMOVE,
+ 0, keyboard_remove_callback, shseat);
+
+ shseat->touch_add_listener =
+ pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_TOUCH_ADD,
+ 0, touch_add_callback, shseat);
+
+ shseat->touch_remove_listener =
+ pepper_object_add_event_listener((pepper_object_t *)seat,
+ PEPPER_EVENT_SEAT_TOUCH_REMOVE,
+ 0, touch_remove_callback, shseat);
}
static void
shell_remove_seat(desktop_shell_t *shell, pepper_seat_t *seat)
{
- shell_seat_t *shseat;
-
- pepper_list_for_each(shseat, &shell->shseat_list, link)
- {
- if (shseat->seat == seat)
- {
- pepper_list_remove(&shseat->link);
- free(shseat);
- return ;
- }
- }
+ shell_seat_t *shseat;
+
+ pepper_list_for_each(shseat, &shell->shseat_list, link) {
+ if (shseat->seat == seat) {
+ pepper_list_remove(&shseat->link);
+ free(shseat);
+ return ;
+ }
+ }
}
static void
input_device_add_callback(pepper_event_listener_t *listener,
- pepper_object_t *object,
- uint32_t id,
- void *info,
- void *data)
+ pepper_object_t *object,
+ uint32_t id,
+ void *info,
+ void *data)
{
- shell_add_input_device(data, info);
+ shell_add_input_device(data, info);
}
static void
seat_add_callback(pepper_event_listener_t *listener,
- pepper_object_t *object,
- uint32_t id,
- void *info,
- void *data)
+ pepper_object_t *object,
+ uint32_t id,
+ void *info,
+ void *data)
{
- shell_add_seat(data, info);
+ shell_add_seat(data, info);
}
static void
seat_remove_callback(pepper_event_listener_t *listener,
- pepper_object_t *object,
- uint32_t id,
- void *info,
- void *data)
+ pepper_object_t *object,
+ uint32_t id,
+ void *info,
+ void *data)
{
- shell_remove_seat(data, info);
+ shell_remove_seat(data, info);
}
static void
init_listeners(desktop_shell_t *shell)
{
- pepper_object_t *compositor = (pepper_object_t *)shell->compositor;
-
- /* input_device_add */
- shell->input_device_add_listener =
- pepper_object_add_event_listener(compositor, PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
- 0, input_device_add_callback, shell);
-
- shell->seat_add_listener =
- pepper_object_add_event_listener(compositor, PEPPER_EVENT_COMPOSITOR_SEAT_ADD,
- 0, seat_add_callback, shell);
-
- shell->seat_remove_listener =
- pepper_object_add_event_listener(compositor, PEPPER_EVENT_COMPOSITOR_SEAT_REMOVE,
- 0, seat_remove_callback, shell);
+ pepper_object_t *compositor = (pepper_object_t *)shell->compositor;
+
+ /* input_device_add */
+ shell->input_device_add_listener =
+ pepper_object_add_event_listener(compositor,
+ PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
+ 0, input_device_add_callback, shell);
+
+ shell->seat_add_listener =
+ pepper_object_add_event_listener(compositor, PEPPER_EVENT_COMPOSITOR_SEAT_ADD,
+ 0, seat_add_callback, shell);
+
+ shell->seat_remove_listener =
+ pepper_object_add_event_listener(compositor,
+ PEPPER_EVENT_COMPOSITOR_SEAT_REMOVE,
+ 0, seat_remove_callback, shell);
}
static void
init_input(desktop_shell_t *shell)
{
- pepper_list_t *l;
- const pepper_list_t *input_device_list =
- pepper_compositor_get_input_device_list(shell->compositor);
+ pepper_list_t *l;
+ const pepper_list_t *input_device_list =
+ pepper_compositor_get_input_device_list(shell->compositor);
- pepper_list_for_each_list(l, input_device_list)
- shell_add_input_device(shell, l->item);
+ pepper_list_for_each_list(l, input_device_list)
+ shell_add_input_device(shell, l->item);
}
static pepper_bool_t
launch_shell_client(desktop_shell_t *shell)
{
- /* TODO: */
- return PEPPER_FALSE;
+ /* TODO: */
+ return PEPPER_FALSE;
}
PEPPER_API pepper_bool_t
pepper_desktop_shell_init(pepper_compositor_t *compositor)
{
- desktop_shell_t *shell;
-
- shell = calloc(1, sizeof(desktop_shell_t));
- if (!shell)
- {
- PEPPER_ERROR("Memory allocation failed\n");
- return PEPPER_FALSE;
- }
-
- shell->compositor = compositor;
-
- pepper_list_init(&shell->shell_client_list);
- pepper_list_init(&shell->shell_surface_list);
- pepper_list_init(&shell->shseat_list);
-
- if (!init_wl_shell(shell))
- {
- PEPPER_ERROR("init_wl_shell() failed\n");
- free(shell);
- return PEPPER_FALSE;
- }
-
- if (!init_xdg_shell(shell))
- {
- PEPPER_ERROR("init_xdg_shell() failed\n");
- fini_wl_shell(shell);
- free(shell);
- return PEPPER_FALSE;
- }
-
- if (!init_pepper_shell(shell))
- {
- PEPPER_ERROR("init_pepper_shell() failed.\n");
- fini_wl_shell(shell);
- fini_xdg_shell(shell);
- free(shell);
- return PEPPER_FALSE;
- }
-
- if (!launch_shell_client(shell))
- PEPPER_ERROR("shell client launch failed, compositor runs without shell client.\n");
-
- init_listeners(shell);
- init_input(shell);
-
- return PEPPER_TRUE;
+ desktop_shell_t *shell;
+
+ shell = calloc(1, sizeof(desktop_shell_t));
+ if (!shell) {
+ PEPPER_ERROR("Memory allocation failed\n");
+ return PEPPER_FALSE;
+ }
+
+ shell->compositor = compositor;
+
+ pepper_list_init(&shell->shell_client_list);
+ pepper_list_init(&shell->shell_surface_list);
+ pepper_list_init(&shell->shseat_list);
+
+ if (!init_wl_shell(shell)) {
+ PEPPER_ERROR("init_wl_shell() failed\n");
+ free(shell);
+ return PEPPER_FALSE;
+ }
+
+ if (!init_xdg_shell(shell)) {
+ PEPPER_ERROR("init_xdg_shell() failed\n");
+ fini_wl_shell(shell);
+ free(shell);
+ return PEPPER_FALSE;
+ }
+
+ if (!init_pepper_shell(shell)) {
+ PEPPER_ERROR("init_pepper_shell() failed.\n");
+ fini_wl_shell(shell);
+ fini_xdg_shell(shell);
+ free(shell);
+ return PEPPER_FALSE;
+ }
+
+ if (!launch_shell_client(shell))
+ PEPPER_ERROR("shell client launch failed, compositor runs without shell client.\n");
+
+ init_listeners(shell);
+ init_input(shell);
+
+ return PEPPER_TRUE;
}
#include "desktop-shell-internal.h"
static void
-wl_shell_surface_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial)
+wl_shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
+ uint32_t serial)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_handle_pong(shsurf, serial);
+ shell_surface_handle_pong(shsurf, serial);
}
static void
wl_shell_surface_move(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *seat_resource,
- uint32_t serial)
+ struct wl_resource *resource,
+ struct wl_resource *seat_resource,
+ uint32_t serial)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_seat_t *seat = wl_resource_get_user_data(seat_resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_seat_t *seat = wl_resource_get_user_data(seat_resource);
- shell_surface_move(shsurf, seat, serial);
+ shell_surface_move(shsurf, seat, serial);
}
static void
wl_shell_surface_resize(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *seat_resource,
- uint32_t serial,
- uint32_t edges)
+ struct wl_resource *resource,
+ struct wl_resource *seat_resource,
+ uint32_t serial,
+ uint32_t edges)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_seat_t *seat = wl_resource_get_user_data(seat_resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_seat_t *seat = wl_resource_get_user_data(seat_resource);
- shell_surface_resize(shsurf, seat, serial, edges);
+ shell_surface_resize(shsurf, seat, serial, edges);
}
static void
-wl_shell_surface_set_toplevel(struct wl_client *client, struct wl_resource *resource)
+wl_shell_surface_set_toplevel(struct wl_client *client,
+ struct wl_resource *resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_toplevel(shsurf);
+ shell_surface_set_toplevel(shsurf);
}
static void
wl_shell_surface_set_transient(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *parent_resource,
- int32_t x,
- int32_t y,
- uint32_t flags)
+ struct wl_resource *resource,
+ struct wl_resource *parent_resource,
+ int32_t x,
+ int32_t y,
+ uint32_t flags)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_surface_t *parent = wl_resource_get_user_data(parent_resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_surface_t *parent = wl_resource_get_user_data(parent_resource);
- shell_surface_set_transient(shsurf, parent, x, y, flags);
+ shell_surface_set_transient(shsurf, parent, x, y, flags);
}
static void
wl_shell_surface_set_fullscreen(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t method,
- uint32_t framerate,
- struct wl_resource *output_resource)
+ struct wl_resource *resource,
+ uint32_t method,
+ uint32_t framerate,
+ struct wl_resource *output_resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_output_t *output = NULL;
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_output_t *output = NULL;
- if (output_resource)
- output = wl_resource_get_user_data(output_resource);
+ if (output_resource)
+ output = wl_resource_get_user_data(output_resource);
- shell_surface_set_fullscreen(shsurf, output, method, framerate);
+ shell_surface_set_fullscreen(shsurf, output, method, framerate);
}
static void
wl_shell_surface_set_popup(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *seat_res,
- uint32_t serial,
- struct wl_resource *parent_res,
- int32_t x,
- int32_t y,
- uint32_t flags)
-{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_seat_t *seat;
- pepper_surface_t *parent;
-
- if (!seat_res)
- {
- wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
- "Invalid seat");
- return ;
- }
- seat = wl_resource_get_user_data(seat_res);
-
- if (!parent_res)
- {
- wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
- "Invalid parent surface");
- return ;
- }
- parent = wl_resource_get_user_data(parent_res);
-
- shell_surface_set_popup(shsurf, seat, parent, x, y, flags, serial);
+ struct wl_resource *resource,
+ struct wl_resource *seat_res,
+ uint32_t serial,
+ struct wl_resource *parent_res,
+ int32_t x,
+ int32_t y,
+ uint32_t flags)
+{
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_seat_t *seat;
+ pepper_surface_t *parent;
+
+ if (!seat_res) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid seat");
+ return ;
+ }
+ seat = wl_resource_get_user_data(seat_res);
+
+ if (!parent_res) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid parent surface");
+ return ;
+ }
+ parent = wl_resource_get_user_data(parent_res);
+
+ shell_surface_set_popup(shsurf, seat, parent, x, y, flags, serial);
}
static void
-wl_shell_surface_set_maximized(struct wl_client *client, struct wl_resource *resource,
- struct wl_resource *output_res)
+wl_shell_surface_set_maximized(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *output_res)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_output_t *output = NULL;
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_output_t *output = NULL;
- if (output_res)
- output = wl_resource_get_user_data(output_res);
+ if (output_res)
+ output = wl_resource_get_user_data(output_res);
- shell_surface_set_maximized(shsurf, output);
+ shell_surface_set_maximized(shsurf, output);
}
static void
-wl_shell_surface_set_title(struct wl_client *client, struct wl_resource *resource,
- const char *title)
+wl_shell_surface_set_title(struct wl_client *client,
+ struct wl_resource *resource,
+ const char *title)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_title(shsurf, title);
+ shell_surface_set_title(shsurf, title);
}
static void
-wl_shell_surface_set_class(struct wl_client *client, struct wl_resource *resource,
- const char *class_)
+wl_shell_surface_set_class(struct wl_client *client,
+ struct wl_resource *resource,
+ const char *class_)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_class(shsurf, class_);
+ shell_surface_set_class(shsurf, class_);
}
-static const struct wl_shell_surface_interface shell_surface_implementation =
-{
- wl_shell_surface_pong,
- wl_shell_surface_move,
- wl_shell_surface_resize,
- wl_shell_surface_set_toplevel,
- wl_shell_surface_set_transient,
- wl_shell_surface_set_fullscreen,
- wl_shell_surface_set_popup,
- wl_shell_surface_set_maximized,
- wl_shell_surface_set_title,
- wl_shell_surface_set_class,
+static const struct wl_shell_surface_interface shell_surface_implementation = {
+ wl_shell_surface_pong,
+ wl_shell_surface_move,
+ wl_shell_surface_resize,
+ wl_shell_surface_set_toplevel,
+ wl_shell_surface_set_transient,
+ wl_shell_surface_set_fullscreen,
+ wl_shell_surface_set_popup,
+ wl_shell_surface_set_maximized,
+ wl_shell_surface_set_title,
+ wl_shell_surface_set_class,
};
static void
-wl_shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource,
- uint32_t id, struct wl_resource *surface_resource)
-{
- shell_client_t *shell_client = wl_resource_get_user_data(resource);
- pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
- shell_surface_t *shsurf;
-
- /* Only one shell surface can be associated with a given surface.*/
- if (!pepper_surface_set_role(surface, "wl_shell_surface"))
- {
- wl_resource_post_error(resource, WL_SHELL_ERROR_ROLE,
- "Assign \"wl_shell_surface\" to wl_surface failed\n");
- return ;
- }
-
- shsurf = shell_surface_create(shell_client, surface, client, &wl_shell_surface_interface,
- &shell_surface_implementation, 1, id);
- if (!shsurf)
- wl_client_post_no_memory(client);
+wl_shell_get_shell_surface(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id, struct wl_resource *surface_resource)
+{
+ shell_client_t *shell_client = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
+ shell_surface_t *shsurf;
+
+ /* Only one shell surface can be associated with a given surface.*/
+ if (!pepper_surface_set_role(surface, "wl_shell_surface")) {
+ wl_resource_post_error(resource, WL_SHELL_ERROR_ROLE,
+ "Assign \"wl_shell_surface\" to wl_surface failed\n");
+ return ;
+ }
+
+ shsurf = shell_surface_create(shell_client, surface, client,
+ &wl_shell_surface_interface,
+ &shell_surface_implementation, 1, id);
+ if (!shsurf)
+ wl_client_post_no_memory(client);
}
-static const struct wl_shell_interface shell_implementation =
-{
- wl_shell_get_shell_surface,
+static const struct wl_shell_interface shell_implementation = {
+ wl_shell_get_shell_surface,
};
static void
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
- shell_client_create((desktop_shell_t *)data, client,
- &wl_shell_interface, &shell_implementation, version, id);
+ shell_client_create((desktop_shell_t *)data, client,
+ &wl_shell_interface, &shell_implementation, version, id);
}
pepper_bool_t
init_wl_shell(desktop_shell_t *shell)
{
- struct wl_display *display = pepper_compositor_get_display(shell->compositor);
- struct wl_global *global;
+ struct wl_display *display = pepper_compositor_get_display(shell->compositor);
+ struct wl_global *global;
- global = wl_global_create(display, &wl_shell_interface, 1, shell, bind_shell);
- if (!global)
- return PEPPER_FALSE;
+ global = wl_global_create(display, &wl_shell_interface, 1, shell, bind_shell);
+ if (!global)
+ return PEPPER_FALSE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
void
fini_wl_shell(desktop_shell_t *shell)
{
- /* TODO */
+ /* TODO */
}
static void
xdg_surface_destroy(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
static void
xdg_surface_set_parent(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *parent_resource)
+ struct wl_resource *resource,
+ struct wl_resource *parent_resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_t *parent = NULL;
-
- if (parent_resource)
- {
- parent = wl_resource_get_user_data(parent_resource);
- shell_surface_set_parent(shsurf, parent->surface);
- }
- else
- {
- shell_surface_set_parent(shsurf, NULL);
- }
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *parent = NULL;
+
+ if (parent_resource) {
+ parent = wl_resource_get_user_data(parent_resource);
+ shell_surface_set_parent(shsurf, parent->surface);
+ } else {
+ shell_surface_set_parent(shsurf, NULL);
+ }
}
static void
xdg_surface_set_app_id(struct wl_client *client,
- struct wl_resource *resource,
- const char *app_id)
+ struct wl_resource *resource,
+ const char *app_id)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_class(shsurf, app_id);
+ shell_surface_set_class(shsurf, app_id);
}
static void
xdg_surface_show_window_menu(struct wl_client *client,
- struct wl_resource *surface_resource,
- struct wl_resource *seat_resource,
- uint32_t serial,
- int32_t x,
- int32_t y)
+ struct wl_resource *surface_resource,
+ struct wl_resource *seat_resource,
+ uint32_t serial,
+ int32_t x,
+ int32_t y)
{
- /* TODO: */
+ /* TODO: */
}
static void
xdg_surface_set_title(struct wl_client *client,
- struct wl_resource *resource,
- const char *title)
+ struct wl_resource *resource,
+ const char *title)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_title(shsurf, title);
+ shell_surface_set_title(shsurf, title);
}
static void
xdg_surface_move(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *seat_resource,
- uint32_t serial)
+ struct wl_resource *resource,
+ struct wl_resource *seat_resource,
+ uint32_t serial)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_seat_t *seat;
-
- if (!seat_resource)
- {
- wl_resource_post_error(resource,
- WL_DISPLAY_ERROR_INVALID_OBJECT,
- "Invalid seat");
- return ;
- }
- seat = wl_resource_get_user_data(seat_resource);
-
- shell_surface_move(shsurf, seat, serial);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_seat_t *seat;
+
+ if (!seat_resource) {
+ wl_resource_post_error(resource,
+ WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid seat");
+ return ;
+ }
+ seat = wl_resource_get_user_data(seat_resource);
+
+ shell_surface_move(shsurf, seat, serial);
}
static void
xdg_surface_resize(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *seat_resource,
- uint32_t serial,
- uint32_t edges)
+ struct wl_resource *resource,
+ struct wl_resource *seat_resource,
+ uint32_t serial,
+ uint32_t edges)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_seat_t *seat;
-
- if (!seat_resource)
- {
- wl_resource_post_error(resource,
- WL_DISPLAY_ERROR_INVALID_OBJECT,
- "Invalid seat");
- return ;
- }
- seat = wl_resource_get_user_data(seat_resource);
-
- shell_surface_resize(shsurf, seat, serial, edges);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_seat_t *seat;
+
+ if (!seat_resource) {
+ wl_resource_post_error(resource,
+ WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid seat");
+ return ;
+ }
+ seat = wl_resource_get_user_data(seat_resource);
+
+ shell_surface_resize(shsurf, seat, serial, edges);
}
static void
xdg_surface_ack_configure(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t serial)
+ struct wl_resource *resource,
+ uint32_t serial)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_ack_configure(shsurf, serial);
+ shell_surface_ack_configure(shsurf, serial);
}
static void
xdg_surface_set_window_geometry(struct wl_client *client,
- struct wl_resource *resource,
- int32_t x,
- int32_t y,
- int32_t width,
- int32_t height)
+ struct wl_resource *resource,
+ int32_t x,
+ int32_t y,
+ int32_t width,
+ int32_t height)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_geometry(shsurf, x, y, width, height);
+ shell_surface_set_geometry(shsurf, x, y, width, height);
}
static void
xdg_surface_set_maximized(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_maximized(shsurf, NULL);
+ shell_surface_set_maximized(shsurf, NULL);
}
static void
xdg_surface_unset_maximized(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_unset_maximized(shsurf);
+ shell_surface_unset_maximized(shsurf);
}
static void
xdg_surface_set_fullscreen(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *output_resource)
+ struct wl_resource *resource,
+ struct wl_resource *output_resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- pepper_output_t *output = NULL;
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ pepper_output_t *output = NULL;
- if (output_resource)
- output = wl_resource_get_user_data(output_resource);
+ if (output_resource)
+ output = wl_resource_get_user_data(output_resource);
- shell_surface_set_fullscreen(shsurf, output, 0, 0);
+ shell_surface_set_fullscreen(shsurf, output, 0, 0);
}
static void
xdg_surface_unset_fullscreen(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_unset_fullscreen(shsurf);
+ shell_surface_unset_fullscreen(shsurf);
}
static void
xdg_surface_set_minimized(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+ shell_surface_t *shsurf = wl_resource_get_user_data(resource);
- shell_surface_set_minimized(shsurf);
+ shell_surface_set_minimized(shsurf);
}
-static const struct xdg_surface_interface xdg_surface_implementation =
-{
- xdg_surface_destroy,
- xdg_surface_set_parent,
- xdg_surface_set_title,
- xdg_surface_set_app_id,
- xdg_surface_show_window_menu,
- xdg_surface_move,
- xdg_surface_resize,
- xdg_surface_ack_configure,
- xdg_surface_set_window_geometry,
- xdg_surface_set_maximized,
- xdg_surface_unset_maximized,
- xdg_surface_set_fullscreen,
- xdg_surface_unset_fullscreen,
- xdg_surface_set_minimized,
+static const struct xdg_surface_interface xdg_surface_implementation = {
+ xdg_surface_destroy,
+ xdg_surface_set_parent,
+ xdg_surface_set_title,
+ xdg_surface_set_app_id,
+ xdg_surface_show_window_menu,
+ xdg_surface_move,
+ xdg_surface_resize,
+ xdg_surface_ack_configure,
+ xdg_surface_set_window_geometry,
+ xdg_surface_set_maximized,
+ xdg_surface_unset_maximized,
+ xdg_surface_set_fullscreen,
+ xdg_surface_unset_fullscreen,
+ xdg_surface_set_minimized,
};
static void
xdg_shell_destroy(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- /* TODO: */
+ /* TODO: */
}
static void
xdg_shell_use_unstable_version(struct wl_client *client,
- struct wl_resource *resource,
- int32_t version)
+ struct wl_resource *resource,
+ int32_t version)
{
- /* TODO: */
- if (version != XDG_SHELL_VERSION_CURRENT)
- {
- PEPPER_ERROR("wl_client@%p want bad XDG_SHELL version %d\n", client, version);
- }
+ /* TODO: */
+ if (version != XDG_SHELL_VERSION_CURRENT) {
+ PEPPER_ERROR("wl_client@%p want bad XDG_SHELL version %d\n", client, version);
+ }
}
static void
xdg_shell_get_xdg_surface(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id,
- struct wl_resource *surface_resource)
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource *surface_resource)
{
- shell_client_t *shell_client = wl_resource_get_user_data(resource);
- pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
- shell_surface_t *shsurf;
-
- if (!pepper_surface_set_role(surface, "xdg_surface"))
- {
- wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE,
- "Assign \"xdg_surface\" to wl_surface failed\n");
- return ;
- }
-
- shsurf = shell_surface_create(shell_client, surface, client, &xdg_surface_interface,
- &xdg_surface_implementation, 1, id);
- if (!shsurf)
- {
- wl_client_post_no_memory(client);
- return ;
- }
-
- shell_surface_set_toplevel(shsurf);
+ shell_client_t *shell_client = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
+ shell_surface_t *shsurf;
+
+ if (!pepper_surface_set_role(surface, "xdg_surface")) {
+ wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE,
+ "Assign \"xdg_surface\" to wl_surface failed\n");
+ return ;
+ }
+
+ shsurf = shell_surface_create(shell_client, surface, client,
+ &xdg_surface_interface,
+ &xdg_surface_implementation, 1, id);
+ if (!shsurf) {
+ wl_client_post_no_memory(client);
+ return ;
+ }
+
+ shell_surface_set_toplevel(shsurf);
}
static void
xdg_popup_destroy(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
-static const struct xdg_popup_interface xdg_popup_implementation =
-{
- xdg_popup_destroy,
+static const struct xdg_popup_interface xdg_popup_implementation = {
+ xdg_popup_destroy,
};
static void
xdg_shell_get_xdg_popup(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id,
- struct wl_resource *surface_resource,
- struct wl_resource *parent_resource,
- struct wl_resource *seat_resource,
- uint32_t serial,
- int32_t x,
- int32_t y)
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource *surface_resource,
+ struct wl_resource *parent_resource,
+ struct wl_resource *seat_resource,
+ uint32_t serial,
+ int32_t x,
+ int32_t y)
{
- shell_client_t *shell_client = wl_resource_get_user_data(resource);
- pepper_surface_t *surface;
- pepper_seat_t *seat;
- pepper_surface_t *parent;
- shell_surface_t *shsurf;
- int flags = 0;
-
- /* Check parameters */
- if (!surface_resource)
- {
- wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "Invalid surface");
- return ;
- }
- surface = wl_resource_get_user_data(surface_resource);
-
- if (!seat_resource)
- {
- wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "Invalid seat");
- return ;
- }
- seat = wl_resource_get_user_data(seat_resource);
-
- if (!parent_resource)
- {
- wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "Invalid parent surface");
- return ;
- }
- parent = wl_resource_get_user_data(parent_resource);
-
- /**
- * TODO: check parent state
- * 1. Parent must have either a xdg_surface or xdg_popup role
- * 2. If there is an existing popup when creating a new popup, the
- * parent must be the current topmost popup.
- */
- {
- const char *role = pepper_surface_get_role(parent);
-
- if (strcmp(role, "xdg_surface") && strcmp(role, "xdg_popup"))
- {
- wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
- "Invalid xdg_popup parent");
- return ;
- }
- }
-
- /* Set role */
- if (!pepper_surface_set_role(surface, "xdg_popup"))
- {
- wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE,
- "Assign \"xdg_popup\" to wl_surface failed\n");
- return ;
- }
-
- /* TODO: */
-
- shsurf = shell_surface_create(shell_client, surface, client, &xdg_popup_interface,
- &xdg_popup_implementation, 1, id);
- if (!shsurf)
- {
- wl_client_post_no_memory(client);
- return ;
- }
-
- shell_surface_set_popup(shsurf, seat, parent, x, y, flags, serial);
+ shell_client_t *shell_client = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface;
+ pepper_seat_t *seat;
+ pepper_surface_t *parent;
+ shell_surface_t *shsurf;
+ int flags = 0;
+
+ /* Check parameters */
+ if (!surface_resource) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid surface");
+ return ;
+ }
+ surface = wl_resource_get_user_data(surface_resource);
+
+ if (!seat_resource) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid seat");
+ return ;
+ }
+ seat = wl_resource_get_user_data(seat_resource);
+
+ if (!parent_resource) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid parent surface");
+ return ;
+ }
+ parent = wl_resource_get_user_data(parent_resource);
+
+ /**
+ * TODO: check parent state
+ * 1. Parent must have either a xdg_surface or xdg_popup role
+ * 2. If there is an existing popup when creating a new popup, the
+ * parent must be the current topmost popup.
+ */
+ {
+ const char *role = pepper_surface_get_role(parent);
+
+ if (strcmp(role, "xdg_surface") && strcmp(role, "xdg_popup")) {
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "Invalid xdg_popup parent");
+ return ;
+ }
+ }
+
+ /* Set role */
+ if (!pepper_surface_set_role(surface, "xdg_popup")) {
+ wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE,
+ "Assign \"xdg_popup\" to wl_surface failed\n");
+ return ;
+ }
+
+ /* TODO: */
+
+ shsurf = shell_surface_create(shell_client, surface, client,
+ &xdg_popup_interface,
+ &xdg_popup_implementation, 1, id);
+ if (!shsurf) {
+ wl_client_post_no_memory(client);
+ return ;
+ }
+
+ shell_surface_set_popup(shsurf, seat, parent, x, y, flags, serial);
}
static void
xdg_shell_pong(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t serial)
+ struct wl_resource *resource,
+ uint32_t serial)
{
- shell_client_t *shell_client = wl_resource_get_user_data(resource);
+ shell_client_t *shell_client = wl_resource_get_user_data(resource);
- shell_client_handle_pong(shell_client, serial);
+ shell_client_handle_pong(shell_client, serial);
}
-static const struct xdg_shell_interface xdg_shell_implementation =
-{
- xdg_shell_destroy,
- xdg_shell_use_unstable_version,
- xdg_shell_get_xdg_surface,
- xdg_shell_get_xdg_popup,
- xdg_shell_pong
+static const struct xdg_shell_interface xdg_shell_implementation = {
+ xdg_shell_destroy,
+ xdg_shell_use_unstable_version,
+ xdg_shell_get_xdg_surface,
+ xdg_shell_get_xdg_popup,
+ xdg_shell_pong
};
static void
-bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
+bind_xdg_shell(struct wl_client *client, void *data, uint32_t version,
+ uint32_t id)
{
- shell_client_create((desktop_shell_t *)data, client,
- &xdg_shell_interface, &xdg_shell_implementation, version, id);
+ shell_client_create((desktop_shell_t *)data, client,
+ &xdg_shell_interface, &xdg_shell_implementation, version, id);
}
pepper_bool_t
init_xdg_shell(desktop_shell_t *shell)
{
- struct wl_display *display = pepper_compositor_get_display(shell->compositor);
- struct wl_global *global;
+ struct wl_display *display = pepper_compositor_get_display(shell->compositor);
+ struct wl_global *global;
- global = wl_global_create(display, &xdg_shell_interface, 1, shell, bind_xdg_shell);
- if (!global)
- return PEPPER_FALSE;
+ global = wl_global_create(display, &xdg_shell_interface, 1, shell,
+ bind_xdg_shell);
+ if (!global)
+ return PEPPER_FALSE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
void
fini_xdg_shell(desktop_shell_t *shell)
{
- /* TODO */
+ /* TODO */
}
* Copyright © 2012 Collabora, Ltd.
* Copyright © 2015 S-Core Corporation
* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
+*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
-*
+*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
-*
+*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
drm_buffer_t *
drm_buffer_create_dumb(pepper_drm_t *drm, uint32_t w, uint32_t h)
{
- drm_buffer_t *buffer;
- struct drm_mode_create_dumb create_arg;
- struct drm_mode_map_dumb map_arg;
- int ret;
+ drm_buffer_t *buffer;
+ struct drm_mode_create_dumb create_arg;
+ struct drm_mode_map_dumb map_arg;
+ int ret;
- buffer = calloc(1, sizeof(drm_buffer_t));
- PEPPER_CHECK(buffer, return NULL, "calloc() failed.\n");
+ buffer = calloc(1, sizeof(drm_buffer_t));
+ PEPPER_CHECK(buffer, return NULL, "calloc() failed.\n");
- buffer->drm = drm;
- buffer->type = DRM_BUFFER_TYPE_DUMB;
- buffer->w = w;
- buffer->h = h;
+ buffer->drm = drm;
+ buffer->type = DRM_BUFFER_TYPE_DUMB;
+ buffer->w = w;
+ buffer->h = h;
- memset(&create_arg, 0x00, sizeof(create_arg));
- create_arg.bpp = 32;
- create_arg.width = w;
- create_arg.height = h;
+ memset(&create_arg, 0x00, sizeof(create_arg));
+ create_arg.bpp = 32;
+ create_arg.width = w;
+ create_arg.height = h;
- ret = drmIoctl(drm->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg);
- PEPPER_CHECK(ret == 0, goto error, "drmIoctl() failed.\n");
+ ret = drmIoctl(drm->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg);
+ PEPPER_CHECK(ret == 0, goto error, "drmIoctl() failed.\n");
- buffer->handle = create_arg.handle;
- buffer->stride = create_arg.pitch;
- buffer->size = create_arg.size;
+ buffer->handle = create_arg.handle;
+ buffer->stride = create_arg.pitch;
+ buffer->size = create_arg.size;
- ret = drmModeAddFB(drm->fd, w, h, 24, 32, buffer->stride, buffer->handle, &buffer->id);
- PEPPER_CHECK(ret == 0, goto error, "drmModeAddFB() failed.\n");
+ ret = drmModeAddFB(drm->fd, w, h, 24, 32, buffer->stride, buffer->handle,
+ &buffer->id);
+ PEPPER_CHECK(ret == 0, goto error, "drmModeAddFB() failed.\n");
- memset(&map_arg, 0, sizeof(map_arg));
- map_arg.handle = buffer->handle;
+ memset(&map_arg, 0, sizeof(map_arg));
+ map_arg.handle = buffer->handle;
- ret = drmIoctl(drm->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
- PEPPER_CHECK(ret == 0, goto error, "drmIoctl() failed.\n");
+ ret = drmIoctl(drm->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
+ PEPPER_CHECK(ret == 0, goto error, "drmIoctl() failed.\n");
- buffer->map = mmap(0, buffer->size, PROT_WRITE, MAP_SHARED, drm->fd, map_arg.offset);
- PEPPER_CHECK(buffer->map != MAP_FAILED, goto error, "mmap() failed.\n");
+ buffer->map = mmap(0, buffer->size, PROT_WRITE, MAP_SHARED, drm->fd,
+ map_arg.offset);
+ PEPPER_CHECK(buffer->map != MAP_FAILED, goto error, "mmap() failed.\n");
- buffer->image = pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, buffer->map, buffer->stride);
- PEPPER_CHECK(buffer->image, goto error, "pixman_image_create_bits() failed.\n");
+ buffer->image = pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, buffer->map,
+ buffer->stride);
+ PEPPER_CHECK(buffer->image, goto error, "pixman_image_create_bits() failed.\n");
- return buffer;
+ return buffer;
error:
- if (buffer->map)
- munmap(buffer->map, buffer->size);
+ if (buffer->map)
+ munmap(buffer->map, buffer->size);
- if (buffer->id)
- drmModeRmFB(drm->fd, buffer->id);
+ if (buffer->id)
+ drmModeRmFB(drm->fd, buffer->id);
- if (buffer->handle)
- {
- struct drm_mode_destroy_dumb destroy_arg;
+ if (buffer->handle) {
+ struct drm_mode_destroy_dumb destroy_arg;
- memset(&destroy_arg, 0x00, sizeof(destroy_arg));
- destroy_arg.handle = buffer->handle;
- drmIoctl(drm->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
- }
+ memset(&destroy_arg, 0x00, sizeof(destroy_arg));
+ destroy_arg.handle = buffer->handle;
+ drmIoctl(drm->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
+ }
- if (buffer->image)
- pixman_image_unref(buffer->image);
+ if (buffer->image)
+ pixman_image_unref(buffer->image);
- free(buffer);
- return NULL;
+ free(buffer);
+ return NULL;
}
static inline pepper_bool_t
-init_buffer_gbm(drm_buffer_t *buffer, pepper_drm_t *drm, struct gbm_bo *bo, uint32_t format)
+init_buffer_gbm(drm_buffer_t *buffer, pepper_drm_t *drm, struct gbm_bo *bo,
+ uint32_t format)
{
- int ret;
- uint32_t handles[4], strides[4], offsets[4];
-
- buffer->drm = drm;
- buffer->handle = gbm_bo_get_handle(bo).u32;
- buffer->w = gbm_bo_get_width(bo);
- buffer->h = gbm_bo_get_height(bo);
- buffer->stride = gbm_bo_get_stride(bo);
- buffer->size = buffer->h * buffer->stride;
-
- handles[0] = buffer->handle;
- strides[0] = buffer->stride;
- offsets[0] = 0;
-
- ret = drmModeAddFB2(drm->fd, buffer->w, buffer->h,
- format ? format : gbm_bo_get_format(bo),
- handles, strides, offsets, &buffer->id , 0);
-
- if (ret != 0)
- {
- ret = drmModeAddFB(drm->fd, buffer->w, buffer->h, 24, 32,
- buffer->stride, buffer->handle, &buffer->id);
- PEPPER_CHECK(ret, return PEPPER_FALSE, "drmModeAddFB() failed.\n");
- }
-
- buffer->bo = bo;
- gbm_bo_set_user_data(bo, buffer, NULL);
-
- return PEPPER_TRUE;
+ int ret;
+ uint32_t handles[4], strides[4], offsets[4];
+
+ buffer->drm = drm;
+ buffer->handle = gbm_bo_get_handle(bo).u32;
+ buffer->w = gbm_bo_get_width(bo);
+ buffer->h = gbm_bo_get_height(bo);
+ buffer->stride = gbm_bo_get_stride(bo);
+ buffer->size = buffer->h * buffer->stride;
+
+ handles[0] = buffer->handle;
+ strides[0] = buffer->stride;
+ offsets[0] = 0;
+
+ ret = drmModeAddFB2(drm->fd, buffer->w, buffer->h,
+ format ? format : gbm_bo_get_format(bo),
+ handles, strides, offsets, &buffer->id , 0);
+
+ if (ret != 0) {
+ ret = drmModeAddFB(drm->fd, buffer->w, buffer->h, 24, 32,
+ buffer->stride, buffer->handle, &buffer->id);
+ PEPPER_CHECK(ret, return PEPPER_FALSE, "drmModeAddFB() failed.\n");
+ }
+
+ buffer->bo = bo;
+ gbm_bo_set_user_data(bo, buffer, NULL);
+
+ return PEPPER_TRUE;
}
drm_buffer_t *
-drm_buffer_create_gbm(pepper_drm_t *drm, struct gbm_surface *surface, struct gbm_bo *bo)
+drm_buffer_create_gbm(pepper_drm_t *drm, struct gbm_surface *surface,
+ struct gbm_bo *bo)
{
- drm_buffer_t *buffer;
+ drm_buffer_t *buffer;
- buffer = calloc(1, sizeof(drm_buffer_t));
- PEPPER_CHECK(buffer, return NULL, "calloc() failed.\n");
+ buffer = calloc(1, sizeof(drm_buffer_t));
+ PEPPER_CHECK(buffer, return NULL, "calloc() failed.\n");
- if (!init_buffer_gbm(buffer, drm, bo, 0))
- {
- free(buffer);
- return NULL;
- }
+ if (!init_buffer_gbm(buffer, drm, bo, 0)) {
+ free(buffer);
+ return NULL;
+ }
- buffer->type = DRM_BUFFER_TYPE_GBM;
- buffer->surface = surface;
- buffer->bo = bo;
+ buffer->type = DRM_BUFFER_TYPE_GBM;
+ buffer->surface = surface;
+ buffer->bo = bo;
- return buffer;
+ return buffer;
}
static void
-handle_client_buffer_destroy(pepper_event_listener_t *listener, pepper_object_t *object,
- uint32_t id, void *info, void *data)
+handle_client_buffer_destroy(pepper_event_listener_t *listener,
+ pepper_object_t *object,
+ uint32_t id, void *info, void *data)
{
- drm_buffer_t *buffer = data;
- buffer->client_buffer = NULL;
+ drm_buffer_t *buffer = data;
+ buffer->client_buffer = NULL;
}
drm_buffer_t *
drm_buffer_create_client(pepper_drm_t *drm,
- struct gbm_bo *bo, pepper_buffer_t *client_buffer, uint32_t format)
+ struct gbm_bo *bo, pepper_buffer_t *client_buffer, uint32_t format)
{
- drm_buffer_t *buffer;
-
- buffer = calloc(1, sizeof(drm_buffer_t));
- PEPPER_CHECK(buffer, return NULL, "calloc() failed.\n");
-
- if (!init_buffer_gbm(buffer, drm, bo, format))
- {
- free(buffer);
- return NULL;
- }
-
- buffer->type = DRM_BUFFER_TYPE_CLIENT;
- buffer->client_buffer = client_buffer;
- pepper_buffer_reference(client_buffer);
- buffer->client_buffer_destroy_listener =
- pepper_object_add_event_listener((pepper_object_t *)client_buffer,
- PEPPER_EVENT_OBJECT_DESTROY, 0,
- handle_client_buffer_destroy, buffer);
-
- return buffer;
+ drm_buffer_t *buffer;
+
+ buffer = calloc(1, sizeof(drm_buffer_t));
+ PEPPER_CHECK(buffer, return NULL, "calloc() failed.\n");
+
+ if (!init_buffer_gbm(buffer, drm, bo, format)) {
+ free(buffer);
+ return NULL;
+ }
+
+ buffer->type = DRM_BUFFER_TYPE_CLIENT;
+ buffer->client_buffer = client_buffer;
+ pepper_buffer_reference(client_buffer);
+ buffer->client_buffer_destroy_listener =
+ pepper_object_add_event_listener((pepper_object_t *)client_buffer,
+ PEPPER_EVENT_OBJECT_DESTROY, 0,
+ handle_client_buffer_destroy, buffer);
+
+ return buffer;
}
void
drm_buffer_release(drm_buffer_t *buffer)
{
- if (buffer->type == DRM_BUFFER_TYPE_GBM)
- gbm_surface_release_buffer(buffer->surface, buffer->bo);
- else if (buffer->type == DRM_BUFFER_TYPE_CLIENT)
- drm_buffer_destroy(buffer);
+ if (buffer->type == DRM_BUFFER_TYPE_GBM)
+ gbm_surface_release_buffer(buffer->surface, buffer->bo);
+ else if (buffer->type == DRM_BUFFER_TYPE_CLIENT)
+ drm_buffer_destroy(buffer);
}
void
drm_buffer_destroy(drm_buffer_t *buffer)
{
- drmModeRmFB(buffer->drm->fd, buffer->id);
-
- if (buffer->type == DRM_BUFFER_TYPE_DUMB)
- {
- struct drm_mode_destroy_dumb destroy_arg;
-
- if (buffer->image)
- pixman_image_unref(buffer->image);
-
- munmap(buffer->map, buffer->size);
-
- memset(&destroy_arg, 0x00, sizeof(destroy_arg));
- destroy_arg.handle = buffer->handle;
- drmIoctl(buffer->drm->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
- }
- else if (buffer->type == DRM_BUFFER_TYPE_GBM)
- {
- gbm_bo_set_user_data(buffer->bo, NULL, NULL);
- gbm_surface_release_buffer(buffer->surface, buffer->bo);
- }
- else if (buffer->type == DRM_BUFFER_TYPE_CLIENT)
- {
- if (buffer->client_buffer)
- {
- pepper_buffer_unreference(buffer->client_buffer);
- pepper_event_listener_remove(buffer->client_buffer_destroy_listener);
- }
-
- gbm_bo_destroy(buffer->bo);
- }
-
- free(buffer);
+ drmModeRmFB(buffer->drm->fd, buffer->id);
+
+ if (buffer->type == DRM_BUFFER_TYPE_DUMB) {
+ struct drm_mode_destroy_dumb destroy_arg;
+
+ if (buffer->image)
+ pixman_image_unref(buffer->image);
+
+ munmap(buffer->map, buffer->size);
+
+ memset(&destroy_arg, 0x00, sizeof(destroy_arg));
+ destroy_arg.handle = buffer->handle;
+ drmIoctl(buffer->drm->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
+ } else if (buffer->type == DRM_BUFFER_TYPE_GBM) {
+ gbm_bo_set_user_data(buffer->bo, NULL, NULL);
+ gbm_surface_release_buffer(buffer->surface, buffer->bo);
+ } else if (buffer->type == DRM_BUFFER_TYPE_CLIENT) {
+ if (buffer->client_buffer) {
+ pepper_buffer_unreference(buffer->client_buffer);
+ pepper_event_listener_remove(buffer->client_buffer_destroy_listener);
+ }
+
+ gbm_bo_destroy(buffer->bo);
+ }
+
+ free(buffer);
}
* Copyright © 2012 Collabora, Ltd.
* Copyright © 2015 S-Core Corporation
* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
+*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
-*
+*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
-*
+*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
static struct udev_device *
find_primary_gpu(struct udev *udev) /* FIXME: copied from weston */
{
- struct udev_enumerate *e;
- struct udev_list_entry *entry;
- struct udev_device *pci, *device, *drm_device = NULL;
- const char *path, *device_seat, *id;
-
- e = udev_enumerate_new(udev);
- udev_enumerate_add_match_subsystem(e, "drm");
- udev_enumerate_add_match_sysname(e, "card[0-9]*");
- udev_enumerate_scan_devices(e);
-
- udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e))
- {
- path = udev_list_entry_get_name(entry);
- device = udev_device_new_from_syspath(udev, path);
- if (!device)
- continue;
- device_seat = udev_device_get_property_value(device, "ID_SEAT");
- if (!device_seat)
- device_seat = "seat0";
- if (strcmp(device_seat, "seat0" /* FIXME: default seat? */))
- {
- udev_device_unref(device);
- continue;
- }
-
- pci = udev_device_get_parent_with_subsystem_devtype(device, "pci", NULL);
- if (pci)
- {
- id = udev_device_get_sysattr_value(pci, "boot_vga");
- if (id && !strcmp(id, "1"))
- {
- if (drm_device)
- udev_device_unref(drm_device);
- drm_device = device;
- break;
- }
- }
-
- if (!drm_device)
- drm_device = device;
- else
- udev_device_unref(device);
- }
-
- udev_enumerate_unref(e);
- return drm_device;
+ struct udev_enumerate *e;
+ struct udev_list_entry *entry;
+ struct udev_device *pci, *device, *drm_device = NULL;
+ const char *path, *device_seat, *id;
+
+ e = udev_enumerate_new(udev);
+ udev_enumerate_add_match_subsystem(e, "drm");
+ udev_enumerate_add_match_sysname(e, "card[0-9]*");
+ udev_enumerate_scan_devices(e);
+
+ udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+ path = udev_list_entry_get_name(entry);
+ device = udev_device_new_from_syspath(udev, path);
+ if (!device)
+ continue;
+ device_seat = udev_device_get_property_value(device, "ID_SEAT");
+ if (!device_seat)
+ device_seat = "seat0";
+ if (strcmp(device_seat, "seat0" /* FIXME: default seat? */)) {
+ udev_device_unref(device);
+ continue;
+ }
+
+ pci = udev_device_get_parent_with_subsystem_devtype(device, "pci", NULL);
+ if (pci) {
+ id = udev_device_get_sysattr_value(pci, "boot_vga");
+ if (id && !strcmp(id, "1")) {
+ if (drm_device)
+ udev_device_unref(drm_device);
+ drm_device = device;
+ break;
+ }
+ }
+
+ if (!drm_device)
+ drm_device = device;
+ else
+ udev_device_unref(device);
+ }
+
+ udev_enumerate_unref(e);
+ return drm_device;
}
#ifdef HAVE_DRM_SPRD
static void
drm_sprd_init(int fd)
{
- drmVersionPtr drm_info;
- int drmIRQ = 78;
- int length = 0;
-
- if (sprd_dev)
- {
- return;
- }
-
- drm_info = drmGetVersion(fd);
- length = drm_info->name_len;
-
- if (length != 4)
- {
- drmFreeVersion(drm_info);
- return;
- }
- if (strncmp("sprd", drm_info->name, 4))
- {
- drmFreeVersion(drm_info);
- return;
- }
- drmFreeVersion(drm_info);
-
- PEPPER_CHECK(!drmCtlInstHandler(fd, drmIRQ), return, "drmCtlInstHandler() failed.\n");
-
- sprd_dev = sprd_device_create(fd);
- PEPPER_CHECK(sprd_dev, return, "sprd_device_create() failed.\n");
-
- return;
+ drmVersionPtr drm_info;
+ int drmIRQ = 78;
+ int length = 0;
+
+ if (sprd_dev) {
+ return;
+ }
+
+ drm_info = drmGetVersion(fd);
+ length = drm_info->name_len;
+
+ if (length != 4) {
+ drmFreeVersion(drm_info);
+ return;
+ }
+ if (strncmp("sprd", drm_info->name, 4)) {
+ drmFreeVersion(drm_info);
+ return;
+ }
+ drmFreeVersion(drm_info);
+
+ PEPPER_CHECK(!drmCtlInstHandler(fd, drmIRQ), return,
+ "drmCtlInstHandler() failed.\n");
+
+ sprd_dev = sprd_device_create(fd);
+ PEPPER_CHECK(sprd_dev, return, "sprd_device_create() failed.\n");
+
+ return;
}
static void
drm_sprd_deinit(void)
{
- if (sprd_dev == NULL)
- return;
+ if (sprd_dev == NULL)
+ return;
- sprd_device_destroy(sprd_dev);
- sprd_dev = NULL;
+ sprd_device_destroy(sprd_dev);
+ sprd_dev = NULL;
}
#endif
static int
handle_drm_event(int fd, uint32_t mask, void *data)
{
- pepper_drm_t *drm = data;
- drmHandleEvent(fd, &drm->drm_event_context);
- return 0;
+ pepper_drm_t *drm = data;
+ drmHandleEvent(fd, &drm->drm_event_context);
+ return 0;
}
static int
handle_udev_event(int fd, uint32_t mask, void *data)
{
- pepper_drm_t *drm = (pepper_drm_t *)data;
- struct udev_device *device;
+ pepper_drm_t *drm = (pepper_drm_t *)data;
+ struct udev_device *device;
- const char *sysnum;
- const char *value;
+ const char *sysnum;
+ const char *value;
- device = udev_monitor_receive_device(drm->udev_monitor);
+ device = udev_monitor_receive_device(drm->udev_monitor);
- sysnum = udev_device_get_sysnum(device);
- if (!sysnum || atoi(sysnum) != drm->sysnum)
- goto done;
+ sysnum = udev_device_get_sysnum(device);
+ if (!sysnum || atoi(sysnum) != drm->sysnum)
+ goto done;
- value = udev_device_get_property_value(device, "HOTPLUG");
- if (!value || strcmp(value, "1"))
- goto done;
+ value = udev_device_get_property_value(device, "HOTPLUG");
+ if (!value || strcmp(value, "1"))
+ goto done;
- drm_update_connectors(drm);
+ drm_update_connectors(drm);
done:
- udev_device_unref(device);
- return 0;
+ udev_device_unref(device);
+ return 0;
}
PEPPER_API pepper_drm_t *
-pepper_drm_create(pepper_compositor_t *compositor, struct udev *udev, const char *device)
+pepper_drm_create(pepper_compositor_t *compositor, struct udev *udev,
+ const char *device)
{
- pepper_drm_t *drm = NULL;
- struct udev_device *udev_device = NULL;
- const char *sysnum_str = NULL;
- const char *filepath;
- struct stat s;
- int ret;
- struct wl_event_loop *loop;
- drm_magic_t magic;
- uint64_t cap;
- clockid_t clock_id;
-
- drm = calloc(1, sizeof(pepper_drm_t));
- PEPPER_CHECK(drm, goto error, "calloc() failed.\n");
-
- drm->compositor = compositor;
- drm->fd = -1;
- pepper_list_init(&drm->plane_list);
- pepper_list_init(&drm->connector_list);
-
- /* Find primary GPU udev device. Usually card0. */
- udev_device = find_primary_gpu(udev);
- PEPPER_CHECK(udev_device, goto error, "find_primary_gpu() failed.\n");
-
- /* Get sysnum for the device. */
- sysnum_str = udev_device_get_sysnum(udev_device);
- PEPPER_CHECK(sysnum_str, goto error, "udev_device_get_sysnum() failed.\n");
-
- drm->sysnum = atoi(sysnum_str);
- PEPPER_CHECK(drm->sysnum >= 0, goto error, "Invalid sysnum.\n");
-
- /* Get device file path. */
- filepath = udev_device_get_devnode(udev_device);
- PEPPER_CHECK(filepath, goto error, "udev_device_get_devnode() failed.\n");
-
- /* Open DRM device file and check validity. */
- drm->fd = open(filepath, O_RDWR | O_CLOEXEC);
- PEPPER_CHECK(drm->fd != -1, goto error, "open(%s, O_RDWR | O_CLOEXEC) failed.\n", filepath);
+ pepper_drm_t *drm = NULL;
+ struct udev_device *udev_device = NULL;
+ const char *sysnum_str = NULL;
+ const char *filepath;
+ struct stat s;
+ int ret;
+ struct wl_event_loop *loop;
+ drm_magic_t magic;
+ uint64_t cap;
+ clockid_t clock_id;
+
+ drm = calloc(1, sizeof(pepper_drm_t));
+ PEPPER_CHECK(drm, goto error, "calloc() failed.\n");
+
+ drm->compositor = compositor;
+ drm->fd = -1;
+ pepper_list_init(&drm->plane_list);
+ pepper_list_init(&drm->connector_list);
+
+ /* Find primary GPU udev device. Usually card0. */
+ udev_device = find_primary_gpu(udev);
+ PEPPER_CHECK(udev_device, goto error, "find_primary_gpu() failed.\n");
+
+ /* Get sysnum for the device. */
+ sysnum_str = udev_device_get_sysnum(udev_device);
+ PEPPER_CHECK(sysnum_str, goto error, "udev_device_get_sysnum() failed.\n");
+
+ drm->sysnum = atoi(sysnum_str);
+ PEPPER_CHECK(drm->sysnum >= 0, goto error, "Invalid sysnum.\n");
+
+ /* Get device file path. */
+ filepath = udev_device_get_devnode(udev_device);
+ PEPPER_CHECK(filepath, goto error, "udev_device_get_devnode() failed.\n");
+
+ /* Open DRM device file and check validity. */
+ drm->fd = open(filepath, O_RDWR | O_CLOEXEC);
+ PEPPER_CHECK(drm->fd != -1, goto error,
+ "open(%s, O_RDWR | O_CLOEXEC) failed.\n", filepath);
#ifdef HAVE_DRM_SPRD
- /*If drm is sprd, this fuction MUST call before other drm function*/
- drm_sprd_init(drm->fd);
+ /*If drm is sprd, this fuction MUST call before other drm function*/
+ drm_sprd_init(drm->fd);
#endif
- ret = fstat(drm->fd, &s);
- PEPPER_CHECK(ret != -1, goto error, "fstat() failed %s.\n", filepath);
+ ret = fstat(drm->fd, &s);
+ PEPPER_CHECK(ret != -1, goto error, "fstat() failed %s.\n", filepath);
- ret = major(s.st_rdev);
- PEPPER_CHECK(ret == 226, goto error, "Not a drm device file %s.\n", filepath);
+ ret = major(s.st_rdev);
+ PEPPER_CHECK(ret == 226, goto error, "Not a drm device file %s.\n", filepath);
- ret = drmGetMagic(drm->fd, &magic);
- PEPPER_CHECK(ret == 0, goto error, "drmGetMagic() failed.\n");
+ ret = drmGetMagic(drm->fd, &magic);
+ PEPPER_CHECK(ret == 0, goto error, "drmGetMagic() failed.\n");
- ret = drmAuthMagic(drm->fd, magic);
- PEPPER_CHECK(ret == 0, goto error, "drmAuthMagic() failed.\n");
+ ret = drmAuthMagic(drm->fd, magic);
+ PEPPER_CHECK(ret == 0, goto error, "drmAuthMagic() failed.\n");
- /* Create udev event monitor. */
- drm->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
- PEPPER_CHECK(drm->udev_monitor, goto error, "udev_monitor_new_from_netlink() failed.\n");
- udev_monitor_filter_add_match_subsystem_devtype(drm->udev_monitor, "drm", NULL);
+ /* Create udev event monitor. */
+ drm->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
+ PEPPER_CHECK(drm->udev_monitor, goto error,
+ "udev_monitor_new_from_netlink() failed.\n");
+ udev_monitor_filter_add_match_subsystem_devtype(drm->udev_monitor, "drm", NULL);
#ifdef HAVE_TBM
- /* Create wayland-tbm*/
- drm->wl_tbm_server = wayland_tbm_server_init(pepper_compositor_get_display(compositor),
- filepath, drm->fd, 0);
+ /* Create wayland-tbm*/
+ drm->wl_tbm_server = wayland_tbm_server_init(pepper_compositor_get_display(
+ compositor),
+ filepath, drm->fd, 0);
#endif
- /* Add DRM event FDs to the compositor's display. */
- loop = wl_display_get_event_loop(pepper_compositor_get_display(compositor));
+ /* Add DRM event FDs to the compositor's display. */
+ loop = wl_display_get_event_loop(pepper_compositor_get_display(compositor));
- drm->drm_event_source = wl_event_loop_add_fd(loop, drm->fd, WL_EVENT_READABLE,
- handle_drm_event, drm);
- PEPPER_CHECK(drm->drm_event_source, goto error, "wl_event_loop_add() failed.\n");
+ drm->drm_event_source = wl_event_loop_add_fd(loop, drm->fd, WL_EVENT_READABLE,
+ handle_drm_event, drm);
+ PEPPER_CHECK(drm->drm_event_source, goto error,
+ "wl_event_loop_add() failed.\n");
- drm->udev_event_source = wl_event_loop_add_fd(loop, udev_monitor_get_fd(drm->udev_monitor),
- WL_EVENT_READABLE, handle_udev_event, drm);
- PEPPER_CHECK(drm->udev_event_source, goto error, "wl_event_loop_add() failed.\n");
+ drm->udev_event_source = wl_event_loop_add_fd(loop,
+ udev_monitor_get_fd(drm->udev_monitor),
+ WL_EVENT_READABLE, handle_udev_event, drm);
+ PEPPER_CHECK(drm->udev_event_source, goto error,
+ "wl_event_loop_add() failed.\n");
- drm->drm_event_context.version = DRM_EVENT_CONTEXT_VERSION;
- drm->drm_event_context.vblank_handler = drm_handle_vblank;
- drm->drm_event_context.page_flip_handler = drm_handle_page_flip;
+ drm->drm_event_context.version = DRM_EVENT_CONTEXT_VERSION;
+ drm->drm_event_context.vblank_handler = drm_handle_vblank;
+ drm->drm_event_context.page_flip_handler = drm_handle_page_flip;
- ret = udev_monitor_enable_receiving(drm->udev_monitor);
- PEPPER_CHECK(ret >= 0, goto error, "udev_monitor_enable_receiving() failed.\n");
+ ret = udev_monitor_enable_receiving(drm->udev_monitor);
+ PEPPER_CHECK(ret >= 0, goto error, "udev_monitor_enable_receiving() failed.\n");
- drm->resources = drmModeGetResources(drm->fd);
- PEPPER_CHECK(drm->resources, goto error, "drmModeGetResources() failed.\n");
+ drm->resources = drmModeGetResources(drm->fd);
+ PEPPER_CHECK(drm->resources, goto error, "drmModeGetResources() failed.\n");
- ret = drmGetCap(drm->fd, 0x8 /* DRM_CAP_CURSOR_WIDTH */, &cap);
- drm->cursor_width = (ret == 0) ? cap : 64;
+ ret = drmGetCap(drm->fd, 0x8 /* DRM_CAP_CURSOR_WIDTH */, &cap);
+ drm->cursor_width = (ret == 0) ? cap : 64;
- ret = drmGetCap(drm->fd, 0x9 /* DRM_CAP_CURSOR_HEIGHT */, &cap);
- drm->cursor_height = (ret == 0) ? cap : 64;
+ ret = drmGetCap(drm->fd, 0x9 /* DRM_CAP_CURSOR_HEIGHT */, &cap);
+ drm->cursor_height = (ret == 0) ? cap : 64;
- drm_init_planes(drm);
- drm_init_connectors(drm);
- udev_device_unref(udev_device);
+ drm_init_planes(drm);
+ drm_init_connectors(drm);
+ udev_device_unref(udev_device);
- /* Try to set clock. */
- ret = drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
+ /* Try to set clock. */
+ ret = drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
- if (ret == 0 && cap == 1)
- clock_id = CLOCK_MONOTONIC;
- else
- clock_id = CLOCK_REALTIME;
+ if (ret == 0 && cap == 1)
+ clock_id = CLOCK_MONOTONIC;
+ else
+ clock_id = CLOCK_REALTIME;
- if (!pepper_compositor_set_clock_id(compositor, clock_id))
- goto error;
+ if (!pepper_compositor_set_clock_id(compositor, clock_id))
+ goto error;
- return drm;
+ return drm;
error:
- if (drm)
- pepper_drm_destroy(drm);
+ if (drm)
+ pepper_drm_destroy(drm);
- if (udev_device)
- udev_device_unref(udev_device);
+ if (udev_device)
+ udev_device_unref(udev_device);
- return NULL;
+ return NULL;
}
PEPPER_API void
pepper_drm_destroy(pepper_drm_t *drm)
{
- drm_connector_t *conn, *next_conn;
- drm_plane_t *plane, *next_plane;
+ drm_connector_t *conn, *next_conn;
+ drm_plane_t *plane, *next_plane;
- pepper_list_for_each_safe(conn, next_conn, &drm->connector_list, link)
- drm_connector_destroy(conn);
+ pepper_list_for_each_safe(conn, next_conn, &drm->connector_list, link)
+ drm_connector_destroy(conn);
- pepper_list_for_each_safe(plane, next_plane, &drm->plane_list, link)
- drm_plane_destroy(plane);
+ pepper_list_for_each_safe(plane, next_plane, &drm->plane_list, link)
+ drm_plane_destroy(plane);
- if (drm->pixman_renderer)
- pepper_renderer_destroy(drm->pixman_renderer);
+ if (drm->pixman_renderer)
+ pepper_renderer_destroy(drm->pixman_renderer);
- if (drm->gl_renderer)
- pepper_renderer_destroy(drm->gl_renderer);
+ if (drm->gl_renderer)
+ pepper_renderer_destroy(drm->gl_renderer);
#ifdef HAVE_TBM
- if (drm->wl_tbm_server)
- wayland_tbm_server_deinit(drm->wl_tbm_server);
+ if (drm->wl_tbm_server)
+ wayland_tbm_server_deinit(drm->wl_tbm_server);
#endif
- if (drm->gbm_device)
- gbm_device_destroy(drm->gbm_device);
+ if (drm->gbm_device)
+ gbm_device_destroy(drm->gbm_device);
- if (drm->resources)
- drmModeFreeResources(drm->resources);
+ if (drm->resources)
+ drmModeFreeResources(drm->resources);
- if (drm->udev_event_source)
- wl_event_source_remove(drm->udev_event_source);
+ if (drm->udev_event_source)
+ wl_event_source_remove(drm->udev_event_source);
- if (drm->drm_event_source)
- wl_event_source_remove(drm->drm_event_source);
+ if (drm->drm_event_source)
+ wl_event_source_remove(drm->drm_event_source);
- if (drm->udev_monitor)
- udev_monitor_unref(drm->udev_monitor);
+ if (drm->udev_monitor)
+ udev_monitor_unref(drm->udev_monitor);
#ifdef HAVE_DRM_SPRD
- drm_sprd_deinit();
+ drm_sprd_deinit();
#endif
- if (drm->fd != -1)
- close(drm->fd);
+ if (drm->fd != -1)
+ close(drm->fd);
- free(drm);
+ free(drm);
}
* Copyright © 2012 Collabora, Ltd.
* Copyright © 2015 S-Core Corporation
* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
+*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
-*
+*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
-*
+*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#include "drm-internal.h"
#include <stdio.h>
-static const char *connector_type_names[] =
-{
- "None",
- "VGA",
- "DVI",
- "DVI",
- "DVI",
- "Composite",
- "TV",
- "LVDS",
- "CTV",
- "DIN",
- "DP",
- "HDMI",
- "HDMI",
- "TV",
- "eDP",
+static const char *connector_type_names[] = {
+ "None",
+ "VGA",
+ "DVI",
+ "DVI",
+ "DVI",
+ "Composite",
+ "TV",
+ "LVDS",
+ "CTV",
+ "DIN",
+ "DP",
+ "HDMI",
+ "HDMI",
+ "TV",
+ "eDP",
};
static inline void
get_connector_name(char *str, drmModeConnector *conn)
{
- const char *type_name;
+ const char *type_name;
- if (conn->connector_type < PEPPER_ARRAY_LENGTH(connector_type_names))
- type_name = connector_type_names[conn->connector_type];
- else
- type_name = "UNKNOWN";
+ if (conn->connector_type < PEPPER_ARRAY_LENGTH(connector_type_names))
+ type_name = connector_type_names[conn->connector_type];
+ else
+ type_name = "UNKNOWN";
- snprintf(str, 32, "%s%d", type_name, conn->connector_type_id);
+ snprintf(str, 32, "%s%d", type_name, conn->connector_type_id);
}
static inline void
add_connector(pepper_drm_t *drm, drmModeConnector *connector)
{
- drm_connector_t *conn;
+ drm_connector_t *conn;
- conn = calloc(1, sizeof(drm_connector_t));
- PEPPER_CHECK(conn, return, "calloc() failed.\n");
+ conn = calloc(1, sizeof(drm_connector_t));
+ PEPPER_CHECK(conn, return, "calloc() failed.\n");
- conn->connector = connector;
+ conn->connector = connector;
}
void
drm_init_connectors(pepper_drm_t *drm)
{
- int i;
-
- for (i = 0; i < drm->resources->count_connectors; i++)
- {
- drm_connector_t *conn = calloc(1, sizeof(drm_connector_t));
- PEPPER_CHECK(conn, continue, "calloc() failed.\n");
-
- conn->drm = drm;
- conn->id = drm->resources->connectors[i];
- conn->connector = drmModeGetConnector(drm->fd, conn->id);
- if (!conn->connector)
- {
- PEPPER_ERROR("drmModeGetConnector() failed.\n");
- free(conn);
- continue;
- }
-
- get_connector_name(&conn->name[0], conn->connector);
- conn->connected = conn->connector->connection == DRM_MODE_CONNECTED;
- pepper_list_insert(drm->connector_list.prev, &conn->link);
-
- if (conn->connected)
- drm_output_create(conn);
- }
+ int i;
+
+ for (i = 0; i < drm->resources->count_connectors; i++) {
+ drm_connector_t *conn = calloc(1, sizeof(drm_connector_t));
+ PEPPER_CHECK(conn, continue, "calloc() failed.\n");
+
+ conn->drm = drm;
+ conn->id = drm->resources->connectors[i];
+ conn->connector = drmModeGetConnector(drm->fd, conn->id);
+ if (!conn->connector) {
+ PEPPER_ERROR("drmModeGetConnector() failed.\n");
+ free(conn);
+ continue;
+ }
+
+ get_connector_name(&conn->name[0], conn->connector);
+ conn->connected = conn->connector->connection == DRM_MODE_CONNECTED;
+ pepper_list_insert(drm->connector_list.prev, &conn->link);
+
+ if (conn->connected)
+ drm_output_create(conn);
+ }
}
void
drm_update_connectors(pepper_drm_t *drm)
{
- drm_connector_t *conn;
-
- pepper_list_for_each(conn, &drm->connector_list, link)
- {
- if (conn->connector)
- drmModeFreeConnector(conn->connector);
-
- /* XXX: Do I have to get connector again here??? */
- conn->connector = drmModeGetConnector(drm->fd, conn->id);
- PEPPER_CHECK(conn->connector, continue, "drmModeGetConnector() failed.\n");
-
- if (conn->connected && conn->connector->connection != DRM_MODE_CONNECTED)
- {
- /* Disconnected. */
- if (conn->output)
- {
- pepper_output_destroy(conn->output->base);
- conn->output = NULL;
- conn->connected = PEPPER_FALSE;
- }
- }
- else if (!conn->connected && conn->connector->connection == DRM_MODE_CONNECTED)
- {
- /* Newly connected. */
- PEPPER_ASSERT(conn->output == NULL);
- drm_output_create(conn);
- }
- }
+ drm_connector_t *conn;
+
+ pepper_list_for_each(conn, &drm->connector_list, link) {
+ if (conn->connector)
+ drmModeFreeConnector(conn->connector);
+
+ /* XXX: Do I have to get connector again here??? */
+ conn->connector = drmModeGetConnector(drm->fd, conn->id);
+ PEPPER_CHECK(conn->connector, continue, "drmModeGetConnector() failed.\n");
+
+ if (conn->connected && conn->connector->connection != DRM_MODE_CONNECTED) {
+ /* Disconnected. */
+ if (conn->output) {
+ pepper_output_destroy(conn->output->base);
+ conn->output = NULL;
+ conn->connected = PEPPER_FALSE;
+ }
+ } else if (!conn->connected &&
+ conn->connector->connection == DRM_MODE_CONNECTED) {
+ /* Newly connected. */
+ PEPPER_ASSERT(conn->output == NULL);
+ drm_output_create(conn);
+ }
+ }
}
void
drm_connector_destroy(drm_connector_t *conn)
{
- if (conn->output)
- pepper_output_destroy(conn->output->base);
+ if (conn->output)
+ pepper_output_destroy(conn->output->base);
- if (conn->connector)
- drmModeFreeConnector(conn->connector);
+ if (conn->connector)
+ drmModeFreeConnector(conn->connector);
- pepper_list_remove(&conn->link);
- free(conn);
+ pepper_list_remove(&conn->link);
+ free(conn);
}
* Copyright © 2012 Collabora, Ltd.
* Copyright © 2015 S-Core Corporation
* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
+*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
-*
+*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
-*
+*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
typedef struct drm_plane drm_plane_t;
typedef struct drm_connector drm_connector_t;
-typedef enum drm_buffer_type
-{
- DRM_BUFFER_TYPE_DUMB,
- DRM_BUFFER_TYPE_GBM,
- DRM_BUFFER_TYPE_CLIENT,
+typedef enum drm_buffer_type {
+ DRM_BUFFER_TYPE_DUMB,
+ DRM_BUFFER_TYPE_GBM,
+ DRM_BUFFER_TYPE_CLIENT,
} drm_buffer_type_t;
-typedef enum drm_render_type
-{
- DRM_RENDER_TYPE_PIXMAN,
- DRM_RENDER_TYPE_GL,
+typedef enum drm_render_type {
+ DRM_RENDER_TYPE_PIXMAN,
+ DRM_RENDER_TYPE_GL,
} drm_render_type_t;
-struct pepper_drm
-{
- pepper_compositor_t *compositor;
+struct pepper_drm {
+ pepper_compositor_t *compositor;
- int fd;
- int sysnum;
- struct udev_monitor *udev_monitor;
+ int fd;
+ int sysnum;
+ struct udev_monitor *udev_monitor;
- drmEventContext drm_event_context;
- struct wl_event_source *drm_event_source;
- struct wl_event_source *udev_event_source;
+ drmEventContext drm_event_context;
+ struct wl_event_source *drm_event_source;
+ struct wl_event_source *udev_event_source;
- pepper_list_t connector_list;
- uint32_t used_crtcs;
- pepper_list_t plane_list;
+ pepper_list_t connector_list;
+ uint32_t used_crtcs;
+ pepper_list_t plane_list;
- drmModeRes *resources;
- struct gbm_device *gbm_device;
+ drmModeRes *resources;
+ struct gbm_device *gbm_device;
#ifdef HAVE_TBM
- struct wayland_tbm_server *wl_tbm_server;
+ struct wayland_tbm_server *wl_tbm_server;
#endif
- pepper_renderer_t *pixman_renderer;
- pepper_renderer_t *gl_renderer;
+ pepper_renderer_t *pixman_renderer;
+ pepper_renderer_t *gl_renderer;
- pepper_bool_t cursor_broken;
- int32_t cursor_width;
- int32_t cursor_height;
+ pepper_bool_t cursor_broken;
+ int32_t cursor_width;
+ int32_t cursor_height;
};
-struct drm_connector
-{
- pepper_drm_t *drm;
- char name[32];
- uint32_t id;
- pepper_bool_t connected;
- drm_output_t *output;
- drmModeConnector *connector;
+struct drm_connector {
+ pepper_drm_t *drm;
+ char name[32];
+ uint32_t id;
+ pepper_bool_t connected;
+ drm_output_t *output;
+ drmModeConnector *connector;
- pepper_list_t link;
+ pepper_list_t link;
};
void
void
drm_connector_destroy(drm_connector_t *conn);
-struct drm_buffer
-{
- pepper_drm_t *drm;
- drm_buffer_type_t type;
- uint32_t id;
- uint32_t handle;
+struct drm_buffer {
+ pepper_drm_t *drm;
+ drm_buffer_type_t type;
+ uint32_t id;
+ uint32_t handle;
- uint32_t w, h;
- uint32_t stride;
- uint32_t size;
+ uint32_t w, h;
+ uint32_t stride;
+ uint32_t size;
- pepper_buffer_t *client_buffer;
- pepper_event_listener_t *client_buffer_destroy_listener;
- struct gbm_surface *surface;
- struct gbm_bo *bo;
- void *map;
+ pepper_buffer_t *client_buffer;
+ pepper_event_listener_t *client_buffer_destroy_listener;
+ struct gbm_surface *surface;
+ struct gbm_bo *bo;
+ void *map;
- pixman_image_t *image;
+ pixman_image_t *image;
};
drm_buffer_t *
drm_buffer_create_dumb(pepper_drm_t *drm, uint32_t w, uint32_t h);
drm_buffer_t *
-drm_buffer_create_gbm(pepper_drm_t *drm, struct gbm_surface *surface, struct gbm_bo *bo);
+drm_buffer_create_gbm(pepper_drm_t *drm, struct gbm_surface *surface,
+ struct gbm_bo *bo);
drm_buffer_t *
drm_buffer_create_client(pepper_drm_t *drm,
- struct gbm_bo *bo, pepper_buffer_t *buffer, uint32_t format);
+ struct gbm_bo *bo, pepper_buffer_t *buffer, uint32_t format);
void
drm_buffer_release(drm_buffer_t *buffer);
void
drm_buffer_destroy(drm_buffer_t *buffer);
-struct drm_output
-{
- pepper_drm_t *drm;
- pepper_output_t *base;
-
- drm_connector_t *conn;
- int32_t crtc_index;
- uint32_t crtc_id;
- drmModeCrtc *saved_crtc;
- int32_t subpixel;
- drmModeModeInfo *mode;
-
- pepper_bool_t destroy_pending;
- pepper_bool_t page_flip_pending;
- int vblank_pending_count;
-
- pepper_view_t *cursor_view;
- pepper_buffer_t *cursor_buffer;
- struct gbm_bo *cursor_bo[2];
- int cursor_bo_index;
- int cursor_x, cursor_y;
- pepper_bool_t need_set_cursor;
-
- pepper_plane_t *cursor_plane;
- pepper_plane_t *primary_plane;
- pepper_plane_t *fb_plane;
- pepper_bool_t use_overlay;
-
- drm_render_type_t render_type;
- pepper_renderer_t *renderer;
- pepper_render_target_t *render_target;
-
- /* pixman */
- pepper_bool_t use_shadow;
- pixman_image_t *shadow_image;
- drm_buffer_t *fb[2];
- pepper_render_target_t *fb_target[2];
- int back_fb_index;
- pixman_region32_t previous_damage;
-
- /* OpenGL */
- struct gbm_surface *gbm_surface;
- pepper_bool_t disable_no_comp;
-
- drm_buffer_t *front, *back;
+struct drm_output {
+ pepper_drm_t *drm;
+ pepper_output_t *base;
+
+ drm_connector_t *conn;
+ int32_t crtc_index;
+ uint32_t crtc_id;
+ drmModeCrtc *saved_crtc;
+ int32_t subpixel;
+ drmModeModeInfo *mode;
+
+ pepper_bool_t destroy_pending;
+ pepper_bool_t page_flip_pending;
+ int vblank_pending_count;
+
+ pepper_view_t *cursor_view;
+ pepper_buffer_t *cursor_buffer;
+ struct gbm_bo *cursor_bo[2];
+ int cursor_bo_index;
+ int cursor_x, cursor_y;
+ pepper_bool_t need_set_cursor;
+
+ pepper_plane_t *cursor_plane;
+ pepper_plane_t *primary_plane;
+ pepper_plane_t *fb_plane;
+ pepper_bool_t use_overlay;
+
+ drm_render_type_t render_type;
+ pepper_renderer_t *renderer;
+ pepper_render_target_t *render_target;
+
+ /* pixman */
+ pepper_bool_t use_shadow;
+ pixman_image_t *shadow_image;
+ drm_buffer_t *fb[2];
+ pepper_render_target_t *fb_target[2];
+ int back_fb_index;
+ pixman_region32_t previous_damage;
+
+ /* OpenGL */
+ struct gbm_surface *gbm_surface;
+ pepper_bool_t disable_no_comp;
+
+ drm_buffer_t *front, *back;
};
drm_output_t *
drm_output_destroy(void *o);
void
-drm_handle_vblank(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data);
+drm_handle_vblank(int fd, unsigned int frame, unsigned int sec,
+ unsigned int usec, void *data);
void
-drm_handle_page_flip(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data);
+drm_handle_page_flip(int fd, unsigned int frame, unsigned int sec,
+ unsigned int usec, void *data);
-struct drm_plane
-{
- pepper_drm_t *drm;
- uint32_t id;
- drmModePlane *plane;
+struct drm_plane {
+ pepper_drm_t *drm;
+ uint32_t id;
+ drmModePlane *plane;
- drm_output_t *output;
- pepper_plane_t *base;
+ drm_output_t *output;
+ pepper_plane_t *base;
- drm_buffer_t *front, *back;
- int dx, dy, dw, dh;
- int sx, sy, sw, sh;
+ drm_buffer_t *front, *back;
+ int dx, dy, dw, dh;
+ int sx, sy, sw, sh;
- pepper_list_t link;
+ pepper_list_t link;
};
void
* Copyright © 2012 Collabora, Ltd.
* Copyright © 2015 S-Core Corporation
* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
+*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
-*
+*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
-*
+*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
static int32_t
drm_output_get_subpixel_order(void *data)
{
- drm_output_t *output = (drm_output_t *)data;
-
- switch (output->subpixel)
- {
- case DRM_MODE_SUBPIXEL_UNKNOWN:
- return WL_OUTPUT_SUBPIXEL_UNKNOWN;
- case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
- return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
- case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
- return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
- case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
- return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
- case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
- return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
- case DRM_MODE_SUBPIXEL_NONE:
- return WL_OUTPUT_SUBPIXEL_NONE;
- default:
- return WL_OUTPUT_SUBPIXEL_UNKNOWN;
- }
-
- return WL_OUTPUT_SUBPIXEL_UNKNOWN;
+ drm_output_t *output = (drm_output_t *)data;
+
+ switch (output->subpixel) {
+ case DRM_MODE_SUBPIXEL_UNKNOWN:
+ return WL_OUTPUT_SUBPIXEL_UNKNOWN;
+ case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
+ return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
+ case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
+ return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
+ case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
+ return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
+ case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
+ return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
+ case DRM_MODE_SUBPIXEL_NONE:
+ return WL_OUTPUT_SUBPIXEL_NONE;
+ default:
+ return WL_OUTPUT_SUBPIXEL_UNKNOWN;
+ }
+
+ return WL_OUTPUT_SUBPIXEL_UNKNOWN;
}
static const char *
drm_output_get_maker_name(void *output)
{
- return "PePPer DRM";
+ return "PePPer DRM";
}
static const char *
drm_output_get_model_name(void *output)
{
- return "PePPer DRM";
+ return "PePPer DRM";
}
static int
drm_output_get_mode_count(void *o)
{
- drm_output_t *output = (drm_output_t *)o;
- return output->conn->connector->count_modes;
+ drm_output_t *output = (drm_output_t *)o;
+ return output->conn->connector->count_modes;
}
static uint32_t
get_refresh_rate(const drmModeModeInfo *info)
{
- return (info->clock * 1000000LL / info->vtotal + info->vtotal / 2) / info->vtotal;
+ return (info->clock * 1000000LL / info->vtotal + info->vtotal / 2) /
+ info->vtotal;
}
static pepper_bool_t
same_mode(const drmModeModeInfo *info, const pepper_output_mode_t *mode)
{
- return info->hdisplay == mode->w && info->vdisplay == mode->h &&
- get_refresh_rate(info) == (uint32_t)mode->refresh;
+ return info->hdisplay == mode->w && info->vdisplay == mode->h &&
+ get_refresh_rate(info) == (uint32_t)mode->refresh;
}
static void
drm_output_get_mode(void *o, int index, pepper_output_mode_t *mode)
{
- drm_output_t *output = (drm_output_t *)o;
- drmModeModeInfo *info = &output->conn->connector->modes[index];
+ drm_output_t *output = (drm_output_t *)o;
+ drmModeModeInfo *info = &output->conn->connector->modes[index];
- mode->flags = 0;
- mode->w = info->hdisplay;
- mode->h = info->vdisplay;
- mode->refresh = get_refresh_rate(info);
+ mode->flags = 0;
+ mode->w = info->hdisplay;
+ mode->h = info->vdisplay;
+ mode->refresh = get_refresh_rate(info);
- if (info->type & DRM_MODE_TYPE_PREFERRED)
- mode->flags |= WL_OUTPUT_MODE_PREFERRED;
+ if (info->type & DRM_MODE_TYPE_PREFERRED)
+ mode->flags |= WL_OUTPUT_MODE_PREFERRED;
- if (info == output->mode)
- mode->flags |= WL_OUTPUT_MODE_CURRENT;
+ if (info == output->mode)
+ mode->flags |= WL_OUTPUT_MODE_CURRENT;
}
static pepper_bool_t
drm_output_set_mode(void *o, const pepper_output_mode_t *mode)
{
- int i;
- drm_output_t *output = (drm_output_t *)o;
+ int i;
+ drm_output_t *output = (drm_output_t *)o;
- if (same_mode(output->mode, mode))
- return PEPPER_TRUE;
+ if (same_mode(output->mode, mode))
+ return PEPPER_TRUE;
- for (i = 0; i < output->conn->connector->count_modes; i++)
- {
- drmModeModeInfo *info = &output->conn->connector->modes[i];
+ for (i = 0; i < output->conn->connector->count_modes; i++) {
+ drmModeModeInfo *info = &output->conn->connector->modes[i];
- if (same_mode(info, mode))
- {
- output->mode = info;
- pepper_output_update_mode(output->base);
- return PEPPER_TRUE;
- }
- }
+ if (same_mode(info, mode)) {
+ output->mode = info;
+ pepper_output_update_mode(output->base);
+ return PEPPER_TRUE;
+ }
+ }
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
static pepper_plane_t *
assign_cursor_plane(drm_output_t *output, pepper_view_t *view)
{
- int32_t w, h;
- pepper_surface_t *surface;
- pepper_buffer_t *buffer;
- struct wl_resource *resource;
+ int32_t w, h;
+ pepper_surface_t *surface;
+ pepper_buffer_t *buffer;
+ struct wl_resource *resource;
- if (output->cursor_view)
- return NULL;
+ if (output->cursor_view)
+ return NULL;
- if (!output->drm->gbm_device)
- return NULL;
+ if (!output->drm->gbm_device)
+ return NULL;
- if (output->drm->cursor_broken)
- return NULL;
+ if (output->drm->cursor_broken)
+ return NULL;
- pepper_view_get_size(view, &w, &h);
- if ((output->drm->cursor_width < w) || (output->drm->cursor_height < h))
- return NULL;
+ pepper_view_get_size(view, &w, &h);
+ if ((output->drm->cursor_width < w) || (output->drm->cursor_height < h))
+ return NULL;
- surface = pepper_view_get_surface(view);
- buffer = pepper_surface_get_buffer(surface);
- if (!buffer)
- return NULL;
+ surface = pepper_view_get_surface(view);
+ buffer = pepper_surface_get_buffer(surface);
+ if (!buffer)
+ return NULL;
- resource = pepper_buffer_get_resource(buffer);
- if (!resource || !wl_shm_buffer_get(resource))
- return NULL;
+ resource = pepper_buffer_get_resource(buffer);
+ if (!resource || !wl_shm_buffer_get(resource))
+ return NULL;
- output->cursor_view = view;
- if (output->cursor_buffer != buffer)
- {
- output->cursor_buffer = buffer;
- output->need_set_cursor = PEPPER_TRUE;
- }
+ output->cursor_view = view;
+ if (output->cursor_buffer != buffer) {
+ output->cursor_buffer = buffer;
+ output->need_set_cursor = PEPPER_TRUE;
+ }
- return output->cursor_plane;
+ return output->cursor_plane;
}
static pepper_plane_t *
assign_fb_plane(drm_output_t *output, pepper_view_t *view)
{
- double x, y;
- int32_t w, h;
- pepper_surface_t *surface;
- pepper_buffer_t *buffer;
- struct wl_resource *resource;
- struct gbm_bo *bo;
-
- const pepper_output_geometry_t *geometry;
-
- if (output->disable_no_comp)
- return NULL;
-
- if (output->back)
- return NULL;
-
- if (!output->drm->gbm_device)
- return NULL;
-
- geometry = pepper_output_get_geometry(output->base);
- pepper_view_get_position(view, &x, &y);
- if ((geometry->x != (int)x) || (geometry->y != (int)y))
- return NULL;
-
- pepper_view_get_size(view, &w, &h);
- if ((geometry->w != w) || (geometry->h != h))
- return NULL;
-
- surface = pepper_view_get_surface(view);
- if (!surface)
- return NULL;
-
- if (geometry->transform != pepper_surface_get_buffer_transform(surface))
- return NULL;
-
- if (pepper_output_get_scale(output->base) != pepper_surface_get_buffer_scale(surface))
- return NULL;
-
- buffer = pepper_surface_get_buffer(surface);
- if (!buffer)
- return NULL;
-
- resource = pepper_buffer_get_resource(buffer);
- if (!resource)
- return NULL;
-
- bo = gbm_bo_import(output->drm->gbm_device,
- GBM_BO_IMPORT_WL_BUFFER, resource, GBM_BO_USE_SCANOUT);
- if (!bo)
- return NULL;
-
- /* TODO: Other alpha formats like ARGB4444, ABGR8888 ?? */
- if (gbm_bo_get_format(bo) == GBM_FORMAT_ARGB8888)
- {
- pixman_box32_t box;
- pixman_region32_t *opaque;
-
- box.x1 = 0;
- box.y1 = 0;
- box.x2 = w;
- box.y2 = h;
-
- opaque = pepper_surface_get_opaque_region(surface);
-
- if (pixman_region32_contains_rectangle(opaque, &box) != PIXMAN_REGION_IN)
- {
- gbm_bo_destroy(bo);
- return NULL;
- }
- }
-
- /* TODO: Hard-coded XRGB8888 */
- output->back = drm_buffer_create_client(output->drm, bo, buffer, GBM_FORMAT_XRGB8888);
- if (!output->back)
- {
- gbm_bo_destroy(bo);
- return NULL;
- }
-
- return output->fb_plane;
+ double x, y;
+ int32_t w, h;
+ pepper_surface_t *surface;
+ pepper_buffer_t *buffer;
+ struct wl_resource *resource;
+ struct gbm_bo *bo;
+
+ const pepper_output_geometry_t *geometry;
+
+ if (output->disable_no_comp)
+ return NULL;
+
+ if (output->back)
+ return NULL;
+
+ if (!output->drm->gbm_device)
+ return NULL;
+
+ geometry = pepper_output_get_geometry(output->base);
+ pepper_view_get_position(view, &x, &y);
+ if ((geometry->x != (int)x) || (geometry->y != (int)y))
+ return NULL;
+
+ pepper_view_get_size(view, &w, &h);
+ if ((geometry->w != w) || (geometry->h != h))
+ return NULL;
+
+ surface = pepper_view_get_surface(view);
+ if (!surface)
+ return NULL;
+
+ if (geometry->transform != pepper_surface_get_buffer_transform(surface))
+ return NULL;
+
+ if (pepper_output_get_scale(output->base) != pepper_surface_get_buffer_scale(
+ surface))
+ return NULL;
+
+ buffer = pepper_surface_get_buffer(surface);
+ if (!buffer)
+ return NULL;
+
+ resource = pepper_buffer_get_resource(buffer);
+ if (!resource)
+ return NULL;
+
+ bo = gbm_bo_import(output->drm->gbm_device,
+ GBM_BO_IMPORT_WL_BUFFER, resource, GBM_BO_USE_SCANOUT);
+ if (!bo)
+ return NULL;
+
+ /* TODO: Other alpha formats like ARGB4444, ABGR8888 ?? */
+ if (gbm_bo_get_format(bo) == GBM_FORMAT_ARGB8888) {
+ pixman_box32_t box;
+ pixman_region32_t *opaque;
+
+ box.x1 = 0;
+ box.y1 = 0;
+ box.x2 = w;
+ box.y2 = h;
+
+ opaque = pepper_surface_get_opaque_region(surface);
+
+ if (pixman_region32_contains_rectangle(opaque, &box) != PIXMAN_REGION_IN) {
+ gbm_bo_destroy(bo);
+ return NULL;
+ }
+ }
+
+ /* TODO: Hard-coded XRGB8888 */
+ output->back = drm_buffer_create_client(output->drm, bo, buffer,
+ GBM_FORMAT_XRGB8888);
+ if (!output->back) {
+ gbm_bo_destroy(bo);
+ return NULL;
+ }
+
+ return output->fb_plane;
}
static pepper_plane_t *
assign_overlay_plane(drm_output_t *output, pepper_view_t *view)
{
- drm_plane_t *plane;
- pepper_surface_t *surface;
- pepper_buffer_t *buffer;
- struct wl_resource *resource;
- struct gbm_bo *bo;
- uint32_t format;
- pepper_bool_t found;
- uint32_t i;
-
- double x, y;
- int w, h;
-
- if (!output->use_overlay)
- return NULL;
-
- if (!output->drm->gbm_device)
- return NULL;
-
- surface = pepper_view_get_surface(view);
- if (!surface)
- return NULL;
-
- buffer = pepper_surface_get_buffer(surface);
- if (!buffer)
- return NULL;
-
- resource = pepper_buffer_get_resource(buffer);
- if (!resource)
- return NULL;
-
- if (wl_shm_buffer_get(resource))
- return NULL;
-
- found = PEPPER_FALSE;
-
- pepper_list_for_each(plane, &output->drm->plane_list, link)
- {
- if (plane->back)
- continue;
-
- if (!(plane->plane->possible_crtcs & (1 << output->crtc_index)))
- continue;
-
- found = PEPPER_TRUE;
- break;
- }
-
- if (!found)
- return NULL;
-
- bo = gbm_bo_import(output->drm->gbm_device,
- GBM_BO_IMPORT_WL_BUFFER, resource, GBM_BO_USE_SCANOUT);
- if (!bo)
- return NULL;
-
- /* TODO: Other alpha formats like ARGB4444, ABGR8888 ?? */
- format = gbm_bo_get_format(bo);
-
- if (format == GBM_FORMAT_ARGB8888)
- {
- pixman_box32_t box;
- pixman_region32_t *opaque;
-
- box.x1 = 0;
- box.y1 = 0;
- box.x2 = w;
- box.y2 = h;
-
- opaque = pepper_surface_get_opaque_region(surface);
-
- if (pixman_region32_contains_rectangle(opaque, &box) == PIXMAN_REGION_IN)
- format = GBM_FORMAT_XRGB8888;
- }
-
- found = PEPPER_FALSE;
-
- for (i = 0; i < plane->plane->count_formats; i++)
- {
- if (plane->plane->formats[i] == format)
- {
- found = PEPPER_TRUE;
- break;
- }
- }
-
- if (!found)
- {
- gbm_bo_destroy(bo);
- return NULL;
- }
-
- plane->back = drm_buffer_create_client(output->drm, bo, buffer, format);
- if (!plane->back)
- {
- gbm_bo_destroy(bo);
- return NULL;
- }
-
- /* set position */
- pepper_view_get_position(view, &x, &y);
- pepper_view_get_size(view, &w, &h);
- plane->dx = (int)x;
- plane->dy = (int)y;
- plane->dw = w;
- plane->dh = h;
-
- plane->sx = 0 << 16;
- plane->sy = 0 << 16;
- plane->sw = w << 16;
- plane->sh = h << 16;
-
- plane->output = output;
-
- return plane->base;
+ drm_plane_t *plane;
+ pepper_surface_t *surface;
+ pepper_buffer_t *buffer;
+ struct wl_resource *resource;
+ struct gbm_bo *bo;
+ uint32_t format;
+ pepper_bool_t found;
+ uint32_t i;
+
+ double x, y;
+ int w, h;
+
+ if (!output->use_overlay)
+ return NULL;
+
+ if (!output->drm->gbm_device)
+ return NULL;
+
+ surface = pepper_view_get_surface(view);
+ if (!surface)
+ return NULL;
+
+ buffer = pepper_surface_get_buffer(surface);
+ if (!buffer)
+ return NULL;
+
+ resource = pepper_buffer_get_resource(buffer);
+ if (!resource)
+ return NULL;
+
+ if (wl_shm_buffer_get(resource))
+ return NULL;
+
+ found = PEPPER_FALSE;
+
+ pepper_list_for_each(plane, &output->drm->plane_list, link) {
+ if (plane->back)
+ continue;
+
+ if (!(plane->plane->possible_crtcs & (1 << output->crtc_index)))
+ continue;
+
+ found = PEPPER_TRUE;
+ break;
+ }
+
+ if (!found)
+ return NULL;
+
+ bo = gbm_bo_import(output->drm->gbm_device,
+ GBM_BO_IMPORT_WL_BUFFER, resource, GBM_BO_USE_SCANOUT);
+ if (!bo)
+ return NULL;
+
+ /* TODO: Other alpha formats like ARGB4444, ABGR8888 ?? */
+ format = gbm_bo_get_format(bo);
+
+ if (format == GBM_FORMAT_ARGB8888) {
+ pixman_box32_t box;
+ pixman_region32_t *opaque;
+
+ box.x1 = 0;
+ box.y1 = 0;
+ box.x2 = w;
+ box.y2 = h;
+
+ opaque = pepper_surface_get_opaque_region(surface);
+
+ if (pixman_region32_contains_rectangle(opaque, &box) == PIXMAN_REGION_IN)
+ format = GBM_FORMAT_XRGB8888;
+ }
+
+ found = PEPPER_FALSE;
+
+ for (i = 0; i < plane->plane->count_formats; i++) {
+ if (plane->plane->formats[i] == format) {
+ found = PEPPER_TRUE;
+ break;
+ }
+ }
+
+ if (!found) {
+ gbm_bo_destroy(bo);
+ return NULL;
+ }
+
+ plane->back = drm_buffer_create_client(output->drm, bo, buffer, format);
+ if (!plane->back) {
+ gbm_bo_destroy(bo);
+ return NULL;
+ }
+
+ /* set position */
+ pepper_view_get_position(view, &x, &y);
+ pepper_view_get_size(view, &w, &h);
+ plane->dx = (int)x;
+ plane->dy = (int)y;
+ plane->dw = w;
+ plane->dh = h;
+
+ plane->sx = 0 << 16;
+ plane->sy = 0 << 16;
+ plane->sw = w << 16;
+ plane->sh = h << 16;
+
+ plane->output = output;
+
+ return plane->base;
}
static void
drm_output_assign_planes(void *o, const pepper_list_t *view_list)
{
- pepper_list_t *l;
- drm_output_t *output = o;
+ pepper_list_t *l;
+ drm_output_t *output = o;
- pepper_list_for_each_list(l, view_list)
- {
- pepper_view_t *view = l->item;
- pepper_plane_t *plane = NULL;
+ pepper_list_for_each_list(l, view_list) {
+ pepper_view_t *view = l->item;
+ pepper_plane_t *plane = NULL;
- if (plane == NULL)
- plane = assign_cursor_plane(output, view);
+ if (plane == NULL)
+ plane = assign_cursor_plane(output, view);
- if (plane == NULL)
- plane = assign_fb_plane(output, view);
+ if (plane == NULL)
+ plane = assign_fb_plane(output, view);
- if (plane == NULL)
- plane = assign_overlay_plane(output, view);
+ if (plane == NULL)
+ plane = assign_overlay_plane(output, view);
- if (plane == NULL)
- plane = output->primary_plane;
+ if (plane == NULL)
+ plane = output->primary_plane;
- pepper_view_assign_plane(view, output->base, plane);
- }
+ pepper_view_assign_plane(view, output->base, plane);
+ }
}
static void
drm_output_render_gl(drm_output_t *output)
{
- const pepper_list_t *render_list = pepper_plane_get_render_list(output->primary_plane);
- pixman_region32_t *damage = pepper_plane_get_damage_region(output->primary_plane);
- struct gbm_bo *bo;
+ const pepper_list_t *render_list = pepper_plane_get_render_list(
+ output->primary_plane);
+ pixman_region32_t *damage = pepper_plane_get_damage_region(
+ output->primary_plane);
+ struct gbm_bo *bo;
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, damage);
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ damage);
- bo = gbm_surface_lock_front_buffer(output->gbm_surface);
- PEPPER_CHECK(bo, return, "gbm_surface_lock_front_buffer() failed.\n");
+ bo = gbm_surface_lock_front_buffer(output->gbm_surface);
+ PEPPER_CHECK(bo, return, "gbm_surface_lock_front_buffer() failed.\n");
- output->back = gbm_bo_get_user_data(bo);
+ output->back = gbm_bo_get_user_data(bo);
- if (!output->back)
- output->back = drm_buffer_create_gbm(output->drm, output->gbm_surface, bo);
+ if (!output->back)
+ output->back = drm_buffer_create_gbm(output->drm, output->gbm_surface, bo);
- pepper_plane_clear_damage_region(output->primary_plane);
+ pepper_plane_clear_damage_region(output->primary_plane);
}
static void
drm_output_render_pixman(drm_output_t *output)
{
- const pepper_list_t *render_list = pepper_plane_get_render_list(output->primary_plane);
- pixman_region32_t *damage = pepper_plane_get_damage_region(output->primary_plane);
- pixman_region32_t total_damage;
-
- output->back_fb_index ^= 1;
- output->back = output->fb[output->back_fb_index];
-
- pixman_region32_init(&total_damage);
- pixman_region32_union(&total_damage, damage, &output->previous_damage);
- pixman_region32_copy(&output->previous_damage, damage);
-
- if (output->use_shadow)
- {
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, damage);
-
- /* Copy shadow image to the back frame buffer. */
- pixman_image_set_clip_region32(output->back->image, &total_damage);
- pixman_image_composite32(PIXMAN_OP_SRC,
- output->shadow_image, NULL, output->back->image,
- 0, 0, 0, 0, 0, 0,
- output->back->w, output->back->h);
- }
- else
- {
- output->render_target = output->fb_target[output->back_fb_index];
- pepper_renderer_set_target(output->renderer, output->fb_target[output->back_fb_index]);
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, &total_damage);
- }
-
- pixman_region32_fini(&total_damage);
- pepper_plane_clear_damage_region(output->primary_plane);
+ const pepper_list_t *render_list = pepper_plane_get_render_list(
+ output->primary_plane);
+ pixman_region32_t *damage = pepper_plane_get_damage_region(
+ output->primary_plane);
+ pixman_region32_t total_damage;
+
+ output->back_fb_index ^= 1;
+ output->back = output->fb[output->back_fb_index];
+
+ pixman_region32_init(&total_damage);
+ pixman_region32_union(&total_damage, damage, &output->previous_damage);
+ pixman_region32_copy(&output->previous_damage, damage);
+
+ if (output->use_shadow) {
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ damage);
+
+ /* Copy shadow image to the back frame buffer. */
+ pixman_image_set_clip_region32(output->back->image, &total_damage);
+ pixman_image_composite32(PIXMAN_OP_SRC,
+ output->shadow_image, NULL, output->back->image,
+ 0, 0, 0, 0, 0, 0,
+ output->back->w, output->back->h);
+ } else {
+ output->render_target = output->fb_target[output->back_fb_index];
+ pepper_renderer_set_target(output->renderer,
+ output->fb_target[output->back_fb_index]);
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ &total_damage);
+ }
+
+ pixman_region32_fini(&total_damage);
+ pepper_plane_clear_damage_region(output->primary_plane);
}
static void
drm_output_render(drm_output_t *output)
{
- if (output->render_type == DRM_RENDER_TYPE_PIXMAN)
- drm_output_render_pixman(output);
- else if (output->render_type == DRM_RENDER_TYPE_GL)
- drm_output_render_gl(output);
+ if (output->render_type == DRM_RENDER_TYPE_PIXMAN)
+ drm_output_render_pixman(output);
+ else if (output->render_type == DRM_RENDER_TYPE_GL)
+ drm_output_render_gl(output);
}
static void
drm_output_start_repaint_loop(void *o)
{
- drm_output_t *output = o;
- struct timespec ts;
+ drm_output_t *output = o;
+ struct timespec ts;
- if (output->front && drmModePageFlip(output->drm->fd, output->crtc_id,
- output->front->id, DRM_MODE_PAGE_FLIP_EVENT, output) >= 0)
- {
- return;
- }
+ if (output->front && drmModePageFlip(output->drm->fd, output->crtc_id,
+ output->front->id, DRM_MODE_PAGE_FLIP_EVENT, output) >= 0) {
+ return;
+ }
- pepper_compositor_get_time(output->drm->compositor, &ts);
- pepper_output_finish_frame(output->base, &ts);
+ pepper_compositor_get_time(output->drm->compositor, &ts);
+ pepper_output_finish_frame(output->base, &ts);
}
static void
drm_output_set_cursor(drm_output_t *output)
{
- pepper_drm_t *drm = output->drm;
- pepper_surface_t *surface;
- pepper_buffer_t *buffer;
-
- double x, y;
-
- if (!output->cursor_view)
- {
- drmModeSetCursor(drm->fd, output->crtc_id, 0, 0, 0);
- return;
- }
-
- surface = pepper_view_get_surface(output->cursor_view);
- buffer = pepper_surface_get_buffer(surface);
-
- if (buffer && output->need_set_cursor)
- {
-
- int32_t i, w, h, stride;
- uint8_t *data;
- uint32_t buf[drm->cursor_width * drm->cursor_height];
-
- struct gbm_bo *bo;
- struct wl_resource *resource;
- struct wl_shm_buffer *shm_buffer;
-
- resource = pepper_buffer_get_resource(buffer);
-
- shm_buffer = wl_shm_buffer_get(resource);
- stride = wl_shm_buffer_get_stride(shm_buffer);
- data = wl_shm_buffer_get_data(shm_buffer);
-
- pepper_view_get_size(output->cursor_view, &w, &h);
-
- memset(buf, 0, sizeof(buf));
- wl_shm_buffer_begin_access(shm_buffer);
- for (i = 0; i < h; i++)
- memcpy(buf + i * drm->cursor_width, data + i * stride, w * sizeof(uint32_t));
- wl_shm_buffer_end_access(shm_buffer);
-
- output->cursor_bo_index ^= 1;
- bo = output->cursor_bo[output->cursor_bo_index];
- gbm_bo_write(bo, buf, sizeof(buf));
-
- if (drmModeSetCursor(drm->fd, output->crtc_id, gbm_bo_get_handle(bo).s32,
- drm->cursor_width, drm->cursor_height))
- {
- PEPPER_TRACE("failed to set cursor\n");
- drm->cursor_broken = PEPPER_TRUE;
- }
-
- output->need_set_cursor = PEPPER_FALSE;
- }
-
- pepper_view_get_position(output->cursor_view, &x, &y);
- if ((output->cursor_x != (int)x) || (output->cursor_y != (int)y))
- {
- if (drmModeMoveCursor(drm->fd, output->crtc_id, (int)x, (int)y))
- {
- PEPPER_TRACE("failed to move cursor\n");
- drm->cursor_broken = PEPPER_TRUE;
- }
-
- output->cursor_x = (int)x;
- output->cursor_y = (int)y;
- }
-
- output->cursor_view = NULL;
+ pepper_drm_t *drm = output->drm;
+ pepper_surface_t *surface;
+ pepper_buffer_t *buffer;
+
+ double x, y;
+
+ if (!output->cursor_view) {
+ drmModeSetCursor(drm->fd, output->crtc_id, 0, 0, 0);
+ return;
+ }
+
+ surface = pepper_view_get_surface(output->cursor_view);
+ buffer = pepper_surface_get_buffer(surface);
+
+ if (buffer && output->need_set_cursor) {
+
+ int32_t i, w, h, stride;
+ uint8_t *data;
+ uint32_t buf[drm->cursor_width * drm->cursor_height];
+
+ struct gbm_bo *bo;
+ struct wl_resource *resource;
+ struct wl_shm_buffer *shm_buffer;
+
+ resource = pepper_buffer_get_resource(buffer);
+
+ shm_buffer = wl_shm_buffer_get(resource);
+ stride = wl_shm_buffer_get_stride(shm_buffer);
+ data = wl_shm_buffer_get_data(shm_buffer);
+
+ pepper_view_get_size(output->cursor_view, &w, &h);
+
+ memset(buf, 0, sizeof(buf));
+ wl_shm_buffer_begin_access(shm_buffer);
+ for (i = 0; i < h; i++)
+ memcpy(buf + i * drm->cursor_width, data + i * stride, w * sizeof(uint32_t));
+ wl_shm_buffer_end_access(shm_buffer);
+
+ output->cursor_bo_index ^= 1;
+ bo = output->cursor_bo[output->cursor_bo_index];
+ gbm_bo_write(bo, buf, sizeof(buf));
+
+ if (drmModeSetCursor(drm->fd, output->crtc_id, gbm_bo_get_handle(bo).s32,
+ drm->cursor_width, drm->cursor_height)) {
+ PEPPER_TRACE("failed to set cursor\n");
+ drm->cursor_broken = PEPPER_TRUE;
+ }
+
+ output->need_set_cursor = PEPPER_FALSE;
+ }
+
+ pepper_view_get_position(output->cursor_view, &x, &y);
+ if ((output->cursor_x != (int)x) || (output->cursor_y != (int)y)) {
+ if (drmModeMoveCursor(drm->fd, output->crtc_id, (int)x, (int)y)) {
+ PEPPER_TRACE("failed to move cursor\n");
+ drm->cursor_broken = PEPPER_TRUE;
+ }
+
+ output->cursor_x = (int)x;
+ output->cursor_y = (int)y;
+ }
+
+ output->cursor_view = NULL;
}
static void
drm_output_repaint(void *o, const pepper_list_t *plane_list)
{
- drm_output_t *output = o;
- drm_plane_t *plane;
- int ret;
+ drm_output_t *output = o;
+ drm_plane_t *plane;
+ int ret;
- if (output->destroy_pending)
- return;
+ if (output->destroy_pending)
+ return;
- if (!output->back)
- drm_output_render(output);
+ if (!output->back)
+ drm_output_render(output);
- if (output->back)
- {
- if (!output->front)
- {
- ret = drmModeSetCrtc(output->drm->fd, output->crtc_id, output->back->id, 0, 0,
- &output->conn->id, 1, output->mode);
- }
+ if (output->back) {
+ if (!output->front) {
+ ret = drmModeSetCrtc(output->drm->fd, output->crtc_id, output->back->id, 0, 0,
+ &output->conn->id, 1, output->mode);
+ }
- ret = drmModePageFlip(output->drm->fd, output->crtc_id, output->back->id,
- DRM_MODE_PAGE_FLIP_EVENT, output);
- PEPPER_CHECK(ret == 0, , "page flip failed.\n");
+ ret = drmModePageFlip(output->drm->fd, output->crtc_id, output->back->id,
+ DRM_MODE_PAGE_FLIP_EVENT, output);
+ PEPPER_CHECK(ret == 0, , "page flip failed.\n");
- output->page_flip_pending = PEPPER_TRUE;
- }
+ output->page_flip_pending = PEPPER_TRUE;
+ }
- drm_output_set_cursor(output);
+ drm_output_set_cursor(output);
- pepper_list_for_each(plane, &output->drm->plane_list, link)
- {
- drmVBlank vbl;
+ pepper_list_for_each(plane, &output->drm->plane_list, link) {
+ drmVBlank vbl;
- if (plane->output != output || plane->back == NULL)
- continue;
+ if (plane->output != output || plane->back == NULL)
+ continue;
- vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT;
+ vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT;
- ret = drmModeSetPlane(output->drm->fd, plane->id,
- output->crtc_id, plane->back->id, 0,
- plane->dx, plane->dy, plane->dw, plane->dh,
- plane->sx, plane->sy, plane->sw, plane->sh);
+ ret = drmModeSetPlane(output->drm->fd, plane->id,
+ output->crtc_id, plane->back->id, 0,
+ plane->dx, plane->dy, plane->dw, plane->dh,
+ plane->sx, plane->sy, plane->sw, plane->sh);
- PEPPER_CHECK(ret == 0, continue, "drmModeSetPlane() failed.\n");
- pepper_plane_clear_damage_region(plane->base);
+ PEPPER_CHECK(ret == 0, continue, "drmModeSetPlane() failed.\n");
+ pepper_plane_clear_damage_region(plane->base);
- if (output->crtc_index > 1)
- {
- vbl.request.type |= (output->crtc_index << DRM_VBLANK_HIGH_CRTC_SHIFT) &
- DRM_VBLANK_HIGH_CRTC_MASK;
- }
- else if (output->crtc_index > 0)
- {
- vbl.request.type |= DRM_VBLANK_SECONDARY;
- }
+ if (output->crtc_index > 1) {
+ vbl.request.type |= (output->crtc_index << DRM_VBLANK_HIGH_CRTC_SHIFT) &
+ DRM_VBLANK_HIGH_CRTC_MASK;
+ } else if (output->crtc_index > 0) {
+ vbl.request.type |= DRM_VBLANK_SECONDARY;
+ }
- vbl.request.sequence = 1;
- vbl.request.signal = (unsigned long)plane;
+ vbl.request.sequence = 1;
+ vbl.request.signal = (unsigned long)plane;
- ret = drmWaitVBlank(output->drm->fd, &vbl);
- PEPPER_CHECK(ret == 0, continue, "drmWaitVBlank() failed.\n");
+ ret = drmWaitVBlank(output->drm->fd, &vbl);
+ PEPPER_CHECK(ret == 0, continue, "drmWaitVBlank() failed.\n");
- output->vblank_pending_count++;
- }
+ output->vblank_pending_count++;
+ }
}
static void
drm_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h)
{
- drm_output_t *output = o;
- pepper_renderer_attach_surface(output->renderer, surface, w, h);
+ drm_output_t *output = o;
+ pepper_renderer_attach_surface(output->renderer, surface, w, h);
}
static void
-drm_output_flush_surface_damage(void *o, pepper_surface_t *surface, pepper_bool_t *keep_buffer)
+drm_output_flush_surface_damage(void *o, pepper_surface_t *surface,
+ pepper_bool_t *keep_buffer)
{
- drm_output_t *output = o;
- pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
+ drm_output_t *output = o;
+ pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
- pepper_renderer_flush_surface_damage(output->renderer, surface);
+ pepper_renderer_flush_surface_damage(output->renderer, surface);
- if (output->render_type == DRM_RENDER_TYPE_PIXMAN)
- goto keep;
+ if (output->render_type == DRM_RENDER_TYPE_PIXMAN)
+ goto keep;
- if (buffer)
- {
- int w, h;
+ if (buffer) {
+ int w, h;
- if (!wl_shm_buffer_get(pepper_buffer_get_resource(buffer)))
- goto keep;
+ if (!wl_shm_buffer_get(pepper_buffer_get_resource(buffer)))
+ goto keep;
- pepper_buffer_get_size(buffer, &w, &h);
- if ((w <= output->drm->cursor_width) && (h <= output->drm->cursor_height))
- goto keep;
- }
+ pepper_buffer_get_size(buffer, &w, &h);
+ if ((w <= output->drm->cursor_width) && (h <= output->drm->cursor_height))
+ goto keep;
+ }
- *keep_buffer = PEPPER_FALSE;
- return;
+ *keep_buffer = PEPPER_FALSE;
+ return;
keep:
- *keep_buffer = PEPPER_TRUE;
+ *keep_buffer = PEPPER_TRUE;
}
-struct pepper_output_backend drm_output_backend =
-{
- drm_output_destroy,
+struct pepper_output_backend drm_output_backend = {
+ drm_output_destroy,
- drm_output_get_subpixel_order,
- drm_output_get_maker_name,
- drm_output_get_model_name,
+ drm_output_get_subpixel_order,
+ drm_output_get_maker_name,
+ drm_output_get_model_name,
- drm_output_get_mode_count,
- drm_output_get_mode,
- drm_output_set_mode,
+ drm_output_get_mode_count,
+ drm_output_get_mode,
+ drm_output_set_mode,
- drm_output_assign_planes,
- drm_output_start_repaint_loop,
- drm_output_repaint,
- drm_output_attach_surface,
- drm_output_flush_surface_damage,
+ drm_output_assign_planes,
+ drm_output_start_repaint_loop,
+ drm_output_repaint,
+ drm_output_attach_surface,
+ drm_output_flush_surface_damage,
};
static int
find_crtc_for_connector(drm_connector_t *conn)
{
- int i, j;
+ int i, j;
- for (i = 0; i < conn->connector->count_encoders; i++)
- {
- int32_t possible_crtcs;
- drmModeEncoder *encoder = drmModeGetEncoder(conn->drm->fd, conn->connector->encoders[i]);
+ for (i = 0; i < conn->connector->count_encoders; i++) {
+ int32_t possible_crtcs;
+ drmModeEncoder *encoder = drmModeGetEncoder(conn->drm->fd,
+ conn->connector->encoders[i]);
- PEPPER_CHECK(encoder, continue, "drmModeGetEncoder() failed.\n");
+ PEPPER_CHECK(encoder, continue, "drmModeGetEncoder() failed.\n");
- possible_crtcs = encoder->possible_crtcs;
- drmModeFreeEncoder(encoder);
+ possible_crtcs = encoder->possible_crtcs;
+ drmModeFreeEncoder(encoder);
- for (j = 0; j < conn->drm->resources->count_crtcs; j++)
- {
- if (!(possible_crtcs & (1 << j)))
- continue;
+ for (j = 0; j < conn->drm->resources->count_crtcs; j++) {
+ if (!(possible_crtcs & (1 << j)))
+ continue;
- if (!(conn->drm->used_crtcs & (1 << j)))
- return j;
- }
- }
+ if (!(conn->drm->used_crtcs & (1 << j)))
+ return j;
+ }
+ }
- return -1;
+ return -1;
}
static void
fini_pixman_renderer(drm_output_t *output)
{
- int i;
+ int i;
- if (output->use_shadow)
- {
- if (output->shadow_image)
- pixman_image_unref(output->shadow_image);
+ if (output->use_shadow) {
+ if (output->shadow_image)
+ pixman_image_unref(output->shadow_image);
- if (output->render_target)
- pepper_render_target_destroy(output->render_target);
- }
+ if (output->render_target)
+ pepper_render_target_destroy(output->render_target);
+ }
- output->shadow_image = NULL;
- output->render_target = NULL;
+ output->shadow_image = NULL;
+ output->render_target = NULL;
- for (i = 0; i < 2; i++)
- {
- if (output->fb[i])
- drm_buffer_destroy(output->fb[i]);
+ for (i = 0; i < 2; i++) {
+ if (output->fb[i])
+ drm_buffer_destroy(output->fb[i]);
- if (output->fb_target[i])
- pepper_render_target_destroy(output->fb_target[i]);
+ if (output->fb_target[i])
+ pepper_render_target_destroy(output->fb_target[i]);
- output->fb[i] = NULL;
- output->fb_target[i] = NULL;
- }
+ output->fb[i] = NULL;
+ output->fb_target[i] = NULL;
+ }
- pixman_region32_fini(&output->previous_damage);
- output->renderer = NULL;
- output->render_target = NULL;
+ pixman_region32_fini(&output->previous_damage);
+ output->renderer = NULL;
+ output->render_target = NULL;
}
static void
init_pixman_renderer(drm_output_t *output)
{
- pepper_drm_t *drm = output->drm;
- int i;
- int w = output->mode->hdisplay;
- int h = output->mode->vdisplay;
-
- if (!drm->pixman_renderer)
- {
- drm->pixman_renderer = pepper_pixman_renderer_create(drm->compositor);
- PEPPER_CHECK(drm->pixman_renderer, return, "pepper_pixman_renderer_create() failed.\n");
- }
-
- output->renderer = drm->pixman_renderer;
-
- for (i = 0; i < 2; i++)
- {
- output->fb[i] = drm_buffer_create_dumb(drm, w, h);
- PEPPER_CHECK(output->fb[i], goto error, "drm_buffer_create_dumb() failed.\n");
- }
-
- pixman_region32_init(&output->previous_damage);
- output->render_type = DRM_RENDER_TYPE_PIXMAN;
-
- if (output->use_shadow)
- {
- output->shadow_image = pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, NULL, 0);
- PEPPER_CHECK(output->shadow_image, goto error, "pixman_image_create_bits() failed.\n");
-
- output->render_target = pepper_pixman_renderer_create_target_for_image(output->shadow_image);
- PEPPER_CHECK(output->render_target, goto error, "pixman target creation failed.\n");
-
- pepper_renderer_set_target(output->renderer, output->render_target);
- }
- else
- {
- for (i = 0; i < 2; i++)
- {
- output->fb_target[i] =
- pepper_pixman_renderer_create_target_for_image(output->fb[i]->image);
- PEPPER_CHECK(output->fb_target[i], goto error, "pixman target creation failed.\n");
- }
- }
-
- return;
+ pepper_drm_t *drm = output->drm;
+ int i;
+ int w = output->mode->hdisplay;
+ int h = output->mode->vdisplay;
+
+ if (!drm->pixman_renderer) {
+ drm->pixman_renderer = pepper_pixman_renderer_create(drm->compositor);
+ PEPPER_CHECK(drm->pixman_renderer, return,
+ "pepper_pixman_renderer_create() failed.\n");
+ }
+
+ output->renderer = drm->pixman_renderer;
+
+ for (i = 0; i < 2; i++) {
+ output->fb[i] = drm_buffer_create_dumb(drm, w, h);
+ PEPPER_CHECK(output->fb[i], goto error, "drm_buffer_create_dumb() failed.\n");
+ }
+
+ pixman_region32_init(&output->previous_damage);
+ output->render_type = DRM_RENDER_TYPE_PIXMAN;
+
+ if (output->use_shadow) {
+ output->shadow_image = pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h, NULL, 0);
+ PEPPER_CHECK(output->shadow_image, goto error,
+ "pixman_image_create_bits() failed.\n");
+
+ output->render_target = pepper_pixman_renderer_create_target_for_image(
+ output->shadow_image);
+ PEPPER_CHECK(output->render_target, goto error,
+ "pixman target creation failed.\n");
+
+ pepper_renderer_set_target(output->renderer, output->render_target);
+ } else {
+ for (i = 0; i < 2; i++) {
+ output->fb_target[i] =
+ pepper_pixman_renderer_create_target_for_image(output->fb[i]->image);
+ PEPPER_CHECK(output->fb_target[i], goto error,
+ "pixman target creation failed.\n");
+ }
+ }
+
+ return;
error:
- fini_pixman_renderer(output);
+ fini_pixman_renderer(output);
}
static void
fini_gl_renderer(drm_output_t *output)
{
- if (output->render_target)
- pepper_render_target_destroy(output->render_target);
+ if (output->render_target)
+ pepper_render_target_destroy(output->render_target);
- if (output->gbm_surface)
- gbm_surface_destroy(output->gbm_surface);
+ if (output->gbm_surface)
+ gbm_surface_destroy(output->gbm_surface);
- output->renderer = NULL;
- output->render_target = NULL;
- output->gbm_surface = NULL;
+ output->renderer = NULL;
+ output->render_target = NULL;
+ output->gbm_surface = NULL;
}
static void
init_gl_renderer(drm_output_t *output)
{
- pepper_drm_t *drm = output->drm;
- int w = output->mode->hdisplay;
- int h = output->mode->vdisplay;
- uint32_t native_visual_id = GBM_FORMAT_XRGB8888;
-
- if (!drm->gl_renderer)
- {
- if (!drm->gbm_device)
- {
- drm->gbm_device = gbm_create_device(drm->fd);
- PEPPER_CHECK(drm->gbm_device, return, "gbm_create_device() failed.\n");
- }
-
- drm->gl_renderer = pepper_gl_renderer_create(drm->compositor, drm->gbm_device, "gbm");
- PEPPER_CHECK(drm->gl_renderer, return, "pepper_gl_renderer_create() failed.\n");
- }
-
- output->renderer = drm->gl_renderer;
-
- output->gbm_surface = gbm_surface_create(drm->gbm_device, w, h, GBM_FORMAT_XRGB8888,
- GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
- PEPPER_CHECK(output->gbm_surface, goto error, "gbm_surface_create() failed.\n");
-
- output->render_target = pepper_gl_renderer_create_target(drm->gl_renderer,
- output->gbm_surface,
- PEPPER_FORMAT_XRGB8888,
- &native_visual_id, w, h);
- PEPPER_CHECK(output->render_target, goto error, "pepper_gl_renderer_create_target() failed.\n");
- output->render_type = DRM_RENDER_TYPE_GL;
-
- pepper_renderer_set_target(output->renderer, output->render_target);
- return;
+ pepper_drm_t *drm = output->drm;
+ int w = output->mode->hdisplay;
+ int h = output->mode->vdisplay;
+ uint32_t native_visual_id = GBM_FORMAT_XRGB8888;
+
+ if (!drm->gl_renderer) {
+ if (!drm->gbm_device) {
+ drm->gbm_device = gbm_create_device(drm->fd);
+ PEPPER_CHECK(drm->gbm_device, return, "gbm_create_device() failed.\n");
+ }
+
+ drm->gl_renderer = pepper_gl_renderer_create(drm->compositor, drm->gbm_device,
+ "gbm");
+ PEPPER_CHECK(drm->gl_renderer, return, "pepper_gl_renderer_create() failed.\n");
+ }
+
+ output->renderer = drm->gl_renderer;
+
+ output->gbm_surface = gbm_surface_create(drm->gbm_device, w, h,
+ GBM_FORMAT_XRGB8888,
+ GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+ PEPPER_CHECK(output->gbm_surface, goto error, "gbm_surface_create() failed.\n");
+
+ output->render_target = pepper_gl_renderer_create_target(drm->gl_renderer,
+ output->gbm_surface,
+ PEPPER_FORMAT_XRGB8888,
+ &native_visual_id, w, h);
+ PEPPER_CHECK(output->render_target, goto error,
+ "pepper_gl_renderer_create_target() failed.\n");
+ output->render_type = DRM_RENDER_TYPE_GL;
+
+ pepper_renderer_set_target(output->renderer, output->render_target);
+ return;
error:
- fini_gl_renderer(output);
+ fini_gl_renderer(output);
}
drm_output_t *
drm_output_create(drm_connector_t *conn)
{
- pepper_drm_t *drm = conn->drm;
- drm_output_t *output;
- drm_plane_t *plane, *tmp;
- const char *render_env = getenv("PEPPER_DRM_RENDERER");
- const char *shadow_env = getenv("PEPPER_DRM_USE_SHADOW");
- const char *disable_no_comp_env = getenv("PEPPER_DRM_DISABLE_NO_COMP");
- const char *use_overlay_env = getenv("PEPPER_DRM_USE_OVERLAY");
-
- PEPPER_CHECK(conn->output == NULL, return NULL, "The connector already has an output.\n");
-
- output = calloc(1, sizeof(drm_output_t));
- PEPPER_CHECK(output, return NULL, "calloc() failed.\n");
-
- output->drm = drm;
- output->conn = conn;
- output->crtc_index = find_crtc_for_connector(conn);
- output->crtc_id = drm->resources->crtcs[output->crtc_index];
- output->saved_crtc = drmModeGetCrtc(drm->fd, output->crtc_id);
- output->mode = &conn->connector->modes[0];
-
- output->base = pepper_compositor_add_output(drm->compositor, &drm_output_backend,
- conn->name, output, WL_OUTPUT_TRANSFORM_NORMAL, 1);
- PEPPER_CHECK(output->base, goto error, "pepper_compositor_add_output() failed.\n");
-
- if (render_env && strcmp(render_env, "gl") == 0)
- init_gl_renderer(output);
-
- if (!output->renderer)
- {
- if (shadow_env && strcmp(shadow_env, "0") == 0)
- output->use_shadow = PEPPER_FALSE;
- else
- output->use_shadow = PEPPER_TRUE;
-
- init_pixman_renderer(output);
- PEPPER_CHECK(output->renderer, goto error, "Failed to initialize renderer.\n");
- }
-
- if (disable_no_comp_env && strcmp(disable_no_comp_env, "1") == 0)
- output->disable_no_comp = PEPPER_TRUE;
-
- if (use_overlay_env && strcmp(use_overlay_env, "1") == 0)
- output->use_overlay = PEPPER_TRUE;
-
- if (drm->gbm_device)
- {
- int i;
-
- for (i = 0; i < 2; i++)
- output->cursor_bo[i] = gbm_bo_create(drm->gbm_device,
- drm->cursor_width, drm->cursor_height,
- GBM_FORMAT_ARGB8888,
- GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
- if (!output->cursor_bo[0] || !output->cursor_bo[1])
- {
- PEPPER_TRACE("failed to create cursor bo\n");
- drm->cursor_broken = PEPPER_TRUE;
- }
- }
-
- output->primary_plane = pepper_output_add_plane(output->base, NULL);
- PEPPER_CHECK(output->primary_plane, goto error, "pepper_output_add_plane() failed.\n");
-
- output->cursor_plane = pepper_output_add_plane(output->base, output->primary_plane);
- PEPPER_CHECK(output->cursor_plane, goto error, "pepper_output_add_plane() failed.\n");
-
- output->fb_plane = pepper_output_add_plane(output->base, output->primary_plane);
- PEPPER_CHECK(output->fb_plane, goto error, "pepper_output_add_plane() failed.\n");
-
- pepper_list_for_each_safe(plane, tmp, &output->drm->plane_list, link)
- {
- if (plane->output == NULL && (plane->plane->possible_crtcs & (1 << output->crtc_index)))
- {
- plane->base = pepper_output_add_plane(output->base, output->primary_plane);
-
- if (plane->base)
- plane->output = output;
- }
- }
-
- drm->used_crtcs |= (1 << output->crtc_index);
- conn->output = output;
-
- return output;
+ pepper_drm_t *drm = conn->drm;
+ drm_output_t *output;
+ drm_plane_t *plane, *tmp;
+ const char *render_env = getenv("PEPPER_DRM_RENDERER");
+ const char *shadow_env = getenv("PEPPER_DRM_USE_SHADOW");
+ const char *disable_no_comp_env = getenv("PEPPER_DRM_DISABLE_NO_COMP");
+ const char *use_overlay_env = getenv("PEPPER_DRM_USE_OVERLAY");
+
+ PEPPER_CHECK(conn->output == NULL, return NULL,
+ "The connector already has an output.\n");
+
+ output = calloc(1, sizeof(drm_output_t));
+ PEPPER_CHECK(output, return NULL, "calloc() failed.\n");
+
+ output->drm = drm;
+ output->conn = conn;
+ output->crtc_index = find_crtc_for_connector(conn);
+ output->crtc_id = drm->resources->crtcs[output->crtc_index];
+ output->saved_crtc = drmModeGetCrtc(drm->fd, output->crtc_id);
+ output->mode = &conn->connector->modes[0];
+
+ output->base = pepper_compositor_add_output(drm->compositor,
+ &drm_output_backend,
+ conn->name, output, WL_OUTPUT_TRANSFORM_NORMAL, 1);
+ PEPPER_CHECK(output->base, goto error,
+ "pepper_compositor_add_output() failed.\n");
+
+ if (render_env && strcmp(render_env, "gl") == 0)
+ init_gl_renderer(output);
+
+ if (!output->renderer) {
+ if (shadow_env && strcmp(shadow_env, "0") == 0)
+ output->use_shadow = PEPPER_FALSE;
+ else
+ output->use_shadow = PEPPER_TRUE;
+
+ init_pixman_renderer(output);
+ PEPPER_CHECK(output->renderer, goto error, "Failed to initialize renderer.\n");
+ }
+
+ if (disable_no_comp_env && strcmp(disable_no_comp_env, "1") == 0)
+ output->disable_no_comp = PEPPER_TRUE;
+
+ if (use_overlay_env && strcmp(use_overlay_env, "1") == 0)
+ output->use_overlay = PEPPER_TRUE;
+
+ if (drm->gbm_device) {
+ int i;
+
+ for (i = 0; i < 2; i++)
+ output->cursor_bo[i] = gbm_bo_create(drm->gbm_device,
+ drm->cursor_width, drm->cursor_height,
+ GBM_FORMAT_ARGB8888,
+ GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
+ if (!output->cursor_bo[0] || !output->cursor_bo[1]) {
+ PEPPER_TRACE("failed to create cursor bo\n");
+ drm->cursor_broken = PEPPER_TRUE;
+ }
+ }
+
+ output->primary_plane = pepper_output_add_plane(output->base, NULL);
+ PEPPER_CHECK(output->primary_plane, goto error,
+ "pepper_output_add_plane() failed.\n");
+
+ output->cursor_plane = pepper_output_add_plane(output->base,
+ output->primary_plane);
+ PEPPER_CHECK(output->cursor_plane, goto error,
+ "pepper_output_add_plane() failed.\n");
+
+ output->fb_plane = pepper_output_add_plane(output->base, output->primary_plane);
+ PEPPER_CHECK(output->fb_plane, goto error,
+ "pepper_output_add_plane() failed.\n");
+
+ pepper_list_for_each_safe(plane, tmp, &output->drm->plane_list, link) {
+ if (plane->output == NULL &&
+ (plane->plane->possible_crtcs & (1 << output->crtc_index))) {
+ plane->base = pepper_output_add_plane(output->base, output->primary_plane);
+
+ if (plane->base)
+ plane->output = output;
+ }
+ }
+
+ drm->used_crtcs |= (1 << output->crtc_index);
+ conn->output = output;
+
+ return output;
error:
- if (output->saved_crtc)
- {
- drmModeFreeCrtc(output->saved_crtc);
- output->saved_crtc = NULL;
- }
+ if (output->saved_crtc) {
+ drmModeFreeCrtc(output->saved_crtc);
+ output->saved_crtc = NULL;
+ }
- if (output->base)
- pepper_output_destroy(output->base);
+ if (output->base)
+ pepper_output_destroy(output->base);
- return NULL;
+ return NULL;
}
void
drm_output_destroy(void *o)
{
- int i;
- drm_output_t *output = o;
- drm_plane_t *plane;
-
- if (output->page_flip_pending || (output->vblank_pending_count > 0))
- {
- output->destroy_pending = PEPPER_TRUE;
- return;
- }
-
- for (i = 0; i < 2; i++)
- {
- if (output->cursor_bo[i])
- gbm_bo_destroy(output->cursor_bo[i]);
- }
-
- if (output->render_type == DRM_RENDER_TYPE_PIXMAN)
- fini_pixman_renderer(output);
- else if (output->render_type == DRM_RENDER_TYPE_GL)
- fini_gl_renderer(output);
-
- if (output->saved_crtc)
- {
- drmModeSetCrtc(output->conn->drm->fd,
- output->saved_crtc->crtc_id,
- output->saved_crtc->buffer_id,
- output->saved_crtc->x, output->saved_crtc->y,
- &output->conn->connector->connector_id, 1, &output->saved_crtc->mode);
- drmModeFreeCrtc(output->saved_crtc);
- }
-
- if (output->fb_plane)
- pepper_plane_destroy(output->fb_plane);
-
- if (output->primary_plane)
- pepper_plane_destroy(output->primary_plane);
-
- /* Release all planes. */
- pepper_list_for_each(plane, &output->drm->plane_list, link)
- {
- if (plane->output == output)
- {
- plane->output = NULL;
- pepper_plane_destroy(plane->base);
- drmModeSetPlane(output->drm->fd, plane->id, output->crtc_id,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- }
- }
-
- /* destroy renderer. */
- free(output);
+ int i;
+ drm_output_t *output = o;
+ drm_plane_t *plane;
+
+ if (output->page_flip_pending || (output->vblank_pending_count > 0)) {
+ output->destroy_pending = PEPPER_TRUE;
+ return;
+ }
+
+ for (i = 0; i < 2; i++) {
+ if (output->cursor_bo[i])
+ gbm_bo_destroy(output->cursor_bo[i]);
+ }
+
+ if (output->render_type == DRM_RENDER_TYPE_PIXMAN)
+ fini_pixman_renderer(output);
+ else if (output->render_type == DRM_RENDER_TYPE_GL)
+ fini_gl_renderer(output);
+
+ if (output->saved_crtc) {
+ drmModeSetCrtc(output->conn->drm->fd,
+ output->saved_crtc->crtc_id,
+ output->saved_crtc->buffer_id,
+ output->saved_crtc->x, output->saved_crtc->y,
+ &output->conn->connector->connector_id, 1, &output->saved_crtc->mode);
+ drmModeFreeCrtc(output->saved_crtc);
+ }
+
+ if (output->fb_plane)
+ pepper_plane_destroy(output->fb_plane);
+
+ if (output->primary_plane)
+ pepper_plane_destroy(output->primary_plane);
+
+ /* Release all planes. */
+ pepper_list_for_each(plane, &output->drm->plane_list, link) {
+ if (plane->output == output) {
+ plane->output = NULL;
+ pepper_plane_destroy(plane->base);
+ drmModeSetPlane(output->drm->fd, plane->id, output->crtc_id,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+ }
+
+ /* destroy renderer. */
+ free(output);
}
void
-drm_handle_vblank(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
+drm_handle_vblank(int fd, unsigned int frame, unsigned int sec,
+ unsigned int usec, void *data)
{
- drm_plane_t *plane = data;
- struct timespec ts;
-
- plane->output->vblank_pending_count--;
-
- if (plane->front)
- drm_buffer_release(plane->front);
-
- plane->front = plane->back;
- plane->back = NULL;
-
- if (plane->output->vblank_pending_count == 0 && !plane->output->page_flip_pending)
- {
- if (plane->output->destroy_pending)
- {
- drm_output_destroy(plane->output);
- }
- else
- {
- ts.tv_sec = sec;
- ts.tv_nsec = usec * 1000;
- pepper_output_finish_frame(plane->output->base, &ts);
- }
- }
+ drm_plane_t *plane = data;
+ struct timespec ts;
+
+ plane->output->vblank_pending_count--;
+
+ if (plane->front)
+ drm_buffer_release(plane->front);
+
+ plane->front = plane->back;
+ plane->back = NULL;
+
+ if (plane->output->vblank_pending_count == 0 &&
+ !plane->output->page_flip_pending) {
+ if (plane->output->destroy_pending) {
+ drm_output_destroy(plane->output);
+ } else {
+ ts.tv_sec = sec;
+ ts.tv_nsec = usec * 1000;
+ pepper_output_finish_frame(plane->output->base, &ts);
+ }
+ }
}
void
-drm_handle_page_flip(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
+drm_handle_page_flip(int fd, unsigned int frame, unsigned int sec,
+ unsigned int usec, void *data)
{
- drm_output_t *output = data;
- struct timespec ts;
-
- if (output->page_flip_pending == PEPPER_TRUE)
- {
- output->page_flip_pending = PEPPER_FALSE;
-
- if (output->front)
- drm_buffer_release(output->front);
-
- output->front = output->back;
- output->back = NULL;
- }
-
- if (output->vblank_pending_count == 0)
- {
- if (output->destroy_pending)
- {
- drm_output_destroy(output);
- }
- else
- {
- ts.tv_sec = sec;
- ts.tv_nsec = usec * 1000;
- pepper_output_finish_frame(output->base, &ts);
- }
- }
+ drm_output_t *output = data;
+ struct timespec ts;
+
+ if (output->page_flip_pending == PEPPER_TRUE) {
+ output->page_flip_pending = PEPPER_FALSE;
+
+ if (output->front)
+ drm_buffer_release(output->front);
+
+ output->front = output->back;
+ output->back = NULL;
+ }
+
+ if (output->vblank_pending_count == 0) {
+ if (output->destroy_pending) {
+ drm_output_destroy(output);
+ } else {
+ ts.tv_sec = sec;
+ ts.tv_nsec = usec * 1000;
+ pepper_output_finish_frame(output->base, &ts);
+ }
+ }
}
* Copyright © 2012 Collabora, Ltd.
* Copyright © 2015 S-Core Corporation
* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
+*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
-*
+*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
-*
+*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
void
drm_init_planes(pepper_drm_t *drm)
{
- int i;
- drmModePlaneRes *res = drmModeGetPlaneResources(drm->fd);
+ int i;
+ drmModePlaneRes *res = drmModeGetPlaneResources(drm->fd);
- PEPPER_CHECK(res, return, "drmModeGetPlaneResources() failed.\n");
+ PEPPER_CHECK(res, return, "drmModeGetPlaneResources() failed.\n");
- for (i = 0; i < (int)res->count_planes; i++)
- {
- drm_plane_t *plane = calloc(1, sizeof(drm_plane_t));
- PEPPER_CHECK(plane, continue, "calloc() failed.\n");
+ for (i = 0; i < (int)res->count_planes; i++) {
+ drm_plane_t *plane = calloc(1, sizeof(drm_plane_t));
+ PEPPER_CHECK(plane, continue, "calloc() failed.\n");
- plane->plane = drmModeGetPlane(drm->fd, res->planes[i]);
- if (!plane->plane)
- {
- PEPPER_ERROR("drmModeGetPlane() failed.\n");
- free(plane);
- continue;
- }
- plane->drm = drm;
- plane->id = plane->plane->plane_id;
+ plane->plane = drmModeGetPlane(drm->fd, res->planes[i]);
+ if (!plane->plane) {
+ PEPPER_ERROR("drmModeGetPlane() failed.\n");
+ free(plane);
+ continue;
+ }
+ plane->drm = drm;
+ plane->id = plane->plane->plane_id;
- pepper_list_insert(drm->plane_list.prev, &plane->link);
- }
+ pepper_list_insert(drm->plane_list.prev, &plane->link);
+ }
- drmModeFreePlaneResources(res);
+ drmModeFreePlaneResources(res);
}
void
drm_plane_destroy(drm_plane_t *plane)
{
- if (plane->plane)
- drmModeFreePlane(plane->plane);
+ if (plane->plane)
+ drmModeFreePlane(plane->plane);
- pepper_list_remove(&plane->link);
- free(plane);
+ pepper_list_remove(&plane->link);
+ free(plane);
}
* Copyright © 2012 Collabora, Ltd.
* Copyright © 2015 S-Core Corporation
* Copyright © 2015-2016 Samsung Electronics co., Ltd. All Rights Reserved.
-*
+*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
-*
+*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
-*
+*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
typedef struct pepper_drm pepper_drm_t;
PEPPER_API pepper_drm_t *
-pepper_drm_create(pepper_compositor_t *compositor, struct udev *udev, const char *device);
+pepper_drm_create(pepper_compositor_t *compositor, struct udev *udev,
+ const char *device);
PEPPER_API void
pepper_drm_destroy(pepper_drm_t *drm);
PEPPER_API pepper_fbdev_t *
pepper_fbdev_create(pepper_compositor_t *compositor, struct udev *udev,
- const char *device, const char *renderer)
+ const char *device, const char *renderer)
{
- pepper_fbdev_t *fbdev;
+ pepper_fbdev_t *fbdev;
- fbdev = (pepper_fbdev_t *)calloc(1, sizeof(pepper_fbdev_t));
- if (!fbdev)
- {
- PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
- goto error;
- }
+ fbdev = (pepper_fbdev_t *)calloc(1, sizeof(pepper_fbdev_t));
+ if (!fbdev) {
+ PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
+ goto error;
+ }
- fbdev->pixman_renderer = pepper_pixman_renderer_create(compositor);
- if (!fbdev->pixman_renderer)
- {
- PEPPER_ERROR("Failed to create pixman renderer.\n");
- goto error;
- }
+ fbdev->pixman_renderer = pepper_pixman_renderer_create(compositor);
+ if (!fbdev->pixman_renderer) {
+ PEPPER_ERROR("Failed to create pixman renderer.\n");
+ goto error;
+ }
- fbdev->compositor = compositor;
- fbdev->udev = udev;
- pepper_list_init(&fbdev->output_list);
+ fbdev->compositor = compositor;
+ fbdev->udev = udev;
+ pepper_list_init(&fbdev->output_list);
- if (!pepper_fbdev_output_create(fbdev, renderer))
- {
- PEPPER_ERROR("Failed to connect fbdev output in %s\n", __FUNCTION__);
- goto error;
- }
+ if (!pepper_fbdev_output_create(fbdev, renderer)) {
+ PEPPER_ERROR("Failed to connect fbdev output in %s\n", __FUNCTION__);
+ goto error;
+ }
- return fbdev;
+ return fbdev;
error:
- if (fbdev)
- pepper_fbdev_destroy(fbdev);
+ if (fbdev)
+ pepper_fbdev_destroy(fbdev);
- return NULL;
+ return NULL;
}
PEPPER_API void
pepper_fbdev_destroy(pepper_fbdev_t *fbdev)
{
- if (fbdev->pixman_renderer)
- pepper_renderer_destroy(fbdev->pixman_renderer);
+ if (fbdev->pixman_renderer)
+ pepper_renderer_destroy(fbdev->pixman_renderer);
- if (!pepper_list_empty(&fbdev->output_list))
- {
- fbdev_output_t *output, *tmp;
+ if (!pepper_list_empty(&fbdev->output_list)) {
+ fbdev_output_t *output, *tmp;
- pepper_list_for_each_safe(output, tmp, &fbdev->output_list, link)
- pepper_fbdev_output_destroy(output);
- }
+ pepper_list_for_each_safe(output, tmp, &fbdev->output_list, link)
+ pepper_fbdev_output_destroy(output);
+ }
- free(fbdev);
+ free(fbdev);
}
typedef struct fbdev_output fbdev_output_t;
-struct pepper_fbdev
-{
- pepper_compositor_t *compositor;
+struct pepper_fbdev {
+ pepper_compositor_t *compositor;
- pepper_list_t output_list;
+ pepper_list_t output_list;
- uint32_t min_width, min_height;
- uint32_t max_width, max_height;
+ uint32_t min_width, min_height;
+ uint32_t max_width, max_height;
- struct udev *udev;
+ struct udev *udev;
- pepper_renderer_t *pixman_renderer;
+ pepper_renderer_t *pixman_renderer;
};
-struct fbdev_output
-{
- pepper_fbdev_t *fbdev;
- pepper_output_t *base;
- pepper_list_t link;
+struct fbdev_output {
+ pepper_fbdev_t *fbdev;
+ pepper_output_t *base;
+ pepper_list_t link;
- pepper_renderer_t *renderer;
+ pepper_renderer_t *renderer;
- pepper_render_target_t *render_target;
- pepper_format_t format;
- int32_t subpixel;
- int w, h;
- int bpp;
- int stride;
+ pepper_render_target_t *render_target;
+ pepper_format_t format;
+ int32_t subpixel;
+ int w, h;
+ int bpp;
+ int stride;
- void *frame_buffer_pixels;
- pixman_image_t *frame_buffer_image;
- pixman_image_t *shadow_image;
- pepper_bool_t use_shadow;
+ void *frame_buffer_pixels;
+ pixman_image_t *frame_buffer_image;
+ pixman_image_t *shadow_image;
+ pepper_bool_t use_shadow;
- struct wl_event_source *frame_done_timer;
+ struct wl_event_source *frame_done_timer;
- pepper_plane_t *primary_plane;
- /* TODO */
+ pepper_plane_t *primary_plane;
+ /* TODO */
};
pepper_bool_t
static void
fbdev_debug_print_fixed_screeninfo(const struct fb_fix_screeninfo *info)
{
- printf("Framebuffer ID: %s\n", info->id);
- printf("Framebuffer type: ");
-
- switch (info->type)
- {
- case FB_TYPE_PACKED_PIXELS:
- printf("packed pixels\n");
- break;
- case FB_TYPE_PLANES:
- printf("planar (non-interleaved)\n");
- break;
- case FB_TYPE_INTERLEAVED_PLANES:
- printf("planar (interleaved)\n");
- break;
- case FB_TYPE_TEXT:
- printf("text (not a framebuffer)\n");
- break;
- case FB_TYPE_VGA_PLANES:
- printf("planar (EGA/VGA)\n");
- break;
- default:
- printf("?????\n");
- }
-
- printf("Bytes per scanline: %i\n", info->line_length);
- printf("Visual type: ");
-
- switch (info->visual)
- {
- case FB_VISUAL_TRUECOLOR:
- printf("truecolor\n");
- break;
- case FB_VISUAL_PSEUDOCOLOR:
- printf("pseudocolor\n");
- break;
- case FB_VISUAL_DIRECTCOLOR:
- printf("directcolor\n");
- break;
- case FB_VISUAL_STATIC_PSEUDOCOLOR:
- printf("fixed pseudocolor\n");
- break;
- default:
- printf("?????\n");
- }
+ printf("Framebuffer ID: %s\n", info->id);
+ printf("Framebuffer type: ");
+
+ switch (info->type) {
+ case FB_TYPE_PACKED_PIXELS:
+ printf("packed pixels\n");
+ break;
+ case FB_TYPE_PLANES:
+ printf("planar (non-interleaved)\n");
+ break;
+ case FB_TYPE_INTERLEAVED_PLANES:
+ printf("planar (interleaved)\n");
+ break;
+ case FB_TYPE_TEXT:
+ printf("text (not a framebuffer)\n");
+ break;
+ case FB_TYPE_VGA_PLANES:
+ printf("planar (EGA/VGA)\n");
+ break;
+ default:
+ printf("?????\n");
+ }
+
+ printf("Bytes per scanline: %i\n", info->line_length);
+ printf("Visual type: ");
+
+ switch (info->visual) {
+ case FB_VISUAL_TRUECOLOR:
+ printf("truecolor\n");
+ break;
+ case FB_VISUAL_PSEUDOCOLOR:
+ printf("pseudocolor\n");
+ break;
+ case FB_VISUAL_DIRECTCOLOR:
+ printf("directcolor\n");
+ break;
+ case FB_VISUAL_STATIC_PSEUDOCOLOR:
+ printf("fixed pseudocolor\n");
+ break;
+ default:
+ printf("?????\n");
+ }
}
static void
fbdev_debug_print_var_screeninfo(const struct fb_var_screeninfo *info)
{
- printf("Bits per pixel: %i\n", info->bits_per_pixel);
- printf("Resolution: %ix%i (virtual %ix%i)\n",
- info->xres, info->yres,
- info->xres_virtual, info->yres_virtual);
- printf("Scrolling offset: (%i,%i)\n",
- info->xoffset, info->yoffset);
- printf("Trans channel: %i bits at offset %i\n",
- info->transp.length, info->transp.offset);
- printf("Red channel: %i bits at offset %i\n",
- info->red.length, info->red.offset);
- printf("Green channel: %i bits at offset %i\n",
- info->red.length, info->green.offset);
- printf("Blue channel: %i bits at offset %i\n",
- info->red.length, info->blue.offset);
+ printf("Bits per pixel: %i\n", info->bits_per_pixel);
+ printf("Resolution: %ix%i (virtual %ix%i)\n",
+ info->xres, info->yres,
+ info->xres_virtual, info->yres_virtual);
+ printf("Scrolling offset: (%i,%i)\n",
+ info->xoffset, info->yoffset);
+ printf("Trans channel: %i bits at offset %i\n",
+ info->transp.length, info->transp.offset);
+ printf("Red channel: %i bits at offset %i\n",
+ info->red.length, info->red.offset);
+ printf("Green channel: %i bits at offset %i\n",
+ info->red.length, info->green.offset);
+ printf("Blue channel: %i bits at offset %i\n",
+ info->red.length, info->blue.offset);
}
static void
fbdev_output_destroy(void *o)
{
- fbdev_output_t *output = (fbdev_output_t *)o;
+ fbdev_output_t *output = (fbdev_output_t *)o;
- pepper_list_remove(&output->link);
+ pepper_list_remove(&output->link);
- if (output->frame_done_timer)
- wl_event_source_remove(output->frame_done_timer);
+ if (output->frame_done_timer)
+ wl_event_source_remove(output->frame_done_timer);
- if (output->render_target)
- pepper_render_target_destroy(output->render_target);
+ if (output->render_target)
+ pepper_render_target_destroy(output->render_target);
- if (output->shadow_image)
- pixman_image_unref(output->shadow_image);
+ if (output->shadow_image)
+ pixman_image_unref(output->shadow_image);
- if (output->frame_buffer_image)
- pixman_image_unref(output->frame_buffer_image);
+ if (output->frame_buffer_image)
+ pixman_image_unref(output->frame_buffer_image);
- if (output->frame_buffer_pixels)
- munmap(output->frame_buffer_pixels, output->h * output->stride);
+ if (output->frame_buffer_pixels)
+ munmap(output->frame_buffer_pixels, output->h * output->stride);
- free(output);
+ free(output);
}
static int32_t
fbdev_output_get_subpixel_order(void *o)
{
- fbdev_output_t *output = (fbdev_output_t *)o;
- return output->subpixel;
+ fbdev_output_t *output = (fbdev_output_t *)o;
+ return output->subpixel;
}
static const char *
fbdev_output_get_maker_name(void *o)
{
- return "PePPer FBDEV";
+ return "PePPer FBDEV";
}
static const char *
fbdev_output_get_model_name(void *o)
{
- return "PePPer FBDEV";
+ return "PePPer FBDEV";
}
static int
fbdev_output_get_mode_count(void *o)
{
- return 1;
+ return 1;
}
static void
fbdev_output_get_mode(void *o, int index, pepper_output_mode_t *mode)
{
- fbdev_output_t *output = (fbdev_output_t *)o;
+ fbdev_output_t *output = (fbdev_output_t *)o;
- if (index != 0)
- return;
+ if (index != 0)
+ return;
- mode->flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
- mode->w = output->w;
- mode->h = output->h;
- mode->refresh = 60000;
+ mode->flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
+ mode->w = output->w;
+ mode->h = output->h;
+ mode->refresh = 60000;
}
static pepper_bool_t
fbdev_output_set_mode(void *o, const pepper_output_mode_t *mode)
{
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
static void
fbdev_output_assign_planes(void *o, const pepper_list_t *view_list)
{
- fbdev_output_t *output = (fbdev_output_t *)o;
- pepper_list_t *l;
-
- pepper_list_for_each_list(l, view_list)
- {
- pepper_view_t *view = l->item;
- pepper_view_assign_plane(view, output->base, output->primary_plane);
- }
+ fbdev_output_t *output = (fbdev_output_t *)o;
+ pepper_list_t *l;
+
+ pepper_list_for_each_list(l, view_list) {
+ pepper_view_t *view = l->item;
+ pepper_view_assign_plane(view, output->base, output->primary_plane);
+ }
}
static void
fbdev_output_start_repaint_loop(void *o)
{
- fbdev_output_t *output = o;
- struct timespec ts;
+ fbdev_output_t *output = o;
+ struct timespec ts;
- pepper_compositor_get_time(output->fbdev->compositor, &ts);
- pepper_output_finish_frame(output->base, &ts);
+ pepper_compositor_get_time(output->fbdev->compositor, &ts);
+ pepper_output_finish_frame(output->base, &ts);
}
static void
fbdev_output_repaint(void *o, const pepper_list_t *plane_list)
{
- fbdev_output_t *output = (fbdev_output_t *)o;
- pepper_list_t *l;
-
- pepper_list_for_each_list(l, plane_list)
- {
- pepper_plane_t *plane = l->item;
-
- if (plane == output->primary_plane)
- {
- const pepper_list_t *render_list = pepper_plane_get_render_list(plane);
- pixman_region32_t *damage = pepper_plane_get_damage_region(plane);
-
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, damage);
- pepper_plane_clear_damage_region(plane);
-
- /* FIXME: composite with damage? */
- if (output->use_shadow)
- pixman_image_composite32(PIXMAN_OP_SRC, output->shadow_image, NULL,
- output->frame_buffer_image, 0, 0, 0, 0, 0, 0,
- output->w, output->h);
- }
- }
-
- wl_event_source_timer_update(output->frame_done_timer, 16);
+ fbdev_output_t *output = (fbdev_output_t *)o;
+ pepper_list_t *l;
+
+ pepper_list_for_each_list(l, plane_list) {
+ pepper_plane_t *plane = l->item;
+
+ if (plane == output->primary_plane) {
+ const pepper_list_t *render_list = pepper_plane_get_render_list(plane);
+ pixman_region32_t *damage = pepper_plane_get_damage_region(plane);
+
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ damage);
+ pepper_plane_clear_damage_region(plane);
+
+ /* FIXME: composite with damage? */
+ if (output->use_shadow)
+ pixman_image_composite32(PIXMAN_OP_SRC, output->shadow_image, NULL,
+ output->frame_buffer_image, 0, 0, 0, 0, 0, 0,
+ output->w, output->h);
+ }
+ }
+
+ wl_event_source_timer_update(output->frame_done_timer, 16);
}
static void
fbdev_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h)
{
- pepper_renderer_attach_surface(((fbdev_output_t *)o)->renderer, surface, w, h);
+ pepper_renderer_attach_surface(((fbdev_output_t *)o)->renderer, surface, w, h);
}
static void
-fbdev_output_flush_surface_damage(void *o, pepper_surface_t *surface, pepper_bool_t *keep_buffer)
+fbdev_output_flush_surface_damage(void *o, pepper_surface_t *surface,
+ pepper_bool_t *keep_buffer)
{
- pepper_renderer_flush_surface_damage(((fbdev_output_t *)o)->renderer, surface);
- *keep_buffer = PEPPER_TRUE;
+ pepper_renderer_flush_surface_damage(((fbdev_output_t *)o)->renderer, surface);
+ *keep_buffer = PEPPER_TRUE;
}
-struct pepper_output_backend fbdev_output_backend =
-{
- fbdev_output_destroy,
+struct pepper_output_backend fbdev_output_backend = {
+ fbdev_output_destroy,
- fbdev_output_get_subpixel_order,
- fbdev_output_get_maker_name,
- fbdev_output_get_model_name,
+ fbdev_output_get_subpixel_order,
+ fbdev_output_get_maker_name,
+ fbdev_output_get_model_name,
- fbdev_output_get_mode_count,
- fbdev_output_get_mode,
- fbdev_output_set_mode,
+ fbdev_output_get_mode_count,
+ fbdev_output_get_mode,
+ fbdev_output_set_mode,
- fbdev_output_assign_planes,
- fbdev_output_start_repaint_loop,
- fbdev_output_repaint,
- fbdev_output_attach_surface,
- fbdev_output_flush_surface_damage,
+ fbdev_output_assign_planes,
+ fbdev_output_start_repaint_loop,
+ fbdev_output_repaint,
+ fbdev_output_attach_surface,
+ fbdev_output_flush_surface_damage,
};
static pepper_bool_t
init_pixman_renderer(fbdev_output_t *output)
{
- pepper_render_target_t *target;
+ pepper_render_target_t *target;
- if (!output->fbdev->pixman_renderer)
- return PEPPER_FALSE;
+ if (!output->fbdev->pixman_renderer)
+ return PEPPER_FALSE;
- if (output->use_shadow)
- target = pepper_pixman_renderer_create_target_for_image(output->shadow_image);
- else
- target = pepper_pixman_renderer_create_target(output->format, output->frame_buffer_pixels,
- output->stride, output->w, output->h);
+ if (output->use_shadow)
+ target = pepper_pixman_renderer_create_target_for_image(output->shadow_image);
+ else
+ target = pepper_pixman_renderer_create_target(output->format,
+ output->frame_buffer_pixels,
+ output->stride, output->w, output->h);
- if (!target)
- return PEPPER_FALSE;
+ if (!target)
+ return PEPPER_FALSE;
- output->renderer = output->fbdev->pixman_renderer;
- output->render_target = target;
- pepper_renderer_set_target(output->renderer, output->render_target);
+ output->renderer = output->fbdev->pixman_renderer;
+ output->render_target = target;
+ pepper_renderer_set_target(output->renderer, output->render_target);
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_bool_t
init_renderer(fbdev_output_t *output, const char *renderer)
{
- /* Only support pixman renderer currently. */
- if (strcmp("pixman", renderer) != 0)
- return PEPPER_FALSE;
+ /* Only support pixman renderer currently. */
+ if (strcmp("pixman", renderer) != 0)
+ return PEPPER_FALSE;
- return init_pixman_renderer(output);
+ return init_pixman_renderer(output);
}
static int
-frame_done_handler(void* data)
+frame_done_handler(void *data)
{
- fbdev_output_t *output = (fbdev_output_t *)data;
- pepper_output_finish_frame(output->base, NULL);
- return 1;
+ fbdev_output_t *output = (fbdev_output_t *)data;
+ pepper_output_finish_frame(output->base, NULL);
+ return 1;
}
pepper_bool_t
pepper_fbdev_output_create(pepper_fbdev_t *fbdev, const char *renderer)
{
- fbdev_output_t *output = NULL;
- int fd;
- struct fb_fix_screeninfo fixed_info;
- struct fb_var_screeninfo var_info;
-
- struct wl_display *display;
- struct wl_event_loop *loop;
-
- /* fbdev open */
- fd = open("/dev/fb0"/*FIXME*/, O_RDWR | O_CLOEXEC);
- if (fd < 0)
- {
- PEPPER_ERROR("Failed to open fbdev in %s\n", __FUNCTION__);
- goto error;
- }
-
- if (ioctl(fd, FBIOGET_FSCREENINFO, &fixed_info) < 0)
- {
- PEPPER_ERROR("Failed to get fixed screen info in %s\n", __FUNCTION__);
- goto error;
- }
-
- fbdev_debug_print_fixed_screeninfo(&fixed_info);
-
- if (ioctl(fd, FBIOGET_VSCREENINFO, &var_info) < 0)
- {
- PEPPER_ERROR("Failed to get variable screen info in %s\n", __FUNCTION__);
- goto error;
- }
-
- fbdev_debug_print_var_screeninfo(&var_info);
-
- output = (fbdev_output_t *)calloc(1, sizeof(fbdev_output_t));
- if (!output)
- {
- PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
- goto error;
- }
-
- output->fbdev = fbdev;
- pepper_list_init(&output->link);
-
- output->format = PEPPER_FORMAT_XRGB8888;
- output->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
- output->w = var_info.xres;
- output->h = var_info.yres;
- output->bpp = var_info.bits_per_pixel;
- output->stride = output->w * (output->bpp / 8);
-
- output->frame_buffer_pixels = mmap(NULL, output->h * output->stride,
- PROT_WRITE, MAP_SHARED, fd, 0);
- if (!output->frame_buffer_pixels)
- {
- PEPPER_ERROR("mmap failed.\n");
- goto error;
- }
-
- close(fd);
-
- /* TODO: read & set output->use_shadow value from somewhere */
- output->use_shadow = PEPPER_TRUE;
- if (output->use_shadow)
- {
- pixman_format_code_t pixman_format = get_pixman_format(output->format);
-
- output->frame_buffer_image = pixman_image_create_bits(pixman_format,
- output->w, output->h,
- output->frame_buffer_pixels,
- output->stride);
- if (!output->frame_buffer_image)
- {
- PEPPER_ERROR("Failed to create pixman image in %s: pixels_image\n", __FUNCTION__);
- goto error;
- }
-
- output->shadow_image = pixman_image_create_bits(pixman_format, output->w, output->h,
- NULL, output->stride);
- if (!output->shadow_image)
- {
- PEPPER_ERROR("Failed to create pixman image in %s: shadow_image\n", __FUNCTION__);
- goto error;
- }
- }
-
- if (!init_renderer(output, renderer))
- {
- PEPPER_ERROR("Failed to initialize renderer in %s\n", __FUNCTION__);
- goto error;
- }
-
- output->base = pepper_compositor_add_output(output->fbdev->compositor,
- &fbdev_output_backend, "fbdev", output,
- WL_OUTPUT_TRANSFORM_NORMAL, 1);
- if (!output->base)
- {
- PEPPER_ERROR("Failed to add output to compositor in %s\n", __FUNCTION__);
- goto error;
- }
-
- output->primary_plane = pepper_output_add_plane(output->base, NULL);
- pepper_list_insert(&fbdev->output_list, &output->link);
-
- display = pepper_compositor_get_display(fbdev->compositor);
- loop = wl_display_get_event_loop(display);
- output->frame_done_timer = wl_event_loop_add_timer(loop, frame_done_handler, output);
-
- return PEPPER_TRUE;
+ fbdev_output_t *output = NULL;
+ int fd;
+ struct fb_fix_screeninfo fixed_info;
+ struct fb_var_screeninfo var_info;
+
+ struct wl_display *display;
+ struct wl_event_loop *loop;
+
+ /* fbdev open */
+ fd = open("/dev/fb0"/*FIXME*/, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ PEPPER_ERROR("Failed to open fbdev in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ if (ioctl(fd, FBIOGET_FSCREENINFO, &fixed_info) < 0) {
+ PEPPER_ERROR("Failed to get fixed screen info in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ fbdev_debug_print_fixed_screeninfo(&fixed_info);
+
+ if (ioctl(fd, FBIOGET_VSCREENINFO, &var_info) < 0) {
+ PEPPER_ERROR("Failed to get variable screen info in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ fbdev_debug_print_var_screeninfo(&var_info);
+
+ output = (fbdev_output_t *)calloc(1, sizeof(fbdev_output_t));
+ if (!output) {
+ PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ output->fbdev = fbdev;
+ pepper_list_init(&output->link);
+
+ output->format = PEPPER_FORMAT_XRGB8888;
+ output->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
+ output->w = var_info.xres;
+ output->h = var_info.yres;
+ output->bpp = var_info.bits_per_pixel;
+ output->stride = output->w * (output->bpp / 8);
+
+ output->frame_buffer_pixels = mmap(NULL, output->h * output->stride,
+ PROT_WRITE, MAP_SHARED, fd, 0);
+ if (!output->frame_buffer_pixels) {
+ PEPPER_ERROR("mmap failed.\n");
+ goto error;
+ }
+
+ close(fd);
+
+ /* TODO: read & set output->use_shadow value from somewhere */
+ output->use_shadow = PEPPER_TRUE;
+ if (output->use_shadow) {
+ pixman_format_code_t pixman_format = get_pixman_format(output->format);
+
+ output->frame_buffer_image = pixman_image_create_bits(pixman_format,
+ output->w, output->h,
+ output->frame_buffer_pixels,
+ output->stride);
+ if (!output->frame_buffer_image) {
+ PEPPER_ERROR("Failed to create pixman image in %s: pixels_image\n",
+ __FUNCTION__);
+ goto error;
+ }
+
+ output->shadow_image = pixman_image_create_bits(pixman_format, output->w,
+ output->h,
+ NULL, output->stride);
+ if (!output->shadow_image) {
+ PEPPER_ERROR("Failed to create pixman image in %s: shadow_image\n",
+ __FUNCTION__);
+ goto error;
+ }
+ }
+
+ if (!init_renderer(output, renderer)) {
+ PEPPER_ERROR("Failed to initialize renderer in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ output->base = pepper_compositor_add_output(output->fbdev->compositor,
+ &fbdev_output_backend, "fbdev", output,
+ WL_OUTPUT_TRANSFORM_NORMAL, 1);
+ if (!output->base) {
+ PEPPER_ERROR("Failed to add output to compositor in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ output->primary_plane = pepper_output_add_plane(output->base, NULL);
+ pepper_list_insert(&fbdev->output_list, &output->link);
+
+ display = pepper_compositor_get_display(fbdev->compositor);
+ loop = wl_display_get_event_loop(display);
+ output->frame_done_timer = wl_event_loop_add_timer(loop, frame_done_handler,
+ output);
+
+ return PEPPER_TRUE;
error:
- if (output)
- pepper_fbdev_output_destroy(output);
+ if (output)
+ pepper_fbdev_output_destroy(output);
- if (fd >= 0)
- close(fd);
+ if (fd >= 0)
+ close(fd);
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
void
pepper_fbdev_output_destroy(fbdev_output_t *output)
{
- fbdev_output_destroy(output);
+ fbdev_output_destroy(output);
}
PEPPER_API pepper_fbdev_t *
pepper_fbdev_create(pepper_compositor_t *compositor, struct udev *udev,
- const char *device, const char *renderer);
+ const char *device, const char *renderer);
PEPPER_API void
pepper_fbdev_destroy(pepper_fbdev_t *fbdev);
typedef struct li_device li_device_t;
typedef struct li_device_property li_device_property_t;
-struct pepper_libinput
-{
- pepper_compositor_t *compositor;
- struct udev *udev;
- struct libinput *libinput;
- struct wl_event_source *libinput_event_source;
- int libinput_fd;
+struct pepper_libinput {
+ pepper_compositor_t *compositor;
+ struct udev *udev;
+ struct libinput *libinput;
+ struct wl_event_source *libinput_event_source;
+ int libinput_fd;
- pepper_list_t device_list;
+ pepper_list_t device_list;
};
-struct li_device
-{
- pepper_libinput_t *input;
- pepper_input_device_t *base;
+struct li_device {
+ pepper_libinput_t *input;
+ pepper_input_device_t *base;
- uint32_t caps;
+ uint32_t caps;
- pepper_list_t property_list;
- pepper_list_t link;
+ pepper_list_t property_list;
+ pepper_list_t link;
};
-struct li_device_property /* FIXME */
-{
- char *key;
- char *data;
- pepper_list_t link;
+struct li_device_property { /* FIXME */
+ char *key;
+ char *data;
+ pepper_list_t link;
};
#endif /* LIBINPUT_INTERNAL_H */
static int
libinput_open_restricted(const char *path, int flags, void *user_data)
{
- int fd;
- struct stat s;
-
- fd = open(path, flags | O_CLOEXEC);
- if (fd < 0)
- {
- PEPPER_ERROR("Failed to open file[%s] in %s\n", path, __FUNCTION__);
- return -1;
- }
-
- if (fstat(fd, &s) < 0)
- {
- PEPPER_ERROR("Failed to get file[%s] status in %s\n", path, __FUNCTION__);
- close(fd);
- return -1;
- }
-
- return fd;
+ int fd;
+ struct stat s;
+
+ fd = open(path, flags | O_CLOEXEC);
+ if (fd < 0) {
+ PEPPER_ERROR("Failed to open file[%s] in %s\n", path, __FUNCTION__);
+ return -1;
+ }
+
+ if (fstat(fd, &s) < 0) {
+ PEPPER_ERROR("Failed to get file[%s] status in %s\n", path, __FUNCTION__);
+ close(fd);
+ return -1;
+ }
+
+ return fd;
}
static void
libinput_close_restricted(int fd, void *user_data)
{
- close(fd);
+ close(fd);
}
-const struct libinput_interface libinput_interface =
-{
- libinput_open_restricted,
- libinput_close_restricted,
+const struct libinput_interface libinput_interface = {
+ libinput_open_restricted,
+ libinput_close_restricted,
};
static uint32_t
get_capabilities(struct libinput_device *device)
{
- uint32_t caps = 0;
+ uint32_t caps = 0;
- if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
- caps |= WL_SEAT_CAPABILITY_POINTER;
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
+ caps |= WL_SEAT_CAPABILITY_POINTER;
- if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
- caps |= WL_SEAT_CAPABILITY_KEYBOARD;
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
+ caps |= WL_SEAT_CAPABILITY_KEYBOARD;
- if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
- caps |= WL_SEAT_CAPABILITY_TOUCH;
+ if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
+ caps |= WL_SEAT_CAPABILITY_TOUCH;
- return caps;
+ return caps;
}
static void
libinput_device_get_properties(struct libinput_device *libinput_device,
- pepper_list_t *property_list)
+ pepper_list_t *property_list)
{
- /* get properties */
- struct udev_device *udev_device = libinput_device_get_udev_device(libinput_device);
- struct udev_list_entry *e;
+ /* get properties */
+ struct udev_device *udev_device = libinput_device_get_udev_device(
+ libinput_device);
+ struct udev_list_entry *e;
- e = udev_device_get_properties_list_entry(udev_device);
+ e = udev_device_get_properties_list_entry(udev_device);
- while (e)
- {
- li_device_property_t *property;
- const char *name = udev_list_entry_get_name(e);
- const char *value = udev_list_entry_get_value(e);
+ while (e) {
+ li_device_property_t *property;
+ const char *name = udev_list_entry_get_name(e);
+ const char *value = udev_list_entry_get_value(e);
- property = (li_device_property_t *)calloc(1, sizeof(li_device_property_t));
- if (!property)
- continue;
+ property = (li_device_property_t *)calloc(1, sizeof(li_device_property_t));
+ if (!property)
+ continue;
- property->key = strdup(name);
- property->data = strdup(value);
+ property->key = strdup(name);
+ property->data = strdup(value);
- pepper_list_insert(property_list, &property->link);
- e = udev_list_entry_get_next(e);
- }
+ pepper_list_insert(property_list, &property->link);
+ e = udev_list_entry_get_next(e);
+ }
}
static const char *
li_device_get_property(void *dev, const char *key)
{
- li_device_t *device = (li_device_t *)dev;
- li_device_property_t *property;
+ li_device_t *device = (li_device_t *)dev;
+ li_device_property_t *property;
- pepper_list_for_each(property, &device->property_list, link)
- {
- if (!strcmp(property->key, key))
- return property->data;
- }
+ pepper_list_for_each(property, &device->property_list, link) {
+ if (!strcmp(property->key, key))
+ return property->data;
+ }
- return NULL;
+ return NULL;
}
-static const pepper_input_device_backend_t li_device_backend =
-{
- li_device_get_property,
+static const pepper_input_device_backend_t li_device_backend = {
+ li_device_get_property,
};
static void
device_added(pepper_libinput_t *input, struct libinput_device *libinput_device)
{
- pepper_list_t property_list;
- uint32_t caps;
- li_device_t *device;
-
- caps = get_capabilities(libinput_device);
- device = (li_device_t *)calloc(1, sizeof(li_device_t));
- if (!device)
- {
- PEPPER_ERROR("Failed to allocate memory\n");
- /* TODO: error handling */
- return;
- }
-
- device->input = input;
- device->caps = caps;
-
- device->base = pepper_input_device_create(input->compositor, caps,
- &li_device_backend, device);
- if (!device->base)
- {
- PEPPER_ERROR("Failed to create pepper input device\n");
- /* TODO: error handling */
- return;
- }
-
- pepper_list_init(&property_list); /* FIXME */
- libinput_device_get_properties(libinput_device, &property_list); /* FIXME */
- pepper_list_init(&device->property_list); /* FIXME */
- pepper_list_insert_list(&device->property_list, &property_list); /* FIXME */
-
- pepper_list_insert(&input->device_list, &device->link);
- libinput_device_set_user_data(libinput_device, device);
+ pepper_list_t property_list;
+ uint32_t caps;
+ li_device_t *device;
+
+ caps = get_capabilities(libinput_device);
+ device = (li_device_t *)calloc(1, sizeof(li_device_t));
+ if (!device) {
+ PEPPER_ERROR("Failed to allocate memory\n");
+ /* TODO: error handling */
+ return;
+ }
+
+ device->input = input;
+ device->caps = caps;
+
+ device->base = pepper_input_device_create(input->compositor, caps,
+ &li_device_backend, device);
+ if (!device->base) {
+ PEPPER_ERROR("Failed to create pepper input device\n");
+ /* TODO: error handling */
+ return;
+ }
+
+ pepper_list_init(&property_list); /* FIXME */
+ libinput_device_get_properties(libinput_device, &property_list); /* FIXME */
+ pepper_list_init(&device->property_list); /* FIXME */
+ pepper_list_insert_list(&device->property_list, &property_list); /* FIXME */
+
+ pepper_list_insert(&input->device_list, &device->link);
+ libinput_device_set_user_data(libinput_device, device);
}
static void
clear_property_list(pepper_list_t *list)
{
- li_device_property_t *property, *tmp;
+ li_device_property_t *property, *tmp;
- if (pepper_list_empty(list))
- return;
+ if (pepper_list_empty(list))
+ return;
- pepper_list_for_each_safe(property, tmp, list, link)
- {
- pepper_list_remove(&property->link);
+ pepper_list_for_each_safe(property, tmp, list, link) {
+ pepper_list_remove(&property->link);
- if (property->key)
- free(property->key);
- if (property->data)
- free(property->data);
+ if (property->key)
+ free(property->key);
+ if (property->data)
+ free(property->data);
- free(property);
- }
+ free(property);
+ }
}
static void
li_device_destroy(li_device_t *device)
{
- pepper_list_remove(&device->link);
- clear_property_list(&device->property_list);
+ pepper_list_remove(&device->link);
+ clear_property_list(&device->property_list);
- if (device->base)
- pepper_input_device_destroy(device->base);
+ if (device->base)
+ pepper_input_device_destroy(device->base);
- free(device);
+ free(device);
}
static void
-device_removed(pepper_libinput_t *input, struct libinput_device *libinput_device)
+device_removed(pepper_libinput_t *input,
+ struct libinput_device *libinput_device)
{
- li_device_t *device;
- device = (li_device_t *)libinput_device_get_user_data(libinput_device);
- li_device_destroy(device);
+ li_device_t *device;
+ device = (li_device_t *)libinput_device_get_user_data(libinput_device);
+ li_device_destroy(device);
}
static void
pointer_motion(struct libinput_device *libinput_device,
- struct libinput_event_pointer *pointer_event)
+ struct libinput_event_pointer *pointer_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
- event.time = libinput_event_pointer_get_time(pointer_event);
- event.x = libinput_event_pointer_get_dx(pointer_event);
- event.y = libinput_event_pointer_get_dy(pointer_event);
+ event.time = libinput_event_pointer_get_time(pointer_event);
+ event.x = libinput_event_pointer_get_dx(pointer_event);
+ event.y = libinput_event_pointer_get_dy(pointer_event);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION, &event);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION, &event);
}
static void
pointer_motion_absolute(struct libinput_device *libinput_device,
- struct libinput_event_pointer *pointer_event)
+ struct libinput_event_pointer *pointer_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
- event.time = libinput_event_pointer_get_time(pointer_event);
- event.x = libinput_event_pointer_get_absolute_x_transformed(pointer_event, 1);
- event.y = libinput_event_pointer_get_absolute_y_transformed(pointer_event, 1);
+ event.time = libinput_event_pointer_get_time(pointer_event);
+ event.x = libinput_event_pointer_get_absolute_x_transformed(pointer_event, 1);
+ event.y = libinput_event_pointer_get_absolute_y_transformed(pointer_event, 1);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE, &event);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE, &event);
}
static void
pointer_button(struct libinput_device *libinput_device,
- struct libinput_event_pointer *pointer_event)
+ struct libinput_event_pointer *pointer_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
- event.time = libinput_event_pointer_get_time(pointer_event);
- event.button = libinput_event_pointer_get_button(pointer_event);
- event.state = libinput_event_pointer_get_button_state(pointer_event);
+ event.time = libinput_event_pointer_get_time(pointer_event);
+ event.button = libinput_event_pointer_get_button(pointer_event);
+ event.state = libinput_event_pointer_get_button_state(pointer_event);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON, &event);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON, &event);
}
static void
pointer_axis(struct libinput_device *libinput_device,
- struct libinput_event_pointer *pointer_event)
+ struct libinput_event_pointer *pointer_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
-
- event.time = libinput_event_pointer_get_time(pointer_event);
-
- if (libinput_event_pointer_has_axis(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
- {
- event.axis = PEPPER_POINTER_AXIS_VERTICAL;
- event.value = libinput_event_pointer_get_axis_value(pointer_event,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS, &event);
- }
- else if (libinput_event_pointer_has_axis(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
- {
- event.axis = PEPPER_POINTER_AXIS_HORIZONTAL;
- event.value = libinput_event_pointer_get_axis_value(pointer_event,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS, &event);
- }
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
+
+ event.time = libinput_event_pointer_get_time(pointer_event);
+
+ if (libinput_event_pointer_has_axis(pointer_event,
+ LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
+ event.axis = PEPPER_POINTER_AXIS_VERTICAL;
+ event.value = libinput_event_pointer_get_axis_value(pointer_event,
+ LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS, &event);
+ } else if (libinput_event_pointer_has_axis(pointer_event,
+ LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
+ event.axis = PEPPER_POINTER_AXIS_HORIZONTAL;
+ event.value = libinput_event_pointer_get_axis_value(pointer_event,
+ LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS, &event);
+ }
}
static void
keyboard_key(struct libinput_device *libinput_device,
- struct libinput_event_keyboard *keyboard_event)
+ struct libinput_event_keyboard *keyboard_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
- event.time = libinput_event_keyboard_get_time(keyboard_event);
- event.key = libinput_event_keyboard_get_key(keyboard_event);
+ event.time = libinput_event_keyboard_get_time(keyboard_event);
+ event.key = libinput_event_keyboard_get_key(keyboard_event);
- if (libinput_event_keyboard_get_key_state(keyboard_event) == LIBINPUT_KEY_STATE_RELEASED)
- event.state = PEPPER_KEY_STATE_RELEASED;
- else
- event.state = PEPPER_KEY_STATE_PRESSED;
+ if (libinput_event_keyboard_get_key_state(keyboard_event) ==
+ LIBINPUT_KEY_STATE_RELEASED)
+ event.state = PEPPER_KEY_STATE_RELEASED;
+ else
+ event.state = PEPPER_KEY_STATE_PRESSED;
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY, &event);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY, &event);
}
static void
touch_down(struct libinput_device *libinput_device,
- struct libinput_event_touch *touch_event)
+ struct libinput_event_touch *touch_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
- event.time = libinput_event_touch_get_time(touch_event);
- event.slot = libinput_event_touch_get_seat_slot(touch_event);
- event.x = libinput_event_touch_get_x_transformed(touch_event, 1);
- event.y = libinput_event_touch_get_y_transformed(touch_event, 1);
+ event.time = libinput_event_touch_get_time(touch_event);
+ event.slot = libinput_event_touch_get_seat_slot(touch_event);
+ event.x = libinput_event_touch_get_x_transformed(touch_event, 1);
+ event.y = libinput_event_touch_get_y_transformed(touch_event, 1);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_DOWN, &event);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_DOWN, &event);
}
static void
touch_up(struct libinput_device *libinput_device,
- struct libinput_event_touch *touch_event)
+ struct libinput_event_touch *touch_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
- event.time = libinput_event_touch_get_time(touch_event);
- event.slot = libinput_event_touch_get_seat_slot(touch_event);
+ event.time = libinput_event_touch_get_time(touch_event);
+ event.slot = libinput_event_touch_get_seat_slot(touch_event);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_UP, &event);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_UP, &event);
}
static void
touch_motion(struct libinput_device *libinput_device,
- struct libinput_event_touch *touch_event)
+ struct libinput_event_touch *touch_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_input_event_t event;
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_input_event_t event;
- event.time = libinput_event_touch_get_time(touch_event);
- event.slot = libinput_event_touch_get_seat_slot(touch_event);
- event.x = libinput_event_touch_get_x_transformed(touch_event, 1);
- event.y = libinput_event_touch_get_y_transformed(touch_event, 1);
+ event.time = libinput_event_touch_get_time(touch_event);
+ event.slot = libinput_event_touch_get_seat_slot(touch_event);
+ event.x = libinput_event_touch_get_x_transformed(touch_event, 1);
+ event.y = libinput_event_touch_get_y_transformed(touch_event, 1);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_MOTION, &event);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_MOTION, &event);
}
static void
touch_frame(struct libinput_device *libinput_device,
- struct libinput_event_touch *touch_event)
+ struct libinput_event_touch *touch_event)
{
- li_device_t *device = libinput_device_get_user_data(libinput_device);
- pepper_object_emit_event((pepper_object_t *)device->base,
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_FRAME, NULL);
+ li_device_t *device = libinput_device_get_user_data(libinput_device);
+ pepper_object_emit_event((pepper_object_t *)device->base,
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_FRAME, NULL);
}
static void
dispatch_event(struct libinput_event *event)
{
- struct libinput *libinput = libinput_event_get_context(event);
- struct libinput_device *libinput_device = libinput_event_get_device(event);
-
- switch (libinput_event_get_type(event))
- {
- case LIBINPUT_EVENT_DEVICE_ADDED:
- device_added((pepper_libinput_t *)libinput_get_user_data(libinput), libinput_device);
- break;
- case LIBINPUT_EVENT_DEVICE_REMOVED:
- device_removed((pepper_libinput_t *)libinput_get_user_data(libinput), libinput_device);
- break;
- case LIBINPUT_EVENT_POINTER_MOTION:
- pointer_motion(libinput_device, libinput_event_get_pointer_event(event));
- break;
- case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
- pointer_motion_absolute(libinput_device, libinput_event_get_pointer_event(event));
- break;
- case LIBINPUT_EVENT_POINTER_BUTTON:
- pointer_button(libinput_device, libinput_event_get_pointer_event(event));
- break;
- case LIBINPUT_EVENT_POINTER_AXIS:
- pointer_axis(libinput_device, libinput_event_get_pointer_event(event));
- break;
- case LIBINPUT_EVENT_KEYBOARD_KEY:
- keyboard_key(libinput_device, libinput_event_get_keyboard_event(event));
- break;
- case LIBINPUT_EVENT_TOUCH_DOWN:
- touch_down(libinput_device, libinput_event_get_touch_event(event));
- break;
- case LIBINPUT_EVENT_TOUCH_UP:
- touch_up(libinput_device, libinput_event_get_touch_event(event));
- break;
- case LIBINPUT_EVENT_TOUCH_MOTION:
- touch_motion(libinput_device, libinput_event_get_touch_event(event));
- break;
- case LIBINPUT_EVENT_TOUCH_FRAME:
- touch_frame(libinput_device, libinput_event_get_touch_event(event));
- break;
- default:
- break;
- }
+ struct libinput *libinput = libinput_event_get_context(event);
+ struct libinput_device *libinput_device = libinput_event_get_device(event);
+
+ switch (libinput_event_get_type(event)) {
+ case LIBINPUT_EVENT_DEVICE_ADDED:
+ device_added((pepper_libinput_t *)libinput_get_user_data(libinput),
+ libinput_device);
+ break;
+ case LIBINPUT_EVENT_DEVICE_REMOVED:
+ device_removed((pepper_libinput_t *)libinput_get_user_data(libinput),
+ libinput_device);
+ break;
+ case LIBINPUT_EVENT_POINTER_MOTION:
+ pointer_motion(libinput_device, libinput_event_get_pointer_event(event));
+ break;
+ case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
+ pointer_motion_absolute(libinput_device,
+ libinput_event_get_pointer_event(event));
+ break;
+ case LIBINPUT_EVENT_POINTER_BUTTON:
+ pointer_button(libinput_device, libinput_event_get_pointer_event(event));
+ break;
+ case LIBINPUT_EVENT_POINTER_AXIS:
+ pointer_axis(libinput_device, libinput_event_get_pointer_event(event));
+ break;
+ case LIBINPUT_EVENT_KEYBOARD_KEY:
+ keyboard_key(libinput_device, libinput_event_get_keyboard_event(event));
+ break;
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ touch_down(libinput_device, libinput_event_get_touch_event(event));
+ break;
+ case LIBINPUT_EVENT_TOUCH_UP:
+ touch_up(libinput_device, libinput_event_get_touch_event(event));
+ break;
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ touch_motion(libinput_device, libinput_event_get_touch_event(event));
+ break;
+ case LIBINPUT_EVENT_TOUCH_FRAME:
+ touch_frame(libinput_device, libinput_event_get_touch_event(event));
+ break;
+ default:
+ break;
+ }
}
static int
dispatch_events(pepper_libinput_t *input)
{
- struct libinput_event *event;
+ struct libinput_event *event;
- if (libinput_dispatch(input->libinput) != 0)
- {
- PEPPER_ERROR("Failed to dispatch libinput events in %s\n", __FUNCTION__);
- return -1;
- }
+ if (libinput_dispatch(input->libinput) != 0) {
+ PEPPER_ERROR("Failed to dispatch libinput events in %s\n", __FUNCTION__);
+ return -1;
+ }
- while ((event = libinput_get_event(input->libinput)))
- {
- dispatch_event(event);
- libinput_event_destroy(event);
- }
+ while ((event = libinput_get_event(input->libinput))) {
+ dispatch_event(event);
+ libinput_event_destroy(event);
+ }
- return 0;
+ return 0;
}
static int
handle_libinput_events(int fd, uint32_t mask, void *data)
{
- pepper_libinput_t *input = (pepper_libinput_t *)data;
- return dispatch_events(input);
+ pepper_libinput_t *input = (pepper_libinput_t *)data;
+ return dispatch_events(input);
}
PEPPER_API pepper_libinput_t *
pepper_libinput_create(pepper_compositor_t *compositor, struct udev *udev)
{
- struct wl_display *display;
- struct wl_event_loop *loop;
- pepper_libinput_t *input;
-
- input = (pepper_libinput_t *)calloc(1, sizeof(pepper_libinput_t));
- if (!input)
- {
- PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
- goto error;
- }
-
- input->compositor = compositor;
- input->udev = udev;
- pepper_list_init(&input->device_list);
-
- input->libinput = libinput_udev_create_context(&libinput_interface, input, input->udev);
- if (!input->libinput)
- {
- PEPPER_ERROR("Failed to initialize libinput in %s\n", __FUNCTION__);
- goto error;
- }
-
- if (libinput_udev_assign_seat(input->libinput, "seat0"/* FIXME */) != 0)
- {
- PEPPER_ERROR("Failed to assign seat in %s\n", __FUNCTION__);
- goto error;
- }
-
- dispatch_events(input); /* FIXME */
-
- /* add libinput_fd to main loop */
- display = pepper_compositor_get_display(compositor);
- loop = wl_display_get_event_loop(display);
- input->libinput_fd = libinput_get_fd(input->libinput);
- input->libinput_event_source = wl_event_loop_add_fd(loop, input->libinput_fd,
- WL_EVENT_READABLE,
- handle_libinput_events, input);
- if (!input->libinput_event_source)
- {
- PEPPER_ERROR("Failed to add libinput fd to the main loop in %s\n", __FUNCTION__);
- goto error;
- }
-
- return input;
+ struct wl_display *display;
+ struct wl_event_loop *loop;
+ pepper_libinput_t *input;
+
+ input = (pepper_libinput_t *)calloc(1, sizeof(pepper_libinput_t));
+ if (!input) {
+ PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ input->compositor = compositor;
+ input->udev = udev;
+ pepper_list_init(&input->device_list);
+
+ input->libinput = libinput_udev_create_context(&libinput_interface, input,
+ input->udev);
+ if (!input->libinput) {
+ PEPPER_ERROR("Failed to initialize libinput in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ if (libinput_udev_assign_seat(input->libinput, "seat0"/* FIXME */) != 0) {
+ PEPPER_ERROR("Failed to assign seat in %s\n", __FUNCTION__);
+ goto error;
+ }
+
+ dispatch_events(input); /* FIXME */
+
+ /* add libinput_fd to main loop */
+ display = pepper_compositor_get_display(compositor);
+ loop = wl_display_get_event_loop(display);
+ input->libinput_fd = libinput_get_fd(input->libinput);
+ input->libinput_event_source = wl_event_loop_add_fd(loop, input->libinput_fd,
+ WL_EVENT_READABLE,
+ handle_libinput_events, input);
+ if (!input->libinput_event_source) {
+ PEPPER_ERROR("Failed to add libinput fd to the main loop in %s\n",
+ __FUNCTION__);
+ goto error;
+ }
+
+ return input;
error:
- if (input)
- pepper_libinput_destroy(input);
+ if (input)
+ pepper_libinput_destroy(input);
- return NULL;
+ return NULL;
}
PEPPER_API void
pepper_libinput_destroy(pepper_libinput_t *input)
{
- li_device_t *device, *tmp;
+ li_device_t *device, *tmp;
- pepper_list_for_each_safe(device, tmp, &input->device_list, link)
- li_device_destroy(device);
+ pepper_list_for_each_safe(device, tmp, &input->device_list, link)
+ li_device_destroy(device);
- if (input->libinput)
- libinput_unref(input->libinput);
+ if (input->libinput)
+ libinput_unref(input->libinput);
- if (input->libinput_event_source)
- wl_event_source_remove(input->libinput_event_source);
+ if (input->libinput_event_source)
+ wl_event_source_remove(input->libinput_event_source);
- free(input);
+ free(input);
}
static void
buffer_resource_destroy_handler(struct wl_listener *listener, void *data)
{
- pepper_buffer_t *buffer = pepper_container_of(listener, buffer, resource_destroy_listener);
- pepper_object_fini(&buffer->base);
- free(buffer);
+ pepper_buffer_t *buffer = pepper_container_of(listener, buffer,
+ resource_destroy_listener);
+ pepper_object_fini(&buffer->base);
+ free(buffer);
}
pepper_buffer_t *
pepper_buffer_from_resource(struct wl_resource *resource)
{
- pepper_buffer_t *buffer;
- struct wl_listener *listener;
+ pepper_buffer_t *buffer;
+ struct wl_listener *listener;
- listener = wl_resource_get_destroy_listener(resource, buffer_resource_destroy_handler);
+ listener = wl_resource_get_destroy_listener(resource,
+ buffer_resource_destroy_handler);
- if (listener)
- return pepper_container_of(listener, buffer, resource_destroy_listener);
+ if (listener)
+ return pepper_container_of(listener, buffer, resource_destroy_listener);
- buffer = (pepper_buffer_t *)pepper_object_alloc(PEPPER_OBJECT_BUFFER, sizeof(pepper_buffer_t));
- PEPPER_CHECK(buffer, return NULL, "pepper_object_alloc() failed.\n");
+ buffer = (pepper_buffer_t *)pepper_object_alloc(PEPPER_OBJECT_BUFFER,
+ sizeof(pepper_buffer_t));
+ PEPPER_CHECK(buffer, return NULL, "pepper_object_alloc() failed.\n");
- buffer->resource = resource;
- buffer->resource_destroy_listener.notify = buffer_resource_destroy_handler;
- wl_resource_add_destroy_listener(resource, &buffer->resource_destroy_listener);
+ buffer->resource = resource;
+ buffer->resource_destroy_listener.notify = buffer_resource_destroy_handler;
+ wl_resource_add_destroy_listener(resource, &buffer->resource_destroy_listener);
- return buffer;
+ return buffer;
}
/**
PEPPER_API void
pepper_buffer_reference(pepper_buffer_t *buffer)
{
- PEPPER_ASSERT(buffer->ref_count >= 0);
- buffer->ref_count++;
+ PEPPER_ASSERT(buffer->ref_count >= 0);
+ buffer->ref_count++;
}
/**
PEPPER_API void
pepper_buffer_unreference(pepper_buffer_t *buffer)
{
- PEPPER_ASSERT(buffer->ref_count > 0);
+ PEPPER_ASSERT(buffer->ref_count > 0);
- if (--buffer->ref_count == 0)
- {
- wl_resource_queue_event(buffer->resource, WL_BUFFER_RELEASE);
- pepper_object_emit_event(&buffer->base, PEPPER_EVENT_BUFFER_RELEASE, NULL);
- }
+ if (--buffer->ref_count == 0) {
+ wl_resource_queue_event(buffer->resource, WL_BUFFER_RELEASE);
+ pepper_object_emit_event(&buffer->base, PEPPER_EVENT_BUFFER_RELEASE, NULL);
+ }
}
/**
PEPPER_API struct wl_resource *
pepper_buffer_get_resource(pepper_buffer_t *buffer)
{
- return buffer->resource;
+ return buffer->resource;
}
/**
PEPPER_API pepper_bool_t
pepper_buffer_get_size(pepper_buffer_t *buffer, int *w, int *h)
{
- if (buffer->attached)
- {
- if (w)
- *w = buffer->w;
+ if (buffer->attached) {
+ if (w)
+ *w = buffer->w;
- if (h)
- *h = buffer->h;
+ if (h)
+ *h = buffer->h;
- return PEPPER_TRUE;
- }
+ return PEPPER_TRUE;
+ }
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
static void
compositor_create_surface(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id)
+ struct wl_resource *resource,
+ uint32_t id)
{
- pepper_compositor_t *compositor = wl_resource_get_user_data(resource);
+ pepper_compositor_t *compositor = wl_resource_get_user_data(resource);
- if (!pepper_surface_create(compositor, client, resource, id))
- wl_resource_post_no_memory(resource);
+ if (!pepper_surface_create(compositor, client, resource, id))
+ wl_resource_post_no_memory(resource);
}
static void
compositor_create_region(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id)
+ struct wl_resource *resource,
+ uint32_t id)
{
- pepper_compositor_t *compositor = wl_resource_get_user_data(resource);
+ pepper_compositor_t *compositor = wl_resource_get_user_data(resource);
- if (!pepper_region_create(compositor, client, resource, id))
- wl_resource_post_no_memory(resource);
+ if (!pepper_region_create(compositor, client, resource, id))
+ wl_resource_post_no_memory(resource);
}
-static const struct wl_compositor_interface compositor_interface =
-{
- compositor_create_surface,
- compositor_create_region
+static const struct wl_compositor_interface compositor_interface = {
+ compositor_create_surface,
+ compositor_create_region
};
static void
unbind_resource(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
static void
compositor_bind(struct wl_client *client,
- void *data,
- uint32_t version,
- uint32_t id)
+ void *data,
+ uint32_t version,
+ uint32_t id)
{
- pepper_compositor_t *compositor = (pepper_compositor_t *)data;
- struct wl_resource *resource;
+ pepper_compositor_t *compositor = (pepper_compositor_t *)data;
+ struct wl_resource *resource;
- resource = wl_resource_create(client, &wl_compositor_interface, version, id);
+ resource = wl_resource_create(client, &wl_compositor_interface, version, id);
- if (!resource)
- {
- PEPPER_ERROR("wl_resource_create failed\n");
- wl_client_post_no_memory(client);
- return;
- }
+ if (!resource) {
+ PEPPER_ERROR("wl_resource_create failed\n");
+ wl_client_post_no_memory(client);
+ return;
+ }
- wl_list_insert(&compositor->resource_list, wl_resource_get_link(resource));
- wl_resource_set_implementation(resource, &compositor_interface, compositor, unbind_resource);
+ wl_list_insert(&compositor->resource_list, wl_resource_get_link(resource));
+ wl_resource_set_implementation(resource, &compositor_interface, compositor,
+ unbind_resource);
}
static pepper_bool_t
-compositor_bind_socket(pepper_compositor_t *compositor, int socket_fd, const char *name)
+compositor_bind_socket(pepper_compositor_t *compositor, int socket_fd,
+ const char *name)
{
- struct stat buf;
- socklen_t size, name_size;
- const char *runtime_dir;
- long flags;
-
- if (socket_fd < 0 || fstat(socket_fd, &buf) < 0 || !S_ISSOCK(buf.st_mode))
- return PEPPER_FALSE;
-
- flags = fcntl(socket_fd, F_GETFD);
- PEPPER_CHECK((-1 != flags), return PEPPER_FALSE, "fcntl(F_GETFD) failed\n");
-
- PEPPER_CHECK((-1 != fcntl(socket_fd, F_SETFD, flags | FD_CLOEXEC)), return PEPPER_FALSE,
- "fcntl(F_SETFD) failed\n");
-
- runtime_dir = getenv("XDG_RUNTIME_DIR");
- if (!runtime_dir) {
- PEPPER_ERROR("XDG_RUNTIME_DIR not set in the environment\n");
- return PEPPER_FALSE;
- }
-
- compositor->addr.sun_family = AF_LOCAL;
- name_size = snprintf(compositor->addr.sun_path, sizeof compositor->addr.sun_path,
- "%s/%s", runtime_dir, name) + 1;
- if (name_size > (int)sizeof(compositor->addr.sun_path))
- {
- PEPPER_ERROR("socket path \"%s/%s\" plus null terminator"
- " exceeds 108 bytes\n", runtime_dir, name);
- return PEPPER_FALSE;
- }
-
- size = offsetof(struct sockaddr_un, sun_path) + name_size;
- if (bind(socket_fd, (struct sockaddr *) &compositor->addr, size) < 0)
- {
- PEPPER_ERROR("failed to bind to %s: %m\n", compositor->addr.sun_path);
- close(socket_fd);
- return PEPPER_FALSE;
- }
-
- if (listen(socket_fd, 1) < 0) {
- close(socket_fd);
- return PEPPER_FALSE;
- }
-
- return PEPPER_TRUE;
+ struct stat buf;
+ socklen_t size, name_size;
+ const char *runtime_dir;
+ long flags;
+
+ if (socket_fd < 0 || fstat(socket_fd, &buf) < 0 || !S_ISSOCK(buf.st_mode))
+ return PEPPER_FALSE;
+
+ flags = fcntl(socket_fd, F_GETFD);
+ PEPPER_CHECK((-1 != flags), return PEPPER_FALSE, "fcntl(F_GETFD) failed\n");
+
+ PEPPER_CHECK((-1 != fcntl(socket_fd, F_SETFD, flags | FD_CLOEXEC)),
+ return PEPPER_FALSE,
+ "fcntl(F_SETFD) failed\n");
+
+ runtime_dir = getenv("XDG_RUNTIME_DIR");
+ if (!runtime_dir) {
+ PEPPER_ERROR("XDG_RUNTIME_DIR not set in the environment\n");
+ return PEPPER_FALSE;
+ }
+
+ compositor->addr.sun_family = AF_LOCAL;
+ name_size = snprintf(compositor->addr.sun_path,
+ sizeof compositor->addr.sun_path,
+ "%s/%s", runtime_dir, name) + 1;
+ if (name_size > (int)sizeof(compositor->addr.sun_path)) {
+ PEPPER_ERROR("socket path \"%s/%s\" plus null terminator"
+ " exceeds 108 bytes\n", runtime_dir, name);
+ return PEPPER_FALSE;
+ }
+
+ size = offsetof(struct sockaddr_un, sun_path) + name_size;
+ if (bind(socket_fd, (struct sockaddr *) &compositor->addr, size) < 0) {
+ PEPPER_ERROR("failed to bind to %s: %m\n", compositor->addr.sun_path);
+ close(socket_fd);
+ return PEPPER_FALSE;
+ }
+
+ if (listen(socket_fd, 1) < 0) {
+ close(socket_fd);
+ return PEPPER_FALSE;
+ }
+
+ return PEPPER_TRUE;
}
void
pepper_compositor_schedule_repaint(pepper_compositor_t *compositor)
{
- pepper_output_t *output;
+ pepper_output_t *output;
- pepper_list_for_each(output, &compositor->output_list, link)
- pepper_output_schedule_repaint(output);
+ pepper_list_for_each(output, &compositor->output_list, link)
+ pepper_output_schedule_repaint(output);
}
/**
PEPPER_API pepper_compositor_t *
pepper_compositor_create_fd(const char *socket_name, int fd)
{
- int ret;
- pepper_compositor_t *compositor;
-
- compositor = (pepper_compositor_t *)pepper_object_alloc(PEPPER_OBJECT_COMPOSITOR,
- sizeof(pepper_compositor_t));
- PEPPER_CHECK(compositor, goto error, "pepper_object_alloc() failed.\n");
-
- wl_list_init(&compositor->resource_list);
-
- pepper_list_init(&compositor->surface_list);
- pepper_list_init(&compositor->view_list);
- pepper_list_init(&compositor->region_list);
- pepper_list_init(&compositor->seat_list);
- pepper_list_init(&compositor->output_list);
- pepper_list_init(&compositor->input_device_list);
-
- compositor->display = wl_display_create();
- PEPPER_CHECK(compositor->display, goto error, "wl_display_create() failed.\n");
-
- if (socket_name)
- {
- if (fd > 0)
- {
- PEPPER_CHECK(PEPPER_TRUE == compositor_bind_socket(compositor, fd, socket_name), goto error,
- "compositor_bind_socket()");
- ret = wl_display_add_socket_fd(compositor->display, fd);
- PEPPER_CHECK(ret == 0, goto error, "wl_display_add_socket_fd(name = %s, fd = %d) failed.\n", socket_name, fd);
- }
- else
- {
- ret = wl_display_add_socket(compositor->display, socket_name);
- PEPPER_CHECK(ret == 0, goto error, "wl_display_add_socket(name = %s) failed.\n", socket_name);
- }
- }
- else
- {
- if (fd > 0)
- {
- ret = wl_display_add_socket_fd(compositor->display, fd);
- PEPPER_CHECK(ret == 0, goto error, "wl_display_add_socket_fd(name = %s, fd = %d) failed.\n", socket_name, fd);
- }
- else
- {
- socket_name = wl_display_add_socket_auto(compositor->display);
- PEPPER_CHECK(socket_name, goto error, "wl_display_add_socket_auto() failed.\n");
- }
- }
-
- if (socket_name)
- {
- compositor->socket_name = strdup(socket_name);
- PEPPER_CHECK(compositor->socket_name, goto error, "strdup() failed.\n");
- }
-
- ret = wl_display_init_shm(compositor->display);
- PEPPER_CHECK(ret == 0, goto error, "wl_display_init_shm() failed.\n");
-
- compositor->global = wl_global_create(compositor->display, &wl_compositor_interface,
- 3, compositor, compositor_bind);
- PEPPER_CHECK(compositor->global, goto error, "wl_global_create() failed.\n");
-
- compositor->subcomp = pepper_subcompositor_create(compositor);
- PEPPER_CHECK(compositor->subcomp, goto error, "pepper_subcompositor_create() failed.\n");
-
- compositor->clock_id = CLOCK_MONOTONIC;
- return compositor;
+ int ret;
+ pepper_compositor_t *compositor;
+
+ compositor = (pepper_compositor_t *)pepper_object_alloc(
+ PEPPER_OBJECT_COMPOSITOR,
+ sizeof(pepper_compositor_t));
+ PEPPER_CHECK(compositor, goto error, "pepper_object_alloc() failed.\n");
+
+ wl_list_init(&compositor->resource_list);
+
+ pepper_list_init(&compositor->surface_list);
+ pepper_list_init(&compositor->view_list);
+ pepper_list_init(&compositor->region_list);
+ pepper_list_init(&compositor->seat_list);
+ pepper_list_init(&compositor->output_list);
+ pepper_list_init(&compositor->input_device_list);
+
+ compositor->display = wl_display_create();
+ PEPPER_CHECK(compositor->display, goto error, "wl_display_create() failed.\n");
+
+ if (socket_name) {
+ if (fd > 0) {
+ PEPPER_CHECK(PEPPER_TRUE == compositor_bind_socket(compositor, fd, socket_name),
+ goto error,
+ "compositor_bind_socket()");
+ ret = wl_display_add_socket_fd(compositor->display, fd);
+ PEPPER_CHECK(ret == 0, goto error,
+ "wl_display_add_socket_fd(name = %s, fd = %d) failed.\n", socket_name, fd);
+ } else {
+ ret = wl_display_add_socket(compositor->display, socket_name);
+ PEPPER_CHECK(ret == 0, goto error, "wl_display_add_socket(name = %s) failed.\n",
+ socket_name);
+ }
+ } else {
+ if (fd > 0) {
+ ret = wl_display_add_socket_fd(compositor->display, fd);
+ PEPPER_CHECK(ret == 0, goto error,
+ "wl_display_add_socket_fd(name = %s, fd = %d) failed.\n", socket_name, fd);
+ } else {
+ socket_name = wl_display_add_socket_auto(compositor->display);
+ PEPPER_CHECK(socket_name, goto error, "wl_display_add_socket_auto() failed.\n");
+ }
+ }
+
+ if (socket_name) {
+ compositor->socket_name = strdup(socket_name);
+ PEPPER_CHECK(compositor->socket_name, goto error, "strdup() failed.\n");
+ }
+
+ ret = wl_display_init_shm(compositor->display);
+ PEPPER_CHECK(ret == 0, goto error, "wl_display_init_shm() failed.\n");
+
+ compositor->global = wl_global_create(compositor->display,
+ &wl_compositor_interface,
+ 3, compositor, compositor_bind);
+ PEPPER_CHECK(compositor->global, goto error, "wl_global_create() failed.\n");
+
+ compositor->subcomp = pepper_subcompositor_create(compositor);
+ PEPPER_CHECK(compositor->subcomp, goto error,
+ "pepper_subcompositor_create() failed.\n");
+
+ compositor->clock_id = CLOCK_MONOTONIC;
+ return compositor;
error:
- if (compositor)
- pepper_compositor_destroy(compositor);
+ if (compositor)
+ pepper_compositor_destroy(compositor);
- return NULL;
+ return NULL;
}
PEPPER_API pepper_compositor_t *
pepper_compositor_create(const char *socket_name)
{
- return pepper_compositor_create_fd(socket_name, -1);
+ return pepper_compositor_create_fd(socket_name, -1);
}
/**
PEPPER_API void
pepper_compositor_destroy(pepper_compositor_t *compositor)
{
- pepper_surface_t *surface, *next_surface;
- pepper_region_t *region, *next_region;
+ pepper_surface_t *surface, *next_surface;
+ pepper_region_t *region, *next_region;
- pepper_list_for_each_safe(surface, next_surface, &compositor->surface_list, link)
- pepper_surface_destroy(surface);
+ pepper_list_for_each_safe(surface, next_surface, &compositor->surface_list,
+ link)
+ pepper_surface_destroy(surface);
- pepper_list_for_each_safe(region, next_region, &compositor->region_list, link)
- pepper_region_destroy(region);
+ pepper_list_for_each_safe(region, next_region, &compositor->region_list, link)
+ pepper_region_destroy(region);
- if (compositor->subcomp)
- pepper_subcompositor_destroy(compositor->subcomp);
+ if (compositor->subcomp)
+ pepper_subcompositor_destroy(compositor->subcomp);
- if (compositor->socket_name)
- free(compositor->socket_name);
+ if (compositor->socket_name)
+ free(compositor->socket_name);
- if (compositor->global)
- wl_global_destroy(compositor->global);
+ if (compositor->global)
+ wl_global_destroy(compositor->global);
- if (compositor->display)
- wl_display_destroy(compositor->display);
+ if (compositor->display)
+ wl_display_destroy(compositor->display);
- if (compositor->addr.sun_path[0])
- unlink(compositor->addr.sun_path);
+ if (compositor->addr.sun_path[0])
+ unlink(compositor->addr.sun_path);
- pepper_object_fini(&compositor->base);
- free(compositor);
+ pepper_object_fini(&compositor->base);
+ free(compositor);
}
/**
PEPPER_API struct wl_display *
pepper_compositor_get_display(pepper_compositor_t *compositor)
{
- return compositor->display;
+ return compositor->display;
}
/**
PEPPER_API struct wl_list *
pepper_compositor_get_resource_list(pepper_compositor_t *compositor)
{
- return &compositor->resource_list;
+ return &compositor->resource_list;
}
/**
PEPPER_API const char *
pepper_compositor_get_socket_name(pepper_compositor_t *compositor)
{
- return compositor->socket_name;
+ return compositor->socket_name;
}
/**
PEPPER_API const pepper_list_t *
pepper_compositor_get_output_list(pepper_compositor_t *compositor)
{
- return &compositor->output_list;
+ return &compositor->output_list;
}
/**
PEPPER_API const pepper_list_t *
pepper_compositor_get_surface_list(pepper_compositor_t *compositor)
{
- return &compositor->surface_list;
+ return &compositor->surface_list;
}
/**
PEPPER_API const pepper_list_t *
pepper_compositor_get_view_list(pepper_compositor_t *compositor)
{
- return &compositor->view_list;
+ return &compositor->view_list;
}
/**
PEPPER_API const pepper_list_t *
pepper_compositor_get_seat_list(pepper_compositor_t *compositor)
{
- return &compositor->seat_list;
+ return &compositor->seat_list;
}
/**
PEPPER_API const pepper_list_t *
pepper_compositor_get_input_device_list(pepper_compositor_t *compositor)
{
- return &compositor->input_device_list;
+ return &compositor->input_device_list;
}
/**
*/
PEPPER_API pepper_view_t *
pepper_compositor_pick_view(pepper_compositor_t *compositor,
- double x, double y, double *vx, double *vy)
+ double x, double y, double *vx, double *vy)
{
- pepper_view_t *view;
- int ix = (int)x;
- int iy = (int)y;
+ pepper_view_t *view;
+ int ix = (int)x;
+ int iy = (int)y;
- pepper_list_for_each(view, &compositor->view_list, compositor_link)
- {
- double lx, ly;
- int ilx, ily;
+ pepper_list_for_each(view, &compositor->view_list, compositor_link) {
+ double lx, ly;
+ int ilx, ily;
- if (!view->surface)
- continue;
+ if (!view->surface)
+ continue;
- if (!pixman_region32_contains_point(&view->bounding_region, ix, iy, NULL))
- continue;
+ if (!pixman_region32_contains_point(&view->bounding_region, ix, iy, NULL))
+ continue;
- pepper_view_get_local_coordinate(view, x, y, &lx, &ly);
+ pepper_view_get_local_coordinate(view, x, y, &lx, &ly);
- ilx = (int)lx;
- ily = (int)ly;
+ ilx = (int)lx;
+ ily = (int)ly;
- if (ilx < 0 || ily < 0 || ilx >= view->w || ily >= view->h)
- continue;
+ if (ilx < 0 || ily < 0 || ilx >= view->w || ily >= view->h)
+ continue;
- if (!pixman_region32_contains_point(&view->surface->input_region, ilx, ily, NULL))
- continue;
+ if (!pixman_region32_contains_point(&view->surface->input_region, ilx, ily,
+ NULL))
+ continue;
- if (vx)
- *vx = lx;
+ if (vx)
+ *vx = lx;
- if (vy)
- *vy = ly;
+ if (vy)
+ *vy = ly;
- return view;
- }
+ return view;
+ }
- return NULL;
+ return NULL;
}
/**
PEPPER_API pepper_bool_t
pepper_compositor_set_clock_id(pepper_compositor_t *compositor, clockid_t id)
{
- struct timespec ts;
+ struct timespec ts;
- if (compositor->clock_used)
- {
- if (compositor->clock_id == id)
- return PEPPER_TRUE;
- }
+ if (compositor->clock_used) {
+ if (compositor->clock_id == id)
+ return PEPPER_TRUE;
+ }
- if (clock_gettime(id, &ts) < 0)
- return PEPPER_FALSE;
+ if (clock_gettime(id, &ts) < 0)
+ return PEPPER_FALSE;
- compositor->clock_id = id;
- compositor->clock_used = PEPPER_TRUE;
+ compositor->clock_id = id;
+ compositor->clock_used = PEPPER_TRUE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
/**
PEPPER_API pepper_bool_t
pepper_compositor_get_time(pepper_compositor_t *compositor, struct timespec *ts)
{
- if (clock_gettime(compositor->clock_id, ts) < 0)
- return PEPPER_FALSE;
+ if (clock_gettime(compositor->clock_id, ts) < 0)
+ return PEPPER_FALSE;
- compositor->clock_used = PEPPER_TRUE;
- return PEPPER_TRUE;
+ compositor->clock_used = PEPPER_TRUE;
+ return PEPPER_TRUE;
}
typedef struct pepper_input_device_entry pepper_input_device_entry_t;
-struct pepper_input_device_entry
-{
- pepper_seat_t *seat;
- pepper_input_device_t *device;
- pepper_event_listener_t *listener;
- pepper_list_t link;
+struct pepper_input_device_entry {
+ pepper_seat_t *seat;
+ pepper_input_device_t *device;
+ pepper_event_listener_t *listener;
+ pepper_list_t link;
};
static void
unbind_resource(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
static const struct wl_seat_interface seat_interface = {
- pepper_pointer_bind_resource,
- pepper_keyboard_bind_resource,
- pepper_touch_bind_resource,
+ pepper_pointer_bind_resource,
+ pepper_keyboard_bind_resource,
+ pepper_touch_bind_resource,
};
static void
bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
- pepper_seat_t *seat = (pepper_seat_t *)data;
- struct wl_resource *resource;
+ pepper_seat_t *seat = (pepper_seat_t *)data;
+ struct wl_resource *resource;
- resource = wl_resource_create(client, &wl_seat_interface, version/*FIXME*/, id);
- if (!resource)
- {
- wl_client_post_no_memory(client);
- return;
- }
+ resource = wl_resource_create(client, &wl_seat_interface, version/*FIXME*/, id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
- wl_list_insert(&seat->resource_list, wl_resource_get_link(resource));
- wl_resource_set_implementation(resource, &seat_interface, data, unbind_resource);
+ wl_list_insert(&seat->resource_list, wl_resource_get_link(resource));
+ wl_resource_set_implementation(resource, &seat_interface, data,
+ unbind_resource);
- wl_seat_send_capabilities(resource, seat->caps);
+ wl_seat_send_capabilities(resource, seat->caps);
- if ((seat->name) && (version >= WL_SEAT_NAME_SINCE_VERSION))
- wl_seat_send_name(resource, seat->name);
+ if ((seat->name) && (version >= WL_SEAT_NAME_SINCE_VERSION))
+ wl_seat_send_name(resource, seat->name);
}
/**
* Global for the wl_seat is created internally, thus broadcasted to all clients via registry.
*/
PEPPER_API pepper_seat_t *
-pepper_compositor_add_seat(pepper_compositor_t *compositor, const char *seat_name)
+pepper_compositor_add_seat(pepper_compositor_t *compositor,
+ const char *seat_name)
{
- pepper_seat_t *seat;
+ pepper_seat_t *seat;
- PEPPER_CHECK(seat_name, return NULL, "seat name must be given.\n");
+ PEPPER_CHECK(seat_name, return NULL, "seat name must be given.\n");
- seat = (pepper_seat_t *)pepper_object_alloc(PEPPER_OBJECT_SEAT, sizeof(pepper_seat_t));
- PEPPER_CHECK(seat, return NULL, "Failed to allocate memory in %s\n", __FUNCTION__);
+ seat = (pepper_seat_t *)pepper_object_alloc(PEPPER_OBJECT_SEAT,
+ sizeof(pepper_seat_t));
+ PEPPER_CHECK(seat, return NULL, "Failed to allocate memory in %s\n",
+ __FUNCTION__);
- pepper_list_init(&seat->link);
- wl_list_init(&seat->resource_list);
- pepper_list_init(&seat->input_device_list);
+ pepper_list_init(&seat->link);
+ wl_list_init(&seat->resource_list);
+ pepper_list_init(&seat->input_device_list);
- seat->name = strdup(seat_name);
- PEPPER_CHECK(seat->name, goto error, "strdup() failed.\n");
+ seat->name = strdup(seat_name);
+ PEPPER_CHECK(seat->name, goto error, "strdup() failed.\n");
- seat->global = wl_global_create(compositor->display, &wl_seat_interface, 4, seat, bind_seat);
- PEPPER_CHECK(seat->global, goto error, "wl_global_create() failed.\n");
+ seat->global = wl_global_create(compositor->display, &wl_seat_interface, 4,
+ seat, bind_seat);
+ PEPPER_CHECK(seat->global, goto error, "wl_global_create() failed.\n");
- seat->compositor = compositor;
+ seat->compositor = compositor;
- seat->link.item = seat;
- pepper_list_insert(&compositor->seat_list, &seat->link);
- pepper_object_emit_event(&seat->compositor->base, PEPPER_EVENT_COMPOSITOR_SEAT_ADD, seat);
+ seat->link.item = seat;
+ pepper_list_insert(&compositor->seat_list, &seat->link);
+ pepper_object_emit_event(&seat->compositor->base,
+ PEPPER_EVENT_COMPOSITOR_SEAT_ADD, seat);
- return seat;
+ return seat;
error:
- if (seat)
- pepper_seat_destroy(seat);
+ if (seat)
+ pepper_seat_destroy(seat);
- return NULL;
+ return NULL;
}
/**
PEPPER_API void
pepper_seat_destroy(pepper_seat_t *seat)
{
- struct wl_resource *resource, *tmp;
+ struct wl_resource *resource, *tmp;
- if (seat->name)
- free(seat->name);
+ if (seat->name)
+ free(seat->name);
- if (seat->pointer)
- pepper_pointer_destroy(seat->pointer);
+ if (seat->pointer)
+ pepper_pointer_destroy(seat->pointer);
- if (seat->keyboard)
- pepper_keyboard_destroy(seat->keyboard);
+ if (seat->keyboard)
+ pepper_keyboard_destroy(seat->keyboard);
- if (seat->touch)
- pepper_touch_destroy(seat->touch);
+ if (seat->touch)
+ pepper_touch_destroy(seat->touch);
- if (seat->global)
- wl_global_destroy(seat->global);
+ if (seat->global)
+ wl_global_destroy(seat->global);
- wl_resource_for_each_safe(resource, tmp, &seat->resource_list)
- wl_resource_destroy(resource);
+ wl_resource_for_each_safe(resource, tmp, &seat->resource_list)
+ wl_resource_destroy(resource);
}
/**
PEPPER_API struct wl_list *
pepper_seat_get_resource_list(pepper_seat_t *seat)
{
- return &seat->resource_list;
+ return &seat->resource_list;
}
/**
PEPPER_API pepper_compositor_t *
pepper_seat_get_compositor(pepper_seat_t *seat)
{
- return seat->compositor;
+ return seat->compositor;
}
/**
PEPPER_API pepper_pointer_t *
pepper_seat_get_pointer(pepper_seat_t *seat)
{
- return seat->pointer;
+ return seat->pointer;
}
/**
PEPPER_API pepper_keyboard_t *
pepper_seat_get_keyboard(pepper_seat_t *seat)
{
- return seat->keyboard;
+ return seat->keyboard;
}
/**
PEPPER_API pepper_touch_t *
pepper_seat_get_touch(pepper_seat_t *seat)
{
- return seat->touch;
+ return seat->touch;
}
/**
PEPPER_API const char *
pepper_seat_get_name(pepper_seat_t *seat)
{
- return seat->name;
+ return seat->name;
}
static void
seat_update_pointer_cap(pepper_seat_t *seat)
{
- if ((seat->caps & WL_SEAT_CAPABILITY_POINTER) && !seat->pointer)
- {
- seat->pointer = pepper_pointer_create(seat);
- pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_POINTER_ADD, seat->pointer);
- }
- else if (!(seat->caps & WL_SEAT_CAPABILITY_POINTER) && seat->pointer)
- {
- pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_POINTER_REMOVE, seat->pointer);
- pepper_pointer_destroy(seat->pointer);
- seat->pointer = NULL;
- }
+ if ((seat->caps & WL_SEAT_CAPABILITY_POINTER) && !seat->pointer) {
+ seat->pointer = pepper_pointer_create(seat);
+ pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_POINTER_ADD,
+ seat->pointer);
+ } else if (!(seat->caps & WL_SEAT_CAPABILITY_POINTER) && seat->pointer) {
+ pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_POINTER_REMOVE,
+ seat->pointer);
+ pepper_pointer_destroy(seat->pointer);
+ seat->pointer = NULL;
+ }
}
static void
seat_update_keyboard_cap(pepper_seat_t *seat)
{
- if ((seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && !seat->keyboard)
- {
- seat->keyboard = pepper_keyboard_create(seat);
- pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_KEYBOARD_ADD, seat->keyboard);
- }
- else if (!(seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard)
- {
- pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_KEYBOARD_REMOVE, seat->keyboard);
- pepper_keyboard_destroy(seat->keyboard);
- seat->keyboard = NULL;
- }
+ if ((seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && !seat->keyboard) {
+ seat->keyboard = pepper_keyboard_create(seat);
+ pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_KEYBOARD_ADD,
+ seat->keyboard);
+ } else if (!(seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard) {
+ pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_KEYBOARD_REMOVE,
+ seat->keyboard);
+ pepper_keyboard_destroy(seat->keyboard);
+ seat->keyboard = NULL;
+ }
}
static void
seat_update_touch_cap(pepper_seat_t *seat)
{
- if ((seat->caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->touch)
- {
- seat->touch = pepper_touch_create(seat);
- pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_TOUCH_ADD, seat->touch);
- }
- else if (!(seat->caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch)
- {
- pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_TOUCH_REMOVE, seat->touch);
- pepper_touch_destroy(seat->touch);
- seat->touch = NULL;
- }
+ if ((seat->caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->touch) {
+ seat->touch = pepper_touch_create(seat);
+ pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_TOUCH_ADD, seat->touch);
+ } else if (!(seat->caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch) {
+ pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_TOUCH_REMOVE,
+ seat->touch);
+ pepper_touch_destroy(seat->touch);
+ seat->touch = NULL;
+ }
}
static void
seat_update_caps(pepper_seat_t *seat)
{
- uint32_t caps = 0;
- pepper_input_device_entry_t *entry;
+ uint32_t caps = 0;
+ pepper_input_device_entry_t *entry;
- pepper_list_for_each(entry, &seat->input_device_list, link)
- caps |= entry->device->caps;
+ pepper_list_for_each(entry, &seat->input_device_list, link)
+ caps |= entry->device->caps;
- if (caps != seat->caps)
- {
- struct wl_resource *resource;
+ if (caps != seat->caps) {
+ struct wl_resource *resource;
- seat->caps = caps;
+ seat->caps = caps;
- seat_update_pointer_cap(seat);
- seat_update_keyboard_cap(seat);
- seat_update_touch_cap(seat);
+ seat_update_pointer_cap(seat);
+ seat_update_keyboard_cap(seat);
+ seat_update_touch_cap(seat);
- wl_resource_for_each(resource, &seat->resource_list)
- wl_seat_send_capabilities(resource, seat->caps);
- }
+ wl_resource_for_each(resource, &seat->resource_list)
+ wl_seat_send_capabilities(resource, seat->caps);
+ }
}
static void
-seat_handle_device_event(pepper_event_listener_t *listener, pepper_object_t *object,
- uint32_t id, void *info, void *data)
+seat_handle_device_event(pepper_event_listener_t *listener,
+ pepper_object_t *object,
+ uint32_t id, void *info, void *data)
{
- pepper_input_device_entry_t *entry = data;
- pepper_seat_t *seat = entry->seat;
-
- switch (id)
- {
- case PEPPER_EVENT_OBJECT_DESTROY:
- pepper_seat_remove_input_device(seat, entry->device);
- break;
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE:
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION:
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON:
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS:
- pepper_pointer_handle_event(seat->pointer, id, info);
- break;
- case PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY:
- pepper_keyboard_handle_event(seat->keyboard, id, info);
- break;
- case PEPPER_EVENT_INPUT_DEVICE_TOUCH_DOWN:
- case PEPPER_EVENT_INPUT_DEVICE_TOUCH_UP:
- case PEPPER_EVENT_INPUT_DEVICE_TOUCH_MOTION:
- case PEPPER_EVENT_INPUT_DEVICE_TOUCH_FRAME:
- pepper_touch_handle_event(seat->touch, id, info);
- break;
- }
+ pepper_input_device_entry_t *entry = data;
+ pepper_seat_t *seat = entry->seat;
+
+ switch (id) {
+ case PEPPER_EVENT_OBJECT_DESTROY:
+ pepper_seat_remove_input_device(seat, entry->device);
+ break;
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE:
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION:
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON:
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS:
+ pepper_pointer_handle_event(seat->pointer, id, info);
+ break;
+ case PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY:
+ pepper_keyboard_handle_event(seat->keyboard, id, info);
+ break;
+ case PEPPER_EVENT_INPUT_DEVICE_TOUCH_DOWN:
+ case PEPPER_EVENT_INPUT_DEVICE_TOUCH_UP:
+ case PEPPER_EVENT_INPUT_DEVICE_TOUCH_MOTION:
+ case PEPPER_EVENT_INPUT_DEVICE_TOUCH_FRAME:
+ pepper_touch_handle_event(seat->touch, id, info);
+ break;
+ }
}
/**
PEPPER_API void
pepper_seat_add_input_device(pepper_seat_t *seat, pepper_input_device_t *device)
{
- pepper_input_device_entry_t *entry;
+ pepper_input_device_entry_t *entry;
- pepper_list_for_each(entry, &seat->input_device_list, link)
- {
- if (entry->device == device)
- return;
- }
+ pepper_list_for_each(entry, &seat->input_device_list, link) {
+ if (entry->device == device)
+ return;
+ }
- entry = calloc(1, sizeof(pepper_input_device_entry_t));
- PEPPER_CHECK(entry, return, "calloc() failed.\n");
+ entry = calloc(1, sizeof(pepper_input_device_entry_t));
+ PEPPER_CHECK(entry, return, "calloc() failed.\n");
- entry->seat = seat;
- entry->device = device;
- pepper_list_insert(&seat->input_device_list, &entry->link);
+ entry->seat = seat;
+ entry->device = device;
+ pepper_list_insert(&seat->input_device_list, &entry->link);
- seat_update_caps(seat);
+ seat_update_caps(seat);
- entry->listener = pepper_object_add_event_listener(&device->base, PEPPER_EVENT_ALL, 0,
- seat_handle_device_event, entry);
+ entry->listener = pepper_object_add_event_listener(&device->base,
+ PEPPER_EVENT_ALL, 0,
+ seat_handle_device_event, entry);
}
/**
* events described in pepper_seat_add_input_device().
*/
PEPPER_API void
-pepper_seat_remove_input_device(pepper_seat_t *seat, pepper_input_device_t *device)
+pepper_seat_remove_input_device(pepper_seat_t *seat,
+ pepper_input_device_t *device)
{
- pepper_input_device_entry_t *entry;
-
- pepper_list_for_each(entry, &seat->input_device_list, link)
- {
- if (entry->device == device)
- {
- pepper_list_remove(&entry->link);
- pepper_event_listener_remove(entry->listener);
- free(entry);
- seat_update_caps(seat);
- return;
- }
- }
+ pepper_input_device_entry_t *entry;
+
+ pepper_list_for_each(entry, &seat->input_device_list, link) {
+ if (entry->device == device) {
+ pepper_list_remove(&entry->link);
+ pepper_event_listener_remove(entry->listener);
+ free(entry);
+ seat_update_caps(seat);
+ return;
+ }
+ }
}
/**
*/
PEPPER_API pepper_input_device_t *
pepper_input_device_create(pepper_compositor_t *compositor, uint32_t caps,
- const pepper_input_device_backend_t *backend, void *data)
+ const pepper_input_device_backend_t *backend, void *data)
{
- pepper_input_device_t *device;
-
- device = (pepper_input_device_t *)pepper_object_alloc(PEPPER_OBJECT_INPUT_DEVICE,
- sizeof(pepper_input_device_t));
- PEPPER_CHECK(device, return NULL, "pepper_object_alloc() failed.\n");
-
- device->compositor = compositor;
- device->caps = caps;
- device->backend = backend;
- device->data = data;
- device->link.item = device;
-
- pepper_list_insert(&compositor->input_device_list, &device->link);
- pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
- device);
- return device;
+ pepper_input_device_t *device;
+
+ device = (pepper_input_device_t *)pepper_object_alloc(
+ PEPPER_OBJECT_INPUT_DEVICE,
+ sizeof(pepper_input_device_t));
+ PEPPER_CHECK(device, return NULL, "pepper_object_alloc() failed.\n");
+
+ device->compositor = compositor;
+ device->caps = caps;
+ device->backend = backend;
+ device->data = data;
+ device->link.item = device;
+
+ pepper_list_insert(&compositor->input_device_list, &device->link);
+ pepper_object_emit_event(&compositor->base,
+ PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
+ device);
+ return device;
}
/**
PEPPER_API void
pepper_input_device_destroy(pepper_input_device_t *device)
{
- pepper_object_emit_event(&device->compositor->base,
- PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE, device);
- pepper_list_remove(&device->link);
- pepper_object_fini(&device->base);
- free(device);
+ pepper_object_emit_event(&device->compositor->base,
+ PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE, device);
+ pepper_list_remove(&device->link);
+ pepper_object_fini(&device->base);
+ free(device);
}
/**
PEPPER_API pepper_compositor_t *
pepper_input_device_get_compositor(pepper_input_device_t *device)
{
- return device->compositor;
+ return device->compositor;
}
/**
PEPPER_API const char *
pepper_input_device_get_property(pepper_input_device_t *device, const char *key)
{
- if (!device->backend)
- return NULL;
+ if (!device->backend)
+ return NULL;
- return device->backend->get_property(device->data, key);
+ return device->backend->get_property(device->data, key);
}
/**
PEPPER_API uint32_t
pepper_input_device_get_caps(pepper_input_device_t *device)
{
- return device->caps;
+ return device->caps;
}
static void
keyboard_release(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
-static const struct wl_keyboard_interface keyboard_impl =
-{
- keyboard_release,
+static const struct wl_keyboard_interface keyboard_impl = {
+ keyboard_release,
};
static void
clear_keymap(pepper_keyboard_t *keyboard)
{
- if (keyboard->state)
- {
- xkb_state_unref(keyboard->state);
- keyboard->state = NULL;
- }
-
- if (keyboard->keymap)
- {
- xkb_keymap_unref(keyboard->keymap);
- keyboard->keymap = NULL;
- }
-
- if (keyboard->keymap_fd >= 0)
- {
- close(keyboard->keymap_fd);
- keyboard->keymap_fd = -1;
- keyboard->keymap_len = -1;
- }
-
- if (keyboard->pending_keymap)
- {
- xkb_keymap_unref(keyboard->pending_keymap);
- keyboard->pending_keymap = NULL;
- }
+ if (keyboard->state) {
+ xkb_state_unref(keyboard->state);
+ keyboard->state = NULL;
+ }
+
+ if (keyboard->keymap) {
+ xkb_keymap_unref(keyboard->keymap);
+ keyboard->keymap = NULL;
+ }
+
+ if (keyboard->keymap_fd >= 0) {
+ close(keyboard->keymap_fd);
+ keyboard->keymap_fd = -1;
+ keyboard->keymap_len = -1;
+ }
+
+ if (keyboard->pending_keymap) {
+ xkb_keymap_unref(keyboard->pending_keymap);
+ keyboard->pending_keymap = NULL;
+ }
}
static void
update_modifiers(pepper_keyboard_t *keyboard)
{
- uint32_t mods_depressed, mods_latched, mods_locked, group;
-
- mods_depressed = xkb_state_serialize_mods(keyboard->state, XKB_STATE_MODS_DEPRESSED);
- mods_latched = xkb_state_serialize_mods(keyboard->state, XKB_STATE_MODS_LATCHED);
- mods_locked = xkb_state_serialize_mods(keyboard->state, XKB_STATE_MODS_LOCKED);
- group = xkb_state_serialize_mods(keyboard->state, XKB_STATE_LAYOUT_EFFECTIVE);
-
- if ((mods_depressed != keyboard->mods_depressed) || (mods_latched != keyboard->mods_latched) ||
- (mods_locked != keyboard->mods_locked) || (group != keyboard->group))
- {
- keyboard->mods_depressed = mods_depressed;
- keyboard->mods_latched = mods_latched;
- keyboard->mods_locked = mods_locked;
- keyboard->group = group;
-
- keyboard->grab->modifiers(keyboard, keyboard->data, mods_depressed, mods_latched,
- mods_locked, group);
- }
+ uint32_t mods_depressed, mods_latched, mods_locked, group;
+
+ mods_depressed = xkb_state_serialize_mods(keyboard->state,
+ XKB_STATE_MODS_DEPRESSED);
+ mods_latched = xkb_state_serialize_mods(keyboard->state,
+ XKB_STATE_MODS_LATCHED);
+ mods_locked = xkb_state_serialize_mods(keyboard->state, XKB_STATE_MODS_LOCKED);
+ group = xkb_state_serialize_mods(keyboard->state, XKB_STATE_LAYOUT_EFFECTIVE);
+
+ if ((mods_depressed != keyboard->mods_depressed) ||
+ (mods_latched != keyboard->mods_latched) ||
+ (mods_locked != keyboard->mods_locked) || (group != keyboard->group)) {
+ keyboard->mods_depressed = mods_depressed;
+ keyboard->mods_latched = mods_latched;
+ keyboard->mods_locked = mods_locked;
+ keyboard->group = group;
+
+ keyboard->grab->modifiers(keyboard, keyboard->data, mods_depressed,
+ mods_latched,
+ mods_locked, group);
+ }
}
static void
update_key(pepper_keyboard_t *keyboard, uint32_t key, uint32_t state)
{
- enum xkb_key_direction direction;
+ enum xkb_key_direction direction;
- if (!keyboard->state)
- return;
+ if (!keyboard->state)
+ return;
- if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
- direction = XKB_KEY_DOWN;
- else
- direction = XKB_KEY_UP;
+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
+ direction = XKB_KEY_DOWN;
+ else
+ direction = XKB_KEY_UP;
- xkb_state_update_key(keyboard->state, key + 8, direction);
- update_modifiers(keyboard);
+ xkb_state_update_key(keyboard->state, key + 8, direction);
+ update_modifiers(keyboard);
}
static void
update_keymap(pepper_keyboard_t *keyboard)
{
- struct wl_resource *resource;
- char *keymap_str = NULL;
- char *keymap_map = NULL;
-
- struct xkb_state *state;
- uint32_t mods_latched = 0;
- uint32_t mods_locked = 0;
- uint32_t format;
-
- if (keyboard->keymap)
- xkb_keymap_unref(keyboard->keymap);
-
- if (keyboard->keymap_fd)
- close(keyboard->keymap_fd);
-
- if (keyboard->pending_keymap)
- {
- format = WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1;
- keyboard->keymap = xkb_keymap_ref(keyboard->pending_keymap);
- xkb_keymap_unref(keyboard->pending_keymap);
- keyboard->pending_keymap = NULL;
-
- keymap_str = xkb_keymap_get_as_string(keyboard->keymap, XKB_KEYMAP_FORMAT_TEXT_V1);
- PEPPER_CHECK(keymap_str, goto error, "failed to get keymap string\n");
-
- keyboard->keymap_len = strlen(keymap_str) + 1;
- keyboard->keymap_fd = pepper_create_anonymous_file(keyboard->keymap_len);
- PEPPER_CHECK(keyboard->keymap_fd, goto error, "failed to create keymap file\n");
-
- keymap_map = mmap(NULL, keyboard->keymap_len, PROT_READ | PROT_WRITE, MAP_SHARED,
- keyboard->keymap_fd, 0);
- PEPPER_CHECK(keymap_map, goto error, "failed to mmap for keymap\n");
-
- strcpy(keymap_map, keymap_str);
-
- state = xkb_state_new(keyboard->keymap);
- PEPPER_CHECK(state, goto error, "failed to create xkb state\n");
-
- if (keyboard->state)
- {
- mods_latched = xkb_state_serialize_mods(keyboard->state, XKB_STATE_MODS_LATCHED);
- mods_locked = xkb_state_serialize_mods(keyboard->state, XKB_STATE_MODS_LOCKED);
- xkb_state_update_mask(state, 0, mods_latched, mods_locked, 0, 0, 0);
- xkb_state_unref(keyboard->state);
- }
-
- keyboard->state = state;
- }
- else
- {
- format = WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP;
- }
-
- wl_resource_for_each(resource, &keyboard->resource_list)
- wl_keyboard_send_keymap(resource, format, keyboard->keymap_fd, keyboard->keymap_len);
-
- update_modifiers(keyboard);
-
- if (!mods_latched && !mods_locked)
- goto done;
-
- wl_resource_for_each(resource, &keyboard->resource_list)
- wl_keyboard_send_modifiers(resource,
- wl_display_next_serial(keyboard->seat->compositor->display),
- keyboard->mods_depressed, keyboard->mods_latched,
- keyboard->mods_locked, keyboard->group);
- goto done;
+ struct wl_resource *resource;
+ char *keymap_str = NULL;
+ char *keymap_map = NULL;
+
+ struct xkb_state *state;
+ uint32_t mods_latched = 0;
+ uint32_t mods_locked = 0;
+ uint32_t format;
+
+ if (keyboard->keymap)
+ xkb_keymap_unref(keyboard->keymap);
+
+ if (keyboard->keymap_fd)
+ close(keyboard->keymap_fd);
+
+ if (keyboard->pending_keymap) {
+ format = WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1;
+ keyboard->keymap = xkb_keymap_ref(keyboard->pending_keymap);
+ xkb_keymap_unref(keyboard->pending_keymap);
+ keyboard->pending_keymap = NULL;
+
+ keymap_str = xkb_keymap_get_as_string(keyboard->keymap,
+ XKB_KEYMAP_FORMAT_TEXT_V1);
+ PEPPER_CHECK(keymap_str, goto error, "failed to get keymap string\n");
+
+ keyboard->keymap_len = strlen(keymap_str) + 1;
+ keyboard->keymap_fd = pepper_create_anonymous_file(keyboard->keymap_len);
+ PEPPER_CHECK(keyboard->keymap_fd, goto error, "failed to create keymap file\n");
+
+ keymap_map = mmap(NULL, keyboard->keymap_len, PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ keyboard->keymap_fd, 0);
+ PEPPER_CHECK(keymap_map, goto error, "failed to mmap for keymap\n");
+
+ strcpy(keymap_map, keymap_str);
+
+ state = xkb_state_new(keyboard->keymap);
+ PEPPER_CHECK(state, goto error, "failed to create xkb state\n");
+
+ if (keyboard->state) {
+ mods_latched = xkb_state_serialize_mods(keyboard->state,
+ XKB_STATE_MODS_LATCHED);
+ mods_locked = xkb_state_serialize_mods(keyboard->state, XKB_STATE_MODS_LOCKED);
+ xkb_state_update_mask(state, 0, mods_latched, mods_locked, 0, 0, 0);
+ xkb_state_unref(keyboard->state);
+ }
+
+ keyboard->state = state;
+ } else {
+ format = WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP;
+ }
+
+ wl_resource_for_each(resource, &keyboard->resource_list)
+ wl_keyboard_send_keymap(resource, format, keyboard->keymap_fd,
+ keyboard->keymap_len);
+
+ update_modifiers(keyboard);
+
+ if (!mods_latched && !mods_locked)
+ goto done;
+
+ wl_resource_for_each(resource, &keyboard->resource_list)
+ wl_keyboard_send_modifiers(resource,
+ wl_display_next_serial(keyboard->seat->compositor->display),
+ keyboard->mods_depressed, keyboard->mods_latched,
+ keyboard->mods_locked, keyboard->group);
+ goto done;
error:
- clear_keymap(keyboard);
+ clear_keymap(keyboard);
done:
- if (keymap_map)
- munmap(keymap_map, keyboard->keymap_len);
+ if (keymap_map)
+ munmap(keymap_map, keyboard->keymap_len);
- if (keymap_str)
- free(keymap_str);
+ if (keymap_str)
+ free(keymap_str);
}
void
-pepper_keyboard_handle_event(pepper_keyboard_t *keyboard, uint32_t id, pepper_input_event_t *event)
+pepper_keyboard_handle_event(pepper_keyboard_t *keyboard, uint32_t id,
+ pepper_input_event_t *event)
{
- uint32_t *keys = keyboard->keys.data;
- unsigned int num_keys = keyboard->keys.size / sizeof(uint32_t);
- unsigned int i;
+ uint32_t *keys = keyboard->keys.data;
+ unsigned int num_keys = keyboard->keys.size / sizeof(uint32_t);
+ unsigned int i;
- if (id != PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY)
- return;
+ if (id != PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY)
+ return;
- /* Update the array of pressed keys. */
- for (i = 0; i < num_keys; i++)
- {
- if (keys[i] == event->key)
- {
- keys[i] = keys[--num_keys];
- break;
- }
- }
+ /* Update the array of pressed keys. */
+ for (i = 0; i < num_keys; i++) {
+ if (keys[i] == event->key) {
+ keys[i] = keys[--num_keys];
+ break;
+ }
+ }
- keyboard->keys.size = num_keys * sizeof(uint32_t);
+ keyboard->keys.size = num_keys * sizeof(uint32_t);
- if (event->state == PEPPER_KEY_STATE_PRESSED)
- *(uint32_t *)wl_array_add(&keyboard->keys, sizeof(uint32_t)) = event->key;
+ if (event->state == PEPPER_KEY_STATE_PRESSED)
+ *(uint32_t *)wl_array_add(&keyboard->keys, sizeof(uint32_t)) = event->key;
- if (keyboard->grab)
- keyboard->grab->key(keyboard, keyboard->data, event->time, event->key, event->state);
+ if (keyboard->grab)
+ keyboard->grab->key(keyboard, keyboard->data, event->time, event->key,
+ event->state);
- if (keyboard->pending_keymap && (keyboard->keys.size == 0))
- update_keymap(keyboard);
+ if (keyboard->pending_keymap && (keyboard->keys.size == 0))
+ update_keymap(keyboard);
- update_key(keyboard, event->key, event->state);
+ update_key(keyboard, event->key, event->state);
- pepper_object_emit_event(&keyboard->base, PEPPER_EVENT_KEYBOARD_KEY, event);
+ pepper_object_emit_event(&keyboard->base, PEPPER_EVENT_KEYBOARD_KEY, event);
}
static void
-keyboard_handle_focus_destroy(pepper_event_listener_t *listener, pepper_object_t *surface,
- uint32_t id, void *info, void *data)
+keyboard_handle_focus_destroy(pepper_event_listener_t *listener,
+ pepper_object_t *surface,
+ uint32_t id, void *info, void *data)
{
- pepper_keyboard_t *keyboard = data;
- pepper_keyboard_set_focus(keyboard, NULL);
+ pepper_keyboard_t *keyboard = data;
+ pepper_keyboard_set_focus(keyboard, NULL);
- if (keyboard->grab)
- keyboard->grab->cancel(keyboard, keyboard->data);
+ if (keyboard->grab)
+ keyboard->grab->cancel(keyboard, keyboard->data);
}
pepper_keyboard_t *
pepper_keyboard_create(pepper_seat_t *seat)
{
- pepper_keyboard_t *keyboard =
- (pepper_keyboard_t *)pepper_object_alloc(PEPPER_OBJECT_KEYBOARD, sizeof(pepper_keyboard_t));
+ pepper_keyboard_t *keyboard =
+ (pepper_keyboard_t *)pepper_object_alloc(PEPPER_OBJECT_KEYBOARD,
+ sizeof(pepper_keyboard_t));
- PEPPER_CHECK(keyboard, return NULL, "pepper_object_alloc() failed.\n");
+ PEPPER_CHECK(keyboard, return NULL, "pepper_object_alloc() failed.\n");
- keyboard->seat = seat;
- wl_list_init(&keyboard->resource_list);
+ keyboard->seat = seat;
+ wl_list_init(&keyboard->resource_list);
- wl_array_init(&keyboard->keys);
+ wl_array_init(&keyboard->keys);
- return keyboard;
+ return keyboard;
}
void
pepper_keyboard_destroy(pepper_keyboard_t *keyboard)
{
- clear_keymap(keyboard);
+ clear_keymap(keyboard);
- if (keyboard->grab)
- keyboard->grab->cancel(keyboard, keyboard->data);
+ if (keyboard->grab)
+ keyboard->grab->cancel(keyboard, keyboard->data);
- if (keyboard->focus)
- pepper_event_listener_remove(keyboard->focus_destroy_listener);
+ if (keyboard->focus)
+ pepper_event_listener_remove(keyboard->focus_destroy_listener);
- wl_array_release(&keyboard->keys);
- free(keyboard);
+ wl_array_release(&keyboard->keys);
+ free(keyboard);
}
static void
unbind_resource(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
void
-pepper_keyboard_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id)
+pepper_keyboard_bind_resource(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id)
{
- pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
- pepper_keyboard_t *keyboard = seat->keyboard;
- struct wl_resource *res;
-
- if (!keyboard)
- return;
-
- res = wl_resource_create(client, &wl_keyboard_interface, wl_resource_get_version(resource), id);
- if (!res)
- {
- wl_client_post_no_memory(client);
- return;
- }
-
- wl_list_insert(&keyboard->resource_list, wl_resource_get_link(res));
- wl_resource_set_implementation(res, &keyboard_impl, keyboard, unbind_resource);
-
- /* TODO: send repeat info */
-
- if (keyboard->keymap)
- {
- wl_keyboard_send_keymap(res, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
- keyboard->keymap_fd, keyboard->keymap_len);
- }
- else
- {
- int fd = open("/dev/null", O_RDONLY);
- wl_keyboard_send_keymap(res, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, fd, 0);
- close(fd);
- }
-
- if (!keyboard->focus || !keyboard->focus->surface || !keyboard->focus->surface->resource)
- return;
-
- if (wl_resource_get_client(keyboard->focus->surface->resource) == client)
- {
- wl_keyboard_send_enter(res, keyboard->focus_serial,
- keyboard->focus->surface->resource, &keyboard->keys);
- }
+ pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
+ pepper_keyboard_t *keyboard = seat->keyboard;
+ struct wl_resource *res;
+
+ if (!keyboard)
+ return;
+
+ res = wl_resource_create(client, &wl_keyboard_interface,
+ wl_resource_get_version(resource), id);
+ if (!res) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_list_insert(&keyboard->resource_list, wl_resource_get_link(res));
+ wl_resource_set_implementation(res, &keyboard_impl, keyboard, unbind_resource);
+
+ /* TODO: send repeat info */
+
+ if (keyboard->keymap) {
+ wl_keyboard_send_keymap(res, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
+ keyboard->keymap_fd, keyboard->keymap_len);
+ } else {
+ int fd = open("/dev/null", O_RDONLY);
+ wl_keyboard_send_keymap(res, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, fd, 0);
+ close(fd);
+ }
+
+ if (!keyboard->focus || !keyboard->focus->surface ||
+ !keyboard->focus->surface->resource)
+ return;
+
+ if (wl_resource_get_client(keyboard->focus->surface->resource) == client) {
+ wl_keyboard_send_enter(res, keyboard->focus_serial,
+ keyboard->focus->surface->resource, &keyboard->keys);
+ }
}
/**
PEPPER_API struct wl_list *
pepper_keyboard_get_resource_list(pepper_keyboard_t *keyboard)
{
- return &keyboard->resource_list;
+ return &keyboard->resource_list;
}
/**
PEPPER_API pepper_compositor_t *
pepper_keyboard_get_compositor(pepper_keyboard_t *keyboard)
{
- return keyboard->seat->compositor;
+ return keyboard->seat->compositor;
}
/**
PEPPER_API pepper_seat_t *
pepper_keyboard_get_seat(pepper_keyboard_t *keyboard)
{
- return keyboard->seat;
+ return keyboard->seat;
}
/**
PEPPER_API void
pepper_keyboard_set_focus(pepper_keyboard_t *keyboard, pepper_view_t *focus)
{
- if (keyboard->focus == focus)
- return;
-
- if (keyboard->focus)
- {
- pepper_event_listener_remove(keyboard->focus_destroy_listener);
- pepper_object_emit_event(&keyboard->base, PEPPER_EVENT_FOCUS_LEAVE, keyboard->focus);
- pepper_object_emit_event(&keyboard->focus->base, PEPPER_EVENT_FOCUS_LEAVE, keyboard);
- }
-
- keyboard->focus = focus;
-
- if (focus)
- {
- keyboard->focus_serial = wl_display_next_serial(keyboard->seat->compositor->display);
-
- keyboard->focus_destroy_listener =
- pepper_object_add_event_listener(&focus->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
- keyboard_handle_focus_destroy, keyboard);
-
- pepper_object_emit_event(&keyboard->base, PEPPER_EVENT_FOCUS_ENTER, focus);
- pepper_object_emit_event(&focus->base, PEPPER_EVENT_FOCUS_ENTER, keyboard);
- }
+ if (keyboard->focus == focus)
+ return;
+
+ if (keyboard->focus) {
+ pepper_event_listener_remove(keyboard->focus_destroy_listener);
+ pepper_object_emit_event(&keyboard->base, PEPPER_EVENT_FOCUS_LEAVE,
+ keyboard->focus);
+ pepper_object_emit_event(&keyboard->focus->base, PEPPER_EVENT_FOCUS_LEAVE,
+ keyboard);
+ }
+
+ keyboard->focus = focus;
+
+ if (focus) {
+ keyboard->focus_serial = wl_display_next_serial(
+ keyboard->seat->compositor->display);
+
+ keyboard->focus_destroy_listener =
+ pepper_object_add_event_listener(&focus->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
+ keyboard_handle_focus_destroy, keyboard);
+
+ pepper_object_emit_event(&keyboard->base, PEPPER_EVENT_FOCUS_ENTER, focus);
+ pepper_object_emit_event(&focus->base, PEPPER_EVENT_FOCUS_ENTER, keyboard);
+ }
}
/**
PEPPER_API pepper_view_t *
pepper_keyboard_get_focus(pepper_keyboard_t *keyboard)
{
- return keyboard->focus;
+ return keyboard->focus;
}
/**
PEPPER_API void
pepper_keyboard_send_leave(pepper_keyboard_t *keyboard, pepper_view_t *view)
{
- struct wl_resource *resource;
- struct wl_client *client;
- uint32_t serial;
+ struct wl_resource *resource;
+ struct wl_client *client;
+ uint32_t serial;
- if (!view || !view->surface || !view->surface->resource)
- return;
+ if (!view || !view->surface || !view->surface->resource)
+ return;
- client = wl_resource_get_client(view->surface->resource);
- serial = wl_display_next_serial(keyboard->seat->compositor->display);
+ client = wl_resource_get_client(view->surface->resource);
+ serial = wl_display_next_serial(keyboard->seat->compositor->display);
- wl_resource_for_each(resource, &keyboard->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_keyboard_send_leave(resource, serial, view->surface->resource);
- }
+ wl_resource_for_each(resource, &keyboard->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_keyboard_send_leave(resource, serial, view->surface->resource);
+ }
}
/**
PEPPER_API void
pepper_keyboard_send_enter(pepper_keyboard_t *keyboard, pepper_view_t *view)
{
- struct wl_resource *resource;
- struct wl_client *client;
- uint32_t serial;
+ struct wl_resource *resource;
+ struct wl_client *client;
+ uint32_t serial;
- if (!view || !view->surface || !view->surface->resource)
- return;
+ if (!view || !view->surface || !view->surface->resource)
+ return;
- client = wl_resource_get_client(view->surface->resource);
- serial = wl_display_next_serial(keyboard->seat->compositor->display);
+ client = wl_resource_get_client(view->surface->resource);
+ serial = wl_display_next_serial(keyboard->seat->compositor->display);
- wl_resource_for_each(resource, &keyboard->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_keyboard_send_enter(resource, serial, view->surface->resource, &keyboard->keys);
- }
+ wl_resource_for_each(resource, &keyboard->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_keyboard_send_enter(resource, serial, view->surface->resource,
+ &keyboard->keys);
+ }
}
/**
*/
PEPPER_API void
pepper_keyboard_send_key(pepper_keyboard_t *keyboard, pepper_view_t *view,
- uint32_t time, uint32_t key, uint32_t state)
+ uint32_t time, uint32_t key, uint32_t state)
{
- struct wl_resource *resource;
- struct wl_client *client;
- uint32_t serial;
- pepper_input_event_t event;
-
- if (!view || !view->surface || !view->surface->resource)
- return;
-
- client = wl_resource_get_client(view->surface->resource);
- serial = wl_display_next_serial(keyboard->seat->compositor->display);
-
- wl_resource_for_each(resource, &keyboard->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_keyboard_send_key(resource, serial, time, key, state);
- }
-
- event.time = time;
- event.key = key;
- event.state = state;
- pepper_object_emit_event(&view->base, PEPPER_EVENT_KEYBOARD_KEY, &event);
+ struct wl_resource *resource;
+ struct wl_client *client;
+ uint32_t serial;
+ pepper_input_event_t event;
+
+ if (!view || !view->surface || !view->surface->resource)
+ return;
+
+ client = wl_resource_get_client(view->surface->resource);
+ serial = wl_display_next_serial(keyboard->seat->compositor->display);
+
+ wl_resource_for_each(resource, &keyboard->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_keyboard_send_key(resource, serial, time, key, state);
+ }
+
+ event.time = time;
+ event.key = key;
+ event.state = state;
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_KEYBOARD_KEY, &event);
}
/**
*/
PEPPER_API void
pepper_keyboard_send_modifiers(pepper_keyboard_t *keyboard, pepper_view_t *view,
- uint32_t depressed, uint32_t latched,
- uint32_t locked, uint32_t group)
+ uint32_t depressed, uint32_t latched,
+ uint32_t locked, uint32_t group)
{
- struct wl_resource *resource;
- struct wl_client *client;
- uint32_t serial;
+ struct wl_resource *resource;
+ struct wl_client *client;
+ uint32_t serial;
- if (!view || !view->surface || !view->surface->resource)
- return;
+ if (!view || !view->surface || !view->surface->resource)
+ return;
- client = wl_resource_get_client(view->surface->resource);
- serial = wl_display_next_serial(keyboard->seat->compositor->display);
+ client = wl_resource_get_client(view->surface->resource);
+ serial = wl_display_next_serial(keyboard->seat->compositor->display);
- wl_resource_for_each(resource, &keyboard->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_keyboard_send_modifiers(resource, serial, depressed, latched, locked, group);
- }
+ wl_resource_for_each(resource, &keyboard->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_keyboard_send_modifiers(resource, serial, depressed, latched, locked, group);
+ }
}
/**
* @param data user data to be passed to grab functions
*/
PEPPER_API void
-pepper_keyboard_set_grab(pepper_keyboard_t *keyboard, const pepper_keyboard_grab_t *grab, void *data)
+pepper_keyboard_set_grab(pepper_keyboard_t *keyboard,
+ const pepper_keyboard_grab_t *grab, void *data)
{
- keyboard->grab = grab;
- keyboard->data = data;
+ keyboard->grab = grab;
+ keyboard->data = data;
}
/**
PEPPER_API const pepper_keyboard_grab_t *
pepper_keyboard_get_grab(pepper_keyboard_t *keyboard)
{
- return keyboard->grab;
+ return keyboard->grab;
}
/**
PEPPER_API void *
pepper_keyboard_get_grab_data(pepper_keyboard_t *keyboard)
{
- return keyboard->data;
+ return keyboard->data;
}
/**
* This function might send wl_pointer.keymap and wl_pointer.modifers events internally
*/
PEPPER_API void
-pepper_keyboard_set_keymap(pepper_keyboard_t *keyboard, struct xkb_keymap *keymap)
+pepper_keyboard_set_keymap(pepper_keyboard_t *keyboard,
+ struct xkb_keymap *keymap)
{
- xkb_keymap_unref(keyboard->pending_keymap);
- if (keymap)
- keyboard->pending_keymap = xkb_keymap_ref(keymap);
- else
- keyboard->pending_keymap = NULL;
-
- if (keyboard->keys.size == 0)
- update_keymap(keyboard);
+ xkb_keymap_unref(keyboard->pending_keymap);
+ if (keymap)
+ keyboard->pending_keymap = xkb_keymap_ref(keymap);
+ else
+ keyboard->pending_keymap = NULL;
+
+ if (keyboard->keys.size == 0)
+ update_keymap(keyboard);
}
* @param output output object
*/
PEPPER_API void
-pepper_pixman_region_global_to_output(pixman_region32_t *region, pepper_output_t *output)
+pepper_pixman_region_global_to_output(pixman_region32_t *region,
+ pepper_output_t *output)
{
- pixman_box32_t *box, b;
- int num_rects, i;
- int32_t scale = output->scale;
- int32_t w = output->geometry.w;
- int32_t h = output->geometry.h;
+ pixman_box32_t *box, b;
+ int num_rects, i;
+ int32_t scale = output->scale;
+ int32_t w = output->geometry.w;
+ int32_t h = output->geometry.h;
- /* Transform into output geometry origin. */
- pixman_region32_translate(region, output->geometry.x, output->geometry.y);
+ /* Transform into output geometry origin. */
+ pixman_region32_translate(region, output->geometry.x, output->geometry.y);
- if (output->geometry.transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1)
- return;
+ if (output->geometry.transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1)
+ return;
- box = pixman_region32_rectangles(region, &num_rects);
+ box = pixman_region32_rectangles(region, &num_rects);
- switch (output->geometry.transform)
- {
- case WL_OUTPUT_TRANSFORM_NORMAL:
- break;
- case WL_OUTPUT_TRANSFORM_90:
- for (i = 0; i < num_rects; i++)
- {
- b.x1 = h - box[i].y2;
- b.y1 = box[i].x1;
- b.x2 = h - box[i].y1;
- b.y2 = box[i].x2;
+ switch (output->geometry.transform) {
+ case WL_OUTPUT_TRANSFORM_NORMAL:
+ break;
+ case WL_OUTPUT_TRANSFORM_90:
+ for (i = 0; i < num_rects; i++) {
+ b.x1 = h - box[i].y2;
+ b.y1 = box[i].x1;
+ b.x2 = h - box[i].y1;
+ b.y2 = box[i].x2;
- box[i] = b;
- }
- break;
- case WL_OUTPUT_TRANSFORM_180:
- for (i = 0; i < num_rects; i++)
- {
- b.x1 = w - box[i].x2;
- b.y1 = h - box[i].y2;
- b.x2 = w - box[i].x1;
- b.y2 = h - box[i].y1;
+ box[i] = b;
+ }
+ break;
+ case WL_OUTPUT_TRANSFORM_180:
+ for (i = 0; i < num_rects; i++) {
+ b.x1 = w - box[i].x2;
+ b.y1 = h - box[i].y2;
+ b.x2 = w - box[i].x1;
+ b.y2 = h - box[i].y1;
- box[i] = b;
- }
- break;
- case WL_OUTPUT_TRANSFORM_270:
- for (i = 0; i < num_rects; i++)
- {
- b.x1 = box[i].y1;
- b.y1 = w - box[i].x2;
- b.x2 = box[i].y2;
- b.y2 = w - box[i].x1;
+ box[i] = b;
+ }
+ break;
+ case WL_OUTPUT_TRANSFORM_270:
+ for (i = 0; i < num_rects; i++) {
+ b.x1 = box[i].y1;
+ b.y1 = w - box[i].x2;
+ b.x2 = box[i].y2;
+ b.y2 = w - box[i].x1;
- box[i] = b;
- }
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED:
- for (i = 0; i < num_rects; i++)
- {
- b.x1 = w - box[i].x2;
- b.y1 = box[i].y1;
- b.x2 = w - box[i].x1;
- b.y2 = box[i].y2;
+ box[i] = b;
+ }
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED:
+ for (i = 0; i < num_rects; i++) {
+ b.x1 = w - box[i].x2;
+ b.y1 = box[i].y1;
+ b.x2 = w - box[i].x1;
+ b.y2 = box[i].y2;
- box[i] = b;
- }
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- for (i = 0; i < num_rects; i++)
- {
- b.x1 = h - box[i].y2;
- b.y1 = w - box[i].x2;
- b.x2 = h - box[i].y1;
- b.y2 = w - box[i].x1;
+ box[i] = b;
+ }
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+ for (i = 0; i < num_rects; i++) {
+ b.x1 = h - box[i].y2;
+ b.y1 = w - box[i].x2;
+ b.x2 = h - box[i].y1;
+ b.y2 = w - box[i].x1;
- box[i] = b;
- }
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_180:
- for (i = 0; i < num_rects; i++)
- {
- b.x1 = box[i].x1;
- b.y1 = h - box[i].y2;
- b.x2 = box[i].x2;
- b.y2 = h - box[i].y1;
+ box[i] = b;
+ }
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+ for (i = 0; i < num_rects; i++) {
+ b.x1 = box[i].x1;
+ b.y1 = h - box[i].y2;
+ b.x2 = box[i].x2;
+ b.y2 = h - box[i].y1;
- box[i] = b;
- }
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- for (i = 0; i < num_rects; i++)
- {
- b.x1 = box[i].y1;
- b.y1 = box[i].x1;
- b.x2 = box[i].y2;
- b.y2 = box[i].x2;
+ box[i] = b;
+ }
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+ for (i = 0; i < num_rects; i++) {
+ b.x1 = box[i].y1;
+ b.y1 = box[i].x1;
+ b.x2 = box[i].y2;
+ b.y2 = box[i].x2;
- box[i] = b;
- }
- break;
- }
+ box[i] = b;
+ }
+ break;
+ }
- if (scale != 1)
- {
- for (i = 0; i < num_rects; i++)
- {
- box[i].x1 *= scale;
- box[i].y1 *= scale;
- box[i].x2 *= scale;
- box[i].y2 *= scale;
- }
- }
+ if (scale != 1) {
+ for (i = 0; i < num_rects; i++) {
+ box[i].x1 *= scale;
+ box[i].y1 *= scale;
+ box[i].x2 *= scale;
+ box[i].y2 *= scale;
+ }
+ }
}
/**
*/
PEPPER_API void
pepper_coordinates_surface_to_buffer(pepper_surface_t *surface,
- double sx, double sy, double *bx, double *by)
+ double sx, double sy, double *bx, double *by)
{
- int32_t scale, w, h;
+ int32_t scale, w, h;
- scale = surface->buffer.scale;
- w = surface->w;
- h = surface->h;
+ scale = surface->buffer.scale;
+ w = surface->w;
+ h = surface->h;
- switch (surface->buffer.transform)
- {
- case WL_OUTPUT_TRANSFORM_NORMAL:
- *bx = sx - surface->buffer.x;
- *by = sy - surface->buffer.y;
- break;
- case WL_OUTPUT_TRANSFORM_90:
- *bx = h - (sy - surface->buffer.y);
- *by = sx - surface->buffer.x;
- break;
- case WL_OUTPUT_TRANSFORM_180:
- *bx = w - (sx - surface->buffer.x);
- *by = h - (sy - surface->buffer.y);
- break;
- case WL_OUTPUT_TRANSFORM_270:
- *bx = sy - surface->buffer.y;
- *by = w - (sx - surface->buffer.x);
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED:
- *bx = w - (sx - surface->buffer.x);
- *by = sy - surface->buffer.y;
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- *bx = h - (sy - surface->buffer.y);
- *by = w - (sx - surface->buffer.x);
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_180:
- *bx = sx - surface->buffer.x;
- *by = h - (sy - surface->buffer.y);
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- *bx = sy - surface->buffer.y;
- *by = sx - surface->buffer.x;
- break;
- }
+ switch (surface->buffer.transform) {
+ case WL_OUTPUT_TRANSFORM_NORMAL:
+ *bx = sx - surface->buffer.x;
+ *by = sy - surface->buffer.y;
+ break;
+ case WL_OUTPUT_TRANSFORM_90:
+ *bx = h - (sy - surface->buffer.y);
+ *by = sx - surface->buffer.x;
+ break;
+ case WL_OUTPUT_TRANSFORM_180:
+ *bx = w - (sx - surface->buffer.x);
+ *by = h - (sy - surface->buffer.y);
+ break;
+ case WL_OUTPUT_TRANSFORM_270:
+ *bx = sy - surface->buffer.y;
+ *by = w - (sx - surface->buffer.x);
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED:
+ *bx = w - (sx - surface->buffer.x);
+ *by = sy - surface->buffer.y;
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+ *bx = h - (sy - surface->buffer.y);
+ *by = w - (sx - surface->buffer.x);
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+ *bx = sx - surface->buffer.x;
+ *by = h - (sy - surface->buffer.y);
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+ *bx = sy - surface->buffer.y;
+ *by = sx - surface->buffer.x;
+ break;
+ }
- if (scale != 1)
- {
- *bx *= scale;
- *by *= scale;
- }
+ if (scale != 1) {
+ *bx *= scale;
+ *by *= scale;
+ }
}
/* Calculate a matrix which transforms vertices into the output local space,
*/
static inline void
make_output_transform(pepper_mat4_t *mat,
- double s, /* scale */
- double a, double b, double c, double d, double e, double f, /* transform */
- double x, double y /* translate */)
+ double s, /* scale */
+ double a, double b, double c, double d, double e, double f, /* transform */
+ double x, double y /* translate */)
{
- double *m = &mat->m[0];
+ double *m = &mat->m[0];
- m[ 0] = s * a;
- m[ 1] = s * c;
- m[ 4] = s * b;
- m[ 5] = s * d;
- m[12] = s * (a * x + b * y + e);
- m[13] = s * (c * x + d * y + f);
+ m[ 0] = s * a;
+ m[ 1] = s * c;
+ m[ 4] = s * b;
+ m[ 5] = s * d;
+ m[12] = s * (a * x + b * y + e);
+ m[13] = s * (c * x + d * y + f);
- if (s != 1.0)
- mat->flags |= PEPPER_MATRIX_SCALE;
+ if (s != 1.0)
+ mat->flags |= PEPPER_MATRIX_SCALE;
- if (x != 0.0 || y != 0.0)
- mat->flags |= PEPPER_MATRIX_TRANSLATE;
+ if (x != 0.0 || y != 0.0)
+ mat->flags |= PEPPER_MATRIX_TRANSLATE;
- if (a != 1.0 || d != 1.0)
- mat->flags |= PEPPER_MATRIX_ROTATE;
+ if (a != 1.0 || d != 1.0)
+ mat->flags |= PEPPER_MATRIX_ROTATE;
}
void
-pepper_transform_global_to_output(pepper_mat4_t *transform, pepper_output_t *output)
+pepper_transform_global_to_output(pepper_mat4_t *transform,
+ pepper_output_t *output)
{
- pepper_mat4_t mat;
- double x = output->geometry.x;
- double y = output->geometry.y;
- double w = output->geometry.w;
- double h = output->geometry.h;
+ pepper_mat4_t mat;
+ double x = output->geometry.x;
+ double y = output->geometry.y;
+ double w = output->geometry.w;
+ double h = output->geometry.h;
- pepper_mat4_init_identity(&mat);
+ pepper_mat4_init_identity(&mat);
- switch (output->geometry.transform)
- {
- default:
- case WL_OUTPUT_TRANSFORM_NORMAL:
- make_output_transform(&mat, (double)output->scale, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, x, y);
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED:
- make_output_transform(&mat, (double)output->scale, -1.0, 0.0, 0.0, 1.0, w, 0.0, x, y);
- break;
- case WL_OUTPUT_TRANSFORM_90:
- make_output_transform(&mat, (double)output->scale, 0.0, -1.0, 1.0, 0.0, h, 0.0, x, y);
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- make_output_transform(&mat, (double)output->scale, 0.0, -1.0, -1.0, 0.0, h, w, x, y);
- break;
- case WL_OUTPUT_TRANSFORM_180:
- make_output_transform(&mat, (double)output->scale, -1.0, 0.0, 0.0, -1.0, w, h, x, y);
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_180:
- make_output_transform(&mat, (double)output->scale, 1.0, 0.0, 0.0, -1.0, 0.0, h, x, y);
- break;
- case WL_OUTPUT_TRANSFORM_270:
- make_output_transform(&mat, (double)output->scale, 0.0, 1.0, -1.0, 0.0, 0.0, w, x, y);
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- make_output_transform(&mat, (double)output->scale, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, x, y);
- break;
- }
+ switch (output->geometry.transform) {
+ default:
+ case WL_OUTPUT_TRANSFORM_NORMAL:
+ make_output_transform(&mat, (double)output->scale, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
+ x, y);
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED:
+ make_output_transform(&mat, (double)output->scale, -1.0, 0.0, 0.0, 1.0, w, 0.0,
+ x, y);
+ break;
+ case WL_OUTPUT_TRANSFORM_90:
+ make_output_transform(&mat, (double)output->scale, 0.0, -1.0, 1.0, 0.0, h, 0.0,
+ x, y);
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+ make_output_transform(&mat, (double)output->scale, 0.0, -1.0, -1.0, 0.0, h, w,
+ x, y);
+ break;
+ case WL_OUTPUT_TRANSFORM_180:
+ make_output_transform(&mat, (double)output->scale, -1.0, 0.0, 0.0, -1.0, w, h,
+ x, y);
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+ make_output_transform(&mat, (double)output->scale, 1.0, 0.0, 0.0, -1.0, 0.0, h,
+ x, y);
+ break;
+ case WL_OUTPUT_TRANSFORM_270:
+ make_output_transform(&mat, (double)output->scale, 0.0, 1.0, -1.0, 0.0, 0.0, w,
+ x, y);
+ break;
+ case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+ make_output_transform(&mat, (double)output->scale, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0,
+ x, y);
+ break;
+ }
- pepper_mat4_multiply(transform, &mat, transform);
+ pepper_mat4_multiply(transform, &mat, transform);
}
pepper_object_t *
pepper_object_alloc(pepper_object_type_t type, size_t size)
{
- pepper_object_t *object = calloc(1, size);
- PEPPER_CHECK(object, return NULL, "calloc() failed.\n");
- pepper_object_init(object, type);
- return object;
+ pepper_object_t *object = calloc(1, size);
+ PEPPER_CHECK(object, return NULL, "calloc() failed.\n");
+ pepper_object_init(object, type);
+ return object;
}
void
pepper_object_init(pepper_object_t *object, pepper_object_type_t type)
{
- object->type = type;
- pepper_list_init(&object->event_listener_list);
+ object->type = type;
+ pepper_list_init(&object->event_listener_list);
- pepper_map_pointer_init(&object->user_data_map, PEPPER_OBJECT_BUCKET_BITS, &object->buckets[0]);
+ pepper_map_pointer_init(&object->user_data_map, PEPPER_OBJECT_BUCKET_BITS,
+ &object->buckets[0]);
- if (!object_map)
- {
- pepper_id_allocator_init(&id_allocator);
+ if (!object_map) {
+ pepper_id_allocator_init(&id_allocator);
- object_map = pepper_map_int32_create(PEPPER_OBJECT_MAP_BUCKET_BITS);
- PEPPER_CHECK(object_map, return, "pepper_map_int32_create() failed.\n");
- }
+ object_map = pepper_map_int32_create(PEPPER_OBJECT_MAP_BUCKET_BITS);
+ PEPPER_CHECK(object_map, return, "pepper_map_int32_create() failed.\n");
+ }
- object->id = pepper_id_allocator_alloc(&id_allocator);
+ object->id = pepper_id_allocator_alloc(&id_allocator);
}
void
pepper_object_fini(pepper_object_t *object)
{
- pepper_event_listener_t *listener, *tmp;
+ pepper_event_listener_t *listener, *tmp;
- pepper_object_emit_event(object, PEPPER_EVENT_OBJECT_DESTROY, NULL);
- pepper_map_fini(&object->user_data_map);
+ pepper_object_emit_event(object, PEPPER_EVENT_OBJECT_DESTROY, NULL);
+ pepper_map_fini(&object->user_data_map);
- pepper_list_for_each_safe(listener, tmp, &object->event_listener_list, link)
- pepper_event_listener_remove(listener);
+ pepper_list_for_each_safe(listener, tmp, &object->event_listener_list, link)
+ pepper_event_listener_remove(listener);
- pepper_map_set(object_map, &object->id, NULL, NULL);
- pepper_id_allocator_free(&id_allocator, object->id);
+ pepper_map_set(object_map, &object->id, NULL, NULL);
+ pepper_id_allocator_free(&id_allocator, object->id);
}
/**
PEPPER_API pepper_object_type_t
pepper_object_get_type(pepper_object_t *object)
{
- return object->type;
+ return object->type;
}
/**
* @see pepper_object_get_user_data()
*/
PEPPER_API void
-pepper_object_set_user_data(pepper_object_t *object, const void *key, void *data,
- pepper_free_func_t free_func)
+pepper_object_set_user_data(pepper_object_t *object, const void *key,
+ void *data,
+ pepper_free_func_t free_func)
{
- pepper_map_set(&object->user_data_map, key, data, free_func);
+ pepper_map_set(&object->user_data_map, key, data, free_func);
}
/**
PEPPER_API void *
pepper_object_get_user_data(pepper_object_t *object, const void *key)
{
- return pepper_map_get(&object->user_data_map, key);
+ return pepper_map_get(&object->user_data_map, key);
}
static void
insert_listener(pepper_object_t *object, pepper_event_listener_t *listener)
{
- pepper_event_listener_t *pos;
-
- pepper_list_for_each(pos, &object->event_listener_list, link)
- {
- if (listener->priority >= pos->priority)
- {
- pepper_list_insert(pos->link.prev, &listener->link);
- break;
- }
- }
-
- if (!listener->link.next)
- pepper_list_insert(object->event_listener_list.prev, &listener->link);
+ pepper_event_listener_t *pos;
+
+ pepper_list_for_each(pos, &object->event_listener_list, link) {
+ if (listener->priority >= pos->priority) {
+ pepper_list_insert(pos->link.prev, &listener->link);
+ break;
+ }
+ }
+
+ if (!listener->link.next)
+ pepper_list_insert(object->event_listener_list.prev, &listener->link);
}
/**
* @see pepper_event_listener_set_priority()
*/
PEPPER_API pepper_event_listener_t *
-pepper_object_add_event_listener(pepper_object_t *object, uint32_t id, int priority,
- pepper_event_callback_t callback, void *data)
+pepper_object_add_event_listener(pepper_object_t *object, uint32_t id,
+ int priority,
+ pepper_event_callback_t callback, void *data)
{
- pepper_event_listener_t *listener;
+ pepper_event_listener_t *listener;
- PEPPER_CHECK(callback, return NULL, "callback must be given.\n");
+ PEPPER_CHECK(callback, return NULL, "callback must be given.\n");
- listener = calloc(1, sizeof(pepper_event_listener_t));
- PEPPER_CHECK(listener, return NULL, "calloc() failed.\n");
+ listener = calloc(1, sizeof(pepper_event_listener_t));
+ PEPPER_CHECK(listener, return NULL, "calloc() failed.\n");
- listener->object = object;
- listener->id = id;
- listener->priority = priority;
- listener->callback = callback;
- listener->data = data;
+ listener->object = object;
+ listener->id = id;
+ listener->priority = priority;
+ listener->callback = callback;
+ listener->data = data;
- insert_listener(object, listener);
- return listener;
+ insert_listener(object, listener);
+ return listener;
}
/**
PEPPER_API void
pepper_event_listener_remove(pepper_event_listener_t *listener)
{
- pepper_list_remove(&listener->link);
- free(listener);
+ pepper_list_remove(&listener->link);
+ free(listener);
}
/**
* @param priority priority (higher priority called earlier)
*/
PEPPER_API void
-pepper_event_listener_set_priority(pepper_event_listener_t *listener, int priority)
+pepper_event_listener_set_priority(pepper_event_listener_t *listener,
+ int priority)
{
- if (!listener->object)
- return;
+ if (!listener->object)
+ return;
- listener->priority = priority;
- pepper_list_remove(&listener->link);
- insert_listener(listener->object, listener);
+ listener->priority = priority;
+ pepper_list_remove(&listener->link);
+ insert_listener(listener->object, listener);
}
/**
PEPPER_API void
pepper_object_emit_event(pepper_object_t *object, uint32_t id, void *info)
{
- pepper_event_listener_t *listener, *tmp;
+ pepper_event_listener_t *listener, *tmp;
- PEPPER_CHECK(id != PEPPER_EVENT_ALL, return, "Cannot emit the PEPPER_EVENT_ALL event");
+ PEPPER_CHECK(id != PEPPER_EVENT_ALL, return,
+ "Cannot emit the PEPPER_EVENT_ALL event");
- pepper_list_for_each_safe(listener, tmp, &object->event_listener_list, link)
- {
- if (listener->id == PEPPER_EVENT_ALL || listener->id == id)
- listener->callback(listener, object, id, info, listener->data);
- }
+ pepper_list_for_each_safe(listener, tmp, &object->event_listener_list, link) {
+ if (listener->id == PEPPER_EVENT_ALL || listener->id == id)
+ listener->callback(listener, object, id, info, listener->data);
+ }
}
/**
PEPPER_API uint32_t
pepper_object_get_id(pepper_object_t *object)
{
- return object->id;
+ return object->id;
}
/**
PEPPER_API pepper_object_t *
pepper_object_from_id(uint32_t id)
{
- return (pepper_object_t *)pepper_map_get(object_map, &id);
+ return (pepper_object_t *)pepper_map_get(object_map, &id);
}
static void
output_send_modes(pepper_output_t *output, struct wl_resource *resource)
{
- int i;
- int mode_count = output->backend->get_mode_count(output->data);
+ int i;
+ int mode_count = output->backend->get_mode_count(output->data);
- for (i = 0; i < mode_count; i++)
- {
- pepper_output_mode_t mode;
+ for (i = 0; i < mode_count; i++) {
+ pepper_output_mode_t mode;
- output->backend->get_mode(output->data, i, &mode);
- wl_output_send_mode(resource, mode.flags, mode.w, mode.h, mode.refresh);
- }
+ output->backend->get_mode(output->data, i, &mode);
+ wl_output_send_mode(resource, mode.flags, mode.w, mode.h, mode.refresh);
+ }
- wl_output_send_done(resource);
+ wl_output_send_done(resource);
}
static void
output_update_mode(pepper_output_t *output)
{
- struct wl_resource *resource;
- int i;
- int mode_count = output->backend->get_mode_count(output->data);
-
- for (i = 0; i < mode_count; i++)
- {
- pepper_output_mode_t mode;
-
- output->backend->get_mode(output->data, i, &mode);
-
- if (mode.flags & WL_OUTPUT_MODE_CURRENT)
- {
- output->current_mode = mode;
- output->geometry.w = mode.w;
- output->geometry.h = mode.h;
-
- wl_resource_for_each(resource, &output->resource_list)
- {
- wl_output_send_mode(resource, mode.flags, mode.w, mode.h, mode.refresh);
- wl_output_send_done(resource);
- }
- }
- }
+ struct wl_resource *resource;
+ int i;
+ int mode_count = output->backend->get_mode_count(output->data);
+
+ for (i = 0; i < mode_count; i++) {
+ pepper_output_mode_t mode;
+
+ output->backend->get_mode(output->data, i, &mode);
+
+ if (mode.flags & WL_OUTPUT_MODE_CURRENT) {
+ output->current_mode = mode;
+ output->geometry.w = mode.w;
+ output->geometry.h = mode.h;
+
+ wl_resource_for_each(resource, &output->resource_list) {
+ wl_output_send_mode(resource, mode.flags, mode.w, mode.h, mode.refresh);
+ wl_output_send_done(resource);
+ }
+ }
+ }
}
static void
output_send_geometry(pepper_output_t *output)
{
- struct wl_resource *resource;
-
- wl_resource_for_each(resource, &output->resource_list)
- {
- wl_output_send_geometry(resource,
- output->geometry.x, output->geometry.y,
- output->geometry.w, output->geometry.h,
- output->geometry.subpixel,
- output->geometry.maker, output->geometry.model,
- output->geometry.transform);
- }
+ struct wl_resource *resource;
+
+ wl_resource_for_each(resource, &output->resource_list) {
+ wl_output_send_geometry(resource,
+ output->geometry.x, output->geometry.y,
+ output->geometry.w, output->geometry.h,
+ output->geometry.subpixel,
+ output->geometry.maker, output->geometry.model,
+ output->geometry.transform);
+ }
}
static void
output_destroy(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
static void
output_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
- struct wl_resource *resource;
- pepper_output_t *output = (pepper_output_t *)data;
-
- resource = wl_resource_create(client, &wl_output_interface, 2, id);
- if (resource == NULL)
- {
- wl_client_post_no_memory(client);
- return;
- }
-
- wl_list_insert(&output->resource_list, wl_resource_get_link(resource));
- wl_resource_set_implementation(resource, NULL, NULL, output_destroy);
-
- wl_output_send_geometry(resource,
- output->geometry.x, output->geometry.y,
- output->geometry.w, output->geometry.h,
- output->geometry.subpixel,
- output->geometry.maker, output->geometry.model,
- output->geometry.transform);
-
- wl_output_send_scale(resource, output->scale);
- output_send_modes(output, resource);
+ struct wl_resource *resource;
+ pepper_output_t *output = (pepper_output_t *)data;
+
+ resource = wl_resource_create(client, &wl_output_interface, 2, id);
+ if (resource == NULL) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_list_insert(&output->resource_list, wl_resource_get_link(resource));
+ wl_resource_set_implementation(resource, NULL, NULL, output_destroy);
+
+ wl_output_send_geometry(resource,
+ output->geometry.x, output->geometry.y,
+ output->geometry.w, output->geometry.h,
+ output->geometry.subpixel,
+ output->geometry.maker, output->geometry.model,
+ output->geometry.transform);
+
+ wl_output_send_scale(resource, output->scale);
+ output_send_modes(output, resource);
}
static void
output_update_planes(pepper_output_t *output)
{
- pepper_plane_t *plane;
- pixman_region32_t clip;
+ pepper_plane_t *plane;
+ pixman_region32_t clip;
- pixman_region32_init(&clip);
+ pixman_region32_init(&clip);
- pepper_list_for_each_reverse(plane, &output->plane_list, link)
- pepper_plane_update(plane, &output->view_list, &clip);
+ pepper_list_for_each_reverse(plane, &output->plane_list, link)
+ pepper_plane_update(plane, &output->view_list, &clip);
- pixman_region32_fini(&clip);
+ pixman_region32_fini(&clip);
}
static void
output_repaint(pepper_output_t *output)
{
- pepper_view_t *view;
-
- pepper_list_for_each(view, &output->compositor->view_list, compositor_link)
- pepper_view_update(view);
-
- pepper_list_init(&output->view_list);
-
- /* Build a list of views in sorted z-order that are visible on the given output. */
- pepper_list_for_each(view, &output->compositor->view_list, compositor_link)
- {
- if (!view->active || !(view->output_overlap & (1 << output->id)) || !view->surface)
- {
- /* Detach from the previously assigned plane. */
- pepper_view_assign_plane(view, output, NULL);
- continue;
- }
-
- pepper_list_insert(output->view_list.prev, &view->link);
- }
-
- output->backend->assign_planes(output->data, &output->view_list);
- output_update_planes(output);
- output->backend->repaint(output->data, &output->plane_list);
-
- output->frame.pending = PEPPER_TRUE;
- output->frame.scheduled = PEPPER_FALSE;
-
- pepper_list_for_each(view, &output->view_list, link)
- {
- /* TODO: Output time stamp and presentation feedback. */
- pepper_surface_send_frame_callback_done(view->surface,
- output->frame.time.tv_sec * 1000 +
- output->frame.time.tv_nsec / 1000000);
- }
+ pepper_view_t *view;
+
+ pepper_list_for_each(view, &output->compositor->view_list, compositor_link)
+ pepper_view_update(view);
+
+ pepper_list_init(&output->view_list);
+
+ /* Build a list of views in sorted z-order that are visible on the given output. */
+ pepper_list_for_each(view, &output->compositor->view_list, compositor_link) {
+ if (!view->active || !(view->output_overlap & (1 << output->id)) ||
+ !view->surface) {
+ /* Detach from the previously assigned plane. */
+ pepper_view_assign_plane(view, output, NULL);
+ continue;
+ }
+
+ pepper_list_insert(output->view_list.prev, &view->link);
+ }
+
+ output->backend->assign_planes(output->data, &output->view_list);
+ output_update_planes(output);
+ output->backend->repaint(output->data, &output->plane_list);
+
+ output->frame.pending = PEPPER_TRUE;
+ output->frame.scheduled = PEPPER_FALSE;
+
+ pepper_list_for_each(view, &output->view_list, link) {
+ /* TODO: Output time stamp and presentation feedback. */
+ pepper_surface_send_frame_callback_done(view->surface,
+ output->frame.time.tv_sec * 1000 +
+ output->frame.time.tv_nsec / 1000000);
+ }
}
static void
idle_repaint(void *data)
{
- pepper_output_t *output = data;
- output->backend->start_repaint_loop(output->data);
+ pepper_output_t *output = data;
+ output->backend->start_repaint_loop(output->data);
}
void
pepper_output_schedule_repaint(pepper_output_t *output)
{
- struct wl_event_loop *loop;
+ struct wl_event_loop *loop;
- if (output->frame.scheduled)
- return;
+ if (output->frame.scheduled)
+ return;
- output->frame.scheduled = PEPPER_TRUE;
+ output->frame.scheduled = PEPPER_TRUE;
- if (output->frame.pending)
- return;
+ if (output->frame.pending)
+ return;
- /* Schedule on the next idle loop so that it can accumulate surface commits. */
- loop = wl_display_get_event_loop(output->compositor->display);
- wl_event_loop_add_idle(loop, idle_repaint, output);
+ /* Schedule on the next idle loop so that it can accumulate surface commits. */
+ loop = wl_display_get_event_loop(output->compositor->display);
+ wl_event_loop_add_idle(loop, idle_repaint, output);
}
/**
* If the damage region is NULL, entire output area is marked as damaged.
*/
PEPPER_API void
-pepper_output_add_damage_region(pepper_output_t *output, pixman_region32_t *region)
+pepper_output_add_damage_region(pepper_output_t *output,
+ pixman_region32_t *region)
{
- pepper_plane_t *plane;
- pepper_list_for_each(plane, &output->plane_list, link)
- pepper_plane_add_damage_region(plane, region);
+ pepper_plane_t *plane;
+ pepper_list_for_each(plane, &output->plane_list, link)
+ pepper_plane_add_damage_region(plane, region);
}
/**
PEPPER_API void
pepper_output_finish_frame(pepper_output_t *output, struct timespec *ts)
{
- struct timespec time;
+ struct timespec time;
- output->frame.pending = PEPPER_FALSE;
+ output->frame.pending = PEPPER_FALSE;
- if (ts)
- time = *ts;
- else
- pepper_compositor_get_time(output->compositor, &time);
+ if (ts)
+ time = *ts;
+ else
+ pepper_compositor_get_time(output->compositor, &time);
- if (output->frame.print_fps)
- {
- if (output->frame.count > 0)
- {
- uint32_t tick = (time.tv_sec - output->frame.time.tv_sec) * 1000 +
- (time.tv_nsec - output->frame.time.tv_nsec) / 1000000;
- uint32_t tick_count;
+ if (output->frame.print_fps) {
+ if (output->frame.count > 0) {
+ uint32_t tick = (time.tv_sec - output->frame.time.tv_sec) * 1000 +
+ (time.tv_nsec - output->frame.time.tv_nsec) / 1000000;
+ uint32_t tick_count;
- output->frame.total_time += tick;
- output->frame.total_time -= output->frame.ticks[output->frame.tick_index];
- output->frame.ticks[output->frame.tick_index] = tick;
+ output->frame.total_time += tick;
+ output->frame.total_time -= output->frame.ticks[output->frame.tick_index];
+ output->frame.ticks[output->frame.tick_index] = tick;
- if (++output->frame.tick_index == PEPPER_OUTPUT_MAX_TICK_COUNT)
- output->frame.tick_index = 0;
+ if (++output->frame.tick_index == PEPPER_OUTPUT_MAX_TICK_COUNT)
+ output->frame.tick_index = 0;
- if (output->frame.count < PEPPER_OUTPUT_MAX_TICK_COUNT)
- tick_count = output->frame.count;
- else
- tick_count = PEPPER_OUTPUT_MAX_TICK_COUNT;
+ if (output->frame.count < PEPPER_OUTPUT_MAX_TICK_COUNT)
+ tick_count = output->frame.count;
+ else
+ tick_count = PEPPER_OUTPUT_MAX_TICK_COUNT;
- PEPPER_TRACE("%s FPS : %.2f\n", output->name,
- (double)(tick_count * 1000) / (double)output->frame.total_time);
- }
- }
+ PEPPER_TRACE("%s FPS : %.2f\n", output->name,
+ (double)(tick_count * 1000) / (double)output->frame.total_time);
+ }
+ }
- output->frame.count++;
- output->frame.time = time;
+ output->frame.count++;
+ output->frame.time = time;
- if (output->frame.scheduled)
- output_repaint(output);
+ if (output->frame.scheduled)
+ output_repaint(output);
}
/**
PEPPER_API void
pepper_output_update_mode(pepper_output_t *output)
{
- output_update_mode(output);
- pepper_object_emit_event(&output->base, PEPPER_EVENT_OUTPUT_MODE_CHANGE, NULL);
+ output_update_mode(output);
+ pepper_object_emit_event(&output->base, PEPPER_EVENT_OUTPUT_MODE_CHANGE, NULL);
}
/**
*/
PEPPER_API pepper_output_t *
pepper_compositor_add_output(pepper_compositor_t *compositor,
- const pepper_output_backend_t *backend, const char *name, void *data,
- int transform, int scale)
+ const pepper_output_backend_t *backend, const char *name, void *data,
+ int transform, int scale)
{
- pepper_output_t *output;
- uint32_t id;
- const char *str;
-
- PEPPER_CHECK(name, return NULL, "Output name must be given.\n");
-
- pepper_list_for_each(output, &compositor->output_list, link)
- {
- PEPPER_CHECK(strcmp(output->name, name) != 0, return NULL,
- "Output with name = %s already exist.\n", name);
- }
-
- id = ffs(~compositor->output_id_allocator);
- PEPPER_CHECK(id != 0, return NULL, "No available output ids.\n");
-
- id = id - 1;
-
- output = (pepper_output_t *)pepper_object_alloc(PEPPER_OBJECT_OUTPUT, sizeof(pepper_output_t));
- PEPPER_CHECK(output, return NULL, "pepper_object_alloc() failed.\n");
-
- output->compositor = compositor;
- output->link.item = output;
- wl_list_init(&output->resource_list);
-
- /* Create global object for this output. */
- output->global = wl_global_create(compositor->display, &wl_output_interface, 2, output,
- output_bind);
- if (!output->global)
- {
- free(output);
- return NULL;
- }
-
- output->id = id;
- compositor->output_id_allocator |= (1 << output->id);
- output->name = strdup(name);
-
- /* Create backend-side object. */
- output->backend = (pepper_output_backend_t *)backend;
- output->data = data;
-
- /* Initialize output modes. */
- output_update_mode(output);
-
- /* Initialize geometry. */
- output->geometry.transform = transform;
- output->scale = scale;
- output->geometry.subpixel = backend->get_subpixel_order(data);
- output->geometry.maker = backend->get_maker_name(data);
- output->geometry.model = backend->get_model_name(data);
- output->geometry.x = 0;
- output->geometry.y = 0;
-
- switch (transform)
- {
- case WL_OUTPUT_TRANSFORM_90:
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- case WL_OUTPUT_TRANSFORM_270:
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- output->geometry.w = output->current_mode.h / scale;
- output->geometry.h = output->current_mode.w / scale;
- break;
- default:
- output->geometry.w = output->current_mode.w / scale;
- output->geometry.h = output->current_mode.h / scale;
- break;
- }
-
- pepper_list_insert(&compositor->output_list, &output->link);
- pepper_list_init(&output->plane_list);
-
- /* FPS */
- str = getenv("PEPPER_DEBUG_FPS");
- if (str && atoi(str) != 0)
- output->frame.print_fps = PEPPER_TRUE;
-
- pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_OUTPUT_ADD, output);
- return output;
+ pepper_output_t *output;
+ uint32_t id;
+ const char *str;
+
+ PEPPER_CHECK(name, return NULL, "Output name must be given.\n");
+
+ pepper_list_for_each(output, &compositor->output_list, link) {
+ PEPPER_CHECK(strcmp(output->name, name) != 0, return NULL,
+ "Output with name = %s already exist.\n", name);
+ }
+
+ id = ffs(~compositor->output_id_allocator);
+ PEPPER_CHECK(id != 0, return NULL, "No available output ids.\n");
+
+ id = id - 1;
+
+ output = (pepper_output_t *)pepper_object_alloc(PEPPER_OBJECT_OUTPUT,
+ sizeof(pepper_output_t));
+ PEPPER_CHECK(output, return NULL, "pepper_object_alloc() failed.\n");
+
+ output->compositor = compositor;
+ output->link.item = output;
+ wl_list_init(&output->resource_list);
+
+ /* Create global object for this output. */
+ output->global = wl_global_create(compositor->display, &wl_output_interface, 2,
+ output,
+ output_bind);
+ if (!output->global) {
+ free(output);
+ return NULL;
+ }
+
+ output->id = id;
+ compositor->output_id_allocator |= (1 << output->id);
+ output->name = strdup(name);
+
+ /* Create backend-side object. */
+ output->backend = (pepper_output_backend_t *)backend;
+ output->data = data;
+
+ /* Initialize output modes. */
+ output_update_mode(output);
+
+ /* Initialize geometry. */
+ output->geometry.transform = transform;
+ output->scale = scale;
+ output->geometry.subpixel = backend->get_subpixel_order(data);
+ output->geometry.maker = backend->get_maker_name(data);
+ output->geometry.model = backend->get_model_name(data);
+ output->geometry.x = 0;
+ output->geometry.y = 0;
+
+ switch (transform) {
+ case WL_OUTPUT_TRANSFORM_90:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+ case WL_OUTPUT_TRANSFORM_270:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+ output->geometry.w = output->current_mode.h / scale;
+ output->geometry.h = output->current_mode.w / scale;
+ break;
+ default:
+ output->geometry.w = output->current_mode.w / scale;
+ output->geometry.h = output->current_mode.h / scale;
+ break;
+ }
+
+ pepper_list_insert(&compositor->output_list, &output->link);
+ pepper_list_init(&output->plane_list);
+
+ /* FPS */
+ str = getenv("PEPPER_DEBUG_FPS");
+ if (str && atoi(str) != 0)
+ output->frame.print_fps = PEPPER_TRUE;
+
+ pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_OUTPUT_ADD,
+ output);
+ return output;
}
/**
PEPPER_API pepper_compositor_t *
pepper_output_get_compositor(pepper_output_t *output)
{
- return output->compositor;
+ return output->compositor;
}
/**
PEPPER_API void
pepper_output_destroy(pepper_output_t *output)
{
- pepper_object_emit_event(&output->compositor->base,
- PEPPER_EVENT_COMPOSITOR_OUTPUT_REMOVE, output);
- pepper_object_fini(&output->base);
+ pepper_object_emit_event(&output->compositor->base,
+ PEPPER_EVENT_COMPOSITOR_OUTPUT_REMOVE, output);
+ pepper_object_fini(&output->base);
- output->compositor->output_id_allocator &= ~(1 << output->id);
- pepper_list_remove(&output->link);
- output->backend->destroy(output->data);
- wl_global_destroy(output->global);
+ output->compositor->output_id_allocator &= ~(1 << output->id);
+ pepper_list_remove(&output->link);
+ output->backend->destroy(output->data);
+ wl_global_destroy(output->global);
- free(output->name);
- free(output);
+ free(output->name);
+ free(output);
}
/**
PEPPER_API struct wl_list *
pepper_output_get_resource_list(pepper_output_t *output)
{
- return &output->resource_list;
+ return &output->resource_list;
}
/**
PEPPER_API void
pepper_output_move(pepper_output_t *output, int32_t x, int32_t y)
{
- if ((output->geometry.x != x) || (output->geometry.y != y))
- {
- output->geometry.x = x;
- output->geometry.y = y;
+ if ((output->geometry.x != x) || (output->geometry.y != y)) {
+ output->geometry.x = x;
+ output->geometry.y = y;
- /* TODO: pepper_output_add_damage_whole(out); */
+ /* TODO: pepper_output_add_damage_whole(out); */
- output_send_geometry(output);
- pepper_object_emit_event(&output->base, PEPPER_EVENT_OUTPUT_MOVE, NULL);
- }
+ output_send_geometry(output);
+ pepper_object_emit_event(&output->base, PEPPER_EVENT_OUTPUT_MOVE, NULL);
+ }
}
/**
PEPPER_API const pepper_output_geometry_t *
pepper_output_get_geometry(pepper_output_t *output)
{
- return &output->geometry;
+ return &output->geometry;
}
/**
PEPPER_API int32_t
pepper_output_get_scale(pepper_output_t *output)
{
- return output->scale;
+ return output->scale;
}
/**
PEPPER_API int
pepper_output_get_mode_count(pepper_output_t *output)
{
- return output->backend->get_mode_count(output->data);
+ return output->backend->get_mode_count(output->data);
}
/**
* @param mode pointer to receive the mode info
*/
PEPPER_API void
-pepper_output_get_mode(pepper_output_t *output, int index, pepper_output_mode_t *mode)
+pepper_output_get_mode(pepper_output_t *output, int index,
+ pepper_output_mode_t *mode)
{
- return output->backend->get_mode(output->data, index, mode);
+ return output->backend->get_mode(output->data, index, mode);
}
/**
PEPPER_API const pepper_output_mode_t *
pepper_output_get_current_mode(pepper_output_t *output)
{
- return &output->current_mode;
+ return &output->current_mode;
}
/**
* modes for some output backends like x11 and wayland backend.
*/
PEPPER_API pepper_bool_t
-pepper_output_set_mode(pepper_output_t *output, const pepper_output_mode_t *mode)
+pepper_output_set_mode(pepper_output_t *output,
+ const pepper_output_mode_t *mode)
{
- if (output->current_mode.w == mode->w && output->current_mode.h == mode->h &&
- output->current_mode.refresh == mode->refresh)
- return PEPPER_TRUE;
+ if (output->current_mode.w == mode->w && output->current_mode.h == mode->h &&
+ output->current_mode.refresh == mode->refresh)
+ return PEPPER_TRUE;
- if (output->backend->set_mode(output->data, mode))
- {
- /* TODO: pepper_output_add_damage_whole(out); */
- return PEPPER_TRUE;
- }
+ if (output->backend->set_mode(output->data, mode)) {
+ /* TODO: pepper_output_add_damage_whole(out); */
+ return PEPPER_TRUE;
+ }
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
/**
PEPPER_API const char *
pepper_output_get_name(pepper_output_t *output)
{
- return output->name;
+ return output->name;
}
/**
PEPPER_API pepper_output_t *
pepper_compositor_find_output(pepper_compositor_t *compositor, const char *name)
{
- pepper_output_t *output;
+ pepper_output_t *output;
- pepper_list_for_each(output, &compositor->output_list, link)
- {
- if (strcmp(output->name, name) == 0)
- return output;
- }
+ pepper_list_for_each(output, &compositor->output_list, link) {
+ if (strcmp(output->name, name) == 0)
+ return output;
+ }
- return NULL;
+ return NULL;
}
*/
typedef struct pepper_input_device_backend pepper_input_device_backend_t;
-struct pepper_input_device_backend
-{
- /**
- * Get property of the device corresponding to the key.
- *
- * @param device device
- * @param key key string
- *
- * @returns property string
- */
- const char * (*get_property)(void *device, const char *key);
+struct pepper_input_device_backend {
+ /**
+ * Get property of the device corresponding to the key.
+ *
+ * @param device device
+ * @param key key string
+ *
+ * @returns property string
+ */
+ const char *(*get_property)(void *device, const char *key);
};
PEPPER_API pepper_input_device_t *
pepper_input_device_create(pepper_compositor_t *compositor, uint32_t caps,
- const pepper_input_device_backend_t *backend, void *data);
+ const pepper_input_device_backend_t *backend, void *data);
PEPPER_API void
pepper_input_device_destroy(pepper_input_device_t *device);
typedef struct pepper_input pepper_input_t;
typedef struct pepper_touch_point pepper_touch_point_t;
-struct pepper_object
-{
- pepper_object_type_t type;
- uint32_t id;
- pepper_map_t user_data_map;
- pepper_map_entry_t *buckets[1 << PEPPER_OBJECT_BUCKET_BITS];
- pepper_list_t event_listener_list;
+struct pepper_object {
+ pepper_object_type_t type;
+ uint32_t id;
+ pepper_map_t user_data_map;
+ pepper_map_entry_t *buckets[1 << PEPPER_OBJECT_BUCKET_BITS];
+ pepper_list_t event_listener_list;
};
pepper_object_t *
void
pepper_object_fini(pepper_object_t *object);
-struct pepper_event_listener
-{
- pepper_object_t *object;
- uint32_t id;
- int priority;
- pepper_event_callback_t callback;
- void *data;
+struct pepper_event_listener {
+ pepper_object_t *object;
+ uint32_t id;
+ int priority;
+ pepper_event_callback_t callback;
+ void *data;
- pepper_list_t link;
+ pepper_list_t link;
};
/* compositor */
-struct pepper_compositor
-{
- pepper_object_t base;
- char *socket_name;
- struct wl_display *display;
- struct wl_global *global;
- struct wl_list resource_list;
-
- pepper_list_t surface_list;
- pepper_list_t region_list;
- pepper_list_t seat_list;
- pepper_list_t output_list;
- pepper_list_t view_list;
- pepper_list_t input_device_list;
- pepper_subcompositor_t *subcomp;
-
- uint32_t output_id_allocator;
- pepper_bool_t update_scheduled;
-
- clockid_t clock_id;
- pepper_bool_t clock_used;
-
- struct sockaddr_un addr;
+struct pepper_compositor {
+ pepper_object_t base;
+ char *socket_name;
+ struct wl_display *display;
+ struct wl_global *global;
+ struct wl_list resource_list;
+
+ pepper_list_t surface_list;
+ pepper_list_t region_list;
+ pepper_list_t seat_list;
+ pepper_list_t output_list;
+ pepper_list_t view_list;
+ pepper_list_t input_device_list;
+ pepper_subcompositor_t *subcomp;
+
+ uint32_t output_id_allocator;
+ pepper_bool_t update_scheduled;
+
+ clockid_t clock_id;
+ pepper_bool_t clock_used;
+
+ struct sockaddr_un addr;
};
void
pepper_compositor_schedule_repaint(pepper_compositor_t *compositor);
-struct pepper_output
-{
- pepper_object_t base;
- pepper_compositor_t *compositor;
- uint32_t id;
- char *name;
-
- struct wl_global *global;
- struct wl_list resource_list;
- pepper_list_t link;
-
- pepper_output_geometry_t geometry;
- int32_t scale;
-
- pepper_output_mode_t current_mode;
-
- /* Backend-specific variables. */
- pepper_output_backend_t *backend;
- void *data;
-
- /* Frame state flags. */
- struct {
- pepper_bool_t scheduled;
- pepper_bool_t pending;
- struct timespec time;
- uint32_t count;
-
- /* For FPS measuring */
- pepper_bool_t print_fps;
- uint32_t ticks[PEPPER_OUTPUT_MAX_TICK_COUNT];
- int tick_index;
- uint32_t total_time;
- } frame;
-
- pepper_list_t plane_list;
- pepper_list_t view_list;
+struct pepper_output {
+ pepper_object_t base;
+ pepper_compositor_t *compositor;
+ uint32_t id;
+ char *name;
+
+ struct wl_global *global;
+ struct wl_list resource_list;
+ pepper_list_t link;
+
+ pepper_output_geometry_t geometry;
+ int32_t scale;
+
+ pepper_output_mode_t current_mode;
+
+ /* Backend-specific variables. */
+ pepper_output_backend_t *backend;
+ void *data;
+
+ /* Frame state flags. */
+ struct {
+ pepper_bool_t scheduled;
+ pepper_bool_t pending;
+ struct timespec time;
+ uint32_t count;
+
+ /* For FPS measuring */
+ pepper_bool_t print_fps;
+ uint32_t ticks[PEPPER_OUTPUT_MAX_TICK_COUNT];
+ int tick_index;
+ uint32_t total_time;
+ } frame;
+
+ pepper_list_t plane_list;
+ pepper_list_t view_list;
};
void
pepper_output_schedule_repaint(pepper_output_t *output);
-struct pepper_buffer
-{
- pepper_object_t base;
- struct wl_resource *resource;
+struct pepper_buffer {
+ pepper_object_t base;
+ struct wl_resource *resource;
- int ref_count;
- struct wl_listener resource_destroy_listener;
+ int ref_count;
+ struct wl_listener resource_destroy_listener;
- /* the buffer size is unknown until it is actually attached to a renderer. */
- int32_t w, h;
- pepper_bool_t attached;
+ /* the buffer size is unknown until it is actually attached to a renderer. */
+ int32_t w, h;
+ pepper_bool_t attached;
};
pepper_buffer_t *
pepper_buffer_from_resource(struct wl_resource *resource);
-struct pepper_surface_state
-{
- pepper_buffer_t *buffer;
- int32_t x;
- int32_t y;
- pepper_bool_t newly_attached;
+struct pepper_surface_state {
+ pepper_buffer_t *buffer;
+ int32_t x;
+ int32_t y;
+ pepper_bool_t newly_attached;
- int32_t transform;
- int32_t scale;
+ int32_t transform;
+ int32_t scale;
- pixman_region32_t damage_region;
- pixman_region32_t opaque_region;
- pixman_region32_t input_region;
+ pixman_region32_t damage_region;
+ pixman_region32_t opaque_region;
+ pixman_region32_t input_region;
- struct wl_list frame_callback_list;
- pepper_event_listener_t *buffer_destroy_listener;
+ struct wl_list frame_callback_list;
+ pepper_event_listener_t *buffer_destroy_listener;
};
void
void
pepper_surface_state_fini(pepper_surface_state_t *state);
-struct pepper_surface
-{
- pepper_object_t base;
- pepper_compositor_t *compositor;
- struct wl_resource *resource;
- pepper_list_t link;
-
- struct {
- pepper_buffer_t *buffer;
- pepper_bool_t has_ref;
- pepper_event_listener_t *destroy_listener;
- int32_t x, y;
- int32_t transform;
- int32_t scale;
- } buffer;
-
- /* Surface size in surface local coordinate space.
- * Buffer is transformed and scaled into surface local coordinate space. */
- int32_t w, h;
-
- pixman_region32_t damage_region;
- pixman_region32_t opaque_region;
- pixman_region32_t input_region;
- pepper_bool_t pickable;
-
- struct wl_list frame_callback_list;
-
- /* Surface states. wl_surface.commit will apply the pending state into current. */
- pepper_surface_state_t pending;
-
- char *role;
- pepper_list_t view_list;
-
- pepper_list_t subsurface_list;
- pepper_list_t subsurface_pending_list;
- pepper_subsurface_t *sub;
+struct pepper_surface {
+ pepper_object_t base;
+ pepper_compositor_t *compositor;
+ struct wl_resource *resource;
+ pepper_list_t link;
+
+ struct {
+ pepper_buffer_t *buffer;
+ pepper_bool_t has_ref;
+ pepper_event_listener_t *destroy_listener;
+ int32_t x, y;
+ int32_t transform;
+ int32_t scale;
+ } buffer;
+
+ /* Surface size in surface local coordinate space.
+ * Buffer is transformed and scaled into surface local coordinate space. */
+ int32_t w, h;
+
+ pixman_region32_t damage_region;
+ pixman_region32_t opaque_region;
+ pixman_region32_t input_region;
+ pepper_bool_t pickable;
+
+ struct wl_list frame_callback_list;
+
+ /* Surface states. wl_surface.commit will apply the pending state into current. */
+ pepper_surface_state_t pending;
+
+ char *role;
+ pepper_list_t view_list;
+
+ pepper_list_t subsurface_list;
+ pepper_list_t subsurface_pending_list;
+ pepper_subsurface_t *sub;
};
pepper_surface_t *
pepper_surface_create(pepper_compositor_t *compositor,
- struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id);
+ struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id);
void
pepper_surface_destroy(pepper_surface_t *surface);
pepper_surface_commit(pepper_surface_t *surface);
void
-pepper_surface_commit_state(pepper_surface_t *surface, pepper_surface_state_t *state);
+pepper_surface_commit_state(pepper_surface_t *surface,
+ pepper_surface_state_t *state);
void
-pepper_surface_send_frame_callback_done(pepper_surface_t *surface, uint32_t time);
+pepper_surface_send_frame_callback_done(pepper_surface_t *surface,
+ uint32_t time);
-struct pepper_region
-{
- pepper_object_t base;
- pepper_compositor_t *compositor;
- struct wl_resource *resource;
- pepper_list_t link;
+struct pepper_region {
+ pepper_object_t base;
+ pepper_compositor_t *compositor;
+ struct wl_resource *resource;
+ pepper_list_t link;
- pixman_region32_t pixman_region;
+ pixman_region32_t pixman_region;
};
pepper_region_t *
pepper_region_create(pepper_compositor_t *compositor,
- struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id);
+ struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id);
void
pepper_region_destroy(pepper_region_t *region);
void
-pepper_transform_pixman_region(pixman_region32_t *region, const pepper_mat4_t *matrix);
+pepper_transform_pixman_region(pixman_region32_t *region,
+ const pepper_mat4_t *matrix);
/* Subcompositor */
-struct pepper_subcompositor
-{
- pepper_object_t base;
- pepper_compositor_t *compositor;
- struct wl_global *global;
- struct wl_list resource_list;
+struct pepper_subcompositor {
+ pepper_object_t base;
+ pepper_compositor_t *compositor;
+ struct wl_global *global;
+ struct wl_list resource_list;
};
pepper_subcompositor_t *
pepper_subcompositor_destroy(pepper_subcompositor_t *subcompositor);
/* Subsurface */
-struct pepper_subsurface
-{
- pepper_surface_t *surface;
- pepper_surface_t *parent;
- struct wl_resource *resource;
+struct pepper_subsurface {
+ pepper_surface_t *surface;
+ pepper_surface_t *parent;
+ struct wl_resource *resource;
- double x, y;
- pepper_list_t children_list;
+ double x, y;
+ pepper_list_t children_list;
- pepper_list_t parent_link; /* link to parent's children_list */
- pepper_list_t self_link; /* link to its own children_list */
+ pepper_list_t parent_link; /* link to parent's children_list */
+ pepper_list_t self_link; /* link to its own children_list */
- /* This state is applied when the parent surface's wl_surface state is applied,
- * regardless of the sub-surface's mode. */
- struct
- {
- double x, y;
- pepper_list_t children_list;
+ /* This state is applied when the parent surface's wl_surface state is applied,
+ * regardless of the sub-surface's mode. */
+ struct {
+ double x, y;
+ pepper_list_t children_list;
- pepper_list_t parent_link;
- pepper_list_t self_link;
- } pending;
+ pepper_list_t parent_link;
+ pepper_list_t self_link;
+ } pending;
- pepper_bool_t need_restack;
+ pepper_bool_t need_restack;
- pepper_bool_t sync; /* requested commit behavior */
+ pepper_bool_t sync; /* requested commit behavior */
- /* In sync mode, wl_surface.commit will apply the pending state into cache.
- * And cached state will flush into surface's current when parent's wl_surface.commit called */
- pepper_surface_state_t cache;
- pepper_bool_t cached;
+ /* In sync mode, wl_surface.commit will apply the pending state into cache.
+ * And cached state will flush into surface's current when parent's wl_surface.commit called */
+ pepper_surface_state_t cache;
+ pepper_bool_t cached;
- pepper_event_listener_t *parent_destroy_listener;
- pepper_event_listener_t *parent_commit_listener;
+ pepper_event_listener_t *parent_destroy_listener;
+ pepper_event_listener_t *parent_commit_listener;
};
pepper_subsurface_t *
pepper_subsurface_create(pepper_surface_t *surface, pepper_surface_t *parent,
- struct wl_client *client, struct wl_resource *resource, uint32_t id);
+ struct wl_client *client, struct wl_resource *resource, uint32_t id);
pepper_bool_t
pepper_subsurface_commit(pepper_subsurface_t *subsurface);
pepper_subsurface_destroy(pepper_subsurface_t *subsurface);
void
-subsurface_destroy_children_views(pepper_subsurface_t *subsurface, pepper_view_t *parent_view);
+subsurface_destroy_children_views(pepper_subsurface_t *subsurface,
+ pepper_view_t *parent_view);
void
-subsurface_create_children_views(pepper_subsurface_t *subsurface, pepper_view_t *parent_view);
+subsurface_create_children_views(pepper_subsurface_t *subsurface,
+ pepper_view_t *parent_view);
/* Input */
-struct pepper_pointer
-{
- pepper_object_t base;
- pepper_seat_t *seat;
- struct wl_list resource_list;
-
- pepper_view_t *focus;
- pepper_event_listener_t *focus_destroy_listener;
- uint32_t focus_serial;
-
- const pepper_pointer_grab_t *grab;
- void *data;
-
- uint32_t time;
- double x, y;
- double vx, vy;
-
- struct {
- double x0, y0;
- double x1, y1;
- } clamp;
-
- double x_velocity;
- double y_velocity;
-
- pepper_view_t *cursor_view;
- int32_t hotspot_x;
- int32_t hotspot_y;
+struct pepper_pointer {
+ pepper_object_t base;
+ pepper_seat_t *seat;
+ struct wl_list resource_list;
+
+ pepper_view_t *focus;
+ pepper_event_listener_t *focus_destroy_listener;
+ uint32_t focus_serial;
+
+ const pepper_pointer_grab_t *grab;
+ void *data;
+
+ uint32_t time;
+ double x, y;
+ double vx, vy;
+
+ struct {
+ double x0, y0;
+ double x1, y1;
+ } clamp;
+
+ double x_velocity;
+ double y_velocity;
+
+ pepper_view_t *cursor_view;
+ int32_t hotspot_x;
+ int32_t hotspot_y;
};
pepper_pointer_t *
pepper_pointer_destroy(pepper_pointer_t *pointer);
void
-pepper_pointer_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id);
+pepper_pointer_bind_resource(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id);
void
-pepper_pointer_handle_event(pepper_pointer_t *pointer, uint32_t id, pepper_input_event_t *event);
+pepper_pointer_handle_event(pepper_pointer_t *pointer, uint32_t id,
+ pepper_input_event_t *event);
-struct pepper_keyboard
-{
- pepper_object_t base;
- pepper_seat_t *seat;
- struct wl_list resource_list;
+struct pepper_keyboard {
+ pepper_object_t base;
+ pepper_seat_t *seat;
+ struct wl_list resource_list;
- pepper_view_t *focus;
- pepper_event_listener_t *focus_destroy_listener;
- uint32_t focus_serial;
+ pepper_view_t *focus;
+ pepper_event_listener_t *focus_destroy_listener;
+ uint32_t focus_serial;
- const pepper_keyboard_grab_t *grab;
- void *data;
+ const pepper_keyboard_grab_t *grab;
+ void *data;
- struct wl_array keys;
+ struct wl_array keys;
- struct xkb_keymap *keymap;
- int keymap_fd;
- int keymap_len;
- struct xkb_keymap *pending_keymap;
+ struct xkb_keymap *keymap;
+ int keymap_fd;
+ int keymap_len;
+ struct xkb_keymap *pending_keymap;
- struct xkb_state *state;
- uint32_t mods_depressed;
- uint32_t mods_latched;
- uint32_t mods_locked;
- uint32_t group;
+ struct xkb_state *state;
+ uint32_t mods_depressed;
+ uint32_t mods_latched;
+ uint32_t mods_locked;
+ uint32_t group;
};
pepper_keyboard_t *
pepper_keyboard_destroy(pepper_keyboard_t *keyboard);
void
-pepper_keyboard_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id);
+pepper_keyboard_bind_resource(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id);
void
-pepper_keyboard_handle_event(pepper_keyboard_t *keyboard, uint32_t id, pepper_input_event_t *event);
+pepper_keyboard_handle_event(pepper_keyboard_t *keyboard, uint32_t id,
+ pepper_input_event_t *event);
-struct pepper_touch_point
-{
- pepper_touch_t *touch;
+struct pepper_touch_point {
+ pepper_touch_t *touch;
- uint32_t id;
- double x, y;
+ uint32_t id;
+ double x, y;
- pepper_view_t *focus;
- uint32_t focus_serial;
- pepper_event_listener_t *focus_destroy_listener;
+ pepper_view_t *focus;
+ uint32_t focus_serial;
+ pepper_event_listener_t *focus_destroy_listener;
- pepper_list_t link;
+ pepper_list_t link;
};
-struct pepper_touch
-{
- pepper_object_t base;
- pepper_seat_t *seat;
- struct wl_list resource_list;
+struct pepper_touch {
+ pepper_object_t base;
+ pepper_seat_t *seat;
+ struct wl_list resource_list;
- pepper_list_t point_list;
+ pepper_list_t point_list;
- const pepper_touch_grab_t *grab;
- void *data;
+ const pepper_touch_grab_t *grab;
+ void *data;
};
pepper_touch_t *
pepper_touch_destroy(pepper_touch_t *touch);
void
-pepper_touch_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id);
+pepper_touch_bind_resource(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id);
void
-pepper_touch_handle_event(pepper_touch_t *touch, uint32_t id, pepper_input_event_t *event);
+pepper_touch_handle_event(pepper_touch_t *touch, uint32_t id,
+ pepper_input_event_t *event);
-struct pepper_seat
-{
- pepper_object_t base;
- pepper_compositor_t *compositor;
- pepper_list_t link;
- char *name;
- struct wl_global *global;
- struct wl_list resource_list;
+struct pepper_seat {
+ pepper_object_t base;
+ pepper_compositor_t *compositor;
+ pepper_list_t link;
+ char *name;
+ struct wl_global *global;
+ struct wl_list resource_list;
- enum wl_seat_capability caps;
+ enum wl_seat_capability caps;
- pepper_pointer_t *pointer;
- pepper_keyboard_t *keyboard;
- pepper_touch_t *touch;
+ pepper_pointer_t *pointer;
+ pepper_keyboard_t *keyboard;
+ pepper_touch_t *touch;
- pepper_list_t input_device_list;
+ pepper_list_t input_device_list;
};
-struct pepper_input_device
-{
- pepper_object_t base;
- pepper_compositor_t *compositor;
- pepper_list_t link;
+struct pepper_input_device {
+ pepper_object_t base;
+ pepper_compositor_t *compositor;
+ pepper_list_t link;
- uint32_t caps;
+ uint32_t caps;
- void *data;
- const pepper_input_device_backend_t *backend;
+ void *data;
+ const pepper_input_device_backend_t *backend;
};
-struct pepper_plane_entry
-{
- pepper_render_item_t base;
+struct pepper_plane_entry {
+ pepper_render_item_t base;
- pepper_plane_t *plane;
- pepper_bool_t need_damage;
- pepper_bool_t need_transform_update;
+ pepper_plane_t *plane;
+ pepper_bool_t need_damage;
+ pepper_bool_t need_transform_update;
- pepper_list_t link;
+ pepper_list_t link;
};
-enum
-{
- PEPPER_VIEW_GEOMETRY_DIRTY = 0x00000001,
- PEPPER_VIEW_ACTIVE_DIRTY = 0x00000002,
- PEPPER_VIEW_Z_ORDER_DIRTY = 0x00000004,
- PEPPER_VIEW_CONTENT_DIRTY = 0x00000008,
+enum {
+ PEPPER_VIEW_GEOMETRY_DIRTY = 0x00000001,
+ PEPPER_VIEW_ACTIVE_DIRTY = 0x00000002,
+ PEPPER_VIEW_Z_ORDER_DIRTY = 0x00000004,
+ PEPPER_VIEW_CONTENT_DIRTY = 0x00000008,
};
-struct pepper_view
-{
- pepper_object_t base;
- pepper_compositor_t *compositor;
- pepper_list_t compositor_link;
+struct pepper_view {
+ pepper_object_t base;
+ pepper_compositor_t *compositor;
+ pepper_list_t compositor_link;
- uint32_t dirty;
+ uint32_t dirty;
- /* Hierarchy. */
- pepper_view_t *parent;
- pepper_list_t parent_link;
- pepper_list_t children_list;
+ /* Hierarchy. */
+ pepper_view_t *parent;
+ pepper_list_t parent_link;
+ pepper_list_t children_list;
- /* Geometry. */
- double x, y;
- int w, h;
- pepper_mat4_t transform;
- pepper_bool_t inherit_transform;
+ /* Geometry. */
+ double x, y;
+ int w, h;
+ pepper_mat4_t transform;
+ pepper_bool_t inherit_transform;
- pepper_mat4_t global_transform;
- pepper_mat4_t global_transform_inverse;
+ pepper_mat4_t global_transform;
+ pepper_mat4_t global_transform_inverse;
- pixman_region32_t bounding_region;
- pixman_region32_t opaque_region;
+ pixman_region32_t bounding_region;
+ pixman_region32_t opaque_region;
- /* Visibility. */
- pepper_bool_t active;
- pepper_bool_t prev_visible;
- pepper_bool_t mapped;
+ /* Visibility. */
+ pepper_bool_t active;
+ pepper_bool_t prev_visible;
+ pepper_bool_t mapped;
- /* Content. */
- pepper_surface_t *surface;
- pepper_list_t surface_link;
+ /* Content. */
+ pepper_surface_t *surface;
+ pepper_list_t surface_link;
- /* Output info. */
- uint32_t output_overlap;
- pepper_plane_entry_t plane_entries[PEPPER_MAX_OUTPUT_COUNT];
+ /* Output info. */
+ uint32_t output_overlap;
+ pepper_plane_entry_t plane_entries[PEPPER_MAX_OUTPUT_COUNT];
- /* Temporary resource. */
- pepper_list_t link;
+ /* Temporary resource. */
+ pepper_list_t link;
};
void
void
pepper_view_surface_damage(pepper_view_t *view);
-struct pepper_plane
-{
- pepper_object_t base;
- pepper_output_t *output;
+struct pepper_plane {
+ pepper_object_t base;
+ pepper_output_t *output;
- pepper_list_t entry_list;
- pixman_region32_t damage_region;
- pixman_region32_t clip_region;
+ pepper_list_t entry_list;
+ pixman_region32_t damage_region;
+ pixman_region32_t clip_region;
- pepper_list_t link;
+ pepper_list_t link;
};
pepper_object_t *
pepper_plane_create(pepper_object_t *output, pepper_object_t *above_plane);
void
-pepper_plane_add_damage_region(pepper_plane_t *plane, pixman_region32_t *region);
+pepper_plane_add_damage_region(pepper_plane_t *plane,
+ pixman_region32_t *region);
void
-pepper_plane_update(pepper_plane_t *plane, const pepper_list_t *view_list, pixman_region32_t *clip);
+pepper_plane_update(pepper_plane_t *plane, const pepper_list_t *view_list,
+ pixman_region32_t *clip);
void
pepper_surface_flush_damage(pepper_surface_t *surface);
/* Misc. */
void
-pepper_pixman_region_global_to_output(pixman_region32_t *region, pepper_output_t *output);
+pepper_pixman_region_global_to_output(pixman_region32_t *region,
+ pepper_output_t *output);
void
-pepper_transform_global_to_output(pepper_mat4_t *transform, pepper_output_t *output);
+pepper_transform_global_to_output(pepper_mat4_t *transform,
+ pepper_output_t *output);
#endif /* PEPPER_INTERNAL_H */
*/
typedef struct pepper_render_item pepper_render_item_t;
-struct pepper_output_backend
-{
- /**
- * Destroy all internal resources by the backend for the given output.
- */
- void (*destroy)(void *output);
-
- /**
- * Return the sub-pixel layout of the physical display screen.
- */
- int32_t (*get_subpixel_order)(void *output);
-
- /**
- * Return a string indicating maker of the output device.
- */
- const char * (*get_maker_name)(void *output);
-
- /**
- * Return a string indicating model name of the output device.
- */
- const char * (*get_model_name)(void *output);
-
- /**
- * Return the number of available modes on the output device.
- */
- int (*get_mode_count)(void *output);
-
- /**
- * Return mode info for the given mode index.
- */
- void (*get_mode)(void *output, int index, pepper_output_mode_t *mode);
-
- /**
- * Change output mode to the given mode. return PEPPER_TRUE on success.
- */
- pepper_bool_t (*set_mode)(void *output, const pepper_output_mode_t *mode);
-
- /**
- * Assign plane for each views in the view list. Called before repaint. Backend should
- * assign planes for the views in the given view list.
- */
- void (*assign_planes)(void *output, const pepper_list_t *view_list);
-
- /**
- * Start repaint. Calld when the repaint state has been changed from idle to scheduled.
- * Backend should call pepper_output_finish_frame() when ready.
- */
- void (*start_repaint_loop)(void *output);
-
- /**
- * Render planes in the plane list. Backend should repaint the output. Backend should call
- * pepper_output_finish_frame() when it is ready to draw a new frame.
- */
- void (*repaint)(void *output, const pepper_list_t *plane_list);
-
- /**
- * Attach buffer to the surface. Called immediately when a new buffer has been attached and
- * committed. Backend must return the size of the attached buffer. Backend have a chance to
- * allocate resources for the surface.
- */
- void (*attach_surface)(void *output, pepper_surface_t *surface, int *w, int *h);
-
- /**
- * Update the surface content. Called before repaint. Backend should handle damage region
- * of the given surface if it is maintaining a copy of the surface.
- */
- void (*flush_surface_damage)(void *output, pepper_surface_t *surface,
- pepper_bool_t *keep_buffer);
+struct pepper_output_backend {
+ /**
+ * Destroy all internal resources by the backend for the given output.
+ */
+ void (*destroy)(void *output);
+
+ /**
+ * Return the sub-pixel layout of the physical display screen.
+ */
+ int32_t (*get_subpixel_order)(void *output);
+
+ /**
+ * Return a string indicating maker of the output device.
+ */
+ const char *(*get_maker_name)(void *output);
+
+ /**
+ * Return a string indicating model name of the output device.
+ */
+ const char *(*get_model_name)(void *output);
+
+ /**
+ * Return the number of available modes on the output device.
+ */
+ int (*get_mode_count)(void *output);
+
+ /**
+ * Return mode info for the given mode index.
+ */
+ void (*get_mode)(void *output, int index,
+ pepper_output_mode_t *mode);
+
+ /**
+ * Change output mode to the given mode. return PEPPER_TRUE on success.
+ */
+ pepper_bool_t (*set_mode)(void *output, const pepper_output_mode_t *mode);
+
+ /**
+ * Assign plane for each views in the view list. Called before repaint. Backend should
+ * assign planes for the views in the given view list.
+ */
+ void (*assign_planes)(void *output, const pepper_list_t *view_list);
+
+ /**
+ * Start repaint. Calld when the repaint state has been changed from idle to scheduled.
+ * Backend should call pepper_output_finish_frame() when ready.
+ */
+ void (*start_repaint_loop)(void *output);
+
+ /**
+ * Render planes in the plane list. Backend should repaint the output. Backend should call
+ * pepper_output_finish_frame() when it is ready to draw a new frame.
+ */
+ void (*repaint)(void *output, const pepper_list_t *plane_list);
+
+ /**
+ * Attach buffer to the surface. Called immediately when a new buffer has been attached and
+ * committed. Backend must return the size of the attached buffer. Backend have a chance to
+ * allocate resources for the surface.
+ */
+ void (*attach_surface)(void *output, pepper_surface_t *surface,
+ int *w, int *h);
+
+ /**
+ * Update the surface content. Called before repaint. Backend should handle damage region
+ * of the given surface if it is maintaining a copy of the surface.
+ */
+ void (*flush_surface_damage)(void *output, pepper_surface_t *surface,
+ pepper_bool_t *keep_buffer);
};
PEPPER_API pepper_output_t *
pepper_compositor_add_output(pepper_compositor_t *compositor,
- const pepper_output_backend_t *backend, const char *name, void *data,
- int transform, int scale);
-
-struct pepper_render_item
-{
- pepper_view_t *view; /**< view to render */
- pepper_mat4_t transform; /**< transform matrix of the view */
- pepper_mat4_t inverse; /**< inverse matrix of the transform matrix */
- pixman_region32_t visible_region; /**< visible region of the view */
+ const pepper_output_backend_t *backend, const char *name, void *data,
+ int transform, int scale);
+
+struct pepper_render_item {
+ pepper_view_t *view; /**< view to render */
+ pepper_mat4_t transform; /**< transform matrix of the view */
+ pepper_mat4_t
+ inverse; /**< inverse matrix of the transform matrix */
+ pixman_region32_t visible_region; /**< visible region of the view */
};
PEPPER_API pepper_plane_t *
pepper_plane_get_render_list(pepper_plane_t *plane);
PEPPER_API void
-pepper_plane_subtract_damage_region(pepper_plane_t *plane, pixman_region32_t *damage);
+pepper_plane_subtract_damage_region(pepper_plane_t *plane,
+ pixman_region32_t *damage);
PEPPER_API void
pepper_plane_clear_damage_region(pepper_plane_t *plane);
PEPPER_API void
-pepper_view_assign_plane(pepper_view_t *view, pepper_output_t *output, pepper_plane_t *plane);
+pepper_view_assign_plane(pepper_view_t *view, pepper_output_t *output,
+ pepper_plane_t *plane);
PEPPER_API void
-pepper_output_add_damage_region(pepper_output_t *output, pixman_region32_t *region);
+pepper_output_add_damage_region(pepper_output_t *output,
+ pixman_region32_t *region);
PEPPER_API void
pepper_output_finish_frame(pepper_output_t *output, struct timespec *ts);
#define PEPPER_FORMAT_G(format) (((format) & 0x000000f0) >> 4)
#define PEPPER_FORMAT_B(format) (((format) & 0x0000000f) >> 0)
-typedef enum
-{
- PEPPER_FORMAT_TYPE_UNKNOWN,
- PEPPER_FORMAT_TYPE_ARGB,
- PEPPER_FORMAT_TYPE_ABGR,
+typedef enum {
+ PEPPER_FORMAT_TYPE_UNKNOWN,
+ PEPPER_FORMAT_TYPE_ARGB,
+ PEPPER_FORMAT_TYPE_ABGR,
} pepper_format_type_t;
-typedef enum
-{
- PEPPER_FORMAT_UNKNOWN = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_UNKNOWN, 0, 0, 0, 0, 0),
+typedef enum {
+ PEPPER_FORMAT_UNKNOWN = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_UNKNOWN, 0, 0, 0, 0, 0),
- PEPPER_FORMAT_ARGB8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 32, 8, 8, 8, 8),
- PEPPER_FORMAT_XRGB8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 32, 0, 8, 8, 8),
- PEPPER_FORMAT_RGB888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 24, 0, 8, 8, 8),
- PEPPER_FORMAT_RGB565 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 16, 0, 5, 6, 5),
+ PEPPER_FORMAT_ARGB8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 32, 8, 8, 8, 8),
+ PEPPER_FORMAT_XRGB8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 32, 0, 8, 8, 8),
+ PEPPER_FORMAT_RGB888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 24, 0, 8, 8, 8),
+ PEPPER_FORMAT_RGB565 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 16, 0, 5, 6, 5),
- PEPPER_FORMAT_ABGR8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 32, 8, 8, 8, 8),
- PEPPER_FORMAT_XBGR8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 32, 0, 8, 8, 8),
- PEPPER_FORMAT_BGR888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 24, 0, 8, 8, 8),
- PEPPER_FORMAT_BGR565 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 16, 0, 5, 6, 5),
+ PEPPER_FORMAT_ABGR8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 32, 8, 8, 8, 8),
+ PEPPER_FORMAT_XBGR8888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 32, 0, 8, 8, 8),
+ PEPPER_FORMAT_BGR888 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 24, 0, 8, 8, 8),
+ PEPPER_FORMAT_BGR565 = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ABGR, 16, 0, 5, 6, 5),
- PEPPER_FORMAT_ALPHA = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 8, 8, 0, 0, 0),
+ PEPPER_FORMAT_ALPHA = PEPPER_FORMAT(PEPPER_FORMAT_TYPE_ARGB, 8, 8, 0, 0, 0),
} pepper_format_t;
static inline pixman_format_code_t
get_pixman_format(pepper_format_t format)
{
- switch (format)
- {
- case PEPPER_FORMAT_ARGB8888:
- return PIXMAN_a8r8g8b8;
- case PEPPER_FORMAT_XRGB8888:
- return PIXMAN_x8r8g8b8;
- case PEPPER_FORMAT_RGB888:
- return PIXMAN_r8g8b8;
- case PEPPER_FORMAT_RGB565:
- return PIXMAN_r5g6b5;
- case PEPPER_FORMAT_ABGR8888:
- return PIXMAN_a8b8g8r8;
- case PEPPER_FORMAT_XBGR8888:
- return PIXMAN_x8b8g8r8;
- case PEPPER_FORMAT_BGR888:
- return PIXMAN_b8g8r8;
- case PEPPER_FORMAT_BGR565:
- return PIXMAN_b5g6r5;
- case PEPPER_FORMAT_ALPHA:
- return PIXMAN_a8;
- default:
- break;
- }
-
- return (pixman_format_code_t)0;
+ switch (format) {
+ case PEPPER_FORMAT_ARGB8888:
+ return PIXMAN_a8r8g8b8;
+ case PEPPER_FORMAT_XRGB8888:
+ return PIXMAN_x8r8g8b8;
+ case PEPPER_FORMAT_RGB888:
+ return PIXMAN_r8g8b8;
+ case PEPPER_FORMAT_RGB565:
+ return PIXMAN_r5g6b5;
+ case PEPPER_FORMAT_ABGR8888:
+ return PIXMAN_a8b8g8r8;
+ case PEPPER_FORMAT_XBGR8888:
+ return PIXMAN_x8b8g8r8;
+ case PEPPER_FORMAT_BGR888:
+ return PIXMAN_b8g8r8;
+ case PEPPER_FORMAT_BGR565:
+ return PIXMAN_b5g6r5;
+ case PEPPER_FORMAT_ALPHA:
+ return PIXMAN_a8;
+ default:
+ break;
+ }
+
+ return (pixman_format_code_t)0;
}
typedef struct pepper_list pepper_list_t;
pos = tmp, \
tmp = pepper_container_of(pos->member.prev, tmp, member))
-struct pepper_list
-{
- pepper_list_t *prev;
- pepper_list_t *next;
- void *item;
+struct pepper_list {
+ pepper_list_t *prev;
+ pepper_list_t *next;
+ void *item;
};
static inline void
pepper_list_init(pepper_list_t *list)
{
- list->prev = list;
- list->next = list;
- list->item = NULL;
+ list->prev = list;
+ list->next = list;
+ list->item = NULL;
}
static inline void
pepper_list_insert(pepper_list_t *list, pepper_list_t *elm)
{
- elm->prev = list;
- elm->next = list->next;
- list->next = elm;
- elm->next->prev = elm;
+ elm->prev = list;
+ elm->next = list->next;
+ list->next = elm;
+ elm->next->prev = elm;
}
static inline void
pepper_list_remove(pepper_list_t *list)
{
- list->prev->next = list->next;
- list->next->prev = list->prev;
- list->prev = NULL;
- list->next = NULL;
+ list->prev->next = list->next;
+ list->next->prev = list->prev;
+ list->prev = NULL;
+ list->next = NULL;
}
static inline pepper_bool_t
pepper_list_empty(const pepper_list_t *list)
{
- return list->next == list;
+ return list->next == list;
}
static inline void
pepper_list_insert_list(pepper_list_t *list, pepper_list_t *other)
{
- if (pepper_list_empty(other))
- return;
+ if (pepper_list_empty(other))
+ return;
- other->next->prev = list;
- other->prev->next = list->next;
- list->next->prev = other->prev;
- list->next = other->next;
+ other->next->prev = list;
+ other->prev->next = list->next;
+ list->next->prev = other->prev;
+ list->next = other->next;
}
/* Hash functions from Thomas Wang https://gist.github.com/badboy/6267743 */
static inline int
pepper_hash32(uint32_t key)
{
- key = ~key + (key << 15);
- key ^= key >> 12;
- key += key << 2;
- key ^= key >> 4;
- key *= 2057;
- key ^= key >> 16;
-
- return key;
+ key = ~key + (key << 15);
+ key ^= key >> 12;
+ key += key << 2;
+ key ^= key >> 4;
+ key *= 2057;
+ key ^= key >> 16;
+
+ return key;
}
static inline int
pepper_hash64(uint64_t key)
{
- key = ~key + (key << 18);
- key ^= key >> 31;
- key *= 21;
- key ^= key >> 11;
- key += key << 6;
- key ^= key >> 22;
-
- return (int)key;
+ key = ~key + (key << 18);
+ key ^= key >> 31;
+ key *= 21;
+ key ^= key >> 11;
+ key += key << 6;
+ key ^= key >> 22;
+
+ return (int)key;
}
typedef struct pepper_map_entry pepper_map_entry_t;
typedef int (*pepper_hash_func_t)(const void *key, int key_length);
typedef int (*pepper_key_length_func_t)(const void *key);
typedef int (*pepper_key_compare_func_t)(const void *key0, int key0_length,
- const void *key1, int key1_length);
+ const void *key1, int key1_length);
-struct pepper_map
-{
- pepper_hash_func_t hash_func;
- pepper_key_length_func_t key_length_func;
- pepper_key_compare_func_t key_compare_func;
-
- int bucket_bits;
- int bucket_size;
- int bucket_mask;
- pepper_map_entry_t **buckets;
+struct pepper_map {
+ pepper_hash_func_t hash_func;
+ pepper_key_length_func_t key_length_func;
+ pepper_key_compare_func_t key_compare_func;
+
+ int bucket_bits;
+ int bucket_size;
+ int bucket_mask;
+ pepper_map_entry_t **buckets;
};
PEPPER_API void
pepper_map_init(pepper_map_t *map,
- int bucket_bits,
- pepper_hash_func_t hash_func,
- pepper_key_length_func_t key_length_func,
- pepper_key_compare_func_t key_compare_func,
- void *buckets);
+ int bucket_bits,
+ pepper_hash_func_t hash_func,
+ pepper_key_length_func_t key_length_func,
+ pepper_key_compare_func_t key_compare_func,
+ void *buckets);
PEPPER_API void
pepper_map_int32_init(pepper_map_t *map, int bucket_bits, void *buckets);
PEPPER_API pepper_map_t *
pepper_map_create(int bucket_bits,
- pepper_hash_func_t hash_func,
- pepper_key_length_func_t key_length_func,
- pepper_key_compare_func_t key_compare_func);
+ pepper_hash_func_t hash_func,
+ pepper_key_length_func_t key_length_func,
+ pepper_key_compare_func_t key_compare_func);
PEPPER_API pepper_map_t *
pepper_map_int32_create(int bucket_bits);
pepper_map_get(pepper_map_t *map, const void *key);
PEPPER_API void
-pepper_map_set(pepper_map_t *map, const void *key, void *data, pepper_free_func_t free_func);
+pepper_map_set(pepper_map_t *map, const void *key, void *data,
+ pepper_free_func_t free_func);
typedef struct pepper_id_allocator pepper_id_allocator_t;
-struct pepper_id_allocator
-{
- uint32_t next_id;
- uint32_t *free_ids;
- int free_id_count;
- int free_id_size;
- int free_id_head;
- int free_id_tail;
+struct pepper_id_allocator {
+ uint32_t next_id;
+ uint32_t *free_ids;
+ int free_id_count;
+ int free_id_size;
+ int free_id_head;
+ int free_id_tail;
};
PEPPER_API void
pepper_create_anonymous_file(off_t size);
PEPPER_API int
-pepper_log(const char* domain, int level, const char *format, ...);
+pepper_log(const char *domain, int level, const char *format, ...);
#define PEPPER_ERROR(fmt, ...) \
do { \
typedef struct pepper_vec3 pepper_vec3_t;
typedef struct pepper_vec2 pepper_vec2_t;
-struct pepper_mat4
-{
- double m[16];
- uint32_t flags;
+struct pepper_mat4 {
+ double m[16];
+ uint32_t flags;
};
-struct pepper_vec2
-{
- double x, y;
+struct pepper_vec2 {
+ double x, y;
};
-struct pepper_vec3
-{
- double x, y, z;
+struct pepper_vec3 {
+ double x, y, z;
};
-struct pepper_vec4
-{
- double x, y, z, w;
+struct pepper_vec4 {
+ double x, y, z, w;
};
enum {
- PEPPER_MATRIX_TRANSLATE = (1 << 0),
- PEPPER_MATRIX_SCALE = (1 << 1),
- PEPPER_MATRIX_ROTATE = (1 << 2),
- PEPPER_MATRIX_COMPLEX = (1 << 3),
+ PEPPER_MATRIX_TRANSLATE = (1 << 0),
+ PEPPER_MATRIX_SCALE = (1 << 1),
+ PEPPER_MATRIX_ROTATE = (1 << 2),
+ PEPPER_MATRIX_COMPLEX = (1 << 3),
};
static inline pepper_bool_t
pepper_mat4_is_translation(const pepper_mat4_t *matrix)
{
- return matrix->flags == PEPPER_MATRIX_TRANSLATE || matrix->flags == 0;
+ return matrix->flags == PEPPER_MATRIX_TRANSLATE || matrix->flags == 0;
}
static inline double
pepper_reciprocal_sqrt(double x)
{
- union {
- float f;
- long i;
- } u;
-
- u.f = x;
- u.i = 0x5f3759df - (u.i >> 1);
- return (double)(u.f * (1.5f - u.f * u.f * x * 0.5f));
+ union {
+ float f;
+ long i;
+ } u;
+
+ u.f = x;
+ u.i = 0x5f3759df - (u.i >> 1);
+ return (double)(u.f * (1.5f - u.f * u.f * x * 0.5f));
}
static inline void
-pepper_mat4_multiply(pepper_mat4_t *dst, const pepper_mat4_t *ma, const pepper_mat4_t *mb)
-{
- pepper_mat4_t tmp;
- double *d = tmp.m;
- const double *a = ma->m;
- const double *b = mb->m;
-
- if (!ma->flags)
- {
- memcpy(dst, mb, sizeof(pepper_mat4_t));
- return;
- }
-
- if (!mb->flags)
- {
- memcpy(dst, ma, sizeof(pepper_mat4_t));
- return;
- }
-
- d[ 0] = a[ 0] * b[ 0] + a[ 4] * b[ 1] + a[ 8] * b[ 2] + a[12] * b [3];
- d[ 4] = a[ 0] * b[ 4] + a[ 4] * b[ 5] + a[ 8] * b[ 6] + a[12] * b [7];
- d[ 8] = a[ 0] * b[ 8] + a[ 4] * b[ 9] + a[ 8] * b[10] + a[12] * b[11];
- d[12] = a[ 0] * b[12] + a[ 4] * b[13] + a[ 8] * b[14] + a[12] * b[15];
-
- d[ 1] = a[ 1] * b[ 0] + a[ 5] * b[ 1] + a[ 9] * b[ 2] + a[13] * b [3];
- d[ 5] = a[ 1] * b[ 4] + a[ 5] * b[ 5] + a[ 9] * b[ 6] + a[13] * b [7];
- d[ 9] = a[ 1] * b[ 8] + a[ 5] * b[ 9] + a[ 9] * b[10] + a[13] * b[11];
- d[13] = a[ 1] * b[12] + a[ 5] * b[13] + a[ 9] * b[14] + a[13] * b[15];
-
- d[ 2] = a[ 2] * b[ 0] + a[ 6] * b[ 1] + a[10] * b[ 2] + a[14] * b [3];
- d[ 6] = a[ 2] * b[ 4] + a[ 6] * b[ 5] + a[10] * b[ 6] + a[14] * b [7];
- d[10] = a[ 2] * b[ 8] + a[ 6] * b[ 9] + a[10] * b[10] + a[14] * b[11];
- d[14] = a[ 2] * b[12] + a[ 6] * b[13] + a[10] * b[14] + a[14] * b[15];
-
- d[ 3] = a[ 3] * b[ 0] + a[ 7] * b[ 1] + a[11] * b[ 2] + a[15] * b [3];
- d[ 7] = a[ 3] * b[ 4] + a[ 7] * b[ 5] + a[11] * b[ 6] + a[15] * b [7];
- d[11] = a[ 3] * b[ 8] + a[ 7] * b[ 9] + a[11] * b[10] + a[15] * b[11];
- d[15] = a[ 3] * b[12] + a[ 7] * b[13] + a[11] * b[14] + a[15] * b[15];
-
- tmp.flags = ma->flags | mb->flags;
- memcpy(dst, &tmp, sizeof(pepper_mat4_t));
+pepper_mat4_multiply(pepper_mat4_t *dst, const pepper_mat4_t *ma,
+ const pepper_mat4_t *mb)
+{
+ pepper_mat4_t tmp;
+ double *d = tmp.m;
+ const double *a = ma->m;
+ const double *b = mb->m;
+
+ if (!ma->flags) {
+ memcpy(dst, mb, sizeof(pepper_mat4_t));
+ return;
+ }
+
+ if (!mb->flags) {
+ memcpy(dst, ma, sizeof(pepper_mat4_t));
+ return;
+ }
+
+ d[ 0] = a[ 0] * b[ 0] + a[ 4] * b[ 1] + a[ 8] * b[ 2] + a[12] * b [3];
+ d[ 4] = a[ 0] * b[ 4] + a[ 4] * b[ 5] + a[ 8] * b[ 6] + a[12] * b [7];
+ d[ 8] = a[ 0] * b[ 8] + a[ 4] * b[ 9] + a[ 8] * b[10] + a[12] * b[11];
+ d[12] = a[ 0] * b[12] + a[ 4] * b[13] + a[ 8] * b[14] + a[12] * b[15];
+
+ d[ 1] = a[ 1] * b[ 0] + a[ 5] * b[ 1] + a[ 9] * b[ 2] + a[13] * b [3];
+ d[ 5] = a[ 1] * b[ 4] + a[ 5] * b[ 5] + a[ 9] * b[ 6] + a[13] * b [7];
+ d[ 9] = a[ 1] * b[ 8] + a[ 5] * b[ 9] + a[ 9] * b[10] + a[13] * b[11];
+ d[13] = a[ 1] * b[12] + a[ 5] * b[13] + a[ 9] * b[14] + a[13] * b[15];
+
+ d[ 2] = a[ 2] * b[ 0] + a[ 6] * b[ 1] + a[10] * b[ 2] + a[14] * b [3];
+ d[ 6] = a[ 2] * b[ 4] + a[ 6] * b[ 5] + a[10] * b[ 6] + a[14] * b [7];
+ d[10] = a[ 2] * b[ 8] + a[ 6] * b[ 9] + a[10] * b[10] + a[14] * b[11];
+ d[14] = a[ 2] * b[12] + a[ 6] * b[13] + a[10] * b[14] + a[14] * b[15];
+
+ d[ 3] = a[ 3] * b[ 0] + a[ 7] * b[ 1] + a[11] * b[ 2] + a[15] * b [3];
+ d[ 7] = a[ 3] * b[ 4] + a[ 7] * b[ 5] + a[11] * b[ 6] + a[15] * b [7];
+ d[11] = a[ 3] * b[ 8] + a[ 7] * b[ 9] + a[11] * b[10] + a[15] * b[11];
+ d[15] = a[ 3] * b[12] + a[ 7] * b[13] + a[11] * b[14] + a[15] * b[15];
+
+ tmp.flags = ma->flags | mb->flags;
+ memcpy(dst, &tmp, sizeof(pepper_mat4_t));
}
static inline void
pepper_mat4_init_identity(pepper_mat4_t *matrix)
{
- matrix->m[ 0] = 1.0f;
- matrix->m[ 1] = 0.0f;
- matrix->m[ 2] = 0.0f;
- matrix->m[ 3] = 0.0f;
-
- matrix->m[ 4] = 0.0f;
- matrix->m[ 5] = 1.0f;
- matrix->m[ 6] = 0.0f;
- matrix->m[ 7] = 0.0f;
-
- matrix->m[ 8] = 0.0f;
- matrix->m[ 9] = 0.0f;
- matrix->m[10] = 1.0f;
- matrix->m[11] = 0.0f;
-
- matrix->m[12] = 0.0f;
- matrix->m[13] = 0.0f;
- matrix->m[14] = 0.0f;
- matrix->m[15] = 1.0f;
-
- matrix->flags = 0;
+ matrix->m[ 0] = 1.0f;
+ matrix->m[ 1] = 0.0f;
+ matrix->m[ 2] = 0.0f;
+ matrix->m[ 3] = 0.0f;
+
+ matrix->m[ 4] = 0.0f;
+ matrix->m[ 5] = 1.0f;
+ matrix->m[ 6] = 0.0f;
+ matrix->m[ 7] = 0.0f;
+
+ matrix->m[ 8] = 0.0f;
+ matrix->m[ 9] = 0.0f;
+ matrix->m[10] = 1.0f;
+ matrix->m[11] = 0.0f;
+
+ matrix->m[12] = 0.0f;
+ matrix->m[13] = 0.0f;
+ matrix->m[14] = 0.0f;
+ matrix->m[15] = 1.0f;
+
+ matrix->flags = 0;
}
static inline void
pepper_mat4_init_translate(pepper_mat4_t *matrix, double x, double y, double z)
{
- pepper_mat4_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
- matrix->m[12] = x;
- matrix->m[13] = y;
- matrix->m[14] = z;
+ matrix->m[12] = x;
+ matrix->m[13] = y;
+ matrix->m[14] = z;
- matrix->flags |= PEPPER_MATRIX_TRANSLATE;
+ matrix->flags |= PEPPER_MATRIX_TRANSLATE;
}
static inline void
pepper_mat4_translate(pepper_mat4_t *matrix, double x, double y, double z)
{
- matrix->m[ 0] += matrix->m[ 3] * x;
- matrix->m[ 1] += matrix->m[ 3] * y;
- matrix->m[ 2] += matrix->m[ 3] * z;
- matrix->m[ 4] += matrix->m[ 7] * x;
- matrix->m[ 5] += matrix->m[ 7] * y;
- matrix->m[ 6] += matrix->m[ 7] * z;
- matrix->m[ 8] += matrix->m[11] * x;
- matrix->m[ 9] += matrix->m[11] * y;
- matrix->m[10] += matrix->m[11] * z;
- matrix->m[12] += matrix->m[15] * x;
- matrix->m[13] += matrix->m[15] * y;
- matrix->m[14] += matrix->m[15] * z;
-
- matrix->flags |= PEPPER_MATRIX_TRANSLATE;
+ matrix->m[ 0] += matrix->m[ 3] * x;
+ matrix->m[ 1] += matrix->m[ 3] * y;
+ matrix->m[ 2] += matrix->m[ 3] * z;
+ matrix->m[ 4] += matrix->m[ 7] * x;
+ matrix->m[ 5] += matrix->m[ 7] * y;
+ matrix->m[ 6] += matrix->m[ 7] * z;
+ matrix->m[ 8] += matrix->m[11] * x;
+ matrix->m[ 9] += matrix->m[11] * y;
+ matrix->m[10] += matrix->m[11] * z;
+ matrix->m[12] += matrix->m[15] * x;
+ matrix->m[13] += matrix->m[15] * y;
+ matrix->m[14] += matrix->m[15] * z;
+
+ matrix->flags |= PEPPER_MATRIX_TRANSLATE;
}
static inline void
pepper_mat4_init_scale(pepper_mat4_t *matrix, double x, double y, double z)
{
- pepper_mat4_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
- matrix->m[ 0] = x;
- matrix->m[ 5] = y;
- matrix->m[10] = z;
+ matrix->m[ 0] = x;
+ matrix->m[ 5] = y;
+ matrix->m[10] = z;
- matrix->flags |= PEPPER_MATRIX_SCALE;
+ matrix->flags |= PEPPER_MATRIX_SCALE;
}
static inline void
pepper_mat4_scale(pepper_mat4_t *matrix, double x, double y, double z)
{
- matrix->m[ 0] *= x;
- matrix->m[ 1] *= y;
- matrix->m[ 2] *= z;
+ matrix->m[ 0] *= x;
+ matrix->m[ 1] *= y;
+ matrix->m[ 2] *= z;
- matrix->m[ 4] *= x;
- matrix->m[ 5] *= y;
- matrix->m[ 6] *= z;
+ matrix->m[ 4] *= x;
+ matrix->m[ 5] *= y;
+ matrix->m[ 6] *= z;
- matrix->m[ 8] *= x;
- matrix->m[ 9] *= y;
- matrix->m[10] *= z;
+ matrix->m[ 8] *= x;
+ matrix->m[ 9] *= y;
+ matrix->m[10] *= z;
- matrix->m[12] *= x;
- matrix->m[13] *= y;
- matrix->m[14] *= z;
+ matrix->m[12] *= x;
+ matrix->m[13] *= y;
+ matrix->m[14] *= z;
- matrix->flags |= PEPPER_MATRIX_SCALE;
+ matrix->flags |= PEPPER_MATRIX_SCALE;
}
static inline void
-pepper_mat4_init_rotate(pepper_mat4_t *matrix, double x, double y, double z, double angle)
-{
- double c;
- double s;
- double invlen;
- double xs;
- double ys;
- double zs;
- double invc;
- double xinvc;
- double yinvc;
- double zinvc;
-
- if (angle == 0.0f || (z == 0.0f && y == 0.0f && z == 0.0f))
- {
- pepper_mat4_init_identity(matrix);
- return;
- }
-
- c = cos(angle);
- s = sin(angle);
-
- if (x == 0.0f && y == 0.0f)
- {
- pepper_mat4_init_identity(matrix);
-
- matrix->m[ 0] = c;
- matrix->m[ 1] = s;
- matrix->m[ 4] = -s;
- matrix->m[ 5] = c;
- }
- else if (y == 0.0f && z == 0.0f)
- {
- pepper_mat4_init_identity(matrix);
-
- matrix->m[ 5] = c;
- matrix->m[ 6] = s;
- matrix->m[ 9] = -s;
- matrix->m[10] = c;
- }
- else if (x == 0.0f && z == 0.0f)
- {
- pepper_mat4_init_identity(matrix);
-
- matrix->m[ 0] = c;
- matrix->m[ 2] = -s;
- matrix->m[ 8] = s;
- matrix->m[10] = c;
- }
- else
- {
- invlen = pepper_reciprocal_sqrt(x * x + y * y + z * z);
-
- x *= invlen;
- y *= invlen;
- z *= invlen;
-
- xs = x * s;
- ys = y * s;
- zs = z * s;
- invc = 1 - c;
- xinvc = x * invc;
- yinvc = y * invc;
- zinvc = z * invc;
-
- matrix->m[ 0] = c + x * xinvc;
- matrix->m[ 4] = x * yinvc - zs;
- matrix->m[ 8] = x * zinvc + ys;
- matrix->m[12] = 0.0f;
-
- matrix->m[ 1] = y * xinvc + zs;
- matrix->m[ 5] = c + y * yinvc;
- matrix->m[ 9] = y * zinvc - xs;
- matrix->m[13] = 0.0f;
-
- matrix->m[ 2] = z * xinvc - ys;
- matrix->m[ 6] = z * yinvc + xs;
- matrix->m[10] = c + z * zinvc;
- matrix->m[14] = 0.0f;
-
- matrix->m[ 3] = 0.0f;
- matrix->m[ 7] = 0.0f;
- matrix->m[11] = 0.0f;
- matrix->m[15] = 1.0f;
- }
-
- matrix->flags |= PEPPER_MATRIX_ROTATE;
+pepper_mat4_init_rotate(pepper_mat4_t *matrix, double x, double y, double z,
+ double angle)
+{
+ double c;
+ double s;
+ double invlen;
+ double xs;
+ double ys;
+ double zs;
+ double invc;
+ double xinvc;
+ double yinvc;
+ double zinvc;
+
+ if (angle == 0.0f || (z == 0.0f && y == 0.0f && z == 0.0f)) {
+ pepper_mat4_init_identity(matrix);
+ return;
+ }
+
+ c = cos(angle);
+ s = sin(angle);
+
+ if (x == 0.0f && y == 0.0f) {
+ pepper_mat4_init_identity(matrix);
+
+ matrix->m[ 0] = c;
+ matrix->m[ 1] = s;
+ matrix->m[ 4] = -s;
+ matrix->m[ 5] = c;
+ } else if (y == 0.0f && z == 0.0f) {
+ pepper_mat4_init_identity(matrix);
+
+ matrix->m[ 5] = c;
+ matrix->m[ 6] = s;
+ matrix->m[ 9] = -s;
+ matrix->m[10] = c;
+ } else if (x == 0.0f && z == 0.0f) {
+ pepper_mat4_init_identity(matrix);
+
+ matrix->m[ 0] = c;
+ matrix->m[ 2] = -s;
+ matrix->m[ 8] = s;
+ matrix->m[10] = c;
+ } else {
+ invlen = pepper_reciprocal_sqrt(x * x + y * y + z * z);
+
+ x *= invlen;
+ y *= invlen;
+ z *= invlen;
+
+ xs = x * s;
+ ys = y * s;
+ zs = z * s;
+ invc = 1 - c;
+ xinvc = x * invc;
+ yinvc = y * invc;
+ zinvc = z * invc;
+
+ matrix->m[ 0] = c + x * xinvc;
+ matrix->m[ 4] = x * yinvc - zs;
+ matrix->m[ 8] = x * zinvc + ys;
+ matrix->m[12] = 0.0f;
+
+ matrix->m[ 1] = y * xinvc + zs;
+ matrix->m[ 5] = c + y * yinvc;
+ matrix->m[ 9] = y * zinvc - xs;
+ matrix->m[13] = 0.0f;
+
+ matrix->m[ 2] = z * xinvc - ys;
+ matrix->m[ 6] = z * yinvc + xs;
+ matrix->m[10] = c + z * zinvc;
+ matrix->m[14] = 0.0f;
+
+ matrix->m[ 3] = 0.0f;
+ matrix->m[ 7] = 0.0f;
+ matrix->m[11] = 0.0f;
+ matrix->m[15] = 1.0f;
+ }
+
+ matrix->flags |= PEPPER_MATRIX_ROTATE;
}
static inline void
-pepper_mat4_rotate(pepper_mat4_t *matrix, double x, double y, double z, double angle)
+pepper_mat4_rotate(pepper_mat4_t *matrix, double x, double y, double z,
+ double angle)
{
- pepper_mat4_t rotate;
+ pepper_mat4_t rotate;
- pepper_mat4_init_rotate(&rotate, x, y, z, angle);
- pepper_mat4_multiply(matrix, &rotate, matrix);
+ pepper_mat4_init_rotate(&rotate, x, y, z, angle);
+ pepper_mat4_multiply(matrix, &rotate, matrix);
}
static inline void
pepper_mat4_copy(pepper_mat4_t *dst, const pepper_mat4_t *src)
{
- memcpy(dst, src, sizeof(pepper_mat4_t));
+ memcpy(dst, src, sizeof(pepper_mat4_t));
}
static inline void
pepper_mat4_inverse(pepper_mat4_t *dst, const pepper_mat4_t *src)
{
- pepper_mat4_t tmp;
- double *d = &tmp.m[0];
- const double *m = &src->m[0];
- double det;
-
- if (!(src->flags & PEPPER_MATRIX_COMPLEX) &&
- !(src->flags & PEPPER_MATRIX_ROTATE))
- {
- pepper_mat4_copy(dst, src);
-
- dst->m[12] = -m[12] / m[ 0];
- dst->m[13] = -m[13] / m[ 5];
- dst->m[14] = -m[14] / m[10];
-
- dst->m[ 0] = 1.0 / m[ 0];
- dst->m[ 5] = 1.0 / m[ 5];
- dst->m[10] = 1.0 / m[10];
-
- return;
- }
-
- d[ 0] = m[ 5] * m[10] * m[15] -
- m[ 5] * m[11] * m[14] -
- m[ 9] * m[ 6] * m[15] +
- m[ 9] * m[ 7] * m[14] +
- m[13] * m[ 6] * m[11] -
- m[13] * m[ 7] * m[10];
-
- d[ 4] = -m[ 4] * m[10] * m[15] +
- m[ 4] * m[11] * m[14] +
- m[ 8] * m[ 6] * m[15] -
- m[ 8] * m[ 7] * m[14] -
- m[12] * m[ 6] * m[11] +
- m[12] * m[ 7] * m[10];
-
- d[ 8] = m[ 4] * m[ 9] * m[15] -
- m[ 4] * m[11] * m[13] -
- m[ 8] * m[ 5] * m[15] +
- m[ 8] * m[ 7] * m[13] +
- m[12] * m[ 5] * m[11] -
- m[12] * m[ 7] * m[ 9];
-
- d[12] = -m[ 4] * m[ 9] * m[14] +
- m[ 4] * m[10] * m[13] +
- m[ 8] * m[ 5] * m[14] -
- m[ 8] * m[ 6] * m[13] -
- m[12] * m[ 5] * m[10] +
- m[12] * m[ 6] * m[ 9];
-
- d[ 1] = -m[ 1] * m[10] * m[15] +
- m[ 1] * m[11] * m[14] +
- m[ 9] * m[ 2] * m[15] -
- m[ 9] * m[ 3] * m[14] -
- m[13] * m[ 2] * m[11] +
- m[13] * m[ 3] * m[10];
-
- d[ 5] = m[ 0] * m[10] * m[15] -
- m[ 0] * m[11] * m[14] -
- m[ 8] * m[ 2] * m[15] +
- m[ 8] * m[ 3] * m[14] +
- m[12] * m[ 2] * m[11] -
- m[12] * m[ 3] * m[10];
-
- d[ 9] = -m[ 0] * m[ 9] * m[15] +
- m[ 0] * m[11] * m[13] +
- m[ 8] * m[ 1] * m[15] -
- m[ 8] * m[ 3] * m[13] -
- m[12] * m[ 1] * m[11] +
- m[12] * m[ 3] * m[ 9];
-
- d[13] = m[ 0] * m[ 9] * m[14] -
- m[ 0] * m[10] * m[13] -
- m[ 8] * m[ 1] * m[14] +
- m[ 8] * m[ 2] * m[13] +
- m[12] * m[ 1] * m[10] -
- m[12] * m[ 2] * m[ 9];
-
- d[ 2] = m[ 1] * m[ 6] * m[15] -
- m[ 1] * m[ 7] * m[14] -
- m[ 5] * m[ 2] * m[15] +
- m[ 5] * m[ 3] * m[14] +
- m[13] * m[ 2] * m[ 7] -
- m[13] * m[ 3] * m[ 6];
-
- d[ 6] = -m[ 0] * m[ 6] * m[15] +
- m[ 0] * m[ 7] * m[14] +
- m[ 4] * m[ 2] * m[15] -
- m[ 4] * m[ 3] * m[14] -
- m[12] * m[ 2] * m[ 7] +
- m[12] * m[ 3] * m[ 6];
-
- d[10] = m[ 0] * m[ 5] * m[15] -
- m[ 0] * m[ 7] * m[13] -
- m[ 4] * m[ 1] * m[15] +
- m[ 4] * m[ 3] * m[13] +
- m[12] * m[ 1] * m[ 7] -
- m[12] * m[ 3] * m[ 5];
-
- d[14] = -m[ 0] * m[ 5] * m[14] +
- m[ 0] * m[ 6] * m[13] +
- m[ 4] * m[ 1] * m[14] -
- m[ 4] * m[ 2] * m[13] -
- m[12] * m[ 1] * m[ 6] +
- m[12] * m[ 2] * m[ 5];
-
- d[ 3] = -m[ 1] * m[ 6] * m[11] +
- m[ 1] * m[ 7] * m[10] +
- m[ 5] * m[ 2] * m[11] -
- m[ 5] * m[ 3] * m[10] -
- m[ 9] * m[ 2] * m[ 7] +
- m[ 9] * m[ 3] * m[ 6];
-
- d[ 7] = m[ 0] * m[ 6] * m[11] -
- m[ 0] * m[ 7] * m[10] -
- m[ 4] * m[ 2] * m[11] +
- m[ 4] * m[ 3] * m[10] +
- m[ 8] * m[ 2] * m[ 7] -
- m[ 8] * m[ 3] * m[ 6];
-
- d[11] = -m[ 0] * m[ 5] * m[11] +
- m[ 0] * m[ 7] * m[ 9] +
- m[ 4] * m[ 1] * m[11] -
- m[ 4] * m[ 3] * m[ 9] -
- m[ 8] * m[ 1] * m[ 7] +
- m[ 8] * m[ 3] * m[ 5];
-
- d[15] = m[ 0] * m[ 5] * m[10] -
- m[ 0] * m[ 6] * m[ 9] -
- m[ 4] * m[ 1] * m[10] +
- m[ 4] * m[ 2] * m[ 9] +
- m[ 8] * m[ 1] * m[ 6] -
- m[ 8] * m[ 2] * m[ 5];
-
- det = m[0] * d[0] + m[1] * d[4] + m[2] * d[8] + m[3] * d[12];
-
- if (det == 0.0)
- {
- PEPPER_ERROR("Matrix is singular. Unable to get inverse matrix.\n");
- return;
- }
-
- det = 1.0 / det;
-
- d[ 0] *= det;
- d[ 1] *= det;
- d[ 2] *= det;
- d[ 3] *= det;
- d[ 4] *= det;
- d[ 5] *= det;
- d[ 6] *= det;
- d[ 7] *= det;
- d[ 8] *= det;
- d[ 9] *= det;
- d[10] *= det;
- d[11] *= det;
- d[12] *= det;
- d[13] *= det;
- d[14] *= det;
- d[15] *= det;
-
- pepper_mat4_copy(dst, &tmp);
- dst->flags = src->flags;
+ pepper_mat4_t tmp;
+ double *d = &tmp.m[0];
+ const double *m = &src->m[0];
+ double det;
+
+ if (!(src->flags & PEPPER_MATRIX_COMPLEX) &&
+ !(src->flags & PEPPER_MATRIX_ROTATE)) {
+ pepper_mat4_copy(dst, src);
+
+ dst->m[12] = -m[12] / m[ 0];
+ dst->m[13] = -m[13] / m[ 5];
+ dst->m[14] = -m[14] / m[10];
+
+ dst->m[ 0] = 1.0 / m[ 0];
+ dst->m[ 5] = 1.0 / m[ 5];
+ dst->m[10] = 1.0 / m[10];
+
+ return;
+ }
+
+ d[ 0] = m[ 5] * m[10] * m[15] -
+ m[ 5] * m[11] * m[14] -
+ m[ 9] * m[ 6] * m[15] +
+ m[ 9] * m[ 7] * m[14] +
+ m[13] * m[ 6] * m[11] -
+ m[13] * m[ 7] * m[10];
+
+ d[ 4] = -m[ 4] * m[10] * m[15] +
+ m[ 4] * m[11] * m[14] +
+ m[ 8] * m[ 6] * m[15] -
+ m[ 8] * m[ 7] * m[14] -
+ m[12] * m[ 6] * m[11] +
+ m[12] * m[ 7] * m[10];
+
+ d[ 8] = m[ 4] * m[ 9] * m[15] -
+ m[ 4] * m[11] * m[13] -
+ m[ 8] * m[ 5] * m[15] +
+ m[ 8] * m[ 7] * m[13] +
+ m[12] * m[ 5] * m[11] -
+ m[12] * m[ 7] * m[ 9];
+
+ d[12] = -m[ 4] * m[ 9] * m[14] +
+ m[ 4] * m[10] * m[13] +
+ m[ 8] * m[ 5] * m[14] -
+ m[ 8] * m[ 6] * m[13] -
+ m[12] * m[ 5] * m[10] +
+ m[12] * m[ 6] * m[ 9];
+
+ d[ 1] = -m[ 1] * m[10] * m[15] +
+ m[ 1] * m[11] * m[14] +
+ m[ 9] * m[ 2] * m[15] -
+ m[ 9] * m[ 3] * m[14] -
+ m[13] * m[ 2] * m[11] +
+ m[13] * m[ 3] * m[10];
+
+ d[ 5] = m[ 0] * m[10] * m[15] -
+ m[ 0] * m[11] * m[14] -
+ m[ 8] * m[ 2] * m[15] +
+ m[ 8] * m[ 3] * m[14] +
+ m[12] * m[ 2] * m[11] -
+ m[12] * m[ 3] * m[10];
+
+ d[ 9] = -m[ 0] * m[ 9] * m[15] +
+ m[ 0] * m[11] * m[13] +
+ m[ 8] * m[ 1] * m[15] -
+ m[ 8] * m[ 3] * m[13] -
+ m[12] * m[ 1] * m[11] +
+ m[12] * m[ 3] * m[ 9];
+
+ d[13] = m[ 0] * m[ 9] * m[14] -
+ m[ 0] * m[10] * m[13] -
+ m[ 8] * m[ 1] * m[14] +
+ m[ 8] * m[ 2] * m[13] +
+ m[12] * m[ 1] * m[10] -
+ m[12] * m[ 2] * m[ 9];
+
+ d[ 2] = m[ 1] * m[ 6] * m[15] -
+ m[ 1] * m[ 7] * m[14] -
+ m[ 5] * m[ 2] * m[15] +
+ m[ 5] * m[ 3] * m[14] +
+ m[13] * m[ 2] * m[ 7] -
+ m[13] * m[ 3] * m[ 6];
+
+ d[ 6] = -m[ 0] * m[ 6] * m[15] +
+ m[ 0] * m[ 7] * m[14] +
+ m[ 4] * m[ 2] * m[15] -
+ m[ 4] * m[ 3] * m[14] -
+ m[12] * m[ 2] * m[ 7] +
+ m[12] * m[ 3] * m[ 6];
+
+ d[10] = m[ 0] * m[ 5] * m[15] -
+ m[ 0] * m[ 7] * m[13] -
+ m[ 4] * m[ 1] * m[15] +
+ m[ 4] * m[ 3] * m[13] +
+ m[12] * m[ 1] * m[ 7] -
+ m[12] * m[ 3] * m[ 5];
+
+ d[14] = -m[ 0] * m[ 5] * m[14] +
+ m[ 0] * m[ 6] * m[13] +
+ m[ 4] * m[ 1] * m[14] -
+ m[ 4] * m[ 2] * m[13] -
+ m[12] * m[ 1] * m[ 6] +
+ m[12] * m[ 2] * m[ 5];
+
+ d[ 3] = -m[ 1] * m[ 6] * m[11] +
+ m[ 1] * m[ 7] * m[10] +
+ m[ 5] * m[ 2] * m[11] -
+ m[ 5] * m[ 3] * m[10] -
+ m[ 9] * m[ 2] * m[ 7] +
+ m[ 9] * m[ 3] * m[ 6];
+
+ d[ 7] = m[ 0] * m[ 6] * m[11] -
+ m[ 0] * m[ 7] * m[10] -
+ m[ 4] * m[ 2] * m[11] +
+ m[ 4] * m[ 3] * m[10] +
+ m[ 8] * m[ 2] * m[ 7] -
+ m[ 8] * m[ 3] * m[ 6];
+
+ d[11] = -m[ 0] * m[ 5] * m[11] +
+ m[ 0] * m[ 7] * m[ 9] +
+ m[ 4] * m[ 1] * m[11] -
+ m[ 4] * m[ 3] * m[ 9] -
+ m[ 8] * m[ 1] * m[ 7] +
+ m[ 8] * m[ 3] * m[ 5];
+
+ d[15] = m[ 0] * m[ 5] * m[10] -
+ m[ 0] * m[ 6] * m[ 9] -
+ m[ 4] * m[ 1] * m[10] +
+ m[ 4] * m[ 2] * m[ 9] +
+ m[ 8] * m[ 1] * m[ 6] -
+ m[ 8] * m[ 2] * m[ 5];
+
+ det = m[0] * d[0] + m[1] * d[4] + m[2] * d[8] + m[3] * d[12];
+
+ if (det == 0.0) {
+ PEPPER_ERROR("Matrix is singular. Unable to get inverse matrix.\n");
+ return;
+ }
+
+ det = 1.0 / det;
+
+ d[ 0] *= det;
+ d[ 1] *= det;
+ d[ 2] *= det;
+ d[ 3] *= det;
+ d[ 4] *= det;
+ d[ 5] *= det;
+ d[ 6] *= det;
+ d[ 7] *= det;
+ d[ 8] *= det;
+ d[ 9] *= det;
+ d[10] *= det;
+ d[11] *= det;
+ d[12] *= det;
+ d[13] *= det;
+ d[14] *= det;
+ d[15] *= det;
+
+ pepper_mat4_copy(dst, &tmp);
+ dst->flags = src->flags;
}
static inline void
pepper_mat4_transform_vec2(const pepper_mat4_t *matrix, pepper_vec2_t *v)
{
- double x, y;
- const double *m = &matrix->m[0];
+ double x, y;
+ const double *m = &matrix->m[0];
- x = m[0] * v->x + m[4] * v->y + m[12];
- y = m[1] * v->x + m[5] * v->y + m[13];
+ x = m[0] * v->x + m[4] * v->y + m[12];
+ y = m[1] * v->x + m[5] * v->y + m[13];
- v->x = x;
- v->y = y;
+ v->x = x;
+ v->y = y;
}
static inline void
pepper_mat4_transform_vec3(const pepper_mat4_t *matrix, pepper_vec3_t *v)
{
- double x, y, z;
- const double *m = &matrix->m[0];
+ double x, y, z;
+ const double *m = &matrix->m[0];
- x = m[0] * v->x + m[4] * v->y + m[ 8] * v->z + m[12];
- y = m[1] * v->x + m[5] * v->y + m[ 9] * v->z + m[13];
- z = m[2] * v->x + m[6] * v->y + m[10] * v->z + m[14];
+ x = m[0] * v->x + m[4] * v->y + m[ 8] * v->z + m[12];
+ y = m[1] * v->x + m[5] * v->y + m[ 9] * v->z + m[13];
+ z = m[2] * v->x + m[6] * v->y + m[10] * v->z + m[14];
- v->x = x;
- v->y = y;
- v->z = z;
+ v->x = x;
+ v->y = y;
+ v->z = z;
}
static inline void
pepper_mat4_transform_vec4(const pepper_mat4_t *matrix, pepper_vec4_t *v)
{
- double x, y, z, w;
- const double *m = &matrix->m[0];
-
- x = m[0] * v->x + m[4] * v->y + m[ 8] * v->z + m[12] * v->w;
- y = m[1] * v->x + m[5] * v->y + m[ 9] * v->z + m[13] * v->w;
- z = m[2] * v->x + m[6] * v->y + m[10] * v->z + m[14] * v->w;
- w = m[3] * v->x + m[7] * v->y + m[11] * v->z + m[15] * v->w;
-
- v->x = x;
- v->y = y;
- v->z = z;
- v->w = w;
+ double x, y, z, w;
+ const double *m = &matrix->m[0];
+
+ x = m[0] * v->x + m[4] * v->y + m[ 8] * v->z + m[12] * v->w;
+ y = m[1] * v->x + m[5] * v->y + m[ 9] * v->z + m[13] * v->w;
+ z = m[2] * v->x + m[6] * v->y + m[10] * v->z + m[14] * v->w;
+ w = m[3] * v->x + m[7] * v->y + m[11] * v->z + m[15] * v->w;
+
+ v->x = x;
+ v->y = y;
+ v->z = z;
+ v->w = w;
}
/* Virtual terminal */
* @param info information of the event.
* @param data data passed when adding the event listener.
*/
-typedef void (*pepper_event_callback_t)(pepper_event_listener_t *listener, pepper_object_t *object,
- uint32_t id, void *info, void *data);
+typedef void (*pepper_event_callback_t)(pepper_event_listener_t *listener,
+ pepper_object_t *object,
+ uint32_t id, void *info, void *data);
/**
* @typedef pepper_input_event_t
*/
typedef struct pepper_touch_grab pepper_touch_grab_t;
-struct pepper_output_geometry
-{
- int32_t x; /**< x coordinate of the output on the compositor coordinate space. */
- int32_t y; /**< y coordinate of the output on the compositor coordinate space. */
- int32_t w; /**< width of the output. */
- int32_t h; /**< height of the output. */
- int32_t subpixel; /**< subpixel layout of the output. */
- const char *maker; /**< maker of the output. */
- const char *model; /**< model name of the output. */
- int32_t transform; /**< wl_output::transform. */
+struct pepper_output_geometry {
+ int32_t
+ x; /**< x coordinate of the output on the compositor coordinate space. */
+ int32_t
+ y; /**< y coordinate of the output on the compositor coordinate space. */
+ int32_t w; /**< width of the output. */
+ int32_t h; /**< height of the output. */
+ int32_t subpixel; /**< subpixel layout of the output. */
+ const char *maker; /**< maker of the output. */
+ const char *model; /**< model name of the output. */
+ int32_t transform; /**< wl_output::transform. */
};
-struct pepper_output_mode
-{
- uint32_t flags; /**< bit flag #pepper_outout_mode_flag. */
- int32_t w, h; /**< width and height of the output mode. */
- int32_t refresh; /**< refresh rate. */
+struct pepper_output_mode {
+ uint32_t flags; /**< bit flag #pepper_outout_mode_flag. */
+ int32_t w, h; /**< width and height of the output mode. */
+ int32_t refresh; /**< refresh rate. */
};
-enum pepper_output_mode_flag
-{
- PEPPER_OUTPUT_MODE_INVALID = (1 << 0), /**< the mode is invalid. */
- PEPPER_OUTPUT_MODE_CURRENT = (1 << 1), /**< the mode is current mode. */
- PEPPER_OUTPUT_MODE_PREFERRED = (1 << 2), /**< the mode is preferred mode. */
+enum pepper_output_mode_flag {
+ PEPPER_OUTPUT_MODE_INVALID = (1 << 0), /**< the mode is invalid. */
+ PEPPER_OUTPUT_MODE_CURRENT = (1 << 1), /**< the mode is current mode. */
+ PEPPER_OUTPUT_MODE_PREFERRED = (1 << 2), /**< the mode is preferred mode. */
};
-typedef enum pepper_object_type
-{
- PEPPER_OBJECT_COMPOSITOR, /**< #pepper_compositor_t */
- PEPPER_OBJECT_OUTPUT, /**< #pepper_output_t */
- PEPPER_OBJECT_SURFACE, /**< #pepper_surface_t */
- PEPPER_OBJECT_BUFFER, /**< #pepper_buffer_t */
- PEPPER_OBJECT_VIEW, /**< #pepper_view_t */
- PEPPER_OBJECT_SEAT, /**< #pepper_seat_t */
- PEPPER_OBJECT_POINTER, /**< #pepper_pointer_t */
- PEPPER_OBJECT_KEYBOARD, /**< #pepper_keyboard_t */
- PEPPER_OBJECT_TOUCH, /**< #pepper_touch_t */
- PEPPER_OBJECT_INPUT_DEVICE, /**< #pepper_input_device_t */
- PEPPER_OBJECT_PLANE, /**< #pepper_plane_t (internally used) */
- PEPPER_OBJECT_SUBCOMPOSITOR,/**< #pepper_compositor_t */
+typedef enum pepper_object_type {
+ PEPPER_OBJECT_COMPOSITOR, /**< #pepper_compositor_t */
+ PEPPER_OBJECT_OUTPUT, /**< #pepper_output_t */
+ PEPPER_OBJECT_SURFACE, /**< #pepper_surface_t */
+ PEPPER_OBJECT_BUFFER, /**< #pepper_buffer_t */
+ PEPPER_OBJECT_VIEW, /**< #pepper_view_t */
+ PEPPER_OBJECT_SEAT, /**< #pepper_seat_t */
+ PEPPER_OBJECT_POINTER, /**< #pepper_pointer_t */
+ PEPPER_OBJECT_KEYBOARD, /**< #pepper_keyboard_t */
+ PEPPER_OBJECT_TOUCH, /**< #pepper_touch_t */
+ PEPPER_OBJECT_INPUT_DEVICE, /**< #pepper_input_device_t */
+ PEPPER_OBJECT_PLANE, /**< #pepper_plane_t (internally used) */
+ PEPPER_OBJECT_SUBCOMPOSITOR,/**< #pepper_compositor_t */
} pepper_object_type_t;
-enum pepper_built_in_events
-{
- /**
- * All events of a #pepper_object_t
- *
- * #pepper_object_t
- * - when : Any event is emitted
- * - info : corresponding info of the event
- */
- PEPPER_EVENT_ALL,
-
- /**
- * Destruction of a #pepper_object_t
- *
- * #pepper_object_t
- * - when : #pepper_object_t is about to be destroyed
- * - info : NULL
- */
- PEPPER_EVENT_OBJECT_DESTROY,
-
- /**
- * Addition of a #pepper_output_t to a #pepper_compositor_t
- *
- * #pepper_compositor_t
- * - when : #pepper_output_t has been added
- * - info : the added #pepper_output_t
- */
- PEPPER_EVENT_COMPOSITOR_OUTPUT_ADD,
-
- /**
- * Removal of a #pepper_output_t from a #pepper_compositor_t
- *
- * #pepper_compositor_t
- * - when : #pepper_output_t has been removed
- * - info : the removed #pepper_output_t.
- */
- PEPPER_EVENT_COMPOSITOR_OUTPUT_REMOVE,
-
- /**
- * Addition of a #pepper_seat_t to a #pepper_compositor_t
- *
- * #pepper_compositor_t
- * - when : #pepper_seat_t has been added
- * - info : the added #pepper_seat_t
- */
- PEPPER_EVENT_COMPOSITOR_SEAT_ADD,
-
- /**
- * Removal of a #pepper_seat_t from a #pepper_compositor_t.
- *
- * #pepper_compositor_t
- * - when : #pepper_seat_t has been removed
- * - info : the removed #pepper_seat_t
- */
- PEPPER_EVENT_COMPOSITOR_SEAT_REMOVE,
-
- /**
- * Addition of a #pepper_surface_t to a #pepper_compositor_t.
- *
- * #pepper_compositor_t
- * - when : #pepper_surface_t has been added
- * - info : the added #pepper_surface_t
- */
- PEPPER_EVENT_COMPOSITOR_SURFACE_ADD,
-
- /**
- * Removal of a #pepper_surface_t from a #pepper_compositor_t.
- *
- * #pepper_compositor_t
- * - when : #pepper_surface_t has been removed
- * - info : the removed #pepper_surface_t
- */
- PEPPER_EVENT_COMPOSITOR_SURFACE_REMOVE,
-
- /**
- * Addition of a #pepper_view_t to a #pepper_compositor_t.
- *
- * #pepper_compositor_t
- * - when : #pepper_view_t has been added
- * - info : the added #pepper_view_t
- */
- PEPPER_EVENT_COMPOSITOR_VIEW_ADD,
-
- /**
- * Removal of a #pepper_view_t from a #pepper_compositor_t.
- *
- * #pepper_compositor_t
- * - when : #pepper_view_t has been removed
- * - info : the removed #pepper_view_t
- */
- PEPPER_EVENT_COMPOSITOR_VIEW_REMOVE,
-
- /**
- * Addition of a #pepper_input_device_t to a #pepper_compositor_t.
- *
- * #pepper_compositor_t
- * - when : #pepper_input_device_t has been added
- * - info : the added #pepper_input_device_t
- */
- PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
-
- /**
- * Removal of a #pepper_input_device_t from a #pepper_compositor_t.
- *
- * #pepper_compositor_t
- * - when : #pepper_input_device_t has been removed
- * - info : the removed #pepper_input_device_t
- */
- PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE,
-
- /**
- * Change in current mode of a #pepper_output_t.
- *
- * #pepper_output_t
- * - when : mode of the #pepper_output_t has been changed
- * - info : NULL
- */
- PEPPER_EVENT_OUTPUT_MODE_CHANGE,
-
- /**
- * Change in position of a #pepper_output_t.
- *
- * #pepper_output_t
- * - when : #pepper_output_t has moved its position.
- * - info : NULL
- */
- PEPPER_EVENT_OUTPUT_MOVE,
-
- /**
- * wl_surface::commit
- *
- * #pepper_surface_t
- * - when : wl_surface::commit has been requested
- * - info : NULL
- */
- PEPPER_EVENT_SURFACE_COMMIT,
-
- /**
- * wl_buffer::release
- *
- * #pepper_buffer_t
- * - when : wl_buffer::release has been sent
- * - info : NULL
- */
- PEPPER_EVENT_BUFFER_RELEASE,
-
- /**
- * Z-order change of a #pepper_view_t.
- *
- * #pepper_view_t
- * - when : stack (z-order) has been changed
- * - info : NULL
- */
- PEPPER_EVENT_VIEW_STACK_CHANGE,
-
- /**
- * Addition of a #pepper_pointer_t to a #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_pointer_t has been added
- * - info : the added #pepper_pointer_t
- */
- PEPPER_EVENT_SEAT_POINTER_ADD,
-
- /**
- * Removal of a #pepper_pointer_t from a #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_pointer_t has been removed
- * - info : the removed #pepper_pointer_t
- */
- PEPPER_EVENT_SEAT_POINTER_REMOVE,
-
- /**
- * Addition of a #pepper_keyboard_t to a #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_keyboard_t has been added
- * - info : the added #pepper_keyboard_t
- */
- PEPPER_EVENT_SEAT_KEYBOARD_ADD,
-
- /**
- * Removal of a #pepper_keyboard_t from a #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_keyboard_t has been removed
- * - info : the removed #pepper_keyboard_t
- */
- PEPPER_EVENT_SEAT_KEYBOARD_REMOVE,
-
- /**
- * Addition of a #pepper_touch_t to a #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_touch_t has been added
- * - info : the added #pepper_touch_t
- */
- PEPPER_EVENT_SEAT_TOUCH_ADD,
-
- /**
- * Removal of a #pepper_touch_t from a #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_touch_t has been removed
- * - info : the removed #pepper_touch_t
- */
- PEPPER_EVENT_SEAT_TOUCH_REMOVE,
-
- /**
- * Addition of a #pepper_input_device_t having pointer capability to a
- * #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_input_device_t having pointer capability has been added
- * - info : the added #pepper_input_device_t
- */
- PEPPER_EVENT_SEAT_POINTER_DEVICE_ADD,
-
- /**
- * Removal of a #pepper_input_device_t having pointer capability from a
- * #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_input_device_t having pointer capability has been removed
- * - info : the removed #pepper_input_device_t
- */
- PEPPER_EVENT_SEAT_POINTER_DEVICE_REMOVE,
-
- /**
- * Addition of a #pepper_input_device_t having keyboard capability to a
- * #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_input_device_t having keyboard capability has been added
- * - info : the added #pepper_input_device_t
- */
- PEPPER_EVENT_SEAT_KEYBOARD_DEVICE_ADD,
-
- /**
- * Removal of a #pepper_input_device_t having keyboard capability from a
- * #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_input_device_t having keyboard capability has been removed
- * - info : the removed #pepper_input_device_t
- */
- PEPPER_EVENT_SEAT_KEYBOARD_DEVICE_REMOVE,
-
- /**
- * Addition of a #pepper_input_device_t having touch capability to a
- * #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_input_device_t having touch capability has been added
- * - info : the added #pepper_input_device_t
- */
- PEPPER_EVENT_SEAT_TOUCH_DEVICE_ADD,
-
- /**
- * Removal of a #pepper_input_device_t having touch capability from a
- * #pepper_seat_t.
- *
- * #pepper_seat_t
- * - when : #pepper_input_device_t having touch capability has been removed
- * - info : the removed #pepper_input_device_t
- */
- PEPPER_EVENT_SEAT_TOUCH_DEVICE_REMOVE,
-
- /**
- * Relative pointer device motion event.
- *
- * #pepper_input_device_t
- * - when : input backend emits pointer motion event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION,
-
- /**
- * Absolute pointer motion event.
- *
- * #pepper_input_device_t
- * - when : input backend emits pointer motion event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE,
-
- /**
- * Pointer button event.
- *
- * #pepper_input_device_t
- * - when : input backend emits pointer button event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON,
-
- /**
- * Pointer axis event.
- *
- * #pepper_input_device_t
- * - when : input backend emits pointer axis event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS,
-
- /**
- * Keyboard key event.
- *
- * #pepper_input_device_t
- * - when : input backend emits key event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY,
-
- /**
- * Touch down event.
- *
- * #pepper_input_device_t
- * - when : input backend emits touch down event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_DOWN,
-
- /**
- * Touch up event.
- *
- * #pepper_input_device_t
- * - when : input backend emits touch up event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_UP,
-
- /**
- * Touch motion event.
- *
- * #pepper_input_device_t
- * - when : input backend emits touch motion event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_MOTION,
-
- /**
- * touch frame event.
- *
- * #pepper_input_device_t
- * - when : input backend emits touch frame event
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_INPUT_DEVICE_TOUCH_FRAME,
-
- /**
- * #pepper_view_t get an input focus.
- *
- * #pepper_pointer_t
- * - when : #pepper_view_t has been set for the focus
- * - info : the focused #pepper_view_t
- *
- * #pepper_keyboard_t
- * - when : #pepper_view_t has been set for the focus
- * - info : the focused #pepper_view_t
- *
- * #pepper_touch_t
- * - when : #pepper_view_t has been set for the focus
- * - info : the focused #pepper_view_t
- *
- * #pepper_view_t
- * - when : Get focused for any of #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
- * - info : #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
- */
- PEPPER_EVENT_FOCUS_ENTER,
-
- /**
- * #pepper_view_t loses an input focus.
- *
- * #pepper_pointer_t
- * - when : current focus has been changed
- * - info : previously focused #pepper_view_t
- *
- * #pepper_keyboard_t
- * - when : current focus has been changed
- * - info : previously focused #pepper_view_t
- *
- * #pepper_touch_t
- * - when : current focus has been changed
- * - info : previously focused #pepper_view_t
- *
- * #pepper_view_t
- * - when : loses any focus of #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
- * - info : #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
- */
- PEPPER_EVENT_FOCUS_LEAVE,
-
- /**
- * Relative pointer motion event.
- *
- * #pepper_pointer_t
- * - when : #pepper_input_device_t emits pointer motion event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_POINTER_MOTION,
-
- /**
- * Absolute pointer motion event.
- *
- * #pepper_pointer_t
- * - when : #pepper_input_device_t emits pointer motion event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_POINTER_MOTION_ABSOLUTE,
-
- /**
- * Pointer button event.
- *
- * #pepper_pointer_t
- * - when : #pepper_input_device_t emits pointer button event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_POINTER_BUTTON,
-
- /**
- * Pointer axis event.
- *
- * #pepper_pointer_t
- * - when : #pepper_input_device_t emits pointer axis event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_POINTER_AXIS,
-
- /**
- * Keyboard key event.
- *
- * #pepper_keyboard_t
- * - when : #pepper_input_device_t emits key event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_KEYBOARD_KEY,
-
- /**
- * Touch down event.
- *
- * #pepper_touch_t
- * - when : #pepper_input_device_t emits touch down event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_TOUCH_DOWN,
-
- /**
- * Touch up event.
- *
- * #pepper_touch_t
- * - when : #pepper_input_device_t emits touch up event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_TOUCH_UP,
-
- /**
- * Touch motion event.
- *
- * #pepper_touch_t
- * - when : #pepper_input_device_t emits touch motion event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_TOUCH_MOTION,
-
- /**
- * touch frame event.
- *
- * #pepper_touch_t
- * - when : #pepper_input_device_t emits touch frame event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_TOUCH_FRAME,
-
- /**
- * Touch calcen event.
- *
- * #pepper_touch_t
- * - when : #pepper_input_device_t emits touch cancel event (to the attached #pepper_seat_t)
- * - info : #pepper_input_event_t
- */
- PEPPER_EVENT_TOUCH_CANCEL,
+enum pepper_built_in_events {
+ /**
+ * All events of a #pepper_object_t
+ *
+ * #pepper_object_t
+ * - when : Any event is emitted
+ * - info : corresponding info of the event
+ */
+ PEPPER_EVENT_ALL,
+
+ /**
+ * Destruction of a #pepper_object_t
+ *
+ * #pepper_object_t
+ * - when : #pepper_object_t is about to be destroyed
+ * - info : NULL
+ */
+ PEPPER_EVENT_OBJECT_DESTROY,
+
+ /**
+ * Addition of a #pepper_output_t to a #pepper_compositor_t
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_output_t has been added
+ * - info : the added #pepper_output_t
+ */
+ PEPPER_EVENT_COMPOSITOR_OUTPUT_ADD,
+
+ /**
+ * Removal of a #pepper_output_t from a #pepper_compositor_t
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_output_t has been removed
+ * - info : the removed #pepper_output_t.
+ */
+ PEPPER_EVENT_COMPOSITOR_OUTPUT_REMOVE,
+
+ /**
+ * Addition of a #pepper_seat_t to a #pepper_compositor_t
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_seat_t has been added
+ * - info : the added #pepper_seat_t
+ */
+ PEPPER_EVENT_COMPOSITOR_SEAT_ADD,
+
+ /**
+ * Removal of a #pepper_seat_t from a #pepper_compositor_t.
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_seat_t has been removed
+ * - info : the removed #pepper_seat_t
+ */
+ PEPPER_EVENT_COMPOSITOR_SEAT_REMOVE,
+
+ /**
+ * Addition of a #pepper_surface_t to a #pepper_compositor_t.
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_surface_t has been added
+ * - info : the added #pepper_surface_t
+ */
+ PEPPER_EVENT_COMPOSITOR_SURFACE_ADD,
+
+ /**
+ * Removal of a #pepper_surface_t from a #pepper_compositor_t.
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_surface_t has been removed
+ * - info : the removed #pepper_surface_t
+ */
+ PEPPER_EVENT_COMPOSITOR_SURFACE_REMOVE,
+
+ /**
+ * Addition of a #pepper_view_t to a #pepper_compositor_t.
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_view_t has been added
+ * - info : the added #pepper_view_t
+ */
+ PEPPER_EVENT_COMPOSITOR_VIEW_ADD,
+
+ /**
+ * Removal of a #pepper_view_t from a #pepper_compositor_t.
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_view_t has been removed
+ * - info : the removed #pepper_view_t
+ */
+ PEPPER_EVENT_COMPOSITOR_VIEW_REMOVE,
+
+ /**
+ * Addition of a #pepper_input_device_t to a #pepper_compositor_t.
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_input_device_t has been added
+ * - info : the added #pepper_input_device_t
+ */
+ PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
+
+ /**
+ * Removal of a #pepper_input_device_t from a #pepper_compositor_t.
+ *
+ * #pepper_compositor_t
+ * - when : #pepper_input_device_t has been removed
+ * - info : the removed #pepper_input_device_t
+ */
+ PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_REMOVE,
+
+ /**
+ * Change in current mode of a #pepper_output_t.
+ *
+ * #pepper_output_t
+ * - when : mode of the #pepper_output_t has been changed
+ * - info : NULL
+ */
+ PEPPER_EVENT_OUTPUT_MODE_CHANGE,
+
+ /**
+ * Change in position of a #pepper_output_t.
+ *
+ * #pepper_output_t
+ * - when : #pepper_output_t has moved its position.
+ * - info : NULL
+ */
+ PEPPER_EVENT_OUTPUT_MOVE,
+
+ /**
+ * wl_surface::commit
+ *
+ * #pepper_surface_t
+ * - when : wl_surface::commit has been requested
+ * - info : NULL
+ */
+ PEPPER_EVENT_SURFACE_COMMIT,
+
+ /**
+ * wl_buffer::release
+ *
+ * #pepper_buffer_t
+ * - when : wl_buffer::release has been sent
+ * - info : NULL
+ */
+ PEPPER_EVENT_BUFFER_RELEASE,
+
+ /**
+ * Z-order change of a #pepper_view_t.
+ *
+ * #pepper_view_t
+ * - when : stack (z-order) has been changed
+ * - info : NULL
+ */
+ PEPPER_EVENT_VIEW_STACK_CHANGE,
+
+ /**
+ * Addition of a #pepper_pointer_t to a #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_pointer_t has been added
+ * - info : the added #pepper_pointer_t
+ */
+ PEPPER_EVENT_SEAT_POINTER_ADD,
+
+ /**
+ * Removal of a #pepper_pointer_t from a #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_pointer_t has been removed
+ * - info : the removed #pepper_pointer_t
+ */
+ PEPPER_EVENT_SEAT_POINTER_REMOVE,
+
+ /**
+ * Addition of a #pepper_keyboard_t to a #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_keyboard_t has been added
+ * - info : the added #pepper_keyboard_t
+ */
+ PEPPER_EVENT_SEAT_KEYBOARD_ADD,
+
+ /**
+ * Removal of a #pepper_keyboard_t from a #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_keyboard_t has been removed
+ * - info : the removed #pepper_keyboard_t
+ */
+ PEPPER_EVENT_SEAT_KEYBOARD_REMOVE,
+
+ /**
+ * Addition of a #pepper_touch_t to a #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_touch_t has been added
+ * - info : the added #pepper_touch_t
+ */
+ PEPPER_EVENT_SEAT_TOUCH_ADD,
+
+ /**
+ * Removal of a #pepper_touch_t from a #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_touch_t has been removed
+ * - info : the removed #pepper_touch_t
+ */
+ PEPPER_EVENT_SEAT_TOUCH_REMOVE,
+
+ /**
+ * Addition of a #pepper_input_device_t having pointer capability to a
+ * #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_input_device_t having pointer capability has been added
+ * - info : the added #pepper_input_device_t
+ */
+ PEPPER_EVENT_SEAT_POINTER_DEVICE_ADD,
+
+ /**
+ * Removal of a #pepper_input_device_t having pointer capability from a
+ * #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_input_device_t having pointer capability has been removed
+ * - info : the removed #pepper_input_device_t
+ */
+ PEPPER_EVENT_SEAT_POINTER_DEVICE_REMOVE,
+
+ /**
+ * Addition of a #pepper_input_device_t having keyboard capability to a
+ * #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_input_device_t having keyboard capability has been added
+ * - info : the added #pepper_input_device_t
+ */
+ PEPPER_EVENT_SEAT_KEYBOARD_DEVICE_ADD,
+
+ /**
+ * Removal of a #pepper_input_device_t having keyboard capability from a
+ * #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_input_device_t having keyboard capability has been removed
+ * - info : the removed #pepper_input_device_t
+ */
+ PEPPER_EVENT_SEAT_KEYBOARD_DEVICE_REMOVE,
+
+ /**
+ * Addition of a #pepper_input_device_t having touch capability to a
+ * #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_input_device_t having touch capability has been added
+ * - info : the added #pepper_input_device_t
+ */
+ PEPPER_EVENT_SEAT_TOUCH_DEVICE_ADD,
+
+ /**
+ * Removal of a #pepper_input_device_t having touch capability from a
+ * #pepper_seat_t.
+ *
+ * #pepper_seat_t
+ * - when : #pepper_input_device_t having touch capability has been removed
+ * - info : the removed #pepper_input_device_t
+ */
+ PEPPER_EVENT_SEAT_TOUCH_DEVICE_REMOVE,
+
+ /**
+ * Relative pointer device motion event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits pointer motion event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION,
+
+ /**
+ * Absolute pointer motion event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits pointer motion event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE,
+
+ /**
+ * Pointer button event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits pointer button event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON,
+
+ /**
+ * Pointer axis event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits pointer axis event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS,
+
+ /**
+ * Keyboard key event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits key event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY,
+
+ /**
+ * Touch down event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits touch down event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_DOWN,
+
+ /**
+ * Touch up event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits touch up event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_UP,
+
+ /**
+ * Touch motion event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits touch motion event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_MOTION,
+
+ /**
+ * touch frame event.
+ *
+ * #pepper_input_device_t
+ * - when : input backend emits touch frame event
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_INPUT_DEVICE_TOUCH_FRAME,
+
+ /**
+ * #pepper_view_t get an input focus.
+ *
+ * #pepper_pointer_t
+ * - when : #pepper_view_t has been set for the focus
+ * - info : the focused #pepper_view_t
+ *
+ * #pepper_keyboard_t
+ * - when : #pepper_view_t has been set for the focus
+ * - info : the focused #pepper_view_t
+ *
+ * #pepper_touch_t
+ * - when : #pepper_view_t has been set for the focus
+ * - info : the focused #pepper_view_t
+ *
+ * #pepper_view_t
+ * - when : Get focused for any of #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
+ * - info : #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
+ */
+ PEPPER_EVENT_FOCUS_ENTER,
+
+ /**
+ * #pepper_view_t loses an input focus.
+ *
+ * #pepper_pointer_t
+ * - when : current focus has been changed
+ * - info : previously focused #pepper_view_t
+ *
+ * #pepper_keyboard_t
+ * - when : current focus has been changed
+ * - info : previously focused #pepper_view_t
+ *
+ * #pepper_touch_t
+ * - when : current focus has been changed
+ * - info : previously focused #pepper_view_t
+ *
+ * #pepper_view_t
+ * - when : loses any focus of #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
+ * - info : #pepper_pointer_t/#pepper_keyboard_t/#pepper_touch_t
+ */
+ PEPPER_EVENT_FOCUS_LEAVE,
+
+ /**
+ * Relative pointer motion event.
+ *
+ * #pepper_pointer_t
+ * - when : #pepper_input_device_t emits pointer motion event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_POINTER_MOTION,
+
+ /**
+ * Absolute pointer motion event.
+ *
+ * #pepper_pointer_t
+ * - when : #pepper_input_device_t emits pointer motion event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_POINTER_MOTION_ABSOLUTE,
+
+ /**
+ * Pointer button event.
+ *
+ * #pepper_pointer_t
+ * - when : #pepper_input_device_t emits pointer button event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_POINTER_BUTTON,
+
+ /**
+ * Pointer axis event.
+ *
+ * #pepper_pointer_t
+ * - when : #pepper_input_device_t emits pointer axis event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_POINTER_AXIS,
+
+ /**
+ * Keyboard key event.
+ *
+ * #pepper_keyboard_t
+ * - when : #pepper_input_device_t emits key event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_KEYBOARD_KEY,
+
+ /**
+ * Touch down event.
+ *
+ * #pepper_touch_t
+ * - when : #pepper_input_device_t emits touch down event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_TOUCH_DOWN,
+
+ /**
+ * Touch up event.
+ *
+ * #pepper_touch_t
+ * - when : #pepper_input_device_t emits touch up event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_TOUCH_UP,
+
+ /**
+ * Touch motion event.
+ *
+ * #pepper_touch_t
+ * - when : #pepper_input_device_t emits touch motion event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_TOUCH_MOTION,
+
+ /**
+ * touch frame event.
+ *
+ * #pepper_touch_t
+ * - when : #pepper_input_device_t emits touch frame event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_TOUCH_FRAME,
+
+ /**
+ * Touch calcen event.
+ *
+ * #pepper_touch_t
+ * - when : #pepper_input_device_t emits touch cancel event (to the attached #pepper_seat_t)
+ * - info : #pepper_input_event_t
+ */
+ PEPPER_EVENT_TOUCH_CANCEL,
};
-enum pepper_pointer_axis
-{
- PEPPER_POINTER_AXIS_VERTICAL, /**< vertical pointer axis. */
- PEPPER_POINTER_AXIS_HORIZONTAL, /**< horizontal pointer axis. */
+enum pepper_pointer_axis {
+ PEPPER_POINTER_AXIS_VERTICAL, /**< vertical pointer axis. */
+ PEPPER_POINTER_AXIS_HORIZONTAL, /**< horizontal pointer axis. */
};
-enum pepper_button_state
-{
- PEPPER_BUTTON_STATE_RELEASED, /**< button is relased. */
- PEPPER_BUTTON_STATE_PRESSED, /**< button is pressed. */
+enum pepper_button_state {
+ PEPPER_BUTTON_STATE_RELEASED, /**< button is relased. */
+ PEPPER_BUTTON_STATE_PRESSED, /**< button is pressed. */
};
-enum pepper_key_state
-{
- PEPPER_KEY_STATE_RELEASED, /**< key is released. */
- PEPPER_KEY_STATE_PRESSED, /**< key is pressed. */
+enum pepper_key_state {
+ PEPPER_KEY_STATE_RELEASED, /**< key is released. */
+ PEPPER_KEY_STATE_PRESSED, /**< key is pressed. */
};
-struct pepper_input_event
-{
- uint32_t time; /**< time in mili-second with undefined base. */
- uint32_t button; /**< pointer button flag. */
- uint32_t state; /**< pointer and key state flag. */
- uint32_t axis; /**< pointer axis. */
- uint32_t key; /**< keyboard key. */
- uint32_t slot; /**< touch point id. */
- double x, y; /**< x, y coordinate value. */
- double value; /**< pointer axis value. */
+struct pepper_input_event {
+ uint32_t time; /**< time in mili-second with undefined base. */
+ uint32_t button; /**< pointer button flag. */
+ uint32_t state; /**< pointer and key state flag. */
+ uint32_t axis; /**< pointer axis. */
+ uint32_t key; /**< keyboard key. */
+ uint32_t slot; /**< touch point id. */
+ double x, y; /**< x, y coordinate value. */
+ double value; /**< pointer axis value. */
};
PEPPER_API pepper_object_type_t
pepper_object_get_type(pepper_object_t *object);
PEPPER_API void
-pepper_object_set_user_data(pepper_object_t *object, const void *key, void *data,
- pepper_free_func_t free_func);
+pepper_object_set_user_data(pepper_object_t *object, const void *key,
+ void *data,
+ pepper_free_func_t free_func);
PEPPER_API void *
pepper_object_get_user_data(pepper_object_t *object, const void *key);
PEPPER_API pepper_event_listener_t *
-pepper_object_add_event_listener(pepper_object_t *object, uint32_t id, int priority,
- pepper_event_callback_t callback, void *data);
+pepper_object_add_event_listener(pepper_object_t *object, uint32_t id,
+ int priority,
+ pepper_event_callback_t callback, void *data);
PEPPER_API void
pepper_event_listener_remove(pepper_event_listener_t *listener);
PEPPER_API void
-pepper_event_listener_set_priority(pepper_event_listener_t *listener, int priority);
+pepper_event_listener_set_priority(pepper_event_listener_t *listener,
+ int priority);
PEPPER_API void
pepper_object_emit_event(pepper_object_t *object, uint32_t id, void *info);
PEPPER_API pepper_view_t *
pepper_compositor_pick_view(pepper_compositor_t *compositor,
- double x, double y, double *vx, double *vy);
+ double x, double y, double *vx, double *vy);
PEPPER_API pepper_bool_t
pepper_compositor_set_clock_id(pepper_compositor_t *compositor, clockid_t id);
PEPPER_API pepper_bool_t
-pepper_compositor_get_time(pepper_compositor_t *compositor, struct timespec *ts);
+pepper_compositor_get_time(pepper_compositor_t *compositor,
+ struct timespec *ts);
PEPPER_API void
pepper_output_destroy(pepper_output_t *output);
pepper_output_get_mode_count(pepper_output_t *output);
PEPPER_API void
-pepper_output_get_mode(pepper_output_t *output, int index, pepper_output_mode_t *mode);
+pepper_output_get_mode(pepper_output_t *output, int index,
+ pepper_output_mode_t *mode);
PEPPER_API const pepper_output_mode_t *
pepper_output_get_current_mode(pepper_output_t *output);
PEPPER_API pepper_bool_t
-pepper_output_set_mode(pepper_output_t *output, const pepper_output_mode_t *mode);
+pepper_output_set_mode(pepper_output_t *output,
+ const pepper_output_mode_t *mode);
PEPPER_API const char *
pepper_output_get_name(pepper_output_t *output);
PEPPER_API pepper_output_t *
-pepper_compositor_find_output(pepper_compositor_t *compositor, const char *name);
+pepper_compositor_find_output(pepper_compositor_t *compositor,
+ const char *name);
PEPPER_API pepper_seat_t *
-pepper_compositor_add_seat(pepper_compositor_t *compositor, const char *seat_name);
+pepper_compositor_add_seat(pepper_compositor_t *compositor,
+ const char *seat_name);
PEPPER_API void
pepper_seat_destroy(pepper_seat_t *seat);
pepper_seat_get_touch(pepper_seat_t *seat);
PEPPER_API void
-pepper_seat_add_input_device(pepper_seat_t *seat, pepper_input_device_t *device);
+pepper_seat_add_input_device(pepper_seat_t *seat,
+ pepper_input_device_t *device);
PEPPER_API void
-pepper_seat_remove_input_device(pepper_seat_t *seat, pepper_input_device_t *device);
+pepper_seat_remove_input_device(pepper_seat_t *seat,
+ pepper_input_device_t *device);
PEPPER_API const char *
-pepper_input_device_get_property(pepper_input_device_t *device, const char *key);
+pepper_input_device_get_property(pepper_input_device_t *device,
+ const char *key);
PEPPER_API pepper_compositor_t *
pepper_input_device_get_compositor(pepper_input_device_t *device);
-struct pepper_pointer_grab
-{
- /**
- * Handler for pointer motion event
- *
- * @param pointer pointer object
- * @param data data registered for the grab (@see pepper_pointer_set_grab)
- * @param time time in mili-second with undefined base
- * @param x movement in x direction on global space
- * @param x movement in y direction on global space
- **/
- void (*motion)(pepper_pointer_t *pointer, void *data, uint32_t time, double x, double y);
-
- /**
- * Handler for pointer button event
- *
- * @param pointer pointer object
- * @param data data registered for the grab (@see pepper_pointer_set_grab)
- * @param time time in mili-second with undefined base
- * @param button button id
- * @param state button state (@see pepper_button_state)
- **/
- void (*button)(pepper_pointer_t *pointer, void *data, uint32_t time, uint32_t button,
- uint32_t state);
-
- /**
- * Handler for pointer axis event
- *
- * @param pointer pointer object
- * @param data data registered for the grab (@see pepper_pointer_set_grab)
- * @param time time in mili-second with undefined base
- * @param axis axis id
- * @param value amount of axis movement
- **/
- void (*axis)(pepper_pointer_t *pointer, void *data, uint32_t time, uint32_t axis, double value);
-
- /**
- * Handler for the grab cancel
- *
- * @param pointer pointer object
- * @param data data registered for the grab (@see pepper_pointer_set_grab)
- *
- * Notifying that the grab is canceled and removed. Place to release resources or clean up grab
- * states.
- **/
- void (*cancel)(pepper_pointer_t *pointer, void *data);
+struct pepper_pointer_grab {
+ /**
+ * Handler for pointer motion event
+ *
+ * @param pointer pointer object
+ * @param data data registered for the grab (@see pepper_pointer_set_grab)
+ * @param time time in mili-second with undefined base
+ * @param x movement in x direction on global space
+ * @param x movement in y direction on global space
+ **/
+ void (*motion)(pepper_pointer_t *pointer, void *data, uint32_t time, double x,
+ double y);
+
+ /**
+ * Handler for pointer button event
+ *
+ * @param pointer pointer object
+ * @param data data registered for the grab (@see pepper_pointer_set_grab)
+ * @param time time in mili-second with undefined base
+ * @param button button id
+ * @param state button state (@see pepper_button_state)
+ **/
+ void (*button)(pepper_pointer_t *pointer, void *data, uint32_t time,
+ uint32_t button,
+ uint32_t state);
+
+ /**
+ * Handler for pointer axis event
+ *
+ * @param pointer pointer object
+ * @param data data registered for the grab (@see pepper_pointer_set_grab)
+ * @param time time in mili-second with undefined base
+ * @param axis axis id
+ * @param value amount of axis movement
+ **/
+ void (*axis)(pepper_pointer_t *pointer, void *data, uint32_t time,
+ uint32_t axis, double value);
+
+ /**
+ * Handler for the grab cancel
+ *
+ * @param pointer pointer object
+ * @param data data registered for the grab (@see pepper_pointer_set_grab)
+ *
+ * Notifying that the grab is canceled and removed. Place to release resources or clean up grab
+ * states.
+ **/
+ void (*cancel)(pepper_pointer_t *pointer, void *data);
};
PEPPER_API struct wl_list *
pepper_pointer_get_seat(pepper_pointer_t *pointer);
PEPPER_API pepper_bool_t
-pepper_pointer_set_clamp(pepper_pointer_t *pointer, double x0, double y0, double x1, double y1);
+pepper_pointer_set_clamp(pepper_pointer_t *pointer, double x0, double y0,
+ double x1, double y1);
PEPPER_API void
-pepper_pointer_get_clamp(pepper_pointer_t *pointer, double *x0, double *y0, double *x1, double *y1);
+pepper_pointer_get_clamp(pepper_pointer_t *pointer, double *x0, double *y0,
+ double *x1, double *y1);
PEPPER_API void
pepper_pointer_set_velocity(pepper_pointer_t *pointer, double vx, double vy);
pepper_pointer_send_leave(pepper_pointer_t *pointer, pepper_view_t *view);
PEPPER_API void
-pepper_pointer_send_enter(pepper_pointer_t *pointer, pepper_view_t *view, double x, double y);
+pepper_pointer_send_enter(pepper_pointer_t *pointer, pepper_view_t *view,
+ double x, double y);
PEPPER_API void
pepper_pointer_send_motion(pepper_pointer_t *pointer, pepper_view_t *view,
- uint32_t time, double x, double y);
+ uint32_t time, double x, double y);
PEPPER_API void
pepper_pointer_send_button(pepper_pointer_t *pointer, pepper_view_t *view,
- uint32_t time, uint32_t button, uint32_t state);
+ uint32_t time, uint32_t button, uint32_t state);
PEPPER_API void
pepper_pointer_send_axis(pepper_pointer_t *pointer, pepper_view_t *view,
- uint32_t time, uint32_t axis, double value);
+ uint32_t time, uint32_t axis, double value);
PEPPER_API void
-pepper_pointer_set_grab(pepper_pointer_t *pointer, const pepper_pointer_grab_t *grab, void *data);
+pepper_pointer_set_grab(pepper_pointer_t *pointer,
+ const pepper_pointer_grab_t *grab, void *data);
PEPPER_API const pepper_pointer_grab_t *
pepper_pointer_get_grab(pepper_pointer_t *pointer);
pepper_pointer_set_hotspot(pepper_pointer_t *pointer, int32_t x, int32_t y);
/* Keyboard. */
-struct pepper_keyboard_grab
-{
- /**
- * Handler for keyboard key event
- *
- * @param keyboard keyboard object
- * @param data data registered for the grab (@see pepper_keyboard_set_grab)
- * @param time time in mili-second with undefined base
- * @param key key code
- * @param state state flag (ex. WL_KEYBOARD_KEY_STATE_PRESSED)
- **/
- void (*key)(pepper_keyboard_t *keyboard, void *data, uint32_t time, uint32_t key,
- uint32_t state);
-
- /**
- * Handler for keyboard modifier event
- *
- * @param keyboard keyboard object
- * @param data data registered for the grab (@see pepper_keyboard_set_grab)
- * @param mods_depressed depressed mods
- * @param mods_latched latched mods
- * @param mods_locked locked mods
- * @param group (none)
- **/
- void (*modifiers)(pepper_keyboard_t *keyboard, void *data, uint32_t mods_depressed,
- uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
-
- /**
- * Handler for grab cancel
- *
- * @param keyboard keyboard object
- * @param data data registered for the grab (@see pepper_keyboard_set_grab)
- **/
- void (*cancel)(pepper_keyboard_t *keyboard, void *data);
+struct pepper_keyboard_grab {
+ /**
+ * Handler for keyboard key event
+ *
+ * @param keyboard keyboard object
+ * @param data data registered for the grab (@see pepper_keyboard_set_grab)
+ * @param time time in mili-second with undefined base
+ * @param key key code
+ * @param state state flag (ex. WL_KEYBOARD_KEY_STATE_PRESSED)
+ **/
+ void (*key)(pepper_keyboard_t *keyboard, void *data, uint32_t time,
+ uint32_t key,
+ uint32_t state);
+
+ /**
+ * Handler for keyboard modifier event
+ *
+ * @param keyboard keyboard object
+ * @param data data registered for the grab (@see pepper_keyboard_set_grab)
+ * @param mods_depressed depressed mods
+ * @param mods_latched latched mods
+ * @param mods_locked locked mods
+ * @param group (none)
+ **/
+ void (*modifiers)(pepper_keyboard_t *keyboard, void *data,
+ uint32_t mods_depressed,
+ uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
+
+ /**
+ * Handler for grab cancel
+ *
+ * @param keyboard keyboard object
+ * @param data data registered for the grab (@see pepper_keyboard_set_grab)
+ **/
+ void (*cancel)(pepper_keyboard_t *keyboard, void *data);
};
PEPPER_API struct wl_list *
PEPPER_API void
pepper_keyboard_send_key(pepper_keyboard_t *keyboard, pepper_view_t *view,
- uint32_t time, uint32_t key, uint32_t state);
+ uint32_t time, uint32_t key, uint32_t state);
PEPPER_API void
pepper_keyboard_send_modifiers(pepper_keyboard_t *keyboard, pepper_view_t *view,
- uint32_t depressed, uint32_t latched,
- uint32_t locked, uint32_t group);
+ uint32_t depressed, uint32_t latched,
+ uint32_t locked, uint32_t group);
PEPPER_API void
-pepper_keyboard_set_grab(pepper_keyboard_t *keyboard, const pepper_keyboard_grab_t *grab, void *data);
+pepper_keyboard_set_grab(pepper_keyboard_t *keyboard,
+ const pepper_keyboard_grab_t *grab, void *data);
PEPPER_API const pepper_keyboard_grab_t *
pepper_keyboard_get_grab(pepper_keyboard_t *keyboard);
pepper_keyboard_get_grab_data(pepper_keyboard_t *keyboard);
PEPPER_API void
-pepper_keyboard_set_keymap(pepper_keyboard_t *keyboard, struct xkb_keymap *keymap);
+pepper_keyboard_set_keymap(pepper_keyboard_t *keyboard,
+ struct xkb_keymap *keymap);
/* Touch. */
-struct pepper_touch_grab
-{
- void (*down)(pepper_touch_t *touch, void *data, uint32_t time, int32_t id, double x, double y);
- void (*up)(pepper_touch_t *touch, void *data, uint32_t time, uint32_t id);
- void (*motion)(pepper_touch_t *touch, void *data,
- uint32_t time, uint32_t id, double x, double y);
- void (*frame)(pepper_touch_t *touch, void *data);
- void (*cancel)(pepper_touch_t *touch, void *data);
+struct pepper_touch_grab {
+ void (*down)(pepper_touch_t *touch, void *data, uint32_t time, int32_t id,
+ double x, double y);
+ void (*up)(pepper_touch_t *touch, void *data, uint32_t time, uint32_t id);
+ void (*motion)(pepper_touch_t *touch, void *data,
+ uint32_t time, uint32_t id, double x, double y);
+ void (*frame)(pepper_touch_t *touch, void *data);
+ void (*cancel)(pepper_touch_t *touch, void *data);
};
PEPPER_API struct wl_list *
pepper_touch_remove_point(pepper_touch_t *touch, uint32_t id);
PEPPER_API void
-pepper_touch_set_focus(pepper_touch_t *touch, uint32_t id, pepper_view_t *focus);
+pepper_touch_set_focus(pepper_touch_t *touch, uint32_t id,
+ pepper_view_t *focus);
PEPPER_API pepper_view_t *
pepper_touch_get_focus(pepper_touch_t *touch, uint32_t id);
PEPPER_API pepper_bool_t
-pepper_touch_get_position(pepper_touch_t *touch, uint32_t id, double *x, double *y);
+pepper_touch_get_position(pepper_touch_t *touch, uint32_t id, double *x,
+ double *y);
PEPPER_API pepper_bool_t
-pepper_touch_set_position(pepper_touch_t *touch, uint32_t id, double x, double y);
+pepper_touch_set_position(pepper_touch_t *touch, uint32_t id, double x,
+ double y);
PEPPER_API void
pepper_touch_send_down(pepper_touch_t *touch, pepper_view_t *view,
- uint32_t time, uint32_t id, double x, double y);
+ uint32_t time, uint32_t id, double x, double y);
PEPPER_API void
-pepper_touch_send_up(pepper_touch_t *touch, pepper_view_t *view, uint32_t time, uint32_t id);
+pepper_touch_send_up(pepper_touch_t *touch, pepper_view_t *view, uint32_t time,
+ uint32_t id);
PEPPER_API void
pepper_touch_send_motion(pepper_touch_t *touch, pepper_view_t *view,
- uint32_t time, uint32_t id, double x, double y);
+ uint32_t time, uint32_t id, double x, double y);
PEPPER_API void
pepper_touch_send_frame(pepper_touch_t *touch, pepper_view_t *view);
pepper_touch_send_cancel(pepper_touch_t *touch, pepper_view_t *view);
PEPPER_API void
-pepper_touch_set_grab(pepper_touch_t *touch, const pepper_touch_grab_t *grab, void *data);
+pepper_touch_set_grab(pepper_touch_t *touch, const pepper_touch_grab_t *grab,
+ void *data);
PEPPER_API const pepper_touch_grab_t *
pepper_touch_get_grab(pepper_touch_t *touch);
pepper_surface_get_buffer(pepper_surface_t *surface);
PEPPER_API void
-pepper_surface_get_buffer_offset(pepper_surface_t *surface, int32_t *x, int32_t *y);
+pepper_surface_get_buffer_offset(pepper_surface_t *surface, int32_t *x,
+ int32_t *y);
PEPPER_API int32_t
pepper_surface_get_buffer_scale(pepper_surface_t *surface);
pepper_view_get_transform_inherit(pepper_view_t *view);
PEPPER_API pepper_bool_t
-pepper_view_stack_above(pepper_view_t *view, pepper_view_t *below, pepper_bool_t subtree);
+pepper_view_stack_above(pepper_view_t *view, pepper_view_t *below,
+ pepper_bool_t subtree);
PEPPER_API pepper_bool_t
-pepper_view_stack_below(pepper_view_t *view, pepper_view_t *above, pepper_bool_t subtree);
+pepper_view_stack_below(pepper_view_t *view, pepper_view_t *above,
+ pepper_bool_t subtree);
PEPPER_API void
pepper_view_stack_top(pepper_view_t *view, pepper_bool_t subtree);
pepper_view_is_opaque(pepper_view_t *view);
PEPPER_API void
-pepper_view_get_local_coordinate(pepper_view_t *view, double gx, double gy, double *lx, double *ly);
+pepper_view_get_local_coordinate(pepper_view_t *view, double gx, double gy,
+ double *lx, double *ly);
PEPPER_API void
-pepper_view_get_global_coordinate(pepper_view_t *view, double lx, double ly, double *gx, double *gy);
+pepper_view_get_global_coordinate(pepper_view_t *view, double lx, double ly,
+ double *gx, double *gy);
/* Misc */
PEPPER_API void
-pepper_pixman_region_global_to_output(pixman_region32_t *region, pepper_output_t *output);
+pepper_pixman_region_global_to_output(pixman_region32_t *region,
+ pepper_output_t *output);
PEPPER_API void
pepper_coordinates_surface_to_buffer(pepper_surface_t *surface,
- double sx, double sy, double *bx, double *by);
+ double sx, double sy, double *bx, double *by);
#ifdef __cplusplus
}
#include "pepper-internal.h"
void
-pepper_plane_update(pepper_plane_t *plane, const pepper_list_t *view_list, pixman_region32_t *clip)
+pepper_plane_update(pepper_plane_t *plane, const pepper_list_t *view_list,
+ pixman_region32_t *clip)
{
- int x = plane->output->geometry.x;
- int y = plane->output->geometry.y;
- int w = plane->output->geometry.w;
- int h = plane->output->geometry.h;
- pixman_region32_t plane_clip;
- pepper_view_t *view;
-
- pixman_region32_init(&plane_clip);
- pepper_list_init(&plane->entry_list);
-
- pepper_list_for_each(view, view_list, link)
- {
- pepper_plane_entry_t *entry = &view->plane_entries[plane->output->id];
-
- if (entry->plane == plane)
- {
- pepper_list_insert(plane->entry_list.prev, &entry->link);
-
- if (entry->need_transform_update)
- {
- entry->base.transform = view->global_transform;
- pepper_transform_global_to_output(&entry->base.transform, plane->output);
- entry->need_transform_update = PEPPER_FALSE;
- pepper_mat4_inverse(&entry->base.inverse, &entry->base.transform);
- }
-
- /* Calculate visible region (output space). */
- pixman_region32_subtract(&entry->base.visible_region,
- &view->bounding_region, &plane_clip);
- pixman_region32_intersect_rect(&entry->base.visible_region,
- &entry->base.visible_region, x, y, w, h);
- pepper_pixman_region_global_to_output(&entry->base.visible_region, plane->output);
-
- /* Accumulate opaque region of this view (global space). */
- pixman_region32_union(&plane_clip, &plane_clip, &view->opaque_region);
-
- /* Add damage for the new visible region. */
- if (entry->need_damage)
- {
- pepper_plane_add_damage_region(plane, &entry->base.visible_region);
- entry->need_damage = PEPPER_FALSE;
- }
-
- /* Flush surface damage. (eg. texture upload) */
- if (view->surface)
- pepper_surface_flush_damage(view->surface);
- }
- }
-
- /* Copy clip region of this plane. */
- pixman_region32_copy(&plane->clip_region, clip);
-
- /* Accumulate clip region obsecured by this plane. */
- pepper_pixman_region_global_to_output(&plane_clip, plane->output);
- pixman_region32_union(clip, clip, &plane_clip);
- pixman_region32_fini(&plane_clip);
+ int x = plane->output->geometry.x;
+ int y = plane->output->geometry.y;
+ int w = plane->output->geometry.w;
+ int h = plane->output->geometry.h;
+ pixman_region32_t plane_clip;
+ pepper_view_t *view;
+
+ pixman_region32_init(&plane_clip);
+ pepper_list_init(&plane->entry_list);
+
+ pepper_list_for_each(view, view_list, link) {
+ pepper_plane_entry_t *entry = &view->plane_entries[plane->output->id];
+
+ if (entry->plane == plane) {
+ pepper_list_insert(plane->entry_list.prev, &entry->link);
+
+ if (entry->need_transform_update) {
+ entry->base.transform = view->global_transform;
+ pepper_transform_global_to_output(&entry->base.transform, plane->output);
+ entry->need_transform_update = PEPPER_FALSE;
+ pepper_mat4_inverse(&entry->base.inverse, &entry->base.transform);
+ }
+
+ /* Calculate visible region (output space). */
+ pixman_region32_subtract(&entry->base.visible_region,
+ &view->bounding_region, &plane_clip);
+ pixman_region32_intersect_rect(&entry->base.visible_region,
+ &entry->base.visible_region, x, y, w, h);
+ pepper_pixman_region_global_to_output(&entry->base.visible_region,
+ plane->output);
+
+ /* Accumulate opaque region of this view (global space). */
+ pixman_region32_union(&plane_clip, &plane_clip, &view->opaque_region);
+
+ /* Add damage for the new visible region. */
+ if (entry->need_damage) {
+ pepper_plane_add_damage_region(plane, &entry->base.visible_region);
+ entry->need_damage = PEPPER_FALSE;
+ }
+
+ /* Flush surface damage. (eg. texture upload) */
+ if (view->surface)
+ pepper_surface_flush_damage(view->surface);
+ }
+ }
+
+ /* Copy clip region of this plane. */
+ pixman_region32_copy(&plane->clip_region, clip);
+
+ /* Accumulate clip region obsecured by this plane. */
+ pepper_pixman_region_global_to_output(&plane_clip, plane->output);
+ pixman_region32_union(clip, clip, &plane_clip);
+ pixman_region32_fini(&plane_clip);
}
/**
PEPPER_API pepper_plane_t *
pepper_output_add_plane(pepper_output_t *output, pepper_plane_t *above)
{
- pepper_plane_t *plane;
+ pepper_plane_t *plane;
- PEPPER_CHECK(!above || above->output == output, return NULL, "Output mismatch.\n");
+ PEPPER_CHECK(!above ||
+ above->output == output, return NULL, "Output mismatch.\n");
- plane = (pepper_plane_t *)pepper_object_alloc(PEPPER_OBJECT_PLANE, sizeof(pepper_plane_t));
- PEPPER_CHECK(plane, return NULL, "pepper_object_alloc() failed.\n");
+ plane = (pepper_plane_t *)pepper_object_alloc(PEPPER_OBJECT_PLANE,
+ sizeof(pepper_plane_t));
+ PEPPER_CHECK(plane, return NULL, "pepper_object_alloc() failed.\n");
- plane->output = output;
- plane->link.item = plane;
+ plane->output = output;
+ plane->link.item = plane;
- if (above)
- pepper_list_insert(above->link.prev, &plane->link);
- else
- pepper_list_insert(output->plane_list.prev, &plane->link);
+ if (above)
+ pepper_list_insert(above->link.prev, &plane->link);
+ else
+ pepper_list_insert(output->plane_list.prev, &plane->link);
- pepper_list_init(&plane->entry_list);
- pixman_region32_init(&plane->damage_region);
- pixman_region32_init(&plane->clip_region);
+ pepper_list_init(&plane->entry_list);
+ pixman_region32_init(&plane->damage_region);
+ pixman_region32_init(&plane->clip_region);
- return plane;
+ return plane;
}
/**
PEPPER_API void
pepper_plane_destroy(pepper_plane_t *plane)
{
- pepper_plane_entry_t *entry;
+ pepper_plane_entry_t *entry;
- pepper_object_fini(&plane->base);
+ pepper_object_fini(&plane->base);
- pepper_list_for_each(entry, &plane->entry_list, link)
- pepper_view_assign_plane(entry->base.view, plane->output, NULL);
+ pepper_list_for_each(entry, &plane->entry_list, link)
+ pepper_view_assign_plane(entry->base.view, plane->output, NULL);
- pepper_list_remove(&plane->link);
- pixman_region32_fini(&plane->damage_region);
- pixman_region32_fini(&plane->clip_region);
+ pepper_list_remove(&plane->link);
+ pixman_region32_fini(&plane->damage_region);
+ pixman_region32_fini(&plane->clip_region);
- free(plane);
+ free(plane);
}
void
pepper_plane_add_damage_region(pepper_plane_t *plane, pixman_region32_t *damage)
{
- if (!damage)
- {
- pixman_region32_union_rect(&plane->damage_region, &plane->damage_region,
- 0, 0, plane->output->geometry.w, plane->output->geometry.h);
- pepper_output_schedule_repaint(plane->output);
- }
- else if (pixman_region32_not_empty(damage))
- {
- pixman_region32_union(&plane->damage_region, &plane->damage_region, damage);
- pepper_output_schedule_repaint(plane->output);
- }
+ if (!damage) {
+ pixman_region32_union_rect(&plane->damage_region, &plane->damage_region,
+ 0, 0, plane->output->geometry.w, plane->output->geometry.h);
+ pepper_output_schedule_repaint(plane->output);
+ } else if (pixman_region32_not_empty(damage)) {
+ pixman_region32_union(&plane->damage_region, &plane->damage_region, damage);
+ pepper_output_schedule_repaint(plane->output);
+ }
}
/**
PEPPER_API pixman_region32_t *
pepper_plane_get_damage_region(pepper_plane_t *plane)
{
- return &plane->damage_region;
+ return &plane->damage_region;
}
/**
PEPPER_API pixman_region32_t *
pepper_plane_get_clip_region(pepper_plane_t *plane)
{
- return &plane->clip_region;
+ return &plane->clip_region;
}
/**
PEPPER_API const pepper_list_t *
pepper_plane_get_render_list(pepper_plane_t *plane)
{
- return &plane->entry_list;
+ return &plane->entry_list;
}
/**
* @param damage region to subtract
*/
PEPPER_API void
-pepper_plane_subtract_damage_region(pepper_plane_t *plane, pixman_region32_t *damage)
+pepper_plane_subtract_damage_region(pepper_plane_t *plane,
+ pixman_region32_t *damage)
{
- pixman_region32_subtract(&plane->damage_region, &plane->damage_region, damage);
+ pixman_region32_subtract(&plane->damage_region, &plane->damage_region, damage);
}
/**
PEPPER_API void
pepper_plane_clear_damage_region(pepper_plane_t *plane)
{
- pixman_region32_clear(&plane->damage_region);
+ pixman_region32_clear(&plane->damage_region);
}
static pepper_view_t *
get_cursor_view(pepper_pointer_t *pointer)
{
- if (pointer->cursor_view)
- return pointer->cursor_view;
+ if (pointer->cursor_view)
+ return pointer->cursor_view;
- pointer->cursor_view = pepper_compositor_add_view(pointer->seat->compositor);
+ pointer->cursor_view = pepper_compositor_add_view(pointer->seat->compositor);
- return pointer->cursor_view;
+ return pointer->cursor_view;
}
static void
-pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, uint32_t serial,
- struct wl_resource *surface_resource, int32_t x, int32_t y)
-{
- pepper_pointer_t *pointer = (pepper_pointer_t *)wl_resource_get_user_data(resource);
- pepper_surface_t *surface;
- pepper_view_t *cursor_view;
-
- cursor_view = get_cursor_view(pointer);
- PEPPER_CHECK(cursor_view, return, "failed to get cursor view\n");
-
- if (!surface_resource)
- {
- pepper_view_set_surface(cursor_view, NULL);
- return;
- }
-
- surface = (pepper_surface_t *)wl_resource_get_user_data(surface_resource);
- if (!surface->role)
- pepper_surface_set_role(surface, "wl_pointer-cursor");
- else if (strcmp("wl_pointer-cursor", surface->role))
- return;
-
- if (surface != pepper_view_get_surface(cursor_view))
- {
- surface->pickable = PEPPER_FALSE;
- pixman_region32_fini(&surface->input_region);
- pixman_region32_init(&surface->input_region);
- pepper_view_set_surface(cursor_view, surface);
- }
-
- pointer->hotspot_x = x;
- pointer->hotspot_y = y;
- pepper_view_set_position(cursor_view, pointer->x - x, pointer->y - y);
- pepper_view_map(cursor_view);
+pointer_set_cursor(struct wl_client *client, struct wl_resource *resource,
+ uint32_t serial,
+ struct wl_resource *surface_resource, int32_t x, int32_t y)
+{
+ pepper_pointer_t *pointer = (pepper_pointer_t *)wl_resource_get_user_data(
+ resource);
+ pepper_surface_t *surface;
+ pepper_view_t *cursor_view;
+
+ cursor_view = get_cursor_view(pointer);
+ PEPPER_CHECK(cursor_view, return, "failed to get cursor view\n");
+
+ if (!surface_resource) {
+ pepper_view_set_surface(cursor_view, NULL);
+ return;
+ }
+
+ surface = (pepper_surface_t *)wl_resource_get_user_data(surface_resource);
+ if (!surface->role)
+ pepper_surface_set_role(surface, "wl_pointer-cursor");
+ else if (strcmp("wl_pointer-cursor", surface->role))
+ return;
+
+ if (surface != pepper_view_get_surface(cursor_view)) {
+ surface->pickable = PEPPER_FALSE;
+ pixman_region32_fini(&surface->input_region);
+ pixman_region32_init(&surface->input_region);
+ pepper_view_set_surface(cursor_view, surface);
+ }
+
+ pointer->hotspot_x = x;
+ pointer->hotspot_y = y;
+ pepper_view_set_position(cursor_view, pointer->x - x, pointer->y - y);
+ pepper_view_map(cursor_view);
}
static void
pointer_release(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
-static const struct wl_pointer_interface pointer_impl =
-{
- pointer_set_cursor,
- pointer_release,
+static const struct wl_pointer_interface pointer_impl = {
+ pointer_set_cursor,
+ pointer_release,
};
static pepper_bool_t
pointer_clamp(pepper_pointer_t *pointer)
{
- pepper_bool_t clamped = PEPPER_FALSE;
-
- if (pointer->x < pointer->clamp.x0)
- {
- pointer->x = pointer->clamp.x0;
- clamped = PEPPER_TRUE;
- }
-
- if (pointer->x > pointer->clamp.x1)
- {
- pointer->x = pointer->clamp.x1;
- clamped = PEPPER_TRUE;
- }
-
- if (pointer->y < pointer->clamp.y0)
- {
- pointer->y = pointer->clamp.y0;
- clamped = PEPPER_TRUE;
- }
-
- if (pointer->y > pointer->clamp.y1)
- {
- pointer->y = pointer->clamp.y1;
- clamped = PEPPER_TRUE;
- }
-
- return clamped;
+ pepper_bool_t clamped = PEPPER_FALSE;
+
+ if (pointer->x < pointer->clamp.x0) {
+ pointer->x = pointer->clamp.x0;
+ clamped = PEPPER_TRUE;
+ }
+
+ if (pointer->x > pointer->clamp.x1) {
+ pointer->x = pointer->clamp.x1;
+ clamped = PEPPER_TRUE;
+ }
+
+ if (pointer->y < pointer->clamp.y0) {
+ pointer->y = pointer->clamp.y0;
+ clamped = PEPPER_TRUE;
+ }
+
+ if (pointer->y > pointer->clamp.y1) {
+ pointer->y = pointer->clamp.y1;
+ clamped = PEPPER_TRUE;
+ }
+
+ return clamped;
}
static void
-pointer_set_position(pepper_pointer_t *pointer, uint32_t time, double x, double y)
+pointer_set_position(pepper_pointer_t *pointer, uint32_t time, double x,
+ double y)
{
- pepper_input_event_t event;
+ pepper_input_event_t event;
- if (x == pointer->x && y == pointer->y)
- return;
+ if (x == pointer->x && y == pointer->y)
+ return;
- pointer->x = x;
- pointer->y = y;
+ pointer->x = x;
+ pointer->y = y;
- pointer_clamp(pointer);
+ pointer_clamp(pointer);
- if (pointer->cursor_view)
- pepper_view_set_position(pointer->cursor_view,
- x - pointer->hotspot_x, y - pointer->hotspot_y);
+ if (pointer->cursor_view)
+ pepper_view_set_position(pointer->cursor_view,
+ x - pointer->hotspot_x, y - pointer->hotspot_y);
- if (pointer->grab)
- pointer->grab->motion(pointer, pointer->data, time, pointer->x, pointer->y);
+ if (pointer->grab)
+ pointer->grab->motion(pointer, pointer->data, time, pointer->x, pointer->y);
- /* Emit motion event. */
- memset(&event, 0x00, sizeof(pepper_input_event_t));
+ /* Emit motion event. */
+ memset(&event, 0x00, sizeof(pepper_input_event_t));
- event.time = time;
- event.x = pointer->x;
- event.y = pointer->y;
- pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_MOTION, &event);
+ event.time = time;
+ event.x = pointer->x;
+ event.y = pointer->y;
+ pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_MOTION, &event);
}
void
-pepper_pointer_handle_event(pepper_pointer_t *pointer, uint32_t id, pepper_input_event_t *event)
-{
- pointer->time = event->time;
-
- switch (id)
- {
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE:
- {
- pointer_set_position(pointer, event->time, event->x, event->y);
- }
- break;
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION:
- {
- pointer_set_position(pointer, event->time,
- pointer->x + event->x * pointer->x_velocity,
- pointer->y + event->y * pointer->y_velocity);
- }
- break;
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON:
- {
- if (pointer->grab)
- {
- pointer->grab->button(pointer, pointer->data,
- event->time, event->button, event->state);
- }
-
- pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_BUTTON, event);
- }
- break;
- case PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS:
- {
- if (pointer->grab)
- pointer->grab->axis(pointer, pointer->data, event->time, event->axis, event->value);
-
- pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_AXIS, event);
- }
- break;
- }
+pepper_pointer_handle_event(pepper_pointer_t *pointer, uint32_t id,
+ pepper_input_event_t *event)
+{
+ pointer->time = event->time;
+
+ switch (id) {
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE: {
+ pointer_set_position(pointer, event->time, event->x, event->y);
+ }
+ break;
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION: {
+ pointer_set_position(pointer, event->time,
+ pointer->x + event->x * pointer->x_velocity,
+ pointer->y + event->y * pointer->y_velocity);
+ }
+ break;
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON: {
+ if (pointer->grab) {
+ pointer->grab->button(pointer, pointer->data,
+ event->time, event->button, event->state);
+ }
+
+ pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_BUTTON, event);
+ }
+ break;
+ case PEPPER_EVENT_INPUT_DEVICE_POINTER_AXIS: {
+ if (pointer->grab)
+ pointer->grab->axis(pointer, pointer->data, event->time, event->axis,
+ event->value);
+
+ pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_AXIS, event);
+ }
+ break;
+ }
}
static void
-pointer_handle_focus_destroy(pepper_event_listener_t *listener, pepper_object_t *surface,
- uint32_t id, void *info, void *data)
+pointer_handle_focus_destroy(pepper_event_listener_t *listener,
+ pepper_object_t *surface,
+ uint32_t id, void *info, void *data)
{
- pepper_pointer_t *pointer = data;
- pepper_pointer_set_focus(pointer, NULL);
+ pepper_pointer_t *pointer = data;
+ pepper_pointer_set_focus(pointer, NULL);
- if (pointer->grab)
- pointer->grab->cancel(pointer, pointer->data);
+ if (pointer->grab)
+ pointer->grab->cancel(pointer, pointer->data);
}
pepper_pointer_t *
pepper_pointer_create(pepper_seat_t *seat)
{
- pepper_pointer_t *pointer =
- (pepper_pointer_t *)pepper_object_alloc(PEPPER_OBJECT_POINTER, sizeof(pepper_pointer_t));
+ pepper_pointer_t *pointer =
+ (pepper_pointer_t *)pepper_object_alloc(PEPPER_OBJECT_POINTER,
+ sizeof(pepper_pointer_t));
- PEPPER_CHECK(pointer, return NULL, "pepper_object_alloc() failed.\n");
+ PEPPER_CHECK(pointer, return NULL, "pepper_object_alloc() failed.\n");
- pointer->seat = seat;
- wl_list_init(&pointer->resource_list);
+ pointer->seat = seat;
+ wl_list_init(&pointer->resource_list);
- pointer->clamp.x0 = -DBL_MAX;
- pointer->clamp.y0 = -DBL_MAX;
- pointer->clamp.x1 = DBL_MAX;
- pointer->clamp.y1 = DBL_MAX;
+ pointer->clamp.x0 = -DBL_MAX;
+ pointer->clamp.y0 = -DBL_MAX;
+ pointer->clamp.x1 = DBL_MAX;
+ pointer->clamp.y1 = DBL_MAX;
- pointer->x_velocity = 1.0;
- pointer->y_velocity = 1.0;
+ pointer->x_velocity = 1.0;
+ pointer->y_velocity = 1.0;
- return pointer;
+ return pointer;
}
void
pepper_pointer_destroy(pepper_pointer_t *pointer)
{
- if (pointer->grab)
- pointer->grab->cancel(pointer, pointer->data);
+ if (pointer->grab)
+ pointer->grab->cancel(pointer, pointer->data);
- if (pointer->focus)
- pepper_event_listener_remove(pointer->focus_destroy_listener);
+ if (pointer->focus)
+ pepper_event_listener_remove(pointer->focus_destroy_listener);
- free(pointer);
+ free(pointer);
}
static void
unbind_resource(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
void
-pepper_pointer_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id)
-{
- pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
- pepper_pointer_t *pointer = seat->pointer;
- struct wl_resource *res;
-
- if (!pointer)
- return;
-
- res = wl_resource_create(client, &wl_pointer_interface, wl_resource_get_version(resource), id);
- if (!res)
- {
- wl_client_post_no_memory(client);
- return;
- }
-
- wl_list_insert(&pointer->resource_list, wl_resource_get_link(res));
- wl_resource_set_implementation(res, &pointer_impl, pointer, unbind_resource);
-
- if (!pointer->focus || !pointer->focus->surface || !pointer->focus->surface->resource)
- return;
-
- if (wl_resource_get_client(pointer->focus->surface->resource) == client)
- {
- wl_pointer_send_enter(res, pointer->focus_serial,
- pointer->focus->surface->resource,
- wl_fixed_from_double(pointer->vx), wl_fixed_from_double(pointer->vy));
- }
+pepper_pointer_bind_resource(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id)
+{
+ pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
+ pepper_pointer_t *pointer = seat->pointer;
+ struct wl_resource *res;
+
+ if (!pointer)
+ return;
+
+ res = wl_resource_create(client, &wl_pointer_interface,
+ wl_resource_get_version(resource), id);
+ if (!res) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_list_insert(&pointer->resource_list, wl_resource_get_link(res));
+ wl_resource_set_implementation(res, &pointer_impl, pointer, unbind_resource);
+
+ if (!pointer->focus || !pointer->focus->surface ||
+ !pointer->focus->surface->resource)
+ return;
+
+ if (wl_resource_get_client(pointer->focus->surface->resource) == client) {
+ wl_pointer_send_enter(res, pointer->focus_serial,
+ pointer->focus->surface->resource,
+ wl_fixed_from_double(pointer->vx), wl_fixed_from_double(pointer->vy));
+ }
}
/**
PEPPER_API struct wl_list *
pepper_pointer_get_resource_list(pepper_pointer_t *pointer)
{
- return &pointer->resource_list;
+ return &pointer->resource_list;
}
/**
PEPPER_API pepper_compositor_t *
pepper_pointer_get_compositor(pepper_pointer_t *pointer)
{
- return pointer->seat->compositor;
+ return pointer->seat->compositor;
}
/**
PEPPER_API pepper_seat_t *
pepper_pointer_get_seat(pepper_pointer_t *pointer)
{
- return pointer->seat;
+ return pointer->seat;
}
/**
* resulting motion events.
*/
PEPPER_API pepper_bool_t
-pepper_pointer_set_clamp(pepper_pointer_t *pointer, double x0, double y0, double x1, double y1)
+pepper_pointer_set_clamp(pepper_pointer_t *pointer, double x0, double y0,
+ double x1, double y1)
{
- if (x1 < x0 || y1 < y0)
- return PEPPER_FALSE;
+ if (x1 < x0 || y1 < y0)
+ return PEPPER_FALSE;
- pointer->clamp.x0 = x0;
- pointer->clamp.y0 = y0;
- pointer->clamp.x1 = x1;
- pointer->clamp.y1 = y1;
+ pointer->clamp.x0 = x0;
+ pointer->clamp.y0 = y0;
+ pointer->clamp.x1 = x1;
+ pointer->clamp.y1 = y1;
- if (pointer_clamp(pointer))
- {
- pepper_input_event_t event;
+ if (pointer_clamp(pointer)) {
+ pepper_input_event_t event;
- if (pointer->grab)
- pointer->grab->motion(pointer, pointer->data, pointer->time, pointer->x, pointer->y);
+ if (pointer->grab)
+ pointer->grab->motion(pointer, pointer->data, pointer->time, pointer->x,
+ pointer->y);
- memset(&event, 0x00, sizeof(pepper_input_event_t));
+ memset(&event, 0x00, sizeof(pepper_input_event_t));
- event.time = pointer->time;
- event.x = pointer->x;
- event.y = pointer->y;
- pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_MOTION, &event);
- }
+ event.time = pointer->time;
+ event.x = pointer->x;
+ event.y = pointer->y;
+ pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_MOTION, &event);
+ }
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
/**
* @param y1 pointer to receive y coordinate of bottom right corner of the clamp area
*/
PEPPER_API void
-pepper_pointer_get_clamp(pepper_pointer_t *pointer, double *x0, double *y0, double *x1, double *y1)
+pepper_pointer_get_clamp(pepper_pointer_t *pointer, double *x0, double *y0,
+ double *x1, double *y1)
{
- if (x0)
- *x0 = pointer->clamp.x0;
+ if (x0)
+ *x0 = pointer->clamp.x0;
- if (y0)
- *y0 = pointer->clamp.y0;
+ if (y0)
+ *y0 = pointer->clamp.y0;
- if (x1)
- *x1 = pointer->clamp.x1;
+ if (x1)
+ *x1 = pointer->clamp.x1;
- if (y1)
- *y1 = pointer->clamp.y1;
+ if (y1)
+ *y1 = pointer->clamp.y1;
}
/**
PEPPER_API void
pepper_pointer_set_velocity(pepper_pointer_t *pointer, double vx, double vy)
{
- pointer->x_velocity = vx;
- pointer->y_velocity = vy;
+ pointer->x_velocity = vx;
+ pointer->y_velocity = vy;
}
/**
PEPPER_API void
pepper_pointer_get_velocity(pepper_pointer_t *pointer, double *vx, double *vy)
{
- if (vx)
- *vx = pointer->x_velocity;
+ if (vx)
+ *vx = pointer->x_velocity;
- if (vy)
- *vy = pointer->y_velocity;
+ if (vy)
+ *vy = pointer->y_velocity;
}
/**
PEPPER_API void
pepper_pointer_get_position(pepper_pointer_t *pointer, double *x, double *y)
{
- if (x)
- *x = pointer->x;
+ if (x)
+ *x = pointer->x;
- if (y)
- *y = pointer->y;
+ if (y)
+ *y = pointer->y;
}
/**
PEPPER_API void
pepper_pointer_set_focus(pepper_pointer_t *pointer, pepper_view_t *focus)
{
- if (pointer->focus == focus)
- return;
+ if (pointer->focus == focus)
+ return;
- if (pointer->focus)
- {
- pepper_event_listener_remove(pointer->focus_destroy_listener);
- pepper_object_emit_event(&pointer->base, PEPPER_EVENT_FOCUS_LEAVE, pointer->focus);
- pepper_object_emit_event(&pointer->focus->base, PEPPER_EVENT_FOCUS_LEAVE, pointer);
- }
+ if (pointer->focus) {
+ pepper_event_listener_remove(pointer->focus_destroy_listener);
+ pepper_object_emit_event(&pointer->base, PEPPER_EVENT_FOCUS_LEAVE,
+ pointer->focus);
+ pepper_object_emit_event(&pointer->focus->base, PEPPER_EVENT_FOCUS_LEAVE,
+ pointer);
+ }
- pointer->focus = focus;
+ pointer->focus = focus;
- if (focus)
- {
- pointer->focus_serial = wl_display_next_serial(pointer->seat->compositor->display);
+ if (focus) {
+ pointer->focus_serial = wl_display_next_serial(
+ pointer->seat->compositor->display);
- pointer->focus_destroy_listener =
- pepper_object_add_event_listener(&focus->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
- pointer_handle_focus_destroy, pointer);
+ pointer->focus_destroy_listener =
+ pepper_object_add_event_listener(&focus->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
+ pointer_handle_focus_destroy, pointer);
- pepper_object_emit_event(&pointer->base, PEPPER_EVENT_FOCUS_ENTER, focus);
- pepper_object_emit_event(&focus->base, PEPPER_EVENT_FOCUS_ENTER, pointer);
- }
+ pepper_object_emit_event(&pointer->base, PEPPER_EVENT_FOCUS_ENTER, focus);
+ pepper_object_emit_event(&focus->base, PEPPER_EVENT_FOCUS_ENTER, pointer);
+ }
}
/**
PEPPER_API pepper_view_t *
pepper_pointer_get_focus(pepper_pointer_t *pointer)
{
- return pointer->focus;
+ return pointer->focus;
}
/**
PEPPER_API void
pepper_pointer_send_leave(pepper_pointer_t *pointer, pepper_view_t *view)
{
- struct wl_resource *resource;
- struct wl_client *client;
- uint32_t serial;
+ struct wl_resource *resource;
+ struct wl_client *client;
+ uint32_t serial;
- if (!view || !view->surface || !view->surface->resource)
- return;
+ if (!view || !view->surface || !view->surface->resource)
+ return;
- client = wl_resource_get_client(view->surface->resource);
- serial = wl_display_next_serial(pointer->seat->compositor->display);
+ client = wl_resource_get_client(view->surface->resource);
+ serial = wl_display_next_serial(pointer->seat->compositor->display);
- wl_resource_for_each(resource, &pointer->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_pointer_send_leave(resource, serial, view->surface->resource);
- }
+ wl_resource_for_each(resource, &pointer->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_pointer_send_leave(resource, serial, view->surface->resource);
+ }
}
/**
* @param view view object having the target surface for the enter event
*/
PEPPER_API void
-pepper_pointer_send_enter(pepper_pointer_t *pointer, pepper_view_t *view, double x, double y)
+pepper_pointer_send_enter(pepper_pointer_t *pointer, pepper_view_t *view,
+ double x, double y)
{
- struct wl_resource *resource;
- wl_fixed_t fx = wl_fixed_from_double(x);
- wl_fixed_t fy = wl_fixed_from_double(y);
- struct wl_client *client;
- uint32_t serial;
-
- if (!view || !view->surface || !view->surface->resource)
- return;
-
- client = wl_resource_get_client(view->surface->resource);
- serial = wl_display_next_serial(pointer->seat->compositor->display);
-
- wl_resource_for_each(resource, &pointer->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_pointer_send_enter(resource, serial, view->surface->resource, fx, fy);
- }
+ struct wl_resource *resource;
+ wl_fixed_t fx = wl_fixed_from_double(x);
+ wl_fixed_t fy = wl_fixed_from_double(y);
+ struct wl_client *client;
+ uint32_t serial;
+
+ if (!view || !view->surface || !view->surface->resource)
+ return;
+
+ client = wl_resource_get_client(view->surface->resource);
+ serial = wl_display_next_serial(pointer->seat->compositor->display);
+
+ wl_resource_for_each(resource, &pointer->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_pointer_send_enter(resource, serial, view->surface->resource, fx, fy);
+ }
}
/**
*/
PEPPER_API void
pepper_pointer_send_motion(pepper_pointer_t *pointer, pepper_view_t *view,
- uint32_t time, double x, double y)
+ uint32_t time, double x, double y)
{
- struct wl_resource *resource;
- wl_fixed_t fx = wl_fixed_from_double(x);
- wl_fixed_t fy = wl_fixed_from_double(y);
- struct wl_client *client;
- pepper_input_event_t event;
-
- if (!view || !view->surface || !view->surface->resource)
- return;
-
- client = wl_resource_get_client(view->surface->resource);
-
- wl_resource_for_each(resource, &pointer->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_pointer_send_motion(resource, time, fx, fy);
- }
-
- event.time = time;
- event.x = x;
- event.y = y;
- pepper_object_emit_event(&view->base, PEPPER_EVENT_POINTER_MOTION, &event);
+ struct wl_resource *resource;
+ wl_fixed_t fx = wl_fixed_from_double(x);
+ wl_fixed_t fy = wl_fixed_from_double(y);
+ struct wl_client *client;
+ pepper_input_event_t event;
+
+ if (!view || !view->surface || !view->surface->resource)
+ return;
+
+ client = wl_resource_get_client(view->surface->resource);
+
+ wl_resource_for_each(resource, &pointer->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_pointer_send_motion(resource, time, fx, fy);
+ }
+
+ event.time = time;
+ event.x = x;
+ event.y = y;
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_POINTER_MOTION, &event);
}
/**
*/
PEPPER_API void
pepper_pointer_send_button(pepper_pointer_t *pointer, pepper_view_t *view,
- uint32_t time, uint32_t button, uint32_t state)
+ uint32_t time, uint32_t button, uint32_t state)
{
- struct wl_resource *resource;
- struct wl_client *client;
- uint32_t serial;
- pepper_input_event_t event;
-
- if (!view || !view->surface || !view->surface->resource)
- return;
-
- client = wl_resource_get_client(view->surface->resource);
- serial = wl_display_next_serial(pointer->seat->compositor->display);
-
- wl_resource_for_each(resource, &pointer->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_pointer_send_button(resource, serial, time, button, state);
- }
-
- event.time = time;
- event.button = button;
- event.state = state;
- pepper_object_emit_event(&view->base, PEPPER_EVENT_POINTER_BUTTON, &event);
+ struct wl_resource *resource;
+ struct wl_client *client;
+ uint32_t serial;
+ pepper_input_event_t event;
+
+ if (!view || !view->surface || !view->surface->resource)
+ return;
+
+ client = wl_resource_get_client(view->surface->resource);
+ serial = wl_display_next_serial(pointer->seat->compositor->display);
+
+ wl_resource_for_each(resource, &pointer->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_pointer_send_button(resource, serial, time, button, state);
+ }
+
+ event.time = time;
+ event.button = button;
+ event.state = state;
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_POINTER_BUTTON, &event);
}
/**
*/
PEPPER_API void
pepper_pointer_send_axis(pepper_pointer_t *pointer, pepper_view_t *view,
- uint32_t time, uint32_t axis, double value)
+ uint32_t time, uint32_t axis, double value)
{
- struct wl_resource *resource;
- wl_fixed_t v = wl_fixed_from_double(value);
- struct wl_client *client;
- pepper_input_event_t event;
-
- if (!view || !view->surface || !view->surface->resource)
- return;
-
- client = wl_resource_get_client(view->surface->resource);
-
- wl_resource_for_each(resource, &pointer->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_pointer_send_axis(resource, time, axis, v);
- }
-
- event.time = time;
- event.axis = axis;
- event.value = value;
- pepper_object_emit_event(&view->base, PEPPER_EVENT_POINTER_AXIS, &event);
+ struct wl_resource *resource;
+ wl_fixed_t v = wl_fixed_from_double(value);
+ struct wl_client *client;
+ pepper_input_event_t event;
+
+ if (!view || !view->surface || !view->surface->resource)
+ return;
+
+ client = wl_resource_get_client(view->surface->resource);
+
+ wl_resource_for_each(resource, &pointer->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_pointer_send_axis(resource, time, axis, v);
+ }
+
+ event.time = time;
+ event.axis = axis;
+ event.value = value;
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_POINTER_AXIS, &event);
}
/**
* @param data user data to be passed to grab functions
*/
PEPPER_API void
-pepper_pointer_set_grab(pepper_pointer_t *pointer, const pepper_pointer_grab_t *grab, void *data)
+pepper_pointer_set_grab(pepper_pointer_t *pointer,
+ const pepper_pointer_grab_t *grab, void *data)
{
- pointer->grab = grab;
- pointer->data = data;
+ pointer->grab = grab;
+ pointer->data = data;
}
/**
PEPPER_API const pepper_pointer_grab_t *
pepper_pointer_get_grab(pepper_pointer_t *pointer)
{
- return pointer->grab;
+ return pointer->grab;
}
/**
PEPPER_API void *
pepper_pointer_get_grab_data(pepper_pointer_t *pointer)
{
- return pointer->data;
+ return pointer->data;
}
PEPPER_API pepper_view_t *
pepper_pointer_get_cursor_view(pepper_pointer_t *pointer)
{
- return pointer->cursor_view;
+ return pointer->cursor_view;
}
PEPPER_API void
pepper_pointer_set_hotspot(pepper_pointer_t *pointer, int32_t x, int32_t y)
{
- pointer->hotspot_x = x;
- pointer->hotspot_y = y;
+ pointer->hotspot_x = x;
+ pointer->hotspot_y = y;
}
static void
region_resource_destroy_handler(struct wl_resource *resource)
{
- pepper_region_t *region = wl_resource_get_user_data(resource);
- pepper_region_destroy(region);
+ pepper_region_t *region = wl_resource_get_user_data(resource);
+ pepper_region_destroy(region);
}
static void
region_destroy(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
static void
region_add(struct wl_client *client, struct wl_resource *resource,
- int32_t x, int32_t y, int32_t w, int32_t h)
+ int32_t x, int32_t y, int32_t w, int32_t h)
{
- pepper_region_t *region = wl_resource_get_user_data(resource);
- pixman_region32_union_rect(®ion->pixman_region, ®ion->pixman_region,
- x, y, w, h);
+ pepper_region_t *region = wl_resource_get_user_data(resource);
+ pixman_region32_union_rect(®ion->pixman_region, ®ion->pixman_region,
+ x, y, w, h);
}
static void
region_subtract(struct wl_client *client, struct wl_resource *resource,
- int32_t x, int32_t y, int32_t w, int32_t h)
+ int32_t x, int32_t y, int32_t w, int32_t h)
{
- pepper_region_t *region = wl_resource_get_user_data(resource);
- pixman_region32_t rect;
+ pepper_region_t *region = wl_resource_get_user_data(resource);
+ pixman_region32_t rect;
- pixman_region32_init_rect(&rect, x, y, w, h);
- pixman_region32_subtract(®ion->pixman_region, ®ion->pixman_region, &rect);
- pixman_region32_fini(&rect);
+ pixman_region32_init_rect(&rect, x, y, w, h);
+ pixman_region32_subtract(®ion->pixman_region, ®ion->pixman_region, &rect);
+ pixman_region32_fini(&rect);
}
-static const struct wl_region_interface region_implementation =
-{
- region_destroy,
- region_add,
- region_subtract,
+static const struct wl_region_interface region_implementation = {
+ region_destroy,
+ region_add,
+ region_subtract,
};
pepper_region_t *
pepper_region_create(pepper_compositor_t *compositor,
- struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id)
+ struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id)
{
- pepper_region_t *region = calloc(1, sizeof(pepper_region_t));
- PEPPER_CHECK(region, return NULL, "calloc(0 failed.\n");
+ pepper_region_t *region = calloc(1, sizeof(pepper_region_t));
+ PEPPER_CHECK(region, return NULL, "calloc(0 failed.\n");
- region->resource = wl_resource_create(client, &wl_region_interface, 1, id);
- PEPPER_CHECK(region->resource, goto error, "wl_resource_create() failed\n");
+ region->resource = wl_resource_create(client, &wl_region_interface, 1, id);
+ PEPPER_CHECK(region->resource, goto error, "wl_resource_create() failed\n");
- region->compositor = compositor;
- wl_resource_set_implementation(region->resource, ®ion_implementation,
- region, region_resource_destroy_handler);
+ region->compositor = compositor;
+ wl_resource_set_implementation(region->resource, ®ion_implementation,
+ region, region_resource_destroy_handler);
- region->link.item = region;
- pepper_list_insert(&compositor->region_list, ®ion->link);
- pixman_region32_init(®ion->pixman_region);
+ region->link.item = region;
+ pepper_list_insert(&compositor->region_list, ®ion->link);
+ pixman_region32_init(®ion->pixman_region);
- return region;
+ return region;
error:
- if (region)
- free(region);
+ if (region)
+ free(region);
- return NULL;
+ return NULL;
}
void
pepper_region_destroy(pepper_region_t *region)
{
- pixman_region32_fini(®ion->pixman_region);
- pepper_list_remove(®ion->link);
- free(region);
+ pixman_region32_fini(®ion->pixman_region);
+ pepper_list_remove(®ion->link);
+ free(region);
}
static inline void
add_bbox_point(double *box, int x, int y, const pepper_mat4_t *matrix)
{
- pepper_vec2_t v = { x, y };
+ pepper_vec2_t v = { x, y };
- pepper_mat4_transform_vec2(matrix, &v);
+ pepper_mat4_transform_vec2(matrix, &v);
- box[0] = PEPPER_MIN(box[0], v.x);
- box[1] = PEPPER_MIN(box[1], v.y);
- box[2] = PEPPER_MAX(box[2], v.x);
- box[3] = PEPPER_MAX(box[3], v.y);
+ box[0] = PEPPER_MIN(box[0], v.x);
+ box[1] = PEPPER_MIN(box[1], v.y);
+ box[2] = PEPPER_MAX(box[2], v.x);
+ box[3] = PEPPER_MAX(box[3], v.y);
}
static inline void
transform_bounding_box(pixman_box32_t *box, const pepper_mat4_t *matrix)
{
- double b[4] = { HUGE_VAL, HUGE_VAL, -HUGE_VAL, -HUGE_VAL };
+ double b[4] = { HUGE_VAL, HUGE_VAL, -HUGE_VAL, -HUGE_VAL };
- add_bbox_point(b, box->x1, box->y1, matrix);
- add_bbox_point(b, box->x2, box->y1, matrix);
- add_bbox_point(b, box->x2, box->y2, matrix);
- add_bbox_point(b, box->x1, box->y2, matrix);
+ add_bbox_point(b, box->x1, box->y1, matrix);
+ add_bbox_point(b, box->x2, box->y1, matrix);
+ add_bbox_point(b, box->x2, box->y2, matrix);
+ add_bbox_point(b, box->x1, box->y2, matrix);
- box->x1 = floor(b[0]);
- box->y1 = floor(b[1]);
- box->x2 = ceil(b[2]);
- box->y2 = ceil(b[3]);
+ box->x1 = floor(b[0]);
+ box->y1 = floor(b[1]);
+ box->x2 = ceil(b[2]);
+ box->y2 = ceil(b[3]);
}
void
-pepper_transform_pixman_region(pixman_region32_t *region, const pepper_mat4_t *matrix)
+pepper_transform_pixman_region(pixman_region32_t *region,
+ const pepper_mat4_t *matrix)
{
- pixman_region32_t result;
- pixman_box32_t *rects;
- int i, num_rects;
+ pixman_region32_t result;
+ pixman_box32_t *rects;
+ int i, num_rects;
- pixman_region32_init(&result);
- rects = pixman_region32_rectangles(region, &num_rects);
+ pixman_region32_init(&result);
+ rects = pixman_region32_rectangles(region, &num_rects);
- for (i = 0; i < num_rects; i++)
- {
- pixman_box32_t box = rects[i];
+ for (i = 0; i < num_rects; i++) {
+ pixman_box32_t box = rects[i];
- transform_bounding_box(&box, matrix);
- pixman_region32_union_rect(&result, &result,
- box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
- }
+ transform_bounding_box(&box, matrix);
+ pixman_region32_union_rect(&result, &result,
+ box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
+ }
- pixman_region32_copy(region, &result);
- pixman_region32_fini(&result);
+ pixman_region32_copy(region, &result);
+ pixman_region32_fini(&result);
}
static void
subcompositor_destroy(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
static void
subcompositor_get_subsurface(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id,
- struct wl_resource *surface_resource,
- struct wl_resource *parent_resource)
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource *surface_resource,
+ struct wl_resource *parent_resource)
{
- pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
- pepper_surface_t *parent = wl_resource_get_user_data(parent_resource);
-
- if (surface->sub)
- {
- wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
- "wl_subcompositor::get_subsurface() already requested");
- return ;
- }
-
- if (surface == parent)
- {
- wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
- "wl_subcompositor::get_subsurface() cannot assign parent for its own");
- return ;
- }
-
- if (!pepper_subsurface_create(surface, parent, client, resource, id))
- wl_resource_post_no_memory(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(surface_resource);
+ pepper_surface_t *parent = wl_resource_get_user_data(parent_resource);
+
+ if (surface->sub) {
+ wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
+ "wl_subcompositor::get_subsurface() already requested");
+ return ;
+ }
+
+ if (surface == parent) {
+ wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
+ "wl_subcompositor::get_subsurface() cannot assign parent for its own");
+ return ;
+ }
+
+ if (!pepper_subsurface_create(surface, parent, client, resource, id))
+ wl_resource_post_no_memory(resource);
}
-static const struct wl_subcompositor_interface subcompositor_interface =
-{
- subcompositor_destroy,
- subcompositor_get_subsurface,
+static const struct wl_subcompositor_interface subcompositor_interface = {
+ subcompositor_destroy,
+ subcompositor_get_subsurface,
};
static void
unbind_resource(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
static void
subcompositor_bind(struct wl_client *client,
- void *data,
- uint32_t version,
- uint32_t id)
+ void *data,
+ uint32_t version,
+ uint32_t id)
{
- pepper_subcompositor_t *subcompositor = (pepper_subcompositor_t *)data;
- struct wl_resource *resource;
+ pepper_subcompositor_t *subcompositor = (pepper_subcompositor_t *)data;
+ struct wl_resource *resource;
- resource = wl_resource_create(client, &wl_subcompositor_interface, version, id);
+ resource = wl_resource_create(client, &wl_subcompositor_interface, version, id);
- if (!resource)
- {
- PEPPER_ERROR("wl_resource_create failed\n");
- wl_client_post_no_memory(client);
- return;
- }
+ if (!resource) {
+ PEPPER_ERROR("wl_resource_create failed\n");
+ wl_client_post_no_memory(client);
+ return;
+ }
- wl_list_insert(&subcompositor->resource_list, wl_resource_get_link(resource));
- wl_resource_set_implementation(resource, &subcompositor_interface, subcompositor, unbind_resource);
+ wl_list_insert(&subcompositor->resource_list, wl_resource_get_link(resource));
+ wl_resource_set_implementation(resource, &subcompositor_interface,
+ subcompositor, unbind_resource);
}
pepper_subcompositor_t *
pepper_subcompositor_create(pepper_compositor_t *compositor)
{
- pepper_subcompositor_t *subcompositor;
+ pepper_subcompositor_t *subcompositor;
- subcompositor = (pepper_subcompositor_t *)pepper_object_alloc(PEPPER_OBJECT_SUBCOMPOSITOR,
- sizeof(pepper_subcompositor_t));
- PEPPER_CHECK(subcompositor, goto error, "pepper_object_alloc() failed.\n");
+ subcompositor = (pepper_subcompositor_t *)pepper_object_alloc(
+ PEPPER_OBJECT_SUBCOMPOSITOR,
+ sizeof(pepper_subcompositor_t));
+ PEPPER_CHECK(subcompositor, goto error, "pepper_object_alloc() failed.\n");
- subcompositor->compositor = compositor;
- subcompositor->global = wl_global_create(compositor->display, &wl_subcompositor_interface, 1,
- subcompositor, subcompositor_bind);
- PEPPER_CHECK(subcompositor->global, goto error, "wl_global_create() failed.\n");
+ subcompositor->compositor = compositor;
+ subcompositor->global = wl_global_create(compositor->display,
+ &wl_subcompositor_interface, 1,
+ subcompositor, subcompositor_bind);
+ PEPPER_CHECK(subcompositor->global, goto error, "wl_global_create() failed.\n");
- wl_list_init(&subcompositor->resource_list);
+ wl_list_init(&subcompositor->resource_list);
- return subcompositor;
+ return subcompositor;
error:
- if (subcompositor)
- pepper_subcompositor_destroy(subcompositor);
+ if (subcompositor)
+ pepper_subcompositor_destroy(subcompositor);
- return NULL;
+ return NULL;
}
void
pepper_subcompositor_destroy(pepper_subcompositor_t *subcompositor)
{
- struct wl_resource *resource, *tmp;
+ struct wl_resource *resource, *tmp;
- if (subcompositor->global)
- wl_global_destroy(subcompositor->global);
+ if (subcompositor->global)
+ wl_global_destroy(subcompositor->global);
- wl_resource_for_each_safe(resource, tmp, &subcompositor->resource_list)
- wl_resource_destroy(resource);
+ wl_resource_for_each_safe(resource, tmp, &subcompositor->resource_list)
+ wl_resource_destroy(resource);
- pepper_object_fini(&subcompositor->base);
- free(subcompositor);
+ pepper_object_fini(&subcompositor->base);
+ free(subcompositor);
}
static void
subsurface_destroy(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
static void
subsurface_set_position(struct wl_client *client,
- struct wl_resource *resource,
- int32_t x,
- int32_t y)
+ struct wl_resource *resource,
+ int32_t x,
+ int32_t y)
{
- pepper_subsurface_t *subsurface = wl_resource_get_user_data(resource);
+ pepper_subsurface_t *subsurface = wl_resource_get_user_data(resource);
- subsurface->pending.x = x;
- subsurface->pending.y = y;
+ subsurface->pending.x = x;
+ subsurface->pending.y = y;
}
static pepper_bool_t
subsurface_is_sibling(pepper_subsurface_t *subsurface, pepper_surface_t *sib)
{
- if (subsurface->parent == sib)
- return PEPPER_TRUE;
- else if(sib->sub && sib->sub->parent == subsurface->parent)
- return PEPPER_TRUE;
+ if (subsurface->parent == sib)
+ return PEPPER_TRUE;
+ else if (sib->sub && sib->sub->parent == subsurface->parent)
+ return PEPPER_TRUE;
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
static void
-subsurface_stack_above(pepper_subsurface_t *subsurface, pepper_subsurface_t *sibling)
+subsurface_stack_above(pepper_subsurface_t *subsurface,
+ pepper_subsurface_t *sibling)
{
- pepper_subsurface_t *parent;
- pepper_list_t *pos;
-
- if (subsurface->parent == sibling->surface)
- {
- parent = sibling;
- pos = &parent->pending.self_link;
- }
- else
- {
- parent = subsurface->parent->sub;
- pos = &sibling->pending.parent_link;
- }
-
- pepper_list_remove(&subsurface->pending.parent_link);
- pepper_list_insert(pos, &subsurface->pending.parent_link);
-
- parent->need_restack = PEPPER_TRUE;
+ pepper_subsurface_t *parent;
+ pepper_list_t *pos;
+
+ if (subsurface->parent == sibling->surface) {
+ parent = sibling;
+ pos = &parent->pending.self_link;
+ } else {
+ parent = subsurface->parent->sub;
+ pos = &sibling->pending.parent_link;
+ }
+
+ pepper_list_remove(&subsurface->pending.parent_link);
+ pepper_list_insert(pos, &subsurface->pending.parent_link);
+
+ parent->need_restack = PEPPER_TRUE;
}
static void
subsurface_place_above(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *sibling_resource)
+ struct wl_resource *resource,
+ struct wl_resource *sibling_resource)
{
- pepper_subsurface_t *sub = wl_resource_get_user_data(resource);
- pepper_surface_t *sibling;
-
- if (!sibling_resource)
- {
- wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
- "reference surface cannot be null");
- return ;
- }
-
- sibling = wl_resource_get_user_data(sibling_resource);
-
- if (sub->surface == sibling)
- {
- wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
- "cannot place above of its own for itself");
- return ;
- }
-
- if (!subsurface_is_sibling(sub, sibling))
- {
- wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
- "reference surface is not sibling");
- return ;
- }
-
- subsurface_stack_above(sub, sibling->sub);
+ pepper_subsurface_t *sub = wl_resource_get_user_data(resource);
+ pepper_surface_t *sibling;
+
+ if (!sibling_resource) {
+ wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
+ "reference surface cannot be null");
+ return ;
+ }
+
+ sibling = wl_resource_get_user_data(sibling_resource);
+
+ if (sub->surface == sibling) {
+ wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
+ "cannot place above of its own for itself");
+ return ;
+ }
+
+ if (!subsurface_is_sibling(sub, sibling)) {
+ wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
+ "reference surface is not sibling");
+ return ;
+ }
+
+ subsurface_stack_above(sub, sibling->sub);
}
static void
-subsurface_stack_below(pepper_subsurface_t *subsurface, pepper_subsurface_t *sibling)
+subsurface_stack_below(pepper_subsurface_t *subsurface,
+ pepper_subsurface_t *sibling)
{
- pepper_subsurface_t *parent;
- pepper_list_t *pos;
-
- if (subsurface->parent == sibling->surface)
- {
- parent = sibling;
- pos = &parent->pending.self_link;
- }
- else
- {
- parent = subsurface->parent->sub;
- pos = &sibling->pending.parent_link;
- }
-
- pepper_list_remove(&subsurface->pending.parent_link);
- pepper_list_insert(pos->prev, &subsurface->pending.parent_link);
-
- parent->need_restack = PEPPER_TRUE;
+ pepper_subsurface_t *parent;
+ pepper_list_t *pos;
+
+ if (subsurface->parent == sibling->surface) {
+ parent = sibling;
+ pos = &parent->pending.self_link;
+ } else {
+ parent = subsurface->parent->sub;
+ pos = &sibling->pending.parent_link;
+ }
+
+ pepper_list_remove(&subsurface->pending.parent_link);
+ pepper_list_insert(pos->prev, &subsurface->pending.parent_link);
+
+ parent->need_restack = PEPPER_TRUE;
}
static void
subsurface_place_below(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *sibling_resource)
+ struct wl_resource *resource,
+ struct wl_resource *sibling_resource)
{
- pepper_subsurface_t *sub = wl_resource_get_user_data(resource);
- pepper_surface_t *sibling;
-
- if (!sibling_resource)
- {
- wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
- "reference surface cannot be null");
- return ;
- }
-
- sibling = wl_resource_get_user_data(sibling_resource);
-
- if (sub->surface == sibling)
- {
- wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
- "cannot place below of its own for itself");
- return ;
- }
-
- if (!subsurface_is_sibling(sub, sibling))
- {
- wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
- "reference surface is not sibling");
- return ;
- }
-
- subsurface_stack_below(sub, sibling->sub);
+ pepper_subsurface_t *sub = wl_resource_get_user_data(resource);
+ pepper_surface_t *sibling;
+
+ if (!sibling_resource) {
+ wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
+ "reference surface cannot be null");
+ return ;
+ }
+
+ sibling = wl_resource_get_user_data(sibling_resource);
+
+ if (sub->surface == sibling) {
+ wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
+ "cannot place below of its own for itself");
+ return ;
+ }
+
+ if (!subsurface_is_sibling(sub, sibling)) {
+ wl_resource_post_error(resource, WL_SUBSURFACE_ERROR_BAD_SURFACE,
+ "reference surface is not sibling");
+ return ;
+ }
+
+ subsurface_stack_below(sub, sibling->sub);
}
static void
subsurface_set_sync(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- pepper_subsurface_t *subsurface = wl_resource_get_user_data(resource);
+ pepper_subsurface_t *subsurface = wl_resource_get_user_data(resource);
- subsurface->sync = PEPPER_TRUE;
+ subsurface->sync = PEPPER_TRUE;
}
/* Copy 'from' -> 'to' state and clear 'from' state */
static void
surface_state_move(pepper_surface_state_t *from, pepper_surface_state_t *to)
{
- if (from->newly_attached)
- {
- to->newly_attached = PEPPER_TRUE;
- to->buffer = from->buffer;
+ if (from->newly_attached) {
+ to->newly_attached = PEPPER_TRUE;
+ to->buffer = from->buffer;
- from->newly_attached = PEPPER_FALSE;
- from->buffer = NULL;
- }
+ from->newly_attached = PEPPER_FALSE;
+ from->buffer = NULL;
+ }
- to->transform = from->transform;
- to->scale = from->scale;
- to->x += from->x;
- to->y += from->y;
+ to->transform = from->transform;
+ to->scale = from->scale;
+ to->x += from->x;
+ to->y += from->y;
- /* FIXME: Need to create another one? */
- to->buffer_destroy_listener = from->buffer_destroy_listener;
+ /* FIXME: Need to create another one? */
+ to->buffer_destroy_listener = from->buffer_destroy_listener;
- pixman_region32_copy(&to->damage_region, &from->damage_region);
- pixman_region32_copy(&to->opaque_region, &from->opaque_region);
- pixman_region32_copy(&to->input_region, &from->input_region);
+ pixman_region32_copy(&to->damage_region, &from->damage_region);
+ pixman_region32_copy(&to->opaque_region, &from->opaque_region);
+ pixman_region32_copy(&to->input_region, &from->input_region);
- wl_list_insert_list(&to->frame_callback_list, &from->frame_callback_list);
+ wl_list_insert_list(&to->frame_callback_list, &from->frame_callback_list);
- /* Clear 'from' state */
- from->x = 0;
- from->y = 0;
- from->scale = 1;
- from->transform = WL_OUTPUT_TRANSFORM_NORMAL;
- from->buffer_destroy_listener = NULL;
+ /* Clear 'from' state */
+ from->x = 0;
+ from->y = 0;
+ from->scale = 1;
+ from->transform = WL_OUTPUT_TRANSFORM_NORMAL;
+ from->buffer_destroy_listener = NULL;
- pixman_region32_clear(&from->damage_region);
- pixman_region32_clear(&from->opaque_region);
- pixman_region32_clear(&from->input_region);
+ pixman_region32_clear(&from->damage_region);
+ pixman_region32_clear(&from->opaque_region);
+ pixman_region32_clear(&from->input_region);
- wl_list_init(&from->frame_callback_list);
+ wl_list_init(&from->frame_callback_list);
}
static void
surface_commit_to_cache(pepper_subsurface_t *subsurface)
{
- /* Commit surface.pending to subsurface.cache */
- surface_state_move(&subsurface->surface->pending, &subsurface->cache);
- subsurface->cached = PEPPER_TRUE;
+ /* Commit surface.pending to subsurface.cache */
+ surface_state_move(&subsurface->surface->pending, &subsurface->cache);
+ subsurface->cached = PEPPER_TRUE;
}
static void
surface_commit_from_cache(pepper_subsurface_t *subsurface)
{
- /* check if dummy */
- if (!subsurface->parent)
- return ;
+ /* check if dummy */
+ if (!subsurface->parent)
+ return ;
- /* Commit subsurface.cache to surface.current directly */
- pepper_surface_commit_state(subsurface->surface, &subsurface->cache);
- subsurface->cached = PEPPER_FALSE;
+ /* Commit subsurface.cache to surface.current directly */
+ pepper_surface_commit_state(subsurface->surface, &subsurface->cache);
+ subsurface->cached = PEPPER_FALSE;
- /* Subsurface emit commit event in here */
- pepper_object_emit_event(&subsurface->surface->base, PEPPER_EVENT_SURFACE_COMMIT, NULL);
+ /* Subsurface emit commit event in here */
+ pepper_object_emit_event(&subsurface->surface->base,
+ PEPPER_EVENT_SURFACE_COMMIT, NULL);
}
static pepper_bool_t
subsurface_get_sync(pepper_subsurface_t *subsurface)
{
- /* TODO: FIXME */
- if (!subsurface)
- return PEPPER_FALSE;
+ /* TODO: FIXME */
+ if (!subsurface)
+ return PEPPER_FALSE;
- if (!subsurface->parent)
- return PEPPER_FALSE;
+ if (!subsurface->parent)
+ return PEPPER_FALSE;
- if (subsurface->sync)
- return PEPPER_TRUE;
+ if (subsurface->sync)
+ return PEPPER_TRUE;
- if (subsurface->parent->sub)
- return subsurface_get_sync(subsurface->parent->sub);
+ if (subsurface->parent->sub)
+ return subsurface_get_sync(subsurface->parent->sub);
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
#define EACH_LIST_FOR_EACH(pos1, head1, pos2, head2, member) \
static void
subsurface_restack_view(pepper_subsurface_t *subsurface)
{
- pepper_subsurface_t *child1 = NULL, *child2;
- pepper_list_t *list;
-
- pepper_list_for_each_list(list, &subsurface->children_list)
- {
- pepper_view_t *view1, *view2;
-
- child2 = list->item;
-
- if (!child1)
- {
- child1 = child2;
- continue;
- }
-
- EACH_LIST_FOR_EACH(view1, &child1->surface->view_list,
- view2, &child2->surface->view_list,
- surface_link)
- {
- pepper_view_stack_above(view1, view2, PEPPER_TRUE);
- }
-
- child1 = child2;
- }
+ pepper_subsurface_t *child1 = NULL, *child2;
+ pepper_list_t *list;
+
+ pepper_list_for_each_list(list, &subsurface->children_list) {
+ pepper_view_t *view1, *view2;
+
+ child2 = list->item;
+
+ if (!child1) {
+ child1 = child2;
+ continue;
+ }
+
+ EACH_LIST_FOR_EACH(view1, &child1->surface->view_list,
+ view2, &child2->surface->view_list,
+ surface_link) {
+ pepper_view_stack_above(view1, view2, PEPPER_TRUE);
+ }
+
+ child1 = child2;
+ }
}
#undef EACH_LIST_FOR_EACH
static void
subsurface_apply_order(pepper_subsurface_t *subsurface)
{
- pepper_list_t *list;
- pepper_subsurface_t *child;
-
- if (!subsurface->need_restack)
- return ;
-
- pepper_list_for_each_list(list, &subsurface->pending.children_list)
- {
- child = list->item;
- if (child)
- {
- /* */
- if (child == subsurface)
- {
- pepper_list_remove(&child->self_link);
- pepper_list_insert(&subsurface->children_list, &child->self_link);
- }
- else
- {
- pepper_list_remove(&child->parent_link);
- pepper_list_insert(&subsurface->children_list, &child->parent_link);
- }
- }
- }
- subsurface_restack_view(subsurface);
-
- subsurface->need_restack = PEPPER_FALSE;
+ pepper_list_t *list;
+ pepper_subsurface_t *child;
+
+ if (!subsurface->need_restack)
+ return ;
+
+ pepper_list_for_each_list(list, &subsurface->pending.children_list) {
+ child = list->item;
+ if (child) {
+ /* */
+ if (child == subsurface) {
+ pepper_list_remove(&child->self_link);
+ pepper_list_insert(&subsurface->children_list, &child->self_link);
+ } else {
+ pepper_list_remove(&child->parent_link);
+ pepper_list_insert(&subsurface->children_list, &child->parent_link);
+ }
+ }
+ }
+ subsurface_restack_view(subsurface);
+
+ subsurface->need_restack = PEPPER_FALSE;
}
static void
subsurface_apply_position(pepper_subsurface_t *subsurface)
{
- pepper_view_t *view;
+ pepper_view_t *view;
- /* Check this subsurface is dummy */
- if (!subsurface->parent)
- return ;
+ /* Check this subsurface is dummy */
+ if (!subsurface->parent)
+ return ;
- subsurface->x = subsurface->pending.x;
- subsurface->y = subsurface->pending.y;
+ subsurface->x = subsurface->pending.x;
+ subsurface->y = subsurface->pending.y;
- pepper_list_for_each(view, &subsurface->surface->view_list, surface_link)
- pepper_view_set_position(view, subsurface->x, subsurface->y);
+ pepper_list_for_each(view, &subsurface->surface->view_list, surface_link)
+ pepper_view_set_position(view, subsurface->x, subsurface->y);
}
static void
subsurface_apply_pending_state(pepper_subsurface_t *subsurface)
{
- subsurface_apply_position(subsurface);
- subsurface_apply_order(subsurface);
+ subsurface_apply_position(subsurface);
+ subsurface_apply_order(subsurface);
}
static void
subsurface_set_desync(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- pepper_subsurface_t *subsurface = wl_resource_get_user_data(resource);
+ pepper_subsurface_t *subsurface = wl_resource_get_user_data(resource);
- if (subsurface->cached)
- surface_commit_from_cache(subsurface);
+ if (subsurface->cached)
+ surface_commit_from_cache(subsurface);
- subsurface->sync = PEPPER_FALSE;
+ subsurface->sync = PEPPER_FALSE;
}
-static struct wl_subsurface_interface subsurface_implementation =
-{
- subsurface_destroy,
- subsurface_set_position,
- subsurface_place_above,
- subsurface_place_below,
- subsurface_set_sync,
- subsurface_set_desync,
+static struct wl_subsurface_interface subsurface_implementation = {
+ subsurface_destroy,
+ subsurface_set_position,
+ subsurface_place_above,
+ subsurface_place_below,
+ subsurface_set_sync,
+ subsurface_set_desync,
};
void
pepper_subsurface_destroy(pepper_subsurface_t *subsurface)
{
- pepper_surface_state_fini(&subsurface->cache);
+ pepper_surface_state_fini(&subsurface->cache);
- if (subsurface->parent)
- {
- pepper_list_remove(&subsurface->parent_link);
- pepper_list_remove(&subsurface->pending.parent_link);
- pepper_event_listener_remove(subsurface->parent_destroy_listener);
- pepper_event_listener_remove(subsurface->parent_commit_listener);
- }
+ if (subsurface->parent) {
+ pepper_list_remove(&subsurface->parent_link);
+ pepper_list_remove(&subsurface->pending.parent_link);
+ pepper_event_listener_remove(subsurface->parent_destroy_listener);
+ pepper_event_listener_remove(subsurface->parent_commit_listener);
+ }
- /* TODO: handle view_list */
+ /* TODO: handle view_list */
- free(subsurface);
+ free(subsurface);
}
static void
subsurface_resource_destroy_handler(struct wl_resource *resource)
{
- pepper_subsurface_t *sub = wl_resource_get_user_data(resource);
- pepper_subsurface_destroy(sub);
+ pepper_subsurface_t *sub = wl_resource_get_user_data(resource);
+ pepper_subsurface_destroy(sub);
}
static void
handle_parent_destroy(pepper_event_listener_t *listener,
- pepper_object_t *object, uint32_t id, void *info, void *data)
+ pepper_object_t *object, uint32_t id, void *info, void *data)
{
- pepper_subsurface_t *subsurface = data;
+ pepper_subsurface_t *subsurface = data;
- /* TODO: handle view_list */
+ /* TODO: handle view_list */
- pepper_list_remove(&subsurface->parent_link);
- pepper_list_remove(&subsurface->pending.parent_link);
+ pepper_list_remove(&subsurface->parent_link);
+ pepper_list_remove(&subsurface->pending.parent_link);
- pepper_event_listener_remove(subsurface->parent_destroy_listener);
+ pepper_event_listener_remove(subsurface->parent_destroy_listener);
- subsurface->parent = NULL;
+ subsurface->parent = NULL;
}
static void
subsurface_parent_commit(pepper_subsurface_t *subsurface)
{
- /* Apply subsurface's pending state, and propagate to children */
- subsurface_apply_pending_state(subsurface);
+ /* Apply subsurface's pending state, and propagate to children */
+ subsurface_apply_pending_state(subsurface);
- if (subsurface->cached)
- surface_commit_from_cache(subsurface);
+ if (subsurface->cached)
+ surface_commit_from_cache(subsurface);
}
static void
handle_parent_commit(pepper_event_listener_t *listener,
- pepper_object_t *object, uint32_t id, void *info, void *data)
+ pepper_object_t *object, uint32_t id, void *info, void *data)
{
- pepper_subsurface_t *subsurface = data;
+ pepper_subsurface_t *subsurface = data;
- subsurface_parent_commit(subsurface);
+ subsurface_parent_commit(subsurface);
}
static pepper_bool_t
pepper_subsurface_create_views(pepper_subsurface_t *subsurface)
{
- pepper_surface_t *parent = subsurface->parent;
- pepper_view_t *parent_view;
+ pepper_surface_t *parent = subsurface->parent;
+ pepper_view_t *parent_view;
- pepper_list_for_each(parent_view, &parent->view_list, surface_link)
- {
- pepper_view_t *subview = pepper_compositor_add_view(parent->compositor);
- PEPPER_CHECK(subview, return PEPPER_FALSE, "pepper_compositor_add_view() failed.\n");
+ pepper_list_for_each(parent_view, &parent->view_list, surface_link) {
+ pepper_view_t *subview = pepper_compositor_add_view(parent->compositor);
+ PEPPER_CHECK(subview, return PEPPER_FALSE,
+ "pepper_compositor_add_view() failed.\n");
- pepper_view_set_surface(subview, subsurface->surface);
- pepper_view_set_parent(subview, parent_view);
- pepper_view_stack_above(subview, parent_view, PEPPER_TRUE);
- pepper_view_set_transform_inherit(subview, PEPPER_TRUE);
+ pepper_view_set_surface(subview, subsurface->surface);
+ pepper_view_set_parent(subview, parent_view);
+ pepper_view_stack_above(subview, parent_view, PEPPER_TRUE);
+ pepper_view_set_transform_inherit(subview, PEPPER_TRUE);
- /* FIXME: map later, when ? */
- pepper_view_map(subview);
- }
+ /* FIXME: map later, when ? */
+ pepper_view_map(subview);
+ }
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_subsurface_t *
pepper_dummy_subsurface_create_for_parent(pepper_surface_t *parent)
{
- pepper_subsurface_t *subsurface;
+ pepper_subsurface_t *subsurface;
- subsurface = calloc(1, sizeof(pepper_subsurface_t));
- PEPPER_CHECK(subsurface, return NULL, "calloc() failed.\n");
+ subsurface = calloc(1, sizeof(pepper_subsurface_t));
+ PEPPER_CHECK(subsurface, return NULL, "calloc() failed.\n");
- subsurface->surface = parent;
+ subsurface->surface = parent;
- /* Insert itself to own children_list. Parent can be placed below/above of own children */
- pepper_list_init(&subsurface->children_list);
- pepper_list_insert(&subsurface->children_list, &subsurface->self_link);
+ /* Insert itself to own children_list. Parent can be placed below/above of own children */
+ pepper_list_init(&subsurface->children_list);
+ pepper_list_insert(&subsurface->children_list, &subsurface->self_link);
- pepper_list_init(&subsurface->pending.children_list);
- pepper_list_insert(&subsurface->pending.children_list, &subsurface->pending.self_link);
+ pepper_list_init(&subsurface->pending.children_list);
+ pepper_list_insert(&subsurface->pending.children_list,
+ &subsurface->pending.self_link);
- return subsurface;
+ return subsurface;
}
pepper_subsurface_t *
pepper_subsurface_create(pepper_surface_t *surface,
- pepper_surface_t *parent,
- struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id)
+ pepper_surface_t *parent,
+ struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id)
{
- pepper_subsurface_t *subsurface = NULL;
- pepper_bool_t ret;
+ pepper_subsurface_t *subsurface = NULL;
+ pepper_bool_t ret;
- if (!pepper_surface_set_role(surface, "wl_subsurface"))
- {
- wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
- "cannot assign wl_subsurface role");
- return NULL;
- }
+ if (!pepper_surface_set_role(surface, "wl_subsurface")) {
+ wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
+ "cannot assign wl_subsurface role");
+ return NULL;
+ }
- /* Make sure that subsurface has no view */
- if (!pepper_list_empty(&surface->view_list))
- goto error;
+ /* Make sure that subsurface has no view */
+ if (!pepper_list_empty(&surface->view_list))
+ goto error;
- subsurface = calloc(1, sizeof(pepper_subsurface_t));
- PEPPER_CHECK(subsurface, goto error, "calloc() failed.\n");
+ subsurface = calloc(1, sizeof(pepper_subsurface_t));
+ PEPPER_CHECK(subsurface, goto error, "calloc() failed.\n");
- subsurface->resource = wl_resource_create(client, &wl_subsurface_interface,
- wl_resource_get_version(resource), id);
- PEPPER_CHECK(subsurface->resource, goto error, "wl_resource_create() failed\n");
+ subsurface->resource = wl_resource_create(client, &wl_subsurface_interface,
+ wl_resource_get_version(resource), id);
+ PEPPER_CHECK(subsurface->resource, goto error, "wl_resource_create() failed\n");
- wl_resource_set_implementation(subsurface->resource, &subsurface_implementation, subsurface,
- subsurface_resource_destroy_handler);
+ wl_resource_set_implementation(subsurface->resource, &subsurface_implementation,
+ subsurface,
+ subsurface_resource_destroy_handler);
- subsurface->surface = surface;
- subsurface->parent = parent;
+ subsurface->surface = surface;
+ subsurface->parent = parent;
- /* A sub-surface is initially in the synchronized mode. */
- subsurface->sync = PEPPER_TRUE;
+ /* A sub-surface is initially in the synchronized mode. */
+ subsurface->sync = PEPPER_TRUE;
- subsurface->x = subsurface->y = 0.f;
- subsurface->pending.x = subsurface->pending.y = 0.f;
+ subsurface->x = subsurface->y = 0.f;
+ subsurface->pending.x = subsurface->pending.y = 0.f;
- subsurface->parent_link.item = subsurface;
- subsurface->self_link.item = subsurface;
- subsurface->pending.parent_link.item = subsurface;
- subsurface->pending.self_link.item = subsurface;
+ subsurface->parent_link.item = subsurface;
+ subsurface->self_link.item = subsurface;
+ subsurface->pending.parent_link.item = subsurface;
+ subsurface->pending.self_link.item = subsurface;
- subsurface->parent_destroy_listener =
- pepper_object_add_event_listener(&parent->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
- handle_parent_destroy, subsurface);
+ subsurface->parent_destroy_listener =
+ pepper_object_add_event_listener(&parent->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
+ handle_parent_destroy, subsurface);
- subsurface->parent_commit_listener =
- pepper_object_add_event_listener(&parent->base, PEPPER_EVENT_SURFACE_COMMIT, 0,
- handle_parent_commit, subsurface);
+ subsurface->parent_commit_listener =
+ pepper_object_add_event_listener(&parent->base, PEPPER_EVENT_SURFACE_COMMIT, 0,
+ handle_parent_commit, subsurface);
- pepper_surface_state_init(&subsurface->cache);
+ pepper_surface_state_init(&subsurface->cache);
- if (!parent->sub)
- parent->sub = pepper_dummy_subsurface_create_for_parent(parent);
- PEPPER_CHECK(parent->sub, goto error, "pepper_dummy_subsurface_create_for_parent() failed\n");
+ if (!parent->sub)
+ parent->sub = pepper_dummy_subsurface_create_for_parent(parent);
+ PEPPER_CHECK(parent->sub, goto error,
+ "pepper_dummy_subsurface_create_for_parent() failed\n");
- /* children_list is z-order sorted, youngest child is top-most */
- pepper_list_init(&subsurface->children_list);
- pepper_list_init(&subsurface->pending.children_list);
+ /* children_list is z-order sorted, youngest child is top-most */
+ pepper_list_init(&subsurface->children_list);
+ pepper_list_init(&subsurface->pending.children_list);
- /* link to myself */
- pepper_list_insert(&subsurface->children_list, &subsurface->self_link);
- pepper_list_insert(&subsurface->pending.children_list, &subsurface->pending.self_link);
+ /* link to myself */
+ pepper_list_insert(&subsurface->children_list, &subsurface->self_link);
+ pepper_list_insert(&subsurface->pending.children_list,
+ &subsurface->pending.self_link);
- /* link to parent */
- pepper_list_insert(&parent->sub->children_list, &subsurface->parent_link);
- pepper_list_insert(&parent->sub->pending.children_list, &subsurface->pending.parent_link);
+ /* link to parent */
+ pepper_list_insert(&parent->sub->children_list, &subsurface->parent_link);
+ pepper_list_insert(&parent->sub->pending.children_list,
+ &subsurface->pending.parent_link);
- /* create views that corresponding to parent's views */
- ret = pepper_subsurface_create_views(subsurface);
- PEPPER_CHECK(ret, goto error, "pepper_subsurface_create_views() failed\n");
+ /* create views that corresponding to parent's views */
+ ret = pepper_subsurface_create_views(subsurface);
+ PEPPER_CHECK(ret, goto error, "pepper_subsurface_create_views() failed\n");
- surface->sub = subsurface;
+ surface->sub = subsurface;
- return subsurface;
+ return subsurface;
error:
- if (subsurface)
- pepper_subsurface_destroy(subsurface);
+ if (subsurface)
+ pepper_subsurface_destroy(subsurface);
- return NULL;
+ return NULL;
}
pepper_bool_t
pepper_subsurface_commit(pepper_subsurface_t *subsurface)
{
- if (subsurface_get_sync(subsurface))
- {
- surface_commit_to_cache(subsurface);
+ if (subsurface_get_sync(subsurface)) {
+ surface_commit_to_cache(subsurface);
- /* consume this commit */
- return PEPPER_TRUE;
- }
+ /* consume this commit */
+ return PEPPER_TRUE;
+ }
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
void
-subsurface_destroy_children_views(pepper_subsurface_t *subsurface, pepper_view_t *parent_view)
+subsurface_destroy_children_views(pepper_subsurface_t *subsurface,
+ pepper_view_t *parent_view)
{
- pepper_list_t *list;
-
- if (!subsurface)
- return ;
-
- pepper_list_for_each_list(list, &subsurface->children_list)
- {
- pepper_subsurface_t *child = list->item;
-
- /* Except its own */
- if(child && (child != subsurface))
- {
- pepper_view_t *view;
-
- pepper_list_for_each(view, &subsurface->surface->view_list, surface_link)
- {
- if (view->parent == parent_view)
- {
- /* FIXME: need this ? */
- pepper_view_set_surface(view, NULL);
- pepper_view_destroy(view);
- }
- }
- }
- }
+ pepper_list_t *list;
+
+ if (!subsurface)
+ return ;
+
+ pepper_list_for_each_list(list, &subsurface->children_list) {
+ pepper_subsurface_t *child = list->item;
+
+ /* Except its own */
+ if (child && (child != subsurface)) {
+ pepper_view_t *view;
+
+ pepper_list_for_each(view, &subsurface->surface->view_list, surface_link) {
+ if (view->parent == parent_view) {
+ /* FIXME: need this ? */
+ pepper_view_set_surface(view, NULL);
+ pepper_view_destroy(view);
+ }
+ }
+ }
+ }
}
void
-subsurface_create_children_views(pepper_subsurface_t *subsurface, pepper_view_t *parent_view)
+subsurface_create_children_views(pepper_subsurface_t *subsurface,
+ pepper_view_t *parent_view)
{
- pepper_list_t *list;
+ pepper_list_t *list;
- if (!subsurface)
- return ;
+ if (!subsurface)
+ return ;
- pepper_list_for_each_list(list, &subsurface->children_list)
- {
- pepper_subsurface_t *child = list->item;
+ pepper_list_for_each_list(list, &subsurface->children_list) {
+ pepper_subsurface_t *child = list->item;
- /* Except its own */
- if(child && (child != subsurface))
- {
- pepper_view_t *view = pepper_compositor_add_view(subsurface->surface->compositor);
- pepper_view_set_surface(view, child->surface);
- pepper_view_set_parent(view, parent_view);
- pepper_view_set_transform_inherit(view, PEPPER_TRUE);
+ /* Except its own */
+ if (child && (child != subsurface)) {
+ pepper_view_t *view = pepper_compositor_add_view(
+ subsurface->surface->compositor);
+ pepper_view_set_surface(view, child->surface);
+ pepper_view_set_parent(view, parent_view);
+ pepper_view_set_transform_inherit(view, PEPPER_TRUE);
- /* FIXME */
- pepper_view_map(view);
- }
- }
+ /* FIXME */
+ pepper_view_map(view);
+ }
+ }
- subsurface->need_restack = PEPPER_TRUE;
+ subsurface->need_restack = PEPPER_TRUE;
}
static void
surface_update_size(pepper_surface_t *surface)
{
- if (surface->buffer.buffer)
- {
- switch (surface->buffer.transform)
- {
- case WL_OUTPUT_TRANSFORM_NORMAL:
- case WL_OUTPUT_TRANSFORM_180:
- case WL_OUTPUT_TRANSFORM_FLIPPED:
- case WL_OUTPUT_TRANSFORM_FLIPPED_180:
- surface->w = surface->buffer.buffer->w;
- surface->h = surface->buffer.buffer->h;
- break;
- case WL_OUTPUT_TRANSFORM_90:
- case WL_OUTPUT_TRANSFORM_270:
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- surface->w = surface->buffer.buffer->h;
- surface->h = surface->buffer.buffer->w;
- break;
- }
-
- surface->w /= surface->buffer.scale;
- surface->h /= surface->buffer.scale;
- }
- else
- {
- surface->w = 0;
- surface->h = 0;
- }
+ if (surface->buffer.buffer) {
+ switch (surface->buffer.transform) {
+ case WL_OUTPUT_TRANSFORM_NORMAL:
+ case WL_OUTPUT_TRANSFORM_180:
+ case WL_OUTPUT_TRANSFORM_FLIPPED:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+ surface->w = surface->buffer.buffer->w;
+ surface->h = surface->buffer.buffer->h;
+ break;
+ case WL_OUTPUT_TRANSFORM_90:
+ case WL_OUTPUT_TRANSFORM_270:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+ surface->w = surface->buffer.buffer->h;
+ surface->h = surface->buffer.buffer->w;
+ break;
+ }
+
+ surface->w /= surface->buffer.scale;
+ surface->h /= surface->buffer.scale;
+ } else {
+ surface->w = 0;
+ surface->h = 0;
+ }
}
static void
surface_state_handle_buffer_destroy(pepper_event_listener_t *listener,
- pepper_object_t *object, uint32_t id, void *info, void *data)
+ pepper_object_t *object, uint32_t id, void *info, void *data)
{
- pepper_surface_state_t *state = data;
- state->buffer = NULL;
+ pepper_surface_state_t *state = data;
+ state->buffer = NULL;
}
static void
surface_handle_buffer_destroy(pepper_event_listener_t *listener,
- pepper_object_t *object, uint32_t id, void *info, void *data)
+ pepper_object_t *object, uint32_t id, void *info, void *data)
{
- pepper_surface_t *surface = data;
- surface->buffer.buffer = NULL;
- surface_update_size(surface);
+ pepper_surface_t *surface = data;
+ surface->buffer.buffer = NULL;
+ surface_update_size(surface);
}
void
pepper_surface_state_init(pepper_surface_state_t *state)
{
- state->buffer = NULL;
- state->x = 0;
- state->y = 0;
- state->transform = WL_OUTPUT_TRANSFORM_NORMAL;
- state->scale = 1;
+ state->buffer = NULL;
+ state->x = 0;
+ state->y = 0;
+ state->transform = WL_OUTPUT_TRANSFORM_NORMAL;
+ state->scale = 1;
- pixman_region32_init(&state->damage_region);
- pixman_region32_init(&state->opaque_region);
- pixman_region32_init_rect(&state->input_region, INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
+ pixman_region32_init(&state->damage_region);
+ pixman_region32_init(&state->opaque_region);
+ pixman_region32_init_rect(&state->input_region, INT32_MIN, INT32_MIN,
+ UINT32_MAX, UINT32_MAX);
- wl_list_init(&state->frame_callback_list);
+ wl_list_init(&state->frame_callback_list);
}
void
pepper_surface_state_fini(pepper_surface_state_t *state)
{
- struct wl_resource *callback, *next;
+ struct wl_resource *callback, *next;
- pixman_region32_fini(&state->damage_region);
- pixman_region32_fini(&state->opaque_region);
- pixman_region32_fini(&state->input_region);
+ pixman_region32_fini(&state->damage_region);
+ pixman_region32_fini(&state->opaque_region);
+ pixman_region32_fini(&state->input_region);
- wl_resource_for_each_safe(callback, next, &state->frame_callback_list)
- wl_resource_destroy(callback);
+ wl_resource_for_each_safe(callback, next, &state->frame_callback_list)
+ wl_resource_destroy(callback);
- if (state->buffer)
- pepper_event_listener_remove(state->buffer_destroy_listener);
+ if (state->buffer)
+ pepper_event_listener_remove(state->buffer_destroy_listener);
}
static void
surface_resource_destroy_handler(struct wl_resource *resource)
{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
- pepper_surface_destroy(surface);
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ pepper_surface_destroy(surface);
}
static void
surface_destroy(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
static void
surface_attach(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *buffer_resource,
- int32_t x,
- int32_t y)
-{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
- pepper_buffer_t *buffer = NULL;
-
- if (buffer_resource)
- {
- buffer = pepper_buffer_from_resource(buffer_resource);
- if (!buffer)
- {
- wl_client_post_no_memory(client);
- return;
- }
- }
-
- if (surface->pending.buffer == buffer)
- return;
-
- if (surface->pending.buffer)
- pepper_event_listener_remove(surface->pending.buffer_destroy_listener);
-
- surface->pending.buffer = buffer;
- surface->pending.x = x;
- surface->pending.y = y;
- surface->pending.newly_attached = PEPPER_TRUE;
-
- if (buffer)
- {
- surface->pending.buffer_destroy_listener =
- pepper_object_add_event_listener(&buffer->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
- surface_state_handle_buffer_destroy, &surface->pending);
- }
+ struct wl_resource *resource,
+ struct wl_resource *buffer_resource,
+ int32_t x,
+ int32_t y)
+{
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ pepper_buffer_t *buffer = NULL;
+
+ if (buffer_resource) {
+ buffer = pepper_buffer_from_resource(buffer_resource);
+ if (!buffer) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+ }
+
+ if (surface->pending.buffer == buffer)
+ return;
+
+ if (surface->pending.buffer)
+ pepper_event_listener_remove(surface->pending.buffer_destroy_listener);
+
+ surface->pending.buffer = buffer;
+ surface->pending.x = x;
+ surface->pending.y = y;
+ surface->pending.newly_attached = PEPPER_TRUE;
+
+ if (buffer) {
+ surface->pending.buffer_destroy_listener =
+ pepper_object_add_event_listener(&buffer->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
+ surface_state_handle_buffer_destroy, &surface->pending);
+ }
}
static void
surface_damage(struct wl_client *client,
- struct wl_resource *resource,
- int32_t x,
- int32_t y,
- int32_t w,
- int32_t h)
+ struct wl_resource *resource,
+ int32_t x,
+ int32_t y,
+ int32_t w,
+ int32_t h)
{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
- pixman_region32_union_rect(&surface->pending.damage_region,
- &surface->pending.damage_region, x, y, w, h);
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ pixman_region32_union_rect(&surface->pending.damage_region,
+ &surface->pending.damage_region, x, y, w, h);
}
static void
frame_callback_resource_destroy_handler(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
static void
surface_frame(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t callback_id)
+ struct wl_resource *resource,
+ uint32_t callback_id)
{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
- struct wl_resource *callback;
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ struct wl_resource *callback;
- callback = wl_resource_create(client, &wl_callback_interface, 1, callback_id);
+ callback = wl_resource_create(client, &wl_callback_interface, 1, callback_id);
- if (!callback)
- {
- wl_resource_post_no_memory(resource);
- return;
- }
+ if (!callback) {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
- wl_resource_set_implementation(callback, NULL, NULL,
- frame_callback_resource_destroy_handler);
- wl_list_insert(surface->pending.frame_callback_list.prev, wl_resource_get_link(callback));
+ wl_resource_set_implementation(callback, NULL, NULL,
+ frame_callback_resource_destroy_handler);
+ wl_list_insert(surface->pending.frame_callback_list.prev,
+ wl_resource_get_link(callback));
}
static void
surface_set_opaque_region(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *region_resource)
+ struct wl_resource *resource,
+ struct wl_resource *region_resource)
{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
- if (region_resource)
- {
- pepper_region_t *region = wl_resource_get_user_data(region_resource);
- pixman_region32_copy(&surface->pending.opaque_region, ®ion->pixman_region);
- }
- else
- {
- pixman_region32_clear(&surface->pending.opaque_region);
- }
+ if (region_resource) {
+ pepper_region_t *region = wl_resource_get_user_data(region_resource);
+ pixman_region32_copy(&surface->pending.opaque_region, ®ion->pixman_region);
+ } else {
+ pixman_region32_clear(&surface->pending.opaque_region);
+ }
}
static void
surface_set_input_region(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *region_resource)
+ struct wl_resource *resource,
+ struct wl_resource *region_resource)
{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
- if (region_resource)
- {
- pepper_region_t *region = wl_resource_get_user_data(region_resource);
- pixman_region32_copy(&surface->pending.input_region, ®ion->pixman_region);
- }
- else
- {
- pixman_region32_init_rect(&surface->pending.input_region,
- INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
- }
+ if (region_resource) {
+ pepper_region_t *region = wl_resource_get_user_data(region_resource);
+ pixman_region32_copy(&surface->pending.input_region, ®ion->pixman_region);
+ } else {
+ pixman_region32_init_rect(&surface->pending.input_region,
+ INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
+ }
}
static void
surface_commit(struct wl_client *client, struct wl_resource *resource)
{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
- /* If this surface is subsurface and subsurface is in synchronized mode,
- * pending surface_state should be commit to cache, not current */
- if (pepper_subsurface_commit(surface->sub))
- return ;
+ /* If this surface is subsurface and subsurface is in synchronized mode,
+ * pending surface_state should be commit to cache, not current */
+ if (pepper_subsurface_commit(surface->sub))
+ return ;
- pepper_surface_commit(surface);
+ pepper_surface_commit(surface);
}
static void
surface_set_buffer_transform(struct wl_client *client,
- struct wl_resource *resource,
- int transform)
+ struct wl_resource *resource,
+ int transform)
{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
- if (transform < 0 || transform > WL_OUTPUT_TRANSFORM_FLIPPED_270)
- {
- wl_resource_post_error(resource, WL_SURFACE_ERROR_INVALID_TRANSFORM,
- "Invalid transform value : %d", transform);
- return;
- }
+ if (transform < 0 || transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) {
+ wl_resource_post_error(resource, WL_SURFACE_ERROR_INVALID_TRANSFORM,
+ "Invalid transform value : %d", transform);
+ return;
+ }
- surface->pending.transform = transform;
+ surface->pending.transform = transform;
}
static void
surface_set_buffer_scale(struct wl_client *client,
- struct wl_resource *resource,
- int32_t scale)
-{
- pepper_surface_t *surface = wl_resource_get_user_data(resource);
-
- if (scale < 1)
- {
- wl_resource_post_error(resource, WL_SURFACE_ERROR_INVALID_SCALE,
- "Invalid scale value (should be >= 1): %d", scale);
- return;
- }
-
- surface->pending.scale = scale;
-}
-
-static const struct wl_surface_interface surface_implementation =
-{
- surface_destroy,
- surface_attach,
- surface_damage,
- surface_frame,
- surface_set_opaque_region,
- surface_set_input_region,
- surface_commit,
- surface_set_buffer_transform,
- surface_set_buffer_scale
+ struct wl_resource *resource,
+ int32_t scale)
+{
+ pepper_surface_t *surface = wl_resource_get_user_data(resource);
+
+ if (scale < 1) {
+ wl_resource_post_error(resource, WL_SURFACE_ERROR_INVALID_SCALE,
+ "Invalid scale value (should be >= 1): %d", scale);
+ return;
+ }
+
+ surface->pending.scale = scale;
+}
+
+static const struct wl_surface_interface surface_implementation = {
+ surface_destroy,
+ surface_attach,
+ surface_damage,
+ surface_frame,
+ surface_set_opaque_region,
+ surface_set_input_region,
+ surface_commit,
+ surface_set_buffer_transform,
+ surface_set_buffer_scale
};
pepper_surface_t *
pepper_surface_create(pepper_compositor_t *compositor,
- struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id)
+ struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id)
{
- pepper_surface_t *surface = (pepper_surface_t *)pepper_object_alloc(PEPPER_OBJECT_SURFACE,
- sizeof(pepper_surface_t));
- PEPPER_CHECK(surface, goto error, "pepper_object_alloc() failed.\n");
+ pepper_surface_t *surface = (pepper_surface_t *)pepper_object_alloc(
+ PEPPER_OBJECT_SURFACE,
+ sizeof(pepper_surface_t));
+ PEPPER_CHECK(surface, goto error, "pepper_object_alloc() failed.\n");
- surface->compositor = compositor;
- surface->resource = wl_resource_create(client, &wl_surface_interface,
- wl_resource_get_version(resource), id);
- PEPPER_CHECK(surface->resource, goto error, "wl_resource_create() failed\n");
+ surface->compositor = compositor;
+ surface->resource = wl_resource_create(client, &wl_surface_interface,
+ wl_resource_get_version(resource), id);
+ PEPPER_CHECK(surface->resource, goto error, "wl_resource_create() failed\n");
- wl_resource_set_implementation(surface->resource, &surface_implementation, surface,
- surface_resource_destroy_handler);
+ wl_resource_set_implementation(surface->resource, &surface_implementation,
+ surface,
+ surface_resource_destroy_handler);
- surface->link.item = surface;
- pepper_list_insert(&compositor->surface_list, &surface->link);
- pepper_surface_state_init(&surface->pending);
+ surface->link.item = surface;
+ pepper_list_insert(&compositor->surface_list, &surface->link);
+ pepper_surface_state_init(&surface->pending);
- surface->buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL;
- surface->buffer.scale = 1;
+ surface->buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL;
+ surface->buffer.scale = 1;
- pixman_region32_init(&surface->damage_region);
- pixman_region32_init(&surface->opaque_region);
- pixman_region32_init_rect(&surface->input_region, INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
- surface->pickable = PEPPER_TRUE;
+ pixman_region32_init(&surface->damage_region);
+ pixman_region32_init(&surface->opaque_region);
+ pixman_region32_init_rect(&surface->input_region, INT32_MIN, INT32_MIN,
+ UINT32_MAX, UINT32_MAX);
+ surface->pickable = PEPPER_TRUE;
- wl_list_init(&surface->frame_callback_list);
- pepper_list_init(&surface->view_list);
- pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_SURFACE_ADD, surface);
+ wl_list_init(&surface->frame_callback_list);
+ pepper_list_init(&surface->view_list);
+ pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_SURFACE_ADD,
+ surface);
- return surface;
+ return surface;
error:
- if (surface)
- free(surface);
+ if (surface)
+ free(surface);
- return NULL;
+ return NULL;
}
void
pepper_surface_destroy(pepper_surface_t *surface)
{
- struct wl_resource *callback, *nc;
- pepper_view_t *view, *nv;
+ struct wl_resource *callback, *nc;
+ pepper_view_t *view, *nv;
- pepper_object_emit_event(&surface->compositor->base,
- PEPPER_EVENT_COMPOSITOR_SURFACE_REMOVE, surface);
- pepper_surface_state_fini(&surface->pending);
- pepper_object_fini(&surface->base);
+ pepper_object_emit_event(&surface->compositor->base,
+ PEPPER_EVENT_COMPOSITOR_SURFACE_REMOVE, surface);
+ pepper_surface_state_fini(&surface->pending);
+ pepper_object_fini(&surface->base);
- pepper_list_for_each_safe(view, nv, &surface->view_list, surface_link)
- pepper_view_set_surface(view, NULL);
+ pepper_list_for_each_safe(view, nv, &surface->view_list, surface_link)
+ pepper_view_set_surface(view, NULL);
- if (surface->buffer.buffer)
- {
- pepper_event_listener_remove(surface->buffer.destroy_listener);
+ if (surface->buffer.buffer) {
+ pepper_event_listener_remove(surface->buffer.destroy_listener);
- if (surface->buffer.has_ref)
- pepper_buffer_unreference(surface->buffer.buffer);
- }
+ if (surface->buffer.has_ref)
+ pepper_buffer_unreference(surface->buffer.buffer);
+ }
- pixman_region32_fini(&surface->damage_region);
- pixman_region32_fini(&surface->opaque_region);
- pixman_region32_fini(&surface->input_region);
+ pixman_region32_fini(&surface->damage_region);
+ pixman_region32_fini(&surface->opaque_region);
+ pixman_region32_fini(&surface->input_region);
- pepper_list_remove(&surface->link);
+ pepper_list_remove(&surface->link);
- wl_resource_for_each_safe(callback, nc, &surface->frame_callback_list)
- wl_resource_destroy(callback);
+ wl_resource_for_each_safe(callback, nc, &surface->frame_callback_list)
+ wl_resource_destroy(callback);
- if (surface->role)
- free(surface->role);
+ if (surface->role)
+ free(surface->role);
- free(surface);
+ free(surface);
}
static void
attach_surface_to_outputs(pepper_surface_t *surface)
{
- pepper_output_t *output;
+ pepper_output_t *output;
- pepper_list_for_each(output, &surface->compositor->output_list, link)
- {
- int w, h;
+ pepper_list_for_each(output, &surface->compositor->output_list, link) {
+ int w, h;
- output->backend->attach_surface(output->data, surface, &w, &h);
+ output->backend->attach_surface(output->data, surface, &w, &h);
- if (surface->buffer.buffer)
- {
- surface->buffer.buffer->w = w;
- surface->buffer.buffer->h = h;
- surface->buffer.buffer->attached = PEPPER_TRUE;
- }
- }
+ if (surface->buffer.buffer) {
+ surface->buffer.buffer->w = w;
+ surface->buffer.buffer->h = h;
+ surface->buffer.buffer->attached = PEPPER_TRUE;
+ }
+ }
}
void
-pepper_surface_commit_state(pepper_surface_t *surface, pepper_surface_state_t *state)
+pepper_surface_commit_state(pepper_surface_t *surface,
+ pepper_surface_state_t *state)
{
- pepper_view_t *view;
+ pepper_view_t *view;
- /* surface.attach(). */
- if (state->newly_attached)
- {
- if (surface->buffer.buffer)
- {
- pepper_event_listener_remove(surface->buffer.destroy_listener);
+ /* surface.attach(). */
+ if (state->newly_attached) {
+ if (surface->buffer.buffer) {
+ pepper_event_listener_remove(surface->buffer.destroy_listener);
- if (surface->buffer.has_ref)
- pepper_buffer_unreference(surface->buffer.buffer);
- }
+ if (surface->buffer.has_ref)
+ pepper_buffer_unreference(surface->buffer.buffer);
+ }
- if (state->buffer)
- {
- pepper_event_listener_remove(state->buffer_destroy_listener);
- pepper_buffer_reference(state->buffer);
- surface->buffer.has_ref = PEPPER_TRUE;
+ if (state->buffer) {
+ pepper_event_listener_remove(state->buffer_destroy_listener);
+ pepper_buffer_reference(state->buffer);
+ surface->buffer.has_ref = PEPPER_TRUE;
- surface->buffer.destroy_listener =
- pepper_object_add_event_listener(&state->buffer->base,
- PEPPER_EVENT_OBJECT_DESTROY, 0,
- surface_handle_buffer_destroy, surface);
- }
+ surface->buffer.destroy_listener =
+ pepper_object_add_event_listener(&state->buffer->base,
+ PEPPER_EVENT_OBJECT_DESTROY, 0,
+ surface_handle_buffer_destroy, surface);
+ }
- surface->buffer.buffer = state->buffer;
- surface->buffer.x += state->x;
- surface->buffer.y += state->y;
+ surface->buffer.buffer = state->buffer;
+ surface->buffer.x += state->x;
+ surface->buffer.y += state->y;
- state->newly_attached = PEPPER_FALSE;
- state->buffer = NULL;
+ state->newly_attached = PEPPER_FALSE;
+ state->buffer = NULL;
- /* Attach to all outputs. */
- attach_surface_to_outputs(surface);
- }
+ /* Attach to all outputs. */
+ attach_surface_to_outputs(surface);
+ }
- /* surface.set_buffer_transform(), surface.set_buffer_scale(). */
- surface->buffer.transform = state->transform;
- surface->buffer.scale = state->scale;
+ /* surface.set_buffer_transform(), surface.set_buffer_scale(). */
+ surface->buffer.transform = state->transform;
+ surface->buffer.scale = state->scale;
- surface_update_size(surface);
+ surface_update_size(surface);
- /* surface.frame(). */
- wl_list_insert_list(&surface->frame_callback_list, &state->frame_callback_list);
- wl_list_init(&state->frame_callback_list);
+ /* surface.frame(). */
+ wl_list_insert_list(&surface->frame_callback_list, &state->frame_callback_list);
+ wl_list_init(&state->frame_callback_list);
- /* surface.damage(). */
- pixman_region32_copy(&surface->damage_region, &state->damage_region);
- pixman_region32_clear(&state->damage_region);
+ /* surface.damage(). */
+ pixman_region32_copy(&surface->damage_region, &state->damage_region);
+ pixman_region32_clear(&state->damage_region);
- /* surface.set_opaque_region(), surface.set_input_region(). */
- pixman_region32_copy(&surface->opaque_region, &state->opaque_region);
+ /* surface.set_opaque_region(), surface.set_input_region(). */
+ pixman_region32_copy(&surface->opaque_region, &state->opaque_region);
- if (surface->pickable)
- pixman_region32_copy(&surface->input_region, &state->input_region);
+ if (surface->pickable)
+ pixman_region32_copy(&surface->input_region, &state->input_region);
- pepper_list_for_each(view, &surface->view_list, surface_link)
- {
- /* TODO: Option for enabling/disabling auto resize */
- pepper_view_resize(view, surface->w, surface->h);
- pepper_view_mark_dirty(view, PEPPER_VIEW_CONTENT_DIRTY);
- }
+ pepper_list_for_each(view, &surface->view_list, surface_link) {
+ /* TODO: Option for enabling/disabling auto resize */
+ pepper_view_resize(view, surface->w, surface->h);
+ pepper_view_mark_dirty(view, PEPPER_VIEW_CONTENT_DIRTY);
+ }
}
void
pepper_surface_commit(pepper_surface_t *surface)
{
- pepper_surface_commit_state(surface, &surface->pending);
+ pepper_surface_commit_state(surface, &surface->pending);
- pepper_object_emit_event(&surface->base, PEPPER_EVENT_SURFACE_COMMIT, NULL);
+ pepper_object_emit_event(&surface->base, PEPPER_EVENT_SURFACE_COMMIT, NULL);
}
void
-pepper_surface_send_frame_callback_done(pepper_surface_t *surface, uint32_t time)
+pepper_surface_send_frame_callback_done(pepper_surface_t *surface,
+ uint32_t time)
{
- struct wl_resource *callback, *next;
+ struct wl_resource *callback, *next;
- wl_resource_for_each_safe(callback, next, &surface->frame_callback_list)
- {
- wl_callback_send_done(callback, time);
- wl_resource_destroy(callback);
- }
+ wl_resource_for_each_safe(callback, next, &surface->frame_callback_list) {
+ wl_callback_send_done(callback, time);
+ wl_resource_destroy(callback);
+ }
}
/**
PEPPER_API struct wl_resource *
pepper_surface_get_resource(pepper_surface_t *surface)
{
- return surface->resource;
+ return surface->resource;
}
/**
PEPPER_API pepper_compositor_t *
pepper_surface_get_compositor(pepper_surface_t *surface)
{
- return surface->compositor;
+ return surface->compositor;
}
/**
PEPPER_API const char *
pepper_surface_get_role(pepper_surface_t *surface)
{
- return surface->role;
+ return surface->role;
}
/**
PEPPER_API pepper_bool_t
pepper_surface_set_role(pepper_surface_t *surface, const char *role)
{
- if (surface->role)
- return PEPPER_FALSE;
+ if (surface->role)
+ return PEPPER_FALSE;
- surface->role = strdup(role);
- if (!surface->role)
- return PEPPER_FALSE;
+ surface->role = strdup(role);
+ if (!surface->role)
+ return PEPPER_FALSE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
/**
PEPPER_API pepper_buffer_t *
pepper_surface_get_buffer(pepper_surface_t *surface)
{
- return surface->buffer.buffer;
+ return surface->buffer.buffer;
}
/**
* @param y pointer to receive y coordinate of the offset
*/
PEPPER_API void
-pepper_surface_get_buffer_offset(pepper_surface_t *surface, int32_t *x, int32_t *y)
+pepper_surface_get_buffer_offset(pepper_surface_t *surface, int32_t *x,
+ int32_t *y)
{
- if (x)
- *x = surface->buffer.x;
+ if (x)
+ *x = surface->buffer.x;
- if (y)
- *y = surface->buffer.y;
+ if (y)
+ *y = surface->buffer.y;
}
/**
PEPPER_API int32_t
pepper_surface_get_buffer_scale(pepper_surface_t *surface)
{
- return surface->buffer.scale;
+ return surface->buffer.scale;
}
/**
PEPPER_API int32_t
pepper_surface_get_buffer_transform(pepper_surface_t *surface)
{
- return surface->buffer.transform;
+ return surface->buffer.transform;
}
/**
PEPPER_API pixman_region32_t *
pepper_surface_get_damage_region(pepper_surface_t *surface)
{
- return &surface->damage_region;
+ return &surface->damage_region;
}
PEPPER_API pixman_region32_t *
pepper_surface_get_opaque_region(pepper_surface_t *surface)
{
- return &surface->opaque_region;
+ return &surface->opaque_region;
}
/**
PEPPER_API pixman_region32_t *
pepper_surface_get_input_region(pepper_surface_t *surface)
{
- return &surface->input_region;
+ return &surface->input_region;
}
/**
PEPPER_API void
pepper_surface_get_size(pepper_surface_t *surface, int *w, int *h)
{
- if (w)
- *w = surface->w;
+ if (w)
+ *w = surface->w;
- if (h)
- *h = surface->h;
+ if (h)
+ *h = surface->h;
}
/**
PEPPER_API void
pepper_surface_send_enter(pepper_surface_t *surface, pepper_output_t *output)
{
- struct wl_resource *resource;
- struct wl_client *client = wl_resource_get_client(surface->resource);
+ struct wl_resource *resource;
+ struct wl_client *client = wl_resource_get_client(surface->resource);
- wl_resource_for_each(resource, &output->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_surface_send_enter(surface->resource, resource);
- }
+ wl_resource_for_each(resource, &output->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_surface_send_enter(surface->resource, resource);
+ }
}
/**
PEPPER_API void
pepper_surface_send_leave(pepper_surface_t *surface, pepper_output_t *output)
{
- struct wl_resource *resource;
- struct wl_client *client = wl_resource_get_client(surface->resource);
+ struct wl_resource *resource;
+ struct wl_client *client = wl_resource_get_client(surface->resource);
- wl_resource_for_each(resource, &output->resource_list)
- {
- if (wl_resource_get_client(resource) == client)
- wl_surface_send_leave(surface->resource, resource);
- }
+ wl_resource_for_each(resource, &output->resource_list) {
+ if (wl_resource_get_client(resource) == client)
+ wl_surface_send_leave(surface->resource, resource);
+ }
}
void
pepper_surface_flush_damage(pepper_surface_t *surface)
{
- pepper_view_t *view;
- pepper_output_t *output;
- pepper_bool_t release_buffer = PEPPER_TRUE;
+ pepper_view_t *view;
+ pepper_output_t *output;
+ pepper_bool_t release_buffer = PEPPER_TRUE;
- if (!pixman_region32_not_empty(&surface->damage_region))
- return;
+ if (!pixman_region32_not_empty(&surface->damage_region))
+ return;
- pepper_list_for_each(view, &surface->view_list, surface_link)
- pepper_view_surface_damage(view);
+ pepper_list_for_each(view, &surface->view_list, surface_link)
+ pepper_view_surface_damage(view);
- pepper_list_for_each(output, &surface->compositor->output_list, link)
- {
- pepper_bool_t keep_buffer;
+ pepper_list_for_each(output, &surface->compositor->output_list, link) {
+ pepper_bool_t keep_buffer;
- output->backend->flush_surface_damage(output->data, surface, &keep_buffer);
+ output->backend->flush_surface_damage(output->data, surface, &keep_buffer);
- if (keep_buffer)
- release_buffer = PEPPER_FALSE;
- }
+ if (keep_buffer)
+ release_buffer = PEPPER_FALSE;
+ }
- pixman_region32_clear(&surface->damage_region);
+ pixman_region32_clear(&surface->damage_region);
- if (surface->buffer.buffer && release_buffer)
- {
- pepper_buffer_unreference(surface->buffer.buffer);
- surface->buffer.has_ref = PEPPER_FALSE;
- }
+ if (surface->buffer.buffer && release_buffer) {
+ pepper_buffer_unreference(surface->buffer.buffer);
+ surface->buffer.has_ref = PEPPER_FALSE;
+ }
}
static void
touch_release(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
-static const struct wl_touch_interface touch_impl =
-{
- touch_release,
+static const struct wl_touch_interface touch_impl = {
+ touch_release,
};
static pepper_touch_point_t *
get_touch_point(pepper_touch_t *touch, uint32_t id)
{
- pepper_touch_point_t *point;
+ pepper_touch_point_t *point;
- pepper_list_for_each(point, &touch->point_list, link)
- {
- if (point->id == id)
- return point;
- }
+ pepper_list_for_each(point, &touch->point_list, link) {
+ if (point->id == id)
+ return point;
+ }
- return NULL;
+ return NULL;
}
static void
touch_point_set_focus(pepper_touch_point_t *point, pepper_view_t *focus);
static void
-touch_point_handle_focus_destroy(pepper_event_listener_t *listener, pepper_object_t *surface,
- uint32_t id, void *info, void *data)
+touch_point_handle_focus_destroy(pepper_event_listener_t *listener,
+ pepper_object_t *surface,
+ uint32_t id, void *info, void *data)
{
- pepper_touch_point_t *point = data;
- touch_point_set_focus(point, NULL);
+ pepper_touch_point_t *point = data;
+ touch_point_set_focus(point, NULL);
}
static void
touch_point_set_focus(pepper_touch_point_t *point, pepper_view_t *focus)
{
- if (point->focus == focus)
- return;
-
- if (point->focus)
- {
- pepper_event_listener_remove(point->focus_destroy_listener);
- pepper_object_emit_event(&point->touch->base, PEPPER_EVENT_FOCUS_LEAVE, point->focus);
- pepper_object_emit_event(&point->focus->base, PEPPER_EVENT_FOCUS_LEAVE, point->focus);
- }
-
- point->focus = focus;
-
- if (focus)
- {
- point->focus_serial = wl_display_next_serial(point->touch->seat->compositor->display);
-
- point->focus_destroy_listener =
- pepper_object_add_event_listener(&focus->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
- touch_point_handle_focus_destroy, point);
-
- pepper_object_emit_event(&point->touch->base, PEPPER_EVENT_FOCUS_ENTER, focus);
- pepper_object_emit_event(&focus->base, PEPPER_EVENT_FOCUS_ENTER, focus);
- }
+ if (point->focus == focus)
+ return;
+
+ if (point->focus) {
+ pepper_event_listener_remove(point->focus_destroy_listener);
+ pepper_object_emit_event(&point->touch->base, PEPPER_EVENT_FOCUS_LEAVE,
+ point->focus);
+ pepper_object_emit_event(&point->focus->base, PEPPER_EVENT_FOCUS_LEAVE,
+ point->focus);
+ }
+
+ point->focus = focus;
+
+ if (focus) {
+ point->focus_serial = wl_display_next_serial(
+ point->touch->seat->compositor->display);
+
+ point->focus_destroy_listener =
+ pepper_object_add_event_listener(&focus->base, PEPPER_EVENT_OBJECT_DESTROY, 0,
+ touch_point_handle_focus_destroy, point);
+
+ pepper_object_emit_event(&point->touch->base, PEPPER_EVENT_FOCUS_ENTER, focus);
+ pepper_object_emit_event(&focus->base, PEPPER_EVENT_FOCUS_ENTER, focus);
+ }
}
void
-pepper_touch_handle_event(pepper_touch_t *touch, uint32_t id, pepper_input_event_t *event)
+pepper_touch_handle_event(pepper_touch_t *touch, uint32_t id,
+ pepper_input_event_t *event)
{
- switch (id)
- {
- case PEPPER_EVENT_TOUCH_DOWN:
- {
- if (touch->grab)
- touch->grab->down(touch, touch->data, event->time, event->slot, event->x, event->y);
- }
- break;
- case PEPPER_EVENT_TOUCH_UP:
- {
- if (touch->grab)
- touch->grab->up(touch, touch->data, event->time, event->slot);
- }
- break;
- case PEPPER_EVENT_TOUCH_MOTION:
- {
- pepper_touch_point_t *point = get_touch_point(touch, event->slot);
-
- point->x = event->x;
- point->y = event->y;
-
- if (touch->grab)
- touch->grab->motion(touch, touch->data, event->time, event->slot, event->x, event->y);
- }
- break;
- case PEPPER_EVENT_TOUCH_FRAME:
- {
- if (touch->grab)
- touch->grab->frame(touch, touch->data);
- }
- break;
- case PEPPER_EVENT_TOUCH_CANCEL:
- {
- if (touch->grab)
- touch->grab->cancel(touch, touch->data);
- }
- break;
- }
-
- pepper_object_emit_event(&touch->base, id, event);
+ switch (id) {
+ case PEPPER_EVENT_TOUCH_DOWN: {
+ if (touch->grab)
+ touch->grab->down(touch, touch->data, event->time, event->slot, event->x,
+ event->y);
+ }
+ break;
+ case PEPPER_EVENT_TOUCH_UP: {
+ if (touch->grab)
+ touch->grab->up(touch, touch->data, event->time, event->slot);
+ }
+ break;
+ case PEPPER_EVENT_TOUCH_MOTION: {
+ pepper_touch_point_t *point = get_touch_point(touch, event->slot);
+
+ point->x = event->x;
+ point->y = event->y;
+
+ if (touch->grab)
+ touch->grab->motion(touch, touch->data, event->time, event->slot, event->x,
+ event->y);
+ }
+ break;
+ case PEPPER_EVENT_TOUCH_FRAME: {
+ if (touch->grab)
+ touch->grab->frame(touch, touch->data);
+ }
+ break;
+ case PEPPER_EVENT_TOUCH_CANCEL: {
+ if (touch->grab)
+ touch->grab->cancel(touch, touch->data);
+ }
+ break;
+ }
+
+ pepper_object_emit_event(&touch->base, id, event);
}
pepper_touch_t *
pepper_touch_create(pepper_seat_t *seat)
{
- pepper_touch_t *touch =
- (pepper_touch_t *)pepper_object_alloc(PEPPER_OBJECT_TOUCH, sizeof(pepper_touch_t));
+ pepper_touch_t *touch =
+ (pepper_touch_t *)pepper_object_alloc(PEPPER_OBJECT_TOUCH,
+ sizeof(pepper_touch_t));
- PEPPER_CHECK(touch, return NULL, "pepper_object_alloc() failed.\n");
+ PEPPER_CHECK(touch, return NULL, "pepper_object_alloc() failed.\n");
- touch->seat = seat;
- wl_list_init(&touch->resource_list);
- pepper_list_init(&touch->point_list);
+ touch->seat = seat;
+ wl_list_init(&touch->resource_list);
+ pepper_list_init(&touch->point_list);
- return touch;
+ return touch;
}
void
pepper_touch_destroy(pepper_touch_t *touch)
{
- pepper_touch_point_t *point, *tmp;
+ pepper_touch_point_t *point, *tmp;
- PEPPER_CHECK(touch, return, "pepper_touch_destroy() failed.\n");
+ PEPPER_CHECK(touch, return, "pepper_touch_destroy() failed.\n");
- pepper_list_for_each_safe(point, tmp, &touch->point_list, link)
- {
- if (point->focus_destroy_listener)
- pepper_event_listener_remove(point->focus_destroy_listener);
+ pepper_list_for_each_safe(point, tmp, &touch->point_list, link) {
+ if (point->focus_destroy_listener)
+ pepper_event_listener_remove(point->focus_destroy_listener);
- free(point);
- }
+ free(point);
+ }
- if (touch->grab)
- touch->grab->cancel(touch, touch->data);
+ if (touch->grab)
+ touch->grab->cancel(touch, touch->data);
- free(touch);
+ free(touch);
}
static void
unbind_resource(struct wl_resource *resource)
{
- wl_list_remove(wl_resource_get_link(resource));
+ wl_list_remove(wl_resource_get_link(resource));
}
void
-pepper_touch_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id)
+pepper_touch_bind_resource(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id)
{
- pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
- pepper_touch_t *touch = seat->touch;
- struct wl_resource *res;
+ pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
+ pepper_touch_t *touch = seat->touch;
+ struct wl_resource *res;
- if (!touch)
- return;
+ if (!touch)
+ return;
- res = wl_resource_create(client, &wl_touch_interface, wl_resource_get_version(resource), id);
- if (!res)
- {
- wl_client_post_no_memory(client);
- return;
- }
+ res = wl_resource_create(client, &wl_touch_interface,
+ wl_resource_get_version(resource), id);
+ if (!res) {
+ wl_client_post_no_memory(client);
+ return;
+ }
- wl_list_insert(&touch->resource_list, wl_resource_get_link(res));
- wl_resource_set_implementation(res, &touch_impl, touch, unbind_resource);
+ wl_list_insert(&touch->resource_list, wl_resource_get_link(res));
+ wl_resource_set_implementation(res, &touch_impl, touch, unbind_resource);
- /* TODO: Send down for newly bound resources. */
+ /* TODO: Send down for newly bound resources. */
}
/**
PEPPER_API struct wl_list *
pepper_touch_get_resource_list(pepper_touch_t *touch)
{
- return &touch->resource_list;
+ return &touch->resource_list;
}
/**
PEPPER_API pepper_compositor_t *
pepper_touch_get_compositor(pepper_touch_t *touch)
{
- return touch->seat->compositor;
+ return touch->seat->compositor;
}
/**
PEPPER_API pepper_seat_t *
pepper_touch_get_seat(pepper_touch_t *touch)
{
- return touch->seat;
+ return touch->seat;
}
/**
PEPPER_API void
pepper_touch_add_point(pepper_touch_t *touch, uint32_t id, double x, double y)
{
- pepper_touch_point_t *point = get_touch_point(touch, id);
- PEPPER_CHECK(!point, return, "Touch point %d already exist.\n", id);
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ PEPPER_CHECK(!point, return, "Touch point %d already exist.\n", id);
- point = calloc(1, sizeof(pepper_touch_point_t));
- PEPPER_CHECK(point, return, "malloc() failed.\n");
+ point = calloc(1, sizeof(pepper_touch_point_t));
+ PEPPER_CHECK(point, return, "malloc() failed.\n");
- point->touch = touch;
- point->id = id;
- point->x = x;
- point->y = y;
+ point->touch = touch;
+ point->id = id;
+ point->x = x;
+ point->y = y;
- pepper_list_insert(touch->point_list.prev, &point->link);
+ pepper_list_insert(touch->point_list.prev, &point->link);
}
/**
PEPPER_API void
pepper_touch_remove_point(pepper_touch_t *touch, uint32_t id)
{
- pepper_touch_point_t *point = get_touch_point(touch, id);
- PEPPER_CHECK(point, return, "Touch point %d does not exist.\n", id);
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ PEPPER_CHECK(point, return, "Touch point %d does not exist.\n", id);
- touch_point_set_focus(point, NULL);
- pepper_list_remove(&point->link);
- free(point);
+ touch_point_set_focus(point, NULL);
+ pepper_list_remove(&point->link);
+ free(point);
}
/**
PEPPER_API void
pepper_touch_set_focus(pepper_touch_t *touch, uint32_t id, pepper_view_t *focus)
{
- pepper_touch_point_t *point = get_touch_point(touch, id);
-
- if (focus)
- {
- if (!point)
- pepper_touch_add_point(touch, id, 0, 0);
-
- touch_point_set_focus(get_touch_point(touch, id), focus);
- }
- else
- {
- if (point)
- pepper_touch_remove_point(touch, id);
- }
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+
+ if (focus) {
+ if (!point)
+ pepper_touch_add_point(touch, id, 0, 0);
+
+ touch_point_set_focus(get_touch_point(touch, id), focus);
+ } else {
+ if (point)
+ pepper_touch_remove_point(touch, id);
+ }
}
/**
PEPPER_API pepper_view_t *
pepper_touch_get_focus(pepper_touch_t *touch, uint32_t id)
{
- pepper_touch_point_t *point = get_touch_point(touch, id);
- PEPPER_CHECK(point, return NULL, "Touch point %d does not exist.\n", id);
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ PEPPER_CHECK(point, return NULL, "Touch point %d does not exist.\n", id);
- return point->focus;
+ return point->focus;
}
/**
* @return PEPPER_TRUE on success, PEPPER_FALSE otherwise
*/
PEPPER_API pepper_bool_t
-pepper_touch_get_position(pepper_touch_t *touch, uint32_t id, double *x, double *y)
+pepper_touch_get_position(pepper_touch_t *touch, uint32_t id, double *x,
+ double *y)
{
- pepper_touch_point_t *point = get_touch_point(touch, id);
- PEPPER_CHECK(point, return PEPPER_FALSE, "Touch point %d does not exist.\n", id);
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ PEPPER_CHECK(point, return PEPPER_FALSE, "Touch point %d does not exist.\n",
+ id);
- if (x)
- *x = point->x;
+ if (x)
+ *x = point->x;
- if (y)
- *y = point->y;
+ if (y)
+ *y = point->y;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
/**
* @return PEPPER_TRUE on success, PEPPER_FALSE otherwise
*/
PEPPER_API pepper_bool_t
-pepper_touch_set_position(pepper_touch_t *touch, uint32_t id, double x, double y)
+pepper_touch_set_position(pepper_touch_t *touch, uint32_t id, double x,
+ double y)
{
- pepper_touch_point_t *point = get_touch_point(touch, id);
- PEPPER_CHECK(point, return PEPPER_FALSE, "Touch point %d does not exist.\n", id);
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ PEPPER_CHECK(point, return PEPPER_FALSE, "Touch point %d does not exist.\n",
+ id);
- point->x = x;
- point->y = y;
+ point->x = x;
+ point->y = y;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
/**
*/
PEPPER_API void
pepper_touch_send_down(pepper_touch_t *touch, pepper_view_t *view,
- uint32_t time, uint32_t id, double x, double y)
+ uint32_t time, uint32_t id, double x, double y)
{
- struct wl_resource *resource;
- wl_fixed_t fx = wl_fixed_from_double(x);
- wl_fixed_t fy = wl_fixed_from_double(y);
- pepper_touch_point_t *point = get_touch_point(touch, id);
- pepper_input_event_t event;
-
- if (!point || !view || !view->surface || !view->surface->resource)
- return;
-
- wl_resource_for_each(resource, &touch->resource_list)
- {
- struct wl_resource *surface_resource = view->surface->resource;
-
- if (wl_resource_get_client(resource) == wl_resource_get_client(surface_resource))
- wl_touch_send_down(resource, point->focus_serial, time, surface_resource, id, fx, fy);
- }
-
- event.time = time;
- event.x = x;
- event.y = y;
- pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_DOWN, &event);
+ struct wl_resource *resource;
+ wl_fixed_t fx = wl_fixed_from_double(x);
+ wl_fixed_t fy = wl_fixed_from_double(y);
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ pepper_input_event_t event;
+
+ if (!point || !view || !view->surface || !view->surface->resource)
+ return;
+
+ wl_resource_for_each(resource, &touch->resource_list) {
+ struct wl_resource *surface_resource = view->surface->resource;
+
+ if (wl_resource_get_client(resource) == wl_resource_get_client(
+ surface_resource))
+ wl_touch_send_down(resource, point->focus_serial, time, surface_resource, id,
+ fx, fy);
+ }
+
+ event.time = time;
+ event.x = x;
+ event.y = y;
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_DOWN, &event);
}
/**
* @param id touch point id
*/
PEPPER_API void
-pepper_touch_send_up(pepper_touch_t *touch, pepper_view_t *view, uint32_t time, uint32_t id)
+pepper_touch_send_up(pepper_touch_t *touch, pepper_view_t *view, uint32_t time,
+ uint32_t id)
{
- struct wl_resource *resource;
- uint32_t serial;
- pepper_touch_point_t *point = get_touch_point(touch, id);
- pepper_input_event_t event;
+ struct wl_resource *resource;
+ uint32_t serial;
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ pepper_input_event_t event;
- if (!point || !view || !view->surface || !view->surface->resource)
- return;
+ if (!point || !view || !view->surface || !view->surface->resource)
+ return;
- serial = wl_display_next_serial(touch->seat->compositor->display);
+ serial = wl_display_next_serial(touch->seat->compositor->display);
- wl_resource_for_each(resource, &touch->resource_list)
- {
- struct wl_resource *surface_resource = view->surface->resource;
+ wl_resource_for_each(resource, &touch->resource_list) {
+ struct wl_resource *surface_resource = view->surface->resource;
- if (wl_resource_get_client(resource) == wl_resource_get_client(surface_resource))
- wl_touch_send_up(resource, serial, time, id);
- }
+ if (wl_resource_get_client(resource) == wl_resource_get_client(
+ surface_resource))
+ wl_touch_send_up(resource, serial, time, id);
+ }
- event.time = time;
- pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_UP, &event);
+ event.time = time;
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_UP, &event);
}
/**
* @param y y coordinate in global space
*/
PEPPER_API void
-pepper_touch_send_motion(pepper_touch_t *touch, pepper_view_t *view, uint32_t time, uint32_t id, double x, double y)
+pepper_touch_send_motion(pepper_touch_t *touch, pepper_view_t *view,
+ uint32_t time, uint32_t id, double x, double y)
{
- struct wl_resource *resource;
- wl_fixed_t fx = wl_fixed_from_double(x);
- wl_fixed_t fy = wl_fixed_from_double(y);
- pepper_touch_point_t *point = get_touch_point(touch, id);
- pepper_input_event_t event;
+ struct wl_resource *resource;
+ wl_fixed_t fx = wl_fixed_from_double(x);
+ wl_fixed_t fy = wl_fixed_from_double(y);
+ pepper_touch_point_t *point = get_touch_point(touch, id);
+ pepper_input_event_t event;
- if (!point || !view || !view->surface || !view->surface->resource)
- return;
+ if (!point || !view || !view->surface || !view->surface->resource)
+ return;
- wl_resource_for_each(resource, &touch->resource_list)
- {
- struct wl_resource *surface_resource = view->surface->resource;
+ wl_resource_for_each(resource, &touch->resource_list) {
+ struct wl_resource *surface_resource = view->surface->resource;
- if (wl_resource_get_client(resource) == wl_resource_get_client(surface_resource))
- wl_touch_send_motion(resource, time, id, fx, fy);
- }
+ if (wl_resource_get_client(resource) == wl_resource_get_client(
+ surface_resource))
+ wl_touch_send_motion(resource, time, id, fx, fy);
+ }
- event.time = time;
- event.x = x;
- event.y = y;
- pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_MOTION, &event);
+ event.time = time;
+ event.x = x;
+ event.y = y;
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_MOTION, &event);
}
/**
PEPPER_API void
pepper_touch_send_frame(pepper_touch_t *touch, pepper_view_t *view)
{
- struct wl_resource *resource;
+ struct wl_resource *resource;
- wl_resource_for_each(resource, &touch->resource_list)
- wl_touch_send_frame(resource);
+ wl_resource_for_each(resource, &touch->resource_list)
+ wl_touch_send_frame(resource);
- pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_FRAME, NULL);
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_FRAME, NULL);
}
/**
PEPPER_API void
pepper_touch_send_cancel(pepper_touch_t *touch, pepper_view_t *view)
{
- struct wl_resource *resource;
+ struct wl_resource *resource;
- wl_resource_for_each(resource, &touch->resource_list)
- wl_touch_send_cancel(resource);
+ wl_resource_for_each(resource, &touch->resource_list)
+ wl_touch_send_cancel(resource);
- pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_CANCEL, NULL);
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_TOUCH_CANCEL, NULL);
}
/**
* @param data user data to be passed to grab functions
*/
PEPPER_API void
-pepper_touch_set_grab(pepper_touch_t *touch, const pepper_touch_grab_t *grab, void *data)
+pepper_touch_set_grab(pepper_touch_t *touch, const pepper_touch_grab_t *grab,
+ void *data)
{
- touch->grab = grab;
- touch->data = data;
+ touch->grab = grab;
+ touch->data = data;
}
/**
PEPPER_API const pepper_touch_grab_t *
pepper_touch_get_grab(pepper_touch_t *touch)
{
- return touch->grab;
+ return touch->grab;
}
/**
PEPPER_API void *
pepper_touch_get_grab_data(pepper_touch_t *touch)
{
- return touch->data;
+ return touch->data;
}
static int
set_cloexec_or_close(int fd)
{
- long flags;
+ long flags;
- if (fd == -1)
- return -1;
+ if (fd == -1)
+ return -1;
- flags = fcntl(fd, F_GETFD);
- if (flags == -1)
- goto err;
+ flags = fcntl(fd, F_GETFD);
+ if (flags == -1)
+ goto err;
- if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
- goto err;
+ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+ goto err;
- return fd;
+ return fd;
err:
- close(fd);
- return -1;
+ close(fd);
+ return -1;
}
static int
create_tmpfile_cloexec(char *tmpname)
{
- int fd;
+ int fd;
#ifdef HAVE_MKOSTEMP
- fd = mkostemp(tmpname, O_CLOEXEC);
- if (fd >= 0)
- unlink(tmpname);
+ fd = mkostemp(tmpname, O_CLOEXEC);
+ if (fd >= 0)
+ unlink(tmpname);
#else
- fd = mkstemp(tmpname);
- if (fd >= 0) {
- fd = set_cloexec_or_close(fd);
- unlink(tmpname);
- }
+ fd = mkstemp(tmpname);
+ if (fd >= 0) {
+ fd = set_cloexec_or_close(fd);
+ unlink(tmpname);
+ }
#endif
- return fd;
+ return fd;
}
PEPPER_API int
pepper_create_anonymous_file(off_t size)
{
- static const char template[] = "/pepper-shared-XXXXXX";
- const char *path;
- char *name;
- int fd;
- int ret;
+ static const char template[] = "/pepper-shared-XXXXXX";
+ const char *path;
+ char *name;
+ int fd;
+ int ret;
- path = getenv("XDG_RUNTIME_DIR");
- if (!path) {
- errno = ENOENT;
- return -1;
- }
+ path = getenv("XDG_RUNTIME_DIR");
+ if (!path) {
+ errno = ENOENT;
+ return -1;
+ }
- name = malloc(strlen(path) + sizeof(template));
- if (!name)
- return -1;
+ name = malloc(strlen(path) + sizeof(template));
+ if (!name)
+ return -1;
- strcpy(name, path);
- strcat(name, template);
+ strcpy(name, path);
+ strcat(name, template);
- fd = create_tmpfile_cloexec(name);
+ fd = create_tmpfile_cloexec(name);
- free(name);
+ free(name);
- if (fd < 0)
- return -1;
+ if (fd < 0)
+ return -1;
#ifdef HAVE_POSIX_FALLOCATE
- ret = posix_fallocate(fd, 0, size);
- if (ret != 0) {
- close(fd);
- errno = ret;
- return -1;
- }
+ ret = posix_fallocate(fd, 0, size);
+ if (ret != 0) {
+ close(fd);
+ errno = ret;
+ return -1;
+ }
#else
- ret = ftruncate(fd, size);
- if (ret < 0) {
- close(fd);
- return -1;
- }
+ ret = ftruncate(fd, size);
+ if (ret < 0) {
+ close(fd);
+ return -1;
+ }
#endif
- return fd;
+ return fd;
}
static void __attribute__ ((constructor))
before_main(void)
{
- pepper_log_file = stdout;
+ pepper_log_file = stdout;
}
static int
pepper_print_timestamp(void)
{
- struct timeval tv;
- struct tm *brokendown_time;
- char string[128];
+ struct timeval tv;
+ struct tm *brokendown_time;
+ char string[128];
- gettimeofday(&tv, NULL);
+ gettimeofday(&tv, NULL);
- brokendown_time = localtime(&tv.tv_sec);
- if (brokendown_time == NULL)
- return fprintf(pepper_log_file, "[(NULL)localtime] ");
+ brokendown_time = localtime(&tv.tv_sec);
+ if (brokendown_time == NULL)
+ return fprintf(pepper_log_file, "[(NULL)localtime] ");
- if (brokendown_time->tm_mday != cached_tm_mday)
- {
- strftime(string, sizeof string, "%Y-%m-%d %Z", brokendown_time);
- fprintf(pepper_log_file, "Date: %s\n", string);
+ if (brokendown_time->tm_mday != cached_tm_mday) {
+ strftime(string, sizeof string, "%Y-%m-%d %Z", brokendown_time);
+ fprintf(pepper_log_file, "Date: %s\n", string);
- cached_tm_mday = brokendown_time->tm_mday;
- }
+ cached_tm_mday = brokendown_time->tm_mday;
+ }
- strftime(string, sizeof string, "%H:%M:%S", brokendown_time);
+ strftime(string, sizeof string, "%H:%M:%S", brokendown_time);
- return fprintf(pepper_log_file, "[%s.%03li] ", string, tv.tv_usec/1000);
+ return fprintf(pepper_log_file, "[%s.%03li] ", string, tv.tv_usec / 1000);
}
static int
-pepper_print_domain(const char* log_domain)
+pepper_print_domain(const char *log_domain)
{
- if (log_domain == NULL)
- return fprintf(pepper_log_file, "UNKNOWN: ");
- else
- return fprintf(pepper_log_file, "%s: ", log_domain);
+ if (log_domain == NULL)
+ return fprintf(pepper_log_file, "UNKNOWN: ");
+ else
+ return fprintf(pepper_log_file, "%s: ", log_domain);
}
static int
pepper_vlog(const char *format, va_list ap)
{
- return vfprintf(pepper_log_file, format, ap);
+ return vfprintf(pepper_log_file, format, ap);
}
PEPPER_API int
-pepper_log(const char* domain, int level, const char *format, ...)
+pepper_log(const char *domain, int level, const char *format, ...)
{
- int l;
- va_list argp;
+ int l;
+ va_list argp;
- if (level > pepper_log_verbosity || level < 0)
- return 0;
+ if (level > pepper_log_verbosity || level < 0)
+ return 0;
- l = pepper_print_timestamp();
- l += pepper_print_domain(domain);
+ l = pepper_print_timestamp();
+ l += pepper_print_domain(domain);
- va_start(argp, format);
- l += pepper_vlog(format, argp);
- va_end(argp);
+ va_start(argp, format);
+ l += pepper_vlog(format, argp);
+ va_end(argp);
- return l;
+ return l;
}
#include "pepper-utils.h"
#include "pepper-utils.h"
-struct pepper_map_entry
-{
- const void *key;
- void *data;
- pepper_free_func_t free_func;
- pepper_map_entry_t *next;
+struct pepper_map_entry {
+ const void *key;
+ void *data;
+ pepper_free_func_t free_func;
+ pepper_map_entry_t *next;
};
static inline int
get_bucket_index(pepper_map_t *map, const void *key)
{
- int key_length = 0;
- int hash;
+ int key_length = 0;
+ int hash;
- if (map->key_length_func)
- key_length = map->key_length_func(key);
+ if (map->key_length_func)
+ key_length = map->key_length_func(key);
- hash = map->hash_func(key, key_length);
- return hash & map->bucket_mask;
+ hash = map->hash_func(key, key_length);
+ return hash & map->bucket_mask;
}
static inline pepper_map_entry_t **
get_bucket(pepper_map_t *map, const void *key)
{
- return &map->buckets[get_bucket_index(map, key)];
+ return &map->buckets[get_bucket_index(map, key)];
}
PEPPER_API void
pepper_map_init(pepper_map_t *map,
- int bucket_bits,
- pepper_hash_func_t hash_func,
- pepper_key_length_func_t key_length_func,
- pepper_key_compare_func_t key_compare_func,
- void *buckets)
+ int bucket_bits,
+ pepper_hash_func_t hash_func,
+ pepper_key_length_func_t key_length_func,
+ pepper_key_compare_func_t key_compare_func,
+ void *buckets)
{
- map->hash_func = hash_func;
- map->key_length_func = key_length_func;
- map->key_compare_func = key_compare_func;
+ map->hash_func = hash_func;
+ map->key_length_func = key_length_func;
+ map->key_compare_func = key_compare_func;
- map->bucket_bits = bucket_bits;
- map->bucket_size = 1 << bucket_bits;
- map->bucket_mask = map->bucket_size - 1;
+ map->bucket_bits = bucket_bits;
+ map->bucket_size = 1 << bucket_bits;
+ map->bucket_mask = map->bucket_size - 1;
- map->buckets = buckets;
+ map->buckets = buckets;
}
static int
int32_hash(const void *key, int key_length)
{
- return pepper_hash32((uint32_t)key);
+ return pepper_hash32((uint32_t)key);
}
static int
int32_key_compare(const void *key0, int key0_length,
- const void *key1, int key1_length)
+ const void *key1, int key1_length)
{
- return (int)(key0 - key1);
+ return (int)(key0 - key1);
}
PEPPER_API void
pepper_map_int32_init(pepper_map_t *map, int bucket_bits, void *buckets)
{
- pepper_map_init(map, bucket_bits, int32_hash, NULL, int32_key_compare, buckets);
+ pepper_map_init(map, bucket_bits, int32_hash, NULL, int32_key_compare, buckets);
}
static int
int64_hash(const void *key, int key_length)
{
- return pepper_hash64((uint64_t)key);
+ return pepper_hash64((uint64_t)key);
}
static int
int64_key_compare(const void *key0, int key0_length,
- const void *key1, int key1_length)
+ const void *key1, int key1_length)
{
- return (int)(key0 - key1);
+ return (int)(key0 - key1);
}
PEPPER_API void
pepper_map_int64_init(pepper_map_t *map, int bucket_bits, void *buckets)
{
- pepper_map_init(map, bucket_bits, int64_hash, NULL, int64_key_compare, buckets);
+ pepper_map_init(map, bucket_bits, int64_hash, NULL, int64_key_compare, buckets);
}
PEPPER_API void
pepper_map_pointer_init(pepper_map_t *map, int bucket_bits, void *buckets)
{
#if INTPTR_MAX == INT32_MAX
- pepper_map_init(map, bucket_bits, int32_hash, NULL, int32_key_compare, buckets);
+ pepper_map_init(map, bucket_bits, int32_hash, NULL, int32_key_compare, buckets);
#elif INTPTR_MAX == INT64_MAX
- pepper_map_init(map, bucket_bits, int64_hash, NULL, int64_key_compare, buckets);
+ pepper_map_init(map, bucket_bits, int64_hash, NULL, int64_key_compare, buckets);
#else
- #error "Not 32 or 64bit system"
+#error "Not 32 or 64bit system"
#endif
}
PEPPER_API void
pepper_map_fini(pepper_map_t *map)
{
- pepper_map_clear(map);
+ pepper_map_clear(map);
}
PEPPER_API pepper_map_t *
pepper_map_create(int bucket_bits,
- pepper_hash_func_t hash_func,
- pepper_key_length_func_t key_length_func,
- pepper_key_compare_func_t key_compare_func)
+ pepper_hash_func_t hash_func,
+ pepper_key_length_func_t key_length_func,
+ pepper_key_compare_func_t key_compare_func)
{
- pepper_map_t *map;
- int bucket_size = 1 << bucket_bits;
+ pepper_map_t *map;
+ int bucket_size = 1 << bucket_bits;
- map = calloc(1, sizeof(pepper_map_t) + bucket_size * sizeof(pepper_map_entry_t *));
- PEPPER_CHECK(map, return NULL, "calloc() failed.\n");
+ map = calloc(1, sizeof(pepper_map_t) + bucket_size * sizeof(
+ pepper_map_entry_t *));
+ PEPPER_CHECK(map, return NULL, "calloc() failed.\n");
- pepper_map_init(map, bucket_bits, hash_func, key_length_func, key_compare_func, map + 1);
- return map;
+ pepper_map_init(map, bucket_bits, hash_func, key_length_func, key_compare_func,
+ map + 1);
+ return map;
}
PEPPER_API pepper_map_t *
pepper_map_int32_create(int bucket_bits)
{
- return pepper_map_create(bucket_bits, int32_hash, NULL, int32_key_compare);
+ return pepper_map_create(bucket_bits, int32_hash, NULL, int32_key_compare);
}
PEPPER_API pepper_map_t *
pepper_map_int64_create(int bucket_bits)
{
- return pepper_map_create(bucket_bits, int64_hash, NULL, int64_key_compare);
+ return pepper_map_create(bucket_bits, int64_hash, NULL, int64_key_compare);
}
PEPPER_API pepper_map_t *
pepper_map_pointer_create(int bucket_bits)
{
#if INTPTR_MAX == INT32_MAX
- return pepper_map_create(bucket_bits, int32_hash, NULL, int32_key_compare);
+ return pepper_map_create(bucket_bits, int32_hash, NULL, int32_key_compare);
#elif INTPTR_MAX == INT64_MAX
- return pepper_map_create(bucket_bits, int64_hash, NULL, int64_key_compare);
+ return pepper_map_create(bucket_bits, int64_hash, NULL, int64_key_compare);
#else
- #error "Not 32 or 64bit system"
+#error "Not 32 or 64bit system"
#endif
- return NULL;
+ return NULL;
}
PEPPER_API void
pepper_map_destroy(pepper_map_t *map)
{
- pepper_map_fini(map);
- free(map);
+ pepper_map_fini(map);
+ free(map);
}
PEPPER_API void
pepper_map_clear(pepper_map_t *map)
{
- int i;
+ int i;
- if (!map->buckets)
- return;
+ if (!map->buckets)
+ return;
- for (i = 0; i < map->bucket_size; i++)
- {
- pepper_map_entry_t *curr = map->buckets[i];
+ for (i = 0; i < map->bucket_size; i++) {
+ pepper_map_entry_t *curr = map->buckets[i];
- while (curr)
- {
- pepper_map_entry_t *next = curr->next;
+ while (curr) {
+ pepper_map_entry_t *next = curr->next;
- if (curr->free_func)
- curr->free_func(curr->data);
+ if (curr->free_func)
+ curr->free_func(curr->data);
- free(curr);
- curr = next;
- }
- }
+ free(curr);
+ curr = next;
+ }
+ }
- memset(map->buckets, 0x00, map->bucket_size * sizeof(pepper_map_entry_t *));
+ memset(map->buckets, 0x00, map->bucket_size * sizeof(pepper_map_entry_t *));
}
PEPPER_API void *
pepper_map_get(pepper_map_t *map, const void *key)
{
- pepper_map_entry_t *curr = *get_bucket(map, key);
+ pepper_map_entry_t *curr = *get_bucket(map, key);
- while (curr)
- {
- int len0 = 0;
- int len1 = 0;
+ while (curr) {
+ int len0 = 0;
+ int len1 = 0;
- if (map->key_length_func)
- {
- len0 = map->key_length_func(curr->key);
- len1 = map->key_length_func(key);
- }
+ if (map->key_length_func) {
+ len0 = map->key_length_func(curr->key);
+ len1 = map->key_length_func(key);
+ }
- if (map->key_compare_func(curr->key, len0, key, len1) == 0)
- return curr->data;
+ if (map->key_compare_func(curr->key, len0, key, len1) == 0)
+ return curr->data;
- curr = curr->next;
- }
+ curr = curr->next;
+ }
- return NULL;
+ return NULL;
}
PEPPER_API void
-pepper_map_set(pepper_map_t *map, const void *key, void *data, pepper_free_func_t free_func)
+pepper_map_set(pepper_map_t *map, const void *key, void *data,
+ pepper_free_func_t free_func)
{
- pepper_map_entry_t **bucket = get_bucket(map, key);
- pepper_map_entry_t *curr = *bucket;
- pepper_map_entry_t *prev = NULL;
- int key_length = 0;
-
- /* Find existing entry for the key. */
- while (curr)
- {
- int len0 = 0;
- int len1 = 0;
-
- if (map->key_length_func)
- {
- len0 = map->key_length_func(curr->key);
- len1 = map->key_length_func(key);
- }
-
- if (map->key_compare_func(curr->key, len0, key, len1) == 0)
- {
- /* Free previous data. */
- if (curr->free_func)
- curr->free_func(curr->data);
-
- if (data)
- {
- /* Set new data. */
- curr->data = data;
- curr->free_func = free_func;
- }
- else
- {
- /* Delete entry. */
- if (prev)
- prev->next = curr->next;
- else
- *bucket = curr->next;
-
- free(curr);
- }
-
- return;
- }
-
- prev = curr;
- curr = curr->next;
- }
-
- if (data == NULL)
- {
- /* Nothing to delete. */
- return;
- }
-
- /* Allocate a new entry. */
- if (map->key_length_func)
- key_length = map->key_length_func(key);
-
- curr = malloc(sizeof(pepper_map_entry_t) + key_length);
- PEPPER_CHECK(curr, return, "malloc() failed.\n");
-
- if (key_length > 0)
- {
- memcpy(curr + 1, key, key_length);
- curr->key = (const void *)(curr + 1);
- }
- else
- {
- curr->key = key;
- }
-
- curr->data = data;
- curr->free_func = free_func;
-
- /* Insert at the head of the bucket. */
- curr->next = *bucket;
- *bucket = curr;
+ pepper_map_entry_t **bucket = get_bucket(map, key);
+ pepper_map_entry_t *curr = *bucket;
+ pepper_map_entry_t *prev = NULL;
+ int key_length = 0;
+
+ /* Find existing entry for the key. */
+ while (curr) {
+ int len0 = 0;
+ int len1 = 0;
+
+ if (map->key_length_func) {
+ len0 = map->key_length_func(curr->key);
+ len1 = map->key_length_func(key);
+ }
+
+ if (map->key_compare_func(curr->key, len0, key, len1) == 0) {
+ /* Free previous data. */
+ if (curr->free_func)
+ curr->free_func(curr->data);
+
+ if (data) {
+ /* Set new data. */
+ curr->data = data;
+ curr->free_func = free_func;
+ } else {
+ /* Delete entry. */
+ if (prev)
+ prev->next = curr->next;
+ else
+ *bucket = curr->next;
+
+ free(curr);
+ }
+
+ return;
+ }
+
+ prev = curr;
+ curr = curr->next;
+ }
+
+ if (data == NULL) {
+ /* Nothing to delete. */
+ return;
+ }
+
+ /* Allocate a new entry. */
+ if (map->key_length_func)
+ key_length = map->key_length_func(key);
+
+ curr = malloc(sizeof(pepper_map_entry_t) + key_length);
+ PEPPER_CHECK(curr, return, "malloc() failed.\n");
+
+ if (key_length > 0) {
+ memcpy(curr + 1, key, key_length);
+ curr->key = (const void *)(curr + 1);
+ } else {
+ curr->key = key;
+ }
+
+ curr->data = data;
+ curr->free_func = free_func;
+
+ /* Insert at the head of the bucket. */
+ curr->next = *bucket;
+ *bucket = curr;
}
#include "pepper-utils.h"
-static struct _vt_data
-{
- int tty_fd;
- int tty_num;
- int saved_tty_num;
- int kb_mode;
+static struct _vt_data {
+ int tty_fd;
+ int tty_num;
+ int saved_tty_num;
+ int kb_mode;
} vt_data;
PEPPER_API void
pepper_virtual_terminal_restore(void)
{
- if (vt_data.tty_fd >= 0)
- {
- int fd = vt_data.tty_fd;
- struct vt_mode mode = {0};
-
- if ((vt_data.kb_mode >= 0) && (ioctl(fd, KDSKBMODE, vt_data.kb_mode) < 0))
- {
- PEPPER_ERROR("");
- }
-
- if (ioctl(fd, KDSETMODE, KD_TEXT) < 0)
- {
- PEPPER_ERROR("");
- }
-
- mode.mode = VT_AUTO;
- if (ioctl(fd, VT_SETMODE, &mode) < 0)
- {
- PEPPER_ERROR("");
- }
-
- if ((vt_data.saved_tty_num > 0) && (ioctl(fd, VT_ACTIVATE, vt_data.saved_tty_num) < 0))
- {
- PEPPER_ERROR("");
- }
-
- close(fd);
- }
+ if (vt_data.tty_fd >= 0) {
+ int fd = vt_data.tty_fd;
+ struct vt_mode mode = {0};
+
+ if ((vt_data.kb_mode >= 0) && (ioctl(fd, KDSKBMODE, vt_data.kb_mode) < 0)) {
+ PEPPER_ERROR("");
+ }
+
+ if (ioctl(fd, KDSETMODE, KD_TEXT) < 0) {
+ PEPPER_ERROR("");
+ }
+
+ mode.mode = VT_AUTO;
+ if (ioctl(fd, VT_SETMODE, &mode) < 0) {
+ PEPPER_ERROR("");
+ }
+
+ if ((vt_data.saved_tty_num > 0) &&
+ (ioctl(fd, VT_ACTIVATE, vt_data.saved_tty_num) < 0)) {
+ PEPPER_ERROR("");
+ }
+
+ close(fd);
+ }
}
PEPPER_API pepper_bool_t
pepper_virtual_terminal_setup(int tty)
{
- int fd;
+ int fd;
- struct vt_stat stat;
- struct vt_mode mode;
+ struct vt_stat stat;
+ struct vt_mode mode;
- memset(&vt_data, -1, sizeof(vt_data));
+ memset(&vt_data, -1, sizeof(vt_data));
- if (tty == 0)
- {
- fd = dup(tty);
- if (fd < 0)
- return PEPPER_FALSE;
+ if (tty == 0) {
+ fd = dup(tty);
+ if (fd < 0)
+ return PEPPER_FALSE;
- if (ioctl(fd, VT_GETSTATE, &stat) == 0)
- vt_data.tty_num = vt_data.saved_tty_num = stat.v_active;
- }
- else
- {
- char tty_str[32];
+ if (ioctl(fd, VT_GETSTATE, &stat) == 0)
+ vt_data.tty_num = vt_data.saved_tty_num = stat.v_active;
+ } else {
+ char tty_str[32];
- sprintf(tty_str, "/dev/tty%d", tty);
- fd = open(tty_str, O_RDWR | O_CLOEXEC);
- if (fd < 0)
- return PEPPER_FALSE;
+ sprintf(tty_str, "/dev/tty%d", tty);
+ fd = open(tty_str, O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ return PEPPER_FALSE;
- if (ioctl(fd, VT_GETSTATE, &stat) == 0)
- vt_data.saved_tty_num = stat.v_active;
+ if (ioctl(fd, VT_GETSTATE, &stat) == 0)
+ vt_data.saved_tty_num = stat.v_active;
- vt_data.tty_num = tty;
- }
+ vt_data.tty_num = tty;
+ }
- vt_data.tty_fd = fd;
+ vt_data.tty_fd = fd;
- if (ioctl(fd, VT_ACTIVATE, vt_data.tty_num) < 0)
- goto error;
+ if (ioctl(fd, VT_ACTIVATE, vt_data.tty_num) < 0)
+ goto error;
- if (ioctl(fd, VT_WAITACTIVE, vt_data.tty_num) < 0)
- goto error;
+ if (ioctl(fd, VT_WAITACTIVE, vt_data.tty_num) < 0)
+ goto error;
- if (ioctl(fd, KDGKBMODE, &vt_data.kb_mode) < 0)
- goto error;
+ if (ioctl(fd, KDGKBMODE, &vt_data.kb_mode) < 0)
+ goto error;
- if (ioctl(fd, KDSKBMODE, K_OFF) < 0)
- goto error;
+ if (ioctl(fd, KDSKBMODE, K_OFF) < 0)
+ goto error;
- if (ioctl(fd, KDSETMODE, KD_GRAPHICS) < 0)
- goto error;
+ if (ioctl(fd, KDSETMODE, KD_GRAPHICS) < 0)
+ goto error;
- if (ioctl(fd, VT_GETMODE, &mode) < 0)
- goto error;
+ if (ioctl(fd, VT_GETMODE, &mode) < 0)
+ goto error;
- mode.mode = VT_PROCESS;
- mode.relsig = SIGUSR1;
- mode.acqsig = SIGUSR1;
- if (ioctl(fd, VT_SETMODE, &mode) < 0)
- goto error;
+ mode.mode = VT_PROCESS;
+ mode.relsig = SIGUSR1;
+ mode.acqsig = SIGUSR1;
+ if (ioctl(fd, VT_SETMODE, &mode) < 0)
+ goto error;
- /* TODO: add signal handling code for SIGUSR1 */
+ /* TODO: add signal handling code for SIGUSR1 */
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
error:
- pepper_virtual_terminal_restore();
+ pepper_virtual_terminal_restore();
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
PEPPER_API void
pepper_id_allocator_init(pepper_id_allocator_t *allocator)
{
- memset(allocator, 0x00, sizeof(pepper_id_allocator_t));
- allocator->next_id = 1;
+ memset(allocator, 0x00, sizeof(pepper_id_allocator_t));
+ allocator->next_id = 1;
}
PEPPER_API void
pepper_id_allocator_fini(pepper_id_allocator_t *allocator)
{
- if (allocator->free_ids)
- free(allocator->free_ids);
+ if (allocator->free_ids)
+ free(allocator->free_ids);
}
PEPPER_API uint32_t
pepper_id_allocator_alloc(pepper_id_allocator_t *allocator)
{
- uint32_t id;
+ uint32_t id;
- if (allocator->free_id_count)
- {
- /* Increase age of the ID (upper N bits) when reusing it. */
- id = allocator->free_ids[allocator->free_id_head++] + PEPPER_ID_AGE;
- allocator->free_id_count--;
+ if (allocator->free_id_count) {
+ /* Increase age of the ID (upper N bits) when reusing it. */
+ id = allocator->free_ids[allocator->free_id_head++] + PEPPER_ID_AGE;
+ allocator->free_id_count--;
- if (allocator->free_id_head == allocator->free_id_size)
- allocator->free_id_head = 0;
- }
- else
- {
- id = allocator->next_id++;
- PEPPER_CHECK(id <= PEPPER_ID_MAX, return 0, "No available IDs left.\n");
- }
+ if (allocator->free_id_head == allocator->free_id_size)
+ allocator->free_id_head = 0;
+ } else {
+ id = allocator->next_id++;
+ PEPPER_CHECK(id <= PEPPER_ID_MAX, return 0, "No available IDs left.\n");
+ }
- return id;
+ return id;
}
PEPPER_API void
pepper_id_allocator_free(pepper_id_allocator_t *allocator, uint32_t id)
{
- if (allocator->free_id_count == allocator->free_id_size)
- {
- int i;
- uint32_t *ids = malloc((allocator->free_id_size + 64) * sizeof(uint32_t));
+ if (allocator->free_id_count == allocator->free_id_size) {
+ int i;
+ uint32_t *ids = malloc((allocator->free_id_size + 64) * sizeof(uint32_t));
- for (i = 0; i < allocator->free_id_size; i++)
- {
- ids[i] = allocator->free_ids[allocator->free_id_head++];
+ for (i = 0; i < allocator->free_id_size; i++) {
+ ids[i] = allocator->free_ids[allocator->free_id_head++];
- if (allocator->free_id_head == allocator->free_id_size)
- allocator->free_id_head = 0;
- }
+ if (allocator->free_id_head == allocator->free_id_size)
+ allocator->free_id_head = 0;
+ }
- if (allocator->free_ids)
- free(allocator->free_ids);
+ if (allocator->free_ids)
+ free(allocator->free_ids);
- allocator->free_id_head = 0;
- allocator->free_id_tail = allocator->free_id_size;
- allocator->free_id_size += 64;
- allocator->free_ids = ids;
- }
+ allocator->free_id_head = 0;
+ allocator->free_id_tail = allocator->free_id_size;
+ allocator->free_id_size += 64;
+ allocator->free_ids = ids;
+ }
- allocator->free_ids[allocator->free_id_tail++] = id;
- allocator->free_id_count++;
+ allocator->free_ids[allocator->free_id_tail++] = id;
+ allocator->free_id_count++;
- if (allocator->free_id_tail == allocator->free_id_size)
- allocator->free_id_tail = 0;
+ if (allocator->free_id_tail == allocator->free_id_size)
+ allocator->free_id_tail = 0;
}
void
pepper_view_mark_dirty(pepper_view_t *view, uint32_t flag)
{
- pepper_view_t *child;
- int i;
+ pepper_view_t *child;
+ int i;
- if (view->dirty & flag)
- return;
+ if (view->dirty & flag)
+ return;
- view->dirty |= flag;
+ view->dirty |= flag;
- /* Mark entire subtree's geometry as dirty. */
- if (flag & PEPPER_VIEW_GEOMETRY_DIRTY)
- {
- pepper_list_for_each(child, &view->children_list, parent_link)
- pepper_view_mark_dirty(child, PEPPER_VIEW_GEOMETRY_DIRTY);
+ /* Mark entire subtree's geometry as dirty. */
+ if (flag & PEPPER_VIEW_GEOMETRY_DIRTY) {
+ pepper_list_for_each(child, &view->children_list, parent_link)
+ pepper_view_mark_dirty(child, PEPPER_VIEW_GEOMETRY_DIRTY);
- for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
- view->plane_entries[i].need_transform_update = PEPPER_TRUE;
- }
+ for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
+ view->plane_entries[i].need_transform_update = PEPPER_TRUE;
+ }
- /* Mark entire subtree's active as dirty. */
- if (flag & PEPPER_VIEW_ACTIVE_DIRTY)
- {
- pepper_list_for_each(child, &view->children_list, parent_link)
- pepper_view_mark_dirty(child, PEPPER_VIEW_ACTIVE_DIRTY);
- }
+ /* Mark entire subtree's active as dirty. */
+ if (flag & PEPPER_VIEW_ACTIVE_DIRTY) {
+ pepper_list_for_each(child, &view->children_list, parent_link)
+ pepper_view_mark_dirty(child, PEPPER_VIEW_ACTIVE_DIRTY);
+ }
- pepper_compositor_schedule_repaint(view->compositor);
+ pepper_compositor_schedule_repaint(view->compositor);
}
void
pepper_view_surface_damage(pepper_view_t *view)
{
- int i;
+ int i;
- for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
- {
- pepper_plane_entry_t *entry = &view->plane_entries[i];
+ for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++) {
+ pepper_plane_entry_t *entry = &view->plane_entries[i];
- if (entry->plane)
- {
- pixman_region32_t damage;
+ if (entry->plane) {
+ pixman_region32_t damage;
- pixman_region32_init(&damage);
- pixman_region32_copy(&damage, &view->surface->damage_region);
- pixman_region32_intersect_rect(&damage, &damage, 0, 0, view->w, view->h);
+ pixman_region32_init(&damage);
+ pixman_region32_copy(&damage, &view->surface->damage_region);
+ pixman_region32_intersect_rect(&damage, &damage, 0, 0, view->w, view->h);
- pepper_transform_pixman_region(&damage, &view->global_transform);
- pixman_region32_translate(&damage,
- -entry->plane->output->geometry.x,
- -entry->plane->output->geometry.y);
- pixman_region32_intersect(&damage, &damage, &entry->base.visible_region);
- pepper_plane_add_damage_region(entry->plane, &damage);
- }
- }
+ pepper_transform_pixman_region(&damage, &view->global_transform);
+ pixman_region32_translate(&damage,
+ -entry->plane->output->geometry.x,
+ -entry->plane->output->geometry.y);
+ pixman_region32_intersect(&damage, &damage, &entry->base.visible_region);
+ pepper_plane_add_damage_region(entry->plane, &damage);
+ }
+ }
}
static pepper_list_t *
view_insert(pepper_view_t *view, pepper_list_t *pos, pepper_bool_t subtree)
{
- if ((pos != &view->compositor_link) && (pos->next != &view->compositor_link))
- {
- pepper_list_remove(&view->compositor_link);
- pepper_list_insert(pos, &view->compositor_link);
- pepper_object_emit_event(&view->base, PEPPER_EVENT_VIEW_STACK_CHANGE, NULL);
- pepper_view_mark_dirty(view, PEPPER_VIEW_Z_ORDER_DIRTY);
- }
+ if ((pos != &view->compositor_link) && (pos->next != &view->compositor_link)) {
+ pepper_list_remove(&view->compositor_link);
+ pepper_list_insert(pos, &view->compositor_link);
+ pepper_object_emit_event(&view->base, PEPPER_EVENT_VIEW_STACK_CHANGE, NULL);
+ pepper_view_mark_dirty(view, PEPPER_VIEW_Z_ORDER_DIRTY);
+ }
- pos = &view->compositor_link;
+ pos = &view->compositor_link;
- if (subtree)
- {
- pepper_view_t *child;
+ if (subtree) {
+ pepper_view_t *child;
- pepper_list_for_each(child, &view->children_list, parent_link)
- pos = view_insert(child, pos, subtree);
- }
+ pepper_list_for_each(child, &view->children_list, parent_link)
+ pos = view_insert(child, pos, subtree);
+ }
- return pos;
+ return pos;
}
static void
plane_entry_set_plane(pepper_plane_entry_t *entry, pepper_plane_t *plane)
{
- if (entry->plane == plane)
- return;
+ if (entry->plane == plane)
+ return;
- if (entry->plane)
- {
- pepper_plane_add_damage_region(entry->plane, &entry->base.visible_region);
- entry->plane = NULL;
- pixman_region32_fini(&entry->base.visible_region);
- }
+ if (entry->plane) {
+ pepper_plane_add_damage_region(entry->plane, &entry->base.visible_region);
+ entry->plane = NULL;
+ pixman_region32_fini(&entry->base.visible_region);
+ }
- entry->plane = plane;
+ entry->plane = plane;
- if (entry->plane)
- {
- pixman_region32_init(&entry->base.visible_region);
- entry->need_damage = PEPPER_TRUE;
- }
+ if (entry->plane) {
+ pixman_region32_init(&entry->base.visible_region);
+ entry->need_damage = PEPPER_TRUE;
+ }
}
/**
* @param plane plane to assign a view
*/
PEPPER_API void
-pepper_view_assign_plane(pepper_view_t *view, pepper_output_t *output, pepper_plane_t *plane)
+pepper_view_assign_plane(pepper_view_t *view, pepper_output_t *output,
+ pepper_plane_t *plane)
{
- PEPPER_CHECK(!plane || plane->output == output, return, "Plane output mismatch.\n");
- plane_entry_set_plane(&view->plane_entries[output->id], plane);
+ PEPPER_CHECK(!plane ||
+ plane->output == output, return, "Plane output mismatch.\n");
+ plane_entry_set_plane(&view->plane_entries[output->id], plane);
}
void
pepper_view_update(pepper_view_t *view)
{
- pepper_bool_t active;
- int i;
- uint32_t output_overlap_prev;
-
- if (!view->dirty)
- return;
-
- /* Update parent view first as transform and active flag are affected by the parent. */
- if (view->parent)
- {
- pepper_view_update(view->parent);
- active = view->parent->active && view->mapped;
- }
- else
- {
- active = view->mapped;
- }
-
- if (view->active == active)
- view->dirty &= ~PEPPER_VIEW_ACTIVE_DIRTY;
-
- if (!view->dirty)
- return;
-
- view->active = active;
-
- /* Damage for the view unmap will be handled by assigning NULL plane. */
- if (!view->active)
- return;
-
- /* We treat the modification as unmapping and remapping the view. So,
- * damage for the unmap and damage for the remap.
- *
- * Here, we know on which planes the view was previously located. So, we can
- * inflict damage on the planes for the unmap.
- *
- * However, new visible region of the view is not known at the moment
- * because no plane is assigned yet. So, simply mark the all plane entries
- * as damaged and the damage for the remap will be inflicted separately for
- * each output when the visible region is calculated on output repaint.
- */
-
- for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
- {
- pepper_plane_entry_t *entry = &view->plane_entries[i];
-
- if (entry->plane)
- pepper_plane_add_damage_region(entry->plane, &entry->base.visible_region);
- }
-
- /* Update geometry. */
- if (view->dirty & PEPPER_VIEW_GEOMETRY_DIRTY)
- {
- pepper_output_t *output;
-
- /* Transform. */
- pepper_mat4_init_translate(&view->global_transform, view->x, view->y, 0.0);
- pepper_mat4_multiply(&view->global_transform, &view->global_transform, &view->transform);
-
- if (view->inherit_transform && view->parent)
- {
- pepper_mat4_multiply(&view->global_transform,
- &view->parent->global_transform, &view->global_transform);
- }
-
- pepper_mat4_inverse(&view->global_transform_inverse, &view->global_transform);
-
- /* Bounding region. */
- pixman_region32_fini(&view->bounding_region);
- pixman_region32_init_rect(&view->bounding_region, 0, 0, view->w, view->h);
- pepper_transform_pixman_region(&view->bounding_region, &view->global_transform);
-
- /* Opaque region. */
- if (view->surface && pepper_mat4_is_translation(&view->global_transform))
- {
- pixman_region32_copy(&view->opaque_region, &view->surface->opaque_region);
- pixman_region32_translate(&view->opaque_region,
- view->global_transform.m[12], view->global_transform.m[13]);
- }
- else
- {
- pixman_region32_clear(&view->opaque_region);
- }
-
- /* Output overlap. */
- output_overlap_prev = view->output_overlap;
- view->output_overlap = 0;
-
- pepper_list_for_each(output, &view->compositor->output_list, link)
- {
- pixman_box32_t box =
- {
- output->geometry.x,
- output->geometry.y,
- output->geometry.x + output->geometry.w,
- output->geometry.y + output->geometry.h
- };
-
- if (pixman_region32_contains_rectangle(&view->bounding_region, &box) != PIXMAN_REGION_OUT)
- {
- view->output_overlap |= (1 << output->id);
- if (!(output_overlap_prev & (1 << output->id)))
- pepper_surface_send_enter(view->surface, output);
- }
- else
- {
- if (view->surface && (output_overlap_prev & (1 << output->id)))
- pepper_surface_send_leave(view->surface, output);
- }
- }
- }
-
- /* Mark the plane entries as damaged. */
- for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
- view->plane_entries[i].need_damage = PEPPER_TRUE;
-
- view->active = active;
- view->dirty = 0;
+ pepper_bool_t active;
+ int i;
+ uint32_t output_overlap_prev;
+
+ if (!view->dirty)
+ return;
+
+ /* Update parent view first as transform and active flag are affected by the parent. */
+ if (view->parent) {
+ pepper_view_update(view->parent);
+ active = view->parent->active && view->mapped;
+ } else {
+ active = view->mapped;
+ }
+
+ if (view->active == active)
+ view->dirty &= ~PEPPER_VIEW_ACTIVE_DIRTY;
+
+ if (!view->dirty)
+ return;
+
+ view->active = active;
+
+ /* Damage for the view unmap will be handled by assigning NULL plane. */
+ if (!view->active)
+ return;
+
+ /* We treat the modification as unmapping and remapping the view. So,
+ * damage for the unmap and damage for the remap.
+ *
+ * Here, we know on which planes the view was previously located. So, we can
+ * inflict damage on the planes for the unmap.
+ *
+ * However, new visible region of the view is not known at the moment
+ * because no plane is assigned yet. So, simply mark the all plane entries
+ * as damaged and the damage for the remap will be inflicted separately for
+ * each output when the visible region is calculated on output repaint.
+ */
+
+ for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++) {
+ pepper_plane_entry_t *entry = &view->plane_entries[i];
+
+ if (entry->plane)
+ pepper_plane_add_damage_region(entry->plane, &entry->base.visible_region);
+ }
+
+ /* Update geometry. */
+ if (view->dirty & PEPPER_VIEW_GEOMETRY_DIRTY) {
+ pepper_output_t *output;
+
+ /* Transform. */
+ pepper_mat4_init_translate(&view->global_transform, view->x, view->y, 0.0);
+ pepper_mat4_multiply(&view->global_transform, &view->global_transform,
+ &view->transform);
+
+ if (view->inherit_transform && view->parent) {
+ pepper_mat4_multiply(&view->global_transform,
+ &view->parent->global_transform, &view->global_transform);
+ }
+
+ pepper_mat4_inverse(&view->global_transform_inverse, &view->global_transform);
+
+ /* Bounding region. */
+ pixman_region32_fini(&view->bounding_region);
+ pixman_region32_init_rect(&view->bounding_region, 0, 0, view->w, view->h);
+ pepper_transform_pixman_region(&view->bounding_region, &view->global_transform);
+
+ /* Opaque region. */
+ if (view->surface && pepper_mat4_is_translation(&view->global_transform)) {
+ pixman_region32_copy(&view->opaque_region, &view->surface->opaque_region);
+ pixman_region32_translate(&view->opaque_region,
+ view->global_transform.m[12], view->global_transform.m[13]);
+ } else {
+ pixman_region32_clear(&view->opaque_region);
+ }
+
+ /* Output overlap. */
+ output_overlap_prev = view->output_overlap;
+ view->output_overlap = 0;
+
+ pepper_list_for_each(output, &view->compositor->output_list, link) {
+ pixman_box32_t box = {
+ output->geometry.x,
+ output->geometry.y,
+ output->geometry.x + output->geometry.w,
+ output->geometry.y + output->geometry.h
+ };
+
+ if (pixman_region32_contains_rectangle(&view->bounding_region,
+ &box) != PIXMAN_REGION_OUT) {
+ view->output_overlap |= (1 << output->id);
+ if (!(output_overlap_prev & (1 << output->id)))
+ pepper_surface_send_enter(view->surface, output);
+ } else {
+ if (view->surface && (output_overlap_prev & (1 << output->id)))
+ pepper_surface_send_leave(view->surface, output);
+ }
+ }
+ }
+
+ /* Mark the plane entries as damaged. */
+ for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
+ view->plane_entries[i].need_damage = PEPPER_TRUE;
+
+ view->active = active;
+ view->dirty = 0;
}
static void
view_init(pepper_view_t *view, pepper_compositor_t *compositor)
{
- int i;
+ int i;
- view->compositor_link.item = view;
- view->parent_link.item = view;
- view->link.item = view;
- view->surface_link.item = view;
+ view->compositor_link.item = view;
+ view->parent_link.item = view;
+ view->link.item = view;
+ view->surface_link.item = view;
- view->compositor = compositor;
- pepper_list_insert(&compositor->view_list, &view->compositor_link);
+ view->compositor = compositor;
+ pepper_list_insert(&compositor->view_list, &view->compositor_link);
- pepper_list_init(&view->children_list);
+ pepper_list_init(&view->children_list);
- pepper_mat4_init_identity(&view->transform);
- pepper_mat4_init_identity(&view->global_transform);
- pixman_region32_init(&view->bounding_region);
- pixman_region32_init(&view->opaque_region);
+ pepper_mat4_init_identity(&view->transform);
+ pepper_mat4_init_identity(&view->global_transform);
+ pixman_region32_init(&view->bounding_region);
+ pixman_region32_init(&view->opaque_region);
- for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
- {
- view->plane_entries[i].base.view = view;
- view->plane_entries[i].link.item = &view->plane_entries[i];
- }
+ for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++) {
+ view->plane_entries[i].base.view = view;
+ view->plane_entries[i].link.item = &view->plane_entries[i];
+ }
}
/**
PEPPER_API pepper_view_t *
pepper_compositor_add_view(pepper_compositor_t *compositor)
{
- pepper_view_t *view = (pepper_view_t *)pepper_object_alloc(PEPPER_OBJECT_VIEW,
- sizeof(pepper_view_t));
- PEPPER_CHECK(view, return NULL, "pepper_object_alloc() failed.\n");
+ pepper_view_t *view = (pepper_view_t *)pepper_object_alloc(PEPPER_OBJECT_VIEW,
+ sizeof(pepper_view_t));
+ PEPPER_CHECK(view, return NULL, "pepper_object_alloc() failed.\n");
- view_init(view, compositor);
+ view_init(view, compositor);
- view->x = 0.0;
- view->y = 0.0;
- view->w = 0;
- view->h = 0;
+ view->x = 0.0;
+ view->y = 0.0;
+ view->w = 0;
+ view->h = 0;
- pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_VIEW_ADD, view);
- return view;
+ pepper_object_emit_event(&compositor->base, PEPPER_EVENT_COMPOSITOR_VIEW_ADD,
+ view);
+ return view;
}
static void
view_unlink_from_surface(pepper_view_t *view)
{
- pepper_list_remove(&view->surface_link);
+ pepper_list_remove(&view->surface_link);
- subsurface_destroy_children_views(view->surface->sub, view);
+ subsurface_destroy_children_views(view->surface->sub, view);
}
static void
view_link_to_surface(pepper_view_t *view)
{
- pepper_list_insert(&view->surface->view_list, &view->surface_link);
+ pepper_list_insert(&view->surface->view_list, &view->surface_link);
- subsurface_create_children_views(view->surface->sub, view);
+ subsurface_create_children_views(view->surface->sub, view);
}
/**
PEPPER_API pepper_bool_t
pepper_view_set_surface(pepper_view_t *view, pepper_surface_t *surface)
{
- if (view->surface == surface)
- return PEPPER_TRUE;
+ if (view->surface == surface)
+ return PEPPER_TRUE;
- if (view->surface)
- view_unlink_from_surface(view);
+ if (view->surface)
+ view_unlink_from_surface(view);
- view->surface = surface;
+ view->surface = surface;
- if (view->surface)
- view_link_to_surface(view);
+ if (view->surface)
+ view_link_to_surface(view);
- pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
- return PEPPER_TRUE;
+ pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
+ return PEPPER_TRUE;
}
/**
PEPPER_API void
pepper_view_destroy(pepper_view_t *view)
{
- int i;
- pepper_view_t *child, *tmp;
+ int i;
+ pepper_view_t *child, *tmp;
- pepper_object_emit_event(&view->compositor->base, PEPPER_EVENT_COMPOSITOR_VIEW_REMOVE, view);
- pepper_object_fini(&view->base);
+ pepper_object_emit_event(&view->compositor->base,
+ PEPPER_EVENT_COMPOSITOR_VIEW_REMOVE, view);
+ pepper_object_fini(&view->base);
- for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
- plane_entry_set_plane(&view->plane_entries[i], NULL);
+ for (i = 0; i < PEPPER_MAX_OUTPUT_COUNT; i++)
+ plane_entry_set_plane(&view->plane_entries[i], NULL);
- pepper_list_for_each_safe(child, tmp, &view->children_list, parent_link)
- pepper_view_destroy(child);
+ pepper_list_for_each_safe(child, tmp, &view->children_list, parent_link)
+ pepper_view_destroy(child);
- if (view->parent)
- pepper_list_remove(&view->parent_link);
+ if (view->parent)
+ pepper_list_remove(&view->parent_link);
- pepper_list_remove(&view->compositor_link);
+ pepper_list_remove(&view->compositor_link);
- if (view->surface)
- pepper_list_remove(&view->surface_link);
+ if (view->surface)
+ pepper_list_remove(&view->surface_link);
- pixman_region32_fini(&view->opaque_region);
- pixman_region32_fini(&view->bounding_region);
+ pixman_region32_fini(&view->opaque_region);
+ pixman_region32_fini(&view->bounding_region);
- free(view);
+ free(view);
}
/**
PEPPER_API pepper_compositor_t *
pepper_view_get_compositor(pepper_view_t *view)
{
- return view->compositor;
+ return view->compositor;
}
/**
PEPPER_API pepper_surface_t *
pepper_view_get_surface(pepper_view_t *view)
{
- return view->surface;
+ return view->surface;
}
/**
PEPPER_API void
pepper_view_set_parent(pepper_view_t *view, pepper_view_t *parent)
{
- if (view->parent == parent)
- return;
+ if (view->parent == parent)
+ return;
- if (view->parent)
- pepper_list_remove(&view->parent_link);
+ if (view->parent)
+ pepper_list_remove(&view->parent_link);
- view->parent = parent;
+ view->parent = parent;
- if (view->parent)
- pepper_list_insert(view->parent->children_list.prev, &view->parent_link);
+ if (view->parent)
+ pepper_list_insert(view->parent->children_list.prev, &view->parent_link);
- pepper_view_mark_dirty(view, PEPPER_VIEW_ACTIVE_DIRTY | PEPPER_VIEW_GEOMETRY_DIRTY);
+ pepper_view_mark_dirty(view,
+ PEPPER_VIEW_ACTIVE_DIRTY | PEPPER_VIEW_GEOMETRY_DIRTY);
}
/**
PEPPER_API pepper_view_t *
pepper_view_get_parent(pepper_view_t *view)
{
- return view->parent;
+ return view->parent;
}
/**
PEPPER_API void
pepper_view_set_transform_inherit(pepper_view_t *view, pepper_bool_t inherit)
{
- if (view->inherit_transform == inherit)
- return;
+ if (view->inherit_transform == inherit)
+ return;
- if (view->inherit_transform)
- {
- /* Inherit flag changed from TRUE to FALSE.
- * We have to update view position and transform from parent local to global. */
- view->x = view->global_transform.m[12];
- view->y = view->global_transform.m[13];
+ if (view->inherit_transform) {
+ /* Inherit flag changed from TRUE to FALSE.
+ * We have to update view position and transform from parent local to global. */
+ view->x = view->global_transform.m[12];
+ view->y = view->global_transform.m[13];
- pepper_mat4_copy(&view->transform, &view->global_transform);
- pepper_mat4_translate(&view->transform, -view->x, -view->y, 0.0);
- }
- else
- {
- /* Inherit flag changed from FALSE to TRUE.
- * We have to update view position and transform from global to parent local. */
+ pepper_mat4_copy(&view->transform, &view->global_transform);
+ pepper_mat4_translate(&view->transform, -view->x, -view->y, 0.0);
+ } else {
+ /* Inherit flag changed from FALSE to TRUE.
+ * We have to update view position and transform from global to parent local. */
- if (view->parent)
- {
- /* Get transform matrix on the parent local coordinate space. */
- pepper_mat4_inverse(&view->transform, &view->parent->global_transform);
- pepper_mat4_multiply(&view->transform, &view->global_transform, &view->transform);
+ if (view->parent) {
+ /* Get transform matrix on the parent local coordinate space. */
+ pepper_mat4_inverse(&view->transform, &view->parent->global_transform);
+ pepper_mat4_multiply(&view->transform, &view->global_transform,
+ &view->transform);
- /* Set position of the (x, y) translation term of the matrix. */
- view->x = view->transform.m[12];
- view->y = view->transform.m[13];
+ /* Set position of the (x, y) translation term of the matrix. */
+ view->x = view->transform.m[12];
+ view->y = view->transform.m[13];
- /* Compensate the view position translation. */
- pepper_mat4_translate(&view->transform, -view->x, -view->y, 0.0);
- }
- }
+ /* Compensate the view position translation. */
+ pepper_mat4_translate(&view->transform, -view->x, -view->y, 0.0);
+ }
+ }
- view->inherit_transform = inherit;
+ view->inherit_transform = inherit;
}
/**
PEPPER_API pepper_bool_t
pepper_view_get_transform_inherit(pepper_view_t *view)
{
- return view->inherit_transform;
+ return view->inherit_transform;
}
/**
* @see pepper_view_stack_bottom()
*/
PEPPER_API pepper_bool_t
-pepper_view_stack_above(pepper_view_t *view, pepper_view_t *below, pepper_bool_t subtree)
+pepper_view_stack_above(pepper_view_t *view, pepper_view_t *below,
+ pepper_bool_t subtree)
{
- view_insert(view, below->compositor_link.prev, subtree);
- return PEPPER_TRUE;
+ view_insert(view, below->compositor_link.prev, subtree);
+ return PEPPER_TRUE;
}
/**
* @see pepper_view_stack_bottom()
*/
PEPPER_API pepper_bool_t
-pepper_view_stack_below(pepper_view_t *view, pepper_view_t *above, pepper_bool_t subtree)
+pepper_view_stack_below(pepper_view_t *view, pepper_view_t *above,
+ pepper_bool_t subtree)
{
- view_insert(view, &above->compositor_link, subtree);
- return PEPPER_TRUE;
+ view_insert(view, &above->compositor_link, subtree);
+ return PEPPER_TRUE;
}
/**
PEPPER_API void
pepper_view_stack_top(pepper_view_t *view, pepper_bool_t subtree)
{
- view_insert(view, &view->compositor->view_list, subtree);
+ view_insert(view, &view->compositor->view_list, subtree);
}
/**
PEPPER_API void
pepper_view_stack_bottom(pepper_view_t *view, pepper_bool_t subtree)
{
- view_insert(view, view->compositor->view_list.prev, subtree);
+ view_insert(view, view->compositor->view_list.prev, subtree);
}
/**
PEPPER_API pepper_view_t *
pepper_view_get_above(pepper_view_t *view)
{
- return view->compositor_link.next->item;
+ return view->compositor_link.next->item;
}
/**
PEPPER_API pepper_view_t *
pepper_view_get_below(pepper_view_t *view)
{
- return view->compositor_link.prev->item;
+ return view->compositor_link.prev->item;
}
/**
PEPPER_API const pepper_list_t *
pepper_view_get_children_list(pepper_view_t *view)
{
- return &view->children_list;
+ return &view->children_list;
}
/**
PEPPER_API void
pepper_view_resize(pepper_view_t *view, int w, int h)
{
- if (view->w == w && view->h == h)
- return;
+ if (view->w == w && view->h == h)
+ return;
- view->w = w;
- view->h = h;
- pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
+ view->w = w;
+ view->h = h;
+ pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
}
/**
PEPPER_API void
pepper_view_get_size(pepper_view_t *view, int *w, int *h)
{
- if (w)
- *w = view->w;
+ if (w)
+ *w = view->w;
- if (h)
- *h = view->h;
+ if (h)
+ *h = view->h;
}
/**
PEPPER_API void
pepper_view_set_position(pepper_view_t *view, double x, double y)
{
- if (view->x == x && view->y == y)
- return;
+ if (view->x == x && view->y == y)
+ return;
- view->x = x;
- view->y = y;
- pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
+ view->x = x;
+ view->y = y;
+ pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
}
/**
PEPPER_API void
pepper_view_get_position(pepper_view_t *view, double *x, double *y)
{
- if (x)
- *x = view->x;
+ if (x)
+ *x = view->x;
- if (y)
- *y = view->y;
+ if (y)
+ *y = view->y;
}
/**
PEPPER_API void
pepper_view_set_transform(pepper_view_t *view, const pepper_mat4_t *matrix)
{
- pepper_mat4_copy(&view->transform, matrix);
- pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
+ pepper_mat4_copy(&view->transform, matrix);
+ pepper_view_mark_dirty(view, PEPPER_VIEW_GEOMETRY_DIRTY);
}
/**
PEPPER_API const pepper_mat4_t *
pepper_view_get_transform(pepper_view_t *view)
{
- return &view->transform;
+ return &view->transform;
}
/**
PEPPER_API void
pepper_view_map(pepper_view_t *view)
{
- if (view->mapped)
- return;
+ if (view->mapped)
+ return;
- view->mapped = PEPPER_TRUE;
- pepper_view_mark_dirty(view, PEPPER_VIEW_ACTIVE_DIRTY);
+ view->mapped = PEPPER_TRUE;
+ pepper_view_mark_dirty(view, PEPPER_VIEW_ACTIVE_DIRTY);
}
/**
PEPPER_API void
pepper_view_unmap(pepper_view_t *view)
{
- if (!view->mapped)
- return;
+ if (!view->mapped)
+ return;
- view->mapped = PEPPER_FALSE;
- pepper_view_mark_dirty(view, PEPPER_VIEW_ACTIVE_DIRTY);
+ view->mapped = PEPPER_FALSE;
+ pepper_view_mark_dirty(view, PEPPER_VIEW_ACTIVE_DIRTY);
}
/**
PEPPER_API pepper_bool_t
pepper_view_is_mapped(pepper_view_t *view)
{
- return view->mapped;
+ return view->mapped;
}
/**
PEPPER_API pepper_bool_t
pepper_view_is_visible(pepper_view_t *view)
{
- if (view->parent)
- return pepper_view_is_visible(view->parent) && view->mapped;
+ if (view->parent)
+ return pepper_view_is_visible(view->parent) && view->mapped;
- return view->mapped;
+ return view->mapped;
}
/**
PEPPER_API pepper_bool_t
pepper_view_is_opaque(pepper_view_t *view)
{
- pepper_surface_t *surface = view->surface;
- struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(surface->buffer.buffer->resource);
- pixman_box32_t extent;
+ pepper_surface_t *surface = view->surface;
+ struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(
+ surface->buffer.buffer->resource);
+ pixman_box32_t extent;
- if (shm_buffer)
- {
- uint32_t shm_format = wl_shm_buffer_get_format(shm_buffer);
+ if (shm_buffer) {
+ uint32_t shm_format = wl_shm_buffer_get_format(shm_buffer);
- if (shm_format == WL_SHM_FORMAT_XRGB8888 || shm_format == WL_SHM_FORMAT_RGB565)
- return PEPPER_TRUE;
- }
+ if (shm_format == WL_SHM_FORMAT_XRGB8888 || shm_format == WL_SHM_FORMAT_RGB565)
+ return PEPPER_TRUE;
+ }
- /* TODO: format check for wl_drm or wl_tbm?? */
+ /* TODO: format check for wl_drm or wl_tbm?? */
- extent.x1 = 0;
- extent.y1 = 0;
- extent.x2 = view->surface->w;
- extent.y2 = view->surface->h;
+ extent.x1 = 0;
+ extent.y1 = 0;
+ extent.x2 = view->surface->w;
+ extent.y2 = view->surface->h;
- if (pixman_region32_contains_rectangle(&surface->opaque_region, &extent) == PIXMAN_REGION_IN)
- return PEPPER_TRUE;
+ if (pixman_region32_contains_rectangle(&surface->opaque_region,
+ &extent) == PIXMAN_REGION_IN)
+ return PEPPER_TRUE;
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
/**
* @param ly pointer to receive y coordinate in view local space
*/
PEPPER_API void
-pepper_view_get_local_coordinate(pepper_view_t *view, double gx, double gy, double *lx, double *ly)
+pepper_view_get_local_coordinate(pepper_view_t *view, double gx, double gy,
+ double *lx, double *ly)
{
- pepper_vec4_t pos = { gx, gy, 0.0, 1.0 };
+ pepper_vec4_t pos = { gx, gy, 0.0, 1.0 };
- pepper_mat4_transform_vec4(&view->global_transform_inverse, &pos);
+ pepper_mat4_transform_vec4(&view->global_transform_inverse, &pos);
- PEPPER_ASSERT(pos.w >= 1e-6);
+ PEPPER_ASSERT(pos.w >= 1e-6);
- *lx = pos.x / pos.w;
- *ly = pos.y / pos.w;
+ *lx = pos.x / pos.w;
+ *ly = pos.y / pos.w;
}
/**
* @param gy pointer to receive y coordinate in global space
*/
PEPPER_API void
-pepper_view_get_global_coordinate(pepper_view_t *view, double lx, double ly, double *gx, double *gy)
+pepper_view_get_global_coordinate(pepper_view_t *view, double lx, double ly,
+ double *gx, double *gy)
{
- pepper_vec4_t pos = { lx, ly, 0.0, 1.0 };
+ pepper_vec4_t pos = { lx, ly, 0.0, 1.0 };
- pepper_mat4_transform_vec4(&view->global_transform, &pos);
+ pepper_mat4_transform_vec4(&view->global_transform, &pos);
- PEPPER_ASSERT(pos.w >= 1e-6);
+ PEPPER_ASSERT(pos.w >= 1e-6);
- *gx = pos.x / pos.w;
- *gy = pos.y / pos.w;
+ *gx = pos.x / pos.w;
+ *gy = pos.y / pos.w;
}
struct wl_display;
#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
-EGLAPI EGLBoolean EGLAPIENTRY eglUnbindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);
+EGLAPI EGLBoolean EGLAPIENTRY eglBindWaylandDisplayWL(EGLDisplay dpy,
+ struct wl_display *display);
+EGLAPI EGLBoolean EGLAPIENTRY eglUnbindWaylandDisplayWL(EGLDisplay dpy,
+ struct wl_display *display);
#endif
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy,
+ struct wl_display *display);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy,
+ struct wl_display *display);
#endif
/*
struct wl_resource;
#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryWaylandBufferWL(EGLDisplay dpy,
+ struct wl_resource *buffer, EGLint attribute, EGLint *value);
#endif
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYWAYLANDBUFFERWL) (EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYWAYLANDBUFFERWL) (EGLDisplay dpy,
+ struct wl_resource *buffer, EGLint attribute, EGLint *value);
#endif
#ifndef EGL_WL_create_wayland_buffer_from_image
#define EGL_WL_create_wayland_buffer_from_image 1
#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI struct wl_buffer * EGLAPIENTRY eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImageKHR image);
+EGLAPI struct wl_buffer *EGLAPIENTRY eglCreateWaylandBufferFromImageWL(
+ EGLDisplay dpy, EGLImageKHR image);
#endif
-typedef struct wl_buffer * (EGLAPIENTRYP PFNEGLCREATEWAYLANDBUFFERFROMIMAGEWL) (EGLDisplay dpy, EGLImageKHR image);
+typedef struct wl_buffer *(EGLAPIENTRYP PFNEGLCREATEWAYLANDBUFFERFROMIMAGEWL) (
+ EGLDisplay dpy, EGLImageKHR image);
#endif
#ifndef EGL_TEXTURE_EXTERNAL_WL
typedef struct gl_render_target gl_render_target_t;
#ifndef EGL_EXT_platform_base
-typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform,
- void *native_display,
- const EGLint *attrib_list);
-
-typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)(EGLDisplay display,
- EGLConfig config,
- void *native_window,
- const EGLint *attrib_list);
+typedef EGLDisplay (*PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum
+ platform,
+ void *native_display,
+ const EGLint *attrib_list);
+
+typedef EGLSurface (*PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)(
+ EGLDisplay display,
+ EGLConfig config,
+ void *native_window,
+ const EGLint *attrib_list);
#endif
#ifndef EGL_PLATFORM_X11_KHR
#define NUM_MAX_PLANES 3
static const char vertex_shader[] =
- "uniform mat4 trans;\n"
- "attribute vec2 position;\n"
- "attribute vec2 texcoord;\n"
- "varying vec2 v_texcoord;\n"
- "void main()\n"
- "{\n"
- " gl_Position = trans * vec4(position, 0.0, 1.0);\n"
- " v_texcoord = texcoord;\n"
- "}\n";
+ "uniform mat4 trans;\n"
+ "attribute vec2 position;\n"
+ "attribute vec2 texcoord;\n"
+ "varying vec2 v_texcoord;\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = trans * vec4(position, 0.0, 1.0);\n"
+ " v_texcoord = texcoord;\n"
+ "}\n";
static const char fragment_shader_rgba[] =
- "precision mediump float;\n"
- "varying vec2 v_texcoord;\n"
- "uniform sampler2D tex;\n"
- "uniform float alpha;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = alpha * texture2D(tex, v_texcoord);\n"
- "}\n";
+ "precision mediump float;\n"
+ "varying vec2 v_texcoord;\n"
+ "uniform sampler2D tex;\n"
+ "uniform float alpha;\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = alpha * texture2D(tex, v_texcoord);\n"
+ "}\n";
static const char fragment_shader_rgbx[] =
- "precision mediump float;\n"
- "varying vec2 v_texcoord;\n"
- "uniform sampler2D tex;\n"
- "uniform float alpha;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;\n"
- " gl_FragColor.a = alpha;\n"
- "}\n";
+ "precision mediump float;\n"
+ "varying vec2 v_texcoord;\n"
+ "uniform sampler2D tex;\n"
+ "uniform float alpha;\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;\n"
+ " gl_FragColor.a = alpha;\n"
+ "}\n";
static const char fragment_shader_y_uv[] =
- "precision mediump float;\n"
- "uniform sampler2D tex;\n"
- "uniform sampler2D tex1;\n"
- "varying vec2 v_texcoord;\n"
- "uniform float alpha;\n"
- "void main()\n"
- "{\n"
- " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
- " float u = texture2D(tex1, v_texcoord).r - 0.5;\n"
- " float v = texture2D(tex1, v_texcoord).g - 0.5;\n"
- " y *= alpha;\n"
- " u *= alpha;\n"
- " v *= alpha;\n"
- " gl_FragColor.r = y + 1.59602678 * v;\n"
- " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n"
- " gl_FragColor.b = y + 2.01723214 * u;\n"
- " gl_FragColor.a = alpha;\n"
- "}\n";
+ "precision mediump float;\n"
+ "uniform sampler2D tex;\n"
+ "uniform sampler2D tex1;\n"
+ "varying vec2 v_texcoord;\n"
+ "uniform float alpha;\n"
+ "void main()\n"
+ "{\n"
+ " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
+ " float u = texture2D(tex1, v_texcoord).r - 0.5;\n"
+ " float v = texture2D(tex1, v_texcoord).g - 0.5;\n"
+ " y *= alpha;\n"
+ " u *= alpha;\n"
+ " v *= alpha;\n"
+ " gl_FragColor.r = y + 1.59602678 * v;\n"
+ " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n"
+ " gl_FragColor.b = y + 2.01723214 * u;\n"
+ " gl_FragColor.a = alpha;\n"
+ "}\n";
static const char fragment_shader_y_xuxv[] =
- "precision mediump float;\n"
- "uniform sampler2D tex;\n"
- "uniform sampler2D tex1;\n"
- "varying vec2 v_texcoord;\n"
- "uniform float alpha;\n"
- "void main()\n"
- "{\n"
- " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
- " float u = texture2D(tex1, v_texcoord).g - 0.5;\n"
- " float v = texture2D(tex1, v_texcoord).a - 0.5;\n"
- " y *= alpha;\n"
- " u *= alpha;\n"
- " v *= alpha;\n"
- " gl_FragColor.r = y + 1.59602678 * v;\n"
- " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n"
- " gl_FragColor.b = y + 2.01723214 * u;\n"
- " gl_FragColor.a = alpha;\n"
- "}\n";
+ "precision mediump float;\n"
+ "uniform sampler2D tex;\n"
+ "uniform sampler2D tex1;\n"
+ "varying vec2 v_texcoord;\n"
+ "uniform float alpha;\n"
+ "void main()\n"
+ "{\n"
+ " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
+ " float u = texture2D(tex1, v_texcoord).g - 0.5;\n"
+ " float v = texture2D(tex1, v_texcoord).a - 0.5;\n"
+ " y *= alpha;\n"
+ " u *= alpha;\n"
+ " v *= alpha;\n"
+ " gl_FragColor.r = y + 1.59602678 * v;\n"
+ " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n"
+ " gl_FragColor.b = y + 2.01723214 * u;\n"
+ " gl_FragColor.a = alpha;\n"
+ "}\n";
static const char fragment_shader_y_u_v[] =
- "precision mediump float;\n"
- "uniform sampler2D tex;\n"
- "uniform sampler2D tex1;\n"
- "uniform sampler2D tex2;\n"
- "varying vec2 v_texcoord;\n"
- "uniform float alpha;\n"
- "void main()"
- "{\n"
- " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
- " float u = texture2D(tex1, v_texcoord).x - 0.5;\n"
- " float v = texture2D(tex2, v_texcoord).x - 0.5;\n"
- " y *= alpha;\n"
- " u *= alpha;\n"
- " v *= alpha;\n"
- " gl_FragColor.r = y + 1.59602678 * v;\n"
- " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n"
- " gl_FragColor.b = y + 2.01723214 * u;\n"
- " gl_FragColor.a = alpha;\n"
- "}\n";
-
-static const char *vertex_shaders[] =
-{
- vertex_shader,
- vertex_shader,
- vertex_shader,
- vertex_shader,
- vertex_shader,
+ "precision mediump float;\n"
+ "uniform sampler2D tex;\n"
+ "uniform sampler2D tex1;\n"
+ "uniform sampler2D tex2;\n"
+ "varying vec2 v_texcoord;\n"
+ "uniform float alpha;\n"
+ "void main()"
+ "{\n"
+ " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
+ " float u = texture2D(tex1, v_texcoord).x - 0.5;\n"
+ " float v = texture2D(tex2, v_texcoord).x - 0.5;\n"
+ " y *= alpha;\n"
+ " u *= alpha;\n"
+ " v *= alpha;\n"
+ " gl_FragColor.r = y + 1.59602678 * v;\n"
+ " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n"
+ " gl_FragColor.b = y + 2.01723214 * u;\n"
+ " gl_FragColor.a = alpha;\n"
+ "}\n";
+
+static const char *vertex_shaders[] = {
+ vertex_shader,
+ vertex_shader,
+ vertex_shader,
+ vertex_shader,
+ vertex_shader,
};
-static const char *fragment_shaders[] =
-{
- fragment_shader_rgba,
- fragment_shader_rgbx,
- fragment_shader_y_uv,
- fragment_shader_y_xuxv,
- fragment_shader_y_u_v,
+static const char *fragment_shaders[] = {
+ fragment_shader_rgba,
+ fragment_shader_rgbx,
+ fragment_shader_y_uv,
+ fragment_shader_y_xuxv,
+ fragment_shader_y_u_v,
};
-enum shader_sampler
-{
- GL_SHADER_SAMPLER_RGBA,
- GL_SHADER_SAMPLER_RGBX,
- GL_SHADER_SAMPLER_Y_UV,
- GL_SHADER_SAMPLER_Y_XUXV,
- GL_SHADER_SAMPLER_Y_U_V,
- GL_SHADER_SAMPLER_NONE,
+enum shader_sampler {
+ GL_SHADER_SAMPLER_RGBA,
+ GL_SHADER_SAMPLER_RGBX,
+ GL_SHADER_SAMPLER_Y_UV,
+ GL_SHADER_SAMPLER_Y_XUXV,
+ GL_SHADER_SAMPLER_Y_U_V,
+ GL_SHADER_SAMPLER_NONE,
};
-struct gl_shader
-{
- GLuint program;
- GLuint vertex_shader;
- GLuint fragment_shader;
- GLint texture_uniform[3];
- GLint alpha_uniform;
- GLint trans_uniform;
- const char *vertex_shader_source;
- const char *fragment_shader_source;
+struct gl_shader {
+ GLuint program;
+ GLuint vertex_shader;
+ GLuint fragment_shader;
+ GLint texture_uniform[3];
+ GLint alpha_uniform;
+ GLint trans_uniform;
+ const char *vertex_shader_source;
+ const char *fragment_shader_source;
};
-enum buffer_type
-{
- BUFFER_TYPE_NONE,
- BUFFER_TYPE_SHM,
- BUFFER_TYPE_EGL,
- BUFFER_TYPE_TBM
+enum buffer_type {
+ BUFFER_TYPE_NONE,
+ BUFFER_TYPE_SHM,
+ BUFFER_TYPE_EGL,
+ BUFFER_TYPE_TBM
};
#define MAX_BUFFER_COUNT 3
-struct gl_render_target
-{
- pepper_render_target_t base;
+struct gl_render_target {
+ pepper_render_target_t base;
- EGLSurface surface;
- EGLConfig config;
+ EGLSurface surface;
+ EGLConfig config;
- void *native_window;
+ void *native_window;
- int32_t width;
- int32_t height;
+ int32_t width;
+ int32_t height;
- pepper_mat4_t proj_mat;
+ pepper_mat4_t proj_mat;
- pixman_region32_t damages[MAX_BUFFER_COUNT];
- int32_t damage_index;
+ pixman_region32_t damages[MAX_BUFFER_COUNT];
+ int32_t damage_index;
};
-struct gl_renderer
-{
- pepper_renderer_t base;
+struct gl_renderer {
+ pepper_renderer_t base;
- void *native_display;
+ void *native_display;
- EGLDisplay display;
- EGLContext context;
+ EGLDisplay display;
+ EGLContext context;
- gl_shader_t shaders[GL_SHADER_SAMPLER_NONE];
+ gl_shader_t shaders[GL_SHADER_SAMPLER_NONE];
- /* EGL_EXT_platform. */
- PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window_surface;
+ /* EGL_EXT_platform. */
+ PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window_surface;
- /* EGL extensions. */
- PFNEGLCREATEIMAGEKHRPROC create_image;
- PFNEGLDESTROYIMAGEKHRPROC destroy_image;
+ /* EGL extensions. */
+ PFNEGLCREATEIMAGEKHRPROC create_image;
+ PFNEGLDESTROYIMAGEKHRPROC destroy_image;
#ifdef EGL_EXT_swap_buffers_with_damage
- PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage;
+ PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage;
#endif
- PFNEGLBINDWAYLANDDISPLAYWL bind_display;
- PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
- PFNEGLQUERYWAYLANDBUFFERWL query_buffer;
+ PFNEGLBINDWAYLANDDISPLAYWL bind_display;
+ PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
+ PFNEGLQUERYWAYLANDBUFFERWL query_buffer;
- pepper_bool_t has_buffer_age;
+ pepper_bool_t has_buffer_age;
- /* GL extensions. */
- PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
+ /* GL extensions. */
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
- pepper_bool_t has_read_format_bgra;
- pepper_bool_t has_unpack_subimage;
+ pepper_bool_t has_read_format_bgra;
+ pepper_bool_t has_unpack_subimage;
- gl_shader_t *current_shader;
+ gl_shader_t *current_shader;
- pepper_bool_t clear_background;
+ pepper_bool_t clear_background;
- pepper_bool_t use_clipper;
- struct wl_array vertex_array;
- int triangles;
+ pepper_bool_t use_clipper;
+ struct wl_array vertex_array;
+ int triangles;
};
-struct gl_surface_state
-{
- gl_renderer_t *renderer;
-
- pepper_surface_t *surface;
- pepper_event_listener_t *surface_destroy_listener;
-
- pepper_buffer_t *buffer;
- pepper_event_listener_t *buffer_destroy_listener;
- int buffer_width, buffer_height;
- int buffer_type;
-
- int num_planes;
- GLuint textures[NUM_MAX_PLANES];
- int sampler;
- int y_inverted;
-
- /* EGL buffer type. */
- EGLImageKHR images[NUM_MAX_PLANES];
-
- /* SHM buffer type. */
- struct {
- struct wl_shm_buffer *buffer;
- pepper_bool_t need_full_upload;
- GLenum format;
- GLenum pixel_format;
- int pitch;
- } shm;
-
- /*TBM buffer type*/
- tbm_surface_h tbm_surface;
+struct gl_surface_state {
+ gl_renderer_t *renderer;
+
+ pepper_surface_t *surface;
+ pepper_event_listener_t *surface_destroy_listener;
+
+ pepper_buffer_t *buffer;
+ pepper_event_listener_t *buffer_destroy_listener;
+ int buffer_width, buffer_height;
+ int buffer_type;
+
+ int num_planes;
+ GLuint textures[NUM_MAX_PLANES];
+ int sampler;
+ int y_inverted;
+
+ /* EGL buffer type. */
+ EGLImageKHR images[NUM_MAX_PLANES];
+
+ /* SHM buffer type. */
+ struct {
+ struct wl_shm_buffer *buffer;
+ pepper_bool_t need_full_upload;
+ GLenum format;
+ GLenum pixel_format;
+ int pitch;
+ } shm;
+
+ /*TBM buffer type*/
+ tbm_surface_h tbm_surface;
};
static pepper_bool_t
-init_gl_shader(gl_renderer_t *gr, gl_shader_t *shader, const char *vs, const char *fs)
+init_gl_shader(gl_renderer_t *gr, gl_shader_t *shader, const char *vs,
+ const char *fs)
{
- GLint status;
- char msg[512];
-
- shader->vertex_shader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(shader->vertex_shader, 1, &vs, NULL);
- glCompileShader(shader->vertex_shader);
- glGetShaderiv(shader->vertex_shader, GL_COMPILE_STATUS, &status);
- if (!status)
- {
- glGetShaderInfoLog(shader->vertex_shader, sizeof(msg), NULL, msg);
- PEPPER_ERROR("Failed to compile vertex shader: %s\n", msg);
- return PEPPER_FALSE;
- }
-
- shader->fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(shader->fragment_shader, 1, &fs, NULL);
- glCompileShader(shader->fragment_shader);
- glGetShaderiv(shader->fragment_shader, GL_COMPILE_STATUS, &status);
- if (!status)
- {
- glGetShaderInfoLog(shader->fragment_shader, sizeof(msg), NULL, msg);
- PEPPER_ERROR("Failed to compile fragment shader: %s\n", msg);
- return PEPPER_FALSE;
- }
-
- shader->program = glCreateProgram();
- glAttachShader(shader->program, shader->vertex_shader);
- glAttachShader(shader->program, shader->fragment_shader);
-
- glBindAttribLocation(shader->program, 0, "position");
- glBindAttribLocation(shader->program, 1, "texcoord");
-
- glLinkProgram(shader->program);
- glGetProgramiv(shader->program, GL_LINK_STATUS, &status);
- if (!status)
- {
- glGetProgramInfoLog(shader->program, sizeof(msg), NULL, msg);
- PEPPER_ERROR("Failed to link program: %s\n", msg);
- return PEPPER_FALSE;
- }
-
- shader->texture_uniform[0] = glGetUniformLocation(shader->program, "tex");
- shader->texture_uniform[1] = glGetUniformLocation(shader->program, "tex1");
- shader->texture_uniform[2] = glGetUniformLocation(shader->program, "tex2");
- shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha");
- shader->trans_uniform = glGetUniformLocation(shader->program, "trans");
- shader->vertex_shader_source = vs;
- shader->fragment_shader_source = fs;
-
- return PEPPER_TRUE;
+ GLint status;
+ char msg[512];
+
+ shader->vertex_shader = glCreateShader(GL_VERTEX_SHADER);
+ glShaderSource(shader->vertex_shader, 1, &vs, NULL);
+ glCompileShader(shader->vertex_shader);
+ glGetShaderiv(shader->vertex_shader, GL_COMPILE_STATUS, &status);
+ if (!status) {
+ glGetShaderInfoLog(shader->vertex_shader, sizeof(msg), NULL, msg);
+ PEPPER_ERROR("Failed to compile vertex shader: %s\n", msg);
+ return PEPPER_FALSE;
+ }
+
+ shader->fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
+ glShaderSource(shader->fragment_shader, 1, &fs, NULL);
+ glCompileShader(shader->fragment_shader);
+ glGetShaderiv(shader->fragment_shader, GL_COMPILE_STATUS, &status);
+ if (!status) {
+ glGetShaderInfoLog(shader->fragment_shader, sizeof(msg), NULL, msg);
+ PEPPER_ERROR("Failed to compile fragment shader: %s\n", msg);
+ return PEPPER_FALSE;
+ }
+
+ shader->program = glCreateProgram();
+ glAttachShader(shader->program, shader->vertex_shader);
+ glAttachShader(shader->program, shader->fragment_shader);
+
+ glBindAttribLocation(shader->program, 0, "position");
+ glBindAttribLocation(shader->program, 1, "texcoord");
+
+ glLinkProgram(shader->program);
+ glGetProgramiv(shader->program, GL_LINK_STATUS, &status);
+ if (!status) {
+ glGetProgramInfoLog(shader->program, sizeof(msg), NULL, msg);
+ PEPPER_ERROR("Failed to link program: %s\n", msg);
+ return PEPPER_FALSE;
+ }
+
+ shader->texture_uniform[0] = glGetUniformLocation(shader->program, "tex");
+ shader->texture_uniform[1] = glGetUniformLocation(shader->program, "tex1");
+ shader->texture_uniform[2] = glGetUniformLocation(shader->program, "tex2");
+ shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha");
+ shader->trans_uniform = glGetUniformLocation(shader->program, "trans");
+ shader->vertex_shader_source = vs;
+ shader->fragment_shader_source = fs;
+
+ return PEPPER_TRUE;
}
static void
fini_gl_shaders(gl_renderer_t *gr)
{
- int i;
-
- for (i = 0; i < GL_SHADER_SAMPLER_NONE; i++)
- {
- gl_shader_t *shader = &gr->shaders[i];
- glDeleteShader(shader->vertex_shader);
- glDeleteShader(shader->fragment_shader);
- glDeleteProgram(shader->program);
- memset(shader, 0, sizeof(gl_shader_t));
- }
+ int i;
+
+ for (i = 0; i < GL_SHADER_SAMPLER_NONE; i++) {
+ gl_shader_t *shader = &gr->shaders[i];
+ glDeleteShader(shader->vertex_shader);
+ glDeleteShader(shader->fragment_shader);
+ glDeleteProgram(shader->program);
+ memset(shader, 0, sizeof(gl_shader_t));
+ }
}
static pepper_bool_t
init_gl_shaders(gl_renderer_t *gr)
{
- int i;
-
- for (i = 0; i < GL_SHADER_SAMPLER_NONE; i++)
- {
- if (!init_gl_shader(gr, &gr->shaders[i], vertex_shaders[i], fragment_shaders[i]))
- {
- fini_gl_shaders(gr);
- return PEPPER_FALSE;
- }
- }
-
- return PEPPER_TRUE;
+ int i;
+
+ for (i = 0; i < GL_SHADER_SAMPLER_NONE; i++) {
+ if (!init_gl_shader(gr, &gr->shaders[i], vertex_shaders[i],
+ fragment_shaders[i])) {
+ fini_gl_shaders(gr);
+ return PEPPER_FALSE;
+ }
+ }
+
+ return PEPPER_TRUE;
}
static pepper_bool_t
gl_renderer_use(gl_renderer_t *gr)
{
- gl_render_target_t *gt = (gl_render_target_t *)gr->base.target;
+ gl_render_target_t *gt = (gl_render_target_t *)gr->base.target;
- if (!eglMakeCurrent(gr->display, gt->surface, gt->surface, gr->context))
- return PEPPER_FALSE;
+ if (!eglMakeCurrent(gr->display, gt->surface, gt->surface, gr->context))
+ return PEPPER_FALSE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static void
gl_renderer_destroy(pepper_renderer_t *renderer)
{
- gl_renderer_t *gr = (gl_renderer_t *)renderer;
+ gl_renderer_t *gr = (gl_renderer_t *)renderer;
- wl_array_release(&gr->vertex_array);
+ wl_array_release(&gr->vertex_array);
- fini_gl_shaders(gr);
+ fini_gl_shaders(gr);
- if (gr->unbind_display)
- gr->unbind_display(gr->display, pepper_compositor_get_display(gr->base.compositor));
+ if (gr->unbind_display)
+ gr->unbind_display(gr->display,
+ pepper_compositor_get_display(gr->base.compositor));
- if (gr->display != EGL_NO_DISPLAY)
- eglMakeCurrent(gr->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ if (gr->display != EGL_NO_DISPLAY)
+ eglMakeCurrent(gr->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- if (gr->context != EGL_NO_CONTEXT)
- eglDestroyContext(gr->display, gr->context);
+ if (gr->context != EGL_NO_CONTEXT)
+ eglDestroyContext(gr->display, gr->context);
- if (gr->display != EGL_NO_DISPLAY)
- eglTerminate(gr->display);
+ if (gr->display != EGL_NO_DISPLAY)
+ eglTerminate(gr->display);
- free(gr);
+ free(gr);
}
/* TODO: Similar with pixman renderer. There might be a way of reusing those codes. */
static void
surface_state_destroy_images(gl_surface_state_t *state)
{
- int i;
-
- for (i = 0; i < state->num_planes; i++)
- {
- if (state->images[i] != EGL_NO_IMAGE_KHR)
- {
- state->renderer->destroy_image(state->renderer->display, state->images[i]);
- state->images[i] = EGL_NO_IMAGE_KHR;
- }
- }
+ int i;
+
+ for (i = 0; i < state->num_planes; i++) {
+ if (state->images[i] != EGL_NO_IMAGE_KHR) {
+ state->renderer->destroy_image(state->renderer->display, state->images[i]);
+ state->images[i] = EGL_NO_IMAGE_KHR;
+ }
+ }
}
static void
surface_state_ensure_textures(gl_surface_state_t *state, int num_planes)
{
- int i;
-
- for (i = 0; i < NUM_MAX_PLANES; i++)
- {
- if (state->textures[i] == 0 && i < num_planes)
- {
- glGenTextures(1, &state->textures[i]);
- glBindTexture(GL_TEXTURE_2D, state->textures[i]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- state->shm.need_full_upload = PEPPER_TRUE;
- }
- else if (state->textures[i] != 0 && i >= num_planes)
- {
- glDeleteTextures(1, &state->textures[i]);
- state->textures[i] = 0;
- }
- }
-
- state->num_planes = num_planes;
+ int i;
+
+ for (i = 0; i < NUM_MAX_PLANES; i++) {
+ if (state->textures[i] == 0 && i < num_planes) {
+ glGenTextures(1, &state->textures[i]);
+ glBindTexture(GL_TEXTURE_2D, state->textures[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ state->shm.need_full_upload = PEPPER_TRUE;
+ } else if (state->textures[i] != 0 && i >= num_planes) {
+ glDeleteTextures(1, &state->textures[i]);
+ state->textures[i] = 0;
+ }
+ }
+
+ state->num_planes = num_planes;
}
static void
surface_state_release_buffer(gl_surface_state_t *state)
{
- surface_state_destroy_images(state);
- surface_state_ensure_textures(state, 0);
-
- if (state->buffer)
- {
- pepper_event_listener_remove(state->buffer_destroy_listener);
- state->buffer = NULL;
- }
+ surface_state_destroy_images(state);
+ surface_state_ensure_textures(state, 0);
+
+ if (state->buffer) {
+ pepper_event_listener_remove(state->buffer_destroy_listener);
+ state->buffer = NULL;
+ }
}
static void
surface_state_handle_buffer_destroy(pepper_event_listener_t *listener,
- pepper_object_t *object,
- uint32_t id,
- void *info,
- void *data)
+ pepper_object_t *object,
+ uint32_t id,
+ void *info,
+ void *data)
{
- gl_surface_state_t *state = data;
- surface_state_release_buffer(state);
+ gl_surface_state_t *state = data;
+ surface_state_release_buffer(state);
}
static void
surface_state_handle_surface_destroy(pepper_event_listener_t *listener,
- pepper_object_t *object,
- uint32_t id,
- void *info,
- void *data)
+ pepper_object_t *object,
+ uint32_t id,
+ void *info,
+ void *data)
{
- gl_surface_state_t *state = data;
- surface_state_release_buffer(state);
- pepper_event_listener_remove(state->surface_destroy_listener);
- pepper_object_set_user_data((pepper_object_t *)state->surface, state->renderer, NULL, NULL);
- free(state);
+ gl_surface_state_t *state = data;
+ surface_state_release_buffer(state);
+ pepper_event_listener_remove(state->surface_destroy_listener);
+ pepper_object_set_user_data((pepper_object_t *)state->surface, state->renderer,
+ NULL, NULL);
+ free(state);
}
static gl_surface_state_t *
get_surface_state(pepper_renderer_t *renderer, pepper_surface_t *surface)
{
- gl_surface_state_t *state = pepper_object_get_user_data((pepper_object_t *)surface, renderer);
+ gl_surface_state_t *state = pepper_object_get_user_data((
+ pepper_object_t *)surface, renderer);
- if (!state)
- {
- state = (gl_surface_state_t *)calloc(1, sizeof(gl_surface_state_t));
- if (!state)
- return NULL;
+ if (!state) {
+ state = (gl_surface_state_t *)calloc(1, sizeof(gl_surface_state_t));
+ if (!state)
+ return NULL;
- state->renderer = (gl_renderer_t *)renderer;
- state->surface = surface;
- state->surface_destroy_listener =
- pepper_object_add_event_listener((pepper_object_t *)surface,
- PEPPER_EVENT_OBJECT_DESTROY, 0,
- surface_state_handle_surface_destroy, state);
+ state->renderer = (gl_renderer_t *)renderer;
+ state->surface = surface;
+ state->surface_destroy_listener =
+ pepper_object_add_event_listener((pepper_object_t *)surface,
+ PEPPER_EVENT_OBJECT_DESTROY, 0,
+ surface_state_handle_surface_destroy, state);
- pepper_object_set_user_data((pepper_object_t *)surface, renderer, state, NULL);
- }
+ pepper_object_set_user_data((pepper_object_t *)surface, renderer, state, NULL);
+ }
- return state;
+ return state;
}
static pepper_bool_t
surface_state_attach_shm(gl_surface_state_t *state, pepper_buffer_t *buffer)
{
- struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(pepper_buffer_get_resource(buffer));
- int w, h;
- int sampler;
- GLenum format;
- GLenum pixel_format;
- int pitch;
-
- if (!shm_buffer)
- return PEPPER_FALSE;
-
- switch (wl_shm_buffer_get_format(shm_buffer))
- {
- case WL_SHM_FORMAT_XRGB8888:
- sampler = GL_SHADER_SAMPLER_RGBX;
- format = GL_BGRA_EXT;
- pixel_format = GL_UNSIGNED_BYTE;
- pitch = wl_shm_buffer_get_stride(shm_buffer) / 4;
- break;
- case WL_SHM_FORMAT_ARGB8888:
- sampler = GL_SHADER_SAMPLER_RGBA;
- format = GL_BGRA_EXT;
- pixel_format = GL_UNSIGNED_BYTE;
- pitch = wl_shm_buffer_get_stride(shm_buffer) / 4;
- break;
- case WL_SHM_FORMAT_RGB565:
- sampler = GL_SHADER_SAMPLER_RGBA;
- format = GL_RGB;
- pixel_format = GL_UNSIGNED_SHORT_5_6_5;
- pitch = wl_shm_buffer_get_stride(shm_buffer) / 2;
- break;
- default:
- PEPPER_ERROR("Unknown shm buffer format.\n");
- return PEPPER_FALSE;
- }
-
- w = wl_shm_buffer_get_width(shm_buffer);
- h = wl_shm_buffer_get_height(shm_buffer);
-
- if (state->buffer_type != BUFFER_TYPE_SHM ||
- w != state->buffer_width || h != state->buffer_height ||
- pitch != state->shm.pitch || format != state->shm.format ||
- pixel_format != state->shm.pixel_format)
- {
- /* Don't use glTexSubImage2D() for shm buffers in this case. */
- state->shm.need_full_upload = PEPPER_TRUE;
- }
-
- state->buffer_type = BUFFER_TYPE_SHM;
- state->buffer_width = w;
- state->buffer_height = h;
-
- /* SHM buffer's origin is upper-left. */
- state->y_inverted = 1;
-
- state->shm.buffer = shm_buffer;
- state->shm.format = format;
- state->shm.pixel_format = pixel_format;
- state->shm.pitch = pitch;
-
- state->sampler = sampler;
-
- return PEPPER_TRUE;
+ struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(
+ pepper_buffer_get_resource(buffer));
+ int w, h;
+ int sampler;
+ GLenum format;
+ GLenum pixel_format;
+ int pitch;
+
+ if (!shm_buffer)
+ return PEPPER_FALSE;
+
+ switch (wl_shm_buffer_get_format(shm_buffer)) {
+ case WL_SHM_FORMAT_XRGB8888:
+ sampler = GL_SHADER_SAMPLER_RGBX;
+ format = GL_BGRA_EXT;
+ pixel_format = GL_UNSIGNED_BYTE;
+ pitch = wl_shm_buffer_get_stride(shm_buffer) / 4;
+ break;
+ case WL_SHM_FORMAT_ARGB8888:
+ sampler = GL_SHADER_SAMPLER_RGBA;
+ format = GL_BGRA_EXT;
+ pixel_format = GL_UNSIGNED_BYTE;
+ pitch = wl_shm_buffer_get_stride(shm_buffer) / 4;
+ break;
+ case WL_SHM_FORMAT_RGB565:
+ sampler = GL_SHADER_SAMPLER_RGBA;
+ format = GL_RGB;
+ pixel_format = GL_UNSIGNED_SHORT_5_6_5;
+ pitch = wl_shm_buffer_get_stride(shm_buffer) / 2;
+ break;
+ default:
+ PEPPER_ERROR("Unknown shm buffer format.\n");
+ return PEPPER_FALSE;
+ }
+
+ w = wl_shm_buffer_get_width(shm_buffer);
+ h = wl_shm_buffer_get_height(shm_buffer);
+
+ if (state->buffer_type != BUFFER_TYPE_SHM ||
+ w != state->buffer_width || h != state->buffer_height ||
+ pitch != state->shm.pitch || format != state->shm.format ||
+ pixel_format != state->shm.pixel_format) {
+ /* Don't use glTexSubImage2D() for shm buffers in this case. */
+ state->shm.need_full_upload = PEPPER_TRUE;
+ }
+
+ state->buffer_type = BUFFER_TYPE_SHM;
+ state->buffer_width = w;
+ state->buffer_height = h;
+
+ /* SHM buffer's origin is upper-left. */
+ state->y_inverted = 1;
+
+ state->shm.buffer = shm_buffer;
+ state->shm.format = format;
+ state->shm.pixel_format = pixel_format;
+ state->shm.pitch = pitch;
+
+ state->sampler = sampler;
+
+ return PEPPER_TRUE;
}
#ifdef HAVE_TBM
static pepper_bool_t
surface_state_attach_tbm(gl_surface_state_t *state, pepper_buffer_t *buffer)
{
- tbm_surface_h tbm_surface = wayland_tbm_server_get_surface(NULL, pepper_buffer_get_resource(buffer));
+ tbm_surface_h tbm_surface = wayland_tbm_server_get_surface(NULL,
+ pepper_buffer_get_resource(buffer));
- if (!tbm_surface)
- return PEPPER_FALSE;
+ if (!tbm_surface)
+ return PEPPER_FALSE;
- state->tbm_surface = tbm_surface;
- state->buffer_width = tbm_surface_get_width(tbm_surface);
- state->buffer_height = tbm_surface_get_height(tbm_surface);
- state->y_inverted = 1;
- state->buffer_type = BUFFER_TYPE_TBM;
+ state->tbm_surface = tbm_surface;
+ state->buffer_width = tbm_surface_get_width(tbm_surface);
+ state->buffer_height = tbm_surface_get_height(tbm_surface);
+ state->y_inverted = 1;
+ state->buffer_type = BUFFER_TYPE_TBM;
- return PEPPER_TRUE;;
+ return PEPPER_TRUE;;
}
#endif
static pepper_bool_t
surface_state_attach_egl(gl_surface_state_t *state, pepper_buffer_t *buffer)
{
- gl_renderer_t *gr = state->renderer;
- EGLDisplay display = gr->display;
- struct wl_resource *resource = pepper_buffer_get_resource(buffer);
+ gl_renderer_t *gr = state->renderer;
+ EGLDisplay display = gr->display;
+ struct wl_resource *resource = pepper_buffer_get_resource(buffer);
- gr->query_buffer(display, resource, EGL_WIDTH, &state->buffer_width);
- gr->query_buffer(display, resource, EGL_HEIGHT, &state->buffer_height);
- if (!gr->query_buffer(display, resource, EGL_WAYLAND_Y_INVERTED_WL, &state->y_inverted))
- state->y_inverted = 1;
+ gr->query_buffer(display, resource, EGL_WIDTH, &state->buffer_width);
+ gr->query_buffer(display, resource, EGL_HEIGHT, &state->buffer_height);
+ if (!gr->query_buffer(display, resource, EGL_WAYLAND_Y_INVERTED_WL,
+ &state->y_inverted))
+ state->y_inverted = 1;
- state->buffer_type = BUFFER_TYPE_EGL;
+ state->buffer_type = BUFFER_TYPE_EGL;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_bool_t
-gl_renderer_attach_surface(pepper_renderer_t *renderer, pepper_surface_t *surface, int *w, int *h)
+gl_renderer_attach_surface(pepper_renderer_t *renderer,
+ pepper_surface_t *surface, int *w, int *h)
{
- gl_surface_state_t *state = get_surface_state(renderer, surface);
- pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
+ gl_surface_state_t *state = get_surface_state(renderer, surface);
+ pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
- surface_state_release_buffer(state);
+ surface_state_release_buffer(state);
- if (!buffer)
- {
- state->buffer_width = 0;
- state->buffer_height = 0;
+ if (!buffer) {
+ state->buffer_width = 0;
+ state->buffer_height = 0;
- goto done;
- }
+ goto done;
+ }
- if (surface_state_attach_shm(state, buffer))
- goto done;
+ if (surface_state_attach_shm(state, buffer))
+ goto done;
#ifdef HAVE_TBM
- if (surface_state_attach_tbm(state, buffer))
- goto done;
+ if (surface_state_attach_tbm(state, buffer))
+ goto done;
#endif
- if (surface_state_attach_egl(state, buffer))
- goto done;
+ if (surface_state_attach_egl(state, buffer))
+ goto done;
- PEPPER_ERROR("Not supported buffer type.\n");
- return PEPPER_FALSE;
+ PEPPER_ERROR("Not supported buffer type.\n");
+ return PEPPER_FALSE;
done:
- state->buffer = buffer;
+ state->buffer = buffer;
- if (state->buffer)
- {
- state->buffer_destroy_listener =
- pepper_object_add_event_listener((pepper_object_t *)buffer,
- PEPPER_EVENT_OBJECT_DESTROY, 0,
- surface_state_handle_buffer_destroy, state);
- }
+ if (state->buffer) {
+ state->buffer_destroy_listener =
+ pepper_object_add_event_listener((pepper_object_t *)buffer,
+ PEPPER_EVENT_OBJECT_DESTROY, 0,
+ surface_state_handle_buffer_destroy, state);
+ }
- *w = state->buffer_width;
- *h = state->buffer_height;
+ *w = state->buffer_width;
+ *h = state->buffer_height;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_bool_t
surface_state_flush_egl(gl_surface_state_t *state)
{
- gl_renderer_t *gr = (gl_renderer_t *)state->renderer;
- int num_planes;
- int sampler;
- EGLint attribs[3];
- int texture_format;
- int i;
- EGLDisplay display = gr->display;
- struct wl_resource *resource = pepper_buffer_get_resource(state->buffer);
-
- if (!gr->query_buffer(display, resource, EGL_TEXTURE_FORMAT, &texture_format))
- return PEPPER_FALSE;
-
- switch (texture_format)
- {
- case EGL_TEXTURE_RGB:
- sampler = GL_SHADER_SAMPLER_RGBX;
- num_planes = 1;
- break;
- case EGL_TEXTURE_RGBA:
- sampler = GL_SHADER_SAMPLER_RGBA;
- num_planes = 1;
- break;
- case EGL_TEXTURE_Y_UV_WL:
- sampler = GL_SHADER_SAMPLER_Y_UV;
- num_planes = 2;
- break;
- case EGL_TEXTURE_Y_U_V_WL:
- sampler = GL_SHADER_SAMPLER_Y_U_V;
- num_planes = 3;
- break;
- case EGL_TEXTURE_Y_XUXV_WL:
- sampler = GL_SHADER_SAMPLER_Y_XUXV;
- num_planes = 2;
- break;
- default:
- PEPPER_ERROR("unknown EGL buffer format.\n");
- return PEPPER_FALSE;
- }
-
- if (num_planes != state->num_planes)
- surface_state_ensure_textures(state, num_planes);
-
- attribs[0] = EGL_WAYLAND_PLANE_WL;
- attribs[2] = EGL_NONE;
-
- for (i = 0; i < num_planes; i++)
- {
- attribs[1] = i;
- state->images[i] = gr->create_image(display, NULL, EGL_WAYLAND_BUFFER_WL,
- resource, attribs);
-
- PEPPER_ASSERT(state->images[i] != EGL_NO_IMAGE_KHR);
-
- glActiveTexture(GL_TEXTURE0 + i);
- glBindTexture(GL_TEXTURE_2D, state->textures[i]);
- gr->image_target_texture_2d(GL_TEXTURE_2D, state->images[i]);
- }
-
- state->sampler = sampler;
- return PEPPER_TRUE;
+ gl_renderer_t *gr = (gl_renderer_t *)state->renderer;
+ int num_planes;
+ int sampler;
+ EGLint attribs[3];
+ int texture_format;
+ int i;
+ EGLDisplay display = gr->display;
+ struct wl_resource *resource = pepper_buffer_get_resource(state->buffer);
+
+ if (!gr->query_buffer(display, resource, EGL_TEXTURE_FORMAT, &texture_format))
+ return PEPPER_FALSE;
+
+ switch (texture_format) {
+ case EGL_TEXTURE_RGB:
+ sampler = GL_SHADER_SAMPLER_RGBX;
+ num_planes = 1;
+ break;
+ case EGL_TEXTURE_RGBA:
+ sampler = GL_SHADER_SAMPLER_RGBA;
+ num_planes = 1;
+ break;
+ case EGL_TEXTURE_Y_UV_WL:
+ sampler = GL_SHADER_SAMPLER_Y_UV;
+ num_planes = 2;
+ break;
+ case EGL_TEXTURE_Y_U_V_WL:
+ sampler = GL_SHADER_SAMPLER_Y_U_V;
+ num_planes = 3;
+ break;
+ case EGL_TEXTURE_Y_XUXV_WL:
+ sampler = GL_SHADER_SAMPLER_Y_XUXV;
+ num_planes = 2;
+ break;
+ default:
+ PEPPER_ERROR("unknown EGL buffer format.\n");
+ return PEPPER_FALSE;
+ }
+
+ if (num_planes != state->num_planes)
+ surface_state_ensure_textures(state, num_planes);
+
+ attribs[0] = EGL_WAYLAND_PLANE_WL;
+ attribs[2] = EGL_NONE;
+
+ for (i = 0; i < num_planes; i++) {
+ attribs[1] = i;
+ state->images[i] = gr->create_image(display, NULL, EGL_WAYLAND_BUFFER_WL,
+ resource, attribs);
+
+ PEPPER_ASSERT(state->images[i] != EGL_NO_IMAGE_KHR);
+
+ glActiveTexture(GL_TEXTURE0 + i);
+ glBindTexture(GL_TEXTURE_2D, state->textures[i]);
+ gr->image_target_texture_2d(GL_TEXTURE_2D, state->images[i]);
+ }
+
+ state->sampler = sampler;
+ return PEPPER_TRUE;
}
#ifdef HAVE_TBM
static pepper_bool_t
surface_state_flush_tbm(gl_surface_state_t *state)
{
- gl_renderer_t *gr = (gl_renderer_t *)state->renderer;
- EGLDisplay display = gr->display;
- tbm_surface_h tbm_surface = wayland_tbm_server_get_surface(NULL, pepper_buffer_get_resource(state->buffer));
- int sampler;
+ gl_renderer_t *gr = (gl_renderer_t *)state->renderer;
+ EGLDisplay display = gr->display;
+ tbm_surface_h tbm_surface = wayland_tbm_server_get_surface(NULL,
+ pepper_buffer_get_resource(state->buffer));
+ int sampler;
- const EGLint image_attribs[] =
- {
+ const EGLint image_attribs[] = {
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
EGL_NONE
};
- if (!tbm_surface)
- return PEPPER_FALSE;
-
- switch (tbm_surface_get_format(tbm_surface))
- {
- case TBM_FORMAT_XRGB8888:
- sampler = GL_SHADER_SAMPLER_RGBX;
- break;
- case TBM_FORMAT_ARGB8888:
- sampler = GL_SHADER_SAMPLER_RGBA;
- break;
- case TBM_FORMAT_RGB565:
- sampler = GL_SHADER_SAMPLER_RGBA;
- break;
- default:
- PEPPER_ERROR("Unknown shm buffer format.\n");
- return PEPPER_FALSE;
- }
-
- surface_state_ensure_textures(state, 1);
- state->images[0] = gr->create_image(display, NULL, EGL_NATIVE_SURFACE_TIZEN,
- state->tbm_surface, image_attribs);
- PEPPER_ASSERT(state->images[0] != EGL_NO_IMAGE_KHR);
-
- glActiveTexture(GL_TEXTURE0 + 0);
- glBindTexture(GL_TEXTURE_2D, state->textures[0]);
- gr->image_target_texture_2d(GL_TEXTURE_2D, state->images[0]);
-
- state->sampler = sampler;
-
- return PEPPER_TRUE;
+ if (!tbm_surface)
+ return PEPPER_FALSE;
+
+ switch (tbm_surface_get_format(tbm_surface)) {
+ case TBM_FORMAT_XRGB8888:
+ sampler = GL_SHADER_SAMPLER_RGBX;
+ break;
+ case TBM_FORMAT_ARGB8888:
+ sampler = GL_SHADER_SAMPLER_RGBA;
+ break;
+ case TBM_FORMAT_RGB565:
+ sampler = GL_SHADER_SAMPLER_RGBA;
+ break;
+ default:
+ PEPPER_ERROR("Unknown shm buffer format.\n");
+ return PEPPER_FALSE;
+ }
+
+ surface_state_ensure_textures(state, 1);
+ state->images[0] = gr->create_image(display, NULL, EGL_NATIVE_SURFACE_TIZEN,
+ state->tbm_surface, image_attribs);
+ PEPPER_ASSERT(state->images[0] != EGL_NO_IMAGE_KHR);
+
+ glActiveTexture(GL_TEXTURE0 + 0);
+ glBindTexture(GL_TEXTURE_2D, state->textures[0]);
+ gr->image_target_texture_2d(GL_TEXTURE_2D, state->images[0]);
+
+ state->sampler = sampler;
+
+ return PEPPER_TRUE;
}
#endif
static pepper_bool_t
surface_state_flush_shm(gl_surface_state_t *state)
{
- gl_renderer_t *gr = (gl_renderer_t *)state->renderer;
-
- surface_state_ensure_textures(state, 1);
- glBindTexture(GL_TEXTURE_2D, state->textures[0]);
-
- if (!gr->has_unpack_subimage)
- {
- wl_shm_buffer_begin_access(state->shm.buffer);
- glTexImage2D(GL_TEXTURE_2D, 0, state->shm.format,
- state->buffer_width, state->buffer_height, 0,
- state->shm.format, state->shm.pixel_format,
- wl_shm_buffer_get_data(state->shm.buffer));
- wl_shm_buffer_end_access(state->shm.buffer);
- }
- else if (state->shm.need_full_upload)
- {
- glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, state->shm.pitch);
- glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0);
- glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0);
-
- wl_shm_buffer_begin_access(state->shm.buffer);
- glTexImage2D(GL_TEXTURE_2D, 0, state->shm.format,
- state->buffer_width, state->buffer_height, 0,
- state->shm.format, state->shm.pixel_format,
- wl_shm_buffer_get_data(state->shm.buffer));
- wl_shm_buffer_end_access(state->shm.buffer);
- state->shm.need_full_upload = PEPPER_FALSE;
- }
- else
- {
- int i, nrects;
- pixman_box32_t *rects;
- pixman_region32_t *damage;
-
- damage = pepper_surface_get_damage_region(state->surface);
- rects = pixman_region32_rectangles(damage, &nrects);
-
- glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, state->shm.pitch);
- wl_shm_buffer_begin_access(state->shm.buffer);
- for (i = 0; i < nrects; i++)
- {
- glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, rects[i].x1);
- glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, rects[i].y1);
- glTexSubImage2D(GL_TEXTURE_2D, 0, rects[i].x1, rects[i].y1,
- rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1,
- state->shm.format, state->shm.pixel_format,
- wl_shm_buffer_get_data(state->shm.buffer));
- }
- wl_shm_buffer_end_access(state->shm.buffer);
- }
-
- state->buffer = NULL;
- return PEPPER_TRUE;
+ gl_renderer_t *gr = (gl_renderer_t *)state->renderer;
+
+ surface_state_ensure_textures(state, 1);
+ glBindTexture(GL_TEXTURE_2D, state->textures[0]);
+
+ if (!gr->has_unpack_subimage) {
+ wl_shm_buffer_begin_access(state->shm.buffer);
+ glTexImage2D(GL_TEXTURE_2D, 0, state->shm.format,
+ state->buffer_width, state->buffer_height, 0,
+ state->shm.format, state->shm.pixel_format,
+ wl_shm_buffer_get_data(state->shm.buffer));
+ wl_shm_buffer_end_access(state->shm.buffer);
+ } else if (state->shm.need_full_upload) {
+ glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, state->shm.pitch);
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0);
+ glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0);
+
+ wl_shm_buffer_begin_access(state->shm.buffer);
+ glTexImage2D(GL_TEXTURE_2D, 0, state->shm.format,
+ state->buffer_width, state->buffer_height, 0,
+ state->shm.format, state->shm.pixel_format,
+ wl_shm_buffer_get_data(state->shm.buffer));
+ wl_shm_buffer_end_access(state->shm.buffer);
+ state->shm.need_full_upload = PEPPER_FALSE;
+ } else {
+ int i, nrects;
+ pixman_box32_t *rects;
+ pixman_region32_t *damage;
+
+ damage = pepper_surface_get_damage_region(state->surface);
+ rects = pixman_region32_rectangles(damage, &nrects);
+
+ glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, state->shm.pitch);
+ wl_shm_buffer_begin_access(state->shm.buffer);
+ for (i = 0; i < nrects; i++) {
+ glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, rects[i].x1);
+ glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, rects[i].y1);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, rects[i].x1, rects[i].y1,
+ rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1,
+ state->shm.format, state->shm.pixel_format,
+ wl_shm_buffer_get_data(state->shm.buffer));
+ }
+ wl_shm_buffer_end_access(state->shm.buffer);
+ }
+
+ state->buffer = NULL;
+ return PEPPER_TRUE;
}
static pepper_bool_t
-gl_renderer_flush_surface_damage(pepper_renderer_t *renderer, pepper_surface_t *surface)
+gl_renderer_flush_surface_damage(pepper_renderer_t *renderer,
+ pepper_surface_t *surface)
{
- gl_surface_state_t *state = get_surface_state(renderer, surface);
+ gl_surface_state_t *state = get_surface_state(renderer, surface);
- if (!state->buffer)
- return PEPPER_TRUE;
+ if (!state->buffer)
+ return PEPPER_TRUE;
- if (state->buffer_type == BUFFER_TYPE_SHM)
- return surface_state_flush_shm(state);
+ if (state->buffer_type == BUFFER_TYPE_SHM)
+ return surface_state_flush_shm(state);
#ifdef HAVE_TBM
- else if(state->buffer_type == BUFFER_TYPE_TBM)
- return surface_state_flush_tbm(state);
+ else if (state->buffer_type == BUFFER_TYPE_TBM)
+ return surface_state_flush_tbm(state);
#endif
- else
- return surface_state_flush_egl(state);
+ else
+ return surface_state_flush_egl(state);
}
static pepper_bool_t
gl_renderer_read_pixels(pepper_renderer_t *renderer,
- int x, int y, int w, int h,
- void *pixels, pepper_format_t format)
+ int x, int y, int w, int h,
+ void *pixels, pepper_format_t format)
{
- gl_renderer_t *gr = (gl_renderer_t *)renderer;
- GLenum gl_format;
- GLenum gl_type;
-
- if (!gl_renderer_use(gr))
- return PEPPER_FALSE;
-
- switch (format)
- {
- case PEPPER_FORMAT_ARGB8888:
- gl_format = GL_BGRA_EXT;
- gl_type = GL_UNSIGNED_BYTE;
- break;
- case PEPPER_FORMAT_ABGR8888:
- gl_format = GL_RGBA;
- gl_type = GL_UNSIGNED_BYTE;
- break;
- default:
- return PEPPER_FALSE;
- }
-
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(x, y, w, h, gl_format, gl_type, pixels);
- return PEPPER_TRUE;
+ gl_renderer_t *gr = (gl_renderer_t *)renderer;
+ GLenum gl_format;
+ GLenum gl_type;
+
+ if (!gl_renderer_use(gr))
+ return PEPPER_FALSE;
+
+ switch (format) {
+ case PEPPER_FORMAT_ARGB8888:
+ gl_format = GL_BGRA_EXT;
+ gl_type = GL_UNSIGNED_BYTE;
+ break;
+ case PEPPER_FORMAT_ABGR8888:
+ gl_format = GL_RGBA;
+ gl_type = GL_UNSIGNED_BYTE;
+ break;
+ default:
+ return PEPPER_FALSE;
+ }
+
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ glReadPixels(x, y, w, h, gl_format, gl_type, pixels);
+ return PEPPER_TRUE;
}
static void
gl_shader_use(gl_renderer_t *gr, gl_shader_t *shader)
{
- if (shader != gr->current_shader)
- {
- glUseProgram(shader->program);
- gr->current_shader = shader;
- }
+ if (shader != gr->current_shader) {
+ glUseProgram(shader->program);
+ gr->current_shader = shader;
+ }
}
static void
output(pepper_vec2_t *vertex, int *out_len, pepper_vec2_t *out_vertices)
{
- out_vertices[*out_len].x = vertex->x;
- out_vertices[*out_len].y = vertex->y;
- *out_len += 1;
+ out_vertices[*out_len].x = vertex->x;
+ out_vertices[*out_len].y = vertex->y;
+ *out_len += 1;
}
static pepper_bool_t
-inside(pepper_vec2_t *vertex, pepper_vec2_t *clip_start, pepper_vec2_t *clip_end)
+inside(pepper_vec2_t *vertex, pepper_vec2_t *clip_start,
+ pepper_vec2_t *clip_end)
{
- if ((clip_start->y > clip_end->y) && (vertex->x >= clip_start->x)) /* left */
- return PEPPER_TRUE;
+ if ((clip_start->y > clip_end->y) && (vertex->x >= clip_start->x)) /* left */
+ return PEPPER_TRUE;
- if ((clip_start->x < clip_end->x) && (vertex->y >= clip_start->y)) /* top */
- return PEPPER_TRUE;
+ if ((clip_start->x < clip_end->x) && (vertex->y >= clip_start->y)) /* top */
+ return PEPPER_TRUE;
- if ((clip_start->y < clip_end->y) && (vertex->x <= clip_start->x)) /* right */
- return PEPPER_TRUE;
+ if ((clip_start->y < clip_end->y) && (vertex->x <= clip_start->x)) /* right */
+ return PEPPER_TRUE;
- if ((clip_start->x > clip_end->x) && (vertex->y <= clip_start->y)) /* bottom */
- return PEPPER_TRUE;
+ if ((clip_start->x > clip_end->x) && (vertex->y <= clip_start->y)) /* bottom */
+ return PEPPER_TRUE;
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
static void
intersect(pepper_vec2_t *vertex1, pepper_vec2_t *vertex2,
- pepper_vec2_t *clip_start, pepper_vec2_t *clip_end, pepper_vec2_t *out_vertex)
+ pepper_vec2_t *clip_start, pepper_vec2_t *clip_end, pepper_vec2_t *out_vertex)
{
- if (clip_start->x == clip_end->x)
- {
- out_vertex->x = clip_start->x;
- out_vertex->y = vertex1->y + (clip_start->x - vertex1->x) * (vertex2->y - vertex1->y)
- / (vertex2->x - vertex1->x);
- }
- else
- {
- out_vertex->x = vertex1->x + (clip_start->y - vertex1->y) * (vertex2->x - vertex1->x)
- / (vertex2->y - vertex1->y);
- out_vertex->y = clip_start->y;
- }
+ if (clip_start->x == clip_end->x) {
+ out_vertex->x = clip_start->x;
+ out_vertex->y = vertex1->y + (clip_start->x - vertex1->x) *
+ (vertex2->y - vertex1->y)
+ / (vertex2->x - vertex1->x);
+ } else {
+ out_vertex->x = vertex1->x + (clip_start->y - vertex1->y) *
+ (vertex2->x - vertex1->x)
+ / (vertex2->y - vertex1->y);
+ out_vertex->y = clip_start->y;
+ }
}
static void
-clip_line(pepper_vec2_t *in_vertices, pepper_vec2_t *out_vertices, int in_len, int *out_len,
- pepper_vec2_t *clip_start, pepper_vec2_t *clip_end)
+clip_line(pepper_vec2_t *in_vertices, pepper_vec2_t *out_vertices, int in_len,
+ int *out_len,
+ pepper_vec2_t *clip_start, pepper_vec2_t *clip_end)
{
- int i;
- pepper_vec2_t *vs, *ve;
- pepper_vec2_t vi;
-
- *out_len = 0;
- vs = &in_vertices[in_len - 1];
-
- for (i = 0; i < in_len; i++)
- {
- ve = &in_vertices[i];
- if (inside(vs, clip_start, clip_end))
- {
- if (inside(ve, clip_start, clip_end))
- {
- output(ve, out_len, out_vertices);
- }
- else
- {
- intersect(vs, ve, clip_start, clip_end, &vi);
- output(&vi, out_len, out_vertices);
- }
- }
- else
- {
- if (inside(ve, clip_start, clip_end))
- {
- intersect(vs, ve, clip_start, clip_end, &vi);
- output(&vi, out_len, out_vertices);
- output(ve, out_len, out_vertices);
- }
- }
- vs = ve;
- }
+ int i;
+ pepper_vec2_t *vs, *ve;
+ pepper_vec2_t vi;
+
+ *out_len = 0;
+ vs = &in_vertices[in_len - 1];
+
+ for (i = 0; i < in_len; i++) {
+ ve = &in_vertices[i];
+ if (inside(vs, clip_start, clip_end)) {
+ if (inside(ve, clip_start, clip_end)) {
+ output(ve, out_len, out_vertices);
+ } else {
+ intersect(vs, ve, clip_start, clip_end, &vi);
+ output(&vi, out_len, out_vertices);
+ }
+ } else {
+ if (inside(ve, clip_start, clip_end)) {
+ intersect(vs, ve, clip_start, clip_end, &vi);
+ output(&vi, out_len, out_vertices);
+ output(ve, out_len, out_vertices);
+ }
+ }
+ vs = ve;
+ }
}
static void
-clip(pepper_vec2_t *vertices, int *len, pixman_box32_t *clip_rect, pepper_bool_t is_rect)
+clip(pepper_vec2_t *vertices, int *len, pixman_box32_t *clip_rect,
+ pepper_bool_t is_rect)
{
- if (is_rect)
- {
- int i;
-
- if ((vertices[0].x >= clip_rect->x2) || (vertices[2].x <= clip_rect->x1) ||
- (vertices[0].y >= clip_rect->y2) || (vertices[2].y <= clip_rect->y1))
- {
- *len = 0;
- return;
- }
-
- for (i = 0; i < *len; i++)
- {
- vertices[i].x = vertices[i].x > clip_rect->x1 ? vertices[i].x : clip_rect->x1;
- vertices[i].x = vertices[i].x < clip_rect->x2 ? vertices[i].x : clip_rect->x2;
- vertices[i].y = vertices[i].y > clip_rect->y1 ? vertices[i].y : clip_rect->y1;
- vertices[i].y = vertices[i].y < clip_rect->y2 ? vertices[i].y : clip_rect->y2;
- }
- }
- else
- {
- pepper_vec2_t cs, ce;
- pepper_vec2_t tmp[8];
- int tmp_len;
-
- /* left */
- cs.x = ce.x = clip_rect->x1;
- cs.y = clip_rect->y2;
- ce.y = clip_rect->y1;
- clip_line(vertices, tmp, *len, &tmp_len, &cs, &ce);
-
- /* top */
- cs.x = clip_rect->x1;
- ce.x = clip_rect->x2;
- cs.y = ce.y = clip_rect->y1;
- clip_line(tmp, vertices, tmp_len, len, &cs, &ce);
-
- /* right */
- cs.x = ce.x = clip_rect->x2;
- cs.y = clip_rect->y1;
- ce.y = clip_rect->y2;
- clip_line(vertices, tmp, *len, &tmp_len, &cs, &ce);
-
- /* bottom */
- cs.x = clip_rect->x2;
- ce.x = clip_rect->x1;
- cs.y = ce.y = clip_rect->y2;
- clip_line(tmp, vertices, tmp_len, len, &cs, &ce);
- }
+ if (is_rect) {
+ int i;
+
+ if ((vertices[0].x >= clip_rect->x2) || (vertices[2].x <= clip_rect->x1) ||
+ (vertices[0].y >= clip_rect->y2) || (vertices[2].y <= clip_rect->y1)) {
+ *len = 0;
+ return;
+ }
+
+ for (i = 0; i < *len; i++) {
+ vertices[i].x = vertices[i].x > clip_rect->x1 ? vertices[i].x : clip_rect->x1;
+ vertices[i].x = vertices[i].x < clip_rect->x2 ? vertices[i].x : clip_rect->x2;
+ vertices[i].y = vertices[i].y > clip_rect->y1 ? vertices[i].y : clip_rect->y1;
+ vertices[i].y = vertices[i].y < clip_rect->y2 ? vertices[i].y : clip_rect->y2;
+ }
+ } else {
+ pepper_vec2_t cs, ce;
+ pepper_vec2_t tmp[8];
+ int tmp_len;
+
+ /* left */
+ cs.x = ce.x = clip_rect->x1;
+ cs.y = clip_rect->y2;
+ ce.y = clip_rect->y1;
+ clip_line(vertices, tmp, *len, &tmp_len, &cs, &ce);
+
+ /* top */
+ cs.x = clip_rect->x1;
+ ce.x = clip_rect->x2;
+ cs.y = ce.y = clip_rect->y1;
+ clip_line(tmp, vertices, tmp_len, len, &cs, &ce);
+
+ /* right */
+ cs.x = ce.x = clip_rect->x2;
+ cs.y = clip_rect->y1;
+ ce.y = clip_rect->y2;
+ clip_line(vertices, tmp, *len, &tmp_len, &cs, &ce);
+
+ /* bottom */
+ cs.x = clip_rect->x2;
+ ce.x = clip_rect->x1;
+ cs.y = ce.y = clip_rect->y2;
+ clip_line(tmp, vertices, tmp_len, len, &cs, &ce);
+ }
}
static float
float_difference(float a, float b)
{
- static const float max_diff = 4.0f * FLT_MIN;
- static const float max_rel_diff = 4.0e-5;
+ static const float max_diff = 4.0f * FLT_MIN;
+ static const float max_rel_diff = 4.0e-5;
- float diff = a - b;
- float adiff = fabsf(diff);
+ float diff = a - b;
+ float adiff = fabsf(diff);
- if (adiff <= max_diff)
- return 0.0f;
+ if (adiff <= max_diff)
+ return 0.0f;
- a = fabsf(a);
- b = fabsf(b);
- if (adiff <= (a > b ? a : b) * max_rel_diff)
- return 0.0f;
+ a = fabsf(a);
+ b = fabsf(b);
+ if (adiff <= (a > b ? a : b) * max_rel_diff)
+ return 0.0f;
- return diff;
+ return diff;
}
static void
-calc_vertices(gl_renderer_t *gr, gl_surface_state_t *state, pepper_render_item_t *node,
- pixman_region32_t *region, pixman_region32_t *surface_region)
+calc_vertices(gl_renderer_t *gr, gl_surface_state_t *state,
+ pepper_render_item_t *node,
+ pixman_region32_t *region, pixman_region32_t *surface_region)
{
- int i, j, k, n;
- int len;
- pepper_vec2_t vertices[8];
- pepper_vec2_t texcoords[8];
- pepper_mat4_t *inverse = &node->inverse;
- pepper_mat4_t *transform = &node->transform;
-
- int nrects, surface_nrects;
- pixman_box32_t *rects, *surface_rects;
-
- GLfloat *vertex_array;
-
- surface_rects = pixman_region32_rectangles(surface_region, &surface_nrects);
- rects = pixman_region32_rectangles(region, &nrects);
- vertex_array = wl_array_add(&gr->vertex_array,
- surface_nrects * nrects * (8 - 2) * 3 * 2 * 2 * sizeof(GLfloat));
- gr->triangles = 0;
-
- for (n = 0; n < surface_nrects; n++)
- {
- for (i = 0; i < nrects; i++)
- {
- vertices[0].x = surface_rects[n].x1;
- vertices[0].y = surface_rects[n].y1;
- vertices[1].x = surface_rects[n].x2;
- vertices[1].y = surface_rects[n].y1;
- vertices[2].x = surface_rects[n].x2;
- vertices[2].y = surface_rects[n].y2;
- vertices[3].x = surface_rects[n].x1;
- vertices[3].y = surface_rects[n].y2;
-
- len = 4;
- for (j = 0; j < len; j++)
- pepper_mat4_transform_vec2(transform, &vertices[j]);
-
- clip(vertices, &len, &rects[i], (transform->flags <= PEPPER_MATRIX_TRANSLATE));
- if (len == 0)
- continue;
-
- memcpy(texcoords, vertices, sizeof(vertices));
- for (j = 0; j < len; j++)
- {
- double x, y;
- pepper_mat4_transform_vec2(inverse, &texcoords[j]);
- pepper_coordinates_surface_to_buffer(pepper_view_get_surface(node->view),
- texcoords[j].x, texcoords[j].y, &x, &y);
- if (!state->y_inverted)
- y = state->buffer_height - y;
- texcoords[j].x = x / state->buffer_width;
- texcoords[j].y = y / state->buffer_height;
- }
-
- for (j = 1, k = 1; j < len; j++)
- {
- if ((float_difference((float)vertices[j - 1].x, (float)vertices[j].x) == 0.0f) &&
- (float_difference((float)vertices[j - 1].y, (float)vertices[j].y) == 0.0f))
- continue;
-
- if (j != k)
- {
- vertices[k].x = vertices[j].x;
- vertices[k].y = vertices[j].y;
- texcoords[k].x = texcoords[j].x;
- texcoords[k].y = texcoords[j].y;
- }
- k++;
- }
-
- if ((float_difference((float)vertices[len - 1].x, (float)vertices[0].x) == 0.0f) &&
- (float_difference((float)vertices[len - 1].y, (float)vertices[0].y) == 0.0f))
- k--;
-
- for (j = 2; j < k; j++)
- {
- *(vertex_array++) = (GLfloat)vertices[0].x;
- *(vertex_array++) = (GLfloat)vertices[0].y;
- *(vertex_array++) = (GLfloat)texcoords[0].x;
- *(vertex_array++) = (GLfloat)texcoords[0].y;
- *(vertex_array++) = (GLfloat)vertices[j - 1].x;
- *(vertex_array++) = (GLfloat)vertices[j - 1].y;
- *(vertex_array++) = (GLfloat)texcoords[j - 1].x;
- *(vertex_array++) = (GLfloat)texcoords[j - 1].y;
- *(vertex_array++) = (GLfloat)vertices[j].x;
- *(vertex_array++) = (GLfloat)vertices[j].y;
- *(vertex_array++) = (GLfloat)texcoords[j].x;
- *(vertex_array++) = (GLfloat)texcoords[j].y;
- gr->triangles++;
- }
- }
- }
+ int i, j, k, n;
+ int len;
+ pepper_vec2_t vertices[8];
+ pepper_vec2_t texcoords[8];
+ pepper_mat4_t *inverse = &node->inverse;
+ pepper_mat4_t *transform = &node->transform;
+
+ int nrects, surface_nrects;
+ pixman_box32_t *rects, *surface_rects;
+
+ GLfloat *vertex_array;
+
+ surface_rects = pixman_region32_rectangles(surface_region, &surface_nrects);
+ rects = pixman_region32_rectangles(region, &nrects);
+ vertex_array = wl_array_add(&gr->vertex_array,
+ surface_nrects * nrects * (8 - 2) * 3 * 2 * 2 * sizeof(GLfloat));
+ gr->triangles = 0;
+
+ for (n = 0; n < surface_nrects; n++) {
+ for (i = 0; i < nrects; i++) {
+ vertices[0].x = surface_rects[n].x1;
+ vertices[0].y = surface_rects[n].y1;
+ vertices[1].x = surface_rects[n].x2;
+ vertices[1].y = surface_rects[n].y1;
+ vertices[2].x = surface_rects[n].x2;
+ vertices[2].y = surface_rects[n].y2;
+ vertices[3].x = surface_rects[n].x1;
+ vertices[3].y = surface_rects[n].y2;
+
+ len = 4;
+ for (j = 0; j < len; j++)
+ pepper_mat4_transform_vec2(transform, &vertices[j]);
+
+ clip(vertices, &len, &rects[i], (transform->flags <= PEPPER_MATRIX_TRANSLATE));
+ if (len == 0)
+ continue;
+
+ memcpy(texcoords, vertices, sizeof(vertices));
+ for (j = 0; j < len; j++) {
+ double x, y;
+ pepper_mat4_transform_vec2(inverse, &texcoords[j]);
+ pepper_coordinates_surface_to_buffer(pepper_view_get_surface(node->view),
+ texcoords[j].x, texcoords[j].y, &x, &y);
+ if (!state->y_inverted)
+ y = state->buffer_height - y;
+ texcoords[j].x = x / state->buffer_width;
+ texcoords[j].y = y / state->buffer_height;
+ }
+
+ for (j = 1, k = 1; j < len; j++) {
+ if ((float_difference((float)vertices[j - 1].x,
+ (float)vertices[j].x) == 0.0f) &&
+ (float_difference((float)vertices[j - 1].y, (float)vertices[j].y) == 0.0f))
+ continue;
+
+ if (j != k) {
+ vertices[k].x = vertices[j].x;
+ vertices[k].y = vertices[j].y;
+ texcoords[k].x = texcoords[j].x;
+ texcoords[k].y = texcoords[j].y;
+ }
+ k++;
+ }
+
+ if ((float_difference((float)vertices[len - 1].x,
+ (float)vertices[0].x) == 0.0f) &&
+ (float_difference((float)vertices[len - 1].y, (float)vertices[0].y) == 0.0f))
+ k--;
+
+ for (j = 2; j < k; j++) {
+ *(vertex_array++) = (GLfloat)vertices[0].x;
+ *(vertex_array++) = (GLfloat)vertices[0].y;
+ *(vertex_array++) = (GLfloat)texcoords[0].x;
+ *(vertex_array++) = (GLfloat)texcoords[0].y;
+ *(vertex_array++) = (GLfloat)vertices[j - 1].x;
+ *(vertex_array++) = (GLfloat)vertices[j - 1].y;
+ *(vertex_array++) = (GLfloat)texcoords[j - 1].x;
+ *(vertex_array++) = (GLfloat)texcoords[j - 1].y;
+ *(vertex_array++) = (GLfloat)vertices[j].x;
+ *(vertex_array++) = (GLfloat)vertices[j].y;
+ *(vertex_array++) = (GLfloat)texcoords[j].x;
+ *(vertex_array++) = (GLfloat)texcoords[j].y;
+ gr->triangles++;
+ }
+ }
+ }
}
static void
-repaint_region_clip(gl_renderer_t *gr, gl_surface_state_t *state, pepper_render_item_t *node,
- pixman_region32_t *damage, pixman_region32_t *surface_region)
+repaint_region_clip(gl_renderer_t *gr, gl_surface_state_t *state,
+ pepper_render_item_t *node,
+ pixman_region32_t *damage, pixman_region32_t *surface_region)
{
- GLfloat *vertex_array;
+ GLfloat *vertex_array;
- calc_vertices(gr, state, node, damage, surface_region);
- vertex_array = gr->vertex_array.data;
+ calc_vertices(gr, state, node, damage, surface_region);
+ vertex_array = gr->vertex_array.data;
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), &vertex_array[0]);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), &vertex_array[2]);
- glEnableVertexAttribArray(1);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
+ &vertex_array[0]);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
+ &vertex_array[2]);
+ glEnableVertexAttribArray(1);
- glDrawArrays(GL_TRIANGLES, 0, gr->triangles * 3);
+ glDrawArrays(GL_TRIANGLES, 0, gr->triangles * 3);
- gr->vertex_array.size = 0;
+ gr->vertex_array.size = 0;
}
static void
repaint_view_clip(pepper_renderer_t *renderer, pepper_output_t *output,
- pepper_render_item_t *node, pixman_region32_t *damage)
+ pepper_render_item_t *node, pixman_region32_t *damage)
{
- gl_renderer_t *gr = (gl_renderer_t *)renderer;
- gl_render_target_t *gt = (gl_render_target_t *)renderer->target;
-
- pepper_surface_t *surface = pepper_view_get_surface(node->view);
- gl_surface_state_t *state = get_surface_state(renderer, surface);
-
- gl_shader_t *shader;
- pixman_region32_t repaint;
- pixman_region32_t surface_blend;
- pixman_region32_t *surface_opaque;
-
- pixman_region32_init(&repaint);
- pixman_region32_intersect(&repaint, &node->visible_region, damage);
-
- if (pixman_region32_not_empty(&repaint))
- {
- int32_t i, w, h;
- float trans[16];
- GLint filter;
-
- pepper_surface_get_size(surface, &w, &h);
- surface_opaque = pepper_surface_get_opaque_region(surface);
- pixman_region32_init_rect(&surface_blend, 0, 0, w, h);
- pixman_region32_subtract(&surface_blend, &surface_blend, surface_opaque);
-
- for (i = 0; i < 16; i++)
- trans[i] = (float)gt->proj_mat.m[i];
-
- filter = (node->transform.flags <= PEPPER_MATRIX_TRANSLATE) ? GL_NEAREST : GL_LINEAR;
- for (i = 0; i < state->num_planes; i++)
- {
- glActiveTexture(GL_TEXTURE0 + i);
- glBindTexture(GL_TEXTURE_2D, state->textures[i]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
- }
-
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- if (pixman_region32_not_empty(surface_opaque))
- {
- if (state->sampler == GL_SHADER_SAMPLER_RGBA)
- shader = &gr->shaders[GL_SHADER_SAMPLER_RGBX];
- else
- shader = &gr->shaders[state->sampler];
-
- gl_shader_use(gr, shader);
-
- glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
- for (i = 0; i < state->num_planes; i++)
- glUniform1i(shader->texture_uniform[i], i);
- glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
-
- repaint_region_clip(gr, state, node, &repaint, surface_opaque);
- }
-
- if (pixman_region32_not_empty(&surface_blend))
- {
- shader = &gr->shaders[state->sampler];
-
- gl_shader_use(gr, shader);
-
- glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
- for (i = 0; i < state->num_planes; i++)
- glUniform1i(shader->texture_uniform[i], i);
- glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
-
- glEnable(GL_BLEND);
- repaint_region_clip(gr, state, node, &repaint, &surface_blend);
- glDisable(GL_BLEND);
- }
-
- pixman_region32_fini(&surface_blend);
- }
-
- pixman_region32_fini(&repaint);
+ gl_renderer_t *gr = (gl_renderer_t *)renderer;
+ gl_render_target_t *gt = (gl_render_target_t *)renderer->target;
+
+ pepper_surface_t *surface = pepper_view_get_surface(node->view);
+ gl_surface_state_t *state = get_surface_state(renderer, surface);
+
+ gl_shader_t *shader;
+ pixman_region32_t repaint;
+ pixman_region32_t surface_blend;
+ pixman_region32_t *surface_opaque;
+
+ pixman_region32_init(&repaint);
+ pixman_region32_intersect(&repaint, &node->visible_region, damage);
+
+ if (pixman_region32_not_empty(&repaint)) {
+ int32_t i, w, h;
+ float trans[16];
+ GLint filter;
+
+ pepper_surface_get_size(surface, &w, &h);
+ surface_opaque = pepper_surface_get_opaque_region(surface);
+ pixman_region32_init_rect(&surface_blend, 0, 0, w, h);
+ pixman_region32_subtract(&surface_blend, &surface_blend, surface_opaque);
+
+ for (i = 0; i < 16; i++)
+ trans[i] = (float)gt->proj_mat.m[i];
+
+ filter = (node->transform.flags <= PEPPER_MATRIX_TRANSLATE) ? GL_NEAREST :
+ GL_LINEAR;
+ for (i = 0; i < state->num_planes; i++) {
+ glActiveTexture(GL_TEXTURE0 + i);
+ glBindTexture(GL_TEXTURE_2D, state->textures[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
+ }
+
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ if (pixman_region32_not_empty(surface_opaque)) {
+ if (state->sampler == GL_SHADER_SAMPLER_RGBA)
+ shader = &gr->shaders[GL_SHADER_SAMPLER_RGBX];
+ else
+ shader = &gr->shaders[state->sampler];
+
+ gl_shader_use(gr, shader);
+
+ glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
+ for (i = 0; i < state->num_planes; i++)
+ glUniform1i(shader->texture_uniform[i], i);
+ glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
+
+ repaint_region_clip(gr, state, node, &repaint, surface_opaque);
+ }
+
+ if (pixman_region32_not_empty(&surface_blend)) {
+ shader = &gr->shaders[state->sampler];
+
+ gl_shader_use(gr, shader);
+
+ glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
+ for (i = 0; i < state->num_planes; i++)
+ glUniform1i(shader->texture_uniform[i], i);
+ glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
+
+ glEnable(GL_BLEND);
+ repaint_region_clip(gr, state, node, &repaint, &surface_blend);
+ glDisable(GL_BLEND);
+ }
+
+ pixman_region32_fini(&surface_blend);
+ }
+
+ pixman_region32_fini(&repaint);
}
static void
-set_vertex(gl_surface_state_t *state, int32_t sx, int32_t sy, GLfloat *vertex_array)
+set_vertex(gl_surface_state_t *state, int32_t sx, int32_t sy,
+ GLfloat *vertex_array)
{
- double x, y;
+ double x, y;
- pepper_coordinates_surface_to_buffer(state->surface, sx, sy, &x, &y);
+ pepper_coordinates_surface_to_buffer(state->surface, sx, sy, &x, &y);
- if (!state->y_inverted)
- y = state->buffer_height - y;
+ if (!state->y_inverted)
+ y = state->buffer_height - y;
- vertex_array[ 0] = sx;
- vertex_array[ 1] = sy;
- vertex_array[ 2] = (GLfloat)x / state->buffer_width;
- vertex_array[ 3] = (GLfloat)y / state->buffer_height;
+ vertex_array[ 0] = sx;
+ vertex_array[ 1] = sy;
+ vertex_array[ 2] = (GLfloat)x / state->buffer_width;
+ vertex_array[ 3] = (GLfloat)y / state->buffer_height;
}
static void
repaint_region_scissor(gl_renderer_t *gr, gl_surface_state_t *state,
- pixman_region32_t *damage, pixman_region32_t *surface_region)
+ pixman_region32_t *damage, pixman_region32_t *surface_region)
{
- int i, j;
- int nrects, surface_nrects;
- pixman_box32_t *rects, *surface_rects;
- GLfloat vertex_array[16];
- gl_render_target_t *gt = (gl_render_target_t *)gr->base.target;
-
- surface_rects = pixman_region32_rectangles(surface_region, &surface_nrects);
-
- for (i = 0; i < surface_nrects; i++)
- {
- set_vertex(state, surface_rects[i].x1, surface_rects[i].y1, &vertex_array[0]);
- set_vertex(state, surface_rects[i].x2, surface_rects[i].y1, &vertex_array[4]);
- set_vertex(state, surface_rects[i].x2, surface_rects[i].y2, &vertex_array[8]);
- set_vertex(state, surface_rects[i].x1, surface_rects[i].y2, &vertex_array[12]);
-
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), &vertex_array[0]);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), &vertex_array[2]);
- glEnableVertexAttribArray(1);
-
- rects = pixman_region32_rectangles(damage, &nrects);
- for (j = 0; j < nrects; j++)
- {
- glScissor(rects[j].x1, gt->height - rects[j].y2,
- rects[j].x2 - rects[j].x1, rects[j].y2 - rects[j].y1);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- }
- }
+ int i, j;
+ int nrects, surface_nrects;
+ pixman_box32_t *rects, *surface_rects;
+ GLfloat vertex_array[16];
+ gl_render_target_t *gt = (gl_render_target_t *)gr->base.target;
+
+ surface_rects = pixman_region32_rectangles(surface_region, &surface_nrects);
+
+ for (i = 0; i < surface_nrects; i++) {
+ set_vertex(state, surface_rects[i].x1, surface_rects[i].y1, &vertex_array[0]);
+ set_vertex(state, surface_rects[i].x2, surface_rects[i].y1, &vertex_array[4]);
+ set_vertex(state, surface_rects[i].x2, surface_rects[i].y2, &vertex_array[8]);
+ set_vertex(state, surface_rects[i].x1, surface_rects[i].y2, &vertex_array[12]);
+
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
+ &vertex_array[0]);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
+ &vertex_array[2]);
+ glEnableVertexAttribArray(1);
+
+ rects = pixman_region32_rectangles(damage, &nrects);
+ for (j = 0; j < nrects; j++) {
+ glScissor(rects[j].x1, gt->height - rects[j].y2,
+ rects[j].x2 - rects[j].x1, rects[j].y2 - rects[j].y1);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ }
+ }
}
static void
repaint_view_scissor(pepper_renderer_t *renderer, pepper_output_t *output,
- pepper_render_item_t *node, pixman_region32_t *damage)
+ pepper_render_item_t *node, pixman_region32_t *damage)
{
- gl_renderer_t *gr = (gl_renderer_t *)renderer;
- gl_render_target_t *gt = (gl_render_target_t *)renderer->target;
-
- pepper_surface_t *surface = pepper_view_get_surface(node->view);
- gl_surface_state_t *state = get_surface_state(renderer, surface);
-
- gl_shader_t *shader;
- pixman_region32_t repaint;
- pixman_region32_t surface_blend;
- pixman_region32_t *surface_opaque;
-
- int i, w, h;
- float trans[16];
- GLint filter;
-
- pixman_region32_init(&repaint);
- pixman_region32_intersect(&repaint, &node->visible_region, damage);
-
- if (!pixman_region32_not_empty(&repaint))
- goto done;
-
- if (node->transform.flags <= PEPPER_MATRIX_TRANSLATE)
- {
- double tx, ty, tz;
-
- tx = node->transform.m[12];
- ty = node->transform.m[13];
- tz = node->transform.m[14];
-
- for (i = 0; i < 16; i++)
- trans[i] = (float)gt->proj_mat.m[i];
-
- trans[12] += trans[0] * tx + trans[4] * ty + trans[8] * tz;
- trans[13] += trans[1] * tx + trans[5] * ty + trans[9] * tz;
- trans[14] += trans[2] * tx + trans[6] * ty + trans[10] * tz;
- trans[15] += trans[3] * tx + trans[7] * ty + trans[11] * tz;
- }
- else
- {
- pepper_mat4_t tmp;
- pepper_mat4_multiply(&tmp, >->proj_mat, &node->transform);
- for (i = 0; i < 16; i++)
- trans[i] = (float)tmp.m[i];
- }
-
- filter = (node->transform.flags <= PEPPER_MATRIX_TRANSLATE) ? GL_NEAREST : GL_LINEAR;
- for (i = 0; i < state->num_planes; i++)
- {
- glActiveTexture(GL_TEXTURE0 + i);
- glBindTexture(GL_TEXTURE_2D, state->textures[i]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
- }
-
- pepper_surface_get_size(surface, &w, &h);
- surface_opaque = pepper_surface_get_opaque_region(surface);
- pixman_region32_init_rect(&surface_blend, 0, 0, w, h);
- pixman_region32_subtract(&surface_blend, &surface_blend, surface_opaque);
-
- glEnable(GL_SCISSOR_TEST);
-
- if (pixman_region32_not_empty(surface_opaque))
- {
- if (state->sampler == GL_SHADER_SAMPLER_RGBA)
- shader = &gr->shaders[GL_SHADER_SAMPLER_RGBX];
- else
- shader = &gr->shaders[state->sampler];
-
- gl_shader_use(gr, shader);
-
- glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
- for (i = 0; i < state->num_planes; i++)
- glUniform1i(shader->texture_uniform[i], i);
- glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
-
- repaint_region_scissor(gr, state, &repaint, surface_opaque);
- }
-
- if (pixman_region32_not_empty(&surface_blend))
- {
- shader = &gr->shaders[state->sampler];
- gl_shader_use(gr, shader);
-
- glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
- for (i = 0; i < state->num_planes; i++)
- glUniform1i(shader->texture_uniform[i], i);
- glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
-
- glEnable(GL_BLEND);
- repaint_region_scissor(gr, state, &repaint, &surface_blend);
- glDisable(GL_BLEND);
- }
-
- glDisable(GL_SCISSOR_TEST);
- pixman_region32_fini(&surface_blend);
+ gl_renderer_t *gr = (gl_renderer_t *)renderer;
+ gl_render_target_t *gt = (gl_render_target_t *)renderer->target;
+
+ pepper_surface_t *surface = pepper_view_get_surface(node->view);
+ gl_surface_state_t *state = get_surface_state(renderer, surface);
+
+ gl_shader_t *shader;
+ pixman_region32_t repaint;
+ pixman_region32_t surface_blend;
+ pixman_region32_t *surface_opaque;
+
+ int i, w, h;
+ float trans[16];
+ GLint filter;
+
+ pixman_region32_init(&repaint);
+ pixman_region32_intersect(&repaint, &node->visible_region, damage);
+
+ if (!pixman_region32_not_empty(&repaint))
+ goto done;
+
+ if (node->transform.flags <= PEPPER_MATRIX_TRANSLATE) {
+ double tx, ty, tz;
+
+ tx = node->transform.m[12];
+ ty = node->transform.m[13];
+ tz = node->transform.m[14];
+
+ for (i = 0; i < 16; i++)
+ trans[i] = (float)gt->proj_mat.m[i];
+
+ trans[12] += trans[0] * tx + trans[4] * ty + trans[8] * tz;
+ trans[13] += trans[1] * tx + trans[5] * ty + trans[9] * tz;
+ trans[14] += trans[2] * tx + trans[6] * ty + trans[10] * tz;
+ trans[15] += trans[3] * tx + trans[7] * ty + trans[11] * tz;
+ } else {
+ pepper_mat4_t tmp;
+ pepper_mat4_multiply(&tmp, >->proj_mat, &node->transform);
+ for (i = 0; i < 16; i++)
+ trans[i] = (float)tmp.m[i];
+ }
+
+ filter = (node->transform.flags <= PEPPER_MATRIX_TRANSLATE) ? GL_NEAREST :
+ GL_LINEAR;
+ for (i = 0; i < state->num_planes; i++) {
+ glActiveTexture(GL_TEXTURE0 + i);
+ glBindTexture(GL_TEXTURE_2D, state->textures[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
+ }
+
+ pepper_surface_get_size(surface, &w, &h);
+ surface_opaque = pepper_surface_get_opaque_region(surface);
+ pixman_region32_init_rect(&surface_blend, 0, 0, w, h);
+ pixman_region32_subtract(&surface_blend, &surface_blend, surface_opaque);
+
+ glEnable(GL_SCISSOR_TEST);
+
+ if (pixman_region32_not_empty(surface_opaque)) {
+ if (state->sampler == GL_SHADER_SAMPLER_RGBA)
+ shader = &gr->shaders[GL_SHADER_SAMPLER_RGBX];
+ else
+ shader = &gr->shaders[state->sampler];
+
+ gl_shader_use(gr, shader);
+
+ glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
+ for (i = 0; i < state->num_planes; i++)
+ glUniform1i(shader->texture_uniform[i], i);
+ glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
+
+ repaint_region_scissor(gr, state, &repaint, surface_opaque);
+ }
+
+ if (pixman_region32_not_empty(&surface_blend)) {
+ shader = &gr->shaders[state->sampler];
+ gl_shader_use(gr, shader);
+
+ glUniform1f(shader->alpha_uniform, 1.0f /* FIXME: view->alpha? */);
+ for (i = 0; i < state->num_planes; i++)
+ glUniform1i(shader->texture_uniform[i], i);
+ glUniformMatrix4fv(shader->trans_uniform, 1, GL_FALSE, trans);
+
+ glEnable(GL_BLEND);
+ repaint_region_scissor(gr, state, &repaint, &surface_blend);
+ glDisable(GL_BLEND);
+ }
+
+ glDisable(GL_SCISSOR_TEST);
+ pixman_region32_fini(&surface_blend);
done:
- pixman_region32_fini(&repaint);
+ pixman_region32_fini(&repaint);
}
static void
gl_renderer_repaint_output(pepper_renderer_t *renderer, pepper_output_t *output,
- const pepper_list_t *list, pixman_region32_t *damage)
+ const pepper_list_t *list, pixman_region32_t *damage)
{
- gl_renderer_t *gr = (gl_renderer_t *)renderer;
- gl_render_target_t *gt = (gl_render_target_t *)renderer->target;
- const pepper_output_geometry_t *geom = pepper_output_get_geometry(output);
-
- int i;
- EGLint buffer_age = 0;
- pixman_region32_t total_damage;
-
- if (!gl_renderer_use(gr))
- return;
-
- glViewport(0, 0, geom->w, geom->h);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- if (gr->has_buffer_age)
- eglQuerySurface(gr->display, ((gl_render_target_t *)renderer->target)->surface,
- EGL_BUFFER_AGE_EXT, &buffer_age);
-
- if (!buffer_age || buffer_age - 1 > MAX_BUFFER_COUNT)
- {
- pixman_region32_init_rect(&total_damage, geom->x, geom->y, geom->w, geom->h);
- }
- else
- {
- int first = gt->damage_index + MAX_BUFFER_COUNT - (buffer_age - 1);
-
- pixman_region32_init(&total_damage);
- pixman_region32_copy(&total_damage, damage);
-
- for (i = 0; i < buffer_age - 1; i++)
- pixman_region32_union(&total_damage, &total_damage,
- >->damages[(first + i) % MAX_BUFFER_COUNT]);
-
- pixman_region32_copy(>->damages[gt->damage_index], damage);
-
- gt->damage_index += 1;
- gt->damage_index %= MAX_BUFFER_COUNT;
- }
-
- if (pixman_region32_not_empty(&total_damage))
- {
- pepper_list_t *l;
-
- if (gr->clear_background)
- {
- int i, nrects;
- pixman_box32_t *rects;
-
- glEnable(GL_SCISSOR_TEST);
- glClearColor(0.0, 0.0, 0.0, 1.0);
-
- rects = pixman_region32_rectangles(&total_damage, &nrects);
-
- glEnable(GL_SCISSOR_TEST);
- for (i = 0; i < nrects; i++)
- {
- glScissor(rects[i].x1, geom->h - rects[i].y2,
- rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1);
- glClear(GL_COLOR_BUFFER_BIT);
- }
- glDisable(GL_SCISSOR_TEST);
- }
-
- if (gr->use_clipper)
- pepper_list_for_each_list_reverse(l, list)
- repaint_view_clip(renderer, output, (pepper_render_item_t *)l->item,
- &total_damage);
- else
- pepper_list_for_each_list_reverse(l, list)
- repaint_view_scissor(renderer, output, (pepper_render_item_t *)l->item,
- &total_damage);
- }
-
- pixman_region32_fini(&total_damage);
-
- eglSwapBuffers(gr->display, ((gl_render_target_t *)renderer->target)->surface);
-
- /* TODO: eglSwapBuffersWithDamage. */
+ gl_renderer_t *gr = (gl_renderer_t *)renderer;
+ gl_render_target_t *gt = (gl_render_target_t *)renderer->target;
+ const pepper_output_geometry_t *geom = pepper_output_get_geometry(output);
+
+ int i;
+ EGLint buffer_age = 0;
+ pixman_region32_t total_damage;
+
+ if (!gl_renderer_use(gr))
+ return;
+
+ glViewport(0, 0, geom->w, geom->h);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ if (gr->has_buffer_age)
+ eglQuerySurface(gr->display, ((gl_render_target_t *)renderer->target)->surface,
+ EGL_BUFFER_AGE_EXT, &buffer_age);
+
+ if (!buffer_age || buffer_age - 1 > MAX_BUFFER_COUNT) {
+ pixman_region32_init_rect(&total_damage, geom->x, geom->y, geom->w, geom->h);
+ } else {
+ int first = gt->damage_index + MAX_BUFFER_COUNT - (buffer_age - 1);
+
+ pixman_region32_init(&total_damage);
+ pixman_region32_copy(&total_damage, damage);
+
+ for (i = 0; i < buffer_age - 1; i++)
+ pixman_region32_union(&total_damage, &total_damage,
+ >->damages[(first + i) % MAX_BUFFER_COUNT]);
+
+ pixman_region32_copy(>->damages[gt->damage_index], damage);
+
+ gt->damage_index += 1;
+ gt->damage_index %= MAX_BUFFER_COUNT;
+ }
+
+ if (pixman_region32_not_empty(&total_damage)) {
+ pepper_list_t *l;
+
+ if (gr->clear_background) {
+ int i, nrects;
+ pixman_box32_t *rects;
+
+ glEnable(GL_SCISSOR_TEST);
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+
+ rects = pixman_region32_rectangles(&total_damage, &nrects);
+
+ glEnable(GL_SCISSOR_TEST);
+ for (i = 0; i < nrects; i++) {
+ glScissor(rects[i].x1, geom->h - rects[i].y2,
+ rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+ glDisable(GL_SCISSOR_TEST);
+ }
+
+ if (gr->use_clipper)
+ pepper_list_for_each_list_reverse(l, list)
+ repaint_view_clip(renderer, output, (pepper_render_item_t *)l->item,
+ &total_damage);
+ else
+ pepper_list_for_each_list_reverse(l, list)
+ repaint_view_scissor(renderer, output, (pepper_render_item_t *)l->item,
+ &total_damage);
+ }
+
+ pixman_region32_fini(&total_damage);
+
+ eglSwapBuffers(gr->display, ((gl_render_target_t *)renderer->target)->surface);
+
+ /* TODO: eglSwapBuffersWithDamage. */
}
static pepper_bool_t
setup_egl_extensions(gl_renderer_t *gr)
{
- const char *extensions = eglQueryString(gr->display, EGL_EXTENSIONS);
-
- if (!extensions)
- {
- PEPPER_ERROR("Failed to get EGL extension string.\n");
- return PEPPER_FALSE;
- }
-
- if (strstr(extensions, "EGL_KHR_image"))
- {
- gr->create_image = (void *)eglGetProcAddress("eglCreateImageKHR");
- gr->destroy_image = (void *)eglGetProcAddress("eglDestroyImageKHR");
- }
- else
- {
- PEPPER_ERROR("EGL_KHR_image not supported only wl_shm will be supported.\n");
- }
+ const char *extensions = eglQueryString(gr->display, EGL_EXTENSIONS);
+
+ if (!extensions) {
+ PEPPER_ERROR("Failed to get EGL extension string.\n");
+ return PEPPER_FALSE;
+ }
+
+ if (strstr(extensions, "EGL_KHR_image")) {
+ gr->create_image = (void *)eglGetProcAddress("eglCreateImageKHR");
+ gr->destroy_image = (void *)eglGetProcAddress("eglDestroyImageKHR");
+ } else {
+ PEPPER_ERROR("EGL_KHR_image not supported only wl_shm will be supported.\n");
+ }
#ifdef EGL_EXT_swap_buffers_with_damage
- if (strstr(extensions, "EGL_EXT_swap_buffers_with_damage"))
- {
- gr->swap_buffers_with_damage =
- (void *)eglGetProcAddress("eglSwapBuffersWithDamageEXT");
- }
- else
- {
- PEPPER_ERROR("Performance Warning: EGL_EXT_swap_buffers_with_damage not supported.\n");
- }
+ if (strstr(extensions, "EGL_EXT_swap_buffers_with_damage")) {
+ gr->swap_buffers_with_damage =
+ (void *)eglGetProcAddress("eglSwapBuffersWithDamageEXT");
+ } else {
+ PEPPER_ERROR("Performance Warning: EGL_EXT_swap_buffers_with_damage not supported.\n");
+ }
#endif
- if (strstr(extensions, "EGL_WL_bind_wayland_display"))
- {
- gr->bind_display = (void *)eglGetProcAddress("eglBindWaylandDisplayWL");
- gr->unbind_display = (void *)eglGetProcAddress("eglUnbindWaylandDisplayWL");
- gr->query_buffer = (void *)eglGetProcAddress("eglQueryWaylandBufferWL");
-
- if (!gr->bind_display(gr->display,
- pepper_compositor_get_display(gr->base.compositor)))
- {
- gr->bind_display = NULL;
- gr->unbind_display = NULL;
- gr->query_buffer = NULL;
- }
- }
-
- if (strstr(extensions, "EGL_EXT_buffer_age"))
- {
- gr->has_buffer_age = PEPPER_TRUE;
- }
- else
- {
- PEPPER_ERROR("Performance Warning: EGL_EXT_buffer_age not supported.\n");
- }
-
- if (strstr(extensions, "EGL_EXT_platform_base"))
- {
- gr->create_platform_window_surface =
- (void *)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
- }
- else
- {
- PEPPER_ERROR("Warning: EGL_EXT_platform_base not supported.\n");
- }
-
- return PEPPER_TRUE;
+ if (strstr(extensions, "EGL_WL_bind_wayland_display")) {
+ gr->bind_display = (void *)eglGetProcAddress("eglBindWaylandDisplayWL");
+ gr->unbind_display = (void *)eglGetProcAddress("eglUnbindWaylandDisplayWL");
+ gr->query_buffer = (void *)eglGetProcAddress("eglQueryWaylandBufferWL");
+
+ if (!gr->bind_display(gr->display,
+ pepper_compositor_get_display(gr->base.compositor))) {
+ gr->bind_display = NULL;
+ gr->unbind_display = NULL;
+ gr->query_buffer = NULL;
+ }
+ }
+
+ if (strstr(extensions, "EGL_EXT_buffer_age")) {
+ gr->has_buffer_age = PEPPER_TRUE;
+ } else {
+ PEPPER_ERROR("Performance Warning: EGL_EXT_buffer_age not supported.\n");
+ }
+
+ if (strstr(extensions, "EGL_EXT_platform_base")) {
+ gr->create_platform_window_surface =
+ (void *)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
+ } else {
+ PEPPER_ERROR("Warning: EGL_EXT_platform_base not supported.\n");
+ }
+
+ return PEPPER_TRUE;
}
static pepper_bool_t
setup_gl_extensions(gl_renderer_t *gr)
{
- const char *extensions = (const char *)glGetString(GL_EXTENSIONS);
+ const char *extensions = (const char *)glGetString(GL_EXTENSIONS);
- if (!extensions)
- {
- PEPPER_ERROR("Failed to get GL extension string.\n");
- return PEPPER_FALSE;
- }
+ if (!extensions) {
+ PEPPER_ERROR("Failed to get GL extension string.\n");
+ return PEPPER_FALSE;
+ }
- gr->image_target_texture_2d = (void *)eglGetProcAddress("glEGLImageTargetTexture2DOES");
+ gr->image_target_texture_2d = (void *)
+ eglGetProcAddress("glEGLImageTargetTexture2DOES");
- if (!gr->image_target_texture_2d)
- {
- PEPPER_ERROR("glEGLImageTargetTexture2DOES not supported.\n");
- return PEPPER_FALSE;
- }
+ if (!gr->image_target_texture_2d) {
+ PEPPER_ERROR("glEGLImageTargetTexture2DOES not supported.\n");
+ return PEPPER_FALSE;
+ }
- if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888"))
- {
- PEPPER_ERROR("GL_EXT_texture_format_BGRA8888 not supported.\n");
- return PEPPER_FALSE;
- }
+ if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888")) {
+ PEPPER_ERROR("GL_EXT_texture_format_BGRA8888 not supported.\n");
+ return PEPPER_FALSE;
+ }
- if (strstr(extensions, "GL_EXT_read_format_bgra"))
- gr->has_read_format_bgra = PEPPER_TRUE;
+ if (strstr(extensions, "GL_EXT_read_format_bgra"))
+ gr->has_read_format_bgra = PEPPER_TRUE;
- if (strstr(extensions, "GL_EXT_unpack_subimage"))
- gr->has_unpack_subimage = PEPPER_TRUE;
+ if (strstr(extensions, "GL_EXT_unpack_subimage"))
+ gr->has_unpack_subimage = PEPPER_TRUE;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static EGLenum
get_egl_platform(const char *str)
{
- if (!str)
- return EGL_NONE;
+ if (!str)
+ return EGL_NONE;
- if (!strcmp(str, "gbm"))
- return EGL_PLATFORM_GBM_KHR;
+ if (!strcmp(str, "gbm"))
+ return EGL_PLATFORM_GBM_KHR;
- if (!strcmp(str, "wayland"))
- return EGL_PLATFORM_WAYLAND_KHR;
+ if (!strcmp(str, "wayland"))
+ return EGL_PLATFORM_WAYLAND_KHR;
- if (!strcmp(str, "x11"))
- return EGL_PLATFORM_X11_KHR;
+ if (!strcmp(str, "x11"))
+ return EGL_PLATFORM_X11_KHR;
- if (!strcmp(str, "tbm"))
- return EGL_PLATFORM_TBM_EXT;
- return EGL_NONE;
+ if (!strcmp(str, "tbm"))
+ return EGL_PLATFORM_TBM_EXT;
+ return EGL_NONE;
}
static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
static pepper_bool_t
setup_display(gl_renderer_t *gr, void *native_display, const char *platform)
{
- EGLenum egl_platform = get_egl_platform(platform);
- const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
- char str[64];
+ EGLenum egl_platform = get_egl_platform(platform);
+ const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+ char str[64];
- if (!extensions || !strstr(extensions, "EGL_EXT_platform_base"))
- {
- gr->display = eglGetDisplay(native_display);
- return gr->display != EGL_NO_DISPLAY;
- }
+ if (!extensions || !strstr(extensions, "EGL_EXT_platform_base")) {
+ gr->display = eglGetDisplay(native_display);
+ return gr->display != EGL_NO_DISPLAY;
+ }
- if (!egl_platform)
- goto use_legacy;
+ if (!egl_platform)
+ goto use_legacy;
- if (!extensions)
- goto use_legacy;
+ if (!extensions)
+ goto use_legacy;
- if (!strstr(extensions, "EGL_EXT_platform_base"))
- goto use_legacy;
+ if (!strstr(extensions, "EGL_EXT_platform_base"))
+ goto use_legacy;
- snprintf(str, sizeof(str), "EGL_KHR_platform_%s", platform);
- if (!strstr(extensions, str))
- goto use_legacy;
+ snprintf(str, sizeof(str), "EGL_KHR_platform_%s", platform);
+ if (!strstr(extensions, str))
+ goto use_legacy;
- snprintf(str, sizeof(str), "EGL_EXT_platform_%s", platform);
- if (!strstr(extensions, str))
- goto use_legacy;
+ snprintf(str, sizeof(str), "EGL_EXT_platform_%s", platform);
+ if (!strstr(extensions, str))
+ goto use_legacy;
- snprintf(str, sizeof(str), "EGL_MESA_platform_%s", platform);
- if (!strstr(extensions, str))
- goto use_legacy;
+ snprintf(str, sizeof(str), "EGL_MESA_platform_%s", platform);
+ if (!strstr(extensions, str))
+ goto use_legacy;
- if (!get_platform_display)
- get_platform_display = (void *)eglGetProcAddress("eglGetPlatformDisplayEXT");
+ if (!get_platform_display)
+ get_platform_display = (void *)eglGetProcAddress("eglGetPlatformDisplayEXT");
- if (!get_platform_display)
- goto use_legacy;
+ if (!get_platform_display)
+ goto use_legacy;
- gr->display = get_platform_display(egl_platform, native_display, NULL);
+ gr->display = get_platform_display(egl_platform, native_display, NULL);
- if (gr->display == EGL_NO_DISPLAY)
- goto use_legacy;
+ if (gr->display == EGL_NO_DISPLAY)
+ goto use_legacy;
- gr->create_platform_window_surface =
- (void *)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
+ gr->create_platform_window_surface =
+ (void *)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
use_legacy:
- if (gr->display == EGL_NO_DISPLAY)
- gr->display = eglGetDisplay(native_display);
+ if (gr->display == EGL_NO_DISPLAY)
+ gr->display = eglGetDisplay(native_display);
- if (gr->display != EGL_NO_DISPLAY)
- return PEPPER_TRUE;
+ if (gr->display != EGL_NO_DISPLAY)
+ return PEPPER_TRUE;
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
PEPPER_API pepper_renderer_t *
-pepper_gl_renderer_create(pepper_compositor_t *compositor, void *native_display, const char *platform)
+pepper_gl_renderer_create(pepper_compositor_t *compositor, void *native_display,
+ const char *platform)
{
- gl_renderer_t *gr;
- EGLint major, minor;
- const char *env;
+ gl_renderer_t *gr;
+ EGLint major, minor;
+ const char *env;
- gr = calloc(1, sizeof(gl_renderer_t));
- if (!gr)
- return NULL;
+ gr = calloc(1, sizeof(gl_renderer_t));
+ if (!gr)
+ return NULL;
- if (!setup_display(gr, native_display, platform))
- goto error;
+ if (!setup_display(gr, native_display, platform))
+ goto error;
- gr->base.compositor = compositor;
- gr->native_display = native_display;
+ gr->base.compositor = compositor;
+ gr->native_display = native_display;
- gr->base.destroy = gl_renderer_destroy;
- gr->base.attach_surface = gl_renderer_attach_surface;
- gr->base.flush_surface_damage = gl_renderer_flush_surface_damage;
- gr->base.read_pixels = gl_renderer_read_pixels;
- gr->base.repaint_output = gl_renderer_repaint_output;
+ gr->base.destroy = gl_renderer_destroy;
+ gr->base.attach_surface = gl_renderer_attach_surface;
+ gr->base.flush_surface_damage = gl_renderer_flush_surface_damage;
+ gr->base.read_pixels = gl_renderer_read_pixels;
+ gr->base.repaint_output = gl_renderer_repaint_output;
- if (!eglInitialize(gr->display, &major, &minor))
- {
- PEPPER_ERROR("eglInitialize() failed.\n");
- goto error;
- }
+ if (!eglInitialize(gr->display, &major, &minor)) {
+ PEPPER_ERROR("eglInitialize() failed.\n");
+ goto error;
+ }
- if (!eglBindAPI(EGL_OPENGL_ES_API))
- {
- PEPPER_ERROR("eglBindAPI() failed.\n");
- goto error;
- }
+ if (!eglBindAPI(EGL_OPENGL_ES_API)) {
+ PEPPER_ERROR("eglBindAPI() failed.\n");
+ goto error;
+ }
- if (!setup_egl_extensions(gr))
- goto error;
+ if (!setup_egl_extensions(gr))
+ goto error;
- env = getenv("PEPPER_RENDER_CLEAR_BACKGROUND");
+ env = getenv("PEPPER_RENDER_CLEAR_BACKGROUND");
- if (env && atoi(env) == 1)
- gr->clear_background = PEPPER_TRUE;
+ if (env && atoi(env) == 1)
+ gr->clear_background = PEPPER_TRUE;
- env = getenv("PEPPER_RENDER_GL_USE_POLYGON_CLIPPER");
+ env = getenv("PEPPER_RENDER_GL_USE_POLYGON_CLIPPER");
- if (env && atoi(env) == 1)
- gr->use_clipper = PEPPER_TRUE;
+ if (env && atoi(env) == 1)
+ gr->use_clipper = PEPPER_TRUE;
- return &gr->base;
+ return &gr->base;
error:
- if (gr)
- gl_renderer_destroy(&gr->base);
+ if (gr)
+ gl_renderer_destroy(&gr->base);
- return NULL;
+ return NULL;
}
static void
gl_render_target_destroy(pepper_render_target_t *target)
{
- int i;
- gl_render_target_t *gt = (gl_render_target_t *)target;
- gl_renderer_t *gr = (gl_renderer_t *)target->renderer;
+ int i;
+ gl_render_target_t *gt = (gl_render_target_t *)target;
+ gl_renderer_t *gr = (gl_renderer_t *)target->renderer;
- for (i = 0; i < MAX_BUFFER_COUNT; i++)
- pixman_region32_fini(>->damages[i]);
+ for (i = 0; i < MAX_BUFFER_COUNT; i++)
+ pixman_region32_fini(>->damages[i]);
- if (gt->surface != EGL_NO_SURFACE)
- eglDestroySurface(gr->display, gt->surface);
+ if (gt->surface != EGL_NO_SURFACE)
+ eglDestroySurface(gr->display, gt->surface);
- free(gt);
+ free(gt);
}
PEPPER_API pepper_render_target_t *
-pepper_gl_renderer_create_target(pepper_renderer_t *renderer, void *native_window,
- pepper_format_t format, const void *visual_id,
- int32_t width, int32_t height)
+pepper_gl_renderer_create_target(pepper_renderer_t *renderer,
+ void *native_window,
+ pepper_format_t format, const void *visual_id,
+ int32_t width, int32_t height)
{
- gl_renderer_t *gr = (gl_renderer_t *)renderer;
- gl_render_target_t *target;
- EGLint config_size = 0, num_configs = 0;
- EGLConfig *configs = NULL;
- EGLConfig config = NULL;
- EGLSurface surface = EGL_NO_SURFACE;
- EGLContext context = EGL_NO_CONTEXT;
- int i;
-
- EGLint context_attribs[] =
- {
- EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_NONE
- };
-
- EGLint config_attribs[] =
- {
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_RED_SIZE, 0,
- EGL_GREEN_SIZE, 0,
- EGL_BLUE_SIZE, 0,
- EGL_ALPHA_SIZE, 0,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_NONE
- };
-
- target = calloc(1, sizeof(gl_render_target_t));
- if (!target)
- return NULL;
-
- config_attribs[3] = PEPPER_FORMAT_R(format);
- config_attribs[5] = PEPPER_FORMAT_G(format);
- config_attribs[7] = PEPPER_FORMAT_B(format);
- config_attribs[9] = PEPPER_FORMAT_A(format);
-
- if (!eglChooseConfig(gr->display, config_attribs, NULL, 0, &config_size))
- {
- PEPPER_ERROR("eglChooseConfig() failed.\n");
- goto error;
- }
-
- if (config_size < 1)
- {
- PEPPER_ERROR("eglChooseConfig() returned no config.\n");
- goto error;
- }
-
- if ((configs = (EGLConfig *)calloc(config_size, sizeof(EGLConfig))) == NULL)
- goto error;
-
- if (!eglChooseConfig(gr->display, config_attribs, configs, config_size, &num_configs))
- {
- PEPPER_ERROR("eglChooseConfig() failed.\n");
- goto error;
- }
-
- if (num_configs < 1)
- goto error;
-
- for (i = 0; i < num_configs; i++)
- {
- EGLint attrib;
-
- if (visual_id)
- {
- /* Native visual id have privilege. */
- if (eglGetConfigAttrib(gr->display, configs[i], EGL_NATIVE_VISUAL_ID, &attrib))
- {
- if (attrib == *((EGLint *)visual_id))
- {
- config = configs[i];
- break;
- }
- }
-
- continue;
- }
-
- if (eglGetConfigAttrib(gr->display, configs[i], EGL_BUFFER_SIZE, &attrib))
- {
- if (attrib == (EGLint)PEPPER_FORMAT_BPP(format))
- {
- config = configs[i];
- break;
- }
- }
- }
-
- free(configs);
- configs = NULL;
-
- if (!config)
- {
- PEPPER_ERROR("No matched config.\n");
- goto error;
- }
-
- /* Try platform window surface creation first. */
- if (gr->create_platform_window_surface)
- surface = gr->create_platform_window_surface(gr->display, config, native_window, NULL);
-
- if (target->surface == EGL_NO_SURFACE)
- {
- surface = eglCreateWindowSurface(gr->display, config,
- (EGLNativeWindowType)native_window, NULL);
- }
-
- if (surface == EGL_NO_SURFACE)
- {
- PEPPER_ERROR("eglCreateWindowSurface() failed.\n");
- goto error;
- }
-
- if (gr->context == EGL_NO_CONTEXT)
- {
- context = eglCreateContext(gr->display, config, EGL_NO_CONTEXT, context_attribs);
- if (context == EGL_NO_CONTEXT)
- {
- PEPPER_ERROR("eglCreateContext() failed.\n");
- goto error;
- }
-
- if (!eglMakeCurrent(gr->display, surface, surface, context))
- {
- PEPPER_ERROR("eglMakeCurrent() failed.\n");
- goto error;
- }
-
- if (!setup_gl_extensions(gr))
- goto error;
-
- if (!init_gl_shaders(gr))
- goto error;
- }
- else
- {
- context = gr->context;
- }
-
- target->base.renderer = renderer;
- target->surface = surface;
- target->config = config;
- target->native_window = native_window;
- target->width = width;
- target->height = height;
-
- if (gr->context == EGL_NO_CONTEXT)
- gr->context = context;
-
- target->base.destroy = gl_render_target_destroy;
-
- pepper_mat4_init_translate(&target->proj_mat, (double)width / -2, (double)height / -2, 0);
- pepper_mat4_scale(&target->proj_mat, (double)2 / width, (double)(-2) / height, 1);
-
- for (i = 0; i < MAX_BUFFER_COUNT; i++)
- pixman_region32_init(&target->damages[i]);
-
- return &target->base;
+ gl_renderer_t *gr = (gl_renderer_t *)renderer;
+ gl_render_target_t *target;
+ EGLint config_size = 0, num_configs = 0;
+ EGLConfig *configs = NULL;
+ EGLConfig config = NULL;
+ EGLSurface surface = EGL_NO_SURFACE;
+ EGLContext context = EGL_NO_CONTEXT;
+ int i;
+
+ EGLint context_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ EGLint config_attribs[] = {
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RED_SIZE, 0,
+ EGL_GREEN_SIZE, 0,
+ EGL_BLUE_SIZE, 0,
+ EGL_ALPHA_SIZE, 0,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE
+ };
+
+ target = calloc(1, sizeof(gl_render_target_t));
+ if (!target)
+ return NULL;
+
+ config_attribs[3] = PEPPER_FORMAT_R(format);
+ config_attribs[5] = PEPPER_FORMAT_G(format);
+ config_attribs[7] = PEPPER_FORMAT_B(format);
+ config_attribs[9] = PEPPER_FORMAT_A(format);
+
+ if (!eglChooseConfig(gr->display, config_attribs, NULL, 0, &config_size)) {
+ PEPPER_ERROR("eglChooseConfig() failed.\n");
+ goto error;
+ }
+
+ if (config_size < 1) {
+ PEPPER_ERROR("eglChooseConfig() returned no config.\n");
+ goto error;
+ }
+
+ if ((configs = (EGLConfig *)calloc(config_size, sizeof(EGLConfig))) == NULL)
+ goto error;
+
+ if (!eglChooseConfig(gr->display, config_attribs, configs, config_size,
+ &num_configs)) {
+ PEPPER_ERROR("eglChooseConfig() failed.\n");
+ goto error;
+ }
+
+ if (num_configs < 1)
+ goto error;
+
+ for (i = 0; i < num_configs; i++) {
+ EGLint attrib;
+
+ if (visual_id) {
+ /* Native visual id have privilege. */
+ if (eglGetConfigAttrib(gr->display, configs[i], EGL_NATIVE_VISUAL_ID,
+ &attrib)) {
+ if (attrib == *((EGLint *)visual_id)) {
+ config = configs[i];
+ break;
+ }
+ }
+
+ continue;
+ }
+
+ if (eglGetConfigAttrib(gr->display, configs[i], EGL_BUFFER_SIZE, &attrib)) {
+ if (attrib == (EGLint)PEPPER_FORMAT_BPP(format)) {
+ config = configs[i];
+ break;
+ }
+ }
+ }
+
+ free(configs);
+ configs = NULL;
+
+ if (!config) {
+ PEPPER_ERROR("No matched config.\n");
+ goto error;
+ }
+
+ /* Try platform window surface creation first. */
+ if (gr->create_platform_window_surface)
+ surface = gr->create_platform_window_surface(gr->display, config, native_window,
+ NULL);
+
+ if (target->surface == EGL_NO_SURFACE) {
+ surface = eglCreateWindowSurface(gr->display, config,
+ (EGLNativeWindowType)native_window, NULL);
+ }
+
+ if (surface == EGL_NO_SURFACE) {
+ PEPPER_ERROR("eglCreateWindowSurface() failed.\n");
+ goto error;
+ }
+
+ if (gr->context == EGL_NO_CONTEXT) {
+ context = eglCreateContext(gr->display, config, EGL_NO_CONTEXT,
+ context_attribs);
+ if (context == EGL_NO_CONTEXT) {
+ PEPPER_ERROR("eglCreateContext() failed.\n");
+ goto error;
+ }
+
+ if (!eglMakeCurrent(gr->display, surface, surface, context)) {
+ PEPPER_ERROR("eglMakeCurrent() failed.\n");
+ goto error;
+ }
+
+ if (!setup_gl_extensions(gr))
+ goto error;
+
+ if (!init_gl_shaders(gr))
+ goto error;
+ } else {
+ context = gr->context;
+ }
+
+ target->base.renderer = renderer;
+ target->surface = surface;
+ target->config = config;
+ target->native_window = native_window;
+ target->width = width;
+ target->height = height;
+
+ if (gr->context == EGL_NO_CONTEXT)
+ gr->context = context;
+
+ target->base.destroy = gl_render_target_destroy;
+
+ pepper_mat4_init_translate(&target->proj_mat, (double)width / -2,
+ (double)height / -2, 0);
+ pepper_mat4_scale(&target->proj_mat, (double)2 / width, (double)(-2) / height,
+ 1);
+
+ for (i = 0; i < MAX_BUFFER_COUNT; i++)
+ pixman_region32_init(&target->damages[i]);
+
+ return &target->base;
error:
- if (context != EGL_NO_CONTEXT)
- eglDestroyContext(gr->display, context);
+ if (context != EGL_NO_CONTEXT)
+ eglDestroyContext(gr->display, context);
- if (surface != EGL_NO_SURFACE)
- eglDestroySurface(gr->display, surface);
+ if (surface != EGL_NO_SURFACE)
+ eglDestroySurface(gr->display, surface);
- free(target);
- return NULL;
+ free(target);
+ return NULL;
}
#endif
PEPPER_API pepper_renderer_t *
-pepper_gl_renderer_create(pepper_compositor_t *compositor, void *display, const char *platform);
+pepper_gl_renderer_create(pepper_compositor_t *compositor, void *display,
+ const char *platform);
PEPPER_API pepper_render_target_t *
-pepper_gl_renderer_create_target(pepper_renderer_t *renderer, void *window, pepper_format_t format,
- const void *visual_id, int32_t width, int32_t height);
+pepper_gl_renderer_create_target(pepper_renderer_t *renderer, void *window,
+ pepper_format_t format,
+ const void *visual_id, int32_t width, int32_t height);
#ifdef __cplusplus
}
PEPPER_API pepper_render_target_t *
pepper_pixman_renderer_create_target(pepper_format_t format, void *pixels,
- int stride, int width, int height);
+ int stride, int width, int height);
PEPPER_API pepper_render_target_t *
pepper_pixman_renderer_create_target_for_image(pixman_image_t *image);
#include "pepper-render.h"
-struct pepper_render_target
-{
- /* Renderer from where this target is created. */
- pepper_renderer_t *renderer;
+struct pepper_render_target {
+ /* Renderer from where this target is created. */
+ pepper_renderer_t *renderer;
- void (*destroy)(pepper_render_target_t *target);
+ void (*destroy)(pepper_render_target_t *target);
};
-struct pepper_renderer
-{
- pepper_compositor_t *compositor;
- pepper_render_target_t *target;
+struct pepper_renderer {
+ pepper_compositor_t *compositor;
+ pepper_render_target_t *target;
- void (*destroy)(pepper_renderer_t *renderer);
+ void (*destroy)(pepper_renderer_t *renderer);
- pepper_bool_t (*attach_surface)(pepper_renderer_t *renderer,
- pepper_surface_t *surface, int *w, int *h);
+ pepper_bool_t (*attach_surface)(pepper_renderer_t *renderer,
+ pepper_surface_t *surface, int *w, int *h);
- pepper_bool_t (*flush_surface_damage)(pepper_renderer_t *renderer, pepper_surface_t *surface);
+ pepper_bool_t (*flush_surface_damage)(pepper_renderer_t *renderer,
+ pepper_surface_t *surface);
- pepper_bool_t (*read_pixels)(pepper_renderer_t *renderer,
- int x, int y, int w, int h,
- void *pixels, pepper_format_t format);
+ pepper_bool_t (*read_pixels)(pepper_renderer_t *renderer,
+ int x, int y, int w, int h,
+ void *pixels, pepper_format_t format);
- void (*repaint_output)(pepper_renderer_t *renderer,
- pepper_output_t *output,
- const pepper_list_t *render_list,
- pixman_region32_t *damage);
+ void (*repaint_output)(pepper_renderer_t *renderer,
+ pepper_output_t *output,
+ const pepper_list_t *render_list,
+ pixman_region32_t *damage);
};
#endif /* PEPPER_RENDER_INTERNAL_H */
pepper_render_target_destroy(pepper_render_target_t *target);
PEPPER_API pepper_bool_t
-pepper_renderer_set_target(pepper_renderer_t *renderer, pepper_render_target_t *target);
+pepper_renderer_set_target(pepper_renderer_t *renderer,
+ pepper_render_target_t *target);
PEPPER_API pepper_render_target_t *
pepper_renderer_get_target(pepper_renderer_t *renderer);
PEPPER_API pepper_bool_t
pepper_renderer_attach_surface(pepper_renderer_t *renderer,
- pepper_surface_t *surface, int *w, int *h);
+ pepper_surface_t *surface, int *w, int *h);
PEPPER_API pepper_bool_t
-pepper_renderer_flush_surface_damage(pepper_renderer_t *renderer, pepper_surface_t *surface);
+pepper_renderer_flush_surface_damage(pepper_renderer_t *renderer,
+ pepper_surface_t *surface);
PEPPER_API void
-pepper_renderer_repaint_output(pepper_renderer_t *renderer, pepper_output_t *output,
- const pepper_list_t *view_list, pixman_region32_t *damage);
+pepper_renderer_repaint_output(pepper_renderer_t *renderer,
+ pepper_output_t *output,
+ const pepper_list_t *view_list, pixman_region32_t *damage);
PEPPER_API pepper_bool_t
-pepper_renderer_read_pixels(pepper_renderer_t *renderer, int x, int y, int w, int h,
- void *pixels, pepper_format_t format);
+pepper_renderer_read_pixels(pepper_renderer_t *renderer, int x, int y, int w,
+ int h,
+ void *pixels, pepper_format_t format);
#ifdef __cplusplus
}
typedef struct pixman_surface_state pixman_surface_state_t;
typedef struct pixman_render_target pixman_render_target_t;
-struct pixman_render_target
-{
- pepper_render_target_t base;
- pixman_image_t *image;
+struct pixman_render_target {
+ pepper_render_target_t base;
+ pixman_image_t *image;
};
-struct pixman_renderer
-{
- pepper_renderer_t base;
- pixman_image_t *background;
+struct pixman_renderer {
+ pepper_renderer_t base;
+ pixman_image_t *background;
};
-struct pixman_surface_state
-{
- pixman_renderer_t *renderer;
+struct pixman_surface_state {
+ pixman_renderer_t *renderer;
- pepper_surface_t *surface;
- pepper_event_listener_t *surface_destroy_listener;
+ pepper_surface_t *surface;
+ pepper_event_listener_t *surface_destroy_listener;
- pepper_buffer_t *buffer;
- pepper_event_listener_t *buffer_destroy_listener;
- int buffer_width, buffer_height;
+ pepper_buffer_t *buffer;
+ pepper_event_listener_t *buffer_destroy_listener;
+ int buffer_width, buffer_height;
- pixman_image_t *image;
+ pixman_image_t *image;
};
static void
pixman_renderer_destroy(pepper_renderer_t *renderer)
{
- pixman_renderer_t *pr = (pixman_renderer_t *)renderer;
+ pixman_renderer_t *pr = (pixman_renderer_t *)renderer;
- if (pr->background)
- pixman_image_unref(pr->background);
+ if (pr->background)
+ pixman_image_unref(pr->background);
- free(renderer);
+ free(renderer);
}
static void
surface_state_destroy_image(pixman_surface_state_t *state)
{
- if (state->image)
- {
- pixman_image_unref(state->image);
- state->image = NULL;
- }
+ if (state->image) {
+ pixman_image_unref(state->image);
+ state->image = NULL;
+ }
}
static void
surface_state_release_buffer(pixman_surface_state_t *state)
{
- surface_state_destroy_image(state);
+ surface_state_destroy_image(state);
- if (state->buffer)
- {
- pepper_event_listener_remove(state->buffer_destroy_listener);
- state->buffer = NULL;
- }
+ if (state->buffer) {
+ pepper_event_listener_remove(state->buffer_destroy_listener);
+ state->buffer = NULL;
+ }
}
static void
surface_state_handle_buffer_destroy(pepper_event_listener_t *listener,
- pepper_object_t *object,
- uint32_t id,
- void *info,
- void *data)
+ pepper_object_t *object,
+ uint32_t id,
+ void *info,
+ void *data)
{
- pixman_surface_state_t *state = data;
- surface_state_release_buffer(state);
+ pixman_surface_state_t *state = data;
+ surface_state_release_buffer(state);
}
static void
surface_state_handle_surface_destroy(pepper_event_listener_t *listener,
- pepper_object_t *object,
- uint32_t id,
- void *info,
- void *data)
+ pepper_object_t *object,
+ uint32_t id,
+ void *info,
+ void *data)
{
- pixman_surface_state_t *state = data;
+ pixman_surface_state_t *state = data;
- surface_state_release_buffer(state);
- pepper_event_listener_remove(state->surface_destroy_listener);
- pepper_object_set_user_data((pepper_object_t *)state->surface, state->renderer, NULL, NULL);
- free(state);
+ surface_state_release_buffer(state);
+ pepper_event_listener_remove(state->surface_destroy_listener);
+ pepper_object_set_user_data((pepper_object_t *)state->surface, state->renderer,
+ NULL, NULL);
+ free(state);
}
static void
surface_state_begin_access(pixman_surface_state_t *state)
{
- struct wl_shm_buffer *shm_buffer;
+ struct wl_shm_buffer *shm_buffer;
#ifdef HAVE_TBM
- tbm_surface_h tbm_surface;
+ tbm_surface_h tbm_surface;
#endif
- shm_buffer = wl_shm_buffer_get(pepper_buffer_get_resource(state->buffer));
- if (shm_buffer)
- {
- wl_shm_buffer_begin_access(shm_buffer);
- return;
- }
+ shm_buffer = wl_shm_buffer_get(pepper_buffer_get_resource(state->buffer));
+ if (shm_buffer) {
+ wl_shm_buffer_begin_access(shm_buffer);
+ return;
+ }
#ifdef HAVE_TBM
- tbm_surface = wayland_tbm_server_get_surface(NULL, pepper_buffer_get_resource(state->buffer));
- if (tbm_surface)
- {
- tbm_surface_info_s tmp;
- tbm_surface_map(tbm_surface, TBM_SURF_OPTION_READ, &tmp);
- return;
- }
+ tbm_surface = wayland_tbm_server_get_surface(NULL,
+ pepper_buffer_get_resource(state->buffer));
+ if (tbm_surface) {
+ tbm_surface_info_s tmp;
+ tbm_surface_map(tbm_surface, TBM_SURF_OPTION_READ, &tmp);
+ return;
+ }
#endif
}
static void
surface_state_end_access(pixman_surface_state_t *state)
{
- struct wl_shm_buffer *shm_buffer;
+ struct wl_shm_buffer *shm_buffer;
#ifdef HAVE_TBM
- tbm_surface_h tbm_surface;
+ tbm_surface_h tbm_surface;
#endif
- shm_buffer = wl_shm_buffer_get(pepper_buffer_get_resource(state->buffer));
- if (shm_buffer)
- {
- wl_shm_buffer_end_access(shm_buffer);
- return;
- }
+ shm_buffer = wl_shm_buffer_get(pepper_buffer_get_resource(state->buffer));
+ if (shm_buffer) {
+ wl_shm_buffer_end_access(shm_buffer);
+ return;
+ }
#ifdef HAVE_TBM
- tbm_surface = wayland_tbm_server_get_surface(NULL, pepper_buffer_get_resource(state->buffer));
- if (tbm_surface)
- {
- tbm_surface_unmap(tbm_surface);
- return;
- }
+ tbm_surface = wayland_tbm_server_get_surface(NULL,
+ pepper_buffer_get_resource(state->buffer));
+ if (tbm_surface) {
+ tbm_surface_unmap(tbm_surface);
+ return;
+ }
#endif
}
static pixman_surface_state_t *
get_surface_state(pepper_renderer_t *renderer, pepper_surface_t *surface)
{
- pixman_surface_state_t *state = pepper_object_get_user_data((pepper_object_t *)surface, renderer);
+ pixman_surface_state_t *state = pepper_object_get_user_data((
+ pepper_object_t *)surface, renderer);
- if (!state)
- {
- state = calloc(1, sizeof(pixman_surface_state_t));
- if (!state)
- return NULL;
+ if (!state) {
+ state = calloc(1, sizeof(pixman_surface_state_t));
+ if (!state)
+ return NULL;
- state->surface = surface;
- state->surface_destroy_listener =
- pepper_object_add_event_listener((pepper_object_t *)surface,
- PEPPER_EVENT_OBJECT_DESTROY, 0,
- surface_state_handle_surface_destroy, state);
+ state->surface = surface;
+ state->surface_destroy_listener =
+ pepper_object_add_event_listener((pepper_object_t *)surface,
+ PEPPER_EVENT_OBJECT_DESTROY, 0,
+ surface_state_handle_surface_destroy, state);
- pepper_object_set_user_data((pepper_object_t *)surface, renderer, state, NULL);
- }
+ pepper_object_set_user_data((pepper_object_t *)surface, renderer, state, NULL);
+ }
- return state;
+ return state;
}
static pepper_bool_t
surface_state_attach_shm(pixman_surface_state_t *state, pepper_buffer_t *buffer)
{
- struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(pepper_buffer_get_resource(buffer));
- pixman_format_code_t format;
- int w, h;
- pixman_image_t *image;
-
- if (!shm_buffer)
- return PEPPER_FALSE;
-
- switch (wl_shm_buffer_get_format(shm_buffer))
- {
- case WL_SHM_FORMAT_XRGB8888:
- format = PIXMAN_x8r8g8b8;
- break;
- case WL_SHM_FORMAT_ARGB8888:
- format = PIXMAN_a8r8g8b8;
- break;
- case WL_SHM_FORMAT_RGB565:
- format = PIXMAN_r5g6b5;
- break;
- default:
- return PEPPER_FALSE;
- }
-
- w = wl_shm_buffer_get_width(shm_buffer);
- h = wl_shm_buffer_get_height(shm_buffer);
-
- image = pixman_image_create_bits(format, w, h,
- wl_shm_buffer_get_data(shm_buffer),
- wl_shm_buffer_get_stride(shm_buffer));
-
- if (!image)
- return PEPPER_FALSE;
-
- state->buffer_width = w;
- state->buffer_height = h;
- state->image = image;
- //state->shm_buffer = shm_buffer;
-
- return PEPPER_TRUE;;
+ struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(
+ pepper_buffer_get_resource(buffer));
+ pixman_format_code_t format;
+ int w, h;
+ pixman_image_t *image;
+
+ if (!shm_buffer)
+ return PEPPER_FALSE;
+
+ switch (wl_shm_buffer_get_format(shm_buffer)) {
+ case WL_SHM_FORMAT_XRGB8888:
+ format = PIXMAN_x8r8g8b8;
+ break;
+ case WL_SHM_FORMAT_ARGB8888:
+ format = PIXMAN_a8r8g8b8;
+ break;
+ case WL_SHM_FORMAT_RGB565:
+ format = PIXMAN_r5g6b5;
+ break;
+ default:
+ return PEPPER_FALSE;
+ }
+
+ w = wl_shm_buffer_get_width(shm_buffer);
+ h = wl_shm_buffer_get_height(shm_buffer);
+
+ image = pixman_image_create_bits(format, w, h,
+ wl_shm_buffer_get_data(shm_buffer),
+ wl_shm_buffer_get_stride(shm_buffer));
+
+ if (!image)
+ return PEPPER_FALSE;
+
+ state->buffer_width = w;
+ state->buffer_height = h;
+ state->image = image;
+ //state->shm_buffer = shm_buffer;
+
+ return PEPPER_TRUE;;
}
#ifdef HAVE_TBM
static pepper_bool_t
surface_state_attach_tbm(pixman_surface_state_t *state, pepper_buffer_t *buffer)
{
- tbm_surface_h tbm_surface = wayland_tbm_server_get_surface(NULL, pepper_buffer_get_resource(buffer));
- tbm_surface_info_s info;
- pixman_format_code_t format;
- int w, h;
- pixman_image_t *image;
-
- if (!tbm_surface)
- return PEPPER_FALSE;
-
- switch (tbm_surface_get_format(tbm_surface))
- {
- case TBM_FORMAT_XRGB8888:
- format = PIXMAN_x8r8g8b8;
- break;
- case TBM_FORMAT_ARGB8888:
- format = PIXMAN_a8r8g8b8;
- break;
- case TBM_FORMAT_RGB565:
- format = PIXMAN_r5g6b5;
- break;
- default:
- return PEPPER_FALSE;
- }
-
- tbm_surface_get_info(tbm_surface, &info);
- if (info.num_planes != 1)
- return PEPPER_FALSE;
-
- w = info.width;
- h = info.height;
- image = pixman_image_create_bits(format, w, h,
- (uint32_t*)info.planes[0].ptr,
- info.planes[0].stride);
-
- if (!image)
- return PEPPER_FALSE;
-
- state->buffer_width = w;
- state->buffer_height = h;
- state->image = image;
- //state->shm_buffer = shm_buffer;
-
- return PEPPER_TRUE;;
+ tbm_surface_h tbm_surface = wayland_tbm_server_get_surface(NULL,
+ pepper_buffer_get_resource(buffer));
+ tbm_surface_info_s info;
+ pixman_format_code_t format;
+ int w, h;
+ pixman_image_t *image;
+
+ if (!tbm_surface)
+ return PEPPER_FALSE;
+
+ switch (tbm_surface_get_format(tbm_surface)) {
+ case TBM_FORMAT_XRGB8888:
+ format = PIXMAN_x8r8g8b8;
+ break;
+ case TBM_FORMAT_ARGB8888:
+ format = PIXMAN_a8r8g8b8;
+ break;
+ case TBM_FORMAT_RGB565:
+ format = PIXMAN_r5g6b5;
+ break;
+ default:
+ return PEPPER_FALSE;
+ }
+
+ tbm_surface_get_info(tbm_surface, &info);
+ if (info.num_planes != 1)
+ return PEPPER_FALSE;
+
+ w = info.width;
+ h = info.height;
+ image = pixman_image_create_bits(format, w, h,
+ (uint32_t *)info.planes[0].ptr,
+ info.planes[0].stride);
+
+ if (!image)
+ return PEPPER_FALSE;
+
+ state->buffer_width = w;
+ state->buffer_height = h;
+ state->image = image;
+ //state->shm_buffer = shm_buffer;
+
+ return PEPPER_TRUE;;
}
#endif
static pepper_bool_t
-pixman_renderer_attach_surface(pepper_renderer_t *renderer, pepper_surface_t *surface,
- int *w, int *h)
+pixman_renderer_attach_surface(pepper_renderer_t *renderer,
+ pepper_surface_t *surface,
+ int *w, int *h)
{
- pixman_surface_state_t *state = get_surface_state(renderer, surface);
- pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
+ pixman_surface_state_t *state = get_surface_state(renderer, surface);
+ pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
- surface_state_release_buffer(state);
+ surface_state_release_buffer(state);
- if (!buffer)
- {
- state->buffer_width = 0;
- state->buffer_height = 0;
+ if (!buffer) {
+ state->buffer_width = 0;
+ state->buffer_height = 0;
- goto done;
- }
+ goto done;
+ }
- if (surface_state_attach_shm(state, buffer))
- goto done;
+ if (surface_state_attach_shm(state, buffer))
+ goto done;
#ifdef HAVE_TBM
- if (surface_state_attach_tbm(state, buffer))
- goto done;
+ if (surface_state_attach_tbm(state, buffer))
+ goto done;
#endif
- PEPPER_ERROR("Not supported buffer type.\n");
- return PEPPER_FALSE;
+ PEPPER_ERROR("Not supported buffer type.\n");
+ return PEPPER_FALSE;
done:
- state->buffer = buffer;
+ state->buffer = buffer;
- if (state->buffer)
- {
- state->buffer_destroy_listener =
- pepper_object_add_event_listener((pepper_object_t *)buffer,
- PEPPER_EVENT_OBJECT_DESTROY, 0,
- surface_state_handle_buffer_destroy, state);
- }
+ if (state->buffer) {
+ state->buffer_destroy_listener =
+ pepper_object_add_event_listener((pepper_object_t *)buffer,
+ PEPPER_EVENT_OBJECT_DESTROY, 0,
+ surface_state_handle_buffer_destroy, state);
+ }
- *w = state->buffer_width;
- *h = state->buffer_height;
+ *w = state->buffer_width;
+ *h = state->buffer_height;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_bool_t
-pixman_renderer_flush_surface_damage(pepper_renderer_t *renderer, pepper_surface_t *surface)
+pixman_renderer_flush_surface_damage(pepper_renderer_t *renderer,
+ pepper_surface_t *surface)
{
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_bool_t
pixman_renderer_read_pixels(pepper_renderer_t *renderer,
- int x, int y, int w, int h,
- void *pixels, pepper_format_t format)
+ int x, int y, int w, int h,
+ void *pixels, pepper_format_t format)
{
- pixman_image_t *src = ((pixman_render_target_t *)renderer->target)->image;
- pixman_image_t *dst;
- pixman_format_code_t pixman_format;
- int stride;
+ pixman_image_t *src = ((pixman_render_target_t *)
+ renderer->target)->image;
+ pixman_image_t *dst;
+ pixman_format_code_t pixman_format;
+ int stride;
- if (!src)
- return PEPPER_FALSE;
+ if (!src)
+ return PEPPER_FALSE;
- pixman_format = get_pixman_format(format);
+ pixman_format = get_pixman_format(format);
- if (!pixman_format)
- {
- /* PEPPER_ERROR("Invalid format.\n"); */
- return PEPPER_FALSE;
- }
+ if (!pixman_format) {
+ /* PEPPER_ERROR("Invalid format.\n"); */
+ return PEPPER_FALSE;
+ }
- stride = (PEPPER_FORMAT_BPP(format) / 8) * w;
- dst = pixman_image_create_bits(pixman_format, w, h, pixels, stride);
+ stride = (PEPPER_FORMAT_BPP(format) / 8) * w;
+ dst = pixman_image_create_bits(pixman_format, w, h, pixels, stride);
- if (!dst)
- {
- /* PEPPER_ERROR("Failed to create pixman image.\n"); */
- return PEPPER_FALSE;
- }
+ if (!dst) {
+ /* PEPPER_ERROR("Failed to create pixman image.\n"); */
+ return PEPPER_FALSE;
+ }
- pixman_image_composite(PIXMAN_OP_SRC, src, NULL, dst, x, y, 0, 0, 0, 0, w, h);
- pixman_image_unref(dst);
+ pixman_image_composite(PIXMAN_OP_SRC, src, NULL, dst, x, y, 0, 0, 0, 0, w, h);
+ pixman_image_unref(dst);
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static void
-pixman_transform_from_pepper_mat4(pixman_transform_t *transform, pepper_mat4_t *mat)
+pixman_transform_from_pepper_mat4(pixman_transform_t *transform,
+ pepper_mat4_t *mat)
{
- transform->matrix[0][0] = pixman_double_to_fixed(mat->m[0]);
- transform->matrix[0][1] = pixman_double_to_fixed(mat->m[4]);
- transform->matrix[0][2] = pixman_double_to_fixed(mat->m[12]);
- transform->matrix[1][0] = pixman_double_to_fixed(mat->m[1]);
- transform->matrix[1][1] = pixman_double_to_fixed(mat->m[5]);
- transform->matrix[1][2] = pixman_double_to_fixed(mat->m[13]);
- transform->matrix[2][0] = pixman_double_to_fixed(mat->m[3]);
- transform->matrix[2][1] = pixman_double_to_fixed(mat->m[7]);
- transform->matrix[2][2] = pixman_double_to_fixed(mat->m[15]);
+ transform->matrix[0][0] = pixman_double_to_fixed(mat->m[0]);
+ transform->matrix[0][1] = pixman_double_to_fixed(mat->m[4]);
+ transform->matrix[0][2] = pixman_double_to_fixed(mat->m[12]);
+ transform->matrix[1][0] = pixman_double_to_fixed(mat->m[1]);
+ transform->matrix[1][1] = pixman_double_to_fixed(mat->m[5]);
+ transform->matrix[1][2] = pixman_double_to_fixed(mat->m[13]);
+ transform->matrix[2][0] = pixman_double_to_fixed(mat->m[3]);
+ transform->matrix[2][1] = pixman_double_to_fixed(mat->m[7]);
+ transform->matrix[2][2] = pixman_double_to_fixed(mat->m[15]);
}
static void
repaint_view(pepper_renderer_t *renderer, pepper_output_t *output,
- pepper_render_item_t *node, pixman_region32_t *damage)
+ pepper_render_item_t *node, pixman_region32_t *damage)
{
- int32_t x, y, w, h, scale;
- pepper_surface_t *surface = pepper_view_get_surface(node->view);
-
- pixman_render_target_t *target = (pixman_render_target_t*)renderer->target;
- pixman_region32_t repaint, repaint_surface;
- pixman_region32_t surface_blend, *surface_opaque;
- pixman_surface_state_t *ps = get_surface_state(renderer, pepper_view_get_surface(node->view));
-
- pixman_region32_init(&repaint);
- pixman_region32_intersect(&repaint, &node->visible_region, damage);
-
- if (pixman_region32_not_empty(&repaint))
- {
- pixman_transform_t trans;
- pixman_filter_t filter;
-
- if (node->transform.flags <= PEPPER_MATRIX_TRANSLATE)
- {
- pixman_transform_init_translate(&trans,
- -pixman_double_to_fixed(node->transform.m[12]),
- -pixman_double_to_fixed(node->transform.m[13]));
- filter = PIXMAN_FILTER_NEAREST;
- }
- else
- {
- pixman_transform_from_pepper_mat4(&trans, &node->inverse);
- filter = PIXMAN_FILTER_BILINEAR;
- }
-
- pepper_surface_get_buffer_offset(surface, &x, &y);
- pepper_surface_get_size(surface, &w, &h);
- pixman_transform_translate(&trans, NULL,
- pixman_int_to_fixed(x), pixman_int_to_fixed(y));
-
- switch (pepper_surface_get_buffer_transform(surface))
- {
- case WL_OUTPUT_TRANSFORM_FLIPPED:
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- case WL_OUTPUT_TRANSFORM_FLIPPED_180:
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- pixman_transform_scale(&trans, NULL, pixman_int_to_fixed(-1), pixman_int_to_fixed(1));
- pixman_transform_translate(&trans, NULL, pixman_int_to_fixed(w), 0);
- break;
- }
-
- switch (pepper_surface_get_buffer_transform(surface))
- {
- case WL_OUTPUT_TRANSFORM_NORMAL:
- case WL_OUTPUT_TRANSFORM_FLIPPED:
- break;
- case WL_OUTPUT_TRANSFORM_90:
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- pixman_transform_rotate(&trans, NULL, 0, pixman_fixed_1);
- pixman_transform_translate(&trans, NULL, pixman_int_to_fixed(h), 0);
- break;
- case WL_OUTPUT_TRANSFORM_180:
- case WL_OUTPUT_TRANSFORM_FLIPPED_180:
- pixman_transform_rotate(&trans, NULL, -pixman_fixed_1, 0);
- pixman_transform_translate(&trans, NULL,
- pixman_int_to_fixed(w),
- pixman_int_to_fixed(h));
- break;
- case WL_OUTPUT_TRANSFORM_270:
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- pixman_transform_rotate(&trans, NULL, 0, -pixman_fixed_1);
- pixman_transform_translate(&trans, NULL, 0, pixman_int_to_fixed(w));
- break;
- }
-
- scale = pepper_surface_get_buffer_scale(surface);
- pixman_transform_scale(&trans, NULL,
- pixman_int_to_fixed(scale),
- pixman_int_to_fixed(scale));
-
- pixman_image_set_transform(ps->image, &trans);
- pixman_image_set_filter(ps->image, filter, NULL, 0);
-
- pixman_region32_init(&repaint_surface);
- pixman_region32_init_rect(&surface_blend, 0, 0, w, h);
-
- if (node->transform.flags <= PEPPER_MATRIX_TRANSLATE)
- {
- surface_opaque = pepper_surface_get_opaque_region(surface);
- pixman_region32_subtract(&surface_blend, &surface_blend, surface_opaque);
-
- if (pixman_region32_not_empty(surface_opaque))
- {
- pixman_region32_translate(surface_opaque,
- (int)node->transform.m[12], (int)node->transform.m[13]);
- pepper_pixman_region_global_to_output(surface_opaque, output);
- pixman_region32_intersect(&repaint_surface, &repaint, surface_opaque);
- pixman_image_set_clip_region32(target->image, &repaint_surface);
-
- surface_state_begin_access(ps);
- pixman_image_composite32(PIXMAN_OP_SRC, ps->image, NULL, target->image,
- 0, 0, /* src_x, src_y */
- 0, 0, /* mask_x, mask_y */
- 0, 0, /* dest_x, dest_y */
- pixman_image_get_width(target->image),
- pixman_image_get_height(target->image));
- surface_state_end_access(ps);
- }
-
- if (pixman_region32_not_empty(&surface_blend))
- {
- pixman_region32_translate(&surface_blend,
- (int)node->transform.m[12], (int)node->transform.m[13]);
- pepper_pixman_region_global_to_output(&surface_blend, output);
- pixman_region32_intersect(&repaint_surface, &repaint, &surface_blend);
- pixman_image_set_clip_region32(target->image, &repaint_surface);
-
- surface_state_begin_access(ps);
- pixman_image_composite32(PIXMAN_OP_OVER, ps->image, NULL, target->image,
- 0, 0, /* src_x, src_y */
- 0, 0, /* mask_x, mask_y */
- 0, 0, /* dest_x, dest_y */
- pixman_image_get_width(target->image),
- pixman_image_get_height(target->image));
- surface_state_end_access(ps);
- }
- }
- else
- {
- pixman_region32_translate(&surface_blend,
- (int)node->transform.m[12], (int)node->transform.m[13]);
- pepper_pixman_region_global_to_output(&surface_blend, output);
- pixman_region32_intersect(&repaint_surface, &repaint, &surface_blend);
- pixman_image_set_clip_region32(target->image, &repaint_surface);
-
- surface_state_begin_access(ps);
- pixman_image_composite32(PIXMAN_OP_OVER, ps->image, NULL, target->image,
- 0, 0, /* src_x, src_y */
- 0, 0, /* mask_x, mask_y */
- 0, 0, /* dest_x, dest_y */
- pixman_image_get_width(target->image),
- pixman_image_get_height(target->image));
- surface_state_end_access(ps);
- }
-
- pixman_region32_fini(&repaint_surface);
- pixman_region32_fini(&surface_blend);
- }
-
- pixman_region32_fini(&repaint);
+ int32_t x, y, w, h, scale;
+ pepper_surface_t *surface = pepper_view_get_surface(node->view);
+
+ pixman_render_target_t *target = (pixman_render_target_t *)renderer->target;
+ pixman_region32_t repaint, repaint_surface;
+ pixman_region32_t surface_blend, *surface_opaque;
+ pixman_surface_state_t *ps = get_surface_state(renderer,
+ pepper_view_get_surface(node->view));
+
+ pixman_region32_init(&repaint);
+ pixman_region32_intersect(&repaint, &node->visible_region, damage);
+
+ if (pixman_region32_not_empty(&repaint)) {
+ pixman_transform_t trans;
+ pixman_filter_t filter;
+
+ if (node->transform.flags <= PEPPER_MATRIX_TRANSLATE) {
+ pixman_transform_init_translate(&trans,
+ -pixman_double_to_fixed(node->transform.m[12]),
+ -pixman_double_to_fixed(node->transform.m[13]));
+ filter = PIXMAN_FILTER_NEAREST;
+ } else {
+ pixman_transform_from_pepper_mat4(&trans, &node->inverse);
+ filter = PIXMAN_FILTER_BILINEAR;
+ }
+
+ pepper_surface_get_buffer_offset(surface, &x, &y);
+ pepper_surface_get_size(surface, &w, &h);
+ pixman_transform_translate(&trans, NULL,
+ pixman_int_to_fixed(x), pixman_int_to_fixed(y));
+
+ switch (pepper_surface_get_buffer_transform(surface)) {
+ case WL_OUTPUT_TRANSFORM_FLIPPED:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+ pixman_transform_scale(&trans, NULL, pixman_int_to_fixed(-1),
+ pixman_int_to_fixed(1));
+ pixman_transform_translate(&trans, NULL, pixman_int_to_fixed(w), 0);
+ break;
+ }
+
+ switch (pepper_surface_get_buffer_transform(surface)) {
+ case WL_OUTPUT_TRANSFORM_NORMAL:
+ case WL_OUTPUT_TRANSFORM_FLIPPED:
+ break;
+ case WL_OUTPUT_TRANSFORM_90:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+ pixman_transform_rotate(&trans, NULL, 0, pixman_fixed_1);
+ pixman_transform_translate(&trans, NULL, pixman_int_to_fixed(h), 0);
+ break;
+ case WL_OUTPUT_TRANSFORM_180:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+ pixman_transform_rotate(&trans, NULL, -pixman_fixed_1, 0);
+ pixman_transform_translate(&trans, NULL,
+ pixman_int_to_fixed(w),
+ pixman_int_to_fixed(h));
+ break;
+ case WL_OUTPUT_TRANSFORM_270:
+ case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+ pixman_transform_rotate(&trans, NULL, 0, -pixman_fixed_1);
+ pixman_transform_translate(&trans, NULL, 0, pixman_int_to_fixed(w));
+ break;
+ }
+
+ scale = pepper_surface_get_buffer_scale(surface);
+ pixman_transform_scale(&trans, NULL,
+ pixman_int_to_fixed(scale),
+ pixman_int_to_fixed(scale));
+
+ pixman_image_set_transform(ps->image, &trans);
+ pixman_image_set_filter(ps->image, filter, NULL, 0);
+
+ pixman_region32_init(&repaint_surface);
+ pixman_region32_init_rect(&surface_blend, 0, 0, w, h);
+
+ if (node->transform.flags <= PEPPER_MATRIX_TRANSLATE) {
+ surface_opaque = pepper_surface_get_opaque_region(surface);
+ pixman_region32_subtract(&surface_blend, &surface_blend, surface_opaque);
+
+ if (pixman_region32_not_empty(surface_opaque)) {
+ pixman_region32_translate(surface_opaque,
+ (int)node->transform.m[12], (int)node->transform.m[13]);
+ pepper_pixman_region_global_to_output(surface_opaque, output);
+ pixman_region32_intersect(&repaint_surface, &repaint, surface_opaque);
+ pixman_image_set_clip_region32(target->image, &repaint_surface);
+
+ surface_state_begin_access(ps);
+ pixman_image_composite32(PIXMAN_OP_SRC, ps->image, NULL, target->image,
+ 0, 0, /* src_x, src_y */
+ 0, 0, /* mask_x, mask_y */
+ 0, 0, /* dest_x, dest_y */
+ pixman_image_get_width(target->image),
+ pixman_image_get_height(target->image));
+ surface_state_end_access(ps);
+ }
+
+ if (pixman_region32_not_empty(&surface_blend)) {
+ pixman_region32_translate(&surface_blend,
+ (int)node->transform.m[12], (int)node->transform.m[13]);
+ pepper_pixman_region_global_to_output(&surface_blend, output);
+ pixman_region32_intersect(&repaint_surface, &repaint, &surface_blend);
+ pixman_image_set_clip_region32(target->image, &repaint_surface);
+
+ surface_state_begin_access(ps);
+ pixman_image_composite32(PIXMAN_OP_OVER, ps->image, NULL, target->image,
+ 0, 0, /* src_x, src_y */
+ 0, 0, /* mask_x, mask_y */
+ 0, 0, /* dest_x, dest_y */
+ pixman_image_get_width(target->image),
+ pixman_image_get_height(target->image));
+ surface_state_end_access(ps);
+ }
+ } else {
+ pixman_region32_translate(&surface_blend,
+ (int)node->transform.m[12], (int)node->transform.m[13]);
+ pepper_pixman_region_global_to_output(&surface_blend, output);
+ pixman_region32_intersect(&repaint_surface, &repaint, &surface_blend);
+ pixman_image_set_clip_region32(target->image, &repaint_surface);
+
+ surface_state_begin_access(ps);
+ pixman_image_composite32(PIXMAN_OP_OVER, ps->image, NULL, target->image,
+ 0, 0, /* src_x, src_y */
+ 0, 0, /* mask_x, mask_y */
+ 0, 0, /* dest_x, dest_y */
+ pixman_image_get_width(target->image),
+ pixman_image_get_height(target->image));
+ surface_state_end_access(ps);
+ }
+
+ pixman_region32_fini(&repaint_surface);
+ pixman_region32_fini(&surface_blend);
+ }
+
+ pixman_region32_fini(&repaint);
}
static void
clear_background(pixman_renderer_t *renderer, pixman_region32_t *damage)
{
- pixman_render_target_t *target = (pixman_render_target_t *)renderer->base.target;
-
- pixman_image_set_clip_region32(target->image, damage);
- pixman_image_composite32(PIXMAN_OP_SRC, renderer->background, NULL, target->image,
- 0, 0, 0, 0, 0, 0,
- pixman_image_get_width(target->image),
- pixman_image_get_height(target->image));
+ pixman_render_target_t *target = (pixman_render_target_t *)
+ renderer->base.target;
+
+ pixman_image_set_clip_region32(target->image, damage);
+ pixman_image_composite32(PIXMAN_OP_SRC, renderer->background, NULL,
+ target->image,
+ 0, 0, 0, 0, 0, 0,
+ pixman_image_get_width(target->image),
+ pixman_image_get_height(target->image));
}
static void
-pixman_renderer_repaint_output(pepper_renderer_t *renderer, pepper_output_t *output,
- const pepper_list_t *render_list,
- pixman_region32_t *damage)
+pixman_renderer_repaint_output(pepper_renderer_t *renderer,
+ pepper_output_t *output,
+ const pepper_list_t *render_list,
+ pixman_region32_t *damage)
{
- if (pixman_region32_not_empty(damage))
- {
- pepper_list_t *l;
- pixman_renderer_t *pr = (pixman_renderer_t *)renderer;
+ if (pixman_region32_not_empty(damage)) {
+ pepper_list_t *l;
+ pixman_renderer_t *pr = (pixman_renderer_t *)renderer;
- if (pr->background)
- clear_background((pixman_renderer_t *)renderer, damage);
+ if (pr->background)
+ clear_background((pixman_renderer_t *)renderer, damage);
- pepper_list_for_each_list_reverse(l, render_list)
- repaint_view(renderer, output, (pepper_render_item_t *)l->item, damage);
- }
+ pepper_list_for_each_list_reverse(l, render_list)
+ repaint_view(renderer, output, (pepper_render_item_t *)l->item, damage);
+ }
}
PEPPER_API pepper_renderer_t *
pepper_pixman_renderer_create(pepper_compositor_t *compositor)
{
- pixman_renderer_t *renderer;
- const char *env;
+ pixman_renderer_t *renderer;
+ const char *env;
- renderer = calloc(1, sizeof(pixman_renderer_t));
- if (!renderer)
- return NULL;
+ renderer = calloc(1, sizeof(pixman_renderer_t));
+ if (!renderer)
+ return NULL;
- renderer->base.compositor = compositor;
+ renderer->base.compositor = compositor;
- env = getenv("PEPPER_RENDER_CLEAR_BACKGROUND");
+ env = getenv("PEPPER_RENDER_CLEAR_BACKGROUND");
- if (env && atoi(env) == 1)
- {
- pixman_color_t bg_color = { 0x0000, 0x0000, 0x0000, 0xffff };
- renderer->background = pixman_image_create_solid_fill(&bg_color);
- }
+ if (env && atoi(env) == 1) {
+ pixman_color_t bg_color = { 0x0000, 0x0000, 0x0000, 0xffff };
+ renderer->background = pixman_image_create_solid_fill(&bg_color);
+ }
- /* Backend functions. */
- renderer->base.destroy = pixman_renderer_destroy;
- renderer->base.attach_surface = pixman_renderer_attach_surface;
- renderer->base.flush_surface_damage = pixman_renderer_flush_surface_damage;
- renderer->base.read_pixels = pixman_renderer_read_pixels;
- renderer->base.repaint_output = pixman_renderer_repaint_output;
+ /* Backend functions. */
+ renderer->base.destroy = pixman_renderer_destroy;
+ renderer->base.attach_surface = pixman_renderer_attach_surface;
+ renderer->base.flush_surface_damage = pixman_renderer_flush_surface_damage;
+ renderer->base.read_pixels = pixman_renderer_read_pixels;
+ renderer->base.repaint_output = pixman_renderer_repaint_output;
- return &renderer->base;
+ return &renderer->base;
}
static void
pixman_render_target_destroy(pepper_render_target_t *target)
{
- pixman_render_target_t *pt = (pixman_render_target_t *)target;
+ pixman_render_target_t *pt = (pixman_render_target_t *)target;
- if (pt->image)
- pixman_image_unref(pt->image);
+ if (pt->image)
+ pixman_image_unref(pt->image);
- free(target);
+ free(target);
}
PEPPER_API pepper_render_target_t *
pepper_pixman_renderer_create_target(pepper_format_t format, void *pixels,
- int stride, int width, int height)
+ int stride, int width, int height)
{
- pixman_render_target_t *target;
- pixman_format_code_t pixman_format;
+ pixman_render_target_t *target;
+ pixman_format_code_t pixman_format;
- target = calloc(1, sizeof(pixman_render_target_t));
- if (!target)
- return NULL;
+ target = calloc(1, sizeof(pixman_render_target_t));
+ if (!target)
+ return NULL;
- target->base.destroy = pixman_render_target_destroy;
+ target->base.destroy = pixman_render_target_destroy;
- pixman_format = get_pixman_format(format);
- if (!pixman_format)
- goto error;
+ pixman_format = get_pixman_format(format);
+ if (!pixman_format)
+ goto error;
- target->image = pixman_image_create_bits(pixman_format, width, height, pixels, stride);
- if (!target->image)
- goto error;
+ target->image = pixman_image_create_bits(pixman_format, width, height, pixels,
+ stride);
+ if (!target->image)
+ goto error;
- target->base.destroy = pixman_render_target_destroy;
- return &target->base;
+ target->base.destroy = pixman_render_target_destroy;
+ return &target->base;
error:
- if (target)
- free(target);
+ if (target)
+ free(target);
- return NULL;
+ return NULL;
}
PEPPER_API pepper_render_target_t *
pepper_pixman_renderer_create_target_for_image(pixman_image_t *image)
{
- pixman_render_target_t *target;
+ pixman_render_target_t *target;
- target = calloc(1, sizeof(pixman_render_target_t));
- if (!target)
- return NULL;
+ target = calloc(1, sizeof(pixman_render_target_t));
+ if (!target)
+ return NULL;
- pixman_image_ref(image);
- target->image = image;
- target->base.destroy = pixman_render_target_destroy;
+ pixman_image_ref(image);
+ target->image = image;
+ target->base.destroy = pixman_render_target_destroy;
- return &target->base;
+ return &target->base;
}
PEPPER_API void
pepper_renderer_destroy(pepper_renderer_t *renderer)
{
- renderer->destroy(renderer);
+ renderer->destroy(renderer);
}
PEPPER_API void
pepper_render_target_destroy(pepper_render_target_t *target)
{
- target->destroy(target);
+ target->destroy(target);
}
PEPPER_API pepper_bool_t
-pepper_renderer_set_target(pepper_renderer_t *renderer, pepper_render_target_t *target)
+pepper_renderer_set_target(pepper_renderer_t *renderer,
+ pepper_render_target_t *target)
{
- if (target->renderer != NULL && target->renderer != renderer)
- return PEPPER_FALSE;
+ if (target->renderer != NULL && target->renderer != renderer)
+ return PEPPER_FALSE;
- renderer->target = target;
- return PEPPER_TRUE;
+ renderer->target = target;
+ return PEPPER_TRUE;
}
PEPPER_API pepper_render_target_t *
pepper_renderer_get_target(pepper_renderer_t *renderer)
{
- return renderer->target;
+ return renderer->target;
}
PEPPER_API pepper_bool_t
pepper_renderer_attach_surface(pepper_renderer_t *renderer,
- pepper_surface_t *surface, int *w, int *h)
+ pepper_surface_t *surface, int *w, int *h)
{
- return renderer->attach_surface(renderer, surface, w, h);
+ return renderer->attach_surface(renderer, surface, w, h);
}
PEPPER_API pepper_bool_t
-pepper_renderer_flush_surface_damage(pepper_renderer_t *renderer, pepper_surface_t *surface)
+pepper_renderer_flush_surface_damage(pepper_renderer_t *renderer,
+ pepper_surface_t *surface)
{
- return renderer->flush_surface_damage(renderer, surface);
+ return renderer->flush_surface_damage(renderer, surface);
}
PEPPER_API void
-pepper_renderer_repaint_output(pepper_renderer_t *renderer, pepper_output_t *output,
- const pepper_list_t *view_list, pixman_region32_t *damage)
+pepper_renderer_repaint_output(pepper_renderer_t *renderer,
+ pepper_output_t *output,
+ const pepper_list_t *view_list, pixman_region32_t *damage)
{
- renderer->repaint_output(renderer, output, view_list, damage);
+ renderer->repaint_output(renderer, output, view_list, damage);
}
PEPPER_API pepper_bool_t
-pepper_renderer_read_pixels(pepper_renderer_t *renderer, int x, int y, int w, int h,
- void *pixels, pepper_format_t format)
+pepper_renderer_read_pixels(pepper_renderer_t *renderer, int x, int y, int w,
+ int h,
+ void *pixels, pepper_format_t format)
{
- return renderer->read_pixels(renderer, x, y, w, h, pixels, format);
+ return renderer->read_pixels(renderer, x, y, w, h, pixels, format);
}
static int
__tdm_handle_event(int fd, uint32_t mask, void *data)
{
- pepper_tdm_t *tdm = data;
+ pepper_tdm_t *tdm = data;
- tdm_display_handle_events(tdm->disp);
- return 0;
+ tdm_display_handle_events(tdm->disp);
+ return 0;
}
PEPPER_API pepper_tdm_t *
pepper_tdm_create(pepper_compositor_t *compositor)
{
- tdm_error ret;
- pepper_tdm_t *tdm = NULL;
- struct wl_event_loop *loop;
+ tdm_error ret;
+ pepper_tdm_t *tdm = NULL;
+ struct wl_event_loop *loop;
- tdm = calloc(1, sizeof(pepper_tdm_t));
- tdm->fd = -1;
- PEPPER_CHECK(tdm, goto error, "calloc() failed.\n");
+ tdm = calloc(1, sizeof(pepper_tdm_t));
+ tdm->fd = -1;
+ PEPPER_CHECK(tdm, goto error, "calloc() failed.\n");
- tdm->compositor = compositor;
- tdm->disp = tdm_display_init(&ret);
- PEPPER_CHECK(ret == TDM_ERROR_NONE, goto error, "tdm_display_init() failed %d\n", ret);
+ tdm->compositor = compositor;
+ tdm->disp = tdm_display_init(&ret);
+ PEPPER_CHECK(ret == TDM_ERROR_NONE, goto error,
+ "tdm_display_init() failed %d\n", ret);
- ret = tdm_display_get_fd(tdm->disp, &tdm->fd);
- PEPPER_CHECK(ret == TDM_ERROR_NONE, goto error, "tdm_display_get_fd() failed %d\n", ret);
+ ret = tdm_display_get_fd(tdm->disp, &tdm->fd);
+ PEPPER_CHECK(ret == TDM_ERROR_NONE, goto error,
+ "tdm_display_get_fd() failed %d\n", ret);
- tdm->bufmgr = tbm_bufmgr_init(tdm->fd);
- PEPPER_CHECK(tdm->bufmgr, goto error, "tbm_bufmgr_init() failed \n");
+ tdm->bufmgr = tbm_bufmgr_init(tdm->fd);
+ PEPPER_CHECK(tdm->bufmgr, goto error, "tbm_bufmgr_init() failed \n");
#ifdef HAVE_TBM
- /* Create wayland-tbm
- FIXME : Cannot get filepath for tbm
- */
+ /* Create wayland-tbm
+ FIXME : Cannot get filepath for tbm
+ */
- tdm->wl_tbm_server = wayland_tbm_server_init(pepper_compositor_get_display(compositor),
- "/dev/dri/card0", tdm->fd, 0);
+ tdm->wl_tbm_server = wayland_tbm_server_init(pepper_compositor_get_display(
+ compositor),
+ "/dev/dri/card0", tdm->fd, 0);
#endif
- /*Setup outputs*/
- pepper_tdm_output_init(tdm);
+ /*Setup outputs*/
+ pepper_tdm_output_init(tdm);
- /* Add TDM event FDs to the compositor's display. */
- loop = wl_display_get_event_loop(pepper_compositor_get_display(compositor));
+ /* Add TDM event FDs to the compositor's display. */
+ loop = wl_display_get_event_loop(pepper_compositor_get_display(compositor));
- tdm->tdm_event_source = wl_event_loop_add_fd(loop, tdm->fd, WL_EVENT_READABLE,
- __tdm_handle_event, tdm);
- PEPPER_CHECK(tdm->tdm_event_source, goto error, "wl_event_loop_add() failed.\n");
+ tdm->tdm_event_source = wl_event_loop_add_fd(loop, tdm->fd, WL_EVENT_READABLE,
+ __tdm_handle_event, tdm);
+ PEPPER_CHECK(tdm->tdm_event_source, goto error,
+ "wl_event_loop_add() failed.\n");
- if (!pepper_compositor_set_clock_id(compositor, CLOCK_MONOTONIC))
- goto error;
+ if (!pepper_compositor_set_clock_id(compositor, CLOCK_MONOTONIC))
+ goto error;
- return tdm;
+ return tdm;
error:
- if (tdm)
- pepper_tdm_destroy(tdm);
+ if (tdm)
+ pepper_tdm_destroy(tdm);
- return NULL;
+ return NULL;
}
PEPPER_API void
pepper_tdm_destroy(pepper_tdm_t *tdm)
{
- if (tdm->tdm_event_source)
- wl_event_source_remove(tdm->tdm_event_source);
+ if (tdm->tdm_event_source)
+ wl_event_source_remove(tdm->tdm_event_source);
- if (tdm->wl_tbm_server)
- wayland_tbm_server_deinit(tdm->wl_tbm_server);
+ if (tdm->wl_tbm_server)
+ wayland_tbm_server_deinit(tdm->wl_tbm_server);
- if (tdm->bufmgr)
- tbm_bufmgr_deinit(tdm->bufmgr);
+ if (tdm->bufmgr)
+ tbm_bufmgr_deinit(tdm->bufmgr);
- if (tdm->disp)
- tdm_display_deinit(tdm->disp);
+ if (tdm->disp)
+ tdm_display_deinit(tdm->disp);
- if (tdm->fd != -1)
- close(tdm->fd);
+ if (tdm->fd != -1)
+ close(tdm->fd);
- free(tdm);
+ free(tdm);
}
typedef struct pepper_tdm_output pepper_tdm_output_t;
typedef struct pepper_tdm_plane pepper_tdm_plane_t;
-typedef enum tdm_render_type
-{
- TDM_RENDER_TYPE_PIXMAN,
- TDM_RENDER_TYPE_GL,
+typedef enum tdm_render_type {
+ TDM_RENDER_TYPE_PIXMAN,
+ TDM_RENDER_TYPE_GL,
} tdm_render_type_t;
-struct pepper_tdm
-{
- pepper_compositor_t *compositor;
- tdm_display *disp;
- tbm_bufmgr bufmgr;
- int fd;
+struct pepper_tdm {
+ pepper_compositor_t *compositor;
+ tdm_display *disp;
+ tbm_bufmgr bufmgr;
+ int fd;
- pepper_list_t output_list;
+ pepper_list_t output_list;
- struct wayland_tbm_server *wl_tbm_server;
- struct wl_event_source *tdm_event_source;
+ struct wayland_tbm_server *wl_tbm_server;
+ struct wl_event_source *tdm_event_source;
- pepper_renderer_t *pixman_renderer;
- pepper_renderer_t *gl_renderer;
+ pepper_renderer_t *pixman_renderer;
+ pepper_renderer_t *gl_renderer;
};
-struct pepper_tdm_output
-{
- pepper_output_t *base;
- pepper_tdm_t *tdm;
- pepper_tdm_output_t *output;
- pepper_tdm_plane_t *primary_plane;
+struct pepper_tdm_output {
+ pepper_output_t *base;
+ pepper_tdm_t *tdm;
+ pepper_tdm_output_t *output;
+ pepper_tdm_plane_t *primary_plane;
- tbm_surface_queue_h tbm_surface_queue;
+ tbm_surface_queue_h tbm_surface_queue;
- tdm_render_type_t render_type;
- pepper_renderer_t *renderer;
- pepper_render_target_t *render_target;
+ tdm_render_type_t render_type;
+ pepper_renderer_t *renderer;
+ pepper_render_target_t *render_target;
- tbm_surface_h back, front;
- pepper_bool_t page_flip_pending;
- /*For pixman*/
- pixman_region32_t previous_damage;
+ tbm_surface_h back, front;
+ pepper_bool_t page_flip_pending;
+ /*For pixman*/
+ pixman_region32_t previous_damage;
};
-struct pepper_tdm_plane
-{
- pepper_plane_t *base;
- pepper_tdm_output_t *output;
- tdm_layer *layer;
- tdm_layer_capability caps;
+struct pepper_tdm_plane {
+ pepper_plane_t *base;
+ pepper_tdm_output_t *output;
+ tdm_layer *layer;
+ tdm_layer_capability caps;
};
int pepper_tdm_output_init(pepper_tdm_t *tdm);
static void
__tdm_renderer_pixman_free_target(void *user_data)
{
- pepper_render_target_t *target = user_data;
+ pepper_render_target_t *target = user_data;
- if (target)
- pepper_render_target_destroy(target);
+ if (target)
+ pepper_render_target_destroy(target);
}
static pepper_render_target_t *
__tdm_renderer_pixman_get_target(tbm_surface_h surface)
{
- tbm_bo bo;
- pepper_render_target_t *target=NULL;
-
- bo = tbm_surface_internal_get_bo(surface, 0);
- if(!tbm_bo_get_user_data(bo, KEY_RENDER_TARGET, (void**)&target))
- {
- tbm_surface_info_s info;
- pepper_format_t format;
-
- tbm_bo_add_user_data(bo, KEY_RENDER_TARGET, __tdm_renderer_pixman_free_target);
-
- tbm_surface_get_info(surface, &info);
- switch(info.format)
- {
- case TBM_FORMAT_XRGB8888:
- format = PEPPER_FORMAT_XRGB8888;
- break;
- case TBM_FORMAT_ARGB8888:
- format = PEPPER_FORMAT_ARGB8888;
- break;
- default:
- tbm_bo_delete_user_data(bo, KEY_RENDER_TARGET);
- PEPPER_ERROR("Unknown tbm format\n");
- return NULL;
- }
- target = pepper_pixman_renderer_create_target(format, info.planes[0].ptr,
- info.planes[0].stride,
- info.width, info.height);
- if (!target)
- {
- tbm_bo_delete_user_data(bo, KEY_RENDER_TARGET);
- PEPPER_ERROR("pepper_pixman_renderer_create_target() fail\n");
- return NULL;
- }
- tbm_bo_set_user_data(bo, KEY_RENDER_TARGET, target);
- }
-
- return target;
+ tbm_bo bo;
+ pepper_render_target_t *target = NULL;
+
+ bo = tbm_surface_internal_get_bo(surface, 0);
+ if (!tbm_bo_get_user_data(bo, KEY_RENDER_TARGET, (void **)&target)) {
+ tbm_surface_info_s info;
+ pepper_format_t format;
+
+ tbm_bo_add_user_data(bo, KEY_RENDER_TARGET, __tdm_renderer_pixman_free_target);
+
+ tbm_surface_get_info(surface, &info);
+ switch (info.format) {
+ case TBM_FORMAT_XRGB8888:
+ format = PEPPER_FORMAT_XRGB8888;
+ break;
+ case TBM_FORMAT_ARGB8888:
+ format = PEPPER_FORMAT_ARGB8888;
+ break;
+ default:
+ tbm_bo_delete_user_data(bo, KEY_RENDER_TARGET);
+ PEPPER_ERROR("Unknown tbm format\n");
+ return NULL;
+ }
+ target = pepper_pixman_renderer_create_target(format, info.planes[0].ptr,
+ info.planes[0].stride,
+ info.width, info.height);
+ if (!target) {
+ tbm_bo_delete_user_data(bo, KEY_RENDER_TARGET);
+ PEPPER_ERROR("pepper_pixman_renderer_create_target() fail\n");
+ return NULL;
+ }
+ tbm_bo_set_user_data(bo, KEY_RENDER_TARGET, target);
+ }
+
+ return target;
}
static void
__tdm_renderer_pixman_render(pepper_tdm_output_t *output)
{
- const pepper_list_t *render_list = pepper_plane_get_render_list(output->primary_plane->base);
- pixman_region32_t *damage = pepper_plane_get_damage_region(output->primary_plane->base);
- pixman_region32_t total_damage;
- tbm_surface_h back;
- pepper_render_target_t *target;
-
- int ret;
-
- /*Set render target*/
- ret = tbm_surface_queue_dequeue(output->tbm_surface_queue, &back);
- PEPPER_CHECK(ret == TBM_SURFACE_QUEUE_ERROR_NONE, return, "tbm_surface_queue_dequeue() failed\n");
-
- target = __tdm_renderer_pixman_get_target(back);
- if (PEPPER_FALSE == pepper_renderer_set_target(output->renderer, target))
- {
- PEPPER_ERROR("pepper_renderer_set_target() failed\n");
- return;
- }
-
- pixman_region32_init(&total_damage);
- pixman_region32_union(&total_damage, damage, &output->previous_damage);
- pixman_region32_copy(&output->previous_damage, damage);
-
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, &total_damage);
-
- pixman_region32_fini(&total_damage);
- pepper_plane_clear_damage_region(output->primary_plane->base);
-
- output->back = back;
+ const pepper_list_t *render_list = pepper_plane_get_render_list(
+ output->primary_plane->base);
+ pixman_region32_t *damage = pepper_plane_get_damage_region(
+ output->primary_plane->base);
+ pixman_region32_t total_damage;
+ tbm_surface_h back;
+ pepper_render_target_t *target;
+
+ int ret;
+
+ /*Set render target*/
+ ret = tbm_surface_queue_dequeue(output->tbm_surface_queue, &back);
+ PEPPER_CHECK(ret == TBM_SURFACE_QUEUE_ERROR_NONE, return,
+ "tbm_surface_queue_dequeue() failed\n");
+
+ target = __tdm_renderer_pixman_get_target(back);
+ if (PEPPER_FALSE == pepper_renderer_set_target(output->renderer, target)) {
+ PEPPER_ERROR("pepper_renderer_set_target() failed\n");
+ return;
+ }
+
+ pixman_region32_init(&total_damage);
+ pixman_region32_union(&total_damage, damage, &output->previous_damage);
+ pixman_region32_copy(&output->previous_damage, damage);
+
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ &total_damage);
+
+ pixman_region32_fini(&total_damage);
+ pepper_plane_clear_damage_region(output->primary_plane->base);
+
+ output->back = back;
}
static void
__tdm_renderer_pixman_fini(pepper_tdm_output_t *output)
{
- pixman_region32_fini(&output->previous_damage);
+ pixman_region32_fini(&output->previous_damage);
- if (output->render_target)
- pepper_render_target_destroy(output->render_target);
+ if (output->render_target)
+ pepper_render_target_destroy(output->render_target);
- if (output->tbm_surface_queue)
- tbm_surface_queue_destroy(output->tbm_surface_queue);
+ if (output->tbm_surface_queue)
+ tbm_surface_queue_destroy(output->tbm_surface_queue);
- output->renderer = NULL;
- output->render_target = NULL;
- output->tbm_surface_queue = NULL;
+ output->renderer = NULL;
+ output->render_target = NULL;
+ output->tbm_surface_queue = NULL;
}
static void
__tdm_renderer_pixman_init(pepper_tdm_output_t *output)
{
- pepper_tdm_t *tdm = output->tdm;
- const tdm_output_mode *mode;
+ pepper_tdm_t *tdm = output->tdm;
+ const tdm_output_mode *mode;
- if (!tdm->pixman_renderer)
- {
- tdm->pixman_renderer = pepper_pixman_renderer_create(tdm->compositor);
- PEPPER_CHECK(tdm->pixman_renderer, return, "pepper_pixman_renderer_create() failed.\n");
- }
+ if (!tdm->pixman_renderer) {
+ tdm->pixman_renderer = pepper_pixman_renderer_create(tdm->compositor);
+ PEPPER_CHECK(tdm->pixman_renderer, return,
+ "pepper_pixman_renderer_create() failed.\n");
+ }
- output->renderer = tdm->pixman_renderer;
+ output->renderer = tdm->pixman_renderer;
- tdm_output_get_mode(output->output, &mode);
- output->tbm_surface_queue = tbm_surface_queue_create(3,
- mode->width, mode->height,
- TBM_FORMAT_XBGR8888, TBM_BO_SCANOUT);
- PEPPER_CHECK(output->tbm_surface_queue, goto error, "tbm_surface_queue_create() failed.\n");
+ tdm_output_get_mode(output->output, &mode);
+ output->tbm_surface_queue = tbm_surface_queue_create(3,
+ mode->width, mode->height,
+ TBM_FORMAT_XBGR8888, TBM_BO_SCANOUT);
+ PEPPER_CHECK(output->tbm_surface_queue, goto error,
+ "tbm_surface_queue_create() failed.\n");
- pixman_region32_init(&output->previous_damage);
- output->render_type = TDM_RENDER_TYPE_PIXMAN;
+ pixman_region32_init(&output->previous_damage);
+ output->render_type = TDM_RENDER_TYPE_PIXMAN;
- return;
+ return;
error:
- __tdm_renderer_pixman_fini(output);
+ __tdm_renderer_pixman_fini(output);
}
static void
__tdm_renderer_gl_render(pepper_tdm_output_t *output)
{
- int ret;
+ int ret;
- const pepper_list_t *render_list = pepper_plane_get_render_list(output->primary_plane->base);
- pixman_region32_t *damage = pepper_plane_get_damage_region(output->primary_plane->base);
+ const pepper_list_t *render_list = pepper_plane_get_render_list(
+ output->primary_plane->base);
+ pixman_region32_t *damage = pepper_plane_get_damage_region(
+ output->primary_plane->base);
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, damage);
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ damage);
- ret = tbm_surface_queue_can_acquire(output->tbm_surface_queue, 1);
- PEPPER_CHECK(ret > 0, return, "tbm_surface_queue_can_acquire() failed.\n");
+ ret = tbm_surface_queue_can_acquire(output->tbm_surface_queue, 1);
+ PEPPER_CHECK(ret > 0, return, "tbm_surface_queue_can_acquire() failed.\n");
- ret = tbm_surface_queue_acquire(output->tbm_surface_queue, &output->back);
- PEPPER_CHECK(ret==TBM_SURFACE_QUEUE_ERROR_NONE, return, "tbm_surface_queue_acquire() failed.\n");
+ ret = tbm_surface_queue_acquire(output->tbm_surface_queue, &output->back);
+ PEPPER_CHECK(ret == TBM_SURFACE_QUEUE_ERROR_NONE, return,
+ "tbm_surface_queue_acquire() failed.\n");
- pepper_plane_clear_damage_region(output->primary_plane->base);
+ pepper_plane_clear_damage_region(output->primary_plane->base);
}
static void
__tdm_renderer_gl_fini(pepper_tdm_output_t *output)
{
- if (output->render_target)
- pepper_render_target_destroy(output->render_target);
+ if (output->render_target)
+ pepper_render_target_destroy(output->render_target);
- if (output->tbm_surface_queue)
- tbm_surface_queue_destroy(output->tbm_surface_queue);
+ if (output->tbm_surface_queue)
+ tbm_surface_queue_destroy(output->tbm_surface_queue);
- output->renderer = NULL;
- output->render_target = NULL;
- output->tbm_surface_queue = NULL;
+ output->renderer = NULL;
+ output->render_target = NULL;
+ output->tbm_surface_queue = NULL;
}
static void
__tdm_renderer_gl_init(pepper_tdm_output_t *output)
{
- pepper_tdm_t *tdm = output->tdm;
- const tdm_output_mode *mode;
- uint32_t native_visual_id = TBM_FORMAT_XRGB8888;
-
- if (!tdm->gl_renderer)
- {
- tdm->gl_renderer = pepper_gl_renderer_create(tdm->compositor, tdm->bufmgr, "tbm");
- PEPPER_CHECK(tdm->gl_renderer, return, "pepper_gl_renderer_create() failed.\n");
- }
-
- output->renderer = tdm->gl_renderer;
-
- tdm_output_get_mode(output->output, &mode);
- output->tbm_surface_queue = tbm_surface_queue_create(3,
- mode->width, mode->height,
- TBM_FORMAT_XRGB8888,
- TBM_BO_SCANOUT);
- PEPPER_CHECK(output->tbm_surface_queue, goto error, "tbm_surface_queue_create() failed.\n");
-
- output->render_target = pepper_gl_renderer_create_target(tdm->gl_renderer,
- output->tbm_surface_queue,
- PEPPER_FORMAT_XRGB8888,
- &native_visual_id,
- mode->width, mode->height);
- PEPPER_CHECK(output->render_target, goto error, "pepper_gl_renderer_create_target() failed.\n");
- output->render_type = TDM_RENDER_TYPE_GL;
-
- pepper_renderer_set_target(output->renderer, output->render_target);
- return;
+ pepper_tdm_t *tdm = output->tdm;
+ const tdm_output_mode *mode;
+ uint32_t native_visual_id = TBM_FORMAT_XRGB8888;
+
+ if (!tdm->gl_renderer) {
+ tdm->gl_renderer = pepper_gl_renderer_create(tdm->compositor, tdm->bufmgr,
+ "tbm");
+ PEPPER_CHECK(tdm->gl_renderer, return, "pepper_gl_renderer_create() failed.\n");
+ }
+
+ output->renderer = tdm->gl_renderer;
+
+ tdm_output_get_mode(output->output, &mode);
+ output->tbm_surface_queue = tbm_surface_queue_create(3,
+ mode->width, mode->height,
+ TBM_FORMAT_XRGB8888,
+ TBM_BO_SCANOUT);
+ PEPPER_CHECK(output->tbm_surface_queue, goto error,
+ "tbm_surface_queue_create() failed.\n");
+
+ output->render_target = pepper_gl_renderer_create_target(tdm->gl_renderer,
+ output->tbm_surface_queue,
+ PEPPER_FORMAT_XRGB8888,
+ &native_visual_id,
+ mode->width, mode->height);
+ PEPPER_CHECK(output->render_target, goto error,
+ "pepper_gl_renderer_create_target() failed.\n");
+ output->render_type = TDM_RENDER_TYPE_GL;
+
+ pepper_renderer_set_target(output->renderer, output->render_target);
+ return;
error:
- __tdm_renderer_gl_fini(output);
+ __tdm_renderer_gl_fini(output);
}
static void
__tdm_plane_destroy(pepper_event_listener_t *listener, pepper_object_t *object,
- uint32_t id, void *info, void *data)
+ uint32_t id, void *info, void *data)
{
- free(data);
+ free(data);
}
static int
__tdm_output_plane_init(pepper_tdm_output_t *output)
{
- int num_layer, i;
- pepper_tdm_plane_t *plane;
- pepper_plane_t *prev=NULL;
- const tdm_output_mode *mode;
- tdm_info_layer info;
-
- tdm_error err;
-
- err = tdm_output_get_mode(output->output, &mode);
- PEPPER_CHECK(err == TDM_ERROR_NONE, return PEPPER_FALSE, "tdm_output_get_mode()\n");
-
- /*TODO : set default layer info*/
- info.transform = TDM_TRANSFORM_NORMAL;
- info.dst_pos.x = 0;
- info.dst_pos.y = 0;
- info.dst_pos.w = mode->width;
- info.dst_pos.h = mode->height;
- info.src_config.size.h = mode->width;
- info.src_config.size.v = mode->height;
- info.src_config.pos.x = 0;
- info.src_config.pos.y = 0;
- info.src_config.pos.w = mode->width;
- info.src_config.pos.h = mode->height;
-
- tdm_output_get_layer_count(output->output, &num_layer);
- PEPPER_CHECK(num_layer > 0, return PEPPER_FALSE, "number of tdm_layer is 0\n");
-
- for (i=0; i<num_layer; i++)
- {
- plane = (pepper_tdm_plane_t *)calloc(1, sizeof(pepper_tdm_plane_t));
- PEPPER_CHECK(plane, return PEPPER_FALSE, "calloc failed\n");
-
- plane->layer = (tdm_layer*)tdm_output_get_layer(output->output, i, &err);
- PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
- "tdm_output_get_layer failed err:%d\n", err);
-
- plane->base = pepper_output_add_plane(output->base, prev);
- PEPPER_CHECK(plane->base, goto error,
- "pepper_output_add_plane() failed\n");
- pepper_object_add_event_listener((pepper_object_t *)plane->base,
- PEPPER_EVENT_OBJECT_DESTROY,
- 0,
- __tdm_plane_destroy, plane);
-
- tdm_layer_get_capabilities(plane->layer, &plane->caps);
- if (plane->caps & TDM_LAYER_CAPABILITY_PRIMARY)
- {
- output->primary_plane = plane;
- }
- tdm_layer_set_info(plane->layer, &info);
- }
-
- if (!output->primary_plane)
- {
- PEPPER_ERROR("primary plane is NULL\n");
- return PEPPER_FALSE;
- }
-
- return PEPPER_TRUE;
+ int num_layer, i;
+ pepper_tdm_plane_t *plane;
+ pepper_plane_t *prev = NULL;
+ const tdm_output_mode *mode;
+ tdm_info_layer info;
+
+ tdm_error err;
+
+ err = tdm_output_get_mode(output->output, &mode);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, return PEPPER_FALSE,
+ "tdm_output_get_mode()\n");
+
+ /*TODO : set default layer info*/
+ info.transform = TDM_TRANSFORM_NORMAL;
+ info.dst_pos.x = 0;
+ info.dst_pos.y = 0;
+ info.dst_pos.w = mode->width;
+ info.dst_pos.h = mode->height;
+ info.src_config.size.h = mode->width;
+ info.src_config.size.v = mode->height;
+ info.src_config.pos.x = 0;
+ info.src_config.pos.y = 0;
+ info.src_config.pos.w = mode->width;
+ info.src_config.pos.h = mode->height;
+
+ tdm_output_get_layer_count(output->output, &num_layer);
+ PEPPER_CHECK(num_layer > 0, return PEPPER_FALSE, "number of tdm_layer is 0\n");
+
+ for (i = 0; i < num_layer; i++) {
+ plane = (pepper_tdm_plane_t *)calloc(1, sizeof(pepper_tdm_plane_t));
+ PEPPER_CHECK(plane, return PEPPER_FALSE, "calloc failed\n");
+
+ plane->layer = (tdm_layer *)tdm_output_get_layer(output->output, i, &err);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
+ "tdm_output_get_layer failed err:%d\n", err);
+
+ plane->base = pepper_output_add_plane(output->base, prev);
+ PEPPER_CHECK(plane->base, goto error,
+ "pepper_output_add_plane() failed\n");
+ pepper_object_add_event_listener((pepper_object_t *)plane->base,
+ PEPPER_EVENT_OBJECT_DESTROY,
+ 0,
+ __tdm_plane_destroy, plane);
+
+ tdm_layer_get_capabilities(plane->layer, &plane->caps);
+ if (plane->caps & TDM_LAYER_CAPABILITY_PRIMARY) {
+ output->primary_plane = plane;
+ }
+ tdm_layer_set_info(plane->layer, &info);
+ }
+
+ if (!output->primary_plane) {
+ PEPPER_ERROR("primary plane is NULL\n");
+ return PEPPER_FALSE;
+ }
+
+ return PEPPER_TRUE;
error:
- if (plane->base)
- pepper_plane_destroy(plane->base);
- else
- free(plane);
+ if (plane->base)
+ pepper_plane_destroy(plane->base);
+ else
+ free(plane);
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
static void
__tdm_output_commit_cb(tdm_output *o, unsigned int sequence,
- unsigned int tv_sec, unsigned int tv_usec, void *user_data)
+ unsigned int tv_sec, unsigned int tv_usec, void *user_data)
{
- pepper_tdm_output_t *output = user_data;
- struct timespec ts;
+ pepper_tdm_output_t *output = user_data;
+ struct timespec ts;
- if (output->page_flip_pending == PEPPER_TRUE)
- {
- output->page_flip_pending = PEPPER_FALSE;
+ if (output->page_flip_pending == PEPPER_TRUE) {
+ output->page_flip_pending = PEPPER_FALSE;
- if (output->front)
- {
- tbm_surface_queue_release(output->tbm_surface_queue, output->front);
- }
+ if (output->front) {
+ tbm_surface_queue_release(output->tbm_surface_queue, output->front);
+ }
- output->front = output->back;
- output->back = NULL;
- }
+ output->front = output->back;
+ output->back = NULL;
+ }
- ts.tv_sec = tv_sec;
- ts.tv_nsec = tv_usec * 1000;
- pepper_output_finish_frame(output->base, &ts);
+ ts.tv_sec = tv_sec;
+ ts.tv_nsec = tv_usec * 1000;
+ pepper_output_finish_frame(output->base, &ts);
}
static void
pepper_tdm_output_destroy(void *o)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- /* TODO: */
+ /* TODO: */
- free(output);
+ free(output);
}
static int32_t
pepper_tdm_output_get_subpixel_order(void *o)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- unsigned int subpixel;
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ unsigned int subpixel;
- tdm_output_get_subpixel(output->output, &subpixel);
- switch(subpixel)
- {
- default:
- subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
- }
+ tdm_output_get_subpixel(output->output, &subpixel);
+ switch (subpixel) {
+ default:
+ subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
+ }
- return subpixel;
+ return subpixel;
}
static const char *
pepper_tdm_output_get_maker_name(void *o)
{
- return "tizen.org";
+ return "tizen.org";
}
static const char *
pepper_tdm_output_get_model_name(void *o)
{
- return "TDM";
+ return "TDM";
}
static int
pepper_tdm_output_get_mode_count(void *o)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- int num_mode;
- const tdm_output_mode *modes;
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ int num_mode;
+ const tdm_output_mode *modes;
- tdm_output_get_available_modes(output->output, &modes, &num_mode);
- return num_mode;
+ tdm_output_get_available_modes(output->output, &modes, &num_mode);
+ return num_mode;
}
static void
pepper_tdm_output_get_mode(void *o, int index, pepper_output_mode_t *mode)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- int num_mode;
- const tdm_output_mode *modes;
- const tdm_output_mode *cur_mode;
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ int num_mode;
+ const tdm_output_mode *modes;
+ const tdm_output_mode *cur_mode;
- tdm_output_get_available_modes(output->output, &modes, &num_mode);
- PEPPER_CHECK(index < num_mode, return, "mode index is invalid\n");
+ tdm_output_get_available_modes(output->output, &modes, &num_mode);
+ PEPPER_CHECK(index < num_mode, return, "mode index is invalid\n");
- mode->flags = 0;
- mode->w = modes[index].width;
- mode->h = modes[index].height;
- mode->refresh = modes[index].refresh;
+ mode->flags = 0;
+ mode->w = modes[index].width;
+ mode->h = modes[index].height;
+ mode->refresh = modes[index].refresh;
- if (modes[index].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
- mode->flags |= WL_OUTPUT_MODE_PREFERRED;
+ if (modes[index].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
+ mode->flags |= WL_OUTPUT_MODE_PREFERRED;
- tdm_output_get_mode(output->output, &cur_mode);
- if (cur_mode == &modes[index])
- mode->flags |= WL_OUTPUT_MODE_CURRENT;
+ tdm_output_get_mode(output->output, &cur_mode);
+ if (cur_mode == &modes[index])
+ mode->flags |= WL_OUTPUT_MODE_CURRENT;
}
static pepper_bool_t
pepper_tdm_output_set_mode(void *o, const pepper_output_mode_t *mode)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- int num_mode, i;
- const tdm_output_mode *modes;
- tdm_error err;
-
- tdm_output_get_available_modes(output->output, &modes, &num_mode);
- for (i=0; i<num_mode; i++)
- {
- if (mode->w == (int32_t)modes[i].width &&
- mode->h == (int32_t)modes[i].height &&
- mode->refresh == (int32_t)modes[i].refresh)
- {
- err = tdm_output_set_mode(output->output, &modes[i]);
- PEPPER_CHECK(err == TDM_ERROR_NONE, return PEPPER_FALSE,
- "tdm_output_set_mode() failed mode:%s\n", modes[i].name);
- return PEPPER_TRUE;
- }
- }
-
- return PEPPER_FALSE;
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ int num_mode, i;
+ const tdm_output_mode *modes;
+ tdm_error err;
+
+ tdm_output_get_available_modes(output->output, &modes, &num_mode);
+ for (i = 0; i < num_mode; i++) {
+ if (mode->w == (int32_t)modes[i].width &&
+ mode->h == (int32_t)modes[i].height &&
+ mode->refresh == (int32_t)modes[i].refresh) {
+ err = tdm_output_set_mode(output->output, &modes[i]);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, return PEPPER_FALSE,
+ "tdm_output_set_mode() failed mode:%s\n", modes[i].name);
+ return PEPPER_TRUE;
+ }
+ }
+
+ return PEPPER_FALSE;
}
static void
pepper_tdm_output_assign_planes(void *o, const pepper_list_t *view_list)
{
- pepper_list_t *l;
- pepper_tdm_output_t *output = o;
+ pepper_list_t *l;
+ pepper_tdm_output_t *output = o;
- pepper_list_for_each_list(l, view_list)
- {
- pepper_view_t *view = l->item;
- pepper_plane_t *plane = NULL;
+ pepper_list_for_each_list(l, view_list) {
+ pepper_view_t *view = l->item;
+ pepper_plane_t *plane = NULL;
- plane = output->primary_plane->base;
+ plane = output->primary_plane->base;
- pepper_view_assign_plane(view, output->base, plane);
- }
+ pepper_view_assign_plane(view, output->base, plane);
+ }
}
static void
pepper_tdm_output_start_repaint_loop(void *o)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- struct timespec ts;
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ struct timespec ts;
- pepper_compositor_get_time(output->tdm->compositor, &ts);
- pepper_output_finish_frame(output->base, &ts);
+ pepper_compositor_get_time(output->tdm->compositor, &ts);
+ pepper_output_finish_frame(output->base, &ts);
}
static void
pepper_tdm_output_repaint(void *o, const pepper_list_t *plane_list)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- tdm_error err;
-
- if (!output->back)
- {
- if (output->render_type == TDM_RENDER_TYPE_GL)
- __tdm_renderer_gl_render(output);
- else if (output->render_type == TDM_RENDER_TYPE_PIXMAN)
- __tdm_renderer_pixman_render(output);
- else
- {
- PEPPER_ERROR("Unknown render type\n");
- return;
- }
- }
-
- if (output->back)
- {
- err = tdm_layer_set_buffer((tdm_layer*)output->primary_plane->layer, output->back);
- PEPPER_CHECK(err == TDM_ERROR_NONE, return, "tdm_layer_set_buffer() failed");
-
- err = tdm_output_commit(output->output, 0, __tdm_output_commit_cb, output);
- PEPPER_CHECK(err == TDM_ERROR_NONE, return, "tdm_output_commit() failed");
-
- output->page_flip_pending = PEPPER_TRUE;
- }
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ tdm_error err;
+
+ if (!output->back) {
+ if (output->render_type == TDM_RENDER_TYPE_GL)
+ __tdm_renderer_gl_render(output);
+ else if (output->render_type == TDM_RENDER_TYPE_PIXMAN)
+ __tdm_renderer_pixman_render(output);
+ else {
+ PEPPER_ERROR("Unknown render type\n");
+ return;
+ }
+ }
+
+ if (output->back) {
+ err = tdm_layer_set_buffer((tdm_layer *)output->primary_plane->layer,
+ output->back);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, return, "tdm_layer_set_buffer() failed");
+
+ err = tdm_output_commit(output->output, 0, __tdm_output_commit_cb, output);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, return, "tdm_output_commit() failed");
+
+ output->page_flip_pending = PEPPER_TRUE;
+ }
}
static void
-pepper_tdm_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h)
+pepper_tdm_output_attach_surface(void *o, pepper_surface_t *surface, int *w,
+ int *h)
{
- pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
- pepper_renderer_attach_surface(output->renderer, surface, w, h);
+ pepper_tdm_output_t *output = (pepper_tdm_output_t *)o;
+ pepper_renderer_attach_surface(output->renderer, surface, w, h);
}
static void
-pepper_tdm_output_flush_surface_damage(void *o, pepper_surface_t *surface, pepper_bool_t *keep_buffer)
+pepper_tdm_output_flush_surface_damage(void *o, pepper_surface_t *surface,
+ pepper_bool_t *keep_buffer)
{
- pepper_tdm_output_t *output = o;
- pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
-
- pepper_renderer_flush_surface_damage(output->renderer, surface);
-
- if (output->render_type == TDM_RENDER_TYPE_GL &&
- (buffer && wl_shm_buffer_get(pepper_buffer_get_resource(buffer))))
- {
- *keep_buffer = PEPPER_FALSE;
- }
- else
- {
- *keep_buffer = PEPPER_TRUE;
- }
+ pepper_tdm_output_t *output = o;
+ pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
+
+ pepper_renderer_flush_surface_damage(output->renderer, surface);
+
+ if (output->render_type == TDM_RENDER_TYPE_GL &&
+ (buffer && wl_shm_buffer_get(pepper_buffer_get_resource(buffer)))) {
+ *keep_buffer = PEPPER_FALSE;
+ } else {
+ *keep_buffer = PEPPER_TRUE;
+ }
}
-struct pepper_output_backend tdm_output_backend =
-{
- pepper_tdm_output_destroy,
+struct pepper_output_backend tdm_output_backend = {
+ pepper_tdm_output_destroy,
- pepper_tdm_output_get_subpixel_order,
- pepper_tdm_output_get_maker_name,
- pepper_tdm_output_get_model_name,
+ pepper_tdm_output_get_subpixel_order,
+ pepper_tdm_output_get_maker_name,
+ pepper_tdm_output_get_model_name,
- pepper_tdm_output_get_mode_count,
- pepper_tdm_output_get_mode,
- pepper_tdm_output_set_mode,
+ pepper_tdm_output_get_mode_count,
+ pepper_tdm_output_get_mode,
+ pepper_tdm_output_set_mode,
- pepper_tdm_output_assign_planes,
- pepper_tdm_output_start_repaint_loop,
- pepper_tdm_output_repaint,
- pepper_tdm_output_attach_surface,
- pepper_tdm_output_flush_surface_damage,
+ pepper_tdm_output_assign_planes,
+ pepper_tdm_output_start_repaint_loop,
+ pepper_tdm_output_repaint,
+ pepper_tdm_output_attach_surface,
+ pepper_tdm_output_flush_surface_damage,
};
int
pepper_tdm_output_init(pepper_tdm_t *tdm)
{
- pepper_tdm_output_t *output;
- tdm_error err;
- int i;
-
- int num_output;
- tdm_output_conn_status status;
-
- const tdm_output_mode *modes;
- const tdm_output_mode *default_mode = NULL;
- const tdm_output_mode *preferred_mode = NULL;
- int num_mode;
-
- const char *render_env = getenv("PEPPER_RENDERER");
-
- tdm_display_get_output_count(tdm->disp, &num_output);
- PEPPER_CHECK(num_output > 0, return PEPPER_FALSE, "Number of output is 0\n");
-
- while(num_output--)
- {
- output = (pepper_tdm_output_t*)calloc(1, sizeof(pepper_tdm_output_t));
- output->tdm = tdm;
- output->output = (tdm_output *)tdm_display_get_output(tdm->disp, num_output, &err);
- PEPPER_CHECK((output->output && (err == TDM_ERROR_NONE)), goto error,
- "tdm_display_get_output(%d) failed err:%d\n", num_output, err);
-
- /*Check connection state*/
- err = tdm_output_get_conn_status(output->output, &status);
- PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
- "tdm_display_get_output(%d) failed err:%d\n", num_output, err);
- if (status != TDM_OUTPUT_CONN_STATUS_CONNECTED)
- continue;
-
-
- /*Setup default mode*/
- err = tdm_output_get_available_modes(output->output, &modes, &num_mode);
- PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
- "tdm_output_get_available_modes(%d) failed err:%d\n", num_output, err);
- for (i=0; i<num_mode; i++)
- {
- if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
- preferred_mode = &modes[i];
-
- if (modes[i].type & TDM_OUTPUT_MODE_TYPE_DEFAULT)
- default_mode = &modes[i];
- }
-
- if (preferred_mode)
- {
- err = tdm_output_set_mode(output->output, preferred_mode);
- PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
- "tdm_output_set_mode() failed err:%d\n",err);
- }
- else if(default_mode)
- {
- err = tdm_output_set_mode(output->output, default_mode);
- PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
- "tdm_output_set_mode() failed err:%d\n",err);
- }
- else
- {
- err = tdm_output_set_mode(output->output, &modes[0]);
- PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
- "tdm_output_set_mode() failed err:%d\n",err);
- }
-
- /*Setup renderer*/
- if (render_env && !strcmp(render_env, "gl"))
- {
- __tdm_renderer_gl_init(output);
- PEPPER_CHECK(output->renderer, goto error, "Failed to initialize gl_renderer.\n");
- }
-
- if (!output->renderer)
- {
- __tdm_renderer_pixman_init(output);
- PEPPER_CHECK(output->renderer, goto error, "Failed to initialize pixman_renderer.\n");
- }
-
- /*Add pepper_output to compositor*/
- output->base = pepper_compositor_add_output(tdm->compositor,
- &tdm_output_backend,
- "tdm_output",
- output,
- WL_OUTPUT_TRANSFORM_NORMAL, 1);
- PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
- "pepper_compositor_add_output() failed err:%d\n",err);
-
- PEPPER_CHECK(PEPPER_TRUE == __tdm_output_plane_init(output), goto error,
- "pepper_tdm_plane_init() failed\n");
- }
-
- return PEPPER_TRUE;
-
- error:
- if (output->base)
- pepper_output_destroy(output->base);
- else
- free(output);
-
- return PEPPER_FALSE;
+ pepper_tdm_output_t *output;
+ tdm_error err;
+ int i;
+
+ int num_output;
+ tdm_output_conn_status status;
+
+ const tdm_output_mode *modes;
+ const tdm_output_mode *default_mode = NULL;
+ const tdm_output_mode *preferred_mode = NULL;
+ int num_mode;
+
+ const char *render_env = getenv("PEPPER_RENDERER");
+
+ tdm_display_get_output_count(tdm->disp, &num_output);
+ PEPPER_CHECK(num_output > 0, return PEPPER_FALSE, "Number of output is 0\n");
+
+ while (num_output--) {
+ output = (pepper_tdm_output_t *)calloc(1, sizeof(pepper_tdm_output_t));
+ output->tdm = tdm;
+ output->output = (tdm_output *)tdm_display_get_output(tdm->disp, num_output,
+ &err);
+ PEPPER_CHECK((output->output && (err == TDM_ERROR_NONE)), goto error,
+ "tdm_display_get_output(%d) failed err:%d\n", num_output, err);
+
+ /*Check connection state*/
+ err = tdm_output_get_conn_status(output->output, &status);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
+ "tdm_display_get_output(%d) failed err:%d\n", num_output, err);
+ if (status != TDM_OUTPUT_CONN_STATUS_CONNECTED)
+ continue;
+
+
+ /*Setup default mode*/
+ err = tdm_output_get_available_modes(output->output, &modes, &num_mode);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
+ "tdm_output_get_available_modes(%d) failed err:%d\n", num_output, err);
+ for (i = 0; i < num_mode; i++) {
+ if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
+ preferred_mode = &modes[i];
+
+ if (modes[i].type & TDM_OUTPUT_MODE_TYPE_DEFAULT)
+ default_mode = &modes[i];
+ }
+
+ if (preferred_mode) {
+ err = tdm_output_set_mode(output->output, preferred_mode);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
+ "tdm_output_set_mode() failed err:%d\n", err);
+ } else if (default_mode) {
+ err = tdm_output_set_mode(output->output, default_mode);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
+ "tdm_output_set_mode() failed err:%d\n", err);
+ } else {
+ err = tdm_output_set_mode(output->output, &modes[0]);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
+ "tdm_output_set_mode() failed err:%d\n", err);
+ }
+
+ /*Setup renderer*/
+ if (render_env && !strcmp(render_env, "gl")) {
+ __tdm_renderer_gl_init(output);
+ PEPPER_CHECK(output->renderer, goto error,
+ "Failed to initialize gl_renderer.\n");
+ }
+
+ if (!output->renderer) {
+ __tdm_renderer_pixman_init(output);
+ PEPPER_CHECK(output->renderer, goto error,
+ "Failed to initialize pixman_renderer.\n");
+ }
+
+ /*Add pepper_output to compositor*/
+ output->base = pepper_compositor_add_output(tdm->compositor,
+ &tdm_output_backend,
+ "tdm_output",
+ output,
+ WL_OUTPUT_TRANSFORM_NORMAL, 1);
+ PEPPER_CHECK(err == TDM_ERROR_NONE, goto error,
+ "pepper_compositor_add_output() failed err:%d\n", err);
+
+ PEPPER_CHECK(PEPPER_TRUE == __tdm_output_plane_init(output), goto error,
+ "pepper_tdm_plane_init() failed\n");
+ }
+
+ return PEPPER_TRUE;
+
+error:
+ if (output->base)
+ pepper_output_destroy(output->base);
+ else
+ free(output);
+
+ return PEPPER_FALSE;
}
typedef struct pepper_wayland pepper_wayland_t;
PEPPER_API pepper_wayland_t *
-pepper_wayland_connect(pepper_compositor_t *compositor, const char *socket_name);
+pepper_wayland_connect(pepper_compositor_t *compositor,
+ const char *socket_name);
PEPPER_API void
pepper_wayland_destroy(pepper_wayland_t *conn);
PEPPER_API pepper_output_t *
-pepper_wayland_output_create(pepper_wayland_t *conn, int32_t w, int32_t h, const char *renderer);
+pepper_wayland_output_create(pepper_wayland_t *conn, int32_t w, int32_t h,
+ const char *renderer);
#ifdef __cplusplus
}
char *
string_alloc(int len)
{
- return (char *)malloc((len + 1) * sizeof (char));
+ return (char *)malloc((len + 1) * sizeof (char));
}
char *
string_copy(const char *str)
{
- int len = strlen(str);
- char *ret = string_alloc(len);
+ int len = strlen(str);
+ char *ret = string_alloc(len);
- if (ret)
- memcpy(ret, str, (len + 1) * sizeof (char));
+ if (ret)
+ memcpy(ret, str, (len + 1) * sizeof (char));
- return ret;
+ return ret;
}
void
string_free(char *str)
{
- free(str);
+ free(str);
}
static void
handle_global(void *data, struct wl_registry *registry,
- uint32_t name, const char *interface, uint32_t version)
+ uint32_t name, const char *interface, uint32_t version)
{
- pepper_wayland_t *conn = data;
-
- if (strcmp(interface, "wl_compositor") == 0)
- {
- conn->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
- }
- else if (strcmp(interface, "wl_seat") == 0)
- {
- wayland_handle_global_seat(conn, registry, name, version);
- }
- else if (strcmp(interface, "wl_shell") == 0)
- {
- conn->shell = wl_registry_bind(registry, name, &wl_shell_interface, 1);
- }
- else if (strcmp(interface, "wl_shm") == 0)
- {
- conn->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
- }
+ pepper_wayland_t *conn = data;
+
+ if (strcmp(interface, "wl_compositor") == 0) {
+ conn->compositor = wl_registry_bind(registry, name, &wl_compositor_interface,
+ 1);
+ } else if (strcmp(interface, "wl_seat") == 0) {
+ wayland_handle_global_seat(conn, registry, name, version);
+ } else if (strcmp(interface, "wl_shell") == 0) {
+ conn->shell = wl_registry_bind(registry, name, &wl_shell_interface, 1);
+ } else if (strcmp(interface, "wl_shm") == 0) {
+ conn->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
+ }
}
static void
handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
{
- /* TODO: */
+ /* TODO: */
}
-static const struct wl_registry_listener registry_listener =
-{
- handle_global,
- handle_global_remove,
+static const struct wl_registry_listener registry_listener = {
+ handle_global,
+ handle_global_remove,
};
static int
handle_wayland_event(int fd, uint32_t mask, void *data)
{
- pepper_wayland_t *conn = data;
- int count = 0;
+ pepper_wayland_t *conn = data;
+ int count = 0;
- if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR))
- return 0;
+ if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR))
+ return 0;
- if (mask & WL_EVENT_READABLE)
- count = wl_display_dispatch(conn->display);
+ if (mask & WL_EVENT_READABLE)
+ count = wl_display_dispatch(conn->display);
- if (mask & WL_EVENT_WRITABLE)
- wl_display_flush(conn->display);
+ if (mask & WL_EVENT_WRITABLE)
+ wl_display_flush(conn->display);
- if (mask == 0)
- {
- count = wl_display_dispatch_pending(conn->display);
- wl_display_flush(conn->display);
- }
+ if (mask == 0) {
+ count = wl_display_dispatch_pending(conn->display);
+ wl_display_flush(conn->display);
+ }
- return count;
+ return count;
}
PEPPER_API pepper_wayland_t *
pepper_wayland_connect(pepper_compositor_t *compositor, const char *socket_name)
{
- pepper_wayland_t *conn;
- struct wl_display *compositor_display;
- struct wl_event_loop *loop;
+ pepper_wayland_t *conn;
+ struct wl_display *compositor_display;
+ struct wl_event_loop *loop;
- conn = (pepper_wayland_t *)calloc(1, sizeof(pepper_wayland_t));
- if (!conn)
- return NULL;
+ conn = (pepper_wayland_t *)calloc(1, sizeof(pepper_wayland_t));
+ if (!conn)
+ return NULL;
- conn->pepper = compositor;
+ conn->pepper = compositor;
- conn->socket_name = string_copy(socket_name);
- conn->display = wl_display_connect(socket_name);
- conn->fd = wl_display_get_fd(conn->display);
+ conn->socket_name = string_copy(socket_name);
+ conn->display = wl_display_connect(socket_name);
+ conn->fd = wl_display_get_fd(conn->display);
- conn->gl_renderer = pepper_gl_renderer_create(compositor, conn->display, "wayland");
- conn->pixman_renderer = pepper_pixman_renderer_create(compositor);
+ conn->gl_renderer = pepper_gl_renderer_create(compositor, conn->display,
+ "wayland");
+ conn->pixman_renderer = pepper_pixman_renderer_create(compositor);
- if (!conn->pixman_renderer)
- {
- free(conn);
- return NULL;
- }
+ if (!conn->pixman_renderer) {
+ free(conn);
+ return NULL;
+ }
- compositor_display = pepper_compositor_get_display(compositor);
- loop = wl_display_get_event_loop(compositor_display);
- conn->event_source = wl_event_loop_add_fd(loop, conn->fd, WL_EVENT_READABLE,
- handle_wayland_event, conn);
- wl_event_source_check(conn->event_source);
+ compositor_display = pepper_compositor_get_display(compositor);
+ loop = wl_display_get_event_loop(compositor_display);
+ conn->event_source = wl_event_loop_add_fd(loop, conn->fd, WL_EVENT_READABLE,
+ handle_wayland_event, conn);
+ wl_event_source_check(conn->event_source);
- pepper_list_init(&conn->seat_list);
- pepper_list_init(&conn->output_list);
+ pepper_list_init(&conn->seat_list);
+ pepper_list_init(&conn->output_list);
- conn->registry = wl_display_get_registry(conn->display);
- wl_registry_add_listener(conn->registry, ®istry_listener, conn);
- wl_display_roundtrip(conn->display);
+ conn->registry = wl_display_get_registry(conn->display);
+ wl_registry_add_listener(conn->registry, ®istry_listener, conn);
+ wl_display_roundtrip(conn->display);
- return conn;
+ return conn;
}
PEPPER_API void
pepper_wayland_destroy(pepper_wayland_t *conn)
{
- wayland_output_t *output, *tmp;
+ wayland_output_t *output, *tmp;
- pepper_list_for_each_safe(output, tmp, &conn->output_list, link)
- pepper_output_destroy(output->base);
+ pepper_list_for_each_safe(output, tmp, &conn->output_list, link)
+ pepper_output_destroy(output->base);
- if (conn->pixman_renderer)
- pepper_renderer_destroy(conn->pixman_renderer);
+ if (conn->pixman_renderer)
+ pepper_renderer_destroy(conn->pixman_renderer);
- if (conn->gl_renderer)
- pepper_renderer_destroy(conn->gl_renderer);
+ if (conn->gl_renderer)
+ pepper_renderer_destroy(conn->gl_renderer);
- if (conn->socket_name)
- string_free(conn->socket_name);
+ if (conn->socket_name)
+ string_free(conn->socket_name);
- if (conn->event_source)
- wl_event_source_remove(conn->event_source);
+ if (conn->event_source)
+ wl_event_source_remove(conn->event_source);
- if (conn->registry)
- wl_registry_destroy(conn->registry);
+ if (conn->registry)
+ wl_registry_destroy(conn->registry);
- if (conn->compositor)
- wl_compositor_destroy(conn->compositor);
+ if (conn->compositor)
+ wl_compositor_destroy(conn->compositor);
- if (conn->shell)
- wl_shell_destroy(conn->shell);
+ if (conn->shell)
+ wl_shell_destroy(conn->shell);
- free(conn);
+ free(conn);
}
static void
pointer_handle_enter(void *data, struct wl_pointer *pointer,
- uint32_t serial, struct wl_surface *surface,
- wl_fixed_t surface_x, wl_fixed_t surface_y)
+ uint32_t serial, struct wl_surface *surface,
+ wl_fixed_t surface_x, wl_fixed_t surface_y)
{
- /* TODO */
+ /* TODO */
}
static void
pointer_handle_leave(void *data, struct wl_pointer *pointer,
- uint32_t serial, struct wl_surface *surface)
+ uint32_t serial, struct wl_surface *surface)
{
- /* TODO */
+ /* TODO */
}
static void
pointer_handle_motion(void *data, struct wl_pointer *pointer,
- uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
+ uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
{
- /* TODO */
+ /* TODO */
}
static void
pointer_handle_button(void *data, struct wl_pointer *pointer,
- uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
+ uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
{
- /* TODO */
+ /* TODO */
}
static void
pointer_handle_axis(void *data, struct wl_pointer *pointer,
- uint32_t time, uint32_t axis, wl_fixed_t value)
+ uint32_t time, uint32_t axis, wl_fixed_t value)
{
- /* TODO */
+ /* TODO */
}
-static const struct wl_pointer_listener pointer_listener =
-{
- pointer_handle_enter,
- pointer_handle_leave,
- pointer_handle_motion,
- pointer_handle_button,
- pointer_handle_axis,
+static const struct wl_pointer_listener pointer_listener = {
+ pointer_handle_enter,
+ pointer_handle_leave,
+ pointer_handle_motion,
+ pointer_handle_button,
+ pointer_handle_axis,
};
static void
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
- uint32_t format, int32_t fd, uint32_t size)
+ uint32_t format, int32_t fd, uint32_t size)
{
- /* TODO */
+ /* TODO */
}
static void
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
- uint32_t serial, struct wl_surface *surface,
- struct wl_array *keys)
+ uint32_t serial, struct wl_surface *surface,
+ struct wl_array *keys)
{
- /* TODO */
+ /* TODO */
}
static void
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
- uint32_t serial, struct wl_surface *surface)
+ uint32_t serial, struct wl_surface *surface)
{
- /* TODO */
+ /* TODO */
}
static void
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
- uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
+ uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
{
- /* TODO */
+ /* TODO */
}
static void
keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
- uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
- uint32_t mods_locked, uint32_t group)
+ uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
+ uint32_t mods_locked, uint32_t group)
{
- /* TODO */
+ /* TODO */
}
static void
keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
- int32_t rate, int32_t delay)
+ int32_t rate, int32_t delay)
{
- /* TODO */
+ /* TODO */
}
-static const struct wl_keyboard_listener keyboard_listener =
-{
- keyboard_handle_keymap,
- keyboard_handle_enter,
- keyboard_handle_leave,
- keyboard_handle_key,
- keyboard_handle_modifiers,
- keyboard_handle_repeat_info
+static const struct wl_keyboard_listener keyboard_listener = {
+ keyboard_handle_keymap,
+ keyboard_handle_enter,
+ keyboard_handle_leave,
+ keyboard_handle_key,
+ keyboard_handle_modifiers,
+ keyboard_handle_repeat_info
};
static void
touch_handle_down(void *data, struct wl_touch *touch,
- uint32_t serial, uint32_t time, struct wl_surface *surface,
- int32_t id, wl_fixed_t x, wl_fixed_t y)
+ uint32_t serial, uint32_t time, struct wl_surface *surface,
+ int32_t id, wl_fixed_t x, wl_fixed_t y)
{
- /* TODO */
+ /* TODO */
}
static void
touch_handle_up(void *data, struct wl_touch *touch,
- uint32_t serial, uint32_t time, int32_t id)
+ uint32_t serial, uint32_t time, int32_t id)
{
- /* TODO */
+ /* TODO */
}
static void
touch_handle_motion(void *data, struct wl_touch *touch,
- uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y)
+ uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y)
{
- /* TODO */
+ /* TODO */
}
static void
touch_handle_frame(void *data, struct wl_touch *touch)
{
- /* TODO */
+ /* TODO */
}
static void
touch_handle_cancel(void *data, struct wl_touch *touch)
{
- /* TODO */
+ /* TODO */
}
-static const struct wl_touch_listener touch_listener =
-{
- touch_handle_down,
- touch_handle_up,
- touch_handle_motion,
- touch_handle_frame,
- touch_handle_cancel,
+static const struct wl_touch_listener touch_listener = {
+ touch_handle_down,
+ touch_handle_up,
+ touch_handle_motion,
+ touch_handle_frame,
+ touch_handle_cancel,
};
static void
seat_handle_caps(void *data, struct wl_seat *s, enum wl_seat_capability caps)
{
- wayland_seat_t *seat = (wayland_seat_t *)data;
-
- if (seat->seat != s) /* FIXME */
- return;
-
- if ((caps & WL_SEAT_CAPABILITY_POINTER) && (!seat->pointer.wl_pointer))
- {
- seat->pointer.wl_pointer = wl_seat_get_pointer(seat->seat);
- if (seat->pointer.wl_pointer)
- wl_pointer_add_listener(seat->pointer.wl_pointer, &pointer_listener, seat);
-
- seat->pointer.base = pepper_input_device_create(seat->conn->pepper,
- WL_SEAT_CAPABILITY_POINTER,
- NULL, NULL);
- }
- else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && (seat->pointer.wl_pointer))
- {
- pepper_input_device_destroy(seat->pointer.base);
- wl_pointer_release(seat->pointer.wl_pointer);
- seat->pointer.wl_pointer = NULL;
- }
-
- if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && (!seat->keyboard.wl_keyboard))
- {
- seat->keyboard.wl_keyboard = wl_seat_get_keyboard(seat->seat);
- if (seat->keyboard.wl_keyboard)
- wl_keyboard_add_listener(seat->keyboard.wl_keyboard, &keyboard_listener, seat);
-
- seat->keyboard.base = pepper_input_device_create(seat->conn->pepper,
- WL_SEAT_CAPABILITY_KEYBOARD,
- NULL, NULL);
- }
- else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (seat->keyboard.wl_keyboard))
- {
- pepper_input_device_destroy(seat->keyboard.base);
- wl_keyboard_release(seat->keyboard.wl_keyboard);
- seat->keyboard.wl_keyboard = NULL;
- }
-
- if ((caps & WL_SEAT_CAPABILITY_TOUCH) && (!seat->touch.wl_touch))
- {
- seat->touch.wl_touch = wl_seat_get_touch(seat->seat);
- if (seat->touch.wl_touch)
- wl_touch_add_listener(seat->touch.wl_touch, &touch_listener, seat);
-
- seat->touch.base = pepper_input_device_create(seat->conn->pepper,
- WL_SEAT_CAPABILITY_KEYBOARD,
- NULL, NULL);
- }
- else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && (seat->touch.wl_touch))
- {
- pepper_input_device_destroy(seat->touch.base);
- wl_touch_release(seat->touch.wl_touch);
- seat->touch.wl_touch = NULL;
- }
+ wayland_seat_t *seat = (wayland_seat_t *)data;
+
+ if (seat->seat != s) /* FIXME */
+ return;
+
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && (!seat->pointer.wl_pointer)) {
+ seat->pointer.wl_pointer = wl_seat_get_pointer(seat->seat);
+ if (seat->pointer.wl_pointer)
+ wl_pointer_add_listener(seat->pointer.wl_pointer, &pointer_listener, seat);
+
+ seat->pointer.base = pepper_input_device_create(seat->conn->pepper,
+ WL_SEAT_CAPABILITY_POINTER,
+ NULL, NULL);
+ } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && (seat->pointer.wl_pointer)) {
+ pepper_input_device_destroy(seat->pointer.base);
+ wl_pointer_release(seat->pointer.wl_pointer);
+ seat->pointer.wl_pointer = NULL;
+ }
+
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && (!seat->keyboard.wl_keyboard)) {
+ seat->keyboard.wl_keyboard = wl_seat_get_keyboard(seat->seat);
+ if (seat->keyboard.wl_keyboard)
+ wl_keyboard_add_listener(seat->keyboard.wl_keyboard, &keyboard_listener, seat);
+
+ seat->keyboard.base = pepper_input_device_create(seat->conn->pepper,
+ WL_SEAT_CAPABILITY_KEYBOARD,
+ NULL, NULL);
+ } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) &&
+ (seat->keyboard.wl_keyboard)) {
+ pepper_input_device_destroy(seat->keyboard.base);
+ wl_keyboard_release(seat->keyboard.wl_keyboard);
+ seat->keyboard.wl_keyboard = NULL;
+ }
+
+ if ((caps & WL_SEAT_CAPABILITY_TOUCH) && (!seat->touch.wl_touch)) {
+ seat->touch.wl_touch = wl_seat_get_touch(seat->seat);
+ if (seat->touch.wl_touch)
+ wl_touch_add_listener(seat->touch.wl_touch, &touch_listener, seat);
+
+ seat->touch.base = pepper_input_device_create(seat->conn->pepper,
+ WL_SEAT_CAPABILITY_KEYBOARD,
+ NULL, NULL);
+ } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && (seat->touch.wl_touch)) {
+ pepper_input_device_destroy(seat->touch.base);
+ wl_touch_release(seat->touch.wl_touch);
+ seat->touch.wl_touch = NULL;
+ }
}
static void
seat_handle_name(void *data, struct wl_seat *s, const char *name)
{
- /* TODO */
+ /* TODO */
}
-static const struct wl_seat_listener seat_listener =
-{
- seat_handle_caps,
- seat_handle_name,
+static const struct wl_seat_listener seat_listener = {
+ seat_handle_caps,
+ seat_handle_name,
};
void
wayland_handle_global_seat(pepper_wayland_t *conn, struct wl_registry *registry,
- uint32_t name, uint32_t version)
+ uint32_t name, uint32_t version)
{
- wayland_seat_t *seat;
+ wayland_seat_t *seat;
- seat = (wayland_seat_t *)calloc(1, sizeof(wayland_seat_t));
- if (!seat)
- {
- PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
- return;
- }
+ seat = (wayland_seat_t *)calloc(1, sizeof(wayland_seat_t));
+ if (!seat) {
+ PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__);
+ return;
+ }
- seat->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
- wl_seat_add_listener(seat->seat, &seat_listener, seat);
+ seat->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
+ wl_seat_add_listener(seat->seat, &seat_listener, seat);
- seat->conn = conn;
- seat->id = name;
+ seat->conn = conn;
+ seat->id = name;
- pepper_list_insert(&conn->seat_list, &seat->link);
+ pepper_list_insert(&conn->seat_list, &seat->link);
}
typedef struct wayland_seat wayland_seat_t;
typedef struct wayland_shm_buffer wayland_shm_buffer_t;
-struct pepper_wayland
-{
- pepper_compositor_t *pepper;
+struct pepper_wayland {
+ pepper_compositor_t *pepper;
- char *socket_name;
- struct wl_display *display;
- int fd;
+ char *socket_name;
+ struct wl_display *display;
+ int fd;
- struct wl_event_source *event_source;
+ struct wl_event_source *event_source;
- struct wl_registry *registry;
- struct wl_compositor *compositor;
- struct wl_shell *shell;
- pepper_list_t seat_list;
- pepper_list_t output_list;
+ struct wl_registry *registry;
+ struct wl_compositor *compositor;
+ struct wl_shell *shell;
+ pepper_list_t seat_list;
+ pepper_list_t output_list;
- struct wl_signal destroy_signal;
+ struct wl_signal destroy_signal;
- struct wl_shm *shm;
+ struct wl_shm *shm;
- pepper_renderer_t *pixman_renderer;
- pepper_renderer_t *gl_renderer;
+ pepper_renderer_t *pixman_renderer;
+ pepper_renderer_t *gl_renderer;
};
-struct wayland_shm_buffer
-{
- wayland_output_t *output;
- pepper_list_t link;
+struct wayland_shm_buffer {
+ wayland_output_t *output;
+ pepper_list_t link;
- struct wl_buffer *buffer;
+ struct wl_buffer *buffer;
- void *pixels;
- int stride;
- int size;
- int w, h;
+ void *pixels;
+ int stride;
+ int size;
+ int w, h;
- pepper_render_target_t *target;
- pixman_region32_t damage;
+ pepper_render_target_t *target;
+ pixman_region32_t damage;
- void *data;
+ void *data;
};
-struct wayland_output
-{
- pepper_wayland_t *conn;
- pepper_output_t *base;
- char name[32];
+struct wayland_output {
+ pepper_wayland_t *conn;
+ pepper_output_t *base;
+ char name[32];
- struct wl_listener conn_destroy_listener;
+ struct wl_listener conn_destroy_listener;
- int32_t w, h;
- int32_t subpixel;
+ int32_t w, h;
+ int32_t subpixel;
- struct wl_surface *surface;
- struct wl_shell_surface *shell_surface;
+ struct wl_surface *surface;
+ struct wl_shell_surface *shell_surface;
- pepper_renderer_t *renderer;
- pepper_render_target_t *render_target;
- pepper_render_target_t *gl_render_target;
+ pepper_renderer_t *renderer;
+ pepper_render_target_t *render_target;
+ pepper_render_target_t *gl_render_target;
- void (*render_pre)(wayland_output_t *output);
- void (*render_post)(wayland_output_t *output);
+ void (*render_pre)(wayland_output_t *output);
+ void (*render_post)(wayland_output_t *output);
- struct {
- /* list containing free buffers. */
- pepper_list_t free_buffers;
+ struct {
+ /* list containing free buffers. */
+ pepper_list_t free_buffers;
- /* list containing attached but not released (from the compositor) buffers. */
- pepper_list_t attached_buffers;
+ /* list containing attached but not released (from the compositor) buffers. */
+ pepper_list_t attached_buffers;
- /* current render target buffer. */
- wayland_shm_buffer_t *current_buffer;
- } shm;
+ /* current render target buffer. */
+ wayland_shm_buffer_t *current_buffer;
+ } shm;
#if ENABLE_WAYLAND_BACKEND_EGL
- struct {
- struct wl_egl_window *window;
- } egl;
+ struct {
+ struct wl_egl_window *window;
+ } egl;
#endif
- pepper_plane_t *primary_plane;
- pepper_list_t link;
+ pepper_plane_t *primary_plane;
+ pepper_list_t link;
};
-struct wayland_seat
-{
- pepper_wayland_t *conn;
- struct wl_seat *seat;
- uint32_t id;
-
- struct
- {
- pepper_input_device_t *base;
- struct wl_pointer *wl_pointer;
- } pointer;
-
- struct
- {
- pepper_input_device_t *base;
- struct wl_keyboard *wl_keyboard;
- } keyboard;
-
- struct
- {
- pepper_input_device_t *base;
- struct wl_touch *wl_touch;
- } touch;
-
- pepper_list_t link;
+struct wayland_seat {
+ pepper_wayland_t *conn;
+ struct wl_seat *seat;
+ uint32_t id;
+
+ struct {
+ pepper_input_device_t *base;
+ struct wl_pointer *wl_pointer;
+ } pointer;
+
+ struct {
+ pepper_input_device_t *base;
+ struct wl_keyboard *wl_keyboard;
+ } keyboard;
+
+ struct {
+ pepper_input_device_t *base;
+ struct wl_touch *wl_touch;
+ } touch;
+
+ pepper_list_t link;
};
void
wayland_handle_global_seat(pepper_wayland_t *conn, struct wl_registry *registry,
- uint32_t name, uint32_t version);
+ uint32_t name, uint32_t version);
wayland_shm_buffer_t *
wayland_shm_buffer_create(wayland_output_t *output);
static const char *model_name = "wayland";
static void
-shell_surface_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial)
+shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
+ uint32_t serial)
{
- wl_shell_surface_pong(shell_surface, serial);
+ wl_shell_surface_pong(shell_surface, serial);
}
static void
-shell_surface_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t edges,
- int32_t w, int32_t h)
+shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
+ uint32_t edges,
+ int32_t w, int32_t h)
{
- wayland_output_t *output = data;
- wayland_shm_buffer_t *buffer, *tmp;
+ wayland_output_t *output = data;
+ wayland_shm_buffer_t *buffer, *tmp;
- output->w = w;
- output->h = h;
+ output->w = w;
+ output->h = h;
- /* Destroy free buffers immediately. */
- pepper_list_for_each_safe(buffer, tmp, &output->shm.free_buffers, link)
- wayland_shm_buffer_destroy(buffer);
+ /* Destroy free buffers immediately. */
+ pepper_list_for_each_safe(buffer, tmp, &output->shm.free_buffers, link)
+ wayland_shm_buffer_destroy(buffer);
- /* Orphan attached buffers. They will be destroyed when the compositor releases them. */
- pepper_list_for_each_safe(buffer, tmp, &output->shm.attached_buffers, link)
- {
- buffer->output = NULL;
- pepper_list_remove(&buffer->link);
- }
+ /* Orphan attached buffers. They will be destroyed when the compositor releases them. */
+ pepper_list_for_each_safe(buffer, tmp, &output->shm.attached_buffers, link) {
+ buffer->output = NULL;
+ pepper_list_remove(&buffer->link);
+ }
- PEPPER_ASSERT(pepper_list_empty(&output->shm.free_buffers));
- PEPPER_ASSERT(pepper_list_empty(&output->shm.attached_buffers));
+ PEPPER_ASSERT(pepper_list_empty(&output->shm.free_buffers));
+ PEPPER_ASSERT(pepper_list_empty(&output->shm.attached_buffers));
- pepper_output_update_mode(output->base);
+ pepper_output_update_mode(output->base);
}
static void
{
}
-static const struct wl_shell_surface_listener shell_surface_listener =
-{
- shell_surface_ping,
- shell_surface_configure,
- shell_surface_popup_done,
+static const struct wl_shell_surface_listener shell_surface_listener = {
+ shell_surface_ping,
+ shell_surface_configure,
+ shell_surface_popup_done,
};
static void
wayland_output_destroy(void *o)
{
- wayland_output_t *output = o;
+ wayland_output_t *output = o;
- wl_list_remove(&output->conn_destroy_listener.link);
+ wl_list_remove(&output->conn_destroy_listener.link);
- wl_surface_destroy(output->surface);
- wl_shell_surface_destroy(output->shell_surface);
+ wl_surface_destroy(output->surface);
+ wl_shell_surface_destroy(output->shell_surface);
- free(output);
+ free(output);
}
static int32_t
wayland_output_get_subpixel_order(void *o)
{
- wayland_output_t *output = o;
- return output->subpixel;
+ wayland_output_t *output = o;
+ return output->subpixel;
}
static const char *
wayland_output_get_maker_name(void *o)
{
- return maker_name;
+ return maker_name;
}
static const char *
wayland_output_get_model_name(void *o)
{
- return model_name;
+ return model_name;
}
static int
wayland_output_get_mode_count(void *o)
{
- /* There's only one available mode in wayland backend which is also the current mode. */
- return 1;
+ /* There's only one available mode in wayland backend which is also the current mode. */
+ return 1;
}
static void
wayland_output_get_mode(void *o, int index, pepper_output_mode_t *mode)
{
- wayland_output_t *output = o;
+ wayland_output_t *output = o;
- if (index != 0)
- return;
+ if (index != 0)
+ return;
- mode->flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
- mode->w = output->w;
- mode->h = output->h;
- mode->refresh = 60000;
+ mode->flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
+ mode->w = output->w;
+ mode->h = output->h;
+ mode->refresh = 60000;
}
static pepper_bool_t
wayland_output_set_mode(void *o, const pepper_output_mode_t *mode)
{
- wayland_output_t *output = o;
+ wayland_output_t *output = o;
- if (mode->w <= 0 || mode->h <= 0)
- return PEPPER_FALSE;
+ if (mode->w <= 0 || mode->h <= 0)
+ return PEPPER_FALSE;
- if (mode->refresh != 60000)
- return PEPPER_FALSE;
+ if (mode->refresh != 60000)
+ return PEPPER_FALSE;
- if (output->w != mode->w || output->h != mode->h)
- {
- output->w = mode->w;
- output->h = mode->h;
+ if (output->w != mode->w || output->h != mode->h) {
+ output->w = mode->w;
+ output->h = mode->h;
- /* TODO: Handle resize here. */
+ /* TODO: Handle resize here. */
- pepper_output_update_mode(output->base);
- }
+ pepper_output_update_mode(output->base);
+ }
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static void
frame_done(void *data, struct wl_callback *callback, uint32_t time)
{
- wayland_output_t *output = data;
+ wayland_output_t *output = data;
- wl_callback_destroy(callback);
- pepper_output_finish_frame(output->base, NULL);
+ wl_callback_destroy(callback);
+ pepper_output_finish_frame(output->base, NULL);
}
-static const struct wl_callback_listener frame_listener =
-{
- frame_done,
+static const struct wl_callback_listener frame_listener = {
+ frame_done,
};
static void
wayland_output_assign_planes(void *o, const pepper_list_t *view_list)
{
- wayland_output_t *output = (wayland_output_t *)o;
- pepper_list_t *l;
-
- pepper_list_for_each_list(l, view_list)
- {
- pepper_view_t *view = l->item;
- pepper_view_assign_plane(view, output->base, output->primary_plane);
- }
+ wayland_output_t *output = (wayland_output_t *)o;
+ pepper_list_t *l;
+
+ pepper_list_for_each_list(l, view_list) {
+ pepper_view_t *view = l->item;
+ pepper_view_assign_plane(view, output->base, output->primary_plane);
+ }
}
static void
wayland_output_start_repaint_loop(void *o)
{
- wayland_output_t *output = o;
- struct timespec ts;
+ wayland_output_t *output = o;
+ struct timespec ts;
- pepper_compositor_get_time(output->conn->pepper, &ts);
- pepper_output_finish_frame(output->base, &ts);
+ pepper_compositor_get_time(output->conn->pepper, &ts);
+ pepper_output_finish_frame(output->base, &ts);
}
static void
wayland_output_repaint(void *o, const pepper_list_t *plane_list)
{
- wayland_output_t *output = o;
- struct wl_callback *callback;
+ wayland_output_t *output = o;
+ struct wl_callback *callback;
- pepper_list_t *l;
+ pepper_list_t *l;
- pepper_list_for_each_list(l, plane_list)
- {
- pepper_plane_t *plane = l->item;
+ pepper_list_for_each_list(l, plane_list) {
+ pepper_plane_t *plane = l->item;
- if (plane == output->primary_plane)
- {
- const pepper_list_t *render_list = pepper_plane_get_render_list(plane);
- pixman_region32_t *damage = pepper_plane_get_damage_region(plane);
+ if (plane == output->primary_plane) {
+ const pepper_list_t *render_list = pepper_plane_get_render_list(plane);
+ pixman_region32_t *damage = pepper_plane_get_damage_region(plane);
- if (output->render_pre)
- output->render_pre(output);
+ if (output->render_pre)
+ output->render_pre(output);
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, damage);
- pepper_plane_clear_damage_region(plane);
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ damage);
+ pepper_plane_clear_damage_region(plane);
- if (output->render_post)
- output->render_post(output);
+ if (output->render_post)
+ output->render_post(output);
- callback = wl_surface_frame(output->surface);
- wl_callback_add_listener(callback, &frame_listener, output);
- wl_surface_commit(output->surface);
- wl_display_flush(output->conn->display);
- }
- }
+ callback = wl_surface_frame(output->surface);
+ wl_callback_add_listener(callback, &frame_listener, output);
+ wl_surface_commit(output->surface);
+ wl_display_flush(output->conn->display);
+ }
+ }
}
static void
-wayland_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h)
+wayland_output_attach_surface(void *o, pepper_surface_t *surface, int *w,
+ int *h)
{
- pepper_renderer_attach_surface(((wayland_output_t *)o)->renderer, surface, w, h);
+ pepper_renderer_attach_surface(((wayland_output_t *)o)->renderer, surface, w,
+ h);
}
static void
-wayland_output_flush_surface_damage(void *o, pepper_surface_t *surface, pepper_bool_t *keep_buffer)
+wayland_output_flush_surface_damage(void *o, pepper_surface_t *surface,
+ pepper_bool_t *keep_buffer)
{
- wayland_output_t *output = o;
- pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
-
- pepper_renderer_flush_surface_damage(output->renderer, surface);
-
- if (output->renderer == output->conn->pixman_renderer ||
- (buffer && !wl_shm_buffer_get(pepper_buffer_get_resource(buffer))))
- {
- *keep_buffer = PEPPER_TRUE;
- }
- else
- {
- *keep_buffer = PEPPER_FALSE;
- }
+ wayland_output_t *output = o;
+ pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
+
+ pepper_renderer_flush_surface_damage(output->renderer, surface);
+
+ if (output->renderer == output->conn->pixman_renderer ||
+ (buffer && !wl_shm_buffer_get(pepper_buffer_get_resource(buffer)))) {
+ *keep_buffer = PEPPER_TRUE;
+ } else {
+ *keep_buffer = PEPPER_FALSE;
+ }
}
-static const pepper_output_backend_t wayland_output_backend =
-{
- wayland_output_destroy,
+static const pepper_output_backend_t wayland_output_backend = {
+ wayland_output_destroy,
- wayland_output_get_subpixel_order,
- wayland_output_get_maker_name,
- wayland_output_get_model_name,
+ wayland_output_get_subpixel_order,
+ wayland_output_get_maker_name,
+ wayland_output_get_model_name,
- wayland_output_get_mode_count,
- wayland_output_get_mode,
- wayland_output_set_mode,
+ wayland_output_get_mode_count,
+ wayland_output_get_mode,
+ wayland_output_set_mode,
- wayland_output_assign_planes,
- wayland_output_start_repaint_loop,
- wayland_output_repaint,
- wayland_output_attach_surface,
- wayland_output_flush_surface_damage,
+ wayland_output_assign_planes,
+ wayland_output_start_repaint_loop,
+ wayland_output_repaint,
+ wayland_output_attach_surface,
+ wayland_output_flush_surface_damage,
};
static void
pixman_render_pre(wayland_output_t *output)
{
- wayland_shm_buffer_t *buffer = NULL;
-
- if (pepper_list_empty(&output->shm.free_buffers))
- {
- buffer = wayland_shm_buffer_create(output);
- if (!buffer)
- {
- PEPPER_ERROR("Failed to create a shm buffer.\n");
- return;
- }
- }
- else
- {
- buffer = pepper_container_of(output->shm.free_buffers.next, buffer, link);
- pepper_list_remove(&buffer->link);
- }
-
- pepper_list_insert(output->shm.attached_buffers.prev, &buffer->link);
- output->shm.current_buffer = buffer;
-
- pepper_renderer_set_target(output->renderer, buffer->target);
+ wayland_shm_buffer_t *buffer = NULL;
+
+ if (pepper_list_empty(&output->shm.free_buffers)) {
+ buffer = wayland_shm_buffer_create(output);
+ if (!buffer) {
+ PEPPER_ERROR("Failed to create a shm buffer.\n");
+ return;
+ }
+ } else {
+ buffer = pepper_container_of(output->shm.free_buffers.next, buffer, link);
+ pepper_list_remove(&buffer->link);
+ }
+
+ pepper_list_insert(output->shm.attached_buffers.prev, &buffer->link);
+ output->shm.current_buffer = buffer;
+
+ pepper_renderer_set_target(output->renderer, buffer->target);
}
static void
pixman_render_post(wayland_output_t *output)
{
- wl_surface_attach(output->surface, output->shm.current_buffer->buffer, 0, 0);
- wl_surface_damage(output->surface, 0, 0, output->w, output->h);
+ wl_surface_attach(output->surface, output->shm.current_buffer->buffer, 0, 0);
+ wl_surface_damage(output->surface, 0, 0, output->w, output->h);
}
static pepper_bool_t
init_gl_renderer(wayland_output_t *output)
{
#if ENABLE_WAYLAND_BACKEND_EGL
- if (!output->connection->gl_renderer)
- return PEPPER_FALSE;
+ if (!output->connection->gl_renderer)
+ return PEPPER_FALSE;
- output->egl.window = wl_egl_window_create(output->surface, output->w, output->h);
- if (!output->egl.window)
- return PEPPER_FALSE;
+ output->egl.window = wl_egl_window_create(output->surface, output->w,
+ output->h);
+ if (!output->egl.window)
+ return PEPPER_FALSE;
- output->gl_render_target = pepper_gl_renderer_create_target(output->conn->renderer,
- output->egl.window,
- PEPPER_FORMAT_ARGB8888, NULL,
- output->w, output->h);
+ output->gl_render_target = pepper_gl_renderer_create_target(
+ output->conn->renderer,
+ output->egl.window,
+ PEPPER_FORMAT_ARGB8888, NULL,
+ output->w, output->h);
- if (!output->gl_render_target)
- {
- wl_egl_window_destroy(output->egl.window);
- return PEPPER_FALSE;
- }
+ if (!output->gl_render_target) {
+ wl_egl_window_destroy(output->egl.window);
+ return PEPPER_FALSE;
+ }
- output->render_target = output->gl_render_target;
- output->renderer = output->conn->renderer;
+ output->render_target = output->gl_render_target;
+ output->renderer = output->conn->renderer;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
#else
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
#endif
}
static pepper_bool_t
init_pixman_renderer(wayland_output_t *output)
{
- if (!output->conn->pixman_renderer)
- return PEPPER_FALSE;
+ if (!output->conn->pixman_renderer)
+ return PEPPER_FALSE;
- pepper_list_init(&output->shm.free_buffers);
- pepper_list_init(&output->shm.attached_buffers);
+ pepper_list_init(&output->shm.free_buffers);
+ pepper_list_init(&output->shm.attached_buffers);
- output->renderer = output->conn->pixman_renderer;
- output->render_pre = pixman_render_pre;
- output->render_post = pixman_render_post;
+ output->renderer = output->conn->pixman_renderer;
+ output->render_pre = pixman_render_pre;
+ output->render_post = pixman_render_post;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_bool_t
init_renderer(wayland_output_t *output, const char *name)
{
- if (strcmp(name, "gl") == 0)
- {
- return init_gl_renderer(output);
- }
+ if (strcmp(name, "gl") == 0) {
+ return init_gl_renderer(output);
+ }
- return init_pixman_renderer(output);
+ return init_pixman_renderer(output);
}
PEPPER_API pepper_output_t *
-pepper_wayland_output_create(pepper_wayland_t *conn, int32_t w, int32_t h, const char *renderer)
+pepper_wayland_output_create(pepper_wayland_t *conn, int32_t w, int32_t h,
+ const char *renderer)
{
- wayland_output_t *output;
-
- output = calloc(1, sizeof(wayland_output_t));
- if (!output)
- return NULL;
-
- output->conn = conn;
- output->w = w;
- output->h = h;
-
- /* Hard-Coded: subpixel order to horizontal RGB. */
- output->subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
-
- /* Create wayland resources. */
- output->surface = wl_compositor_create_surface(conn->compositor);
- output->shell_surface = wl_shell_get_shell_surface(conn->shell, output->surface);
- wl_shell_surface_add_listener(output->shell_surface, &shell_surface_listener, output);
- wl_shell_surface_set_toplevel(output->shell_surface);
- snprintf(&output->name[0], 32, "wayland-%p", output);
-
- /* Add compositor base class output object for this output. */
- output->base = pepper_compositor_add_output(conn->pepper, &wayland_output_backend,
- output->name, output, WL_OUTPUT_TRANSFORM_NORMAL, 1);
- if (!output->base)
- {
- wayland_output_destroy(output);
- return NULL;
- }
-
- /* Create renderer. */
- if (!init_renderer(output, renderer))
- {
- wayland_output_destroy(output);
- return NULL;
- }
-
- output->primary_plane = pepper_output_add_plane(output->base, NULL);
- pepper_list_insert(&conn->output_list, &output->link);
-
- return output->base;
+ wayland_output_t *output;
+
+ output = calloc(1, sizeof(wayland_output_t));
+ if (!output)
+ return NULL;
+
+ output->conn = conn;
+ output->w = w;
+ output->h = h;
+
+ /* Hard-Coded: subpixel order to horizontal RGB. */
+ output->subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
+
+ /* Create wayland resources. */
+ output->surface = wl_compositor_create_surface(conn->compositor);
+ output->shell_surface = wl_shell_get_shell_surface(conn->shell,
+ output->surface);
+ wl_shell_surface_add_listener(output->shell_surface, &shell_surface_listener,
+ output);
+ wl_shell_surface_set_toplevel(output->shell_surface);
+ snprintf(&output->name[0], 32, "wayland-%p", output);
+
+ /* Add compositor base class output object for this output. */
+ output->base = pepper_compositor_add_output(conn->pepper,
+ &wayland_output_backend,
+ output->name, output, WL_OUTPUT_TRANSFORM_NORMAL, 1);
+ if (!output->base) {
+ wayland_output_destroy(output);
+ return NULL;
+ }
+
+ /* Create renderer. */
+ if (!init_renderer(output, renderer)) {
+ wayland_output_destroy(output);
+ return NULL;
+ }
+
+ output->primary_plane = pepper_output_add_plane(output->base, NULL);
+ pepper_list_insert(&conn->output_list, &output->link);
+
+ return output->base;
}
static void
buffer_release(void *data, struct wl_buffer *buf)
{
- wayland_shm_buffer_t *buffer = data;
-
- if (buffer->output)
- {
- /* Move to free buffer list. */
- pepper_list_remove(&buffer->link);
- pepper_list_insert(buffer->output->shm.free_buffers.next, &buffer->link);
- }
- else
- {
- /* Orphaned buffer due to output resize or something. Destroy it. */
- wayland_shm_buffer_destroy(buffer);
- }
+ wayland_shm_buffer_t *buffer = data;
+
+ if (buffer->output) {
+ /* Move to free buffer list. */
+ pepper_list_remove(&buffer->link);
+ pepper_list_insert(buffer->output->shm.free_buffers.next, &buffer->link);
+ } else {
+ /* Orphaned buffer due to output resize or something. Destroy it. */
+ wayland_shm_buffer_destroy(buffer);
+ }
}
-static const struct wl_buffer_listener buffer_listener =
-{
- buffer_release,
+static const struct wl_buffer_listener buffer_listener = {
+ buffer_release,
};
wayland_shm_buffer_t *
wayland_shm_buffer_create(wayland_output_t *output)
{
- wayland_shm_buffer_t *buffer;
- int fd;
- struct wl_shm_pool *pool;
-
- buffer = calloc(1, sizeof(wayland_shm_buffer_t));
- if (!buffer)
- return NULL;
-
- buffer->output = output;
- pepper_list_init(&buffer->link);
-
- buffer->w = output->w;
- buffer->h = output->h;
- buffer->stride = buffer->w * 4;
- buffer->size = buffer->stride * buffer->h;
-
- fd = pepper_create_anonymous_file(buffer->size);
-
- if (fd < 0)
- {
- PEPPER_ERROR("Failed to create anonymous file");
- goto error;
- }
-
- buffer->pixels = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- if (!buffer->pixels)
- {
- PEPPER_ERROR("mmap() failed for fd=%d\n", fd);
- goto error;
- }
-
- pool = wl_shm_create_pool(output->conn->shm, fd, buffer->size);
- buffer->buffer = wl_shm_pool_create_buffer(pool, 0, buffer->w, buffer->h,
- buffer->stride, WL_SHM_FORMAT_ARGB8888);
- wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);
- wl_shm_pool_destroy(pool);
- close(fd);
-
- buffer->target = pepper_pixman_renderer_create_target(PEPPER_FORMAT_ARGB8888,
- buffer->pixels, buffer->stride,
- buffer->w, buffer->h);
-
- if (!buffer->target)
- goto error;
-
- pixman_region32_init_rect(&buffer->damage, 0, 0, buffer->w, buffer->h);
- return buffer;
+ wayland_shm_buffer_t *buffer;
+ int fd;
+ struct wl_shm_pool *pool;
+
+ buffer = calloc(1, sizeof(wayland_shm_buffer_t));
+ if (!buffer)
+ return NULL;
+
+ buffer->output = output;
+ pepper_list_init(&buffer->link);
+
+ buffer->w = output->w;
+ buffer->h = output->h;
+ buffer->stride = buffer->w * 4;
+ buffer->size = buffer->stride * buffer->h;
+
+ fd = pepper_create_anonymous_file(buffer->size);
+
+ if (fd < 0) {
+ PEPPER_ERROR("Failed to create anonymous file");
+ goto error;
+ }
+
+ buffer->pixels = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED,
+ fd, 0);
+ if (!buffer->pixels) {
+ PEPPER_ERROR("mmap() failed for fd=%d\n", fd);
+ goto error;
+ }
+
+ pool = wl_shm_create_pool(output->conn->shm, fd, buffer->size);
+ buffer->buffer = wl_shm_pool_create_buffer(pool, 0, buffer->w, buffer->h,
+ buffer->stride, WL_SHM_FORMAT_ARGB8888);
+ wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);
+ wl_shm_pool_destroy(pool);
+ close(fd);
+
+ buffer->target = pepper_pixman_renderer_create_target(PEPPER_FORMAT_ARGB8888,
+ buffer->pixels, buffer->stride,
+ buffer->w, buffer->h);
+
+ if (!buffer->target)
+ goto error;
+
+ pixman_region32_init_rect(&buffer->damage, 0, 0, buffer->w, buffer->h);
+ return buffer;
error:
- if (fd >= 0)
- close(fd);
+ if (fd >= 0)
+ close(fd);
- if (buffer)
- free(buffer);
+ if (buffer)
+ free(buffer);
- if (buffer->target)
- pepper_render_target_destroy(buffer->target);
+ if (buffer->target)
+ pepper_render_target_destroy(buffer->target);
- return NULL;
+ return NULL;
}
void
wayland_shm_buffer_destroy(wayland_shm_buffer_t *buffer)
{
- pepper_render_target_destroy(buffer->target);
- pixman_region32_fini(&buffer->damage);
- wl_buffer_destroy(buffer->buffer);
- munmap(buffer->pixels, buffer->size);
- pepper_list_remove(&buffer->link);
+ pepper_render_target_destroy(buffer->target);
+ pixman_region32_fini(&buffer->damage);
+ wl_buffer_destroy(buffer->buffer);
+ munmap(buffer->pixels, buffer->size);
+ pepper_list_remove(&buffer->link);
}
PEPPER_API pepper_output_t *
pepper_x11_output_create(pepper_x11_connection_t *connection,
- int x, int y, int w, int h, int transform, int scale,
- const char *renderer);
+ int x, int y, int w, int h, int transform, int scale,
+ const char *renderer);
PEPPER_API pepper_bool_t
-pepper_x11_input_create(pepper_x11_connection_t* conn);
+pepper_x11_input_create(pepper_x11_connection_t *conn);
#ifdef __cplusplus
}
*/
static inline pepper_bool_t
-x11_get_next_event(xcb_connection_t *xcb_conn, xcb_generic_event_t **event, uint32_t mask)
+x11_get_next_event(xcb_connection_t *xcb_conn, xcb_generic_event_t **event,
+ uint32_t mask)
{
- *event = xcb_poll_for_event(xcb_conn);
- return *event != NULL;
+ *event = xcb_poll_for_event(xcb_conn);
+ return *event != NULL;
}
static x11_output_t *
x11_find_output_by_window(pepper_x11_connection_t *conn, xcb_window_t window)
{
- x11_output_t *output;
+ x11_output_t *output;
- pepper_list_for_each(output, &conn->output_list, link)
- {
- if ( window == output->window )
- return output;
- }
+ pepper_list_for_each(output, &conn->output_list, link) {
+ if ( window == output->window )
+ return output;
+ }
- return NULL;
+ return NULL;
}
static int
x11_handle_event(int fd, uint32_t mask, void *data)
{
- pepper_x11_connection_t *connection = data;
- x11_seat_t *seat;
- xcb_generic_event_t *event = NULL;
-
- uint32_t count = 0;
-
- /* TODO: At now, x11-backend has only 1 seat per connection, "seat0"
- * but if not, we need to find matched seat at here
- */
- seat = connection->seat;
-
- while(x11_get_next_event(connection->xcb_connection, &event, mask))
- {
- uint32_t type = event->response_type & ~0x80;
-
- switch (type)
- {
- case XCB_ENTER_NOTIFY:
- case XCB_LEAVE_NOTIFY:
- case XCB_KEY_PRESS:
- case XCB_KEY_RELEASE:
- case XCB_BUTTON_PRESS:
- case XCB_BUTTON_RELEASE:
- case XCB_MOTION_NOTIFY:
- if (connection->use_xinput)
- x11_handle_input_event(seat, type, event);
- break;
- case XCB_EXPOSE:
- PEPPER_TRACE("XCB_EXPOSE\n");
- {
- xcb_expose_event_t *expose = (xcb_expose_event_t *)event;
- x11_output_t *output = x11_find_output_by_window(connection, expose->window);
-
- if (output)
- {
- /* TODO: Damage only newly exposed area. */
- pepper_output_add_damage_region(output->base, NULL);
- }
- }
- break;
- case XCB_FOCUS_IN:
- /* TODO: Cursor handling */
- PEPPER_TRACE("XCB_FOCUS_IN\n");
- break;
- case XCB_FOCUS_OUT:
- PEPPER_TRACE("XCB_FOCUS_OUT\n");
- break;
- case XCB_KEYMAP_NOTIFY:
- PEPPER_TRACE("XCB_KEYMAP_NOTIFY\n");
- {
- /* TODO: ignore at this time. */
- }
- break;
- case XCB_CONFIGURE_NOTIFY:
- /* Window moved */
- PEPPER_TRACE("XCB_CONFIGURE_NOTIFY\n");
- break;
- case XCB_QUERY_EXTENSION:
- PEPPER_TRACE("XCB_QUERY_EXTENSION\n");
- break;
- case XCB_DESTROY_NOTIFY:
- PEPPER_TRACE("XCB_DESTROY_NOTIFY\n");
- break;
- case XCB_UNMAP_NOTIFY:
- PEPPER_TRACE("XCB_UNMAP_NOTIFY\n");
- break;
- case XCB_CLIENT_MESSAGE:
- PEPPER_TRACE("XCB_CLIENT_MESSAGE\n");
- {
- xcb_client_message_event_t *msg;
- xcb_atom_t atom;
- xcb_window_t window;
- x11_output_t *output = NULL;
-
- msg = (xcb_client_message_event_t *)event;
- atom = msg->data.data32[0];
- window = msg->window;
-
- if (atom == connection->atom.wm_delete_window)
- {
- output = x11_find_output_by_window(connection, window);
- if (output)
- x11_output_destroy(output);
- }
- }
- break;
- default :
- PEPPER_ERROR("unknown event: type [0x%x] \n", type);
- break;
- }
-
- free(event);
- count++;
- }
-
- return count;
+ pepper_x11_connection_t *connection = data;
+ x11_seat_t *seat;
+ xcb_generic_event_t *event = NULL;
+
+ uint32_t count = 0;
+
+ /* TODO: At now, x11-backend has only 1 seat per connection, "seat0"
+ * but if not, we need to find matched seat at here
+ */
+ seat = connection->seat;
+
+ while (x11_get_next_event(connection->xcb_connection, &event, mask)) {
+ uint32_t type = event->response_type & ~0x80;
+
+ switch (type) {
+ case XCB_ENTER_NOTIFY:
+ case XCB_LEAVE_NOTIFY:
+ case XCB_KEY_PRESS:
+ case XCB_KEY_RELEASE:
+ case XCB_BUTTON_PRESS:
+ case XCB_BUTTON_RELEASE:
+ case XCB_MOTION_NOTIFY:
+ if (connection->use_xinput)
+ x11_handle_input_event(seat, type, event);
+ break;
+ case XCB_EXPOSE:
+ PEPPER_TRACE("XCB_EXPOSE\n");
+ {
+ xcb_expose_event_t *expose = (xcb_expose_event_t *)event;
+ x11_output_t *output = x11_find_output_by_window(connection, expose->window);
+
+ if (output) {
+ /* TODO: Damage only newly exposed area. */
+ pepper_output_add_damage_region(output->base, NULL);
+ }
+ }
+ break;
+ case XCB_FOCUS_IN:
+ /* TODO: Cursor handling */
+ PEPPER_TRACE("XCB_FOCUS_IN\n");
+ break;
+ case XCB_FOCUS_OUT:
+ PEPPER_TRACE("XCB_FOCUS_OUT\n");
+ break;
+ case XCB_KEYMAP_NOTIFY:
+ PEPPER_TRACE("XCB_KEYMAP_NOTIFY\n");
+ {
+ /* TODO: ignore at this time. */
+ }
+ break;
+ case XCB_CONFIGURE_NOTIFY:
+ /* Window moved */
+ PEPPER_TRACE("XCB_CONFIGURE_NOTIFY\n");
+ break;
+ case XCB_QUERY_EXTENSION:
+ PEPPER_TRACE("XCB_QUERY_EXTENSION\n");
+ break;
+ case XCB_DESTROY_NOTIFY:
+ PEPPER_TRACE("XCB_DESTROY_NOTIFY\n");
+ break;
+ case XCB_UNMAP_NOTIFY:
+ PEPPER_TRACE("XCB_UNMAP_NOTIFY\n");
+ break;
+ case XCB_CLIENT_MESSAGE:
+ PEPPER_TRACE("XCB_CLIENT_MESSAGE\n");
+ {
+ xcb_client_message_event_t *msg;
+ xcb_atom_t atom;
+ xcb_window_t window;
+ x11_output_t *output = NULL;
+
+ msg = (xcb_client_message_event_t *)event;
+ atom = msg->data.data32[0];
+ window = msg->window;
+
+ if (atom == connection->atom.wm_delete_window) {
+ output = x11_find_output_by_window(connection, window);
+ if (output)
+ x11_output_destroy(output);
+ }
+ }
+ break;
+ default :
+ PEPPER_ERROR("unknown event: type [0x%x] \n", type);
+ break;
+ }
+
+ free(event);
+ count++;
+ }
+
+ return count;
}
#define F(field) offsetof(pepper_x11_connection_t, field)
static void
x11_init_atoms(pepper_x11_connection_t *conn)
{
- static const struct
- {
- const char *name;
- int offset;
- } atoms[] =
- {
- { "WM_PROTOCOLS", F(atom.wm_protocols) },
- { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
- { "WM_SIZE_HINTS", F(atom.wm_size_hints) },
- { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
- { "WM_CLASS", F(atom.wm_class) },
- { "_NET_WM_NAME", F(atom.net_wm_name) },
- { "_NET_WM_ICON", F(atom.net_wm_icon) },
- { "_NET_WM_STATE", F(atom.net_wm_state) },
- { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
- { "_NET_SUPPORTING_WM_CHECK", F(atom.net_supporting_wm_check) },
- { "_NET_SUPPORTED", F(atom.net_supported) },
- { "STRING", F(atom.string) },
- { "UTF8_STRING", F(atom.utf8_string) },
- { "CARDINAL", F(atom.cardinal) },
- };
-
- xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
- xcb_intern_atom_reply_t *reply;
-
- unsigned int i;
-
- for (i = 0; i < ARRAY_LENGTH(atoms); i++)
- {
- cookies[i] = xcb_intern_atom(conn->xcb_connection, 0,
- strlen(atoms[i].name),
- atoms[i].name);
- }
-
- for (i = 0; i < ARRAY_LENGTH(atoms); i++)
- {
- reply = xcb_intern_atom_reply(conn->xcb_connection, cookies[i], NULL);
- *(xcb_atom_t *) ((char *)conn + atoms[i].offset) = reply->atom;
- free(reply);
- }
+ static const struct {
+ const char *name;
+ int offset;
+ } atoms[] = {
+ { "WM_PROTOCOLS", F(atom.wm_protocols) },
+ { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
+ { "WM_SIZE_HINTS", F(atom.wm_size_hints) },
+ { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
+ { "WM_CLASS", F(atom.wm_class) },
+ { "_NET_WM_NAME", F(atom.net_wm_name) },
+ { "_NET_WM_ICON", F(atom.net_wm_icon) },
+ { "_NET_WM_STATE", F(atom.net_wm_state) },
+ { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
+ { "_NET_SUPPORTING_WM_CHECK", F(atom.net_supporting_wm_check) },
+ { "_NET_SUPPORTED", F(atom.net_supported) },
+ { "STRING", F(atom.string) },
+ { "UTF8_STRING", F(atom.utf8_string) },
+ { "CARDINAL", F(atom.cardinal) },
+ };
+
+ xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
+ xcb_intern_atom_reply_t *reply;
+
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
+ cookies[i] = xcb_intern_atom(conn->xcb_connection, 0,
+ strlen(atoms[i].name),
+ atoms[i].name);
+ }
+
+ for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
+ reply = xcb_intern_atom_reply(conn->xcb_connection, cookies[i], NULL);
+ *(xcb_atom_t *) ((char *)conn + atoms[i].offset) = reply->atom;
+ free(reply);
+ }
}
PEPPER_API pepper_x11_connection_t *
pepper_x11_connect(pepper_compositor_t *compositor, const char *display_name)
{
- pepper_x11_connection_t *connection = NULL;
- struct wl_display *wdisplay;
- struct wl_event_loop *loop;
- xcb_screen_iterator_t scr_iter;
-
- if (!compositor)
- {
- PEPPER_ERROR("Compositor is null\n");
- return NULL;
- }
-
- connection = (pepper_x11_connection_t *)calloc(1, sizeof(pepper_x11_connection_t));
- if (!connection)
- {
- PEPPER_ERROR("Memory allocation failed\n");
- return NULL;
- }
-
- connection->display = XOpenDisplay(display_name);
- if (!connection->display)
- {
- PEPPER_ERROR("XOpenDisplay failed\n");
- free(connection);
- return NULL;
- }
-
- connection->xcb_connection = XGetXCBConnection(connection->display);
- XSetEventQueueOwner(connection->display, XCBOwnsEventQueue);
-
- if (xcb_connection_has_error(connection->xcb_connection))
- {
- PEPPER_ERROR("xcb connection has error\n");
- free(connection);
- return NULL;
- }
- connection->compositor = compositor;
-
- connection->gl_renderer = pepper_gl_renderer_create(connection->compositor,
- connection->display, "x11");
-
- connection->pixman_renderer = pepper_pixman_renderer_create(connection->compositor);
- if (!connection->pixman_renderer)
- {
- PEPPER_ERROR("Failed to create pixman renderer.\n");
- free(connection);
- return NULL;
- }
-
- scr_iter = xcb_setup_roots_iterator(xcb_get_setup(connection->xcb_connection));
- connection->screen = scr_iter.data;
-
- connection->fd = xcb_get_file_descriptor(connection->xcb_connection);
- if (display_name)
- connection->display_name = strdup(display_name);
- else
- connection->display_name = NULL;
-
- x11_init_atoms(connection);
-
- wdisplay = pepper_compositor_get_display(compositor);
- loop = wl_display_get_event_loop(wdisplay);
-
- connection->xcb_event_source = wl_event_loop_add_fd(loop,
- connection->fd,
- WL_EVENT_READABLE,
- x11_handle_event,
- connection);
-
- wl_event_source_check(connection->xcb_event_source);
- pepper_list_init(&connection->output_list);
-
- return connection;
+ pepper_x11_connection_t *connection = NULL;
+ struct wl_display *wdisplay;
+ struct wl_event_loop *loop;
+ xcb_screen_iterator_t scr_iter;
+
+ if (!compositor) {
+ PEPPER_ERROR("Compositor is null\n");
+ return NULL;
+ }
+
+ connection = (pepper_x11_connection_t *)calloc(1,
+ sizeof(pepper_x11_connection_t));
+ if (!connection) {
+ PEPPER_ERROR("Memory allocation failed\n");
+ return NULL;
+ }
+
+ connection->display = XOpenDisplay(display_name);
+ if (!connection->display) {
+ PEPPER_ERROR("XOpenDisplay failed\n");
+ free(connection);
+ return NULL;
+ }
+
+ connection->xcb_connection = XGetXCBConnection(connection->display);
+ XSetEventQueueOwner(connection->display, XCBOwnsEventQueue);
+
+ if (xcb_connection_has_error(connection->xcb_connection)) {
+ PEPPER_ERROR("xcb connection has error\n");
+ free(connection);
+ return NULL;
+ }
+ connection->compositor = compositor;
+
+ connection->gl_renderer = pepper_gl_renderer_create(connection->compositor,
+ connection->display, "x11");
+
+ connection->pixman_renderer = pepper_pixman_renderer_create(
+ connection->compositor);
+ if (!connection->pixman_renderer) {
+ PEPPER_ERROR("Failed to create pixman renderer.\n");
+ free(connection);
+ return NULL;
+ }
+
+ scr_iter = xcb_setup_roots_iterator(xcb_get_setup(connection->xcb_connection));
+ connection->screen = scr_iter.data;
+
+ connection->fd = xcb_get_file_descriptor(connection->xcb_connection);
+ if (display_name)
+ connection->display_name = strdup(display_name);
+ else
+ connection->display_name = NULL;
+
+ x11_init_atoms(connection);
+
+ wdisplay = pepper_compositor_get_display(compositor);
+ loop = wl_display_get_event_loop(wdisplay);
+
+ connection->xcb_event_source = wl_event_loop_add_fd(loop,
+ connection->fd,
+ WL_EVENT_READABLE,
+ x11_handle_event,
+ connection);
+
+ wl_event_source_check(connection->xcb_event_source);
+ pepper_list_init(&connection->output_list);
+
+ return connection;
}
PEPPER_API void
pepper_x11_destroy(pepper_x11_connection_t *conn)
{
- x11_output_t *output, *tmp;
+ x11_output_t *output, *tmp;
- x11_seat_destroy(conn->seat);
+ x11_seat_destroy(conn->seat);
- pepper_list_for_each_safe(output, tmp, &conn->output_list, link)
- x11_output_destroy(output);
+ pepper_list_for_each_safe(output, tmp, &conn->output_list, link)
+ x11_output_destroy(output);
- if (conn->xcb_event_source)
- wl_event_source_remove(conn->xcb_event_source);
+ if (conn->xcb_event_source)
+ wl_event_source_remove(conn->xcb_event_source);
- if (conn->pixman_renderer)
- pepper_renderer_destroy(conn->pixman_renderer);
+ if (conn->pixman_renderer)
+ pepper_renderer_destroy(conn->pixman_renderer);
- if (conn->gl_renderer)
- pepper_renderer_destroy(conn->gl_renderer);
+ if (conn->gl_renderer)
+ pepper_renderer_destroy(conn->gl_renderer);
- XCloseDisplay(conn->display);
- free(conn);
+ XCloseDisplay(conn->display);
+ free(conn);
}
static void *
x11_output_cursor_set(void *o, void *c)
{
- x11_output_t *output = o;
- x11_cursor_t *cursor = c;
- x11_cursor_t *current_cursor;
- pepper_x11_connection_t *conn;
-
- if (!output)
- {
- PEPPER_ERROR("x11:output:cursor:%s output is null\n", __FUNCTION__);
- return NULL;
- }
-
- if (!cursor)
- {
- PEPPER_ERROR("x11:output:cursor:%s cursor is null\n", __FUNCTION__);
- return NULL;
- }
-
- conn = output->connection;
-
- current_cursor = output->cursor;
- output->cursor = cursor;
-
- /* set cursor for window*/
- {
- uint32_t mask = XCB_CW_CURSOR;
- uint32_t value_list = cursor->xcb_cursor;
- xcb_change_window_attributes(conn->xcb_connection,
- output->window,
- mask,
- &value_list);
- }
-
- return current_cursor;
+ x11_output_t *output = o;
+ x11_cursor_t *cursor = c;
+ x11_cursor_t *current_cursor;
+ pepper_x11_connection_t *conn;
+
+ if (!output) {
+ PEPPER_ERROR("x11:output:cursor:%s output is null\n", __FUNCTION__);
+ return NULL;
+ }
+
+ if (!cursor) {
+ PEPPER_ERROR("x11:output:cursor:%s cursor is null\n", __FUNCTION__);
+ return NULL;
+ }
+
+ conn = output->connection;
+
+ current_cursor = output->cursor;
+ output->cursor = cursor;
+
+ /* set cursor for window*/
+ {
+ uint32_t mask = XCB_CW_CURSOR;
+ uint32_t value_list = cursor->xcb_cursor;
+ xcb_change_window_attributes(conn->xcb_connection,
+ output->window,
+ mask,
+ &value_list);
+ }
+
+ return current_cursor;
}
static void *
x11_output_cursor_create(void *output, int32_t w, int32_t h, void *image)
{
- xcb_pixmap_t pixmap;
- xcb_gc_t gc;
- pepper_x11_connection_t *conn;
- x11_cursor_t *cursor;
-
- if (!output)
- {
- PEPPER_ERROR("x11:output:cursor:%s: output is null\n", __FUNCTION__);
- return NULL;
- }
- if (!image)
- {
- PEPPER_ERROR("x11:output:cursor:%s: image is null\n", __FUNCTION__);
- return NULL;
- }
- if (w<0 || h<0)
- {
- PEPPER_ERROR("x11:output:cursor:%s: width(%d) or height(%d) is invalid\n",
- __FUNCTION__, w, h);
- return NULL;
- }
-
- cursor = calloc(1, sizeof(x11_cursor_t));
- if (!cursor)
- {
- PEPPER_ERROR("x11:cursor: memory allocation failed");
- return NULL;
- }
- cursor->data = image;
- cursor->w = w;
- cursor->h = h;
-
- conn = ((x11_output_t *)output)->connection;
-
- pixmap = xcb_generate_id(conn->xcb_connection);
- gc = xcb_generate_id(conn->xcb_connection);
-
- xcb_create_pixmap(conn->xcb_connection, 1/*depth?*/,
- pixmap, conn->screen->root, w, h);
- xcb_create_gc(conn->xcb_connection, gc, pixmap, 0, NULL);
- xcb_put_image(conn->xcb_connection, XCB_IMAGE_FORMAT_XY_PIXMAP, pixmap,
- gc, w, h, 0, 0, 0, 32, w*h*sizeof(uint8_t), cursor->data);
- cursor->xcb_cursor = xcb_generate_id(conn->xcb_connection);
- /*
- * cb_void_cookie_t xcb_create_cursor(xcb_connection_t *conn,
- * xcb_cursor_t cid,
- * xcb_pixmap_t source,
- * xcb_pixmap_t mask,
- * uint16_t fore_red, TODO: NOT YET DOCUMENTED.
- * uint16_t fore_green,
- * uint16_t fore_blue,
- * uint16_t back_red,
- * uint16_t back_green,
- * uint16_t back_blue,
- * uint16_t x,
- * uint16_t y);
- */
- xcb_create_cursor(conn->xcb_connection, cursor->xcb_cursor,
- pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1);
-
- xcb_free_gc(conn->xcb_connection, gc);
- xcb_free_pixmap(conn->xcb_connection, pixmap);
-
- return (void *)cursor;
+ xcb_pixmap_t pixmap;
+ xcb_gc_t gc;
+ pepper_x11_connection_t *conn;
+ x11_cursor_t *cursor;
+
+ if (!output) {
+ PEPPER_ERROR("x11:output:cursor:%s: output is null\n", __FUNCTION__);
+ return NULL;
+ }
+ if (!image) {
+ PEPPER_ERROR("x11:output:cursor:%s: image is null\n", __FUNCTION__);
+ return NULL;
+ }
+ if (w < 0 || h < 0) {
+ PEPPER_ERROR("x11:output:cursor:%s: width(%d) or height(%d) is invalid\n",
+ __FUNCTION__, w, h);
+ return NULL;
+ }
+
+ cursor = calloc(1, sizeof(x11_cursor_t));
+ if (!cursor) {
+ PEPPER_ERROR("x11:cursor: memory allocation failed");
+ return NULL;
+ }
+ cursor->data = image;
+ cursor->w = w;
+ cursor->h = h;
+
+ conn = ((x11_output_t *)output)->connection;
+
+ pixmap = xcb_generate_id(conn->xcb_connection);
+ gc = xcb_generate_id(conn->xcb_connection);
+
+ xcb_create_pixmap(conn->xcb_connection, 1/*depth?*/,
+ pixmap, conn->screen->root, w, h);
+ xcb_create_gc(conn->xcb_connection, gc, pixmap, 0, NULL);
+ xcb_put_image(conn->xcb_connection, XCB_IMAGE_FORMAT_XY_PIXMAP, pixmap,
+ gc, w, h, 0, 0, 0, 32, w * h * sizeof(uint8_t), cursor->data);
+ cursor->xcb_cursor = xcb_generate_id(conn->xcb_connection);
+ /*
+ * cb_void_cookie_t xcb_create_cursor(xcb_connection_t *conn,
+ * xcb_cursor_t cid,
+ * xcb_pixmap_t source,
+ * xcb_pixmap_t mask,
+ * uint16_t fore_red, TODO: NOT YET DOCUMENTED.
+ * uint16_t fore_green,
+ * uint16_t fore_blue,
+ * uint16_t back_red,
+ * uint16_t back_green,
+ * uint16_t back_blue,
+ * uint16_t x,
+ * uint16_t y);
+ */
+ xcb_create_cursor(conn->xcb_connection, cursor->xcb_cursor,
+ pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1);
+
+ xcb_free_gc(conn->xcb_connection, gc);
+ xcb_free_pixmap(conn->xcb_connection, pixmap);
+
+ return (void *)cursor;
}
static void
x11_output_cursor_destroy(void *o, void *c)
{
- xcb_connection_t *conn;
- x11_cursor_t *cursor;
-
- if (!o)
- {
- PEPPER_ERROR("x11:output:cursor:%s: output is null\n", __FUNCTION__);
- return ;
- }
- if (!c)
- {
- PEPPER_ERROR("x11:output:cursor:%s: cursor is null\n", __FUNCTION__);
- return ;
- }
-
- conn = ((x11_output_t *)o)->connection->xcb_connection;
- cursor = (x11_cursor_t *)c;
-
- xcb_free_cursor(conn, cursor->xcb_cursor);
- free(cursor);
+ xcb_connection_t *conn;
+ x11_cursor_t *cursor;
+
+ if (!o) {
+ PEPPER_ERROR("x11:output:cursor:%s: output is null\n", __FUNCTION__);
+ return ;
+ }
+ if (!c) {
+ PEPPER_ERROR("x11:output:cursor:%s: cursor is null\n", __FUNCTION__);
+ return ;
+ }
+
+ conn = ((x11_output_t *)o)->connection->xcb_connection;
+ cursor = (x11_cursor_t *)c;
+
+ xcb_free_cursor(conn, cursor->xcb_cursor);
+ free(cursor);
}
static inline uint32_t
get_standard_button(uint32_t xcb_button)
{
- switch (xcb_button)
- {
- case XCB_BUTTON_INDEX_1:
- return BTN_LEFT;
- case XCB_BUTTON_INDEX_2:
- return BTN_MIDDLE;
- case XCB_BUTTON_INDEX_3:
- return BTN_RIGHT;
- case XCB_BUTTON_INDEX_4:
- case XCB_BUTTON_INDEX_5:
- break;
- }
-
- return 0;
+ switch (xcb_button) {
+ case XCB_BUTTON_INDEX_1:
+ return BTN_LEFT;
+ case XCB_BUTTON_INDEX_2:
+ return BTN_MIDDLE;
+ case XCB_BUTTON_INDEX_3:
+ return BTN_RIGHT;
+ case XCB_BUTTON_INDEX_4:
+ case XCB_BUTTON_INDEX_5:
+ break;
+ }
+
+ return 0;
}
void
-x11_handle_input_event(x11_seat_t* seat, uint32_t type, xcb_generic_event_t* xev)
+x11_handle_input_event(x11_seat_t *seat, uint32_t type,
+ xcb_generic_event_t *xev)
{
- pepper_input_event_t event;
-
- switch (type)
- {
- case XCB_ENTER_NOTIFY:
- {
- PEPPER_TRACE("enter\n");
- }
- break;
- case XCB_LEAVE_NOTIFY:
- {
- PEPPER_TRACE("leave\n");
- }
- break;
- case XCB_KEY_PRESS:
- {
- xcb_key_press_event_t *kp = (xcb_key_press_event_t *)xev;
-
- event.time = kp->time;
- event.key = kp->detail - 8;
- event.state = PEPPER_KEY_STATE_PRESSED;
-
- pepper_object_emit_event((pepper_object_t *)seat->keyboard,
- PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY, &event);
- }
- break;
- case XCB_KEY_RELEASE:
- {
- xcb_key_release_event_t *kr = (xcb_key_release_event_t *)xev;
-
- event.time = kr->time;
- event.key = kr->detail - 8;
- event.state = PEPPER_KEY_STATE_RELEASED;
-
- pepper_object_emit_event((pepper_object_t *)seat->keyboard,
- PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY, &event);
- }
- break;
- case XCB_BUTTON_PRESS:
- {
- xcb_button_press_event_t *bp = (xcb_button_press_event_t *)xev;
-
- event.time = bp->time;
- event.state = PEPPER_BUTTON_STATE_PRESSED;
- event.button = get_standard_button(bp->detail);
-
- pepper_object_emit_event((pepper_object_t *)seat->pointer,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON, &event);
- }
- break;
- case XCB_BUTTON_RELEASE:
- {
- xcb_button_release_event_t *br = (xcb_button_release_event_t *)xev;
-
- event.time = br->time;
- event.state = PEPPER_BUTTON_STATE_RELEASED;
- event.button = get_standard_button(br->detail);
-
- pepper_object_emit_event((pepper_object_t *)seat->pointer,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON, &event);
- }
- break;
- case XCB_MOTION_NOTIFY:
- {
- xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev;
-
- event.time = motion->time;
- event.x = motion->event_x;
- event.y = motion->event_y;
-
- pepper_object_emit_event((pepper_object_t *)seat->pointer,
- PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE, &event);
- }
- break;
- default :
- PEPPER_ERROR("unknown input event, [0x%x]\n", type);
- break;
- }
+ pepper_input_event_t event;
+
+ switch (type) {
+ case XCB_ENTER_NOTIFY: {
+ PEPPER_TRACE("enter\n");
+ }
+ break;
+ case XCB_LEAVE_NOTIFY: {
+ PEPPER_TRACE("leave\n");
+ }
+ break;
+ case XCB_KEY_PRESS: {
+ xcb_key_press_event_t *kp = (xcb_key_press_event_t *)xev;
+
+ event.time = kp->time;
+ event.key = kp->detail - 8;
+ event.state = PEPPER_KEY_STATE_PRESSED;
+
+ pepper_object_emit_event((pepper_object_t *)seat->keyboard,
+ PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY, &event);
+ }
+ break;
+ case XCB_KEY_RELEASE: {
+ xcb_key_release_event_t *kr = (xcb_key_release_event_t *)xev;
+
+ event.time = kr->time;
+ event.key = kr->detail - 8;
+ event.state = PEPPER_KEY_STATE_RELEASED;
+
+ pepper_object_emit_event((pepper_object_t *)seat->keyboard,
+ PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY, &event);
+ }
+ break;
+ case XCB_BUTTON_PRESS: {
+ xcb_button_press_event_t *bp = (xcb_button_press_event_t *)xev;
+
+ event.time = bp->time;
+ event.state = PEPPER_BUTTON_STATE_PRESSED;
+ event.button = get_standard_button(bp->detail);
+
+ pepper_object_emit_event((pepper_object_t *)seat->pointer,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON, &event);
+ }
+ break;
+ case XCB_BUTTON_RELEASE: {
+ xcb_button_release_event_t *br = (xcb_button_release_event_t *)xev;
+
+ event.time = br->time;
+ event.state = PEPPER_BUTTON_STATE_RELEASED;
+ event.button = get_standard_button(br->detail);
+
+ pepper_object_emit_event((pepper_object_t *)seat->pointer,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_BUTTON, &event);
+ }
+ break;
+ case XCB_MOTION_NOTIFY: {
+ xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev;
+
+ event.time = motion->time;
+ event.x = motion->event_x;
+ event.y = motion->event_y;
+
+ pepper_object_emit_event((pepper_object_t *)seat->pointer,
+ PEPPER_EVENT_INPUT_DEVICE_POINTER_MOTION_ABSOLUTE, &event);
+ }
+ break;
+ default :
+ PEPPER_ERROR("unknown input event, [0x%x]\n", type);
+ break;
+ }
}
void
x11_window_input_property_change(xcb_connection_t *conn, xcb_window_t window)
{
- static const uint32_t values[] =
- {
- XCB_EVENT_MASK_EXPOSURE |
- XCB_EVENT_MASK_STRUCTURE_NOTIFY |
- XCB_EVENT_MASK_KEY_PRESS |
- XCB_EVENT_MASK_KEY_RELEASE |
- XCB_EVENT_MASK_BUTTON_PRESS |
- XCB_EVENT_MASK_BUTTON_RELEASE |
- XCB_EVENT_MASK_POINTER_MOTION |
- XCB_EVENT_MASK_ENTER_WINDOW |
- XCB_EVENT_MASK_LEAVE_WINDOW |
- XCB_EVENT_MASK_KEYMAP_STATE |
- XCB_EVENT_MASK_FOCUS_CHANGE
- };
- xcb_change_window_attributes(conn, window, XCB_CW_EVENT_MASK, values);
- xcb_flush(conn);
+ static const uint32_t values[] = {
+ XCB_EVENT_MASK_EXPOSURE |
+ XCB_EVENT_MASK_STRUCTURE_NOTIFY |
+ XCB_EVENT_MASK_KEY_PRESS |
+ XCB_EVENT_MASK_KEY_RELEASE |
+ XCB_EVENT_MASK_BUTTON_PRESS |
+ XCB_EVENT_MASK_BUTTON_RELEASE |
+ XCB_EVENT_MASK_POINTER_MOTION |
+ XCB_EVENT_MASK_ENTER_WINDOW |
+ XCB_EVENT_MASK_LEAVE_WINDOW |
+ XCB_EVENT_MASK_KEYMAP_STATE |
+ XCB_EVENT_MASK_FOCUS_CHANGE
+ };
+ xcb_change_window_attributes(conn, window, XCB_CW_EVENT_MASK, values);
+ xcb_flush(conn);
}
void
x11_seat_destroy(void *data)
{
- x11_seat_t *seat = (x11_seat_t *)data;
+ x11_seat_t *seat = (x11_seat_t *)data;
- if (seat->pointer)
- pepper_input_device_destroy(seat->pointer);
+ if (seat->pointer)
+ pepper_input_device_destroy(seat->pointer);
- if (seat->keyboard)
- pepper_input_device_destroy(seat->keyboard);
+ if (seat->keyboard)
+ pepper_input_device_destroy(seat->keyboard);
- if (seat->conn)
- seat->conn->seat = NULL;
+ if (seat->conn)
+ seat->conn->seat = NULL;
- free(seat);
+ free(seat);
}
PEPPER_API pepper_bool_t
-pepper_x11_input_create(pepper_x11_connection_t* conn)
+pepper_x11_input_create(pepper_x11_connection_t *conn)
{
- x11_seat_t *seat;
- x11_output_t *out, *tmp;
+ x11_seat_t *seat;
+ x11_output_t *out, *tmp;
- if (!conn)
- {
- PEPPER_ERROR("connection is null...\n");
- return PEPPER_FALSE;
- }
+ if (!conn) {
+ PEPPER_ERROR("connection is null...\n");
+ return PEPPER_FALSE;
+ }
- seat = calloc(1, sizeof(x11_seat_t));
- if (!seat)
- {
- PEPPER_ERROR("failed to allocate memory\n");
- return PEPPER_FALSE;
- }
+ seat = calloc(1, sizeof(x11_seat_t));
+ if (!seat) {
+ PEPPER_ERROR("failed to allocate memory\n");
+ return PEPPER_FALSE;
+ }
- conn->use_xinput = PEPPER_TRUE;
+ conn->use_xinput = PEPPER_TRUE;
- pepper_list_for_each_safe(out, tmp, &conn->output_list, link)
- x11_window_input_property_change(conn->xcb_connection, out->window);
+ pepper_list_for_each_safe(out, tmp, &conn->output_list, link)
+ x11_window_input_property_change(conn->xcb_connection, out->window);
- /* XXX: if x-input-module used without x-output-module,
- * need to create dummy window for input with output-size */
+ /* XXX: if x-input-module used without x-output-module,
+ * need to create dummy window for input with output-size */
- seat->id = X11_BACKEND_INPUT_ID;
+ seat->id = X11_BACKEND_INPUT_ID;
- /* Hard-coded: */
- seat->pointer = pepper_input_device_create(conn->compositor, WL_SEAT_CAPABILITY_POINTER,
- NULL, NULL);
- if (!seat->pointer)
- {
- PEPPER_ERROR("failed to create pepper pointer device\n");
+ /* Hard-coded: */
+ seat->pointer = pepper_input_device_create(conn->compositor,
+ WL_SEAT_CAPABILITY_POINTER,
+ NULL, NULL);
+ if (!seat->pointer) {
+ PEPPER_ERROR("failed to create pepper pointer device\n");
- goto failed;
- }
- seat->caps |= WL_SEAT_CAPABILITY_POINTER;
+ goto failed;
+ }
+ seat->caps |= WL_SEAT_CAPABILITY_POINTER;
- seat->keyboard = pepper_input_device_create(conn->compositor, WL_SEAT_CAPABILITY_KEYBOARD,
- NULL, NULL);
- if (!seat->keyboard)
- {
- PEPPER_ERROR("failed to create pepper keyboard device\n");
+ seat->keyboard = pepper_input_device_create(conn->compositor,
+ WL_SEAT_CAPABILITY_KEYBOARD,
+ NULL, NULL);
+ if (!seat->keyboard) {
+ PEPPER_ERROR("failed to create pepper keyboard device\n");
- goto failed;
- }
- seat->caps |= WL_SEAT_CAPABILITY_KEYBOARD;
+ goto failed;
+ }
+ seat->caps |= WL_SEAT_CAPABILITY_KEYBOARD;
- /* x-connection has only 1 seat */
- conn->seat = seat;
- seat->conn = conn;
+ /* x-connection has only 1 seat */
+ conn->seat = seat;
+ seat->conn = conn;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
failed:
- x11_seat_destroy(seat);
- return PEPPER_FALSE;
+ x11_seat_destroy(seat);
+ return PEPPER_FALSE;
}
typedef struct x11_seat x11_seat_t;
typedef struct x11_shm_image x11_shm_image_t;
-struct x11_shm_image
-{
- int shm_id;
- void *buf;
- pepper_format_t format;
- int stride;
- int w, h;
- xcb_shm_seg_t segment;
- pepper_render_target_t *target; /* XXX: need double-buffering? */
+struct x11_shm_image {
+ int shm_id;
+ void *buf;
+ pepper_format_t format;
+ int stride;
+ int w, h;
+ xcb_shm_seg_t segment;
+ pepper_render_target_t *target; /* XXX: need double-buffering? */
};
-struct x11_output
-{
- pepper_output_t *base;
- pepper_x11_connection_t *connection;
- char name[32];
- pepper_list_t link;
+struct x11_output {
+ pepper_output_t *base;
+ pepper_x11_connection_t *connection;
+ char name[32];
+ pepper_list_t link;
- int32_t x, y;
- int32_t w, h;
- uint32_t subpixel;
- uint8_t depth;
- uint8_t bpp;
+ int32_t x, y;
+ int32_t w, h;
+ uint32_t subpixel;
+ uint8_t depth;
+ uint8_t bpp;
- xcb_window_t window;
- xcb_gc_t gc;
- x11_cursor_t *cursor;
+ xcb_window_t window;
+ xcb_gc_t gc;
+ x11_cursor_t *cursor;
- pepper_renderer_t *renderer;
- x11_shm_image_t shm;
- pepper_render_target_t *target;
- pepper_render_target_t *gl_target;
+ pepper_renderer_t *renderer;
+ x11_shm_image_t shm;
+ pepper_render_target_t *target;
+ pepper_render_target_t *gl_target;
- struct wl_event_source *frame_done_timer;
- struct wl_listener conn_destroy_listener;
+ struct wl_event_source *frame_done_timer;
+ struct wl_listener conn_destroy_listener;
- pepper_plane_t *primary_plane;
+ pepper_plane_t *primary_plane;
};
-struct x11_seat
-{
- pepper_x11_connection_t *conn;
+struct x11_seat {
+ pepper_x11_connection_t *conn;
- pepper_input_device_t *pointer;
- pepper_input_device_t *keyboard;
- pepper_input_device_t *touch;
+ pepper_input_device_t *pointer;
+ pepper_input_device_t *keyboard;
+ pepper_input_device_t *touch;
- uint32_t id;
- uint32_t caps;
- char *name;
+ uint32_t id;
+ uint32_t caps;
+ char *name;
- pepper_list_t link;
+ pepper_list_t link;
- struct wl_listener conn_destroy_listener;
+ struct wl_listener conn_destroy_listener;
};
-struct pepper_x11_connection
-{
- pepper_compositor_t *compositor;
- char *display_name;
-
- Display *display;
- xcb_screen_t *screen;
- xcb_connection_t *xcb_connection;
-
- struct wl_event_source *xcb_event_source;
- int fd;
-
- pepper_list_t output_list;
-
- pepper_bool_t use_xinput;
- x11_seat_t *seat;
-
- struct {
- xcb_atom_t wm_protocols;
- xcb_atom_t wm_normal_hints;
- xcb_atom_t wm_size_hints;
- xcb_atom_t wm_delete_window;
- xcb_atom_t wm_class;
- xcb_atom_t net_wm_name;
- xcb_atom_t net_supporting_wm_check;
- xcb_atom_t net_supported;
- xcb_atom_t net_wm_icon;
- xcb_atom_t net_wm_state;
- xcb_atom_t net_wm_state_fullscreen;
- xcb_atom_t string;
- xcb_atom_t utf8_string;
- xcb_atom_t cardinal;
- xcb_atom_t xkb_names;
- } atom;
-
- pepper_renderer_t *pixman_renderer;
- pepper_renderer_t *gl_renderer;
+struct pepper_x11_connection {
+ pepper_compositor_t *compositor;
+ char *display_name;
+
+ Display *display;
+ xcb_screen_t *screen;
+ xcb_connection_t *xcb_connection;
+
+ struct wl_event_source *xcb_event_source;
+ int fd;
+
+ pepper_list_t output_list;
+
+ pepper_bool_t use_xinput;
+ x11_seat_t *seat;
+
+ struct {
+ xcb_atom_t wm_protocols;
+ xcb_atom_t wm_normal_hints;
+ xcb_atom_t wm_size_hints;
+ xcb_atom_t wm_delete_window;
+ xcb_atom_t wm_class;
+ xcb_atom_t net_wm_name;
+ xcb_atom_t net_supporting_wm_check;
+ xcb_atom_t net_supported;
+ xcb_atom_t net_wm_icon;
+ xcb_atom_t net_wm_state;
+ xcb_atom_t net_wm_state_fullscreen;
+ xcb_atom_t string;
+ xcb_atom_t utf8_string;
+ xcb_atom_t cardinal;
+ xcb_atom_t xkb_names;
+ } atom;
+
+ pepper_renderer_t *pixman_renderer;
+ pepper_renderer_t *gl_renderer;
};
-struct x11_cursor
-{
- xcb_cursor_t xcb_cursor;
- int w, h;
- uint8_t *data;
+struct x11_cursor {
+ xcb_cursor_t xcb_cursor;
+ int w, h;
+ uint8_t *data;
};
/* it declared in xcb-icccm.h */
typedef struct xcb_size_hints {
- uint32_t flags;
- uint32_t pad[4];
- int32_t min_width, min_height;
- int32_t max_width, max_height;
- int32_t width_inc, height_inc;
- int32_t min_aspect_x, min_aspect_y;
- int32_t max_aspect_x, max_aspect_y;
- int32_t base_width, base_height;
- int32_t win_gravity;
-}xcb_size_hints_t;
+ uint32_t flags;
+ uint32_t pad[4];
+ int32_t min_width, min_height;
+ int32_t max_width, max_height;
+ int32_t width_inc, height_inc;
+ int32_t min_aspect_x, min_aspect_y;
+ int32_t max_aspect_x, max_aspect_y;
+ int32_t base_width, base_height;
+ int32_t win_gravity;
+} xcb_size_hints_t;
#define WM_NORMAL_HINTS_MIN_SIZE 16
#define WM_NORMAL_HINTS_MAX_SIZE 32
/* -- xcb-icccm.h */
x11_window_input_property_change(xcb_connection_t *conn, xcb_window_t window);
void
-x11_handle_input_event(x11_seat_t* seat, uint32_t type, xcb_generic_event_t* xev);
+x11_handle_input_event(x11_seat_t *seat, uint32_t type,
+ xcb_generic_event_t *xev);
void
x11_output_destroy(void *o);
static uint8_t
xcb_depth_get(xcb_screen_t *screen, xcb_visualid_t id)
{
- xcb_depth_iterator_t i;
- xcb_visualtype_iterator_t j;
-
- i = xcb_screen_allowed_depths_iterator(screen);
- for (; i.rem; xcb_depth_next(&i))
- {
- j = xcb_depth_visuals_iterator(i.data);
- for (; j.rem; xcb_visualtype_next(&j))
- {
- if (j.data->visual_id == id)
- return i.data->depth;
- }
- }
- return 0;
+ xcb_depth_iterator_t i;
+ xcb_visualtype_iterator_t j;
+
+ i = xcb_screen_allowed_depths_iterator(screen);
+ for (; i.rem; xcb_depth_next(&i)) {
+ j = xcb_depth_visuals_iterator(i.data);
+ for (; j.rem; xcb_visualtype_next(&j)) {
+ if (j.data->visual_id == id)
+ return i.data->depth;
+ }
+ }
+ return 0;
}
static xcb_visualtype_t *
xcb_visualtype_get(xcb_screen_t *screen, xcb_visualid_t id)
{
- if (screen)
- {
- xcb_depth_iterator_t depth_iter;
-
- depth_iter = xcb_screen_allowed_depths_iterator(screen);
- for (; depth_iter.rem; xcb_depth_next(&depth_iter))
- {
- xcb_visualtype_iterator_t visual_iter;
-
- visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
- for (; visual_iter.rem; xcb_visualtype_next(&visual_iter))
- if (visual_iter.data->visual_id == id)
- return visual_iter.data;
- }
- }
- return NULL;
+ if (screen) {
+ xcb_depth_iterator_t depth_iter;
+
+ depth_iter = xcb_screen_allowed_depths_iterator(screen);
+ for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
+ xcb_visualtype_iterator_t visual_iter;
+
+ visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
+ for (; visual_iter.rem; xcb_visualtype_next(&visual_iter))
+ if (visual_iter.data->visual_id == id)
+ return visual_iter.data;
+ }
+ }
+ return NULL;
}
static void
x11_output_wait_for_map(x11_output_t *output)
{
- xcb_generic_event_t *event;
- xcb_map_notify_event_t *map_notify;
-
- uint8_t response_type;
- int mapped = 0, configured = 0;
-
- while (!mapped || !configured)
- {
- event = xcb_wait_for_event(output->connection->xcb_connection);
- response_type = event->response_type & ~0x80;
-
- switch (response_type)
- {
- case XCB_MAP_NOTIFY:
- map_notify = (xcb_map_notify_event_t *) event;
- if (map_notify->window == output->window)
- mapped = 1;
- break;
- case XCB_CONFIGURE_NOTIFY:
- configured = 1;
- break;
- }
- }
+ xcb_generic_event_t *event;
+ xcb_map_notify_event_t *map_notify;
+
+ uint8_t response_type;
+ int mapped = 0, configured = 0;
+
+ while (!mapped || !configured) {
+ event = xcb_wait_for_event(output->connection->xcb_connection);
+ response_type = event->response_type & ~0x80;
+
+ switch (response_type) {
+ case XCB_MAP_NOTIFY:
+ map_notify = (xcb_map_notify_event_t *) event;
+ if (map_notify->window == output->window)
+ mapped = 1;
+ break;
+ case XCB_CONFIGURE_NOTIFY:
+ configured = 1;
+ break;
+ }
+ }
}
static int
-frame_done_handler(void* data)
+frame_done_handler(void *data)
{
- x11_output_t *output = data;
- pepper_output_finish_frame(output->base, NULL);
- return 1;
+ x11_output_t *output = data;
+ pepper_output_finish_frame(output->base, NULL);
+ return 1;
}
static pepper_bool_t
gl_renderer_init(x11_output_t *output)
{
- output->gl_target = pepper_gl_renderer_create_target(output->connection->gl_renderer,
- (void *)(intptr_t)output->window,
- PEPPER_FORMAT_ARGB8888,
- &output->connection->screen->root_visual,
- output->w, output->h);
-
- if (!output->gl_target)
- {
- PEPPER_ERROR("Failed to create gl render target.\n");
- return PEPPER_FALSE;
- }
-
- output->renderer = output->connection->gl_renderer;
- output->target = output->gl_target;
- return PEPPER_TRUE;
+ output->gl_target = pepper_gl_renderer_create_target(
+ output->connection->gl_renderer,
+ (void *)(intptr_t)output->window,
+ PEPPER_FORMAT_ARGB8888,
+ &output->connection->screen->root_visual,
+ output->w, output->h);
+
+ if (!output->gl_target) {
+ PEPPER_ERROR("Failed to create gl render target.\n");
+ return PEPPER_FALSE;
+ }
+
+ output->renderer = output->connection->gl_renderer;
+ output->target = output->gl_target;
+ return PEPPER_TRUE;
}
static void
x11_shm_image_deinit(xcb_connection_t *conn, x11_shm_image_t *shm)
{
- if (shm->target)
- {
- pepper_render_target_destroy(shm->target);
- shm->target = NULL;
- }
-
- if (shm->segment)
- {
- xcb_shm_detach(conn, shm->segment);
- shm->segment = 0;
- }
-
- if (shm->buf)
- {
- shmdt(shm->buf);
- shm->buf = NULL;
- }
-
- if (shm->shm_id)
- {
- shmctl(shm->shm_id, IPC_RMID, NULL);
- shm->shm_id = -1;
- }
+ if (shm->target) {
+ pepper_render_target_destroy(shm->target);
+ shm->target = NULL;
+ }
+
+ if (shm->segment) {
+ xcb_shm_detach(conn, shm->segment);
+ shm->segment = 0;
+ }
+
+ if (shm->buf) {
+ shmdt(shm->buf);
+ shm->buf = NULL;
+ }
+
+ if (shm->shm_id) {
+ shmctl(shm->shm_id, IPC_RMID, NULL);
+ shm->shm_id = -1;
+ }
}
static pepper_bool_t
-x11_shm_image_init(x11_shm_image_t *shm, xcb_connection_t *conn, int w, int h, int bpp)
+x11_shm_image_init(x11_shm_image_t *shm, xcb_connection_t *conn, int w, int h,
+ int bpp)
{
- xcb_generic_error_t *err = NULL;
- xcb_void_cookie_t cookie;
- pepper_format_t format;
-
- /* FIXME: Hard coded */
- if (bpp == 32)
- {
- format = PEPPER_FORMAT_ARGB8888;
- }
- else if (bpp == 16)
- {
- format = PEPPER_FORMAT_RGB565;
- }
- else
- {
- PEPPER_ERROR("cannot find pixman format\n");
- goto err;
- }
-
- /* Create MIT-SHM id and attach */
- shm->shm_id = shmget(IPC_PRIVATE, w * h * (bpp/ 8), IPC_CREAT | S_IRWXU);
- if (shm->shm_id == -1)
- {
- PEPPER_ERROR("shmget() failed\n");
- goto err;
- }
-
- shm->buf = shmat(shm->shm_id, NULL, 0 /* read/write */);
- if (-1 == (long)shm->buf)
- {
- PEPPER_ERROR("shmat() failed\n");
- goto err;
- }
-
- /* Create XCB-SHM segment and attach */
- shm->segment = xcb_generate_id(conn);
- cookie = xcb_shm_attach_checked(conn, shm->segment, shm->shm_id, 1);
- err = xcb_request_check(conn, cookie);
- if (err)
- {
- PEPPER_ERROR("xcb_shm_attach error %d\n", err->error_code);
- goto err;
- }
-
- shmctl(shm->shm_id, IPC_RMID, NULL);
-
- /* Now create pepper render target */
- shm->target = pepper_pixman_renderer_create_target(format, shm->buf, w * (bpp / 8), w, h);
- if (!shm->target)
- {
- PEPPER_ERROR("Failed to create pixman render target\n");
- goto err;
- }
-
- shm->format = format;
- shm->stride = w * (bpp / 8);
- shm->w = w;
- shm->h = h;
-
- return PEPPER_TRUE;
+ xcb_generic_error_t *err = NULL;
+ xcb_void_cookie_t cookie;
+ pepper_format_t format;
+
+ /* FIXME: Hard coded */
+ if (bpp == 32) {
+ format = PEPPER_FORMAT_ARGB8888;
+ } else if (bpp == 16) {
+ format = PEPPER_FORMAT_RGB565;
+ } else {
+ PEPPER_ERROR("cannot find pixman format\n");
+ goto err;
+ }
+
+ /* Create MIT-SHM id and attach */
+ shm->shm_id = shmget(IPC_PRIVATE, w * h * (bpp / 8), IPC_CREAT | S_IRWXU);
+ if (shm->shm_id == -1) {
+ PEPPER_ERROR("shmget() failed\n");
+ goto err;
+ }
+
+ shm->buf = shmat(shm->shm_id, NULL, 0 /* read/write */);
+ if (-1 == (long)shm->buf) {
+ PEPPER_ERROR("shmat() failed\n");
+ goto err;
+ }
+
+ /* Create XCB-SHM segment and attach */
+ shm->segment = xcb_generate_id(conn);
+ cookie = xcb_shm_attach_checked(conn, shm->segment, shm->shm_id, 1);
+ err = xcb_request_check(conn, cookie);
+ if (err) {
+ PEPPER_ERROR("xcb_shm_attach error %d\n", err->error_code);
+ goto err;
+ }
+
+ shmctl(shm->shm_id, IPC_RMID, NULL);
+
+ /* Now create pepper render target */
+ shm->target = pepper_pixman_renderer_create_target(format, shm->buf,
+ w * (bpp / 8), w, h);
+ if (!shm->target) {
+ PEPPER_ERROR("Failed to create pixman render target\n");
+ goto err;
+ }
+
+ shm->format = format;
+ shm->stride = w * (bpp / 8);
+ shm->w = w;
+ shm->h = h;
+
+ return PEPPER_TRUE;
err:
- if (err)
- free(err);
+ if (err)
+ free(err);
- if (shm->buf)
- shmdt(shm->buf);
+ if (shm->buf)
+ shmdt(shm->buf);
- if (shm->shm_id)
- shmctl(shm->shm_id, IPC_RMID, NULL);
+ if (shm->shm_id)
+ shmctl(shm->shm_id, IPC_RMID, NULL);
- return PEPPER_FALSE;
+ return PEPPER_FALSE;
}
static pepper_bool_t
x11_shm_init(x11_output_t *output)
{
- xcb_screen_iterator_t scr_iter;
- xcb_format_iterator_t fmt_iter;
- xcb_visualtype_t *visual_type;
- xcb_connection_t *xcb_conn = output->connection->xcb_connection;
- int bpp = 0;
-
- /* Check if XCB-SHM is available */
- {
- const xcb_query_extension_reply_t *ext;
- ext = xcb_get_extension_data(xcb_conn, &xcb_shm_id);
- if (ext == NULL || !ext->present)
- {
- PEPPER_ERROR("xcb-shm extension is not available\n");
- return PEPPER_FALSE;
- }
- }
-
- /* Find root visual */
- scr_iter = xcb_setup_roots_iterator(xcb_get_setup(xcb_conn));
- visual_type = xcb_visualtype_get(scr_iter.data,
- scr_iter.data->root_visual);
- if (!visual_type)
- {
- PEPPER_ERROR("Failed to lookup visual for root window\n");
- return PEPPER_FALSE;;
- }
-
- output->depth = xcb_depth_get(scr_iter.data,
- scr_iter.data->root_visual);
-
- fmt_iter = xcb_setup_pixmap_formats_iterator(xcb_get_setup(xcb_conn));
- for (; fmt_iter.rem; xcb_format_next(&fmt_iter))
- {
- if (fmt_iter.data->depth == output->depth)
- {
- bpp = fmt_iter.data->bits_per_pixel;
- break;
- }
- }
- output->bpp = bpp;
-
- /* Init x11_shm_image */
- if (!x11_shm_image_init(&output->shm, xcb_conn, output->w, output->h, bpp))
- {
- PEPPER_ERROR("x11_shm_image_init failed\n");
- return PEPPER_FALSE;
- }
-
- output->gc = xcb_generate_id(xcb_conn);
- xcb_create_gc(xcb_conn, output->gc, output->window, 0, NULL);
-
- return PEPPER_TRUE;
+ xcb_screen_iterator_t scr_iter;
+ xcb_format_iterator_t fmt_iter;
+ xcb_visualtype_t *visual_type;
+ xcb_connection_t *xcb_conn = output->connection->xcb_connection;
+ int bpp = 0;
+
+ /* Check if XCB-SHM is available */
+ {
+ const xcb_query_extension_reply_t *ext;
+ ext = xcb_get_extension_data(xcb_conn, &xcb_shm_id);
+ if (ext == NULL || !ext->present) {
+ PEPPER_ERROR("xcb-shm extension is not available\n");
+ return PEPPER_FALSE;
+ }
+ }
+
+ /* Find root visual */
+ scr_iter = xcb_setup_roots_iterator(xcb_get_setup(xcb_conn));
+ visual_type = xcb_visualtype_get(scr_iter.data,
+ scr_iter.data->root_visual);
+ if (!visual_type) {
+ PEPPER_ERROR("Failed to lookup visual for root window\n");
+ return PEPPER_FALSE;;
+ }
+
+ output->depth = xcb_depth_get(scr_iter.data,
+ scr_iter.data->root_visual);
+
+ fmt_iter = xcb_setup_pixmap_formats_iterator(xcb_get_setup(xcb_conn));
+ for (; fmt_iter.rem; xcb_format_next(&fmt_iter)) {
+ if (fmt_iter.data->depth == output->depth) {
+ bpp = fmt_iter.data->bits_per_pixel;
+ break;
+ }
+ }
+ output->bpp = bpp;
+
+ /* Init x11_shm_image */
+ if (!x11_shm_image_init(&output->shm, xcb_conn, output->w, output->h, bpp)) {
+ PEPPER_ERROR("x11_shm_image_init failed\n");
+ return PEPPER_FALSE;
+ }
+
+ output->gc = xcb_generate_id(xcb_conn);
+ xcb_create_gc(xcb_conn, output->gc, output->window, 0, NULL);
+
+ return PEPPER_TRUE;
}
static pepper_bool_t
pixman_renderer_init(x11_output_t *output)
{
- /* Initialize xcb-shm infra and init shm-buffer */
- if (!x11_shm_init(output))
- {
- PEPPER_ERROR("shm_init failed\n");
- return PEPPER_FALSE;
- }
+ /* Initialize xcb-shm infra and init shm-buffer */
+ if (!x11_shm_init(output)) {
+ PEPPER_ERROR("shm_init failed\n");
+ return PEPPER_FALSE;
+ }
- output->renderer = output->connection->pixman_renderer;
- output->target = output->shm.target;
+ output->renderer = output->connection->pixman_renderer;
+ output->target = output->shm.target;
- return PEPPER_TRUE;
+ return PEPPER_TRUE;
}
static pepper_bool_t
renderer_init(x11_output_t *output, const char *renderer)
{
- if (!strcmp(renderer, "gl"))
- {
- if (gl_renderer_init(output))
- return PEPPER_TRUE;
- }
-
- /* Pixman is default renderer */
- return pixman_renderer_init(output);
+ if (!strcmp(renderer, "gl")) {
+ if (gl_renderer_init(output))
+ return PEPPER_TRUE;
+ }
+
+ /* Pixman is default renderer */
+ return pixman_renderer_init(output);
}
void
x11_output_destroy(void *o)
{
- x11_output_t *output = o;
- pepper_x11_connection_t *conn = output->connection;
-
- if (output->gl_target)
- pepper_render_target_destroy(output->gl_target);
-
- /* XXX */
- x11_shm_image_deinit(conn->xcb_connection, &output->shm);
- wl_event_source_remove(output->frame_done_timer);
- xcb_destroy_window(conn->xcb_connection, output->window);
- pepper_list_remove(&output->link);
- xcb_flush(conn->xcb_connection);
- free(output);
+ x11_output_t *output = o;
+ pepper_x11_connection_t *conn = output->connection;
+
+ if (output->gl_target)
+ pepper_render_target_destroy(output->gl_target);
+
+ /* XXX */
+ x11_shm_image_deinit(conn->xcb_connection, &output->shm);
+ wl_event_source_remove(output->frame_done_timer);
+ xcb_destroy_window(conn->xcb_connection, output->window);
+ pepper_list_remove(&output->link);
+ xcb_flush(conn->xcb_connection);
+ free(output);
}
static int32_t
x11_output_get_subpixel_order(void *o)
{
- x11_output_t *output = o;
- return output->subpixel;
+ x11_output_t *output = o;
+ return output->subpixel;
}
static const char *
x11_output_get_maker_name(void *o)
{
- return "PePPer_x11";
+ return "PePPer_x11";
}
static const char *
x11_output_get_model_name(void *o)
{
- return "PePPer_x11";
+ return "PePPer_x11";
}
static int
x11_output_get_mode_count(void *o)
{
- /* There's only one available mode in x11 backend which is also the current mode. */
- return 1;
+ /* There's only one available mode in x11 backend which is also the current mode. */
+ return 1;
}
static void
x11_output_get_mode(void *o, int index, pepper_output_mode_t *mode)
{
- x11_output_t *output = o;
+ x11_output_t *output = o;
- if (index != 0)
- return;
+ if (index != 0)
+ return;
- mode->flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
- mode->w = output->w;
- mode->h = output->h;
- mode->refresh = 60000;
+ mode->flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
+ mode->w = output->w;
+ mode->h = output->h;
+ mode->refresh = 60000;
}
static pepper_bool_t
x11_output_set_mode(void *o, const pepper_output_mode_t *mode)
{
- x11_output_t *output = o;
-
- if (mode->w <= 0 || mode->h <= 0)
- return PEPPER_FALSE;
-
- if (mode->refresh != 60000)
- return PEPPER_FALSE;
-
- if (output->w != mode->w || output->h != mode->h)
- {
- output->w = mode->w;
- output->h = mode->h;
-
- /* Resize output window. */
- {
- xcb_connection_t *conn = output->connection->xcb_connection;
- xcb_size_hints_t hints;
- uint32_t values[2];
-
- values[0] = output->w;
- values[1] = output->h;
-
- /* set hints for window */
- memset(&hints, 0, sizeof(hints));
- hints.flags = WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
- hints.min_width = hints.max_width = output->w;
- hints.min_height = hints.max_height = output->h;
- xcb_change_property(conn,
- XCB_PROP_MODE_REPLACE,
- output->window,
- output->connection->atom.wm_normal_hints,
- output->connection->atom.wm_size_hints,
- 32,
- sizeof(hints) / 4,
- (uint8_t *)&hints);
-
- /* resize window */
- xcb_configure_window (conn,
- output->window,
- XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
- values);
-
- /* resize image */
- if (output->shm.target)
- {
- /* Release existing shm-buffer */
- x11_shm_image_deinit(conn, &output->shm);
-
- /* Init x11_shm_image */
- if (!x11_shm_image_init(&output->shm, conn, output->w, output->h, output->bpp))
- {
- PEPPER_ERROR("x11_shm_image_init failed\n");
- return PEPPER_FALSE;
- }
- }
-
- /* flush connection */
- xcb_flush(output->connection->xcb_connection);
- }
-
- pepper_output_update_mode(output->base);
- }
-
- return PEPPER_TRUE;
+ x11_output_t *output = o;
+
+ if (mode->w <= 0 || mode->h <= 0)
+ return PEPPER_FALSE;
+
+ if (mode->refresh != 60000)
+ return PEPPER_FALSE;
+
+ if (output->w != mode->w || output->h != mode->h) {
+ output->w = mode->w;
+ output->h = mode->h;
+
+ /* Resize output window. */
+ {
+ xcb_connection_t *conn = output->connection->xcb_connection;
+ xcb_size_hints_t hints;
+ uint32_t values[2];
+
+ values[0] = output->w;
+ values[1] = output->h;
+
+ /* set hints for window */
+ memset(&hints, 0, sizeof(hints));
+ hints.flags = WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
+ hints.min_width = hints.max_width = output->w;
+ hints.min_height = hints.max_height = output->h;
+ xcb_change_property(conn,
+ XCB_PROP_MODE_REPLACE,
+ output->window,
+ output->connection->atom.wm_normal_hints,
+ output->connection->atom.wm_size_hints,
+ 32,
+ sizeof(hints) / 4,
+ (uint8_t *)&hints);
+
+ /* resize window */
+ xcb_configure_window (conn,
+ output->window,
+ XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
+ values);
+
+ /* resize image */
+ if (output->shm.target) {
+ /* Release existing shm-buffer */
+ x11_shm_image_deinit(conn, &output->shm);
+
+ /* Init x11_shm_image */
+ if (!x11_shm_image_init(&output->shm, conn, output->w, output->h,
+ output->bpp)) {
+ PEPPER_ERROR("x11_shm_image_init failed\n");
+ return PEPPER_FALSE;
+ }
+ }
+
+ /* flush connection */
+ xcb_flush(output->connection->xcb_connection);
+ }
+
+ pepper_output_update_mode(output->base);
+ }
+
+ return PEPPER_TRUE;
}
static void
x11_output_assign_planes(void *o, const pepper_list_t *view_list)
{
- x11_output_t *output = (x11_output_t *)o;
- pepper_list_t *l;
-
- pepper_list_for_each_list(l, view_list)
- {
- pepper_view_t *view = l->item;
- pepper_view_assign_plane(view, output->base, output->primary_plane);
- }
+ x11_output_t *output = (x11_output_t *)o;
+ pepper_list_t *l;
+
+ pepper_list_for_each_list(l, view_list) {
+ pepper_view_t *view = l->item;
+ pepper_view_assign_plane(view, output->base, output->primary_plane);
+ }
}
static void
x11_output_start_repaint_loop(void *o)
{
- x11_output_t *output = o;
- struct timespec ts;
+ x11_output_t *output = o;
+ struct timespec ts;
- pepper_compositor_get_time(output->connection->compositor, &ts);
- pepper_output_finish_frame(output->base, &ts);
+ pepper_compositor_get_time(output->connection->compositor, &ts);
+ pepper_output_finish_frame(output->base, &ts);
}
static void
x11_output_repaint(void *o, const pepper_list_t *plane_list)
{
- x11_output_t *output = o;
- pepper_list_t *l;
-
- pepper_list_for_each_list(l, plane_list)
- {
- pepper_plane_t *plane = l->item;
-
- if (plane == output->primary_plane)
- {
- const pepper_list_t *render_list = pepper_plane_get_render_list(plane);
- pixman_region32_t *damage = pepper_plane_get_damage_region(plane);
-
- pepper_renderer_set_target(output->renderer, output->target);
- pepper_renderer_repaint_output(output->renderer, output->base, render_list, damage);
- pepper_plane_clear_damage_region(plane);
-
- if (output->renderer == output->connection->pixman_renderer)
- {
- xcb_void_cookie_t cookie;
- xcb_generic_error_t *err;
-
- cookie = xcb_shm_put_image_checked(output->connection->xcb_connection,
- output->window,
- output->gc,
- output->w,
- output->h,
- 0, /* src_x */
- 0, /* src_y */
- output->shm.w, /* src_w */
- output->shm.h, /* src_h */
- 0, /* dst_x */
- 0, /* dst_y */
- output->depth, /* depth */
- XCB_IMAGE_FORMAT_Z_PIXMAP, /* format */
- 0, /* send_event */
- output->shm.segment, /* xcb shm segment */
- 0); /* offset */
-
- err = xcb_request_check(output->connection->xcb_connection, cookie);
- if (err)
- {
- PEPPER_ERROR("Failed to put shm image, err: %d\n", err->error_code);
- free(err);
- }
- }
-
- /* XXX: frame_done callback called after 10ms, referenced from weston */
- wl_event_source_timer_update(output->frame_done_timer, 10);
- }
-
- /* TODO: Cursor??? */
- }
+ x11_output_t *output = o;
+ pepper_list_t *l;
+
+ pepper_list_for_each_list(l, plane_list) {
+ pepper_plane_t *plane = l->item;
+
+ if (plane == output->primary_plane) {
+ const pepper_list_t *render_list = pepper_plane_get_render_list(plane);
+ pixman_region32_t *damage = pepper_plane_get_damage_region(plane);
+
+ pepper_renderer_set_target(output->renderer, output->target);
+ pepper_renderer_repaint_output(output->renderer, output->base, render_list,
+ damage);
+ pepper_plane_clear_damage_region(plane);
+
+ if (output->renderer == output->connection->pixman_renderer) {
+ xcb_void_cookie_t cookie;
+ xcb_generic_error_t *err;
+
+ cookie = xcb_shm_put_image_checked(output->connection->xcb_connection,
+ output->window,
+ output->gc,
+ output->w,
+ output->h,
+ 0, /* src_x */
+ 0, /* src_y */
+ output->shm.w, /* src_w */
+ output->shm.h, /* src_h */
+ 0, /* dst_x */
+ 0, /* dst_y */
+ output->depth, /* depth */
+ XCB_IMAGE_FORMAT_Z_PIXMAP, /* format */
+ 0, /* send_event */
+ output->shm.segment, /* xcb shm segment */
+ 0); /* offset */
+
+ err = xcb_request_check(output->connection->xcb_connection, cookie);
+ if (err) {
+ PEPPER_ERROR("Failed to put shm image, err: %d\n", err->error_code);
+ free(err);
+ }
+ }
+
+ /* XXX: frame_done callback called after 10ms, referenced from weston */
+ wl_event_source_timer_update(output->frame_done_timer, 10);
+ }
+
+ /* TODO: Cursor??? */
+ }
}
static void
x11_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h)
{
- pepper_renderer_attach_surface(((x11_output_t *)o)->renderer, surface, w, h);
+ pepper_renderer_attach_surface(((x11_output_t *)o)->renderer, surface, w, h);
}
static void
-x11_output_flush_surface_damage(void *o, pepper_surface_t *surface, pepper_bool_t *keep_buffer)
-{
- x11_output_t *output = o;
- pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
-
- pepper_renderer_flush_surface_damage(output->renderer, surface);
-
- if (output->renderer == output->connection->pixman_renderer ||
- (buffer && !wl_shm_buffer_get(pepper_buffer_get_resource(buffer))))
- {
- *keep_buffer = PEPPER_TRUE;
- }
- else
- {
- *keep_buffer = PEPPER_FALSE;
- }
-}
-
-/* X11 output backend to export for PePPer core */
-static const pepper_output_backend_t x11_output_backend =
+x11_output_flush_surface_damage(void *o, pepper_surface_t *surface,
+ pepper_bool_t *keep_buffer)
{
- x11_output_destroy,
+ x11_output_t *output = o;
+ pepper_buffer_t *buffer = pepper_surface_get_buffer(surface);
- x11_output_get_subpixel_order,
- x11_output_get_maker_name,
- x11_output_get_model_name,
+ pepper_renderer_flush_surface_damage(output->renderer, surface);
- x11_output_get_mode_count,
- x11_output_get_mode,
- x11_output_set_mode,
+ if (output->renderer == output->connection->pixman_renderer ||
+ (buffer && !wl_shm_buffer_get(pepper_buffer_get_resource(buffer)))) {
+ *keep_buffer = PEPPER_TRUE;
+ } else {
+ *keep_buffer = PEPPER_FALSE;
+ }
+}
- x11_output_assign_planes,
- x11_output_start_repaint_loop,
- x11_output_repaint,
- x11_output_attach_surface,
- x11_output_flush_surface_damage,
+/* X11 output backend to export for PePPer core */
+static const pepper_output_backend_t x11_output_backend = {
+ x11_output_destroy,
+
+ x11_output_get_subpixel_order,
+ x11_output_get_maker_name,
+ x11_output_get_model_name,
+
+ x11_output_get_mode_count,
+ x11_output_get_mode,
+ x11_output_set_mode,
+
+ x11_output_assign_planes,
+ x11_output_start_repaint_loop,
+ x11_output_repaint,
+ x11_output_attach_surface,
+ x11_output_flush_surface_damage,
};
PEPPER_API pepper_output_t *
pepper_x11_output_create(pepper_x11_connection_t *connection,
- int x, int y, int w, int h, int transform, int scale,
- const char *renderer)
+ int x, int y, int w, int h, int transform, int scale,
+ const char *renderer)
{
- static const char *window_name = "PePPer Compositor";
- static const char *class_name = "pepper-1\0PePPer Compositor";
-
- pepper_output_t *base;
- x11_output_t *output;
-
- struct wl_display *wldisplay;
- struct wl_event_loop *loop;
-
- output = calloc(1, sizeof(x11_output_t));
- if (!output)
- {
- PEPPER_ERROR("memory allocation failed");
- return NULL;
- }
-
- output->connection = connection;
- output->w = w;
- output->h = h;
-
- /* Hard-Coded: subpixel order to horizontal RGB. */
- output->subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
-
- /* Create X11 window */
- {
- uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
- uint32_t values[2] = {
- connection->screen->white_pixel,
- XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY
- };
- xcb_size_hints_t hints;
- xcb_atom_t list[1];
-
- output->window = xcb_generate_id(connection->xcb_connection);
- xcb_create_window(connection->xcb_connection,
- XCB_COPY_FROM_PARENT,
- output->window,
- connection->screen->root,
- 0, 0, w, h, 0,
- XCB_WINDOW_CLASS_INPUT_OUTPUT,
- connection->screen->root_visual,
- mask,
- values);
-
- /* cannot resize */
- memset(&hints, 0, sizeof(hints));
- hints.flags = WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
- hints.min_width = hints.max_width = w;
- hints.min_height = hints.max_height = h;
- xcb_change_property(connection->xcb_connection,
- XCB_PROP_MODE_REPLACE,
- output->window,
- connection->atom.wm_normal_hints,
- connection->atom.wm_size_hints,
- 32,
- sizeof(hints) / 4,
- (uint8_t *)&hints);
-
- /* set window name */
- xcb_change_property(connection->xcb_connection, XCB_PROP_MODE_REPLACE,
- output->window,
- connection->atom.net_wm_name,
- connection->atom.utf8_string, 8,
- strlen(window_name), window_name);
- xcb_change_property(connection->xcb_connection, XCB_PROP_MODE_REPLACE,
- output->window,
- connection->atom.wm_class,
- connection->atom.string, 8,
- strlen(class_name), class_name);
-
- /* set property to receive wm_delete_window message */
- list[0] = connection->atom.wm_delete_window;
- xcb_change_property(connection->xcb_connection, XCB_PROP_MODE_REPLACE,
- output->window,
- connection->atom.wm_protocols,
- XCB_ATOM_ATOM, 32,
- 1, list);
-
-
- xcb_map_window(connection->xcb_connection, output->window);
-
- if (connection->use_xinput)
- x11_window_input_property_change(connection->xcb_connection,
- output->window);
-
- pepper_list_insert(&connection->output_list, &output->link);
- xcb_flush(connection->xcb_connection);
- x11_output_wait_for_map(output);
- }
-
- wldisplay = pepper_compositor_get_display(connection->compositor);
- loop = wl_display_get_event_loop(wldisplay);
- output->frame_done_timer = wl_event_loop_add_timer(loop, frame_done_handler, output);
-
- /* Init renderer */
- renderer_init(output, renderer);
-
- /* Register output object */
- snprintf(&output->name[0], 32, "x11-%p", output);
- base = pepper_compositor_add_output(connection->compositor,
- &x11_output_backend, output->name, output,
- transform, scale);
- if (!base)
- {
- PEPPER_ERROR("pepper_compositor_add_output failed\n");
- x11_output_destroy(output);
- return NULL;
- }
-
- output->base = base;
- output->primary_plane = pepper_output_add_plane(output->base, NULL);
- pepper_output_move(base, x, y);
-
- return base;
+ static const char *window_name = "PePPer Compositor";
+ static const char *class_name = "pepper-1\0PePPer Compositor";
+
+ pepper_output_t *base;
+ x11_output_t *output;
+
+ struct wl_display *wldisplay;
+ struct wl_event_loop *loop;
+
+ output = calloc(1, sizeof(x11_output_t));
+ if (!output) {
+ PEPPER_ERROR("memory allocation failed");
+ return NULL;
+ }
+
+ output->connection = connection;
+ output->w = w;
+ output->h = h;
+
+ /* Hard-Coded: subpixel order to horizontal RGB. */
+ output->subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
+
+ /* Create X11 window */
+ {
+ uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
+ uint32_t values[2] = {
+ connection->screen->white_pixel,
+ XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY
+ };
+ xcb_size_hints_t hints;
+ xcb_atom_t list[1];
+
+ output->window = xcb_generate_id(connection->xcb_connection);
+ xcb_create_window(connection->xcb_connection,
+ XCB_COPY_FROM_PARENT,
+ output->window,
+ connection->screen->root,
+ 0, 0, w, h, 0,
+ XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ connection->screen->root_visual,
+ mask,
+ values);
+
+ /* cannot resize */
+ memset(&hints, 0, sizeof(hints));
+ hints.flags = WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
+ hints.min_width = hints.max_width = w;
+ hints.min_height = hints.max_height = h;
+ xcb_change_property(connection->xcb_connection,
+ XCB_PROP_MODE_REPLACE,
+ output->window,
+ connection->atom.wm_normal_hints,
+ connection->atom.wm_size_hints,
+ 32,
+ sizeof(hints) / 4,
+ (uint8_t *)&hints);
+
+ /* set window name */
+ xcb_change_property(connection->xcb_connection, XCB_PROP_MODE_REPLACE,
+ output->window,
+ connection->atom.net_wm_name,
+ connection->atom.utf8_string, 8,
+ strlen(window_name), window_name);
+ xcb_change_property(connection->xcb_connection, XCB_PROP_MODE_REPLACE,
+ output->window,
+ connection->atom.wm_class,
+ connection->atom.string, 8,
+ strlen(class_name), class_name);
+
+ /* set property to receive wm_delete_window message */
+ list[0] = connection->atom.wm_delete_window;
+ xcb_change_property(connection->xcb_connection, XCB_PROP_MODE_REPLACE,
+ output->window,
+ connection->atom.wm_protocols,
+ XCB_ATOM_ATOM, 32,
+ 1, list);
+
+
+ xcb_map_window(connection->xcb_connection, output->window);
+
+ if (connection->use_xinput)
+ x11_window_input_property_change(connection->xcb_connection,
+ output->window);
+
+ pepper_list_insert(&connection->output_list, &output->link);
+ xcb_flush(connection->xcb_connection);
+ x11_output_wait_for_map(output);
+ }
+
+ wldisplay = pepper_compositor_get_display(connection->compositor);
+ loop = wl_display_get_event_loop(wldisplay);
+ output->frame_done_timer = wl_event_loop_add_timer(loop, frame_done_handler,
+ output);
+
+ /* Init renderer */
+ renderer_init(output, renderer);
+
+ /* Register output object */
+ snprintf(&output->name[0], 32, "x11-%p", output);
+ base = pepper_compositor_add_output(connection->compositor,
+ &x11_output_backend, output->name, output,
+ transform, scale);
+ if (!base) {
+ PEPPER_ERROR("pepper_compositor_add_output failed\n");
+ x11_output_destroy(output);
+ return NULL;
+ }
+
+ output->base = base;
+ output->primary_plane = pepper_output_add_plane(output->base, NULL);
+ pepper_output_move(base, x, y);
+
+ return base;
}
static void
handle_signals(int s, siginfo_t *siginfo, void *context)
{
- pepper_virtual_terminal_restore();
- raise(SIGTRAP);
+ pepper_virtual_terminal_restore();
+ raise(SIGTRAP);
}
static void
init_signals()
{
- struct sigaction action;
+ struct sigaction action;
- action.sa_flags = SA_SIGINFO | SA_RESETHAND;
- action.sa_sigaction = handle_signals;
- sigemptyset(&action.sa_mask);
+ action.sa_flags = SA_SIGINFO | SA_RESETHAND;
+ action.sa_sigaction = handle_signals;
+ sigemptyset(&action.sa_mask);
- sigaction(SIGSEGV, &action, NULL);
- sigaction(SIGABRT, &action, NULL);
+ sigaction(SIGSEGV, &action, NULL);
+ sigaction(SIGABRT, &action, NULL);
}
static int
handle_sigint(int signal_number, void *data)
{
- struct wl_display *display = (struct wl_display *)data;
- wl_display_terminate(display);
+ struct wl_display *display = (struct wl_display *)data;
+ wl_display_terminate(display);
- return 0;
+ return 0;
}
int
main(int argc, char **argv)
{
- pepper_compositor_t *compositor = NULL;
- pepper_drm_t *drm = NULL;
- pepper_libinput_t *input = NULL;
+ pepper_compositor_t *compositor = NULL;
+ pepper_drm_t *drm = NULL;
+ pepper_libinput_t *input = NULL;
- struct udev *udev = NULL;
+ struct udev *udev = NULL;
- struct wl_display *display = NULL;
- struct wl_event_loop *loop = NULL;
- struct wl_event_source *sigint = NULL;
- int tty;
- const char *tty_str;
+ struct wl_display *display = NULL;
+ struct wl_event_loop *loop = NULL;
+ struct wl_event_source *sigint = NULL;
+ int tty;
+ const char *tty_str;
- init_signals();
+ init_signals();
- tty_str = getenv("PEPPER_DRM_TTY");
+ tty_str = getenv("PEPPER_DRM_TTY");
- if (!tty_str)
- tty = 0;
- else
- tty = atoi(tty_str);
+ if (!tty_str)
+ tty = 0;
+ else
+ tty = atoi(tty_str);
- if (!pepper_virtual_terminal_setup(tty))
- goto cleanup;
+ if (!pepper_virtual_terminal_setup(tty))
+ goto cleanup;
- compositor = pepper_compositor_create("wayland-0");
- if (!compositor)
- goto cleanup;
+ compositor = pepper_compositor_create("wayland-0");
+ if (!compositor)
+ goto cleanup;
- udev = udev_new();
- if (!udev)
- goto cleanup;
+ udev = udev_new();
+ if (!udev)
+ goto cleanup;
- input = pepper_libinput_create(compositor, udev);
- if (!input)
- goto cleanup;
+ input = pepper_libinput_create(compositor, udev);
+ if (!input)
+ goto cleanup;
- drm = pepper_drm_create(compositor, udev, NULL);
- if (!drm)
- goto cleanup;
+ drm = pepper_drm_create(compositor, udev, NULL);
+ if (!drm)
+ goto cleanup;
- if (!pepper_desktop_shell_init(compositor))
- goto cleanup;
+ if (!pepper_desktop_shell_init(compositor))
+ goto cleanup;
- display = pepper_compositor_get_display(compositor);
- if (!display)
- goto cleanup;
+ display = pepper_compositor_get_display(compositor);
+ if (!display)
+ goto cleanup;
- loop = wl_display_get_event_loop(display);
- sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
- if (!sigint)
- goto cleanup;
+ loop = wl_display_get_event_loop(display);
+ sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
+ if (!sigint)
+ goto cleanup;
- wl_display_run(display);
+ wl_display_run(display);
cleanup:
- if (sigint)
- wl_event_source_remove(sigint);
+ if (sigint)
+ wl_event_source_remove(sigint);
- if (drm)
- pepper_drm_destroy(drm);
+ if (drm)
+ pepper_drm_destroy(drm);
- if (input)
- pepper_libinput_destroy(input);
+ if (input)
+ pepper_libinput_destroy(input);
- if (udev)
- udev_unref(udev);
+ if (udev)
+ udev_unref(udev);
- if (compositor)
- pepper_compositor_destroy(compositor);
+ if (compositor)
+ pepper_compositor_destroy(compositor);
- pepper_virtual_terminal_restore();
+ pepper_virtual_terminal_restore();
- return 0;
+ return 0;
}
static void
handle_signals(int s, siginfo_t *siginfo, void *context)
{
- pepper_virtual_terminal_restore();
- raise(SIGTRAP);
+ pepper_virtual_terminal_restore();
+ raise(SIGTRAP);
}
static void
init_signals()
{
- struct sigaction action;
+ struct sigaction action;
- action.sa_flags = SA_SIGINFO | SA_RESETHAND;
- action.sa_sigaction = handle_signals;
- sigemptyset(&action.sa_mask);
+ action.sa_flags = SA_SIGINFO | SA_RESETHAND;
+ action.sa_sigaction = handle_signals;
+ sigemptyset(&action.sa_mask);
- sigaction(SIGSEGV, &action, NULL);
- sigaction(SIGABRT, &action, NULL);
+ sigaction(SIGSEGV, &action, NULL);
+ sigaction(SIGABRT, &action, NULL);
}
static int
handle_sigint(int signal_number, void *data)
{
- struct wl_display *display = (struct wl_display *)data;
- wl_display_terminate(display);
+ struct wl_display *display = (struct wl_display *)data;
+ wl_display_terminate(display);
- return 0;
+ return 0;
}
int
main(int argc, char **argv)
{
- pepper_compositor_t *compositor = NULL;
- pepper_fbdev_t *fbdev = NULL;
- pepper_libinput_t *input = NULL;
+ pepper_compositor_t *compositor = NULL;
+ pepper_fbdev_t *fbdev = NULL;
+ pepper_libinput_t *input = NULL;
- struct udev *udev = NULL;
+ struct udev *udev = NULL;
- struct wl_display *display = NULL;
- struct wl_event_loop *loop = NULL;
- struct wl_event_source *sigint = NULL;
+ struct wl_display *display = NULL;
+ struct wl_event_loop *loop = NULL;
+ struct wl_event_source *sigint = NULL;
- { /* for gdb attach */
- char cc;
- int ret;
+ { /* for gdb attach */
+ char cc;
+ int ret;
- ret = scanf("%c", &cc);
- if (ret < 0)
- return -1;
- }
+ ret = scanf("%c", &cc);
+ if (ret < 0)
+ return -1;
+ }
- init_signals();
+ init_signals();
- if (!pepper_virtual_terminal_setup(0/*FIXME*/))
- goto cleanup;
+ if (!pepper_virtual_terminal_setup(0/*FIXME*/))
+ goto cleanup;
- compositor = pepper_compositor_create("wayland-0");
- if (!compositor)
- goto cleanup;
+ compositor = pepper_compositor_create("wayland-0");
+ if (!compositor)
+ goto cleanup;
- udev = udev_new();
- if (!udev)
- goto cleanup;
+ udev = udev_new();
+ if (!udev)
+ goto cleanup;
- input = pepper_libinput_create(compositor, udev);
- if (!input)
- goto cleanup;
+ input = pepper_libinput_create(compositor, udev);
+ if (!input)
+ goto cleanup;
- fbdev = pepper_fbdev_create(compositor, udev, "", "pixman");
- if (!fbdev)
- goto cleanup;
+ fbdev = pepper_fbdev_create(compositor, udev, "", "pixman");
+ if (!fbdev)
+ goto cleanup;
- if (!pepper_desktop_shell_init(compositor))
- goto cleanup;
+ if (!pepper_desktop_shell_init(compositor))
+ goto cleanup;
- display = pepper_compositor_get_display(compositor);
- if (!display)
- goto cleanup;
+ display = pepper_compositor_get_display(compositor);
+ if (!display)
+ goto cleanup;
- loop = wl_display_get_event_loop(display);
- sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
- if (!sigint)
- goto cleanup;
+ loop = wl_display_get_event_loop(display);
+ sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
+ if (!sigint)
+ goto cleanup;
- wl_display_run(display);
+ wl_display_run(display);
cleanup:
- if (sigint)
- wl_event_source_remove(sigint);
+ if (sigint)
+ wl_event_source_remove(sigint);
- if (fbdev)
- pepper_fbdev_destroy(fbdev);
+ if (fbdev)
+ pepper_fbdev_destroy(fbdev);
- if (input)
- pepper_libinput_destroy(input);
+ if (input)
+ pepper_libinput_destroy(input);
- if (udev)
- udev_unref(udev);
+ if (udev)
+ udev_unref(udev);
- if (compositor)
- pepper_compositor_destroy(compositor);
+ if (compositor)
+ pepper_compositor_destroy(compositor);
- pepper_virtual_terminal_restore();
+ pepper_virtual_terminal_restore();
- return 0;
+ return 0;
}
static void
handle_signals(int s, siginfo_t *siginfo, void *context)
{
- raise(SIGTRAP);
+ raise(SIGTRAP);
}
static void
init_signals()
{
- struct sigaction action;
+ struct sigaction action;
- action.sa_flags = SA_SIGINFO | SA_RESETHAND;
- action.sa_sigaction = handle_signals;
- sigemptyset(&action.sa_mask);
+ action.sa_flags = SA_SIGINFO | SA_RESETHAND;
+ action.sa_sigaction = handle_signals;
+ sigemptyset(&action.sa_mask);
- sigaction(SIGSEGV, &action, NULL);
- sigaction(SIGABRT, &action, NULL);
+ sigaction(SIGSEGV, &action, NULL);
+ sigaction(SIGABRT, &action, NULL);
}
static int
handle_sigint(int signal_number, void *data)
{
- struct wl_display *display = (struct wl_display *)data;
- wl_display_terminate(display);
+ struct wl_display *display = (struct wl_display *)data;
+ wl_display_terminate(display);
- return 0;
+ return 0;
}
int
main(int argc, char **argv)
{
- pepper_compositor_t *compositor = NULL;
- pepper_tdm_t *tdm = NULL;
- pepper_libinput_t *input = NULL;
+ pepper_compositor_t *compositor = NULL;
+ pepper_tdm_t *tdm = NULL;
+ pepper_libinput_t *input = NULL;
- struct udev *udev = NULL;
+ struct udev *udev = NULL;
- struct wl_display *display = NULL;
- struct wl_event_loop *loop = NULL;
- struct wl_event_source *sigint = NULL;
+ struct wl_display *display = NULL;
+ struct wl_event_loop *loop = NULL;
+ struct wl_event_source *sigint = NULL;
- init_signals();
+ init_signals();
- compositor = pepper_compositor_create("wayland-0");
- if (!compositor)
- goto cleanup;
+ compositor = pepper_compositor_create("wayland-0");
+ if (!compositor)
+ goto cleanup;
- udev = udev_new();
- if (!udev)
- goto cleanup;
+ udev = udev_new();
+ if (!udev)
+ goto cleanup;
- input = pepper_libinput_create(compositor, udev);
- if (!input)
- goto cleanup;
+ input = pepper_libinput_create(compositor, udev);
+ if (!input)
+ goto cleanup;
- tdm = pepper_tdm_create(compositor);
- if (!tdm)
- goto cleanup;
+ tdm = pepper_tdm_create(compositor);
+ if (!tdm)
+ goto cleanup;
- if (!pepper_desktop_shell_init(compositor))
- goto cleanup;
+ if (!pepper_desktop_shell_init(compositor))
+ goto cleanup;
- display = pepper_compositor_get_display(compositor);
- if (!display)
- goto cleanup;
+ display = pepper_compositor_get_display(compositor);
+ if (!display)
+ goto cleanup;
- loop = wl_display_get_event_loop(display);
- sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
- if (!sigint)
- goto cleanup;
+ loop = wl_display_get_event_loop(display);
+ sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
+ if (!sigint)
+ goto cleanup;
- wl_display_run(display);
+ wl_display_run(display);
cleanup:
- if (sigint)
- wl_event_source_remove(sigint);
+ if (sigint)
+ wl_event_source_remove(sigint);
- if (tdm)
- pepper_drm_destroy(tdm);
+ if (tdm)
+ pepper_drm_destroy(tdm);
- if (input)
- pepper_libinput_destroy(input);
+ if (input)
+ pepper_libinput_destroy(input);
- if (udev)
- udev_unref(udev);
+ if (udev)
+ udev_unref(udev);
- if (compositor)
- pepper_compositor_destroy(compositor);
+ if (compositor)
+ pepper_compositor_destroy(compositor);
- return 0;
+ return 0;
}
int
main(int argc, char **argv)
{
- pepper_compositor_t *compositor;
- pepper_wayland_t *conn;
- pepper_output_t *output;
- struct wl_display *display;
+ pepper_compositor_t *compositor;
+ pepper_wayland_t *conn;
+ pepper_output_t *output;
+ struct wl_display *display;
- compositor = pepper_compositor_create("wayland-1");
- PEPPER_ASSERT(compositor);
+ compositor = pepper_compositor_create("wayland-1");
+ PEPPER_ASSERT(compositor);
- conn = pepper_wayland_connect(compositor, "wayland-0");
- PEPPER_ASSERT(conn);
+ conn = pepper_wayland_connect(compositor, "wayland-0");
+ PEPPER_ASSERT(conn);
- output = pepper_wayland_output_create(conn, 640, 480, "pixman");
- PEPPER_ASSERT(output);
+ output = pepper_wayland_output_create(conn, 640, 480, "pixman");
+ PEPPER_ASSERT(output);
- display = pepper_compositor_get_display(compositor);
- PEPPER_ASSERT(display);
+ display = pepper_compositor_get_display(compositor);
+ PEPPER_ASSERT(display);
- wl_display_run(display);
+ wl_display_run(display);
- return 0;
+ return 0;
}
static int
handle_sigint(int signal_number, void *data)
{
- struct wl_display *display = (struct wl_display *)data;
- wl_display_terminate(display);
+ struct wl_display *display = (struct wl_display *)data;
+ wl_display_terminate(display);
- return 0;
+ return 0;
}
int
main(int argc, char **argv)
{
- pepper_compositor_t *compositor;
- pepper_output_t *output;
- pepper_output_mode_t mode;
- pepper_x11_connection_t *conn;
- struct wl_event_loop *loop = NULL;
- struct wl_event_source *sigint = NULL;
- struct wl_display *display;
- const char *socket = NULL;
- const char *renderer;
+ pepper_compositor_t *compositor;
+ pepper_output_t *output;
+ pepper_output_mode_t mode;
+ pepper_x11_connection_t *conn;
+ struct wl_event_loop *loop = NULL;
+ struct wl_event_source *sigint = NULL;
+ struct wl_display *display;
+ const char *socket = NULL;
+ const char *renderer;
- if (argc > 1)
- socket = argv[1];
+ if (argc > 1)
+ socket = argv[1];
- if (argc > 2)
- renderer = argv[2];
+ if (argc > 2)
+ renderer = argv[2];
- compositor = pepper_compositor_create(socket);
- PEPPER_ASSERT(compositor);
+ compositor = pepper_compositor_create(socket);
+ PEPPER_ASSERT(compositor);
- conn = pepper_x11_connect(compositor, NULL);
- PEPPER_ASSERT(conn);
+ conn = pepper_x11_connect(compositor, NULL);
+ PEPPER_ASSERT(conn);
- output = pepper_x11_output_create(conn, 0, 0, 1024, 768,
- WL_OUTPUT_TRANSFORM_90, 1, renderer);
- PEPPER_ASSERT(output);
+ output = pepper_x11_output_create(conn, 0, 0, 1024, 768,
+ WL_OUTPUT_TRANSFORM_90, 1, renderer);
+ PEPPER_ASSERT(output);
- if (!pepper_x11_input_create(conn))
- PEPPER_ASSERT(0);
+ if (!pepper_x11_input_create(conn))
+ PEPPER_ASSERT(0);
- if (!pepper_desktop_shell_init(compositor))
- PEPPER_ASSERT(0);
+ if (!pepper_desktop_shell_init(compositor))
+ PEPPER_ASSERT(0);
- display = pepper_compositor_get_display(compositor);
- PEPPER_ASSERT(display);
+ display = pepper_compositor_get_display(compositor);
+ PEPPER_ASSERT(display);
- loop = wl_display_get_event_loop(display);
- sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
+ loop = wl_display_get_event_loop(display);
+ sigint = wl_event_loop_add_signal(loop, SIGINT, handle_sigint, display);
- wl_display_run(display);
+ wl_display_run(display);
- wl_event_source_remove(sigint);
- pepper_x11_destroy(conn);
- pepper_compositor_destroy(compositor);
+ wl_event_source_remove(sigint);
+ pepper_x11_destroy(conn);
+ pepper_compositor_destroy(compositor);
- return 0;
+ return 0;
}