All remaining operations implemented
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Fri, 7 Jun 2013 16:10:39 +0000 (20:10 +0400)
committerStanislav Vorobiov <s.vorobiov@samsung.com>
Fri, 7 Jun 2013 16:10:39 +0000 (20:10 +0400)
Change-Id: I17c9d8e6332e081146c75ac9a2b38b11b46fe0c7

src/tbm_bufmgr_emulator.c

index 461559a971f7b672d45c9da7a9d892c4ee491a58..4184ebb193999d9a4494d2002b70a460f80ed79b 100644 (file)
@@ -7,6 +7,14 @@
 #include "vigs.h"
 #include "tbm_emulator_log.h"
 #include <string.h>
+#include <stdlib.h>
+
+struct tbm_bo_emulator
+{
+    struct vigs_drm_surface *sfc;
+
+    int is_write;
+};
 
 static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_gem *gem,
                                        int device)
@@ -48,24 +56,41 @@ static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_gem *gem,
 
 static void tbm_bufmgr_emulator_deinit(void *priv)
 {
+    struct vigs_drm_device *drm_dev = priv;
+
     TBM_EMULATOR_LOG_DEBUG("enter");
+
+    vigs_drm_device_destroy(drm_dev);
 }
 
 static int tbm_bufmgr_emulator_bo_size(tbm_bo bo)
 {
+    struct tbm_bo_emulator *bo_emulator;
+
     TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-    return 0;
+
+    bo_emulator = (struct tbm_bo_emulator*)tbm_backend_get_bo_priv(bo);
+
+    return bo_emulator->sfc->gem.size;
 }
 
 static void *tbm_bufmgr_emulator_bo_alloc(tbm_bo bo, int size, int flags)
 {
-    TBM_EMULATOR_LOG_DEBUG("enter");
+    TBM_EMULATOR_LOG_ERROR("not supported");
     return NULL;
 }
 
 static void tbm_bufmgr_emulator_bo_free(tbm_bo bo)
 {
+    struct tbm_bo_emulator *bo_emulator;
+
     TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
+
+    bo_emulator = (struct tbm_bo_emulator*)tbm_backend_get_bo_priv(bo);
+
+    vigs_drm_gem_unref(&bo_emulator->sfc->gem);
+
+    free(bo_emulator);
 }
 
 static void *tbm_bufmgr_emulator_bo_import(tbm_bo bo, unsigned int key)
@@ -73,6 +98,7 @@ static void *tbm_bufmgr_emulator_bo_import(tbm_bo bo, unsigned int key)
     struct vigs_drm_device *drm_dev;
     int ret;
     struct vigs_drm_surface *sfc;
+    struct tbm_bo_emulator *bo_emulator;
 
     TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %u", bo, key);
 
@@ -87,62 +113,110 @@ static void *tbm_bufmgr_emulator_bo_import(tbm_bo bo, unsigned int key)
         return NULL;
     }
 
+    bo_emulator = calloc(1, sizeof(*bo_emulator));
+
+    if (!bo_emulator) {
+        TBM_EMULATOR_LOG_ERROR("calloc failed");
+        vigs_drm_gem_unref(&sfc->gem);
+        return NULL;
+    }
+
+    bo_emulator->sfc = sfc;
+
     TBM_EMULATOR_LOG_DEBUG("handle = %u", sfc->gem.handle);
 
-    return sfc;
+    return bo_emulator;
 }
 
 static unsigned int tbm_bufmgr_emulator_bo_export(tbm_bo bo)
 {
+    struct tbm_bo_emulator *bo_emulator;
+    int ret;
+
     TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-    return 0;
+
+    bo_emulator = (struct tbm_bo_emulator*)tbm_backend_get_bo_priv(bo);
+
+    ret = vigs_drm_gem_get_name(&bo_emulator->sfc->gem);
+
+    if (ret != 0) {
+        TBM_EMULATOR_LOG_ERROR("vigs_drm_gem_get_name failed: %s",
+                               strerror(-ret));
+        return 0;
+    }
+
+    return bo_emulator->sfc->gem.name;
 }
 
 static tbm_bo_handle tbm_bufmgr_emulator_bo_get_handle(tbm_bo bo, int device)
 {
-    struct vigs_drm_gem *gem;
+    struct tbm_bo_emulator *bo_emulator;
 
     TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d", bo, device);
 
-    gem = (struct vigs_drm_gem*)tbm_backend_get_bo_priv(bo);
+    bo_emulator = (struct tbm_bo_emulator*)tbm_backend_get_bo_priv(bo);
 
-    return get_tbm_bo_handle(gem, device);
+    return get_tbm_bo_handle(&bo_emulator->sfc->gem, device);
 }
 
 static tbm_bo_handle tbm_bufmgr_emulator_bo_map(tbm_bo bo, int device, int opt)
 {
-    struct vigs_drm_gem *gem;
+    struct tbm_bo_emulator *bo_emulator;
+    tbm_bo_handle handle;
 
     TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d, opt = %d", bo, device, opt);
 
-    gem = (struct vigs_drm_gem*)tbm_backend_get_bo_priv(bo);
+    bo_emulator = (struct tbm_bo_emulator*)tbm_backend_get_bo_priv(bo);
+
+    handle = get_tbm_bo_handle(&bo_emulator->sfc->gem, device);
 
-    return get_tbm_bo_handle(gem, device);
+    if (!handle.ptr) {
+        return handle;
+    }
+
+    if ((opt & TBM_OPTION_READ) != 0) {
+        vigs_drm_surface_update_vram(bo_emulator->sfc);
+    }
+
+    if ((opt & TBM_OPTION_WRITE) != 0) {
+        bo_emulator->is_write = 1;
+    }
+
+    return handle;
 }
 
 static int tbm_bufmgr_emulator_bo_unmap(tbm_bo bo)
 {
+    struct tbm_bo_emulator *bo_emulator;
+
     TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
 
+    bo_emulator = (struct tbm_bo_emulator*)tbm_backend_get_bo_priv(bo);
+
+    if (bo_emulator->is_write) {
+        vigs_drm_surface_update_gpu(bo_emulator->sfc);
+        bo_emulator->is_write = 0;
+    }
+
     return 1;
 }
 
 static int tbm_bufmgr_emulator_bo_cache_flush(tbm_bo bo, int flags)
 {
     TBM_EMULATOR_LOG_DEBUG("bo = %p, flags = %d", bo, flags);
-    return 0;
+    return 1;
 }
 
 static int tbm_bufmgr_emulator_bo_get_global_key(tbm_bo bo)
 {
-    struct vigs_drm_gem *gem;
+    struct tbm_bo_emulator *bo_emulator;
     int ret;
 
     TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
 
-    gem = (struct vigs_drm_gem*)tbm_backend_get_bo_priv(bo);
+    bo_emulator = (struct tbm_bo_emulator*)tbm_backend_get_bo_priv(bo);
 
-    ret = vigs_drm_gem_get_name(gem);
+    ret = vigs_drm_gem_get_name(&bo_emulator->sfc->gem);
 
     if (ret != 0) {
         TBM_EMULATOR_LOG_ERROR("vigs_drm_gem_get_name failed: %s",
@@ -150,7 +224,7 @@ static int tbm_bufmgr_emulator_bo_get_global_key(tbm_bo bo)
         return 0;
     }
 
-    return gem->name;
+    return bo_emulator->sfc->gem.name;
 }
 
 MODULEINITPPROTO(tbm_bufmgr_emulator_init);