summaryrefslogtreecommitdiff
path: root/cros_gralloc
diff options
context:
space:
mode:
Diffstat (limited to 'cros_gralloc')
-rw-r--r--cros_gralloc/cros_alloc_device.cc31
-rw-r--r--cros_gralloc/cros_gralloc.h12
-rw-r--r--cros_gralloc/cros_gralloc_handle.h6
-rw-r--r--cros_gralloc/cros_gralloc_helpers.cc10
-rw-r--r--cros_gralloc/cros_gralloc_helpers.h16
-rw-r--r--cros_gralloc/cros_gralloc_module.cc77
6 files changed, 69 insertions, 83 deletions
diff --git a/cros_gralloc/cros_alloc_device.cc b/cros_gralloc/cros_alloc_device.cc
index 86d5e34..6477c0d 100644
--- a/cros_gralloc/cros_alloc_device.cc
+++ b/cros_gralloc/cros_alloc_device.cc
@@ -6,8 +6,7 @@
#include "cros_gralloc.h"
-static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv,
- int width, int height,
+static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv, int width, int height,
int format, int usage)
{
uint64_t drv_usage;
@@ -29,9 +28,8 @@ static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv,
if (!combo) {
cros_gralloc_error("Unsupported combination -- HAL format: %u, "
"HAL flags: %u, drv_format: %4.4s, "
- "drv_flags: %llu", format, usage,
- reinterpret_cast<char*>(&drv_format),
- drv_usage);
+ "drv_flags: %llu",
+ format, usage, reinterpret_cast<char *>(&drv_format), drv_usage);
return NULL;
}
@@ -85,7 +83,7 @@ static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo)
mod = drv_bo_get_plane_format_modifier(bo, p);
hnd->format_modifiers[p] = static_cast<uint32_t>(mod >> 32);
- hnd->format_modifiers[p+1] = static_cast<uint32_t>(mod);
+ hnd->format_modifiers[p + 1] = static_cast<uint32_t>(mod);
}
hnd->width = drv_bo_get_width(bo);
@@ -98,10 +96,10 @@ static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo)
return hnd;
}
-static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format,
- int usage, buffer_handle_t *handle, int *stride)
+static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format, int usage,
+ buffer_handle_t *handle, int *stride)
{
- auto mod = (struct cros_gralloc_module *) dev->common.module;
+ auto mod = (struct cros_gralloc_module *)dev->common.module;
std::lock_guard<std::mutex> lock(mod->mutex);
auto bo = cros_gralloc_bo_create(mod->drv, w, h, format, usage);
@@ -127,8 +125,8 @@ static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format,
static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle)
{
struct cros_gralloc_bo *bo;
- auto hnd = (struct cros_gralloc_handle *) handle;
- auto mod = (struct cros_gralloc_module *) dev->common.module;
+ auto hnd = (struct cros_gralloc_handle *)handle;
+ auto mod = (struct cros_gralloc_module *)dev->common.module;
std::lock_guard<std::mutex> lock(mod->mutex);
if (cros_gralloc_validate_handle(hnd)) {
@@ -151,8 +149,8 @@ static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle)
static int cros_gralloc_close(struct hw_device_t *dev)
{
- auto mod = (struct cros_gralloc_module *) dev->module;
- auto alloc = (struct alloc_device_t *) dev;
+ auto mod = (struct cros_gralloc_module *)dev->module;
+ auto alloc = (struct alloc_device_t *)dev;
std::lock_guard<std::mutex> lock(mod->mutex);
if (mod->drv) {
@@ -168,10 +166,9 @@ static int cros_gralloc_close(struct hw_device_t *dev)
return CROS_GRALLOC_ERROR_NONE;
}
-int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
- struct hw_device_t **dev)
+int cros_gralloc_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev)
{
- auto module = (struct cros_gralloc_module *) mod;
+ auto module = (struct cros_gralloc_module *)mod;
std::lock_guard<std::mutex> lock(module->mutex);
if (module->drv)
@@ -194,7 +191,7 @@ int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
alloc->free = cros_gralloc_free;
alloc->common.tag = HARDWARE_DEVICE_TAG;
alloc->common.version = 0;
- alloc->common.module = (hw_module_t*) mod;
+ alloc->common.module = (hw_module_t *)mod;
alloc->common.close = cros_gralloc_close;
*dev = &alloc->common;
diff --git a/cros_gralloc/cros_gralloc.h b/cros_gralloc/cros_gralloc.h
index a24b862..deca856 100644
--- a/cros_gralloc/cros_gralloc.h
+++ b/cros_gralloc/cros_gralloc.h
@@ -10,8 +10,8 @@
#include "cros_gralloc_helpers.h"
#include <mutex>
-#include <unordered_set>
#include <unordered_map>
+#include <unordered_set>
struct cros_gralloc_bo {
struct bo *bo;
@@ -30,16 +30,14 @@ struct cros_gralloc_module {
gralloc_module_t base;
struct driver *drv;
std::mutex mutex;
- std::unordered_map<cros_gralloc_handle*, handle_info> handles;
- std::unordered_map<uint32_t, cros_gralloc_bo*> buffers;
+ std::unordered_map<cros_gralloc_handle *, handle_info> handles;
+ std::unordered_map<uint32_t, cros_gralloc_bo *> buffers;
};
-int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
- struct hw_device_t **dev);
+int cros_gralloc_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev);
int cros_gralloc_validate_reference(struct cros_gralloc_module *mod,
- struct cros_gralloc_handle *hnd,
- struct cros_gralloc_bo **obj);
+ struct cros_gralloc_handle *hnd, struct cros_gralloc_bo **obj);
int cros_gralloc_decrement_reference_count(struct cros_gralloc_module *mod,
struct cros_gralloc_bo *obj);
diff --git a/cros_gralloc/cros_gralloc_handle.h b/cros_gralloc/cros_gralloc_handle.h
index 63b9da9..e2c0bcc 100644
--- a/cros_gralloc/cros_gralloc_handle.h
+++ b/cros_gralloc/cros_gralloc_handle.h
@@ -7,8 +7,8 @@
#ifndef CROS_GRALLOC_HANDLE_H
#define CROS_GRALLOC_HANDLE_H
-#include <cutils/native_handle.h>
#include <cstdint>
+#include <cutils/native_handle.h>
#define DRV_MAX_PLANES 4
@@ -26,11 +26,11 @@ struct cros_gralloc_handle {
uint32_t format_modifiers[2 * DRV_MAX_PLANES];
uint32_t width;
uint32_t height;
- uint32_t format; /* DRM format */
+ uint32_t format; /* DRM format */
uint32_t magic;
uint32_t pixel_stride;
int32_t droid_format;
- int32_t usage; /* Android usage. */
+ int32_t usage; /* Android usage. */
};
#endif
diff --git a/cros_gralloc/cros_gralloc_helpers.cc b/cros_gralloc/cros_gralloc_helpers.cc
index ed998e8..ed0a25a 100644
--- a/cros_gralloc/cros_gralloc_helpers.cc
+++ b/cros_gralloc/cros_gralloc_helpers.cc
@@ -32,12 +32,12 @@ uint64_t cros_gralloc_convert_flags(int flags)
if (flags & GRALLOC_USAGE_HW_2D)
usage |= BO_USE_RENDERING;
if (flags & GRALLOC_USAGE_HW_COMPOSER)
- /* HWC wants to use display hardware, but can defer to OpenGL. */
+ /* HWC wants to use display hardware, but can defer to OpenGL. */
usage |= BO_USE_SCANOUT | BO_USE_RENDERING;
if (flags & GRALLOC_USAGE_HW_FB)
usage |= BO_USE_NONE;
if (flags & GRALLOC_USAGE_EXTERNAL_DISP)
- /* We're ignoring this flag until we decide what to with display link */
+ /* We're ignoring this flag until we decide what to with display link */
usage |= BO_USE_NONE;
if (flags & GRALLOC_USAGE_PROTECTED)
usage |= BO_USE_PROTECTED;
@@ -86,8 +86,7 @@ uint32_t cros_gralloc_convert_format(int format)
return DRM_FORMAT_NONE;
}
-static int32_t cros_gralloc_query_rendernode(struct driver **drv,
- const char *undesired)
+static int32_t cros_gralloc_query_rendernode(struct driver **drv, const char *undesired)
{
/*
* Create a driver from rendernode while filtering out
@@ -154,8 +153,7 @@ int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd)
return CROS_GRALLOC_ERROR_NONE;
}
-void cros_gralloc_log(const char *prefix, const char *file, int line,
- const char *format, ...)
+void cros_gralloc_log(const char *prefix, const char *file, int line, const char *format, ...)
{
char buf[50];
snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line);
diff --git a/cros_gralloc/cros_gralloc_helpers.h b/cros_gralloc/cros_gralloc_helpers.h
index 7ba3a9a..0d79f92 100644
--- a/cros_gralloc/cros_gralloc_helpers.h
+++ b/cros_gralloc/cros_gralloc_helpers.h
@@ -33,12 +33,14 @@ typedef enum {
* reserved for cases where no alternative to get same information (such as
* querying ANativeWindow) exists.
*/
+// clang-format off
enum {
GRALLOC_DRM_GET_STRIDE,
GRALLOC_DRM_GET_FORMAT,
GRALLOC_DRM_GET_DIMENSIONS,
GRALLOC_DRM_GET_BACKING_STORE,
};
+// clang-format on
constexpr uint32_t cros_gralloc_magic(void)
{
@@ -74,14 +76,12 @@ int32_t cros_gralloc_rendernode_open(struct driver **drv);
int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
/* Logging code adapted from bsdrm */
-__attribute__((format(printf, 4, 5)))
-void cros_gralloc_log(const char *prefix, const char *file, int line,
- const char *format, ...);
-
-#define cros_gralloc_error(...) \
- do { \
- cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, \
- __LINE__, __VA_ARGS__); \
+__attribute__((format(printf, 4, 5))) void cros_gralloc_log(const char *prefix, const char *file,
+ int line, const char *format, ...);
+
+#define cros_gralloc_error(...) \
+ do { \
+ cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, __LINE__, __VA_ARGS__); \
} while (0)
#endif
diff --git a/cros_gralloc/cros_gralloc_module.cc b/cros_gralloc/cros_gralloc_module.cc
index ebc9c62..0101342 100644
--- a/cros_gralloc/cros_gralloc_module.cc
+++ b/cros_gralloc/cros_gralloc_module.cc
@@ -10,8 +10,7 @@
#include <xf86drm.h>
int cros_gralloc_validate_reference(struct cros_gralloc_module *mod,
- struct cros_gralloc_handle *hnd,
- struct cros_gralloc_bo **bo)
+ struct cros_gralloc_handle *hnd, struct cros_gralloc_bo **bo)
{
if (!mod->handles.count(hnd))
return CROS_GRALLOC_ERROR_BAD_HANDLE;
@@ -44,13 +43,13 @@ int cros_gralloc_decrement_reference_count(struct cros_gralloc_module *mod,
return CROS_GRALLOC_ERROR_NONE;
}
-static int cros_gralloc_register_buffer(struct gralloc_module_t const* module,
- buffer_handle_t handle)
+static int cros_gralloc_register_buffer(struct gralloc_module_t const *module,
+ buffer_handle_t handle)
{
uint32_t id;
struct cros_gralloc_bo *bo;
- auto hnd = (struct cros_gralloc_handle *) handle;
- auto mod = (struct cros_gralloc_module *) module;
+ auto hnd = (struct cros_gralloc_handle *)handle;
+ auto mod = (struct cros_gralloc_module *)module;
std::lock_guard<std::mutex> lock(mod->mutex);
if (cros_gralloc_validate_handle(hnd)) {
@@ -91,9 +90,9 @@ static int cros_gralloc_register_buffer(struct gralloc_module_t const* module,
data.strides[p] = hnd->strides[p];
data.offsets[p] = hnd->offsets[p];
data.sizes[p] = hnd->sizes[p];
- data.format_modifiers[p] = static_cast<uint64_t>
- (hnd->format_modifiers[p]) << 32;
- data.format_modifiers[p] |= hnd->format_modifiers[p+1];
+ data.format_modifiers[p] = static_cast<uint64_t>(hnd->format_modifiers[p])
+ << 32;
+ data.format_modifiers[p] |= hnd->format_modifiers[p + 1];
}
bo = new cros_gralloc_bo();
@@ -116,12 +115,12 @@ static int cros_gralloc_register_buffer(struct gralloc_module_t const* module,
return CROS_GRALLOC_ERROR_NONE;
}
-static int cros_gralloc_unregister_buffer(struct gralloc_module_t const* module,
+static int cros_gralloc_unregister_buffer(struct gralloc_module_t const *module,
buffer_handle_t handle)
{
struct cros_gralloc_bo *bo;
- auto hnd = (struct cros_gralloc_handle *) handle;
- auto mod = (struct cros_gralloc_module *) module;
+ auto hnd = (struct cros_gralloc_handle *)handle;
+ auto mod = (struct cros_gralloc_module *)module;
std::lock_guard<std::mutex> lock(mod->mutex);
if (cros_gralloc_validate_handle(hnd)) {
@@ -147,13 +146,12 @@ static int cros_gralloc_unregister_buffer(struct gralloc_module_t const* module,
return cros_gralloc_decrement_reference_count(mod, bo);
}
-static int cros_gralloc_lock(struct gralloc_module_t const* module,
- buffer_handle_t handle, int usage, int l, int t,
- int w, int h, void** vaddr)
+static int cros_gralloc_lock(struct gralloc_module_t const *module, buffer_handle_t handle,
+ int usage, int l, int t, int w, int h, void **vaddr)
{
struct cros_gralloc_bo *bo;
- auto mod = (struct cros_gralloc_module *) module;
- auto hnd = (struct cros_gralloc_handle *) handle;
+ auto mod = (struct cros_gralloc_module *)module;
+ auto hnd = (struct cros_gralloc_handle *)handle;
std::lock_guard<std::mutex> lock(mod->mutex);
if (cros_gralloc_validate_handle(hnd)) {
@@ -177,8 +175,7 @@ static int cros_gralloc_lock(struct gralloc_module_t const* module,
*vaddr = bo->map_data->addr;
} else {
*vaddr = drv_bo_map(bo->bo, 0, 0, drv_bo_get_width(bo->bo),
- drv_bo_get_height(bo->bo), 0,
- &bo->map_data, 0);
+ drv_bo_get_height(bo->bo), 0, &bo->map_data, 0);
}
if (*vaddr == MAP_FAILED) {
@@ -192,12 +189,11 @@ static int cros_gralloc_lock(struct gralloc_module_t const* module,
return CROS_GRALLOC_ERROR_NONE;
}
-static int cros_gralloc_unlock(struct gralloc_module_t const* module,
- buffer_handle_t handle)
+static int cros_gralloc_unlock(struct gralloc_module_t const *module, buffer_handle_t handle)
{
struct cros_gralloc_bo *bo;
- auto hnd = (struct cros_gralloc_handle *) handle;
- auto mod = (struct cros_gralloc_module *) module;
+ auto hnd = (struct cros_gralloc_handle *)handle;
+ auto mod = (struct cros_gralloc_module *)module;
std::lock_guard<std::mutex> lock(mod->mutex);
if (cros_gralloc_validate_handle(hnd)) {
@@ -218,8 +214,7 @@ static int cros_gralloc_unlock(struct gralloc_module_t const* module,
return CROS_GRALLOC_ERROR_NONE;
}
-static int cros_gralloc_perform(struct gralloc_module_t const* module,
- int op, ... )
+static int cros_gralloc_perform(struct gralloc_module_t const *module, int op, ...)
{
va_list args;
struct cros_gralloc_bo *bo;
@@ -227,7 +222,7 @@ static int cros_gralloc_perform(struct gralloc_module_t const* module,
uint64_t *out_store;
buffer_handle_t handle;
uint32_t *out_width, *out_height, *out_stride;
- auto mod = (struct cros_gralloc_module *) module;
+ auto mod = (struct cros_gralloc_module *)module;
std::lock_guard<std::mutex> lock(mod->mutex);
switch (op) {
@@ -242,7 +237,7 @@ static int cros_gralloc_perform(struct gralloc_module_t const* module,
va_start(args, op);
handle = va_arg(args, buffer_handle_t);
- auto hnd = (struct cros_gralloc_handle *) handle;
+ auto hnd = (struct cros_gralloc_handle *)handle;
if (cros_gralloc_validate_handle(hnd)) {
cros_gralloc_error("Invalid handle.");
@@ -282,16 +277,15 @@ static int cros_gralloc_perform(struct gralloc_module_t const* module,
return CROS_GRALLOC_ERROR_NONE;
}
-static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
- buffer_handle_t handle, int usage, int l,
- int t, int w, int h,
+static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const *module, buffer_handle_t handle,
+ int usage, int l, int t, int w, int h,
struct android_ycbcr *ycbcr)
{
uint8_t *addr = NULL;
size_t offsets[DRV_MAX_PLANES];
struct cros_gralloc_bo *bo;
- auto hnd = (struct cros_gralloc_handle *) handle;
- auto mod = (struct cros_gralloc_module *) module;
+ auto hnd = (struct cros_gralloc_handle *)handle;
+ auto mod = (struct cros_gralloc_module *)module;
std::lock_guard<std::mutex> lock(mod->mutex);
if (cros_gralloc_validate_handle(hnd)) {
@@ -316,8 +310,7 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
vaddr = bo->map_data->addr;
} else {
vaddr = drv_bo_map(bo->bo, 0, 0, drv_bo_get_width(bo->bo),
- drv_bo_get_height(bo->bo), 0,
- &bo->map_data, 0);
+ drv_bo_get_height(bo->bo), 0, &bo->map_data, 0);
}
if (vaddr == MAP_FAILED) {
@@ -325,7 +318,7 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
return CROS_GRALLOC_ERROR_UNSUPPORTED;
}
- addr = static_cast<uint8_t*>(vaddr);
+ addr = static_cast<uint8_t *>(vaddr);
}
for (size_t p = 0; p < drv_bo_get_num_planes(bo->bo); p++)
@@ -365,13 +358,13 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
return CROS_GRALLOC_ERROR_NONE;
}
-static struct hw_module_methods_t cros_gralloc_module_methods = {
- .open = cros_gralloc_open
-};
+static struct hw_module_methods_t cros_gralloc_module_methods = {.open = cros_gralloc_open };
struct cros_gralloc_module HAL_MODULE_INFO_SYM = {
- .base = {
- .common = {
+ .base =
+ {
+ .common =
+ {
.tag = HARDWARE_MODULE_TAG,
.module_api_version = GRALLOC_MODULE_API_VERSION_0_2,
.hal_api_version = 0,
@@ -379,14 +372,14 @@ struct cros_gralloc_module HAL_MODULE_INFO_SYM = {
.name = "CrOS Gralloc",
.author = "Chrome OS",
.methods = &cros_gralloc_module_methods,
- },
+ },
.registerBuffer = cros_gralloc_register_buffer,
.unregisterBuffer = cros_gralloc_unregister_buffer,
.lock = cros_gralloc_lock,
.unlock = cros_gralloc_unlock,
.perform = cros_gralloc_perform,
.lock_ycbcr = cros_gralloc_lock_ycbcr,
- },
+ },
.drv = NULL,
};