#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)
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)
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);
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",
return 0;
}
- return gem->name;
+ return bo_emulator->sfc->gem.name;
}
MODULEINITPPROTO(tbm_bufmgr_emulator_init);