wayland_shm: Refactor surface creation
authorDerek Foreman <derekf@osg.samsung.com>
Fri, 15 Apr 2016 15:38:28 +0000 (10:38 -0500)
committerMike Blumenkrantz <zmike@osg.samsung.com>
Tue, 19 Apr 2016 19:11:10 +0000 (15:11 -0400)
Split this into two parts, one that makes the base surface, one that
calls the potential back ends.

Once the dmabuf backend is added this will allow a fallback path to
re-initialize the surface as wl_shm if dmabuf fails.

src/modules/evas/engines/wayland_shm/evas_engine.h
src/modules/evas/engines/wayland_shm/evas_outbuf.c
src/modules/evas/engines/wayland_shm/evas_shm.c

index 2441c13c3f139a2c395a80ca721b382af632eac4..f76cf3ca5a67f49662318f1d81744c925581d679 100644 (file)
@@ -76,6 +76,7 @@ typedef struct _Shm_Surface Shm_Surface;
 
 typedef enum _Surface_Type Surface_Type;
 enum _Surface_Type {
+   SURFACE_EMPTY,
    SURFACE_SHM
 };
 
@@ -86,6 +87,7 @@ struct _Surface
    union {
       Shm_Surface *shm;
    } surf;
+   Evas_Engine_Info_Wayland_Shm *info;
    struct
      {
         void (*destroy)(Surface *surface);
@@ -125,7 +127,7 @@ struct _Outbuf
      } priv;
 };
 
-Surface *_evas_shm_surface_create(Evas_Engine_Info_Wayland_Shm *info, int w, int h, int num_buff);
+Eina_Bool _evas_shm_surface_create(Surface *s, int w, int h, int num_buff);
 
 Outbuf *_evas_outbuf_setup(int w, int h, Evas_Engine_Info_Wayland_Shm *info);
 void _evas_outbuf_free(Outbuf *ob);
@@ -140,4 +142,6 @@ void _evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image *update, int x, int
 void _evas_outbuf_update_region_free(Outbuf *ob, RGBA_Image *update);
 void _evas_surface_damage(struct wl_surface *s, int compositor_version, int w, int h, Eina_Rectangle *rects, unsigned int count);
 
+Eina_Bool _evas_surface_init(Surface *s, int w, int h, int num_buf);
+
 #endif
index b9a472ce18bde023a5d42e0ce07de1c38e41d1d5..1ba9a7dc373c14721236e37fbd266670bf6afe7c 100644 (file)
@@ -9,6 +9,30 @@
 #define GREEN_MASK 0x00ff00
 #define BLUE_MASK 0x0000ff
 
+Eina_Bool
+_evas_surface_init(Surface *s, int w, int h, int num_buf)
+{
+   if (_evas_shm_surface_create(s, w, h, num_buf)) return EINA_TRUE;
+
+   return EINA_FALSE;
+}
+
+static Surface *
+_evas_surface_create(Evas_Engine_Info_Wayland_Shm *info, int w, int h, int num_buf)
+{
+   Surface *out;
+
+   out = calloc(1, sizeof(*out));
+   if (!out) return NULL;
+   out->type = SURFACE_EMPTY;
+   out->info = info;
+
+   if (_evas_surface_init(out, w, h, num_buf)) return out;
+
+   free(out);
+   return NULL;
+}
+
 Outbuf *
 _evas_outbuf_setup(int w, int h, Evas_Engine_Info_Wayland_Shm *info)
 {
@@ -57,7 +81,7 @@ _evas_outbuf_setup(int w, int h, Evas_Engine_Info_Wayland_Shm *info)
      }
    else goto unhandled_rotation;
 
-   ob->surface = _evas_shm_surface_create(info, sw, sh, ob->num_buff);
+   ob->surface = _evas_surface_create(info, sw, sh, ob->num_buff);
    if (!ob->surface) goto surf_err;
 
 unhandled_rotation:
index f716865a45145db9785026eddfe7ee3f2239870e..2f4fe59245f085c2f2d04dce7ad4055b279af69b 100644 (file)
@@ -407,7 +407,6 @@ _evas_shm_surface_destroy(Surface *surface)
      _shm_leaf_destroy(&surface->surf.shm->leaf[i]);
 
    free(surface->surf.shm);
-   free(surface);
 }
 
 void 
@@ -568,28 +567,25 @@ _evas_shm_surface_post(Surface *s, Eina_Rectangle *rects, unsigned int count)
    surf->current = NULL;
 }
 
-Surface *
-_evas_shm_surface_create(Evas_Engine_Info_Wayland_Shm *info, int w, int h, int num_buff)
+Eina_Bool
+_evas_shm_surface_create(Surface *s, int w, int h, int num_buff)
 {
-   Surface *s;
    Shm_Surface *surf;
    int i = 0;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
-   if (!(s = calloc(1, sizeof(Surface)))) return NULL;
-   if (!(s->surf.shm = calloc(1, sizeof(Shm_Surface)))) goto err;
-   s->type = SURFACE_SHM;
+   if (!(s->surf.shm = calloc(1, sizeof(Shm_Surface)))) return EINA_FALSE;
    surf = s->surf.shm;
 
    surf->w = w;
    surf->h = h;
-   surf->disp = info->info.wl_disp;
-   surf->shm = info->info.wl_shm;
-   surf->surface = info->info.wl_surface;
+   surf->disp = s->info->info.wl_disp;
+   surf->shm = s->info->info.wl_shm;
+   surf->surface = s->info->info.wl_surface;
    surf->num_buff = num_buff;
-   surf->alpha = info->info.destination_alpha;
-   surf->compositor_version = info->info.compositor_version;
+   surf->alpha = s->info->info.destination_alpha;
+   surf->compositor_version = s->info->info.compositor_version;
 
    /* create surface buffers */
    for (; i < surf->num_buff; i++)
@@ -601,15 +597,16 @@ _evas_shm_surface_create(Evas_Engine_Info_Wayland_Shm *info, int w, int h, int n
           }
      }
 
+   s->type = SURFACE_SHM;
    s->funcs.destroy = _evas_shm_surface_destroy;
    s->funcs.reconfigure = _evas_shm_surface_reconfigure;
    s->funcs.data_get = _evas_shm_surface_data_get;
    s->funcs.assign = _evas_shm_surface_assign;
    s->funcs.post = _evas_shm_surface_post;
 
-   return s;
+   return EINA_TRUE;
 
 err:
    _evas_shm_surface_destroy(s);
-   return NULL;
+   return EINA_FALSE;
 }