1
0
Fork 0

drm_hwcomposer: Update style to conform with Google Style Guide

Change-Id: I9b1a7dbcb9b8c6b0a6eb3c6416b5e4898a5097d8
Signed-off-by: Sean Paul <seanpaul@chromium.org>
This commit is contained in:
Sean Paul 2015-04-29 16:05:23 -04:00
parent 6efb79fc87
commit ef8f1f9905
4 changed files with 1207 additions and 1368 deletions

View file

@ -14,52 +14,60 @@
* limitations under the License.
*/
#ifndef ANDROID_DRM_HWCOMPOSER_H_
#define ANDROID_DRM_HWCOMPOSER_H_
#include <stdbool.h>
#include <stdint.h>
#include <hardware/hardware.h>
#include <hardware/hwcomposer.h>
struct hwc_import_context;
enum {
/* perform(const struct gralloc_module_t *mod,
* int op,
* int drm_fd,
* buffer_handle_t buffer,
* struct hwc_drm_bo *bo);
*/
GRALLOC_MODULE_PERFORM_DRM_IMPORT = 0xffeeff00,
/* perform(const struct gralloc_module_t *mod,
* int op,
* int drm_fd,
* buffer_handle_t buffer,
* struct hwc_drm_bo *bo);
*/
GRALLOC_MODULE_PERFORM_DRM_IMPORT = 0xffeeff00,
/* perform(const struct gralloc_module_t *mod,
* int op,
* buffer_handle_t buffer,
* void (*free_callback)(void *),
* void *priv);
*/
GRALLOC_MODULE_PERFORM_SET_IMPORTER_PRIVATE = 0xffeeff01,
/* perform(const struct gralloc_module_t *mod,
* int op,
* buffer_handle_t buffer,
* void (*free_callback)(void *),
* void *priv);
*/
GRALLOC_MODULE_PERFORM_SET_IMPORTER_PRIVATE = 0xffeeff01,
/* perform(const struct gralloc_module_t *mod,
* int op,
* buffer_handle_t buffer,
* void (*free_callback)(void *),
* void **priv);
*/
GRALLOC_MODULE_PERFORM_GET_IMPORTER_PRIVATE = 0xffeeff02,
/* perform(const struct gralloc_module_t *mod,
* int op,
* buffer_handle_t buffer,
* void (*free_callback)(void *),
* void **priv);
*/
GRALLOC_MODULE_PERFORM_GET_IMPORTER_PRIVATE = 0xffeeff02,
};
struct hwc_drm_bo {
uint32_t width;
uint32_t height;
uint32_t format; /* DRM_FORMAT_* from drm_fourcc.h */
uint32_t pitches[4];
uint32_t offsets[4];
uint32_t gem_handles[4];
uint32_t fb_id;
int acquire_fence_fd;
};
typedef struct hwc_drm_bo {
uint32_t width;
uint32_t height;
uint32_t format; /* DRM_FORMAT_* from drm_fourcc.h */
uint32_t pitches[4];
uint32_t offsets[4];
uint32_t gem_handles[4];
uint32_t fb_id;
int acquire_fence_fd;
} hwc_drm_bo_t;
int hwc_import_init(struct hwc_import_context **ctx);
int hwc_import_destroy(struct hwc_import_context *ctx);
int hwc_import_bo_create(int fd, struct hwc_import_context *ctx,
buffer_handle_t buf, struct hwc_drm_bo *bo);
buffer_handle_t buf, struct hwc_drm_bo *bo);
bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx,
struct hwc_drm_bo *bo);
struct hwc_drm_bo *bo);
#endif

File diff suppressed because it is too large Load diff

View file

@ -27,115 +27,98 @@
#include "drm_hwcomposer.h"
struct hwc_import_context {
struct drm_module_t *gralloc_module;
struct drm_module_t *gralloc_module;
};
int hwc_import_init(struct hwc_import_context **ctx)
{
int ret;
struct hwc_import_context *import_ctx;
int hwc_import_init(struct hwc_import_context **ctx) {
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;
}
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;
}
int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
(const hw_module_t **)&import_ctx->gralloc_module);
if (ret) {
ALOGE("Failed to open gralloc module");
free(import_ctx);
return ret;
}
*ctx = import_ctx;
*ctx = import_ctx;
return 0;
err:
free(import_ctx);
return ret;
return 0;
}
int hwc_import_destroy(struct hwc_import_context *ctx)
{
free(ctx);
return 0;
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;
}
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_import_bo_create(int fd, hwc_import_context *ctx,
buffer_handle_t handle, struct hwc_drm_bo *bo)
{
gralloc_drm_handle_t *gr_handle = gralloc_drm_handle(handle);
struct gralloc_drm_bo_t *gralloc_bo;
uint32_t gem_handle;
int ret;
buffer_handle_t handle, struct hwc_drm_bo *bo) {
gralloc_drm_handle_t *gr_handle = gralloc_drm_handle(handle);
if (!gr_handle)
return -EINVAL;
if (!gr_handle)
return -EINVAL;
struct gralloc_drm_bo_t *gralloc_bo = gr_handle->data;
if (!gralloc_bo) {
ALOGE("Could not get drm bo from handle");
return -EINVAL;
}
gralloc_bo = gr_handle->data;
if (!gralloc_bo) {
ALOGE("Could not get drm bo from handle");
return -EINVAL;
}
uint32_t gem_handle;
int ret = drmPrimeFDToHandle(fd, gr_handle->prime_fd, &gem_handle);
if (ret) {
ALOGE("failed to import prime fd %d ret=%d", gr_handle->prime_fd, ret);
return ret;
}
ret = drmPrimeFDToHandle(fd, gr_handle->prime_fd, &gem_handle);
if (ret) {
ALOGE("failed to import prime fd %d ret=%d",
gr_handle->prime_fd, ret);
return ret;
}
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] = gem_handle;
bo->offsets[0] = 0;
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] = gem_handle;
bo->offsets[0] = 0;
ret = drmModeAddFB2(fd, bo->width, bo->height, bo->format, bo->gem_handles,
bo->pitches, bo->offsets, &bo->fb_id, 0);
if (ret) {
ALOGE("could not create drm fb %d", ret);
return ret;
}
ret = drmModeAddFB2(fd, bo->width, bo->height, bo->format,
bo->gem_handles, bo->pitches, bo->offsets,
&bo->fb_id, 0);
if (ret) {
ALOGE("could not create drm fb %d", ret);
return ret;
}
return ret;
return ret;
}
bool hwc_import_bo_release(int fd, hwc_import_context *ctx,
struct hwc_drm_bo *bo)
{
(void)ctx;
bool hwc_import_bo_release(int fd, hwc_import_context */* ctx */,
struct hwc_drm_bo *bo) {
if (bo->fb_id)
if (drmModeRmFB(fd, bo->fb_id))
ALOGE("Failed to rm fb");
if (bo->fb_id)
if (drmModeRmFB(fd, bo->fb_id))
ALOGE("Failed to rm fb");
/* hwc may close the gem handles now. */
return true;
/* hwc may close the gem handles now. */
return true;
}

View file

@ -15,7 +15,6 @@
* limitations under the License.
*/
#include <cutils/log.h>
#include <hardware/gralloc.h>
@ -27,146 +26,128 @@
#define ARRAY_SIZE(arr) (int)(sizeof(arr) / sizeof((arr)[0]))
struct hwc_import_context {
const gralloc_module_t *gralloc_module;
const gralloc_module_t *gralloc_module;
};
int hwc_import_init(struct hwc_import_context **ctx)
{
int ret;
struct hwc_import_context *import_ctx;
int hwc_import_init(struct hwc_import_context **ctx) {
struct hwc_import_context *import_ctx = (struct hwc_import_context *)calloc(1, sizeof(*import_ctx));
if (!ctx) {
ALOGE("Failed to allocate gralloc import context");
return -ENOMEM;
}
import_ctx = (struct hwc_import_context *)calloc(1,
sizeof(*import_ctx));
if (!ctx) {
ALOGE("Failed to allocate gralloc import context");
return -ENOMEM;
}
int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
(const hw_module_t **)&import_ctx->gralloc_module);
if (ret) {
ALOGE("Failed to open gralloc module");
free(import_ctx);
return ret;
}
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;
}
if (!strcasecmp(import_ctx->gralloc_module->common.author, "NVIDIA"))
ALOGW("Using non-NVIDIA gralloc module: %s\n",
import_ctx->gralloc_module->common.name);
if (!strcasecmp(import_ctx->gralloc_module->common.author, "NVIDIA"))
ALOGW("Using non-NVIDIA gralloc module: %s\n",
import_ctx->gralloc_module->common.name);
*ctx = import_ctx;
*ctx = import_ctx;
return 0;
err:
free(import_ctx);
return ret;
return 0;
}
int hwc_import_destroy(struct hwc_import_context *ctx)
{
free(ctx);
return 0;
int hwc_import_destroy(struct hwc_import_context *ctx) {
free(ctx);
return 0;
}
struct importer_priv
{
int drm_fd;
struct hwc_drm_bo bo;
struct importer_priv {
int drm_fd;
struct hwc_drm_bo bo;
};
static void free_priv(void *p)
{
struct importer_priv *priv = (struct importer_priv *)p;
struct drm_gem_close gem_close;
int i, ret;
static void free_priv(void *p) {
struct importer_priv *priv = (struct importer_priv *)p;
if (priv->bo.fb_id) {
int ret = drmModeRmFB(priv->drm_fd, priv->bo.fb_id);
if (ret)
ALOGE("Failed to rm fb %d", ret);
}
if (priv->bo.fb_id) {
ret = drmModeRmFB(priv->drm_fd, priv->bo.fb_id);
if (ret)
ALOGE("Failed to rm fb %d", ret);
}
struct drm_gem_close gem_close;
memset(&gem_close, 0, sizeof(gem_close));
for (int i = 0; i < ARRAY_SIZE(priv->bo.gem_handles); i++) {
if (!priv->bo.gem_handles[i])
continue;
gem_close.handle = priv->bo.gem_handles[i];
int ret = drmIoctl(priv->drm_fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
if (ret)
ALOGE("Failed to close gem handle %d", ret);
}
memset(&gem_close, 0, sizeof(gem_close));
for (i = 0; i < ARRAY_SIZE(priv->bo.gem_handles); i++) {
if (!priv->bo.gem_handles[i])
continue;
gem_close.handle = priv->bo.gem_handles[i];
ret = drmIoctl(priv->drm_fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
if (ret)
ALOGE("Failed to close gem handle %d", ret);
}
free(priv);
free(priv);
}
static int
hwc_import_set_priv(hwc_import_context *ctx, buffer_handle_t handle, struct importer_priv *priv)
{
int ret;
const gralloc_module_t *g = ctx->gralloc_module;
return g->perform(g, GRALLOC_MODULE_PERFORM_SET_IMPORTER_PRIVATE, handle, free_priv, priv);
static int hwc_import_set_priv(hwc_import_context *ctx, buffer_handle_t handle,
struct importer_priv *priv) {
const gralloc_module_t *g = ctx->gralloc_module;
return g->perform(g, GRALLOC_MODULE_PERFORM_SET_IMPORTER_PRIVATE, handle,
free_priv, priv);
}
static struct importer_priv *
hwc_import_get_priv(hwc_import_context *ctx, buffer_handle_t handle)
{
int ret;
void *priv = NULL;
const gralloc_module_t *g = ctx->gralloc_module;
ret = g->perform(g, GRALLOC_MODULE_PERFORM_GET_IMPORTER_PRIVATE, handle, free_priv, &priv);
return ret ? NULL : (struct importer_priv *)priv;
static struct importer_priv *hwc_import_get_priv(hwc_import_context *ctx,
buffer_handle_t handle) {
const gralloc_module_t *g = ctx->gralloc_module;
void *priv = NULL;
int ret = g->perform(g, GRALLOC_MODULE_PERFORM_GET_IMPORTER_PRIVATE, handle,
free_priv, &priv);
return ret ? NULL : (struct importer_priv *)priv;
}
int hwc_import_bo_create(int fd, hwc_import_context *ctx,
buffer_handle_t handle, struct hwc_drm_bo *bo)
{
int ret = 0;
const gralloc_module_t *g = ctx->gralloc_module;
buffer_handle_t handle, struct hwc_drm_bo *bo) {
/* Get imported bo that is cached in gralloc buffer, or create a new one. */
struct importer_priv *priv = hwc_import_get_priv(ctx, handle);
if (priv) {
*bo = priv->bo;
return 0;
}
/* Get imported bo that is cached in gralloc buffer, or create a new one. */
struct importer_priv *priv = hwc_import_get_priv(ctx, handle);
if (!priv) {
priv = (struct importer_priv *)calloc(1, sizeof(*priv));
if (!priv)
return -ENOMEM;
priv->drm_fd = fd;
priv = (struct importer_priv *)calloc(1, sizeof(*priv));
if (!priv)
return -ENOMEM;
priv->drm_fd = fd;
ret = g->perform(g, GRALLOC_MODULE_PERFORM_DRM_IMPORT, fd, handle, &priv->bo);
if (ret) {
ALOGE("GRALLOC_MODULE_PERFORM_DRM_IMPORT failed %d", ret);
free_priv(priv);
return ret;
}
const gralloc_module_t *g = ctx->gralloc_module;
int ret =
g->perform(g, GRALLOC_MODULE_PERFORM_DRM_IMPORT, fd, handle, &priv->bo);
if (ret) {
ALOGE("GRALLOC_MODULE_PERFORM_DRM_IMPORT failed %d", ret);
free_priv(priv);
return ret;
}
ret = drmModeAddFB2(fd, priv->bo.width, priv->bo.height,
priv->bo.format, priv->bo.gem_handles,
priv->bo.pitches, priv->bo.offsets,
&priv->bo.fb_id, 0);
if (ret) {
ALOGE("Failed to add fb %d", ret);
free_priv(priv);
return ret;
}
ret = drmModeAddFB2(fd, priv->bo.width, priv->bo.height, priv->bo.format,
priv->bo.gem_handles, priv->bo.pitches,
priv->bo.offsets, &priv->bo.fb_id, 0);
if (ret) {
ALOGE("Failed to add fb %d", ret);
free_priv(priv);
return ret;
}
ret = hwc_import_set_priv(ctx, handle, priv);
if (ret) {
/* This will happen is persist.tegra.gpu_mapping_cache is 0/off,
* or if NV gralloc runs out of "priv slots" (currently 3 per buffer,
* only one of which should be used by drm_hwcomposer). */
ALOGE("Failed to register free callback for imported buffer %d", ret);
free_priv(priv);
return ret;
}
}
*bo = priv->bo;
return ret;
ret = hwc_import_set_priv(ctx, handle, priv);
if (ret) {
/* This will happen is persist.tegra.gpu_mapping_cache is 0/off,
* or if NV gralloc runs out of "priv slots" (currently 3 per buffer,
* only one of which should be used by drm_hwcomposer). */
ALOGE("Failed to register free callback for imported buffer %d", ret);
free_priv(priv);
return ret;
}
*bo = priv->bo;
return ret;
}
bool hwc_import_bo_release(int fd, hwc_import_context *ctx,
struct hwc_drm_bo *bo)
{
/* hwc may not close the gem handles, we own them */
return false;
struct hwc_drm_bo *bo) {
/* hwc may not close the gem handles, we own them */
return false;
}