Created
January 4, 2016 22:06
-
-
Save nazgee/5101e74197c0ab733eb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static struct gbm_bo *gbm_kms_bo_create(struct gbm_device *gbm, | |
uint32_t width, uint32_t height, | |
uint32_t format, uint32_t usage) | |
{ | |
struct gbm_kms_device *dev = (struct gbm_kms_device*)gbm; | |
struct gbm_kms_bo *bo; | |
unsigned attr[] = { | |
KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8, | |
KMS_WIDTH, 0, | |
KMS_HEIGHT, 0, | |
KMS_TERMINATE_PROP_LIST | |
}; | |
GBM_DEBUG("%s: %s: %d\n", __FILE__, __func__, __LINE__); | |
if (!(bo = calloc(1, sizeof(struct gbm_kms_bo)))) | |
return NULL; | |
switch (format) { | |
// 32bpp | |
case GBM_FORMAT_ARGB8888: | |
case GBM_FORMAT_XRGB8888: | |
break; | |
default: | |
// unsupported... | |
goto error; | |
} | |
if (usage & GBM_BO_USE_CURSOR_64X64) | |
attr[1] = KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; | |
attr[3] = width; | |
attr[5] = height; | |
// Create BO | |
if (kms_bo_create(dev->kms, attr, &bo->bo)) | |
goto error; | |
bo->base.gbm = gbm; | |
bo->base.width = width; | |
bo->base.height = height; | |
bo->base.format = format; | |
kms_bo_get_prop(bo->bo, KMS_HANDLE, &bo->base.handle.u32); | |
kms_bo_get_prop(bo->bo, KMS_PITCH, &bo->base.stride); | |
bo->size = bo->base.stride * bo->base.height; | |
if (drmPrimeHandleToFD(dev->base.base.fd, bo->base.handle.u32, DRM_CLOEXEC, &bo->fd)) { | |
GBM_DEBUG("%s: %s: drmPrimeHandleToFD() failed. %s\n", __FILE__, __func__, strerror(errno)); | |
goto error; | |
} | |
// Map to the user space for bo_write | |
if (usage & GBM_BO_USE_WRITE) { | |
if (kms_bo_map(bo->bo, &bo->addr)) | |
goto error; | |
} | |
return (struct gbm_bo*)bo; | |
error: | |
GBM_DEBUG("%s: %s: %d: ERROR!!!!\n", __FILE__, __func__, __LINE__); | |
gbm_kms_bo_destroy((struct gbm_bo*)bo); | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment