From a669a5055eadae85ffa000cea19a2241d0699348 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 13 Aug 2012 15:55:23 +0200 Subject: gbm: Use libkms to replace DRI cursor images Uses libkms instead of dri image cursor. Since this is the only user of the DRI cursor and write interface we can remove cursor surfaces entirely from the DRI interface and as a consequence also from the Gallium interface as well. Tho to make everybody happy with this it would probably should add a kms_bo_write function, but that is probably wise in anyways. The only downside is that it adds a dependancy on libkms, this could how ever be replaced with the dumb_bo drm ioctl interface. Tested-by: Scott Moreau Signed-off-by: Jakob Bornecrantz --- src/gbm/backends/dri/gbm_dri.c | 65 ++++++++++++++++++++++++++++++++------- src/gbm/backends/dri/gbm_driint.h | 8 +++++ 2 files changed, 62 insertions(+), 11 deletions(-) (limited to 'src/gbm/backends') diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c index 5c332d48809..47874aede9c 100644 --- a/src/gbm/backends/dri/gbm_dri.c +++ b/src/gbm/backends/dri/gbm_dri.c @@ -299,13 +299,21 @@ gbm_dri_is_format_supported(struct gbm_device *gbm, static int gbm_dri_bo_write(struct gbm_bo *_bo, const void *buf, size_t count) { - struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm); struct gbm_dri_bo *bo = gbm_dri_bo(_bo); + void *ptr; + int ret; + + if (bo->bo == NULL) + return -1; - if (dri->image->base.version < 4) + ret = kms_bo_map(bo->bo, &ptr); + if (ret < 0) return -1; - return dri->image->write(bo->image, buf, count); + memcpy(ptr, buf, count); + + kms_bo_unmap(bo->bo); + return 0; } static void @@ -314,7 +322,10 @@ gbm_dri_bo_destroy(struct gbm_bo *_bo) struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm); struct gbm_dri_bo *bo = gbm_dri_bo(_bo); - dri->image->destroyImage(bo->image); + if (bo->image != NULL) + dri->image->destroyImage(bo->image); + if (bo->bo != NULL) + kms_bo_destroy(&bo->bo); free(bo); } @@ -446,9 +457,6 @@ gbm_dri_bo_create(struct gbm_device *gbm, int dri_format; unsigned dri_use = 0; - if (dri->image->base.version < 4 && (usage & GBM_BO_USE_WRITE)) - return NULL; - bo = calloc(1, sizeof *bo); if (bo == NULL) return NULL; @@ -457,6 +465,33 @@ gbm_dri_bo_create(struct gbm_device *gbm, bo->base.base.width = width; bo->base.base.height = height; + if (usage & GBM_BO_USE_WRITE) { + int ret; + unsigned attrs[7] = { + KMS_WIDTH, 64, + KMS_HEIGHT, 64, + KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8, + KMS_TERMINATE_PROP_LIST, + }; + + if (!(usage & GBM_BO_USE_CURSOR_64X64)) + return NULL; + + if (dri->kms == NULL) + return NULL; + + ret = kms_bo_create(dri->kms, attrs, &bo->bo); + if (ret < 0) { + free(bo); + return NULL; + } + + kms_bo_get_prop(bo->bo, KMS_PITCH, &bo->base.base.stride); + kms_bo_get_prop(bo->bo, KMS_HANDLE, (unsigned*)&bo->base.base.handle); + + return &bo->base.base; + } + switch (format) { case GBM_FORMAT_RGB565: dri_format =__DRI_IMAGE_FORMAT_RGB565; @@ -564,13 +599,21 @@ dri_device_create(int fd) dri->base.type = GBM_DRM_DRIVER_TYPE_DRI; dri->base.base.name = "drm"; + kms_create(fd, &dri->kms); + if (dri->kms == NULL) + goto err_kms; + ret = dri_screen_create(dri); - if (ret) { - free(dri); - return NULL; - } + if (ret) + goto err_dri; return &dri->base.base; + +err_dri: + kms_destroy(&dri->kms); +err_kms: + free(dri); + return NULL; } struct gbm_backend gbm_dri_backend = { diff --git a/src/gbm/backends/dri/gbm_driint.h b/src/gbm/backends/dri/gbm_driint.h index f4043683f11..4b619a0e59e 100644 --- a/src/gbm/backends/dri/gbm_driint.h +++ b/src/gbm/backends/dri/gbm_driint.h @@ -30,6 +30,8 @@ #include "gbmint.h" +#include "libkms.h" + #include "common.h" #include "common_drm.h" @@ -41,6 +43,9 @@ struct gbm_dri_surface; struct gbm_dri_device { struct gbm_drm_device base; + /* Only used for cursors */ + struct kms_driver *kms; + void *driver; __DRIscreen *screen; @@ -72,6 +77,9 @@ struct gbm_dri_bo { struct gbm_drm_bo base; __DRIimage *image; + + /* Only used for cursors */ + struct kms_bo *bo; }; struct gbm_dri_surface { -- cgit v1.2.3