*/
if (drv_num_buffers_per_bo(bo_) != 1) {
cros_gralloc_error("Can only support one buffer per bo.");
- return CROS_GRALLOC_ERROR_NO_RESOURCES;
+ return -EINVAL;
}
if (flags) {
if (vaddr == MAP_FAILED) {
cros_gralloc_error("Mapping failed.");
- return CROS_GRALLOC_ERROR_UNSUPPORTED;
+ return -EFAULT;
}
addr[0] = static_cast<uint8_t *>(vaddr);
addr[plane] = addr[0] + drv_bo_get_plane_offset(bo_, plane);
lockcount_++;
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
int32_t cros_gralloc_buffer::unlock()
{
if (lockcount_ <= 0) {
cros_gralloc_error("Buffer was not locked.");
- return CROS_GRALLOC_ERROR_UNSUPPORTED;
+ return -EINVAL;
}
if (!--lockcount_) {
}
}
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
drmFreeVersion(version);
drv_ = drv_create(fd);
if (drv_)
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
}
- return CROS_GRALLOC_ERROR_NO_RESOURCES;
+ return -ENODEV;
}
bool cros_gralloc_driver::is_supported(const struct cros_gralloc_buffer_descriptor *descriptor)
descriptor->drv_usage);
if (!bo) {
cros_gralloc_error("Failed to create bo.");
- return CROS_GRALLOC_ERROR_NO_RESOURCES;
+ return -ENOMEM;
}
/*
if (drv_num_buffers_per_bo(bo) != 1) {
drv_bo_destroy(bo);
cros_gralloc_error("Can only support one buffer per bo.");
- return CROS_GRALLOC_ERROR_NO_RESOURCES;
+ return -EINVAL;
}
hnd = new cros_gralloc_handle();
buffers_.emplace(id, buffer);
handles_.emplace(hnd, std::make_pair(buffer, 1));
*out_handle = &hnd->base;
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
auto buffer = get_buffer(hnd);
if (buffer) {
handles_[hnd].second++;
buffer->increase_refcount();
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
if (drmPrimeFDToHandle(drv_get_fd(drv_), hnd->fds[0], &id)) {
cros_gralloc_error("drmPrimeFDToHandle failed.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -errno;
}
if (buffers_.count(id)) {
bo = drv_bo_import(drv_, &data);
if (!bo)
- return CROS_GRALLOC_ERROR_NO_RESOURCES;
+ return -EFAULT;
id = drv_bo_get_plane_handle(bo, 0).u32;
}
handles_.emplace(hnd, std::make_pair(buffer, 1));
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
int32_t cros_gralloc_driver::release(buffer_handle_t handle)
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
auto buffer = get_buffer(hnd);
if (!buffer) {
cros_gralloc_error("Invalid Reference.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
if (!--handles_[hnd].second)
delete buffer;
}
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence, uint64_t flags,
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
auto buffer = get_buffer(hnd);
if (!buffer) {
cros_gralloc_error("Invalid Reference.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
if (acquire_fence >= 0) {
cros_gralloc_error("Sync wait not yet supported.");
- return CROS_GRALLOC_ERROR_UNSUPPORTED;
+ return -EINVAL;
}
return buffer->lock(flags, addr);
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
auto buffer = get_buffer(hnd);
if (!buffer) {
cros_gralloc_error("Invalid Reference.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
return buffer->unlock();
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
auto buffer = get_buffer(hnd);
if (!buffer) {
cros_gralloc_error("Invalid Reference.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
*out_store = static_cast<uint64_t>(buffer->get_id());
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
cros_gralloc_buffer *cros_gralloc_driver::get_buffer(cros_gralloc_handle_t hnd)
#ifndef CROS_GRALLOC_TYPES_H
#define CROS_GRALLOC_TYPES_H
-typedef enum {
- CROS_GRALLOC_ERROR_NONE = 0,
- CROS_GRALLOC_ERROR_BAD_DESCRIPTOR = 1,
- CROS_GRALLOC_ERROR_BAD_HANDLE = 2,
- CROS_GRALLOC_ERROR_BAD_VALUE = 3,
- CROS_GRALLOC_ERROR_NOT_SHARED = 4,
- CROS_GRALLOC_ERROR_NO_RESOURCES = 5,
- CROS_GRALLOC_ERROR_UNDEFINED = 6,
- CROS_GRALLOC_ERROR_UNSUPPORTED = 7,
-} cros_gralloc_error_t;
-
struct cros_gralloc_buffer_descriptor {
uint32_t width;
uint32_t height;
"drv_format: %4.4s, drv_flags: %llu",
format, usage, reinterpret_cast<char *>(&descriptor.drm_format),
static_cast<unsigned long long>(descriptor.drv_usage));
- return CROS_GRALLOC_ERROR_UNSUPPORTED;
+ return -EINVAL;
}
ret = mod->driver->allocate(&descriptor, handle);
auto hnd = cros_gralloc_convert_handle(*handle);
*stride = hnd->pixel_stride;
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
static int gralloc0_free(alloc_device_t *dev, buffer_handle_t handle)
static int gralloc0_close(struct hw_device_t *dev)
{
/* Memory is freed by managed pointers on process close. */
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
static int gralloc0_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev)
if (module->alloc) {
*dev = &module->alloc->common;
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
if (strcmp(name, GRALLOC_HARDWARE_GPU0)) {
cros_gralloc_error("Incorrect device name - %s.", name);
- return CROS_GRALLOC_ERROR_UNSUPPORTED;
+ return -EINVAL;
}
module->driver = std::make_unique<cros_gralloc_driver>();
if (module->driver->init()) {
cros_gralloc_error("Failed to initialize driver.");
- return CROS_GRALLOC_ERROR_NO_RESOURCES;
+ return -ENOMEM;
}
module->alloc = std::make_unique<alloc_device_t>();
module->alloc->common.close = gralloc0_close;
*dev = &module->alloc->common;
- return CROS_GRALLOC_ERROR_NONE;
+ return 0;
}
static int gralloc0_register_buffer(struct gralloc_module_t const *module, buffer_handle_t handle)
mod->driver = std::make_unique<cros_gralloc_driver>();
if (mod->driver->init()) {
cros_gralloc_error("Failed to initialize driver.");
- return CROS_GRALLOC_ERROR_NO_RESOURCES;
+ return -ENOMEM;
}
}
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
if ((hnd->droid_format == HAL_PIXEL_FORMAT_YCbCr_420_888)) {
cros_gralloc_error("HAL_PIXEL_FORMAT_YCbCr_*_888 format not compatible.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
fence = -1;
case GRALLOC_DRM_GET_BACKING_STORE:
break;
default:
- return CROS_GRALLOC_ERROR_UNSUPPORTED;
+ return -EINVAL;
}
va_start(args, op);
- ret = CROS_GRALLOC_ERROR_NONE;
+ ret = 0;
handle = va_arg(args, buffer_handle_t);
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
switch (op) {
ret = mod->driver->get_backing_store(handle, out_store);
break;
default:
- ret = CROS_GRALLOC_ERROR_UNSUPPORTED;
+ ret = -EINVAL;
}
va_end(args);
auto hnd = cros_gralloc_convert_handle(handle);
if (!hnd) {
cros_gralloc_error("Invalid handle.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
if ((hnd->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) &&
(hnd->droid_format != HAL_PIXEL_FORMAT_YV12) &&
(hnd->droid_format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED)) {
cros_gralloc_error("Non-YUV format not compatible.");
- return CROS_GRALLOC_ERROR_BAD_HANDLE;
+ return -EINVAL;
}
fence = -1;
break;
default:
mod->driver->unlock(handle);
- return CROS_GRALLOC_ERROR_UNSUPPORTED;
+ return -EINVAL;
}
- return ret;
+ return 0;
}
static struct hw_module_methods_t gralloc0_module_methods = {.open = gralloc0_open };