From 98eb4d06ff64d76477a9538e25438c334ec239ec Mon Sep 17 00:00:00 2001 From: Christopher Michael Date: Thu, 26 Jan 2012 18:21:54 +0000 Subject: [PATCH] E Comp (wayland): Commit new code for comp module that renders wayland clients in e17 (x11). NB: This is an inital 'working' commit, tho there are still things on the todo for this, so don't expect it to "fully" work yet. SVN revision: 67553 --- src/modules/comp/Makefile.am | 4 +- src/modules/comp/e_mod_comp.c | 6 +- src/modules/comp/e_mod_comp_wl.c | 241 +++++-------- src/modules/comp/e_mod_comp_wl.h | 228 +++++-------- src/modules/comp/e_mod_comp_wl_buffer.c | 66 ++++ src/modules/comp/e_mod_comp_wl_buffer.h | 10 + src/modules/comp/e_mod_comp_wl_comp.c | 300 +--------------- src/modules/comp/e_mod_comp_wl_comp.h | 6 +- src/modules/comp/e_mod_comp_wl_input.c | 105 ++---- src/modules/comp/e_mod_comp_wl_input.h | 3 +- src/modules/comp/e_mod_comp_wl_output.c | 404 +--------------------- src/modules/comp/e_mod_comp_wl_output.h | 4 +- src/modules/comp/e_mod_comp_wl_shell.c | 415 ++++++----------------- src/modules/comp/e_mod_comp_wl_shell.h | 4 +- src/modules/comp/e_mod_comp_wl_shm.c | 49 ++- src/modules/comp/e_mod_comp_wl_shm.h | 5 +- src/modules/comp/e_mod_comp_wl_surface.c | 411 +++++----------------- src/modules/comp/e_mod_comp_wl_surface.h | 12 +- 18 files changed, 523 insertions(+), 1750 deletions(-) create mode 100644 src/modules/comp/e_mod_comp_wl_buffer.c create mode 100644 src/modules/comp/e_mod_comp_wl_buffer.h diff --git a/src/modules/comp/Makefile.am b/src/modules/comp/Makefile.am index 371c218d6..62dbe4c88 100644 --- a/src/modules/comp/Makefile.am +++ b/src/modules/comp/Makefile.am @@ -45,7 +45,9 @@ module_la_SOURCES += e_mod_comp_wl.h \ e_mod_comp_wl_shell.h \ e_mod_comp_wl_shell.c \ e_mod_comp_wl_surface.h \ - e_mod_comp_wl_surface.c + e_mod_comp_wl_surface.c \ + e_mod_comp_wl_buffer.h \ + e_mod_comp_wl_buffer.c endif module_la_LIBADD = @e_libs@ @dlopen_libs@ @WAYLAND_LIBS@ diff --git a/src/modules/comp/e_mod_comp.c b/src/modules/comp/e_mod_comp.c index d4a1f5c51..008d26e2d 100644 --- a/src/modules/comp/e_mod_comp.c +++ b/src/modules/comp/e_mod_comp.c @@ -513,7 +513,11 @@ _e_mod_comp_win_update(E_Comp_Win *cw) { Ecore_X_Pixmap pm; - pm = ecore_x_composite_name_window_pixmap_get(cw->win); +#ifdef HAVE_WAYLAND + pm = e_mod_comp_wl_pixmap_get(cw->win); +#endif + + if (!pm) pm = ecore_x_composite_name_window_pixmap_get(cw->win); if (pm) { Ecore_X_Pixmap oldpm; diff --git a/src/modules/comp/e_mod_comp_wl.c b/src/modules/comp/e_mod_comp_wl.c index 561566191..b97c04795 100644 --- a/src/modules/comp/e_mod_comp_wl.c +++ b/src/modules/comp/e_mod_comp_wl.c @@ -1,15 +1,14 @@ #include "e.h" #include "e_mod_main.h" -#include "e_mod_comp.h" #ifdef HAVE_WAYLAND +# include # include "e_mod_comp_wl.h" # include "e_mod_comp_wl_comp.h" +# include "e_mod_comp_wl_shm.h" # include "e_mod_comp_wl_output.h" # include "e_mod_comp_wl_input.h" # include "e_mod_comp_wl_shell.h" #endif -#include -#include /* local function prototypes */ static Eina_Bool _e_mod_comp_wl_fd_handle(void *data, Ecore_Fd_Handler *hdl __UNUSED__); @@ -31,29 +30,34 @@ e_mod_comp_wl_init(void) /* init wayland display */ if (!(_wl_disp = wl_display_create())) { - printf("Failed to create wayland display\n"); EINA_LOG_ERR("Failed to create wayland display\n"); return EINA_FALSE; } - /* TODO: Add signal handlers ? */ - - /* init wayland compositor */ + /* init a wayland compositor ?? */ if (!e_mod_comp_wl_comp_init()) { wl_display_terminate(_wl_disp); - printf("Failed to initialize compositor\n"); - EINA_LOG_ERR("Failed to initialize compositor\n"); + EINA_LOG_ERR("Failed to create wayland shm\n"); + return EINA_FALSE; + } + + /* init shm */ + if (!e_mod_comp_wl_shm_init()) + { + e_mod_comp_wl_comp_shutdown(); + wl_display_terminate(_wl_disp); + EINA_LOG_ERR("Failed to create wayland shm\n"); return EINA_FALSE; } /* init output */ - if (!e_mod_comp_wl_output_init()) + if (!e_mod_comp_wl_output_init()) { + e_mod_comp_wl_shm_shutdown(); e_mod_comp_wl_comp_shutdown(); wl_display_terminate(_wl_disp); - printf("Failed to initialize output\n"); - EINA_LOG_ERR("Failed to initialize output\n"); + EINA_LOG_ERR("Failed to create wayland output\n"); return EINA_FALSE; } @@ -61,24 +65,22 @@ e_mod_comp_wl_init(void) if (!e_mod_comp_wl_input_init()) { e_mod_comp_wl_output_shutdown(); + e_mod_comp_wl_shm_shutdown(); e_mod_comp_wl_comp_shutdown(); wl_display_terminate(_wl_disp); - printf("Failed to initialize input\n"); - EINA_LOG_ERR("Failed to initialize input\n"); + EINA_LOG_ERR("Failed to create wayland input\n"); return EINA_FALSE; } -// NB: x11 compositor adds X event source to wayland event loop - - /* init shell */ + /* init a wayland shell */ if (!e_mod_comp_wl_shell_init()) { e_mod_comp_wl_input_shutdown(); e_mod_comp_wl_output_shutdown(); + e_mod_comp_wl_shm_shutdown(); e_mod_comp_wl_comp_shutdown(); wl_display_terminate(_wl_disp); - printf("Failed to initialize shell\n"); - EINA_LOG_ERR("Failed to initialize shell\n"); + EINA_LOG_ERR("Failed to create wayland shell\n"); return EINA_FALSE; } @@ -87,10 +89,10 @@ e_mod_comp_wl_init(void) e_mod_comp_wl_shell_shutdown(); e_mod_comp_wl_input_shutdown(); e_mod_comp_wl_output_shutdown(); + e_mod_comp_wl_shm_shutdown(); e_mod_comp_wl_comp_shutdown(); wl_display_terminate(_wl_disp); - printf("Failed to add display socket\n"); - EINA_LOG_ERR("Failed to add display socket\n"); + EINA_LOG_ERR("Failed to add socket to wayland display\n"); return EINA_FALSE; } @@ -99,9 +101,7 @@ e_mod_comp_wl_init(void) _wl_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, - _e_mod_comp_wl_fd_handle, _wl_disp, NULL, NULL); - - e_mod_comp_wl_comp_wake(); + _e_mod_comp_wl_fd_handle, NULL, NULL, NULL); wl_event_loop_dispatch(loop, 0); @@ -113,11 +113,18 @@ e_mod_comp_wl_shutdown(void) { LOGFN(__FILE__, __LINE__, __FUNCTION__); + if (_wl_fd_handler) + ecore_main_fd_handler_del(_wl_fd_handler); + _wl_fd_handler = NULL; + e_mod_comp_wl_shell_shutdown(); e_mod_comp_wl_input_shutdown(); e_mod_comp_wl_output_shutdown(); + e_mod_comp_wl_shm_shutdown(); e_mod_comp_wl_comp_shutdown(); - wl_display_terminate(_wl_disp); + + if (_wl_disp) wl_display_terminate(_wl_disp); + _wl_disp = NULL; } uint32_t @@ -125,164 +132,70 @@ e_mod_comp_wl_time_get(void) { struct timeval tv; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - gettimeofday(&tv, NULL); return tv.tv_sec * 1000 + tv.tv_usec / 1000; } -void -e_mod_comp_wl_matrix_init(Wayland_Matrix *matrix) -{ - static const Wayland_Matrix identity = - { - { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } - }; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - memcpy(matrix, &identity, sizeof(identity)); -} - -void -e_mod_comp_wl_matrix_translate(Wayland_Matrix *matrix, GLfloat x, GLfloat y, GLfloat z) -{ - Wayland_Matrix translate = - { - { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 } - }; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - e_mod_comp_wl_matrix_multiply(matrix, &translate); -} - -void -e_mod_comp_wl_matrix_scale(Wayland_Matrix *matrix, GLfloat x, GLfloat y, GLfloat z) -{ - Wayland_Matrix scale = - { - { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 } - }; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - e_mod_comp_wl_matrix_multiply(matrix, &scale); -} - -void -e_mod_comp_wl_matrix_multiply(Wayland_Matrix *m, const Wayland_Matrix *n) -{ - Wayland_Matrix tmp; - const GLfloat *row, *column; - div_t d; - int i, j; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - for (i = 0; i < 16; i++) { - tmp.d[i] = 0; - d = div(i, 4); - row = m->d + d.quot * 4; - column = n->d + d.rem; - for (j = 0; j < 4; j++) - tmp.d[i] += row[j] * column[j * 4]; - } - memcpy(m, &tmp, sizeof tmp); -} - -void -e_mod_comp_wl_matrix_transform(Wayland_Matrix *matrix, Wayland_Vector *v) -{ - int i, j; - Wayland_Vector t; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - for (i = 0; i < 4; i++) - { - t.f[i] = 0; - for (j = 0; j < 4; j++) - t.f[i] += v->f[j] * matrix->d[i + j * 4]; - } - - *v = t; -} - -void -e_mod_comp_wl_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface) +Ecore_X_Pixmap +e_mod_comp_wl_pixmap_get(Ecore_X_Window win) { + Wayland_Compositor *comp; Wayland_Surface *ws; + struct wl_list *list; + Ecore_X_Pixmap pmap = 0; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - ws = (Wayland_Surface *)surface; - - if (ws->saved_texture != 0) - ws->texture = ws->saved_texture; - - glBindTexture(GL_TEXTURE_2D, ws->texture); - - if (wl_buffer_is_shm(buffer)) + comp = e_mod_comp_wl_comp_get(); + list = &comp->surfaces; + wl_list_for_each(ws, list, link) { - struct wl_list *attached; - - ws->pitch = wl_shm_buffer_get_stride(buffer) / 4; - glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, ws->pitch, buffer->height, - 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, - wl_shm_buffer_get_data(buffer)); - - switch (wl_shm_buffer_get_format(buffer)) + if ((ws->win) && (ws->win->border->win == win)) { - case WL_SHM_FORMAT_ARGB8888: - ws->visual = WAYLAND_ARGB_VISUAL; - break; - case WL_SHM_FORMAT_XRGB8888: - ws->visual = WAYLAND_RGB_VISUAL; - break; + if (ws->buffer) + { + Ecore_X_Connection *conn; + Ecore_X_GC gc; + uint8_t *pix; + int depth; + + depth = ecore_x_window_depth_get(win); + conn = ecore_x_connection_get(); + + pmap = xcb_generate_id(conn); + xcb_create_pixmap(conn, depth, pmap, win, ws->w, ws->h); + + if (wl_buffer_is_shm(ws->buffer)) + pix = (uint8_t *)wl_shm_buffer_get_data(ws->buffer); + else + { + /* FIXME: egl buffer ?? */ + printf("Wayland Buffer is NOT SHM !!\n"); + return 0; + } + + gc = ecore_x_gc_new(pmap, 0, NULL); + xcb_put_image(conn, 2, pmap, gc, ws->w, ws->h, + 0, 0, 0, depth, + (ws->w * ws->h * sizeof(int)), pix); + ecore_x_gc_free(gc); + } + else if (ws->image) + { + /* NB: No buffer means it may be an egl surface */ + printf("Get Pixmap Data from EGL Surface !!!\n"); + } } - - attached = buffer->user_data; - wl_list_remove(&ws->buffer_link); - wl_list_insert(attached, &ws->buffer_link); } - else - { - Wayland_Compositor *comp; - comp = e_mod_comp_wl_comp_get(); - if (ws->image != EGL_NO_IMAGE_KHR) - comp->destroy_image(comp->egl.display, ws->image); - ws->image = comp->create_image(comp->egl.display, NULL, - EGL_WAYLAND_BUFFER_WL, buffer, NULL); - comp->image_target_texture_2d(GL_TEXTURE_2D, ws->image); - ws->visual = WAYLAND_ARGB_VISUAL; - ws->pitch = ws->width; - } -} - -void -e_mod_comp_wl_buffer_post_release(struct wl_buffer *buffer) -{ - if (--buffer->busy_count > 0) return; - assert(buffer->resource.client != NULL); - wl_resource_queue_event(&buffer->resource, WL_BUFFER_RELEASE); + return pmap; } /* local functions */ static Eina_Bool -_e_mod_comp_wl_fd_handle(void *data, Ecore_Fd_Handler *hdl __UNUSED__) +_e_mod_comp_wl_fd_handle(void *data __UNUSED__, Ecore_Fd_Handler *hdl __UNUSED__) { - struct wl_display *disp; struct wl_event_loop *loop; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!(disp = data)) return ECORE_CALLBACK_RENEW; - if (disp != _wl_disp) return ECORE_CALLBACK_RENEW; - - loop = wl_display_get_event_loop(disp); + loop = wl_display_get_event_loop(_wl_disp); wl_event_loop_dispatch(loop, 0); - return ECORE_CALLBACK_RENEW; } diff --git a/src/modules/comp/e_mod_comp_wl.h b/src/modules/comp/e_mod_comp_wl.h index e5fa5cd13..afcf5732a 100644 --- a/src/modules/comp/e_mod_comp_wl.h +++ b/src/modules/comp/e_mod_comp_wl.h @@ -10,7 +10,7 @@ # include # include -//# define LOGFNS 1 +# define LOGFNS 1 # ifdef LOGFNS # include @@ -19,20 +19,23 @@ # define LOGFN(fl, ln, fn) # endif -typedef enum _Wayland_Shell_Surface_Type Wayland_Shell_Surface_Type; typedef enum _Wayland_Visual Wayland_Visual; -typedef struct _Wayland_Matrix Wayland_Matrix; -typedef struct _Wayland_Vector Wayland_Vector; -typedef struct _Wayland_Shader Wayland_Shader; -typedef struct _Wayland_Mode Wayland_Mode; -typedef struct _Wayland_Compositor Wayland_Compositor; -typedef struct _Wayland_Output Wayland_Output; +typedef enum _Wayland_Shell_Surface_Type Wayland_Shell_Surface_Type; typedef struct _Wayland_Frame_Callback Wayland_Frame_Callback; -typedef struct _Wayland_Transform Wayland_Transform; typedef struct _Wayland_Surface Wayland_Surface; -typedef struct _Wayland_Input Wayland_Input; -typedef struct _Wayland_Shell_Surface Wayland_Shell_Surface; typedef struct _Wayland_Shell Wayland_Shell; +typedef struct _Wayland_Shell_Surface Wayland_Shell_Surface; +typedef struct _Wayland_Compositor Wayland_Compositor; +typedef struct _Wayland_Mode Wayland_Mode; +typedef struct _Wayland_Output Wayland_Output; +typedef struct _Wayland_Input Wayland_Input; + +enum _Wayland_Visual +{ + WAYLAND_NONE_VISUAL, + WAYLAND_ARGB_VISUAL, + WAYLAND_RGB_VISUAL +}; enum _Wayland_Shell_Surface_Type { @@ -47,143 +50,31 @@ enum _Wayland_Shell_Surface_Type SHELL_SURFACE_POPUP }; -enum _Wayland_Visual -{ - WAYLAND_NONE_VISUAL, - WAYLAND_ARGB_VISUAL, - WAYLAND_RGB_VISUAL -}; - -struct _Wayland_Matrix -{ - GLfloat d[16]; -}; - -struct _Wayland_Vector -{ - GLfloat f[4]; -}; - -struct _Wayland_Shader -{ - GLuint program; - GLuint vertex_shader; - GLuint fragment_shader; - GLuint proj_uniform; - GLuint tex_uniform; - GLuint alpha_uniform; - GLuint color_uniform; -}; - -struct _Wayland_Mode -{ - uint32_t flags, refresh; - int32_t width, height; - struct wl_list link; -}; - -struct _Wayland_Compositor -{ - struct wl_shm *shm; - - struct - { - EGLDisplay display; - EGLContext context; - EGLConfig config; - } egl; - - Wayland_Shader texture_shader; - Wayland_Shader solid_shader; - - struct wl_array vertices, indices; - struct wl_list surfaces; - - struct wl_event_source *idle_source; - - PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC - image_target_renderbuffer_storage; - PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d; - PFNEGLCREATEIMAGEKHRPROC create_image; - PFNEGLDESTROYIMAGEKHRPROC destroy_image; - PFNEGLBINDWAYLANDDISPLAYWL bind_display; - PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display; - Eina_Bool has_bind : 1; - - uint32_t current_alpha; - - void (*destroy) (void); -}; - -struct _Wayland_Output -{ - int x, y, width, height; - char *make, *model; - uint32_t subpixel, flags; - - EGLSurface egl_surface; - - Wayland_Mode mode; - Wayland_Matrix matrix; - - Eina_Bool repaint_needed : 1; - Eina_Bool repaint_scheduled : 1; - - struct wl_event_source *finish_frame_timer; - - struct wl_list link; - struct wl_list frame_callbacks; - - pixman_region32_t region, prev_damage; - - struct wl_buffer *scanout_buffer; - struct wl_listener scanout_buffer_destroy_listener; - struct wl_buffer *pending_scanout_buffer; - struct wl_listener pending_scanout_buffer_destroy_listener; - - int (*prepare_render) (Wayland_Output *output); - int (*present) (Wayland_Output *output); - int (*prepare_scanout_surface) (Wayland_Output *output, Wayland_Surface *ws); -}; - struct _Wayland_Frame_Callback { struct wl_resource resource; struct wl_list link; }; -struct _Wayland_Transform -{ - Wayland_Matrix matrix, inverse; -}; - struct _Wayland_Surface { struct wl_surface surface; - GLuint texture, saved_texture; - pixman_region32_t damage, opaque; - int32_t x, y, width, height; - int32_t pitch; + struct wl_buffer *buffer; + struct wl_list link; + struct wl_list buffer_link; + struct wl_listener buffer_destroy_listener; + struct wl_list frame_callbacks; - Wayland_Transform *transform; - uint32_t visual, alpha; + pixman_region32_t damage, opaque; + GLuint texture, saved_texture; + + int32_t x, y, w, h; + uint32_t visual, pitch; EGLImageKHR image; - struct wl_list link; - struct wl_list buffer_link; - struct wl_list frame_callbacks; - - struct wl_buffer *buffer; - struct wl_listener buffer_destroy_listener; -}; - -struct _Wayland_Input -{ - struct wl_input_device input_device; - Wayland_Surface *sprite; - int32_t hotspot_x, hotspot_y; - struct wl_list link; + E_Win *win; + Ecore_X_Window input_win; }; struct _Wayland_Shell @@ -195,24 +86,70 @@ struct _Wayland_Shell void (*destroy) (Wayland_Shell *shell); }; -struct _Wayland_Shell_Surface +struct _Wayland_Shell_Surface { struct wl_resource resource; Wayland_Surface *surface; struct wl_listener surface_destroy_listener; Wayland_Shell_Surface *parent; - Wayland_Shell_Surface_Type type; - + struct wl_list link; int32_t saved_x, saved_y; + Wayland_Shell_Surface_Type type; struct { struct wl_grab grab; - uint32_t timestmap; + uint32_t timestamp; int32_t x, y; - int32_t initial_up; } popup; +}; +struct _Wayland_Compositor +{ + struct wl_list surfaces; + + struct + { + EGLDisplay display; + EGLContext context; + EGLConfig config; + } egl; + + PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC + image_target_renderbuffer_storage; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d; + PFNEGLCREATEIMAGEKHRPROC create_image; + PFNEGLDESTROYIMAGEKHRPROC destroy_image; + PFNEGLBINDWAYLANDDISPLAYWL bind_display; + PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display; + Eina_Bool has_bind : 1; + + void (*destroy) (void); +}; + +struct _Wayland_Mode +{ + uint32_t flags, refresh; + int32_t w, h; + struct wl_list link; +}; + +struct _Wayland_Output +{ + int32_t x, y, w, h; + char *make, *model; + uint32_t subpixel, flags; + + Wayland_Mode mode; + + struct wl_list link; + struct wl_list frame_callbacks; +}; + +struct _Wayland_Input +{ + struct wl_input_device input_device; + int32_t hotspot_x, hotspot_y; struct wl_list link; }; @@ -223,7 +160,7 @@ struct wl_shell Eina_Bool locked : 1; Eina_Bool prepare_event_sent : 1; - Wayland_Shell_Surface *lock_surface; +// Wayland_Shell_Surface *lock_surface; struct wl_listener lock_surface_listener; struct wl_list hidden_surfaces; @@ -237,14 +174,7 @@ struct wl_shell Eina_Bool e_mod_comp_wl_init(void); void e_mod_comp_wl_shutdown(void); uint32_t e_mod_comp_wl_time_get(void); - -void e_mod_comp_wl_matrix_init(Wayland_Matrix *matrix); -void e_mod_comp_wl_matrix_translate(Wayland_Matrix *matrix, GLfloat x, GLfloat y, GLfloat z); -void e_mod_comp_wl_matrix_scale(Wayland_Matrix *matrix, GLfloat x, GLfloat y, GLfloat z); -void e_mod_comp_wl_matrix_multiply(Wayland_Matrix *m, const Wayland_Matrix *n); -void e_mod_comp_wl_matrix_transform(Wayland_Matrix *matrix, Wayland_Vector *v); -void e_mod_comp_wl_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface); -void e_mod_comp_wl_buffer_post_release(struct wl_buffer *buffer); +Ecore_X_Pixmap e_mod_comp_wl_pixmap_get(Ecore_X_Window win); extern struct wl_display *_wl_disp; diff --git a/src/modules/comp/e_mod_comp_wl_buffer.c b/src/modules/comp/e_mod_comp_wl_buffer.c new file mode 100644 index 000000000..ca1780adb --- /dev/null +++ b/src/modules/comp/e_mod_comp_wl_buffer.c @@ -0,0 +1,66 @@ +#include "e.h" +#include "e_mod_main.h" +#include "e_mod_comp.h" +#ifdef HAVE_WAYLAND +# include "e_mod_comp_wl.h" +# include "e_mod_comp_wl_buffer.h" +# include "e_mod_comp_wl_comp.h" +#endif + +void +e_mod_comp_wl_buffer_post_release(struct wl_buffer *buffer) +{ + if (--buffer->busy_count > 0) return; + if (buffer->resource.client) + wl_resource_queue_event(&buffer->resource, WL_BUFFER_RELEASE); +} + +void +e_mod_comp_wl_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface) +{ + Wayland_Surface *ws; + + LOGFN(__FILE__, __LINE__, __FUNCTION__); + + ws = (Wayland_Surface *)surface; + + if (ws->saved_texture != 0) + ws->texture = ws->saved_texture; + + glBindTexture(GL_TEXTURE_2D, ws->texture); + + if (wl_buffer_is_shm(buffer)) + { + struct wl_list *attached; + + ws->pitch = wl_shm_buffer_get_stride(buffer) / 4; + glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, ws->pitch, buffer->height, + 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, + wl_shm_buffer_get_data(buffer)); + switch (wl_shm_buffer_get_format(buffer)) + { + case WL_SHM_FORMAT_ARGB8888: + ws->visual = WAYLAND_ARGB_VISUAL; + break; + case WL_SHM_FORMAT_XRGB8888: + ws->visual = WAYLAND_RGB_VISUAL; + break; + } + attached = buffer->user_data; + wl_list_remove(&ws->buffer_link); + wl_list_insert(attached, &ws->buffer_link); + } + else + { + Wayland_Compositor *comp; + + comp = e_mod_comp_wl_comp_get(); + if (ws->image != EGL_NO_IMAGE_KHR) + comp->destroy_image(comp->egl.display, ws->image); + ws->image = comp->create_image(comp->egl.display, NULL, + EGL_WAYLAND_BUFFER_WL, buffer, NULL); + comp->image_target_texture_2d(GL_TEXTURE_2D, ws->image); + ws->visual = WAYLAND_ARGB_VISUAL; + ws->pitch = ws->w; + } +} diff --git a/src/modules/comp/e_mod_comp_wl_buffer.h b/src/modules/comp/e_mod_comp_wl_buffer.h new file mode 100644 index 000000000..ed57a136f --- /dev/null +++ b/src/modules/comp/e_mod_comp_wl_buffer.h @@ -0,0 +1,10 @@ +#ifdef E_TYPEDEFS +#else +# ifndef E_MOD_COMP_WL_BUFFER_H +# define E_MOD_COMP_WL_BUFFER_H + +void e_mod_comp_wl_buffer_post_release(struct wl_buffer *buffer); +void e_mod_comp_wl_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface); + +# endif +#endif diff --git a/src/modules/comp/e_mod_comp_wl_comp.c b/src/modules/comp/e_mod_comp_wl_comp.c index b80365625..55e59b5d5 100644 --- a/src/modules/comp/e_mod_comp_wl_comp.c +++ b/src/modules/comp/e_mod_comp_wl_comp.c @@ -4,36 +4,21 @@ # include "e_mod_comp_wl.h" # include "e_mod_comp_wl_comp.h" # include "e_mod_comp_wl_shm.h" -# include "e_mod_comp_wl_input.h" -# include "e_mod_comp_wl_output.h" # include "e_mod_comp_wl_surface.h" #endif /* local function prototypes */ static Eina_Bool _e_mod_comp_wl_comp_egl_init(void); static void _e_mod_comp_wl_comp_egl_shutdown(void); -static Eina_Bool _e_mod_comp_wl_comp_shader_init(Wayland_Shader *shader, const char *vertex_source, const char *fragment_source); -/* static void _e_mod_comp_wl_comp_shader_shutdown(void); */ -static Eina_Bool _e_mod_comp_wl_comp_solid_shader_init(Wayland_Shader *shader, GLuint vertex_shader, const char *fragment_source); -/* static void _e_mod_comp_wl_comp_solid_shader_shutdown(); */ -static int _e_mod_comp_wl_comp_compile_shader(GLenum type, const char *source); static void _e_mod_comp_wl_comp_destroy(void); static void _e_mod_comp_wl_comp_bind(struct wl_client *client, void *data, uint32_t version __UNUSED__, uint32_t id); static void _e_mod_comp_wl_comp_surface_create(struct wl_client *client, struct wl_resource *resource, uint32_t id); -static int _e_mod_comp_wl_comp_idle_handler(void *data); /* wayland interfaces */ static const struct wl_compositor_interface _wl_comp_interface = { _e_mod_comp_wl_comp_surface_create }; - -static const struct wl_shm_callbacks _wl_shm_callbacks = -{ - e_mod_comp_wl_shm_buffer_created, - e_mod_comp_wl_shm_buffer_damaged, - e_mod_comp_wl_shm_buffer_destroyed -}; static const struct wl_surface_interface _wl_surface_interface = { e_mod_comp_wl_surface_destroy, @@ -44,47 +29,11 @@ static const struct wl_surface_interface _wl_surface_interface = /* private variables */ static Wayland_Compositor *_wl_comp; -static const char vertex_shader[] = -{ - "uniform mat4 proj;\n" - "attribute vec2 position;\n" - "attribute vec2 texcoord;\n" - "varying vec2 v_texcoord;\n" - "void main()\n" - "{\n" - " gl_Position = proj * vec4(position, 0.0, 1.0);\n" - " v_texcoord = texcoord;\n" - "}\n" -}; - -static const char texture_fragment_shader[] = -{ - "precision mediump float;\n" - "varying vec2 v_texcoord;\n" - "uniform sampler2D tex;\n" - "uniform float alpha;\n" - "void main()\n" - "{\n" - " gl_FragColor = texture2D(tex, v_texcoord)\n;" - " gl_FragColor = alpha * gl_FragColor;\n" - "}\n" -}; - -static const char solid_fragment_shader[] = -{ - "precision mediump float;\n" - "uniform vec4 color;\n" - "void main()\n" - "{\n" - " gl_FragColor = color\n;" - "}\n" -}; Eina_Bool e_mod_comp_wl_comp_init(void) { const char *extensions; - struct wl_event_loop *loop; LOGFN(__FILE__, __LINE__, __FUNCTION__); @@ -96,19 +45,15 @@ e_mod_comp_wl_comp_init(void) memset(_wl_comp, 0, sizeof(*_wl_comp)); -// open display, get X connection, create cursor - if (!_e_mod_comp_wl_comp_egl_init()) { - EINA_LOG_ERR("Failed to init EGL\n"); + EINA_LOG_ERR("Could not initialize egl\n"); free(_wl_comp); return EINA_FALSE; } _wl_comp->destroy = _e_mod_comp_wl_comp_destroy; -// weston_compositor_init - if (!wl_display_add_global(_wl_disp, &wl_compositor_interface, _wl_comp, _e_mod_comp_wl_comp_bind)) { @@ -117,8 +62,6 @@ e_mod_comp_wl_comp_init(void) return EINA_FALSE; } - _wl_comp->shm = wl_shm_init(_wl_disp, &_wl_shm_callbacks); - _wl_comp->image_target_texture_2d = (void *)eglGetProcAddress("glEGLImageTargetTexture2DOES"); _wl_comp->image_target_renderbuffer_storage = (void *) @@ -146,119 +89,27 @@ e_mod_comp_wl_comp_init(void) if (_wl_comp->has_bind) _wl_comp->bind_display(_wl_comp->egl.display, _wl_disp); - wl_list_init(&_wl_comp->surfaces); - -// spring init -// screenshooter init - wl_data_device_manager_init(_wl_disp); - glActiveTexture(GL_TEXTURE0); - - /* init shader */ - if (!_e_mod_comp_wl_comp_shader_init(&_wl_comp->texture_shader, - vertex_shader, texture_fragment_shader)) - { - EINA_LOG_ERR("Failed to initialize texture shader\n"); - free(_wl_comp); - return EINA_FALSE; - } - - /* init solid shader */ - if (!_e_mod_comp_wl_comp_solid_shader_init(&_wl_comp->solid_shader, - _wl_comp->texture_shader.vertex_shader, - solid_fragment_shader)) - { - EINA_LOG_ERR("Failed to initialize solid shader\n"); - free(_wl_comp); - return EINA_FALSE; - } - - loop = wl_display_get_event_loop(_wl_disp); - _wl_comp->idle_source = - wl_event_loop_add_timer(loop, _e_mod_comp_wl_comp_idle_handler, _wl_comp); - wl_event_source_timer_update(_wl_comp->idle_source, 300 * 1000); - - e_mod_comp_wl_comp_schedule_repaint(); + wl_list_init(&_wl_comp->surfaces); return EINA_TRUE; } -Eina_Bool +void e_mod_comp_wl_comp_shutdown(void) { LOGFN(__FILE__, __LINE__, __FUNCTION__); - if (!_wl_comp) return EINA_TRUE; - if (_wl_comp->destroy) _wl_comp->destroy(); - return EINA_TRUE; + if (_wl_comp) _wl_comp->destroy(); } Wayland_Compositor * e_mod_comp_wl_comp_get(void) { - LOGFN(__FILE__, __LINE__, __FUNCTION__); - return _wl_comp; } -void -e_mod_comp_wl_comp_repick(void) -{ - Wayland_Input *device; - uint32_t timestamp; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - device = e_mod_comp_wl_input_get(); - timestamp = e_mod_comp_wl_time_get(); - e_mod_comp_wl_input_repick(&device->input_device, timestamp); -} - -Wayland_Surface * -e_mod_comp_wl_comp_surface_pick(int32_t x, int32_t y, int32_t *sx, int32_t *sy) -{ - Wayland_Surface *surface; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - wl_list_for_each(surface, &_wl_comp->surfaces, link) - { - if (!surface->surface.resource.client) continue; - e_mod_comp_wl_surface_transform(surface, x, y, sx, sy); - if ((0 <= *sx) && (*sx < surface->width) && - (0 <= *sy) && (*sy < surface->height)) - return surface; - } - - return NULL; -} - -void -e_mod_comp_wl_comp_schedule_repaint(void) -{ - Wayland_Output *output; - struct wl_event_loop *loop; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!(output = e_mod_comp_wl_output_get())) return; - loop = wl_display_get_event_loop(_wl_disp); - output->repaint_needed = EINA_TRUE; - if (output->repaint_scheduled) return; - wl_event_loop_add_idle(loop, e_mod_comp_wl_output_idle_repaint, output); - output->repaint_scheduled = EINA_TRUE; -} - -void -e_mod_comp_wl_comp_wake(void) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - wl_event_source_timer_update(_wl_comp->idle_source, - 300 * 1000); -} - /* local functions */ static Eina_Bool _e_mod_comp_wl_comp_egl_init(void) @@ -346,109 +197,6 @@ _e_mod_comp_wl_comp_egl_shutdown(void) eglReleaseThread(); } -static Eina_Bool -_e_mod_comp_wl_comp_shader_init(Wayland_Shader *shader, const char *vertex_source, const char *fragment_source) -{ - GLint status; - char msg[512]; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - shader->vertex_shader = - _e_mod_comp_wl_comp_compile_shader(GL_VERTEX_SHADER, vertex_source); - shader->fragment_shader = - _e_mod_comp_wl_comp_compile_shader(GL_FRAGMENT_SHADER, fragment_source); - - 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); - EINA_LOG_ERR("Link info: %s\n", msg); - return EINA_FALSE; - } - - shader->proj_uniform = glGetUniformLocation(shader->program, "proj"); - shader->tex_uniform = glGetUniformLocation(shader->program, "tex"); - shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha"); - - return EINA_TRUE; -} - -/* static void */ -/* _e_mod_comp_wl_comp_shader_shutdown(void) */ -/* { */ - -/* } */ - -static Eina_Bool -_e_mod_comp_wl_comp_solid_shader_init(Wayland_Shader *shader, GLuint vertex_shader, const char *fragment_source) -{ - GLint status; - char msg[512]; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - shader->vertex_shader = vertex_shader; - shader->fragment_shader = - _e_mod_comp_wl_comp_compile_shader(GL_FRAGMENT_SHADER, fragment_source); - - 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); - EINA_LOG_ERR("Link info: %s\n", msg); - return EINA_FALSE; - } - - shader->proj_uniform = glGetUniformLocation(shader->program, "proj"); - shader->color_uniform = glGetUniformLocation(shader->program, "color"); - - return EINA_TRUE; -} - -/* static void */ -/* _e_mod_comp_wl_comp_solid_shader_shutdown() */ -/* { */ - -/* } */ - -static int -_e_mod_comp_wl_comp_compile_shader(GLenum type, const char *source) -{ - GLuint s; - GLint status; - char msg[512]; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - s = glCreateShader(type); - glShaderSource(s, 1, &source, NULL); - glCompileShader(s); - glGetShaderiv(s, GL_COMPILE_STATUS, &status); - if (!status) - { - glGetShaderInfoLog(s, sizeof(msg), NULL, msg); - EINA_LOG_ERR("shader info: %s\n", msg); - return GL_NONE; - } - - return s; -} - static void _e_mod_comp_wl_comp_destroy(void) { @@ -457,15 +205,9 @@ _e_mod_comp_wl_comp_destroy(void) if (_wl_comp->has_bind) _wl_comp->unbind_display(_wl_comp->egl.display, _wl_disp); - if (_wl_comp->idle_source) wl_event_source_remove(_wl_comp->idle_source); - - wl_shm_finish(_wl_comp->shm); - - wl_array_release(&_wl_comp->vertices); - wl_array_release(&_wl_comp->indices); - _e_mod_comp_wl_comp_egl_shutdown(); + if (&_wl_comp->surfaces) wl_list_remove(&_wl_comp->surfaces); free(_wl_comp); } @@ -481,38 +223,22 @@ _e_mod_comp_wl_comp_bind(struct wl_client *client, void *data, uint32_t version static void _e_mod_comp_wl_comp_surface_create(struct wl_client *client, struct wl_resource *resource, uint32_t id) { - Wayland_Surface *surface; + Wayland_Surface *ws; LOGFN(__FILE__, __LINE__, __FUNCTION__); - if (!(surface = e_mod_comp_wl_surface_create(0, 0, 0, 0))) + if (!(ws = e_mod_comp_wl_surface_create(0, 0, 0, 0))) { wl_resource_post_no_memory(resource); return; } - surface->surface.resource.destroy = e_mod_comp_wl_surface_destroy_surface; - surface->surface.resource.object.id = id; - surface->surface.resource.object.interface = &wl_surface_interface; - surface->surface.resource.object.implementation = + ws->surface.resource.destroy = e_mod_comp_wl_surface_destroy_surface; + ws->surface.resource.object.id = id; + ws->surface.resource.object.interface = &wl_surface_interface; + ws->surface.resource.object.implementation = (void (**)(void))&_wl_surface_interface; - surface->surface.resource.data = surface; + ws->surface.resource.data = ws; - wl_client_add_resource(client, &surface->surface.resource); -} - -static int -_e_mod_comp_wl_comp_idle_handler(void *data) -{ - Wayland_Compositor *wc; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!(wc = data)) return 1; - - /* TODO: Check idle inhibit */ - - /* TODO: fade */ - - return 1; + wl_client_add_resource(client, &ws->surface.resource); } diff --git a/src/modules/comp/e_mod_comp_wl_comp.h b/src/modules/comp/e_mod_comp_wl_comp.h index f040007d1..273e2d36d 100644 --- a/src/modules/comp/e_mod_comp_wl_comp.h +++ b/src/modules/comp/e_mod_comp_wl_comp.h @@ -4,12 +4,8 @@ # define E_MOD_COMP_WL_COMP_H Eina_Bool e_mod_comp_wl_comp_init(void); -Eina_Bool e_mod_comp_wl_comp_shutdown(void); +void e_mod_comp_wl_comp_shutdown(void); Wayland_Compositor *e_mod_comp_wl_comp_get(void); -void e_mod_comp_wl_comp_repick(void); -Wayland_Surface *e_mod_comp_wl_comp_surface_pick(int32_t x, int32_t y, int32_t *sx, int32_t *sy); -void e_mod_comp_wl_comp_schedule_repaint(void); -void e_mod_comp_wl_comp_wake(void); # endif #endif diff --git a/src/modules/comp/e_mod_comp_wl_input.c b/src/modules/comp/e_mod_comp_wl_input.c index 6ff673403..ffae4ffbb 100644 --- a/src/modules/comp/e_mod_comp_wl_input.c +++ b/src/modules/comp/e_mod_comp_wl_input.c @@ -2,15 +2,13 @@ #include "e_mod_main.h" #ifdef HAVE_WAYLAND # include "e_mod_comp_wl.h" -# include "e_mod_comp_wl_comp.h" # include "e_mod_comp_wl_input.h" -# include "e_mod_comp_wl_surface.h" #endif /* local function prototypes */ static void _e_mod_comp_wl_input_bind(struct wl_client *client, void *data, uint32_t version __UNUSED__, uint32_t id); static void _e_mod_comp_wl_input_unbind(struct wl_resource *resource); -static void _e_mod_comp_wl_input_attach(struct wl_client *client, struct wl_resource *resource, uint32_t timestamp, struct wl_resource *buffer_resource, int32_t x, int32_t y); +static void _e_mod_comp_wl_input_attach(struct wl_client *client, struct wl_resource *resource, uint32_t timestamp, struct wl_resource *buffer_resource __UNUSED__, int32_t x, int32_t y); /* wayland interfaces */ static const struct wl_input_device_interface _wl_input_interface = @@ -26,7 +24,7 @@ e_mod_comp_wl_input_init(void) { LOGFN(__FILE__, __LINE__, __FUNCTION__); - if (!(_wl_input = malloc(sizeof(Wayland_Input)))) + if (!(_wl_input = malloc(sizeof(Wayland_Input)))) { EINA_LOG_ERR("Could not allocate space for input\n"); return EINA_FALSE; @@ -35,67 +33,36 @@ e_mod_comp_wl_input_init(void) memset(_wl_input, 0, sizeof(*_wl_input)); wl_input_device_init(&_wl_input->input_device); - wl_display_add_global(_wl_disp, &wl_input_device_interface, _wl_input, - _e_mod_comp_wl_input_bind); + if (!wl_display_add_global(_wl_disp, &wl_input_device_interface, _wl_input, + _e_mod_comp_wl_input_bind)) + { + EINA_LOG_ERR("Failed to add input to wayland\n"); + free(_wl_input); + return EINA_FALSE; + } - _wl_input->sprite = NULL; _wl_input->hotspot_x = 16; _wl_input->hotspot_y = 16; return EINA_TRUE; } -Eina_Bool +void e_mod_comp_wl_input_shutdown(void) { LOGFN(__FILE__, __LINE__, __FUNCTION__); - if (!_wl_input) return EINA_TRUE; - - if (_wl_input->sprite) - e_mod_comp_wl_surface_destroy_surface(&_wl_input->sprite->surface.resource); - + if (!_wl_input) return; wl_input_device_release(&_wl_input->input_device); - free(_wl_input); - return EINA_TRUE; } Wayland_Input * e_mod_comp_wl_input_get(void) { - LOGFN(__FILE__, __LINE__, __FUNCTION__); - return _wl_input; } -void -e_mod_comp_wl_input_repick(struct wl_input_device *device, uint32_t timestamp) -{ - const struct wl_grab_interface *interface; - Wayland_Surface *surface, *focus; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - surface = - e_mod_comp_wl_comp_surface_pick(device->x, device->y, - &device->current_x, &device->current_y); - - if (&surface->surface != device->current) - { - interface = device->grab->interface; - interface->focus(device->grab, timestamp, &surface->surface, - device->current_x, device->current_y); - device->current = &surface->surface; - } - - if ((focus = (Wayland_Surface *)device->grab->focus)) - { - e_mod_comp_wl_surface_transform(focus, device->x, device->y, - &device->grab->x, &device->grab->y); - } -} - /* local functions */ static void _e_mod_comp_wl_input_bind(struct wl_client *client, void *data, uint32_t version __UNUSED__, uint32_t id) @@ -123,50 +90,16 @@ _e_mod_comp_wl_input_unbind(struct wl_resource *resource) } static void -_e_mod_comp_wl_input_attach(struct wl_client *client, struct wl_resource *resource, uint32_t timestamp, struct wl_resource *buffer_resource, int32_t x, int32_t y) +_e_mod_comp_wl_input_attach(struct wl_client *client, struct wl_resource *resource, uint32_t timestamp, struct wl_resource *buffer_resource __UNUSED__, int32_t x, int32_t y) { - Wayland_Input *device; - struct wl_buffer *buffer; + Wayland_Input *wi; LOGFN(__FILE__, __LINE__, __FUNCTION__); - device = resource->data; - if (timestamp < device->input_device.pointer_focus_time) return; - if (!device->input_device.pointer_focus) return; - if (device->input_device.pointer_focus->resource.client != client) - return; - - if (device->sprite) - e_mod_comp_wl_surface_damage_below(device->sprite); - - if (!buffer_resource) - { - if (device->sprite) - { - e_mod_comp_wl_surface_destroy_surface(&device->sprite->surface.resource); - device->sprite = NULL; - } - return; - } - - if (!device->sprite) - { - device->sprite = - e_mod_comp_wl_surface_create(device->input_device.x, - device->input_device.y, 32, 32); - wl_list_init(&device->sprite->link); - } - - buffer = buffer_resource->data; - - e_mod_comp_wl_buffer_attach(buffer, &device->sprite->surface); - - device->hotspot_x = x; - device->hotspot_y = y; - device->sprite->width = buffer->width; - device->sprite->height = buffer->height; - device->sprite->x = device->input_device.x - device->hotspot_x; - device->sprite->y = device->input_device.y - device->hotspot_y; - - e_mod_comp_wl_surface_damage_surface(device->sprite); + wi = resource->data; + if (timestamp < wi->input_device.pointer_focus_time) return; + if (!wi->input_device.pointer_focus) return; + if (wi->input_device.pointer_focus->resource.client != client) return; + wi->hotspot_x = x; + wi->hotspot_y = y; } diff --git a/src/modules/comp/e_mod_comp_wl_input.h b/src/modules/comp/e_mod_comp_wl_input.h index 29bd8cd15..7db777af8 100644 --- a/src/modules/comp/e_mod_comp_wl_input.h +++ b/src/modules/comp/e_mod_comp_wl_input.h @@ -4,9 +4,8 @@ # define E_MOD_COMP_WL_INPUT_H Eina_Bool e_mod_comp_wl_input_init(void); -Eina_Bool e_mod_comp_wl_input_shutdown(void); +void e_mod_comp_wl_input_shutdown(void); Wayland_Input *e_mod_comp_wl_input_get(void); -void e_mod_comp_wl_input_repick(struct wl_input_device *device, uint32_t timestamp); # endif #endif diff --git a/src/modules/comp/e_mod_comp_wl_output.c b/src/modules/comp/e_mod_comp_wl_output.c index 6812d98ae..7c0f2ddc9 100644 --- a/src/modules/comp/e_mod_comp_wl_output.c +++ b/src/modules/comp/e_mod_comp_wl_output.c @@ -2,25 +2,13 @@ #include "e_mod_main.h" #ifdef HAVE_WAYLAND # include "e_mod_comp_wl.h" -# include "e_mod_comp_wl_comp.h" # include "e_mod_comp_wl_output.h" -# include "e_mod_comp_wl_surface.h" #endif # define WL_OUTPUT_FLIPPED 0x01 /* local function prototypes */ static void _e_mod_comp_wl_output_bind(struct wl_client *client, void *data, uint32_t version __UNUSED__, uint32_t id); -static void _e_mod_comp_wl_output_scanout_buffer_destroy(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp __UNUSED__); -static void _e_mod_comp_wl_output_pending_scanout_buffer_destroy(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp __UNUSED__); -static int _e_mod_comp_wl_output_finish_frame_handler(void *data); -static void _e_mod_comp_wl_output_finish_frame(Wayland_Output *output, int secs); -static void _e_mod_comp_wl_output_repaint(Wayland_Output *output, int secs); -static Eina_Bool _e_mod_comp_wl_output_setup_scanout_surface(Wayland_Output *output, Wayland_Surface *ws); -static int _e_mod_comp_wl_output_prepare_render(Wayland_Output *output); -static int _e_mod_comp_wl_output_present(Wayland_Output *output); -static int _e_mod_comp_wl_output_prepare_scanout_surface(Wayland_Output *output __UNUSED__, Wayland_Surface *surface __UNUSED__); -static void _e_mod_comp_wl_output_move(Wayland_Output *output, int32_t x, int32_t y); /* private variables */ static Wayland_Output *_wl_output; @@ -28,20 +16,19 @@ static Wayland_Output *_wl_output; Eina_Bool e_mod_comp_wl_output_init(void) { - Wayland_Compositor *comp; - struct wl_event_loop *loop; Ecore_X_Window *roots; int num = 0, rw, rh; LOGFN(__FILE__, __LINE__, __FUNCTION__); roots = ecore_x_window_root_list(&num); - if ((!roots) || (num <= 0)) + if ((!roots) || (num <= 0)) { EINA_LOG_ERR("Could not get root window list\n"); return EINA_FALSE; } ecore_x_window_size_get(roots[0], &rw, &rh); + free(roots); if (!(_wl_output = malloc(sizeof(Wayland_Output)))) { @@ -53,152 +40,47 @@ e_mod_comp_wl_output_init(void) _wl_output->mode.flags = (WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED); - - _wl_output->mode.width = rw; - _wl_output->mode.height = rh; + _wl_output->mode.w = rw; + _wl_output->mode.h = rh; _wl_output->mode.refresh = 60; -// weston output init - _wl_output->x = 0; _wl_output->y = 0; - _wl_output->width = rw; - _wl_output->height = rh; + _wl_output->w = rw; + _wl_output->h = rh; _wl_output->flags = WL_OUTPUT_FLIPPED; - _e_mod_comp_wl_output_move(_wl_output, 0, 0); - - _wl_output->scanout_buffer_destroy_listener.func = - _e_mod_comp_wl_output_scanout_buffer_destroy; - _wl_output->pending_scanout_buffer_destroy_listener.func = - _e_mod_comp_wl_output_pending_scanout_buffer_destroy; - wl_list_init(&_wl_output->link); wl_list_init(&_wl_output->frame_callbacks); if (!wl_display_add_global(_wl_disp, &wl_output_interface, _wl_output, _e_mod_comp_wl_output_bind)) { - EINA_LOG_ERR("Failed to add wayland output\n"); + EINA_LOG_ERR("Failed to add output to wayland\n"); free(_wl_output); return EINA_FALSE; } -// NB: compositor-x11 has create output window - - comp = e_mod_comp_wl_comp_get(); - - /* NB: Fix me !! This is why wayland clients are not displaying. */ - /* The default wayland compositor creates it's egl surface against an - * 'output' window. Their output window is created with root window as - * the parent. This does not work in E17 due to the way E is handling - * backgrounds. Currently, wayland clients are getting created, but they - * do not display...or rather, they display below the E17 background. - * The fix here would be to use something other than roots[0] as the - * 'parent' of the output surface */ - _wl_output->egl_surface = - eglCreateWindowSurface(comp->egl.display, comp->egl.config, - roots[0], NULL); - free(roots); - - if (!_wl_output->egl_surface) - { - EINA_LOG_ERR("Failed to create EGL Surface\n"); - free(_wl_output); - return EINA_FALSE; - } - if (!eglMakeCurrent(comp->egl.display, _wl_output->egl_surface, - _wl_output->egl_surface, comp->egl.context)) - { - EINA_LOG_ERR("Failed to make current\n"); - free(_wl_output); - return EINA_FALSE; - } - - loop = wl_display_get_event_loop(_wl_disp); - _wl_output->finish_frame_timer = - wl_event_loop_add_timer(loop, _e_mod_comp_wl_output_finish_frame_handler, - _wl_output); - - _wl_output->prepare_render = _e_mod_comp_wl_output_prepare_render; - _wl_output->present = _e_mod_comp_wl_output_present; - _wl_output->prepare_scanout_surface = - _e_mod_comp_wl_output_prepare_scanout_surface; - -// TODO: Add output destroy function - - return EINA_TRUE; -} - -Eina_Bool -e_mod_comp_wl_output_shutdown(void) -{ - Wayland_Compositor *comp; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!_wl_output) return EINA_TRUE; - - comp = e_mod_comp_wl_comp_get(); - - wl_list_remove(&_wl_output->frame_callbacks); - wl_list_remove(&_wl_output->link); - - if (_wl_output->finish_frame_timer) - wl_event_source_remove(_wl_output->finish_frame_timer); - - eglDestroySurface(comp->egl.display, _wl_output->egl_surface); - - pixman_region32_fini(&_wl_output->region); - pixman_region32_fini(&_wl_output->prev_damage); - - free(_wl_output); - return EINA_TRUE; } void -e_mod_comp_wl_output_damage(Wayland_Output *output) +e_mod_comp_wl_output_shutdown(void) { - Wayland_Compositor *comp; - Wayland_Surface *ws; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - comp = e_mod_comp_wl_comp_get(); - if (wl_list_empty(&comp->surfaces)) return; - ws = container_of(comp->surfaces.next, Wayland_Surface, link); - pixman_region32_union(&ws->damage, &ws->damage, &output->region); - e_mod_comp_wl_comp_schedule_repaint(); + if (!_wl_output) return; + wl_list_remove(&_wl_output->frame_callbacks); + wl_list_remove(&_wl_output->link); + free(_wl_output); } Wayland_Output * e_mod_comp_wl_output_get(void) { - LOGFN(__FILE__, __LINE__, __FUNCTION__); - return _wl_output; } -void -e_mod_comp_wl_output_idle_repaint(void *data) -{ - Wayland_Output *output; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!(output = data)) return; - if (output->repaint_needed) - { - struct timeval tv; - uint32_t timestamp; - - gettimeofday(&tv, NULL); - timestamp = tv.tv_sec * 1000 + tv.tv_usec / 1000; - _e_mod_comp_wl_output_repaint(output, timestamp); - } -} - /* local functions */ static void _e_mod_comp_wl_output_bind(struct wl_client *client, void *data, uint32_t version __UNUSED__, uint32_t id) @@ -209,269 +91,11 @@ _e_mod_comp_wl_output_bind(struct wl_client *client, void *data, uint32_t versio LOGFN(__FILE__, __LINE__, __FUNCTION__); if (!(output = data)) return; - resource = wl_client_add_object(client, &wl_output_interface, NULL, id, data); - wl_resource_post_event(resource, WL_OUTPUT_GEOMETRY, output->x, output->y, - output->width, output->height, output->subpixel, + output->w, output->h, output->subpixel, output->make, output->model); - wl_resource_post_event(resource, WL_OUTPUT_MODE, output->mode.flags, - output->mode.width, output->mode.height, - output->mode.refresh); -} - -static void -_e_mod_comp_wl_output_scanout_buffer_destroy(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp __UNUSED__) -{ - Wayland_Output *output; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - output = - container_of(listener, Wayland_Output, scanout_buffer_destroy_listener); - - output->scanout_buffer = NULL; - - if (!output->pending_scanout_buffer) - e_mod_comp_wl_comp_schedule_repaint(); -} - -static void -_e_mod_comp_wl_output_pending_scanout_buffer_destroy(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp __UNUSED__) -{ - Wayland_Output *output; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - output = - container_of(listener, Wayland_Output, - pending_scanout_buffer_destroy_listener); - - output->pending_scanout_buffer = NULL; - - e_mod_comp_wl_comp_schedule_repaint(); -} - -static int -_e_mod_comp_wl_output_finish_frame_handler(void *data) -{ - Wayland_Output *output; - uint32_t msec; - struct timeval tv; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!(output = data)) return 1; - - gettimeofday(&tv, NULL); - msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; - _e_mod_comp_wl_output_finish_frame(output, msec); - - return 1; -} - -static void -_e_mod_comp_wl_output_finish_frame(Wayland_Output *output, int secs) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!output) return; - if (output->scanout_buffer) - { - e_mod_comp_wl_buffer_post_release(output->scanout_buffer); - wl_list_remove(&output->scanout_buffer_destroy_listener.link); - output->scanout_buffer = NULL; - } - if (output->pending_scanout_buffer) - { - output->scanout_buffer = output->pending_scanout_buffer; - wl_list_remove(&output->pending_scanout_buffer_destroy_listener.link); - wl_list_insert(output->scanout_buffer->resource.destroy_listener_list.prev, - &output->scanout_buffer_destroy_listener.link); - output->pending_scanout_buffer = NULL; - } - if (output->repaint_needed) - _e_mod_comp_wl_output_repaint(output, secs); - else - output->repaint_scheduled = EINA_FALSE; -} - -static void -_e_mod_comp_wl_output_repaint(Wayland_Output *output, int secs) -{ - Wayland_Frame_Callback *cb, *cnext; - Wayland_Compositor *comp; - Wayland_Surface *ws; - pixman_region32_t opaque, new_damage, total_damage, repaint; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!output) return; - - comp = e_mod_comp_wl_comp_get(); - - /* start weston output repaint */ - output->prepare_render(output); - - glViewport(0, 0, output->width, output->height); - - glUseProgram(comp->texture_shader.program); - glUniformMatrix4fv(comp->texture_shader.proj_uniform, 1, GL_FALSE, - output->matrix.d); - glUniform1i(comp->texture_shader.tex_uniform, 0); - - /* TODO: Set cursor */ - - pixman_region32_init(&new_damage); - pixman_region32_init(&opaque); - - wl_list_for_each(ws, &comp->surfaces, link) - { - pixman_region32_subtract(&ws->damage, &ws->damage, &opaque); - pixman_region32_union(&new_damage, &new_damage, &ws->damage); - pixman_region32_union(&opaque, &opaque, &ws->opaque); - } - - pixman_region32_init(&total_damage); - pixman_region32_union(&total_damage, &new_damage, &output->prev_damage); - pixman_region32_intersect(&output->prev_damage, &new_damage, &output->region); - - pixman_region32_fini(&opaque); - pixman_region32_fini(&new_damage); - - ws = container_of(comp->surfaces.next, Wayland_Surface, link); - - if (_e_mod_comp_wl_output_setup_scanout_surface(output, ws)) - return; - - /* TODO: Handle Fullscreen */ - { - wl_list_for_each(ws, &comp->surfaces, link) - { - pixman_region32_copy(&ws->damage, &total_damage); - pixman_region32_subtract(&total_damage, &total_damage, &ws->opaque); - } - - wl_list_for_each_reverse(ws, &comp->surfaces, link) - { - pixman_region32_init(&repaint); - pixman_region32_intersect(&repaint, &output->region, &ws->damage); - e_mod_comp_wl_surface_draw(ws, output, &repaint); - pixman_region32_subtract(&ws->damage, &ws->damage, &output->region); - pixman_region32_fini(&repaint); - } - } - - /* TODO: Fade out */ - - pixman_region32_fini(&total_damage); - - /* end weston output repaint */ - - output->repaint_needed = EINA_FALSE; - output->repaint_scheduled = EINA_TRUE; - output->present(output); - - wl_list_for_each_safe(cb, cnext, &output->frame_callbacks, link) - { - wl_resource_post_event(&cb->resource, WL_CALLBACK_DONE, secs); - wl_resource_destroy(&cb->resource, 0); - } - - /* TODO: Handle animations */ -} - -static Eina_Bool -_e_mod_comp_wl_output_setup_scanout_surface(Wayland_Output *output, Wayland_Surface *ws) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if ((!output) || (!ws)) return EINA_FALSE; - - if ((ws->visual != WAYLAND_RGB_VISUAL) || - (output->prepare_scanout_surface(output, ws) != 0)) - return EINA_FALSE; - - output->pending_scanout_buffer = ws->buffer; - output->pending_scanout_buffer->busy_count++; - - wl_list_insert(output->pending_scanout_buffer->resource.destroy_listener_list.prev, - &output->pending_scanout_buffer_destroy_listener.link); - - return EINA_TRUE; -} - -static int -_e_mod_comp_wl_output_prepare_render(Wayland_Output *output) -{ - Wayland_Compositor *comp; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!output) return -1; - comp = e_mod_comp_wl_comp_get(); - - if (!eglMakeCurrent(comp->egl.display, output->egl_surface, - output->egl_surface, comp->egl.context)) - { - EINA_LOG_ERR("Failed to make current\n"); - return -1; - } - - return 0; -} - -static int -_e_mod_comp_wl_output_present(Wayland_Output *output) -{ - Wayland_Compositor *comp; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!output) return -1; - - comp = e_mod_comp_wl_comp_get(); - - if (_e_mod_comp_wl_output_prepare_render(output)) return -1; - - eglSwapBuffers(comp->egl.display, output->egl_surface); - - wl_event_source_timer_update(output->finish_frame_timer, 10); - - return 0; -} - -static int -_e_mod_comp_wl_output_prepare_scanout_surface(Wayland_Output *output __UNUSED__, Wayland_Surface *surface __UNUSED__) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - return -1; -} - -static void -_e_mod_comp_wl_output_move(Wayland_Output *output, int32_t x, int32_t y) -{ - int flip; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!output) return; - - pixman_region32_init(&output->prev_damage); - pixman_region32_init_rect(&output->region, x, y, - output->width, output->height); - - e_mod_comp_wl_matrix_init(&output->matrix); - e_mod_comp_wl_matrix_translate(&output->matrix, - -output->x - output->width / 2.0, - -output->y - output->height / 2.0, 0); - - flip = (output->flags & WL_OUTPUT_FLIPPED) ? -1 : 1; - - e_mod_comp_wl_matrix_scale(&output->matrix, 2.0 / output->width, - flip * 2.0 / output->height, 1); - e_mod_comp_wl_output_damage(output); + output->mode.w, output->mode.h, output->mode.refresh); } diff --git a/src/modules/comp/e_mod_comp_wl_output.h b/src/modules/comp/e_mod_comp_wl_output.h index 19dbcdb0c..21fa8e5d2 100644 --- a/src/modules/comp/e_mod_comp_wl_output.h +++ b/src/modules/comp/e_mod_comp_wl_output.h @@ -4,10 +4,8 @@ # define E_MOD_COMP_WL_OUTPUT_H Eina_Bool e_mod_comp_wl_output_init(void); -Eina_Bool e_mod_comp_wl_output_shutdown(void); -void e_mod_comp_wl_output_damage(Wayland_Output *output); +void e_mod_comp_wl_output_shutdown(void); Wayland_Output *e_mod_comp_wl_output_get(void); -void e_mod_comp_wl_output_idle_repaint(void *data); # endif #endif diff --git a/src/modules/comp/e_mod_comp_wl_shell.c b/src/modules/comp/e_mod_comp_wl_shell.c index a54774541..b88f7be9e 100644 --- a/src/modules/comp/e_mod_comp_wl_shell.c +++ b/src/modules/comp/e_mod_comp_wl_shell.c @@ -3,10 +3,10 @@ #ifdef HAVE_WAYLAND # include "e_mod_comp_wl.h" # include "e_mod_comp_wl_comp.h" -# include "e_mod_comp_wl_input.h" # include "e_mod_comp_wl_output.h" -# include "e_mod_comp_wl_surface.h" +# include "e_mod_comp_wl_input.h" # include "e_mod_comp_wl_shell.h" +# include "e_mod_comp_wl_surface.h" #endif /* local function prototypes */ @@ -16,23 +16,19 @@ static void _e_mod_comp_wl_shell_unlock(Wayland_Shell *base); static void _e_mod_comp_wl_shell_map(Wayland_Shell *base, Wayland_Surface *surface, int32_t width, int32_t height); static void _e_mod_comp_wl_shell_configure(Wayland_Shell *base, Wayland_Surface *surface, int32_t x, int32_t y, int32_t width, int32_t height); static void _e_mod_comp_wl_shell_destroy(Wayland_Shell *base); - -static void _e_mod_comp_wl_shell_surface_destroy_handle(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp); - -static Wayland_Shell_Surface *_e_mod_comp_wl_shell_get_shell_surface(Wayland_Surface *surface); -static Wayland_Shell_Surface_Type _e_mod_comp_wl_shell_get_shell_surface_type(Wayland_Surface *surface); -static void _e_mod_comp_wl_shell_center_on_output(Wayland_Surface *ws); -static void _e_mod_comp_wl_shell_activate(Wayland_Shell *base, Wayland_Surface *ws, Wayland_Input *device, uint32_t timestamp); +static void _e_mod_comp_wl_shell_activate(Wayland_Shell *base, Wayland_Surface *surface, uint32_t timestamp); static void _e_mod_comp_wl_shell_shell_surface_get(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource); -static void _e_mod_comp_wl_shell_surface_destroy(struct wl_resource *resource); static void _e_mod_comp_wl_shell_surface_move(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *input_resource, uint32_t timestamp); static void _e_mod_comp_wl_shell_surface_resize(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *input_resource, uint32_t timestamp, uint32_t edges); static void _e_mod_comp_wl_shell_surface_set_toplevel(struct wl_client *client __UNUSED__, struct wl_resource *resource); static void _e_mod_comp_wl_shell_surface_set_transient(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *parent_resource, int32_t x, int32_t y, uint32_t flags __UNUSED__); static void _e_mod_comp_wl_shell_surface_set_fullscreen(struct wl_client *client __UNUSED__, struct wl_resource *resource); static void _e_mod_comp_wl_shell_surface_set_popup(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *input_resource __UNUSED__, uint32_t timestamp __UNUSED__, struct wl_resource *parent_resource, int32_t x, int32_t y, uint32_t flags __UNUSED__); -static Eina_Bool _e_mod_comp_wl_shell_surface_type_reset(Wayland_Shell_Surface *wss); + +static void _e_mod_comp_wl_shell_surface_destroy_handle(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp); +static Wayland_Shell_Surface *_e_mod_comp_wl_shell_get_shell_surface(Wayland_Surface *ws); +static void _e_mod_comp_wl_shell_surface_destroy(struct wl_resource *resource); /* wayland interfaces */ static const struct wl_shell_interface _wl_shell_interface = @@ -59,7 +55,7 @@ e_mod_comp_wl_shell_init(void) if (!(_wl_shell = malloc(sizeof(*_wl_shell)))) { - EINA_LOG_ERR("Cannot allocate space for shell\n"); + EINA_LOG_ERR("Could not allocate space for shell\n"); return EINA_FALSE; } @@ -71,10 +67,6 @@ e_mod_comp_wl_shell_init(void) _wl_shell->shell.configure = _e_mod_comp_wl_shell_configure; _wl_shell->shell.destroy = _e_mod_comp_wl_shell_destroy; - wl_list_init(&_wl_shell->hidden_surfaces); - - /* FIXME: Shell configuration for screensaver ? */ - if (!wl_display_add_global(_wl_disp, &wl_shell_interface, _wl_shell, _e_mod_comp_wl_shell_bind)) { @@ -86,21 +78,19 @@ e_mod_comp_wl_shell_init(void) return EINA_TRUE; } -Eina_Bool +void e_mod_comp_wl_shell_shutdown(void) { LOGFN(__FILE__, __LINE__, __FUNCTION__); - _wl_shell->shell.destroy(&_wl_shell->shell); - return EINA_TRUE; + if (_wl_shell) + _wl_shell->shell.destroy(&_wl_shell->shell); } -Wayland_Shell * +struct wl_shell * e_mod_comp_wl_shell_get(void) { - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - return &_wl_shell->shell; + return _wl_shell; } /* local functions */ @@ -119,41 +109,11 @@ _e_mod_comp_wl_shell_bind(struct wl_client *client, void *data, uint32_t version static void _e_mod_comp_wl_shell_lock(Wayland_Shell *base) { - Wayland_Compositor *comp; - Wayland_Surface *cur, *tmp; - Wayland_Input *input; struct wl_shell *shell; - uint32_t timestamp; LOGFN(__FILE__, __LINE__, __FUNCTION__); - comp = e_mod_comp_wl_comp_get(); shell = container_of(base, struct wl_shell, shell); - - if (shell->locked) return; - shell->locked = EINA_TRUE; - - if (!wl_list_empty(&shell->hidden_surfaces)) - EINA_LOG_ERR("Shell Hidden Surface list is not empty\n"); - - wl_list_for_each_safe(cur, tmp, &comp->surfaces, link) - { - if (!cur->surface.resource.client) continue; - - if (_e_mod_comp_wl_shell_get_shell_surface_type(cur) == - SHELL_SURFACE_BACKGROUND) - continue; - - wl_list_remove(&cur->link); - wl_list_insert(shell->hidden_surfaces.prev, &cur->link); - } - - e_mod_comp_wl_comp_repick(); - - /* reset keyboard focus */ - input = e_mod_comp_wl_input_get(); - timestamp = e_mod_comp_wl_time_get(); - wl_input_device_set_keyboard_focus(&input->input_device, NULL, timestamp); } static void @@ -164,98 +124,40 @@ _e_mod_comp_wl_shell_unlock(Wayland_Shell *base) LOGFN(__FILE__, __LINE__, __FUNCTION__); shell = container_of(base, struct wl_shell, shell); - if ((!shell->locked) || (shell->lock_surface)) - { - e_mod_comp_wl_comp_wake(); - return; - } - - if (!shell->child.desktop_shell) - { - /* TODO: Resume desktop */ - return; - } - - if (shell->prepare_event_sent) return; - wl_resource_post_event(shell->child.desktop_shell, 1); - shell->prepare_event_sent = EINA_TRUE; } static void _e_mod_comp_wl_shell_map(Wayland_Shell *base, Wayland_Surface *surface, int32_t width, int32_t height) { + Wayland_Compositor *comp; + Wayland_Shell_Surface *wss; struct wl_shell *shell; struct wl_list *list; - Wayland_Compositor *comp; - Wayland_Shell_Surface *shsurf; - Wayland_Shell_Surface_Type type; + uint32_t type; Eina_Bool do_configure = EINA_FALSE; LOGFN(__FILE__, __LINE__, __FUNCTION__); - type = SHELL_SURFACE_NONE; comp = e_mod_comp_wl_comp_get(); + type = SHELL_SURFACE_NONE; shell = container_of(base, struct wl_shell, shell); - if ((shsurf = _e_mod_comp_wl_shell_get_shell_surface(surface))) - type = shsurf->type; + if ((wss = _e_mod_comp_wl_shell_get_shell_surface(surface))) + type = wss->type; + if (shell->locked) { list = &shell->hidden_surfaces; do_configure = EINA_FALSE; } - else + else { list = &comp->surfaces; do_configure = EINA_TRUE; } - surface->width = width; - surface->height = height; - - /* initial position */ - switch (type) - { - case SHELL_SURFACE_TOPLEVEL: - surface->x = 10 + random() % 400; - surface->y = 10 + random() % 400; - break; - case SHELL_SURFACE_SCREENSAVER: - case SHELL_SURFACE_FULLSCREEN: - _e_mod_comp_wl_shell_center_on_output(surface); - break; - case SHELL_SURFACE_LOCK: - _e_mod_comp_wl_shell_center_on_output(surface); - break; - default: - break; - } - - /* surface stacking */ - switch (type) - { - case SHELL_SURFACE_BACKGROUND: - wl_list_insert(comp->surfaces.prev, &surface->link); - do_configure = EINA_TRUE; - break; - case SHELL_SURFACE_PANEL: - wl_list_insert(list, &surface->link); - break; - case SHELL_SURFACE_LOCK: - wl_list_insert(&comp->surfaces, &surface->link); - e_mod_comp_wl_comp_repick(); - e_mod_comp_wl_comp_wake(); - do_configure = EINA_TRUE; - break; - case SHELL_SURFACE_SCREENSAVER: - /* TODO: Handle show of screensaver */ - do_configure = EINA_FALSE; - break; - default: - /* skip panels */ - wl_list_insert(list, &surface->link); - break; - } + surface->w = width; + surface->h = height; switch (type) { @@ -263,44 +165,31 @@ _e_mod_comp_wl_shell_map(Wayland_Shell *base, Wayland_Surface *surface, int32_t surface->x = 10 + random() % 400; surface->y = 10 + random() % 400; break; - case SHELL_SURFACE_POPUP: - /* TODO: handle popup map */ - break; default: + wl_list_insert(list, &surface->link); break; } - surface->width = width; - surface->height = height; if (do_configure) - { - e_mod_comp_wl_surface_configure(surface, surface->x, surface->y, - width, height); - e_mod_comp_wl_comp_repick(); - } + e_mod_comp_wl_surface_configure(surface, surface->x, surface->y, + surface->w, surface->h); - switch (type) + switch (type) { case SHELL_SURFACE_TOPLEVEL: case SHELL_SURFACE_TRANSIENT: case SHELL_SURFACE_FULLSCREEN: - if (!shell->locked) - _e_mod_comp_wl_shell_activate(base, surface, - e_mod_comp_wl_input_get(), - e_mod_comp_wl_time_get()); - break; - default: + if (!shell->locked) + _e_mod_comp_wl_shell_activate(base, surface, e_mod_comp_wl_time_get()); break; } - - /* NB: Maybe handle zoom ?? */ } static void _e_mod_comp_wl_shell_configure(Wayland_Shell *base, Wayland_Surface *surface, int32_t x, int32_t y, int32_t width, int32_t height) { struct wl_shell *shell; - Wayland_Shell_Surface *shsurf; + Wayland_Shell_Surface *wss; Wayland_Shell_Surface_Type type; Eina_Bool do_configure = EINA_FALSE; @@ -309,24 +198,23 @@ _e_mod_comp_wl_shell_configure(Wayland_Shell *base, Wayland_Surface *surface, in type = SHELL_SURFACE_NONE; shell = container_of(base, struct wl_shell, shell); do_configure = !shell->locked; - if ((shsurf = _e_mod_comp_wl_shell_get_shell_surface(surface))) - type = shsurf->type; + if ((wss = _e_mod_comp_wl_shell_get_shell_surface(surface))) + type = wss->type; - surface->width = width; - surface->height = height; + surface->w = width; + surface->h = height; - switch (type) + switch (type) { case SHELL_SURFACE_SCREENSAVER: do_configure = !do_configure; case SHELL_SURFACE_FULLSCREEN: - _e_mod_comp_wl_shell_center_on_output(surface); break; default: break; } - if (do_configure) + if (do_configure) e_mod_comp_wl_surface_configure(surface, x, y, width, height); } @@ -343,98 +231,21 @@ _e_mod_comp_wl_shell_destroy(Wayland_Shell *base) } static void -_e_mod_comp_wl_shell_surface_destroy_handle(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp) +_e_mod_comp_wl_shell_activate(Wayland_Shell *base, Wayland_Surface *surface, uint32_t timestamp) { - Wayland_Shell_Surface *shsurf; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - shsurf = container_of(listener, Wayland_Shell_Surface, surface_destroy_listener); - shsurf->surface = NULL; - wl_resource_destroy(&shsurf->resource, timestamp); -} - -static Wayland_Shell_Surface * -_e_mod_comp_wl_shell_get_shell_surface(Wayland_Surface *surface) -{ - struct wl_list *lst; - struct wl_listener *listener; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - lst = &surface->surface.resource.destroy_listener_list; - wl_list_for_each(listener, lst, link) - { - if (listener->func == _e_mod_comp_wl_shell_surface_destroy_handle) - return container_of(listener, Wayland_Shell_Surface, - surface_destroy_listener); - } - - return NULL; -} - -static Wayland_Shell_Surface_Type -_e_mod_comp_wl_shell_get_shell_surface_type(Wayland_Surface *surface) -{ - Wayland_Shell_Surface *shsurf; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - if (!(shsurf = _e_mod_comp_wl_shell_get_shell_surface(surface))) - return SHELL_SURFACE_NONE; - - return shsurf->type; -} - -static void -_e_mod_comp_wl_shell_center_on_output(Wayland_Surface *ws) -{ - Wayland_Output *output; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - output = e_mod_comp_wl_output_get(); - ws->x = output->x + (output->mode.width - ws->width) / 2; - ws->y = output->y + (output->mode.height - ws->height) / 2; -} - -static void -_e_mod_comp_wl_shell_activate(Wayland_Shell *base, Wayland_Surface *ws, Wayland_Input *device, uint32_t timestamp) -{ - Wayland_Compositor *comp; struct wl_shell *shell; LOGFN(__FILE__, __LINE__, __FUNCTION__); - comp = e_mod_comp_wl_comp_get(); shell = container_of(base, struct wl_shell, shell); - - e_mod_comp_wl_surface_activate(ws, device, timestamp); - - switch (_e_mod_comp_wl_shell_get_shell_surface_type(ws)) - { - case SHELL_SURFACE_BACKGROUND: - wl_list_remove(&ws->link); - wl_list_insert(comp->surfaces.prev, &ws->link); - break; - case SHELL_SURFACE_PANEL: - break; - case SHELL_SURFACE_SCREENSAVER: - break; - default: - if (!shell->locked) - { - /* TODO: bring panel on top */ - } - break; - } + e_mod_comp_wl_surface_activate(surface, e_mod_comp_wl_input_get(), timestamp); } static void _e_mod_comp_wl_shell_shell_surface_get(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { Wayland_Surface *ws; - Wayland_Shell_Surface *shsurf; + Wayland_Shell_Surface *wss; LOGFN(__FILE__, __LINE__, __FUNCTION__); @@ -447,84 +258,43 @@ _e_mod_comp_wl_shell_shell_surface_get(struct wl_client *client, struct wl_resou return; } - if (!(shsurf = calloc(1, sizeof(*shsurf)))) + if (!(wss = calloc(1, sizeof(*wss)))) { wl_resource_post_no_memory(resource); return; } - shsurf->resource.destroy = _e_mod_comp_wl_shell_surface_destroy; - shsurf->resource.object.id = id; - shsurf->resource.object.interface = &wl_shell_surface_interface; - shsurf->resource.object.implementation = + wss->resource.destroy = _e_mod_comp_wl_shell_surface_destroy; + wss->resource.object.id = id; + wss->resource.object.interface = &wl_shell_surface_interface; + wss->resource.object.implementation = (void (**)(void)) &_wl_shell_surface_interface; - shsurf->resource.data = shsurf; + wss->resource.data = wss; - shsurf->surface = ws; - shsurf->surface_destroy_listener.func = + wss->surface = ws; + wss->surface_destroy_listener.func = _e_mod_comp_wl_shell_surface_destroy_handle; wl_list_insert(ws->surface.resource.destroy_listener_list.prev, - &shsurf->surface_destroy_listener.link); + &wss->surface_destroy_listener.link); - wl_list_init(&shsurf->link); + wl_list_init(&wss->link); - shsurf->type = SHELL_SURFACE_NONE; - wl_client_add_resource(client, &shsurf->resource); -} - -static void -_e_mod_comp_wl_shell_surface_destroy(struct wl_resource *resource) -{ - Wayland_Shell_Surface *wss; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - wss = resource->data; - /* TODO: popup grab input */ - if (wss->surface) - wl_list_remove(&wss->surface_destroy_listener.link); - wl_list_remove(&wss->link); - free(wss); + wss->type = SHELL_SURFACE_NONE; + wl_client_add_resource(client, &wss->resource); } static void _e_mod_comp_wl_shell_surface_move(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *input_resource, uint32_t timestamp) { - Wayland_Input *wi; - Wayland_Shell_Surface *wss; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - wi = input_resource->data; - wss = resource->data; - - if ((!wi->input_device.button_count) || - (wi->input_device.grab_time != timestamp) || - (wi->input_device.pointer_focus != &wss->surface->surface)) - return; - - if (!e_mod_comp_wl_surface_move(wss->surface, wi, timestamp)) - wl_resource_post_no_memory(resource); } static void _e_mod_comp_wl_shell_surface_resize(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *input_resource, uint32_t timestamp, uint32_t edges) { - Wayland_Input *wi; - Wayland_Shell_Surface *wss; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - wi = input_resource->data; - wss = resource->data; - - if ((!wi->input_device.button_count) || - (wi->input_device.grab_time != timestamp) || - (wi->input_device.pointer_focus != &wss->surface->surface)) - return; - - if (!e_mod_comp_wl_surface_resize(wss, wi, timestamp, edges)) - wl_resource_post_no_memory(resource); } static void @@ -535,7 +305,9 @@ _e_mod_comp_wl_shell_surface_set_toplevel(struct wl_client *client __UNUSED__, s LOGFN(__FILE__, __LINE__, __FUNCTION__); wss = resource->data; - if (!_e_mod_comp_wl_shell_surface_type_reset(wss)) return; + + /* TODO: Surface type reset */ + e_mod_comp_wl_surface_damage_surface(wss->surface); wss->type = SHELL_SURFACE_TOPLEVEL; } @@ -553,10 +325,13 @@ _e_mod_comp_wl_shell_surface_set_transient(struct wl_client *client __UNUSED__, ws = wss->surface; pws = pss->surface; - if (!_e_mod_comp_wl_shell_surface_type_reset(wss)) return; + /* TODO: Surface type reset */ + ws->x = pws->x + x; ws->y = pws->y + y; + e_mod_comp_wl_surface_damage_surface(ws); + wss->type = SHELL_SURFACE_TRANSIENT; } @@ -571,13 +346,12 @@ _e_mod_comp_wl_shell_surface_set_fullscreen(struct wl_client *client __UNUSED__, wss = resource->data; ws = wss->surface; - if (!_e_mod_comp_wl_shell_surface_type_reset(wss)) return; - output = e_mod_comp_wl_output_get(); + wss->saved_x = ws->x; wss->saved_y = ws->y; - ws->x = (output->width - ws->width) / 2; - ws->y = (output->height - ws->height) / 2; + ws->x = (output->w - ws->w) / 2; + ws->y = (output->h - ws->h) / 2; e_mod_comp_wl_surface_damage_surface(ws); wss->type = SHELL_SURFACE_FULLSCREEN; } @@ -599,33 +373,48 @@ _e_mod_comp_wl_shell_surface_set_popup(struct wl_client *client __UNUSED__, stru wss->popup.y = y; } -static Eina_Bool -_e_mod_comp_wl_shell_surface_type_reset(Wayland_Shell_Surface *wss) +static void +_e_mod_comp_wl_shell_surface_destroy_handle(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp) { + Wayland_Shell_Surface *wss; + LOGFN(__FILE__, __LINE__, __FUNCTION__); - switch (wss->type) - { - case SHELL_SURFACE_FULLSCREEN: - wss->surface->x = wss->saved_x; - wss->surface->y = wss->saved_y; - break; - case SHELL_SURFACE_PANEL: - case SHELL_SURFACE_BACKGROUND: - wl_list_remove(&wss->link); - wl_list_init(&wss->link); - break; - case SHELL_SURFACE_SCREENSAVER: - case SHELL_SURFACE_LOCK: - wl_resource_post_error(&wss->resource, - WL_DISPLAY_ERROR_INVALID_METHOD, - "Cannot reassign surface type"); - return EINA_FALSE; - break; - default: - break; - } - - wss->type = SHELL_SURFACE_NONE; - return EINA_TRUE; + wss = container_of(listener, Wayland_Shell_Surface, surface_destroy_listener); + wss->surface = NULL; + wl_resource_destroy(&wss->resource, timestamp); +} + +static Wayland_Shell_Surface * +_e_mod_comp_wl_shell_get_shell_surface(Wayland_Surface *ws) +{ + struct wl_list *list; + struct wl_listener *listener; + + LOGFN(__FILE__, __LINE__, __FUNCTION__); + + list = &ws->surface.resource.destroy_listener_list; + wl_list_for_each(listener, list, link) + { + if (listener->func == _e_mod_comp_wl_shell_surface_destroy_handle) + return container_of(listener, Wayland_Shell_Surface, + surface_destroy_listener); + } + return NULL; +} + +static void +_e_mod_comp_wl_shell_surface_destroy(struct wl_resource *resource) +{ + Wayland_Shell_Surface *wss; + + LOGFN(__FILE__, __LINE__, __FUNCTION__); + + wss = resource->data; + + /* TODO: popup grab input */ + + if (wss->surface) wl_list_remove(&wss->surface_destroy_listener.link); + wl_list_remove(&wss->link); + free(wss); } diff --git a/src/modules/comp/e_mod_comp_wl_shell.h b/src/modules/comp/e_mod_comp_wl_shell.h index 93a9c0dbf..05a062c4c 100644 --- a/src/modules/comp/e_mod_comp_wl_shell.h +++ b/src/modules/comp/e_mod_comp_wl_shell.h @@ -4,8 +4,8 @@ # define E_MOD_COMP_WL_SHELL_H Eina_Bool e_mod_comp_wl_shell_init(void); -Eina_Bool e_mod_comp_wl_shell_shutdown(void); -Wayland_Shell *e_mod_comp_wl_shell_get(void); +void e_mod_comp_wl_shell_shutdown(void); +struct wl_shell *e_mod_comp_wl_shell_get(void); # endif #endif diff --git a/src/modules/comp/e_mod_comp_wl_shm.c b/src/modules/comp/e_mod_comp_wl_shm.c index 9b56b16c6..6ede01624 100644 --- a/src/modules/comp/e_mod_comp_wl_shm.c +++ b/src/modules/comp/e_mod_comp_wl_shm.c @@ -5,8 +5,41 @@ # include "e_mod_comp_wl_shm.h" #endif +/* local function prototypes */ +static void _e_mod_comp_wl_shm_buffer_created(struct wl_buffer *buffer); +static void _e_mod_comp_wl_shm_buffer_damaged(struct wl_buffer *buffer, int32_t x __UNUSED__, int32_t y __UNUSED__, int32_t width __UNUSED__, int32_t height __UNUSED__); +static void _e_mod_comp_wl_shm_buffer_destroyed(struct wl_buffer *buffer); + +/* wayland interfaces */ +static const struct wl_shm_callbacks _wl_shm_callbacks = +{ + _e_mod_comp_wl_shm_buffer_created, + _e_mod_comp_wl_shm_buffer_damaged, + _e_mod_comp_wl_shm_buffer_destroyed +}; + +/* private variables */ +static struct wl_shm *_wl_shm; + +Eina_Bool +e_mod_comp_wl_shm_init(void) +{ + if (!(_wl_shm = wl_shm_init(_wl_disp, &_wl_shm_callbacks))) + return EINA_FALSE; + + return EINA_TRUE; +} + void -e_mod_comp_wl_shm_buffer_created(struct wl_buffer *buffer) +e_mod_comp_wl_shm_shutdown(void) +{ + if (_wl_shm) wl_shm_finish(_wl_shm); + _wl_shm = NULL; +} + +/* local functions */ +static void +_e_mod_comp_wl_shm_buffer_created(struct wl_buffer *buffer) { struct wl_list *attached; @@ -22,8 +55,8 @@ e_mod_comp_wl_shm_buffer_created(struct wl_buffer *buffer) buffer->user_data = attached; } -void -e_mod_comp_wl_shm_buffer_damaged(struct wl_buffer *buffer, int32_t x __UNUSED__, int32_t y __UNUSED__, int32_t width __UNUSED__, int32_t height __UNUSED__) +static void +_e_mod_comp_wl_shm_buffer_damaged(struct wl_buffer *buffer, int32_t x __UNUSED__, int32_t y __UNUSED__, int32_t width __UNUSED__, int32_t height __UNUSED__) { struct wl_list *attached; GLsizei tex_width; @@ -33,18 +66,17 @@ e_mod_comp_wl_shm_buffer_damaged(struct wl_buffer *buffer, int32_t x __UNUSED__, attached = buffer->user_data; tex_width = wl_shm_buffer_get_stride(buffer) / 4; - wl_list_for_each(ws, attached, buffer_link) { glBindTexture(GL_TEXTURE_2D, ws->texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, - tex_width, buffer->height, 0, GL_BGRA_EXT, + glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, + tex_width, buffer->height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, wl_shm_buffer_get_data(buffer)); } } -void -e_mod_comp_wl_shm_buffer_destroyed(struct wl_buffer *buffer) +static void +_e_mod_comp_wl_shm_buffer_destroyed(struct wl_buffer *buffer) { struct wl_list *attached; Wayland_Surface *ws, *next; @@ -59,4 +91,3 @@ e_mod_comp_wl_shm_buffer_destroyed(struct wl_buffer *buffer) } free(attached); } - diff --git a/src/modules/comp/e_mod_comp_wl_shm.h b/src/modules/comp/e_mod_comp_wl_shm.h index b32abec30..527be0a12 100644 --- a/src/modules/comp/e_mod_comp_wl_shm.h +++ b/src/modules/comp/e_mod_comp_wl_shm.h @@ -3,9 +3,8 @@ # ifndef E_MOD_COMP_WL_SHM_H # define E_MOD_COMP_WL_SHM_H -void e_mod_comp_wl_shm_buffer_created(struct wl_buffer *buffer); -void e_mod_comp_wl_shm_buffer_damaged(struct wl_buffer *buffer, int32_t x __UNUSED__, int32_t y __UNUSED__, int32_t width __UNUSED__, int32_t height __UNUSED__); -void e_mod_comp_wl_shm_buffer_destroyed(struct wl_buffer *buffer); +Eina_Bool e_mod_comp_wl_shm_init(void); +void e_mod_comp_wl_shm_shutdown(void); # endif #endif diff --git a/src/modules/comp/e_mod_comp_wl_surface.c b/src/modules/comp/e_mod_comp_wl_surface.c index b45335322..ae010921f 100644 --- a/src/modules/comp/e_mod_comp_wl_surface.c +++ b/src/modules/comp/e_mod_comp_wl_surface.c @@ -4,59 +4,59 @@ # include "e_mod_comp_wl.h" # include "e_mod_comp_wl_comp.h" # include "e_mod_comp_wl_output.h" -# include "e_mod_comp_wl_surface.h" +# include "e_mod_comp_wl_input.h" # include "e_mod_comp_wl_shell.h" +# include "e_mod_comp_wl_surface.h" +# include "e_mod_comp_wl_buffer.h" #endif /* local function prototypes */ static void _e_mod_comp_wl_surface_buffer_destroy_handle(struct wl_listener *listener, struct wl_resource *resource __UNUSED__, uint32_t timestamp __UNUSED__); -static int _e_mod_comp_wl_surface_texture_region(Wayland_Surface *ws, pixman_region32_t *region); -static int _e_mod_comp_wl_surface_texture_transformed_surface(Wayland_Surface *ws); -static void _e_mod_comp_wl_surface_transform_vertex(Wayland_Surface *ws, GLfloat x, GLfloat y, GLfloat u, GLfloat v, GLfloat *r); -static void _e_mod_comp_wl_surface_frame_destroy_callback(struct wl_resource *resource); -static void _e_mod_comp_wl_surface_damage_rectangle(Wayland_Surface *ws, int32_t x, int32_t y, int32_t width, int32_t height); -static void _e_mod_comp_wl_surface_flush_damage(Wayland_Surface *ws); static void _e_mod_comp_wl_surface_raise(Wayland_Surface *ws); +static void _e_mod_comp_wl_surface_damage_rectangle(Wayland_Surface *ws, int32_t x, int32_t y, int32_t width, int32_t height); +static void _e_mod_comp_wl_surface_frame_destroy_callback(struct wl_resource *resource); Wayland_Surface * -e_mod_comp_wl_surface_create(int32_t x, int32_t y, int32_t width, int32_t height) +e_mod_comp_wl_surface_create(int32_t x, int32_t y, int32_t w, int32_t h) { - Wayland_Surface *surface; + Wayland_Surface *ws; LOGFN(__FILE__, __LINE__, __FUNCTION__); - if (!(surface = calloc(1, sizeof(Wayland_Surface)))) return NULL; + if (!(ws = calloc(1, sizeof(Wayland_Surface)))) return NULL; - wl_list_init(&surface->link); - wl_list_init(&surface->buffer_link); + wl_list_init(&ws->link); + wl_list_init(&ws->buffer_link); + + glGenTextures(1, &ws->texture); + glBindTexture(GL_TEXTURE_2D, ws->texture); - glGenTextures(1, &surface->texture); - glBindTexture(GL_TEXTURE_2D, surface->texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - surface->surface.resource.client = NULL; + ws->surface.resource.client = NULL; - surface->visual = WAYLAND_NONE_VISUAL; - surface->image = EGL_NO_IMAGE_KHR; - surface->saved_texture = 0; - surface->x = x; - surface->y = y; - surface->width = width; - surface->height = height; - surface->buffer = NULL; + ws->x = x; + ws->y = y; + ws->w = w; + ws->h = h; + ws->buffer = NULL; - pixman_region32_init(&surface->damage); - pixman_region32_init(&surface->opaque); + ws->win = e_win_new(e_container_current_get(e_manager_current_get())); + e_win_borderless_set(ws->win, EINA_TRUE); + e_win_move_resize(ws->win, x, y, w, h); - wl_list_init(&surface->frame_callbacks); + pixman_region32_init(&ws->damage); + pixman_region32_init(&ws->opaque); - surface->buffer_destroy_listener.func = + wl_list_init(&ws->frame_callbacks); + + ws->buffer_destroy_listener.func = _e_mod_comp_wl_surface_buffer_destroy_handle; - surface->transform = NULL; + /* ws->transform = NULL; */ - return surface; + return ws; } void @@ -71,8 +71,8 @@ void e_mod_comp_wl_surface_attach(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *buffer_resource, int32_t x, int32_t y) { Wayland_Surface *ws; - Wayland_Shell *shell; struct wl_buffer *buffer; + struct wl_shell *shell; LOGFN(__FILE__, __LINE__, __FUNCTION__); @@ -80,7 +80,7 @@ e_mod_comp_wl_surface_attach(struct wl_client *client __UNUSED__, struct wl_reso buffer = buffer_resource->data; shell = e_mod_comp_wl_shell_get(); - e_mod_comp_wl_surface_damage_below(ws); + /* TODO: damage below ?? */ if (ws->buffer) { @@ -93,12 +93,12 @@ e_mod_comp_wl_surface_attach(struct wl_client *client __UNUSED__, struct wl_reso wl_list_insert(ws->buffer->resource.destroy_listener_list.prev, &ws->buffer_destroy_listener.link); - if (!ws->visual) - shell->map(shell, ws, buffer->width, buffer->height); - else if ((x != 0) || (y != 0) || (ws->width != buffer->width) || - (ws->height != buffer->height)) - shell->configure(shell, ws, ws->x + x, ws->y + y, - buffer->width, buffer->height); + if (!ws->visual) + shell->shell.map(&shell->shell, ws, buffer->width, buffer->height); + else if ((x != 0) || (y != 0) || + (ws->w != buffer->width) || (ws->h != buffer->height)) + shell->shell.configure(&shell->shell, ws, ws->x + x, ws->y + y, + buffer->width, buffer->height); e_mod_comp_wl_buffer_attach(buffer, &ws->surface); } @@ -123,7 +123,6 @@ e_mod_comp_wl_surface_frame(struct wl_client *client, struct wl_resource *resour LOGFN(__FILE__, __LINE__, __FUNCTION__); ws = resource->data; - if (!(cb = malloc(sizeof(*cb)))) { wl_resource_post_no_memory(resource); @@ -137,7 +136,6 @@ e_mod_comp_wl_surface_frame(struct wl_client *client, struct wl_resource *resour cb->resource.data = cb; wl_client_add_resource(client, &cb->resource); - wl_list_insert(ws->frame_callbacks.prev, &cb->link); } @@ -150,14 +148,14 @@ e_mod_comp_wl_surface_destroy_surface(struct wl_resource *resource) ws = container_of(resource, Wayland_Surface, surface.resource); - e_mod_comp_wl_surface_damage_below(ws); + /* TODO: damage below */ + /* TODO: flush damage */ - _e_mod_comp_wl_surface_flush_damage(ws); + if (ws->win) + e_object_del(E_OBJECT(ws->win)); wl_list_remove(&ws->link); - e_mod_comp_wl_comp_repick(); - if (!ws->saved_texture) glDeleteTextures(1, &ws->texture); else @@ -183,64 +181,51 @@ e_mod_comp_wl_surface_destroy_surface(struct wl_resource *resource) } void -e_mod_comp_wl_surface_draw(Wayland_Surface *ws, Wayland_Output *output __UNUSED__, pixman_region32_t *clip) +e_mod_comp_wl_surface_configure(Wayland_Surface *ws, int32_t x, int32_t y, int32_t width, int32_t height) { - Wayland_Compositor *comp; - GLfloat *v; - pixman_region32_t repaint; - GLint filter; - int n = 0; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - comp = e_mod_comp_wl_comp_get(); - pixman_region32_init_rect(&repaint, ws->x, ws->y, ws->width, ws->height); - pixman_region32_intersect(&repaint, &repaint, clip); - if (!pixman_region32_not_empty(&repaint)) return; - switch (ws->visual) + if (!ws) return; + + /* TODO: damage below ? */ + + ws->x = x; + ws->y = y; + ws->w = width; + ws->h = height; + + if (!wl_list_empty(&ws->frame_callbacks)) { - case WAYLAND_ARGB_VISUAL: - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - break; - case WAYLAND_RGB_VISUAL: - glDisable(GL_BLEND); - break; - default: - break; + Wayland_Output *output; + + output = e_mod_comp_wl_output_get(); + wl_list_insert_list(output->frame_callbacks.prev, + &ws->frame_callbacks); + wl_list_init(&ws->frame_callbacks); } - if (ws->alpha != comp->current_alpha) - { - glUniform1f(comp->texture_shader.alpha_uniform, ws->alpha / 255.0); - comp->current_alpha = ws->alpha; - } + e_mod_comp_wl_surface_damage_surface(ws); - if (ws->transform == NULL) - { - filter = GL_NEAREST; - n = _e_mod_comp_wl_surface_texture_region(ws, &repaint); - } + pixman_region32_fini(&ws->opaque); + if (ws->visual == WAYLAND_RGB_VISUAL) + pixman_region32_init_rect(&ws->opaque, ws->x, ws->y, ws->w, ws->h); else - { - filter = GL_LINEAR; - n = _e_mod_comp_wl_surface_texture_transformed_surface(ws); - } + pixman_region32_init(&ws->opaque); - glBindTexture(GL_TEXTURE_2D, ws->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + if (ws->win) + e_win_move_resize(ws->win, ws->x, ws->y, ws->w, ws->h); +} - v = comp->vertices.data; - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(*v), &v[0]); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(*v), &v[2]); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glDrawElements(GL_TRIANGLES, n * 6, GL_UNSIGNED_INT, comp->indices.data); +void +e_mod_comp_wl_surface_activate(Wayland_Surface *ws, Wayland_Input *wi, uint32_t timestamp) +{ + LOGFN(__FILE__, __LINE__, __FUNCTION__); - comp->vertices.size = 0; - comp->indices.size = 0; - pixman_region32_fini(&repaint); + if (ws->win) e_win_show(ws->win); + + _e_mod_comp_wl_surface_raise(ws); + wl_input_device_set_keyboard_focus(&wi->input_device, &ws->surface, timestamp); + wl_data_device_set_keyboard_focus(&wi->input_device); } void @@ -248,110 +233,7 @@ e_mod_comp_wl_surface_damage_surface(Wayland_Surface *ws) { LOGFN(__FILE__, __LINE__, __FUNCTION__); - _e_mod_comp_wl_surface_damage_rectangle(ws, 0, 0, ws->width, ws->height); -} - -void -e_mod_comp_wl_surface_transform(Wayland_Surface *ws, int32_t x, int32_t y, int32_t *sx, int32_t *sy) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - *sx = x - ws->x; - *sy = y - ws->y; -} - -void -e_mod_comp_wl_surface_configure(Wayland_Surface *ws, int32_t x, int32_t y, int32_t width, int32_t height) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - e_mod_comp_wl_surface_damage_below(ws); - - ws->x = x; - ws->y = y; - ws->width = width; - ws->height = height; - - e_mod_comp_wl_surface_assign_output(ws); - e_mod_comp_wl_surface_damage_surface(ws); - - pixman_region32_fini(&ws->opaque); - if (ws->visual == WAYLAND_RGB_VISUAL) - pixman_region32_init_rect(&ws->opaque, ws->x, ws->y, ws->width, ws->height); - else - pixman_region32_init(&ws->opaque); -} - -void -e_mod_comp_wl_surface_assign_output(Wayland_Surface *ws) -{ - Wayland_Output *output; - pixman_region32_t region; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - output = e_mod_comp_wl_output_get(); - pixman_region32_init_rect(®ion, ws->x, ws->y, ws->width, ws->height); - pixman_region32_intersect(®ion, ®ion, &output->region); - - /* NB: maybe region32_extents if we handle more than one output */ - - if (!wl_list_empty(&ws->frame_callbacks)) - { - wl_list_insert_list(output->frame_callbacks.prev, - &ws->frame_callbacks); - wl_list_init(&ws->frame_callbacks); - } -} - -void -e_mod_comp_wl_surface_damage_below(Wayland_Surface *ws) -{ - Wayland_Compositor *comp; - Wayland_Surface *below; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - comp = e_mod_comp_wl_comp_get(); - if (ws->link.next == &comp->surfaces) return; - below = container_of(ws->link.next, Wayland_Surface, link); - pixman_region32_union_rect(&below->damage, &below->damage, - ws->x, ws->y, ws->width, ws->height); - e_mod_comp_wl_comp_schedule_repaint(); -} - -void -e_mod_comp_wl_surface_activate(Wayland_Surface *ws, Wayland_Input *device, uint32_t timestamp) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - _e_mod_comp_wl_surface_raise(ws); - wl_input_device_set_keyboard_focus(&device->input_device, &ws->surface, timestamp); - wl_data_device_set_keyboard_focus(&device->input_device); -} - -Eina_Bool -e_mod_comp_wl_surface_move(Wayland_Surface *ws, Wayland_Input *wi, uint32_t timestamp) -{ - /* TODO: Code me */ - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - wl_input_device_set_pointer_focus(&wi->input_device, NULL, timestamp, - 0, 0, 0, 0); - return EINA_TRUE; -} - -Eina_Bool -e_mod_comp_wl_surface_resize(Wayland_Shell_Surface *wss, Wayland_Input *wi, uint32_t timestamp, uint32_t edges) -{ - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - /* TODO: Code me */ - - wl_input_device_set_pointer_focus(&wi->input_device, NULL, timestamp, - 0, 0, 0, 0); - return EINA_TRUE; + _e_mod_comp_wl_surface_damage_rectangle(ws, 0, 0, ws->w, ws->h); } /* local functions */ @@ -366,106 +248,27 @@ _e_mod_comp_wl_surface_buffer_destroy_handle(struct wl_listener *listener, struc ws->buffer = NULL; } -static int -_e_mod_comp_wl_surface_texture_region(Wayland_Surface *ws, pixman_region32_t *region) +static void +_e_mod_comp_wl_surface_raise(Wayland_Surface *ws) { Wayland_Compositor *comp; - GLfloat *v, inv_width, inv_height; - pixman_box32_t *rects; - unsigned int *p; - int i, n; LOGFN(__FILE__, __LINE__, __FUNCTION__); comp = e_mod_comp_wl_comp_get(); - rects = pixman_region32_rectangles(region, &n); - v = wl_array_add(&comp->vertices, n * 16 * sizeof *v); - p = wl_array_add(&comp->indices, n * 6 * sizeof *p); - inv_width = 1.0 / ws->pitch; - inv_height = 1.0 / ws->height; - - for (i = 0; i < n; i++, v += 16, p += 6) { - v[ 0] = rects[i].x1; - v[ 1] = rects[i].y1; - v[ 2] = (GLfloat) (rects[i].x1 - ws->x) * inv_width; - v[ 3] = (GLfloat) (rects[i].y1 - ws->y) * inv_height; - - v[ 4] = rects[i].x1; - v[ 5] = rects[i].y2; - v[ 6] = v[ 2]; - v[ 7] = (GLfloat) (rects[i].y2 - ws->y) * inv_height; - - v[ 8] = rects[i].x2; - v[ 9] = rects[i].y1; - v[10] = (GLfloat) (rects[i].x2 - ws->x) * inv_width; - v[11] = v[ 3]; - - v[12] = rects[i].x2; - v[13] = rects[i].y2; - v[14] = v[10]; - v[15] = v[ 7]; - - p[0] = i * 4 + 0; - p[1] = i * 4 + 1; - p[2] = i * 4 + 2; - p[3] = i * 4 + 2; - p[4] = i * 4 + 1; - p[5] = i * 4 + 3; - } - - return n; -} - -static int -_e_mod_comp_wl_surface_texture_transformed_surface(Wayland_Surface *ws) -{ - Wayland_Compositor *comp; - GLfloat *v; - unsigned int *p; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - comp = e_mod_comp_wl_comp_get(); - v = wl_array_add(&comp->vertices, 16 * sizeof *v); - p = wl_array_add(&comp->indices, 6 * sizeof *p); - - _e_mod_comp_wl_surface_transform_vertex(ws, ws->x, ws->y, 0.0, 0.0, &v[0]); - _e_mod_comp_wl_surface_transform_vertex(ws, ws->x, ws->y + ws->height, - 0.0, 1.0, &v[4]); - _e_mod_comp_wl_surface_transform_vertex(ws, ws->x + ws->width, ws->y, - 1.0, 0.0, &v[8]); - _e_mod_comp_wl_surface_transform_vertex(ws, ws->x + ws->width, - ws->y + ws->height, 1.0, 1.0, - &v[12]); - - p[0] = 0; - p[1] = 1; - p[2] = 2; - p[3] = 2; - p[4] = 1; - p[5] = 3; - - return 1; + wl_list_remove(&ws->link); + wl_list_insert(&comp->surfaces, &ws->link); + /* TODO: repick */ + e_mod_comp_wl_surface_damage_surface(ws); } static void -_e_mod_comp_wl_surface_transform_vertex(Wayland_Surface *ws, GLfloat x, GLfloat y, GLfloat u, GLfloat v, GLfloat *r) +_e_mod_comp_wl_surface_damage_rectangle(Wayland_Surface *ws, int32_t x, int32_t y, int32_t width, int32_t height) { - Wayland_Vector t; - LOGFN(__FILE__, __LINE__, __FUNCTION__); - t.f[0] = x; - t.f[1] = y; - t.f[2] = 0.0; - t.f[3] = 1.0; - - e_mod_comp_wl_matrix_transform(&ws->transform->matrix, &t); - - r[ 0] = t.f[0]; - r[ 1] = t.f[1]; - r[ 2] = u; - r[ 3] = v; + pixman_region32_union_rect(&ws->damage, &ws->damage, + ws->x + x, ws->y + y, width, height); } static void @@ -479,47 +282,3 @@ _e_mod_comp_wl_surface_frame_destroy_callback(struct wl_resource *resource) wl_list_remove(&cb->link); free(cb); } - -static void -_e_mod_comp_wl_surface_damage_rectangle(Wayland_Surface *ws, int32_t x, int32_t y, int32_t width, int32_t height) -{ - Wayland_Compositor *comp; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - comp = e_mod_comp_wl_comp_get(); - pixman_region32_union_rect(&ws->damage, &ws->damage, - ws->x + x, ws->y + y, width, height); - e_mod_comp_wl_comp_schedule_repaint(); -} - -static void -_e_mod_comp_wl_surface_flush_damage(Wayland_Surface *ws) -{ - Wayland_Compositor *comp; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - comp = e_mod_comp_wl_comp_get(); - if (ws->link.next != &comp->surfaces) - { - Wayland_Surface *below; - - below = container_of(ws->link.next, Wayland_Surface, link); - pixman_region32_union(&below->damage, &below->damage, &ws->damage); - } -} - -static void -_e_mod_comp_wl_surface_raise(Wayland_Surface *ws) -{ - Wayland_Compositor *comp; - - LOGFN(__FILE__, __LINE__, __FUNCTION__); - - comp = e_mod_comp_wl_comp_get(); - wl_list_remove(&ws->link); - wl_list_insert(&comp->surfaces, &ws->link); - e_mod_comp_wl_comp_repick(); - e_mod_comp_wl_surface_damage_surface(ws); -} diff --git a/src/modules/comp/e_mod_comp_wl_surface.h b/src/modules/comp/e_mod_comp_wl_surface.h index 78a0dd06b..23841ee77 100644 --- a/src/modules/comp/e_mod_comp_wl_surface.h +++ b/src/modules/comp/e_mod_comp_wl_surface.h @@ -3,21 +3,15 @@ # ifndef E_MOD_COMP_WL_SURFACE_H # define E_MOD_COMP_WL_SURFACE_H -Wayland_Surface *e_mod_comp_wl_surface_create(int32_t x, int32_t y, int32_t width, int32_t height); +Wayland_Surface *e_mod_comp_wl_surface_create(int32_t x, int32_t y, int32_t w, int32_t h); void e_mod_comp_wl_surface_destroy(struct wl_client *client __UNUSED__, struct wl_resource *resource); void e_mod_comp_wl_surface_attach(struct wl_client *client __UNUSED__, struct wl_resource *resource, struct wl_resource *buffer_resource, int32_t x, int32_t y); void e_mod_comp_wl_surface_damage(struct wl_client *client __UNUSED__, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height); void e_mod_comp_wl_surface_frame(struct wl_client *client, struct wl_resource *resource, uint32_t callback); void e_mod_comp_wl_surface_destroy_surface(struct wl_resource *resource); -void e_mod_comp_wl_surface_draw(Wayland_Surface *ws, Wayland_Output *output __UNUSED__, pixman_region32_t *clip); -void e_mod_comp_wl_surface_damage_surface(Wayland_Surface *ws); -void e_mod_comp_wl_surface_transform(Wayland_Surface *ws, int32_t x, int32_t y, int32_t *sx, int32_t *sy); void e_mod_comp_wl_surface_configure(Wayland_Surface *ws, int32_t x, int32_t y, int32_t width, int32_t height); -void e_mod_comp_wl_surface_assign_output(Wayland_Surface *ws); -void e_mod_comp_wl_surface_damage_below(Wayland_Surface *ws); -void e_mod_comp_wl_surface_activate(Wayland_Surface *ws, Wayland_Input *device, uint32_t timestamp); -Eina_Bool e_mod_comp_wl_surface_move(Wayland_Surface *ws, Wayland_Input *wi, uint32_t timestamp); -Eina_Bool e_mod_comp_wl_surface_resize(Wayland_Shell_Surface *wss, Wayland_Input *wi, uint32_t timestamp, uint32_t edges); +void e_mod_comp_wl_surface_activate(Wayland_Surface *ws, Wayland_Input *wi, uint32_t timestamp); +void e_mod_comp_wl_surface_damage_surface(Wayland_Surface *ws); # endif #endif