stefan pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=d815d9bd108a11628ac4e8679957b05cf49b3c3f

commit d815d9bd108a11628ac4e8679957b05cf49b3c3f
Author: Chris Michael <cp.mich...@samsung.com>
Date:   Tue Apr 7 10:51:13 2015 -0400

    evas-drm: Use Ecore_Drm_Fb for framebuffers
    
    Summary: This commit changes the evas drm engine to use Ecore_Drm_Fb
    for framebuffers. We remove the old 'Buffer' structure from the evas
    engine and replace it in Outbuf with Ecore_Drm_Fb. This also removes
    unused functions from the evas_drm.c file as we can now use
    ecore_drm_fb calls
    
    @fix
    
    Signed-off-by: Chris Michael <cp.mich...@samsung.com>
---
 src/modules/evas/engines/drm/evas_drm.c    | 110 ++---------------------------
 src/modules/evas/engines/drm/evas_engine.h |  25 +------
 src/modules/evas/engines/drm/evas_outbuf.c |  55 ++++++---------
 3 files changed, 30 insertions(+), 160 deletions(-)

diff --git a/src/modules/evas/engines/drm/evas_drm.c 
b/src/modules/evas/engines/drm/evas_drm.c
index bf5bfb1..b44e344 100644
--- a/src/modules/evas/engines/drm/evas_drm.c
+++ b/src/modules/evas/engines/drm/evas_drm.c
@@ -233,7 +233,7 @@ evas_drm_outbuf_setup(Outbuf *ob)
 }
 
 void 
-evas_drm_outbuf_framebuffer_set(Outbuf *ob, Buffer *buffer)
+evas_drm_outbuf_framebuffer_set(Outbuf *ob, Ecore_Drm_Fb *buffer)
 {
    int ret;
 
@@ -242,115 +242,13 @@ evas_drm_outbuf_framebuffer_set(Outbuf *ob, Buffer 
*buffer)
 
    /* DBG("Drm Framebuffer Set: %d", buffer->fb); */
 
-   buffer->valid = EINA_FALSE;
-   ret = drmModeSetCrtc(ob->priv.fd, ob->priv.crtc, buffer->fb, 0, 0, 
+   ret = drmModeSetCrtc(ob->priv.fd, ob->priv.crtc, buffer->id, 0, 0, 
                         &ob->priv.conn, 1, &ob->priv.mode);
-
    if (ret) ERR("Failed to set crtc: %m");
-   else buffer->valid = EINA_TRUE;
-}
-
-Eina_Bool 
-evas_drm_framebuffer_create(int fd, Buffer *buffer, int depth)
-{
-   struct drm_mode_create_dumb carg;
-   struct drm_mode_destroy_dumb darg;
-   struct drm_mode_map_dumb marg;
-
-   /* check for valid info */
-   if (fd < 0) return EINA_FALSE;
-
-   /* try to create a dumb buffer */
-   memset(&carg, 0, sizeof(carg));
-   carg.width = buffer->w;
-   carg.height = buffer->h;
-   carg.bpp = depth;
-
-   if (drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &carg) < 0)
-     {
-        ERR("Could not create dumb buffer: %m");
-        return EINA_FALSE;
-     }
-
-   buffer->stride = carg.pitch;
-   buffer->size = carg.size;
-   buffer->handle = carg.handle;
-
-   DBG("Buffer: %d %d", buffer->w, buffer->h);
-   DBG("Buffer Stride: %d", buffer->stride);
-   DBG("Buffer Size: %d", buffer->size);
-
-   /* try to create a framebuffer object */
-   /* FIXME: Hardcoded bpp */
-   if (drmModeAddFB(fd, buffer->w, buffer->h, 24, depth, buffer->stride, 
-                    buffer->handle, &buffer->fb))
-     {
-        ERR("Could not create framebuffer object: %m");
-        goto add_err;
-     }
-
-   DBG("Creating dumb buffer: %d %d %d %d", buffer->fb, 
-       buffer->w, buffer->h, depth);
-
-   /* try to mmap the buffer */
-   memset(&marg, 0, sizeof(marg));
-   marg.handle = buffer->handle;
-   if (drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &marg))
-     {
-        ERR("Could not map dumb buffer: %m");
-        goto map_err;
-     }
-
-   /* do actual mmap of memory */
-   buffer->data = 
-     mmap(NULL, buffer->size, (PROT_READ | PROT_WRITE), 
-          MAP_SHARED, fd, marg.offset);
-   if (buffer->data == MAP_FAILED)
-     {
-        ERR("Could not mmap dumb buffer: %m");
-        goto map_err;
-     }
-
-   /* clear memory */
-   memset(buffer->data, 0, buffer->size);
-
-   return EINA_TRUE;
-
-map_err:
-   /* remove the framebuffer */
-   drmModeRmFB(fd, buffer->fb);
-
-add_err:
-   /* destroy buffer */
-   memset(&darg, 0, sizeof(darg));
-   darg.handle = buffer->handle;
-   drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);
-
-   return EINA_FALSE;
-}
-
-void 
-evas_drm_framebuffer_destroy(int fd, Buffer *buffer)
-{
-   struct drm_mode_destroy_dumb darg;
-
-   /* check for valid info */
-   if (fd < 0) return;
-
-   /* unmap the buffer data */
-   if (buffer->data) munmap(buffer->data, buffer->size);
-
-   /* remove the framebuffer */
-   drmModeRmFB(fd, buffer->fb);
-
-   /* destroy buffer */
-   memset(&darg, 0, sizeof(darg));
-   darg.handle = buffer->handle;
-   drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);
 }
 
 Eina_Bool 
-evas_drm_framebuffer_send(Outbuf *ob, Buffer *buffer)
+evas_drm_framebuffer_send(Outbuf *ob, Ecore_Drm_Fb *buffer)
 {
    /* check for valid Output buffer */
    if ((!ob) || (ob->priv.fd < 0)) return EINA_FALSE;
@@ -361,7 +259,7 @@ evas_drm_framebuffer_send(Outbuf *ob, Buffer *buffer)
    if (ob->vsync)
      {
         if (drmModePageFlip(ob->priv.fd, ob->priv.crtc, 
-                            buffer->fb, DRM_MODE_PAGE_FLIP_EVENT, ob) < 0)
+                            buffer->id, DRM_MODE_PAGE_FLIP_EVENT, ob) < 0)
           {
              ERR("Cannot flip crtc %u for connector %u: %m", 
                  ob->priv.crtc, ob->priv.conn);
diff --git a/src/modules/evas/engines/drm/evas_engine.h 
b/src/modules/evas/engines/drm/evas_engine.h
index 4bb6a91..7a4dffe 100644
--- a/src/modules/evas/engines/drm/evas_engine.h
+++ b/src/modules/evas/engines/drm/evas_engine.h
@@ -49,25 +49,8 @@ extern int _evas_engine_drm_log_dom;
 /* define a maximum number of 'buffers' (double-buff, triple-buff, etc) */
 # define NUM_BUFFERS 2
 
-typedef struct _Buffer Buffer;
 typedef struct _Plane Plane;
 
-struct _Buffer
-{
-   int w, h;
-   int stride, size;
-   int handle;
-   unsigned int fb;
-
-   void *data; // used for software framebuffers
-
-# ifdef HAVE_DRM_HW_ACCEL
-   void *bo; // used for hardware framebuffers
-# endif
-
-   Eina_Bool valid : 1;
-};
-
 struct _Plane
 {
    unsigned int id;
@@ -93,7 +76,7 @@ struct _Outbuf
 
    struct
    {
-      Buffer buffer[NUM_BUFFERS];
+      Ecore_Drm_Fb *buffer[NUM_BUFFERS];
 
       Eina_List *pending_writes;
       Eina_List *planes;
@@ -128,9 +111,7 @@ void evas_outbuf_update_region_free(Outbuf *ob, RGBA_Image 
*update);
 void evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *rects, Evas_Render_Mode 
render_mode);
 
 Eina_Bool evas_drm_outbuf_setup(Outbuf *ob);
-void evas_drm_outbuf_framebuffer_set(Outbuf *ob, Buffer *buffer);
-Eina_Bool evas_drm_framebuffer_create(int fd, Buffer *buffer, int depth);
-void evas_drm_framebuffer_destroy(int fd, Buffer *buffer);
-Eina_Bool evas_drm_framebuffer_send(Outbuf *ob, Buffer *buffer);
+void evas_drm_outbuf_framebuffer_set(Outbuf *ob, Ecore_Drm_Fb *buffer);
+Eina_Bool evas_drm_framebuffer_send(Outbuf *ob, Ecore_Drm_Fb *buffer);
 
 #endif
diff --git a/src/modules/evas/engines/drm/evas_outbuf.c 
b/src/modules/evas/engines/drm/evas_outbuf.c
index 0583c5a..a5df8fe 100644
--- a/src/modules/evas/engines/drm/evas_outbuf.c
+++ b/src/modules/evas/engines/drm/evas_outbuf.c
@@ -8,23 +8,8 @@
 #define GREEN_MASK 0x00ff00
 #define BLUE_MASK 0x0000ff
 
-static Eina_Bool 
-_evas_outbuf_buffer_new(Outbuf *ob, Buffer *buff)
-{
-   buff->w = ob->w;
-   buff->h = ob->h;
-   if (buff->w < ob->priv.mode.hdisplay) buff->w = ob->priv.mode.hdisplay;
-   if (buff->h < ob->priv.mode.vdisplay) buff->h = ob->priv.mode.vdisplay;
-
-   /* create a dumb framebuffer */
-   if (!evas_drm_framebuffer_create(ob->priv.fd, buff, ob->depth))
-     return EINA_FALSE;
-
-   return EINA_TRUE;
-}
-
 static void 
-_evas_outbuf_buffer_put(Outbuf *ob, Buffer *buffer, Eina_Rectangle *rects, 
unsigned int count)
+_evas_outbuf_buffer_put(Outbuf *ob, Ecore_Drm_Fb *buffer, Eina_Rectangle 
*rects, unsigned int count)
 {
    /* validate input params */
    if ((!ob) || (!buffer)) return;
@@ -44,7 +29,7 @@ _evas_outbuf_buffer_put(Outbuf *ob, Buffer *buffer, 
Eina_Rectangle *rects, unsig
      }
 
    /* DBG("Marking FB Dirty: %d", buffer->fb); */
-   ret = drmModeDirtyFB(ob->priv.fd, buffer->fb, clip, count);
+   ret = drmModeDirtyFB(ob->priv.fd, buffer->id, clip, count);
    if (ret)
      {
         if (ret == -EINVAL)
@@ -56,12 +41,12 @@ _evas_outbuf_buffer_put(Outbuf *ob, Buffer *buffer, 
Eina_Rectangle *rects, unsig
 static void 
 _evas_outbuf_buffer_swap(Outbuf *ob, Eina_Rectangle *rects, unsigned int count)
 {
-   Buffer *buff;
+   Ecore_Drm_Fb *buff;
 
-   buff = &(ob->priv.buffer[ob->priv.curr]);
+   buff = ob->priv.buffer[ob->priv.curr];
 
    /* if this buffer is not valid, we need to set it */
-   if (!buff->valid) evas_drm_outbuf_framebuffer_set(ob, buff);
+   evas_drm_outbuf_framebuffer_set(ob, buff);
 
    /* mark the fb as dirty */
    _evas_outbuf_buffer_put(ob, buff, rects, count);
@@ -84,6 +69,7 @@ evas_outbuf_setup(Evas_Engine_Info_Drm *info, int w, int h)
    ob->w = w;
    ob->h = h;
 
+   ob->info = info;
    ob->depth = info->info.depth;
    ob->rotation = info->info.rotation;
    ob->destination_alpha = info->info.destination_alpha;
@@ -124,18 +110,21 @@ evas_outbuf_setup(Evas_Engine_Info_Drm *info, int w, int 
h)
    /* try to create buffers */
    for (; i < ob->priv.num; i++)
      {
-        if (!_evas_outbuf_buffer_new(ob, &(ob->priv.buffer[i])))
-          break;
+        ob->priv.buffer[i] = 
+          ecore_drm_fb_create(ob->info->info.dev, ob->w, ob->h);
+        if (!ob->priv.buffer[i])
+          {
+             ERR("Failed to create buffer %d", i);
+             break;
+          }
      }
 
    /* set the front buffer to be the one on the crtc */
-   evas_drm_outbuf_framebuffer_set(ob, &(ob->priv.buffer[0]));
+   evas_drm_outbuf_framebuffer_set(ob, ob->priv.buffer[0]);
 
    /* set back buffer as first one to draw into */
    /* ob->priv.curr = (ob->priv.num - 1); */
 
-   ob->info = info;
-
    return ob;
 }
 
@@ -146,7 +135,7 @@ evas_outbuf_free(Outbuf *ob)
 
    /* destroy the old buffers */
    for (; i < ob->priv.num; i++)
-     evas_drm_framebuffer_destroy(ob->priv.fd, &(ob->priv.buffer[i]));
+     ecore_drm_fb_destroy(ob->priv.buffer[i]);
 
    /* free allocate space for outbuf */
    free(ob);
@@ -190,13 +179,15 @@ evas_outbuf_reconfigure(Outbuf *ob, int w, int h, int 
rot, Outbuf_Depth depth)
 
    /* destroy the old buffers */
    for (; i < ob->priv.num; i++)
-     evas_drm_framebuffer_destroy(ob->priv.fd, &(ob->priv.buffer[i]));
+     ecore_drm_fb_destroy(ob->priv.buffer[i]);
 
    for (i = 0; i < ob->priv.num; i++)
      {
-        if (!_evas_outbuf_buffer_new(ob, &(ob->priv.buffer[i])))
+        ob->priv.buffer[i] = 
+          ecore_drm_fb_create(ob->info->info.dev, ob->w, ob->h);
+        if (!ob->priv.buffer[i])
           {
-             CRI("Failed to create buffer");
+             ERR("Failed to create buffer %d", i);
              break;
           }
      }
@@ -290,7 +281,7 @@ evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image 
*update, int x, int y, int
    Eina_Rectangle rect = {0, 0, 0, 0}, pr;
    DATA32 *src;
    DATA8 *dst;
-   Buffer *buff;
+   Ecore_Drm_Fb *buff;
    int bpp = 0, bpl = 0;
    int rx = 0, ry = 0;
 
@@ -304,8 +295,8 @@ evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image 
*update, int x, int y, int
    if (!(src = update->image.data)) return;
 
    /* check for valid desination data */
-   buff = &(ob->priv.buffer[ob->priv.curr]);
-   if (!(dst = buff->data)) return;
+   buff = ob->priv.buffer[ob->priv.curr];
+   if (!(dst = buff->mmap)) return;
 
    if ((ob->rotation == 0) || (ob->rotation == 180))
      {

-- 


Reply via email to