diff options
author | Sean Paul <seanpaul@chromium.org> | 2015-01-22 18:01:18 -0500 |
---|---|---|
committer | Sean Paul <seanpaul@google.com> | 2015-02-04 14:46:27 -0800 |
commit | cd36a9e3864aaba47ba22af36fad97fe6c782637 (patch) | |
tree | 77dcf322fd9ca9e7d872a450464bbea9991d5b12 /hwcomposer_import_drm_gralloc.cpp | |
parent | 9aa5ad3e2e25610c86ffc0714302b5905fbb8451 (diff) |
drm_hwcomposer: Split gralloc out into an importer
Add the concept of an importer so we can plug in different
sources of bo.
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Change-Id: I4f741ef4fa7c44e9cb31db61a146aed273854a69
Diffstat (limited to 'hwcomposer_import_drm_gralloc.cpp')
-rw-r--r-- | hwcomposer_import_drm_gralloc.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/hwcomposer_import_drm_gralloc.cpp b/hwcomposer_import_drm_gralloc.cpp new file mode 100644 index 0000000..065170c --- /dev/null +++ b/hwcomposer_import_drm_gralloc.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include <cutils/log.h> + +#include <drm/drm_fourcc.h> + +#include <gralloc_drm.h> +#include <gralloc_drm_priv.h> +#include <gralloc_drm_handle.h> + +#include "drm_hwcomposer.h" + +struct hwc_import_context { + struct drm_module_t *gralloc_module; +}; + +int hwc_import_init(struct hwc_import_context **ctx) +{ + int ret; + struct hwc_import_context *import_ctx; + + import_ctx = (struct hwc_import_context *)calloc(1, + sizeof(*import_ctx)); + if (!ctx) { + ALOGE("Failed to allocate gralloc import context"); + return -ENOMEM; + } + + ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, + (const hw_module_t **)&import_ctx->gralloc_module); + if (ret) { + ALOGE("Failed to open gralloc module"); + goto err; + } + + *ctx = import_ctx; + + return 0; + +err: + free(import_ctx); + return ret; +} + +int hwc_import_destroy(struct hwc_import_context *ctx) +{ + free(ctx); + return 0; +} + +static uint32_t hwc_convert_hal_format_to_drm_format(uint32_t hal_format) +{ + switch(hal_format) { + case HAL_PIXEL_FORMAT_RGB_888: + return DRM_FORMAT_BGR888; + case HAL_PIXEL_FORMAT_BGRA_8888: + return DRM_FORMAT_ARGB8888; + case HAL_PIXEL_FORMAT_RGBX_8888: + return DRM_FORMAT_XBGR8888; + case HAL_PIXEL_FORMAT_RGBA_8888: + return DRM_FORMAT_ABGR8888; + case HAL_PIXEL_FORMAT_RGB_565: + return DRM_FORMAT_BGR565; + case HAL_PIXEL_FORMAT_YV12: + return DRM_FORMAT_YVU420; + default: + ALOGE("Cannot convert hal format to drm format %u", hal_format); + return -EINVAL; + } +} + +int hwc_create_bo_from_import(int /* fd */, hwc_import_context *ctx, + buffer_handle_t handle, struct hwc_drm_bo *bo) +{ + gralloc_drm_t *drm = ctx->gralloc_module->drm; + gralloc_drm_handle_t *gr_handle; + struct gralloc_drm_bo_t *gralloc_bo; + gr_handle = (gralloc_drm_handle_t *)handle; + + gralloc_bo = gr_handle->data; + if (!gralloc_bo) { + ALOGE("Could not get drm bo from handle"); + return -EINVAL; + } + + bo->importer_fd = drm->fd; + bo->width = gr_handle->width; + bo->height = gr_handle->height; + bo->format = hwc_convert_hal_format_to_drm_format(gr_handle->format); + bo->pitches[0] = gr_handle->stride; + bo->gem_handles[0] = gralloc_bo->fb_handle; + bo->offsets[0] = 0; + + return 0; +} |