--- /dev/null
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+BasedOnStyle: LLVM
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+BreakBeforeBraces: Linux
+ColumnLimit: 100
+IndentWidth: 8
+TabWidth: 8
+UseTab: Always
+Cpp11BracedListStyle: false
+IndentCaseLabels: false
--- /dev/null
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+[Hooks Scripts]
+hook0 = ./presubmit.sh
* found in the LICENSE file.
*/
#ifdef DRV_AMDGPU
+#include <amdgpu.h>
+#include <amdgpu_drm.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <xf86drm.h>
-#include <amdgpu_drm.h>
-#include <amdgpu.h>
#include "addrinterface.h"
#include "drv_priv.h"
#define CIASICIDGFXENGINE_SOUTHERNISLAND 0x0000000A
#endif
+// clang-format off
#define mmCC_RB_BACKEND_DISABLE 0x263d
#define mmGB_TILE_MODE0 0x2644
#define mmGB_MACROTILE_MODE0 0x2664
FAMILY_PI,
FAMILY_LAST,
};
+// clang-format on
-const static uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888
-};
+const static uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR8888,
+ DRM_FORMAT_XRGB8888 };
-static int amdgpu_set_metadata(int fd, uint32_t handle,
- struct amdgpu_bo_metadata *info)
+static int amdgpu_set_metadata(int fd, uint32_t handle, struct amdgpu_bo_metadata *info)
{
- struct drm_amdgpu_gem_metadata args = {0};
+ struct drm_amdgpu_gem_metadata args = { 0 };
if (!info)
return -EINVAL;
memcpy(args.data.data, info->umd_metadata, info->size_metadata);
}
- return drmCommandWriteRead(fd, DRM_AMDGPU_GEM_METADATA, &args,
- sizeof(args));
+ return drmCommandWriteRead(fd, DRM_AMDGPU_GEM_METADATA, &args, sizeof(args));
}
-static int amdgpu_read_mm_regs(int fd, unsigned dword_offset,
- unsigned count, uint32_t instance,
+static int amdgpu_read_mm_regs(int fd, unsigned dword_offset, unsigned count, uint32_t instance,
uint32_t flags, uint32_t *values)
{
struct drm_amdgpu_info request;
memset(&request, 0, sizeof(request));
- request.return_pointer = (uintptr_t) values;
+ request.return_pointer = (uintptr_t)values;
request.return_size = count * sizeof(uint32_t);
request.query = AMDGPU_INFO_READ_MMR_REG;
request.read_mmr_reg.dword_offset = dword_offset;
request.read_mmr_reg.instance = instance;
request.read_mmr_reg.flags = flags;
- return drmCommandWrite(fd, DRM_AMDGPU_INFO, &request,
- sizeof(struct drm_amdgpu_info));
+ return drmCommandWrite(fd, DRM_AMDGPU_INFO, &request, sizeof(struct drm_amdgpu_info));
}
static int amdgpu_query_gpu(int fd, struct amdgpu_gpu_info *gpu_info)
if (!gpu_info)
return -EINVAL;
- instance = AMDGPU_INFO_MMR_SH_INDEX_MASK <<
- AMDGPU_INFO_MMR_SH_INDEX_SHIFT;
+ instance = AMDGPU_INFO_MMR_SH_INDEX_MASK << AMDGPU_INFO_MMR_SH_INDEX_SHIFT;
ret = amdgpu_read_mm_regs(fd, mmCC_RB_BACKEND_DISABLE, 1, instance, 0,
&gpu_info->backend_disable[0]);
if (ret)
return ret;
/* extract bitfield CC_RB_BACKEND_DISABLE.BACKEND_DISABLE */
- gpu_info->backend_disable[0] =
- (gpu_info->backend_disable[0] >> 16) & 0xff;
+ gpu_info->backend_disable[0] = (gpu_info->backend_disable[0] >> 16) & 0xff;
- ret = amdgpu_read_mm_regs(fd, mmGB_TILE_MODE0, 32, 0xffffffff, 0,
- gpu_info->gb_tile_mode);
+ ret = amdgpu_read_mm_regs(fd, mmGB_TILE_MODE0, 32, 0xffffffff, 0, gpu_info->gb_tile_mode);
if (ret)
return ret;
if (ret)
return ret;
- ret = amdgpu_read_mm_regs(fd, mmGB_ADDR_CONFIG, 1, 0xffffffff, 0,
- &gpu_info->gb_addr_cfg);
+ ret = amdgpu_read_mm_regs(fd, mmGB_ADDR_CONFIG, 1, 0xffffffff, 0, &gpu_info->gb_addr_cfg);
if (ret)
return ret;
- ret = amdgpu_read_mm_regs(fd, mmMC_ARB_RAMCFG, 1, 0xffffffff, 0,
- &gpu_info->mc_arb_ramcfg);
+ ret = amdgpu_read_mm_regs(fd, mmMC_ARB_RAMCFG, 1, 0xffffffff, 0, &gpu_info->mc_arb_ramcfg);
if (ret)
return ret;
return ADDR_OK;
}
-static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
- uint32_t height, uint32_t format,
+static int amdgpu_addrlib_compute(void *addrlib, uint32_t width, uint32_t height, uint32_t format,
uint32_t usage, uint32_t *tiling_flags,
ADDR_COMPUTE_SURFACE_INFO_OUTPUT *addr_out)
{
- ADDR_COMPUTE_SURFACE_INFO_INPUT addr_surf_info_in = {0};
- ADDR_TILEINFO addr_tile_info = {0};
- ADDR_TILEINFO addr_tile_info_out = {0};
+ ADDR_COMPUTE_SURFACE_INFO_INPUT addr_surf_info_in = { 0 };
+ ADDR_TILEINFO addr_tile_info = { 0 };
+ ADDR_TILEINFO addr_tile_info_out = { 0 };
uint32_t bits_per_pixel;
addr_surf_info_in.size = sizeof(ADDR_COMPUTE_SURFACE_INFO_INPUT);
/* Set the requested tiling mode. */
addr_surf_info_in.tileMode = ADDR_TM_2D_TILED_THIN1;
- if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN |
- BO_USE_SW_WRITE_OFTEN))
+ if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
addr_surf_info_in.tileMode = ADDR_TM_LINEAR_ALIGNED;
else if (width <= 16 || height <= 16)
addr_surf_info_in.tileMode = ADDR_TM_1D_TILED_THIN1;
addr_out->size = sizeof(ADDR_COMPUTE_SURFACE_INFO_OUTPUT);
addr_out->pTileInfo = &addr_tile_info_out;
- if (AddrComputeSurfaceInfo(addrlib, &addr_surf_info_in,
- addr_out) != ADDR_OK)
+ if (AddrComputeSurfaceInfo(addrlib, &addr_surf_info_in, addr_out) != ADDR_OK)
return -EINVAL;
- ADDR_CONVERT_TILEINFOTOHW_INPUT s_in = {0};
- ADDR_CONVERT_TILEINFOTOHW_OUTPUT s_out = {0};
- ADDR_TILEINFO s_tile_hw_info_out = {0};
+ ADDR_CONVERT_TILEINFOTOHW_INPUT s_in = { 0 };
+ ADDR_CONVERT_TILEINFOTOHW_OUTPUT s_out = { 0 };
+ ADDR_TILEINFO s_tile_hw_info_out = { 0 };
s_in.size = sizeof(ADDR_CONVERT_TILEINFOTOHW_INPUT);
/* Convert from real value to HW value */
/* LINEAR_ALIGNED */
*tiling_flags |= AMDGPU_TILING_SET(ARRAY_MODE, 1);
- *tiling_flags |= AMDGPU_TILING_SET(BANK_WIDTH,
- drv_log_base2(addr_tile_info_out.bankWidth));
- *tiling_flags |= AMDGPU_TILING_SET(BANK_HEIGHT,
- drv_log_base2(addr_tile_info_out.bankHeight));
- *tiling_flags |= AMDGPU_TILING_SET(TILE_SPLIT,
- s_tile_hw_info_out.tileSplitBytes);
+ *tiling_flags |= AMDGPU_TILING_SET(BANK_WIDTH, drv_log_base2(addr_tile_info_out.bankWidth));
+ *tiling_flags |=
+ AMDGPU_TILING_SET(BANK_HEIGHT, drv_log_base2(addr_tile_info_out.bankHeight));
+ *tiling_flags |= AMDGPU_TILING_SET(TILE_SPLIT, s_tile_hw_info_out.tileSplitBytes);
*tiling_flags |= AMDGPU_TILING_SET(MACRO_TILE_ASPECT,
- drv_log_base2(addr_tile_info_out.macroAspectRatio));
- *tiling_flags |= AMDGPU_TILING_SET(PIPE_CONFIG,
- s_tile_hw_info_out.pipeConfig);
+ drv_log_base2(addr_tile_info_out.macroAspectRatio));
+ *tiling_flags |= AMDGPU_TILING_SET(PIPE_CONFIG, s_tile_hw_info_out.pipeConfig);
*tiling_flags |= AMDGPU_TILING_SET(NUM_BANKS, s_tile_hw_info_out.banks);
return 0;
static void *amdgpu_addrlib_init(int fd)
{
int ret;
- ADDR_CREATE_INPUT addr_create_input = {0};
- ADDR_CREATE_OUTPUT addr_create_output = {0};
- ADDR_REGISTER_VALUE reg_value = {0};
- ADDR_CREATE_FLAGS create_flags = { {0} };
+ ADDR_CREATE_INPUT addr_create_input = { 0 };
+ ADDR_CREATE_OUTPUT addr_create_output = { 0 };
+ ADDR_REGISTER_VALUE reg_value = { 0 };
+ ADDR_CREATE_FLAGS create_flags = { { 0 } };
ADDR_E_RETURNCODE addr_ret;
addr_create_input.size = sizeof(ADDR_CREATE_INPUT);
addr_create_output.size = sizeof(ADDR_CREATE_OUTPUT);
- struct amdgpu_gpu_info gpu_info = {0};
+ struct amdgpu_gpu_info gpu_info = { 0 };
ret = amdgpu_query_gpu(fd, &gpu_info);
reg_value.backendDisables = gpu_info.backend_disable[0];
reg_value.pTileConfig = gpu_info.gb_tile_mode;
- reg_value.noOfEntries = sizeof(gpu_info.gb_tile_mode)
- / sizeof(gpu_info.gb_tile_mode[0]);
+ reg_value.noOfEntries = sizeof(gpu_info.gb_tile_mode) / sizeof(gpu_info.gb_tile_mode[0]);
reg_value.pMacroTileConfig = gpu_info.gb_macro_tile_mode;
- reg_value.noOfMacroEntries = sizeof(gpu_info.gb_macro_tile_mode)
- / sizeof(gpu_info.gb_macro_tile_mode[0]);
+ reg_value.noOfMacroEntries =
+ sizeof(gpu_info.gb_macro_tile_mode) / sizeof(gpu_info.gb_macro_tile_mode[0]);
create_flags.value = 0;
create_flags.useTileIndex = 1;
metadata.priority = 1;
metadata.modifier = DRM_FORMAT_MOD_NONE;
- ret = drv_add_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats), &metadata,
+ ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
flags);
if (ret)
return ret;
- drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata,
- BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata, BO_USE_SCANOUT);
metadata.tiling = ADDR_NON_DISPLAYABLE << 16 | ADDR_TM_LINEAR_ALIGNED;
metadata.priority = 2;
metadata.modifier = DRM_FORMAT_MOD_NONE;
- ret = drv_add_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats), &metadata,
+ ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
flags);
if (ret)
return ret;
metadata.tiling = ADDR_DISPLAYABLE << 16 | ADDR_TM_2D_TILED_THIN1;
metadata.priority = 3;
- ret = drv_add_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats), &metadata,
+ ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
flags);
if (ret)
return ret;
- drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
- BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
- BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata,
- BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata, BO_USE_SCANOUT);
metadata.tiling = ADDR_NON_DISPLAYABLE << 16 | ADDR_TM_2D_TILED_THIN1;
metadata.priority = 4;
- ret = drv_add_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats), &metadata,
+ ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
flags);
if (ret)
return ret;
drv->priv = NULL;
}
-static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t usage)
+static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t usage)
{
- void *addrlib = bo->drv->priv;
+ void *addrlib = bo->drv->priv;
union drm_amdgpu_gem_create gem_create;
- struct amdgpu_bo_metadata metadata = {0};
- ADDR_COMPUTE_SURFACE_INFO_OUTPUT addr_out = {0};
+ struct amdgpu_bo_metadata metadata = { 0 };
+ ADDR_COMPUTE_SURFACE_INFO_OUTPUT addr_out = { 0 };
uint32_t tiling_flags = 0;
uint32_t gem_create_flags = 0;
int ret;
- if (amdgpu_addrlib_compute(addrlib, width,
- height, format, usage,
- &tiling_flags,
+ if (amdgpu_addrlib_compute(addrlib, width, height, format, usage, &tiling_flags,
&addr_out) < 0)
return -EINVAL;
bo->tiling = tiling_flags;
bo->offsets[0] = 0;
bo->sizes[0] = addr_out.surfSize;
- bo->strides[0] = addr_out.pixelPitch
- * DIV_ROUND_UP(addr_out.pixelBits, 8);
- if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN |
- BO_USE_SW_WRITE_OFTEN | BO_USE_SW_WRITE_RARELY |
- BO_USE_SW_READ_RARELY))
+ bo->strides[0] = addr_out.pixelPitch * DIV_ROUND_UP(addr_out.pixelBits, 8);
+ if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN |
+ BO_USE_SW_WRITE_RARELY | BO_USE_SW_READ_RARELY))
gem_create_flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
else
gem_create_flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
gem_create.in.domain_flags = gem_create_flags;
/* Allocate the buffer with the preferred heap. */
- ret = drmCommandWriteRead(drv_get_fd(bo->drv), DRM_AMDGPU_GEM_CREATE,
- &gem_create, sizeof(gem_create));
+ ret = drmCommandWriteRead(drv_get_fd(bo->drv), DRM_AMDGPU_GEM_CREATE, &gem_create,
+ sizeof(gem_create));
if (ret < 0)
return ret;
metadata.tiling_info = tiling_flags;
- ret = amdgpu_set_metadata(drv_get_fd(bo->drv),
- bo->handles[0].u32, &metadata);
+ ret = amdgpu_set_metadata(drv_get_fd(bo->drv), bo->handles[0].u32, &metadata);
return ret;
}
}
data->length = bo->sizes[0];
- return mmap(0, bo->sizes[0], PROT_READ | PROT_WRITE, MAP_SHARED,
- bo->drv->fd, gem_map.out.addr_ptr);
+ return mmap(0, bo->sizes[0], PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
+ gem_map.out.addr_ptr);
}
struct backend backend_amdgpu = {
};
#endif
-
#include "helpers.h"
#include "util.h"
-const static uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB888, DRM_FORMAT_XRGB8888
-};
+const static uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB888,
+ DRM_FORMAT_XRGB8888 };
static int cirrus_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-struct backend backend_cirrus =
-{
+struct backend backend_cirrus = {
.name = "cirrus",
.init = cirrus_init,
.bo_create = drv_dumb_bo_create,
#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;
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;
}
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);
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);
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)) {
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) {
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)
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;
#include "cros_gralloc_helpers.h"
#include <mutex>
-#include <unordered_set>
#include <unordered_map>
+#include <unordered_set>
struct cros_gralloc_bo {
struct bo *bo;
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);
#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
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
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;
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
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);
* 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)
{
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
#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;
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)) {
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();
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)) {
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)) {
*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) {
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)) {
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;
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) {
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.");
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)) {
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) {
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++)
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,
.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,
};
#ifdef DRV_AMDGPU
&backend_amdgpu,
#endif
- &backend_cirrus,
- &backend_evdi,
+ &backend_cirrus, &backend_evdi,
#ifdef DRV_EXYNOS
&backend_exynos,
#endif
#ifdef DRV_VC4
&backend_vc4,
#endif
- &backend_vgem,
- &backend_virtio_gpu,
+ &backend_vgem, &backend_virtio_gpu,
};
- for(i = 0; i < ARRAY_SIZE(backend_list); i++)
+ for (i = 0; i < ARRAY_SIZE(backend_list); i++)
if (!strcmp(drm_version->name, backend_list[i]->name)) {
drmFreeVersion(drm_version);
return backend_list[i];
struct driver *drv;
int ret;
- drv = (struct driver *) calloc(1, sizeof(*drv));
+ drv = (struct driver *)calloc(1, sizeof(*drv));
if (!drv)
return NULL;
/* Start with a power of 2 number of allocations. */
drv->backend->combos.allocations = 2;
drv->backend->combos.size = 0;
- drv->backend->combos.data = calloc(drv->backend->combos.allocations,
- sizeof(struct combination));
+ drv->backend->combos.data =
+ calloc(drv->backend->combos.allocations, sizeof(struct combination));
if (!drv->backend->combos.data)
goto free_map_table;
return drv->fd;
}
-const char *
-drv_get_name(struct driver *drv)
+const char *drv_get_name(struct driver *drv)
{
return drv->backend->name;
}
-struct combination *drv_get_combination(struct driver *drv, uint32_t format,
- uint64_t usage)
+struct combination *drv_get_combination(struct driver *drv, uint32_t format, uint64_t usage)
{
struct combination *curr, *best;
for (i = 0; i < drv->backend->combos.size; i++) {
curr = &drv->backend->combos.data[i];
if ((format == curr->format) && usage == (curr->usage & usage))
- if (!best ||
- best->metadata.priority < curr->metadata.priority)
+ if (!best || best->metadata.priority < curr->metadata.priority)
best = curr;
}
return best;
}
-struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height,
- uint32_t format)
+struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, uint32_t format)
{
struct bo *bo;
- bo = (struct bo *) calloc(1, sizeof(*bo));
+ bo = (struct bo *)calloc(1, sizeof(*bo));
if (!bo)
return NULL;
return bo;
}
-struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height,
- uint32_t format, uint64_t flags)
+struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, uint32_t format,
+ uint64_t flags)
{
int ret;
size_t plane;
return bo;
}
-struct bo *drv_bo_create_with_modifiers(struct driver *drv,
- uint32_t width, uint32_t height,
- uint32_t format,
- const uint64_t *modifiers, uint32_t count)
+struct bo *drv_bo_create_with_modifiers(struct driver *drv, uint32_t width, uint32_t height,
+ uint32_t format, const uint64_t *modifiers, uint32_t count)
{
int ret;
size_t plane;
if (!bo)
return NULL;
- ret = drv->backend->bo_create_with_modifiers(bo, width, height,
- format, modifiers, count);
+ ret = drv->backend->bo_create_with_modifiers(bo, width, height, format, modifiers, count);
if (ret) {
free(bo);
return bo;
}
-
void drv_bo_destroy(struct bo *bo)
{
size_t plane;
return bo;
}
-void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
- uint32_t height, uint32_t flags, struct map_info **map_data,
- size_t plane)
+void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
+ uint32_t flags, struct map_info **map_data, size_t plane)
{
void *ptr;
uint8_t *addr;
pthread_mutex_lock(&bo->drv->driver_lock);
if (!drmHashLookup(bo->drv->map_table, bo->handles[plane].u32, &ptr)) {
- data = (struct map_info *) ptr;
+ data = (struct map_info *)ptr;
data->refcount++;
goto success;
}
data->refcount = 1;
data->addr = addr;
data->handle = bo->handles[plane].u32;
- drmHashInsert(bo->drv->map_table, bo->handles[plane].u32,
- (void *) data);
+ drmHashInsert(bo->drv->map_table, bo->handles[plane].u32, (void *)data);
success:
*map_data = data;
offset = drv_bo_get_plane_stride(bo, plane) * y;
offset += drv_stride_from_format(bo->format, x, plane);
- addr = (uint8_t *) data->addr;
+ addr = (uint8_t *)data->addr;
addr += drv_bo_get_plane_offset(bo, plane) + offset;
pthread_mutex_unlock(&bo->drv->driver_lock);
- return (void *) addr;
+ return (void *)addr;
}
int drv_bo_unmap(struct bo *bo, struct map_info *data)
int ret, fd;
assert(plane < bo->num_planes);
- ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32,
- DRM_CLOEXEC | DRM_RDWR, &fd);
+ ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC | DRM_RDWR, &fd);
return (ret) ? ret : fd;
-
}
uint32_t drv_bo_get_plane_offset(struct bo *bo, size_t plane)
uint64_t drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane)
{
- assert(plane < bo->num_planes);
+ assert(plane < bo->num_planes);
return bo->format_modifiers[plane];
}
return 0;
}
-uint32_t drv_size_from_format(uint32_t format, uint32_t stride,
- uint32_t height, size_t plane)
+uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, size_t plane)
{
assert(plane < drv_num_planes_from_format(format));
uint32_t vertical_subsampling;
#define DRV_MAX_PLANES 4
+// clang-format off
/* Use flags */
#define BO_USE_NONE 0
#define BO_USE_SCANOUT (1ull << 0)
BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | \
BO_USE_TEXTURE
+// clang-format on
struct driver;
struct bo;
struct combination;
void *priv;
};
-struct driver *
-drv_create(int fd);
+struct driver *drv_create(int fd);
-void
-drv_destroy(struct driver *drv);
+void drv_destroy(struct driver *drv);
-int
-drv_get_fd(struct driver *drv);
+int drv_get_fd(struct driver *drv);
-const char *
-drv_get_name(struct driver *drv);
+const char *drv_get_name(struct driver *drv);
-struct combination *
-drv_get_combination(struct driver *drv, uint32_t format, uint64_t usage);
+struct combination *drv_get_combination(struct driver *drv, uint32_t format, uint64_t usage);
-struct bo *
-drv_bo_new(struct driver *drv, uint32_t width, uint32_t height,
- uint32_t format);
+struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, uint32_t format);
-struct bo *
-drv_bo_create(struct driver *drv, uint32_t width, uint32_t height,
- uint32_t format, uint64_t flags);
+struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, uint32_t format,
+ uint64_t flags);
-struct bo *
-drv_bo_create_with_modifiers(struct driver *drv,
- uint32_t width, uint32_t height,
- uint32_t format,
- const uint64_t *modifiers, uint32_t count);
+struct bo *drv_bo_create_with_modifiers(struct driver *drv, uint32_t width, uint32_t height,
+ uint32_t format, const uint64_t *modifiers, uint32_t count);
-void
-drv_bo_destroy(struct bo *bo);
+void drv_bo_destroy(struct bo *bo);
-struct bo *
-drv_bo_import(struct driver *drv, struct drv_import_fd_data *data);
+struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data);
-void *
-drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
- uint32_t height, uint32_t flags, struct map_info **map_data,
- size_t plane);
+void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
+ uint32_t flags, struct map_info **map_data, size_t plane);
-int
-drv_bo_unmap(struct bo *bo, struct map_info *map_data);
+int drv_bo_unmap(struct bo *bo, struct map_info *map_data);
-uint32_t
-drv_bo_get_width(struct bo *bo);
+uint32_t drv_bo_get_width(struct bo *bo);
-uint32_t
-drv_bo_get_height(struct bo *bo);
+uint32_t drv_bo_get_height(struct bo *bo);
-uint32_t
-drv_bo_get_stride_or_tiling(struct bo *bo);
+uint32_t drv_bo_get_stride_or_tiling(struct bo *bo);
-size_t
-drv_bo_get_num_planes(struct bo *bo);
+size_t drv_bo_get_num_planes(struct bo *bo);
-union bo_handle
-drv_bo_get_plane_handle(struct bo *bo, size_t plane);
+union bo_handle drv_bo_get_plane_handle(struct bo *bo, size_t plane);
-int
-drv_bo_get_plane_fd(struct bo *bo, size_t plane);
+int drv_bo_get_plane_fd(struct bo *bo, size_t plane);
-uint32_t
-drv_bo_get_plane_offset(struct bo *bo, size_t plane);
+uint32_t drv_bo_get_plane_offset(struct bo *bo, size_t plane);
-uint32_t
-drv_bo_get_plane_size(struct bo *bo, size_t plane);
+uint32_t drv_bo_get_plane_size(struct bo *bo, size_t plane);
-uint32_t
-drv_bo_get_plane_stride(struct bo *bo, size_t plane);
+uint32_t drv_bo_get_plane_stride(struct bo *bo, size_t plane);
-uint64_t
-drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane);
+uint64_t drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane);
-uint32_t
-drv_bo_get_format(struct bo *bo);
+uint32_t drv_bo_get_format(struct bo *bo);
-uint32_t
-drv_bo_get_stride_in_pixels(struct bo *bo);
+uint32_t drv_bo_get_stride_in_pixels(struct bo *bo);
-uint32_t
-drv_resolve_format(struct driver *drv, uint32_t format);
+uint32_t drv_resolve_format(struct driver *drv, uint32_t format);
-size_t
-drv_num_planes_from_format(uint32_t format);
+size_t drv_num_planes_from_format(uint32_t format);
-uint32_t
-drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height,
- size_t plane);
+uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, size_t plane);
-uint32_t
-drv_num_buffers_per_bo(struct bo *bo);
+uint32_t drv_num_buffers_per_bo(struct bo *bo);
#ifdef __cplusplus
}
#include "drv.h"
-struct bo
-{
+struct bo {
struct driver *drv;
uint32_t width;
uint32_t height;
uint32_t allocations;
};
-struct backend
-{
+struct backend {
char *name;
int (*init)(struct driver *drv);
void (*close)(struct driver *drv);
- int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags);
- int (*bo_create_with_modifiers)(struct bo *bo,
- uint32_t width, uint32_t height,
- uint32_t format,
- const uint64_t *modifiers,
- uint32_t count);
+ int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags);
+ int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
+ uint32_t format, const uint64_t *modifiers, uint32_t count);
int (*bo_destroy)(struct bo *bo);
int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
- void* (*bo_map)(struct bo *bo, struct map_info *data, size_t plane);
+ void *(*bo_map)(struct bo *bo, struct map_info *data, size_t plane);
int (*bo_unmap)(struct bo *bo, struct map_info *data);
uint32_t (*resolve_format)(uint32_t format);
struct combinations combos;
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
static int evdi_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-struct backend backend_evdi =
-{
+struct backend backend_evdi = {
.name = "evdi",
.init = evdi_init,
.bo_create = drv_dumb_bo_create,
.bo_import = drv_prime_bo_import,
.bo_map = drv_dumb_bo_map,
};
-
#ifdef DRV_EXYNOS
+// clang-format off
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <xf86drm.h>
#include <exynos_drm.h>
+// clang-format on
#include "drv_priv.h"
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_NV12, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_NV12,
+ DRM_FORMAT_XRGB8888 };
static int exynos_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
size_t plane;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_EXYNOS_GEM_CREATE, &gem_create);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_EXYNOS_GEM_CREATE failed "
- "(size=%zu)\n", size);
+ "(size=%zu)\n",
+ size);
goto cleanup_planes;
}
return 0;
cleanup_planes:
- for ( ; plane != 0; plane--) {
+ for (; plane != 0; plane--) {
struct drm_gem_close gem_close;
memset(&gem_close, 0, sizeof(gem_close));
gem_close.handle = bo->handles[plane - 1].u32;
- int gem_close_ret = drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE,
- &gem_close);
+ int gem_close_ret = drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
if (gem_close_ret) {
- fprintf(stderr,
- "drv: DRM_IOCTL_GEM_CLOSE failed: %d\n",
- gem_close_ret);
+ fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed: %d\n", gem_close_ret);
}
}
* Use dumb mapping with exynos even though a GEM buffer is created.
* libdrm does the same thing in exynos_drm.c
*/
-struct backend backend_exynos =
-{
+struct backend backend_exynos = {
.name = "exynos",
.init = exynos_init,
.bo_create = exynos_bo_create,
#include <xf86drm.h>
#include "drv.h"
-#include "gbm_priv.h"
#include "gbm_helpers.h"
+#include "gbm_priv.h"
#include "util.h"
-PUBLIC int
-gbm_device_get_fd(struct gbm_device *gbm)
+PUBLIC int gbm_device_get_fd(struct gbm_device *gbm)
{
return drv_get_fd(gbm->drv);
}
-PUBLIC const char *
-gbm_device_get_backend_name(struct gbm_device *gbm)
+PUBLIC const char *gbm_device_get_backend_name(struct gbm_device *gbm)
{
return drv_get_name(gbm->drv);
}
-PUBLIC int
-gbm_device_is_format_supported(struct gbm_device *gbm,
- uint32_t format, uint32_t usage)
+PUBLIC int gbm_device_is_format_supported(struct gbm_device *gbm, uint32_t format, uint32_t usage)
{
uint64_t drv_usage;
- if (usage & GBM_BO_USE_CURSOR &&
- usage & GBM_BO_USE_RENDERING)
+ if (usage & GBM_BO_USE_CURSOR && usage & GBM_BO_USE_RENDERING)
return 0;
drv_usage = gbm_convert_flags(usage);
{
struct gbm_device *gbm;
- gbm = (struct gbm_device*) malloc(sizeof(*gbm));
+ gbm = (struct gbm_device *)malloc(sizeof(*gbm));
if (!gbm)
return NULL;
free(gbm);
}
-PUBLIC struct gbm_surface *gbm_surface_create(struct gbm_device *gbm,
- uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+PUBLIC struct gbm_surface *gbm_surface_create(struct gbm_device *gbm, uint32_t width,
+ uint32_t height, uint32_t format, uint32_t flags)
{
- struct gbm_surface *surface =
- (struct gbm_surface*) malloc(sizeof(*surface));
+ struct gbm_surface *surface = (struct gbm_surface *)malloc(sizeof(*surface));
if (!surface)
return NULL;
return NULL;
}
-PUBLIC void gbm_surface_release_buffer(struct gbm_surface *surface,
- struct gbm_bo *bo)
+PUBLIC void gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo)
{
}
{
struct gbm_bo *bo;
- bo = (struct gbm_bo*) calloc(1, sizeof(*bo));
+ bo = (struct gbm_bo *)calloc(1, sizeof(*bo));
if (!bo)
return NULL;
return bo;
}
-PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width,
- uint32_t height, uint32_t format,
- uint32_t flags)
+PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width, uint32_t height,
+ uint32_t format, uint32_t flags)
{
struct gbm_bo *bo;
if (!bo)
return NULL;
- bo->bo = drv_bo_create(gbm->drv, width, height, format,
- gbm_convert_flags(flags));
+ bo->bo = drv_bo_create(gbm->drv, width, height, format, gbm_convert_flags(flags));
if (!bo->bo) {
free(bo);
return bo;
}
-PUBLIC struct gbm_bo *gbm_bo_create_with_modifiers(struct gbm_device *gbm,
- uint32_t width,
- uint32_t height,
- uint32_t format,
- const uint64_t *modifiers,
- uint32_t count)
+PUBLIC struct gbm_bo *gbm_bo_create_with_modifiers(struct gbm_device *gbm, uint32_t width,
+ uint32_t height, uint32_t format,
+ const uint64_t *modifiers, uint32_t count)
{
struct gbm_bo *bo;
if (!bo)
return NULL;
- bo->bo = drv_bo_create_with_modifiers(gbm->drv,
- width, height, format,
- modifiers, count);
+ bo->bo = drv_bo_create_with_modifiers(gbm->drv, width, height, format, modifiers, count);
if (!bo->bo) {
free(bo);
free(bo);
}
-PUBLIC struct gbm_bo *
-gbm_bo_import(struct gbm_device *gbm, uint32_t type,
- void *buffer, uint32_t usage)
+PUBLIC struct gbm_bo *gbm_bo_import(struct gbm_device *gbm, uint32_t type, void *buffer,
+ uint32_t usage)
{
struct gbm_bo *bo;
struct drv_import_fd_data drv_data;
drv_data.fds[i] = fd_planar_data->fds[i];
drv_data.offsets[i] = fd_planar_data->offsets[i];
drv_data.strides[i] = fd_planar_data->strides[i];
- drv_data.format_modifiers[i] =
- fd_planar_data->format_modifiers[i];
+ drv_data.format_modifiers[i] = fd_planar_data->format_modifiers[i];
drv_data.sizes[i] = drv_size_from_format(
- drv_data.format,
- drv_data.strides[i],
- drv_data.height,
- i);
+ drv_data.format, drv_data.strides[i], drv_data.height, i);
}
for (i = num_planes; i < GBM_MAX_PLANES; i++)
return bo;
}
-PUBLIC void *
-gbm_bo_map(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t width,
- uint32_t height, uint32_t flags, uint32_t *stride, void **map_data,
- size_t plane)
+PUBLIC void *gbm_bo_map(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
+ uint32_t flags, uint32_t *stride, void **map_data, size_t plane)
{
if (!bo || width == 0 || height == 0 || !stride || !map_data)
return NULL;
*stride = gbm_bo_get_plane_stride(bo, plane);
- return drv_bo_map(bo->bo, x, y, width, height, 0,
- (struct map_info**)map_data, plane);
+ return drv_bo_map(bo->bo, x, y, width, height, 0, (struct map_info **)map_data, plane);
}
-PUBLIC void
-gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
+PUBLIC void gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
{
assert(bo);
drv_bo_unmap(bo->bo, map_data);
}
-PUBLIC uint32_t
-gbm_bo_get_width(struct gbm_bo *bo)
+PUBLIC uint32_t gbm_bo_get_width(struct gbm_bo *bo)
{
return drv_bo_get_width(bo->bo);
}
-PUBLIC uint32_t
-gbm_bo_get_height(struct gbm_bo *bo)
+PUBLIC uint32_t gbm_bo_get_height(struct gbm_bo *bo)
{
return drv_bo_get_height(bo->bo);
}
-PUBLIC uint32_t
-gbm_bo_get_stride(struct gbm_bo *bo)
+PUBLIC uint32_t gbm_bo_get_stride(struct gbm_bo *bo)
{
return gbm_bo_get_plane_stride(bo, 0);
}
-PUBLIC uint32_t
-gbm_bo_get_stride_or_tiling(struct gbm_bo *bo)
+PUBLIC uint32_t gbm_bo_get_stride_or_tiling(struct gbm_bo *bo)
{
return drv_bo_get_stride_or_tiling(bo->bo);
}
-PUBLIC uint32_t
-gbm_bo_get_format(struct gbm_bo *bo)
+PUBLIC uint32_t gbm_bo_get_format(struct gbm_bo *bo)
{
return bo->gbm_format;
}
-PUBLIC uint64_t
-gbm_bo_get_format_modifier(struct gbm_bo *bo)
+PUBLIC uint64_t gbm_bo_get_format_modifier(struct gbm_bo *bo)
{
return gbm_bo_get_plane_format_modifier(bo, 0);
}
-PUBLIC struct gbm_device *
-gbm_bo_get_device(struct gbm_bo *bo)
+PUBLIC struct gbm_device *gbm_bo_get_device(struct gbm_bo *bo)
{
return bo->gbm;
}
-PUBLIC union gbm_bo_handle
-gbm_bo_get_handle(struct gbm_bo *bo)
+PUBLIC union gbm_bo_handle gbm_bo_get_handle(struct gbm_bo *bo)
{
return gbm_bo_get_plane_handle(bo, 0);
}
-PUBLIC int
-gbm_bo_get_fd(struct gbm_bo *bo)
+PUBLIC int gbm_bo_get_fd(struct gbm_bo *bo)
{
return gbm_bo_get_plane_fd(bo, 0);
}
-PUBLIC size_t
-gbm_bo_get_num_planes(struct gbm_bo *bo)
+PUBLIC size_t gbm_bo_get_num_planes(struct gbm_bo *bo)
{
return drv_bo_get_num_planes(bo->bo);
}
-PUBLIC union gbm_bo_handle
-gbm_bo_get_plane_handle(struct gbm_bo *bo, size_t plane)
+PUBLIC union gbm_bo_handle gbm_bo_get_plane_handle(struct gbm_bo *bo, size_t plane)
{
- return (union gbm_bo_handle) drv_bo_get_plane_handle(bo->bo, plane).u64;
+ return (union gbm_bo_handle)drv_bo_get_plane_handle(bo->bo, plane).u64;
}
-PUBLIC int
-gbm_bo_get_plane_fd(struct gbm_bo *bo, size_t plane)
+PUBLIC int gbm_bo_get_plane_fd(struct gbm_bo *bo, size_t plane)
{
return drv_bo_get_plane_fd(bo->bo, plane);
}
-PUBLIC uint32_t
-gbm_bo_get_plane_offset(struct gbm_bo *bo, size_t plane)
+PUBLIC uint32_t gbm_bo_get_plane_offset(struct gbm_bo *bo, size_t plane)
{
return drv_bo_get_plane_offset(bo->bo, plane);
}
-PUBLIC uint32_t
-gbm_bo_get_plane_size(struct gbm_bo *bo, size_t plane)
+PUBLIC uint32_t gbm_bo_get_plane_size(struct gbm_bo *bo, size_t plane)
{
return drv_bo_get_plane_size(bo->bo, plane);
}
-PUBLIC uint32_t
-gbm_bo_get_plane_stride(struct gbm_bo *bo, size_t plane)
+PUBLIC uint32_t gbm_bo_get_plane_stride(struct gbm_bo *bo, size_t plane)
{
return drv_bo_get_plane_stride(bo->bo, plane);
}
-PUBLIC uint64_t
-gbm_bo_get_plane_format_modifier(struct gbm_bo *bo, size_t plane)
+PUBLIC uint64_t gbm_bo_get_plane_format_modifier(struct gbm_bo *bo, size_t plane)
{
return drv_bo_get_plane_format_modifier(bo->bo, plane);
}
-PUBLIC void
-gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
- void (*destroy_user_data)(struct gbm_bo *, void *))
+PUBLIC void gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
+ void (*destroy_user_data)(struct gbm_bo *, void *))
{
bo->user_data = data;
bo->destroy_user_data = destroy_user_data;
}
-PUBLIC void *
-gbm_bo_get_user_data(struct gbm_bo *bo)
+PUBLIC void *gbm_bo_get_user_data(struct gbm_bo *bo)
{
return bo->user_data;
}
#define GBM_PRIV_H
#include <stdint.h>
-#include <sys/types.h>
#include <stdlib.h>
+#include <sys/types.h>
#include "drv.h"
#include "gbm.h"
-struct gbm_device
-{
+struct gbm_device {
struct driver *drv;
};
-struct gbm_surface
-{
+struct gbm_surface {
};
-struct gbm_bo
-{
+struct gbm_bo {
struct gbm_device *gbm;
struct bo *bo;
uint32_t gbm_format;
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_RGBX8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_RGBX8888 };
static int gma500_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-struct backend backend_gma500 =
-{
+struct backend backend_gma500 = {
.name = "gma500",
.init = gma500_init,
.bo_create = drv_dumb_bo_create,
#include "helpers.h"
#include "util.h"
-static uint32_t subsample_stride(uint32_t stride, uint32_t format,
- size_t plane) {
+static uint32_t subsample_stride(uint32_t stride, uint32_t format, size_t plane)
+{
if (plane != 0) {
switch (format) {
uint32_t drv_bo_get_stride_in_pixels(struct bo *bo)
{
- uint32_t bytes_per_pixel = DIV_ROUND_UP(bpp_from_format(bo->format, 0),
- 8);
+ uint32_t bytes_per_pixel = DIV_ROUND_UP(bpp_from_format(bo->format, 0), 8);
return DIV_ROUND_UP(bo->strides[0], bytes_per_pixel);
}
*/
uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane)
{
- uint32_t stride = DIV_ROUND_UP(width * bpp_from_format(format, plane),
- 8);
+ uint32_t stride = DIV_ROUND_UP(width * bpp_from_format(format, plane), 8);
/*
* The stride of Android YV12 buffers is required to be aligned to 16 bytes
* (see <system/graphics.h>).
*/
if (format == DRM_FORMAT_YVU420_ANDROID)
- stride = (plane == 0) ? ALIGN(stride, 32): ALIGN(stride, 16);
+ stride = (plane == 0) ? ALIGN(stride, 32) : ALIGN(stride, 16);
return stride;
}
* the first plane, height and a format. This function assumes there is just
* one kernel buffer per buffer object.
*/
-int drv_bo_from_format(struct bo *bo, uint32_t stride,
- uint32_t aligned_height, uint32_t format)
+int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, uint32_t format)
{
size_t p, num_planes;
for (p = 0; p < num_planes; p++) {
bo->strides[p] = subsample_stride(stride, format, p);
- bo->sizes[p] = drv_size_from_format(format, bo->strides[p],
- bo->height, p);
+ bo->sizes[p] = drv_size_from_format(format, bo->strides[p], bo->height, p);
bo->offsets[p] = offset;
offset += bo->sizes[p];
- bo->total_size += drv_size_from_format(format, bo->strides[p],
- aligned_height, p);
+ bo->total_size += drv_size_from_format(format, bo->strides[p], aligned_height, p);
}
return 0;
}
-int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
int ret;
size_t plane;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_MODE_DESTROY_DUMB failed "
- "(handle=%x)\n", bo->handles[0].u32);
+ "(handle=%x)\n",
+ bo->handles[0].u32);
return ret;
}
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed "
"(handle=%x) error %d\n",
- bo->handles[plane].u32, ret);
+ bo->handles[plane].u32, ret);
error = ret;
}
}
memset(&prime_handle, 0, sizeof(prime_handle));
prime_handle.fd = data->fds[plane];
- ret = drmIoctl(bo->drv->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE,
- &prime_handle);
+ ret = drmIoctl(bo->drv->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &prime_handle);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_PRIME_FD_TO_HANDLE "
- "failed (fd=%u)\n", prime_handle.fd);
+ "failed (fd=%u)\n",
+ prime_handle.fd);
/*
* Need to call GEM close on planes that were opened,
if (bo->handles[i].u32 == bo->handles[plane].u32)
data->length += bo->sizes[i];
- return mmap(0, data->length, PROT_READ | PROT_WRITE, MAP_SHARED,
- bo->drv->fd, map_dumb.offset);
+ return mmap(0, data->length, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
+ map_dumb.offset);
}
-uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo,
- size_t plane)
+uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo, size_t plane)
{
void *count;
uintptr_t num = 0;
if (!drmHashLookup(drv->buffer_table, bo->handles[plane].u32, &count))
- num = (uintptr_t) (count);
+ num = (uintptr_t)(count);
return num;
}
-void drv_increment_reference_count(struct driver *drv, struct bo *bo,
- size_t plane)
+void drv_increment_reference_count(struct driver *drv, struct bo *bo, size_t plane)
{
uintptr_t num = drv_get_reference_count(drv, bo, plane);
/* If a value isn't in the table, drmHashDelete is a no-op */
drmHashDelete(drv->buffer_table, bo->handles[plane].u32);
- drmHashInsert(drv->buffer_table, bo->handles[plane].u32,
- (void *) (num + 1));
+ drmHashInsert(drv->buffer_table, bo->handles[plane].u32, (void *)(num + 1));
}
-void drv_decrement_reference_count(struct driver *drv, struct bo *bo,
- size_t plane)
+void drv_decrement_reference_count(struct driver *drv, struct bo *bo, size_t plane)
{
uintptr_t num = drv_get_reference_count(drv, bo, plane);
drmHashDelete(drv->buffer_table, bo->handles[plane].u32);
if (num > 0)
- drmHashInsert(drv->buffer_table, bo->handles[plane].u32,
- (void *) (num - 1));
+ drmHashInsert(drv->buffer_table, bo->handles[plane].u32, (void *)(num - 1));
}
uint32_t drv_log_base2(uint32_t value)
return ret;
}
-int drv_add_combination(struct driver *drv, uint32_t format,
- struct format_metadata *metadata, uint64_t usage)
+int drv_add_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
+ uint64_t usage)
{
struct combinations *combos = &drv->backend->combos;
if (combos->size >= combos->allocations) {
struct combination *new_data;
combos->allocations *= 2;
- new_data = realloc(combos->data, combos->allocations
- * sizeof(*combos->data));
+ new_data = realloc(combos->data, combos->allocations * sizeof(*combos->data));
if (!new_data)
return -ENOMEM;
return 0;
}
-int drv_add_combinations(struct driver *drv, const uint32_t *formats,
- uint32_t num_formats, struct format_metadata *metadata,
- uint64_t usage)
+int drv_add_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats,
+ struct format_metadata *metadata, uint64_t usage)
{
int ret;
uint32_t i;
return 0;
}
-void drv_modify_combination(struct driver *drv, uint32_t format,
- struct format_metadata *metadata, uint64_t usage)
+void drv_modify_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
+ uint64_t usage)
{
uint32_t i;
struct combination *combo;
/* Attempts to add the specified usage to an existing combination. */
for (i = 0; i < drv->backend->combos.size; i++) {
combo = &drv->backend->combos.data[i];
- if (combo->format == format &&
- combo->metadata.tiling == metadata->tiling &&
+ if (combo->format == format && combo->metadata.tiling == metadata->tiling &&
combo->metadata.modifier == metadata->modifier)
combo->usage |= usage;
}
if (!plane)
goto out;
- props = drmModeObjectGetProperties(drv->fd, plane->plane_id,
- DRM_MODE_OBJECT_PLANE);
+ props = drmModeObjectGetProperties(drv->fd, plane->plane_id, DRM_MODE_OBJECT_PLANE);
if (!props)
goto out;
if (!found && item_size >= allocations) {
struct kms_item *new_data = NULL;
allocations *= 2;
- new_data = realloc(items, allocations *
- sizeof(*items));
+ new_data = realloc(items, allocations * sizeof(*items));
if (!new_data) {
item_size = 0;
goto out;
drmModeFreeObjectProperties(props);
drmModeFreePlane(plane);
-
}
drmModeFreePlaneResources(resources);
return items;
}
-int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
- uint32_t num_formats)
+int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats)
{
int ret;
uint32_t i, j, num_items;
metadata.priority = 1;
metadata.modifier = DRM_FORMAT_MOD_NONE;
- ret = drv_add_combinations(drv, formats, num_formats, &metadata,
- BO_COMMON_USE_MASK);
+ ret = drv_add_combinations(drv, formats, num_formats, &metadata, BO_COMMON_USE_MASK);
if (ret)
return ret;
/*
* kernel disregards the alpha component of ARGB unless it's an overlay
* plane.
*/
- drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
items = drv_query_kms(drv, &num_items);
if (!items || !num_items)
combo = &drv->backend->combos.data[j];
if (items[i].format == combo->format)
combo->usage |= BO_USE_SCANOUT;
-
-
}
}
#include "drv.h"
uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane);
-int drv_bo_from_format(struct bo *bo, uint32_t stride,
- uint32_t aligned_height, uint32_t format);
-int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags);
+int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, uint32_t format);
+int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags);
int drv_dumb_bo_destroy(struct bo *bo);
int drv_gem_bo_destroy(struct bo *bo);
int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data);
void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane);
-uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo,
- size_t plane);
-void drv_increment_reference_count(struct driver *drv, struct bo *bo,
- size_t plane);
-void drv_decrement_reference_count(struct driver *drv, struct bo *bo,
- size_t plane);
+uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo, size_t plane);
+void drv_increment_reference_count(struct driver *drv, struct bo *bo, size_t plane);
+void drv_decrement_reference_count(struct driver *drv, struct bo *bo, size_t plane);
uint32_t drv_log_base2(uint32_t value);
-int drv_add_combination(struct driver *drv, uint32_t format,
- struct format_metadata *metadata, uint64_t usage);
-int drv_add_combinations(struct driver *drv, const uint32_t *formats,
- uint32_t num_formats, struct format_metadata *metadata,
- uint64_t usage);
-void drv_modify_combination(struct driver *drv, uint32_t format,
- struct format_metadata *metadata, uint64_t usage);
+int drv_add_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
+ uint64_t usage);
+int drv_add_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats,
+ struct format_metadata *metadata, uint64_t usage);
+void drv_modify_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
+ uint64_t usage);
struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items);
-int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
- uint32_t num_formats);
+int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats);
#endif
#include "helpers.h"
#include "util.h"
-static const uint32_t tileable_formats[] = {
- DRM_FORMAT_ARGB1555, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
- DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB1555,
- DRM_FORMAT_XRGB8888, DRM_FORMAT_UYVY, DRM_FORMAT_YUYV
-};
+static const uint32_t tileable_formats[] = { DRM_FORMAT_ARGB1555, DRM_FORMAT_ABGR8888,
+ DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
+ DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB1555,
+ DRM_FORMAT_XRGB8888, DRM_FORMAT_UYVY,
+ DRM_FORMAT_YUYV };
-static const uint32_t linear_only_formats[] = {
- DRM_FORMAT_GR88, DRM_FORMAT_R8, DRM_FORMAT_YVU420,
- DRM_FORMAT_YVU420_ANDROID
-};
+static const uint32_t linear_only_formats[] = { DRM_FORMAT_GR88, DRM_FORMAT_R8, DRM_FORMAT_YVU420,
+ DRM_FORMAT_YVU420_ANDROID };
-struct i915_device
-{
+struct i915_device {
int gen;
drm_intel_bufmgr *mgr;
uint32_t count;
};
-struct i915_bo
-{
+struct i915_bo {
drm_intel_bo *ibos[DRV_MAX_PLANES];
};
static int get_gen(int device_id)
{
- const uint16_t gen3_ids[] = {0x2582, 0x2592, 0x2772, 0x27A2, 0x27AE,
- 0x29C2, 0x29B2, 0x29D2, 0xA001, 0xA011};
+ const uint16_t gen3_ids[] = { 0x2582, 0x2592, 0x2772, 0x27A2, 0x27AE,
+ 0x29C2, 0x29B2, 0x29D2, 0xA001, 0xA011 };
unsigned i;
- for(i = 0; i < ARRAY_SIZE(gen3_ids); i++)
+ for (i = 0; i < ARRAY_SIZE(gen3_ids); i++)
if (gen3_ids[i] == device_id)
return 3;
combo = &drv->backend->combos.data[i];
if (combo->format == item->format) {
if ((combo->metadata.tiling == I915_TILING_Y &&
- item->modifier == I915_FORMAT_MOD_Y_TILED) ||
+ item->modifier == I915_FORMAT_MOD_Y_TILED) ||
(combo->metadata.tiling == I915_TILING_X &&
- item->modifier == I915_FORMAT_MOD_X_TILED)) {
+ item->modifier == I915_FORMAT_MOD_X_TILED)) {
combo->metadata.modifier = item->modifier;
combo->usage |= item->usage;
} else if (combo->metadata.tiling != I915_TILING_Y) {
metadata.priority = 1;
metadata.modifier = DRM_FORMAT_MOD_NONE;
- ret = drv_add_combinations(drv, linear_only_formats,
- ARRAY_SIZE(linear_only_formats), &metadata,
- flags);
+ ret = drv_add_combinations(drv, linear_only_formats, ARRAY_SIZE(linear_only_formats),
+ &metadata, flags);
if (ret)
return ret;
- ret = drv_add_combinations(drv, tileable_formats,
- ARRAY_SIZE(tileable_formats), &metadata,
+ ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata,
flags);
if (ret)
return ret;
- drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
flags &= ~BO_USE_SW_WRITE_OFTEN;
flags &= ~BO_USE_SW_READ_OFTEN;
metadata.tiling = I915_TILING_X;
metadata.priority = 2;
- ret = drv_add_combinations(drv, tileable_formats,
- ARRAY_SIZE(tileable_formats), &metadata,
+ ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata,
flags);
if (ret)
return ret;
metadata.tiling = I915_TILING_Y;
metadata.priority = 3;
- ret = drv_add_combinations(drv, tileable_formats,
- ARRAY_SIZE(tileable_formats), &metadata,
- flags);
+ ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata,
+ flags);
if (ret)
return ret;
return 0;
}
-static int i915_align_dimensions(struct bo *bo, uint32_t tiling,
- uint32_t *stride, uint32_t *aligned_height)
+static int i915_align_dimensions(struct bo *bo, uint32_t tiling, uint32_t *stride,
+ uint32_t *aligned_height)
{
struct i915_device *i915 = bo->drv->priv;
uint32_t horizontal_alignment = 4;
if (i915->gen == 3) {
horizontal_alignment = 512;
vertical_alignment = 8;
- } else {
+ } else {
horizontal_alignment = 128;
vertical_alignment = 32;
}
drv->priv = NULL;
}
-static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
int ret;
size_t plane;
stride = drv_stride_from_format(format, width, 0);
struct i915_device *i915_dev = (struct i915_device *)bo->drv->priv;
- if (flags & (BO_USE_CURSOR | BO_USE_LINEAR |
- BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
+ if (flags & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
tiling_mode = I915_TILING_NONE;
else if (flags & BO_USE_SCANOUT)
tiling_mode = I915_TILING_X;
* Align the Y plane to 128 bytes so the chroma planes would be aligned
* to 64 byte boundaries. This is an Intel HW requirement.
*/
- if (format == DRM_FORMAT_YVU420 ||
- format == DRM_FORMAT_YVU420_ANDROID) {
+ if (format == DRM_FORMAT_YVU420 || format == DRM_FORMAT_YVU420_ANDROID) {
stride = ALIGN(stride, 128);
tiling_mode = I915_TILING_NONE;
}
bo->priv = i915_bo;
- i915_bo->ibos[0] = drm_intel_bo_alloc(i915_dev->mgr, name,
- bo->total_size, 0);
+ i915_bo->ibos[0] = drm_intel_bo_alloc(i915_dev->mgr, name, bo->total_size, 0);
if (!i915_bo->ibos[0]) {
fprintf(stderr, "drv: drm_intel_bo_alloc failed");
free(i915_bo);
bo->tiling = tiling_mode;
- ret = drm_intel_bo_set_tiling(i915_bo->ibos[0], &bo->tiling,
- bo->strides[0]);
+ ret = drm_intel_bo_set_tiling(i915_bo->ibos[0], &bo->tiling, bo->strides[0]);
if (ret || bo->tiling != tiling_mode) {
fprintf(stderr, "drv: drm_intel_gem_bo_set_tiling failed "
- "errno=%x, stride=%x\n", errno, bo->strides[0]);
+ "errno=%x, stride=%x\n",
+ errno, bo->strides[0]);
/* Calls i915 bo destroy. */
bo->drv->backend->bo_destroy(bo);
return -errno;
*/
for (plane = 0; plane < bo->num_planes; plane++) {
- i915_bo->ibos[plane] = drm_intel_bo_gem_create_from_prime(i915_dev->mgr,
- data->fds[plane], data->sizes[plane]);
+ i915_bo->ibos[plane] = drm_intel_bo_gem_create_from_prime(
+ i915_dev->mgr, data->fds[plane], data->sizes[plane]);
if (!i915_bo->ibos[plane]) {
/*
bo->handles[plane].u32 = i915_bo->ibos[plane]->handle;
}
- if (drm_intel_bo_get_tiling(i915_bo->ibos[0], &bo->tiling,
- &swizzling)) {
+ if (drm_intel_bo_get_tiling(i915_bo->ibos[0], &bo->tiling, &swizzling)) {
fprintf(stderr, "drv: drm_intel_bo_get_tiling failed");
i915_bo_destroy(bo);
return -EINVAL;
}
}
-struct backend backend_i915 =
-{
+struct backend backend_i915 = {
.name = "i915",
.init = i915_init,
.close = i915_close,
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
static int marvell_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-struct backend backend_marvell =
-{
+struct backend backend_marvell = {
.name = "marvell",
.init = marvell_init,
.bo_create = drv_dumb_bo_create,
#ifdef DRV_MEDIATEK
+// clang-format off
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <xf86drm.h>
#include <mediatek_drm.h>
+// clang-format on
#include "drv_priv.h"
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
- DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888, DRM_FORMAT_YVU420,
- DRM_FORMAT_YVU420_ANDROID
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
+ DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888,
+ DRM_FORMAT_XRGB8888, DRM_FORMAT_YVU420,
+ DRM_FORMAT_YVU420_ANDROID };
static int mediatek_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
int ret;
size_t plane;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_CREATE failed "
- "(size=%llu)\n", gem_create.size);
+ "(size=%llu)\n",
+ gem_create.size);
return ret;
}
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_MAP_OFFSET, &gem_map);
if (ret) {
- fprintf(stderr,"drv: DRM_IOCTL_MTK_GEM_MAP_OFFSET failed\n");
+ fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_MAP_OFFSET failed\n");
return MAP_FAILED;
}
data->length = bo->total_size;
- return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
- bo->drv->fd, gem_map.offset);
+ return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
+ gem_map.offset);
}
static uint32_t mediatek_resolve_format(uint32_t format)
}
}
-struct backend backend_mediatek =
-{
+struct backend backend_mediatek = {
.name = "mediatek",
.init = mediatek_init,
.bo_create = mediatek_bo_create,
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
static int nouveau_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-struct backend backend_nouveau =
-{
+struct backend backend_nouveau = {
.name = "nouveau",
.init = nouveau_init,
.bo_create = drv_dumb_bo_create,
--- /dev/null
+#!/bin/sh
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+find \
+ '(' -name '*.[ch]' -or -name '*.cc' ')' \
+ -not -name 'gbm.h' \
+ -exec clang-format -style=file -i {} +
#ifdef DRV_ROCKCHIP
#include <errno.h>
+#include <rockchip_drm.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <xf86drm.h>
-#include <rockchip_drm.h>
#include "drv_priv.h"
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_NV12,
- DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
- DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
+ DRM_FORMAT_NV12, DRM_FORMAT_RGB565,
+ DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
+ DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID };
-static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format)
+static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height, uint32_t format)
{
/* We've restricted ourselves to four bytes per pixel. */
const uint32_t pixel_size = 4;
* alignement for the body plane. */
const uint32_t body_plane_alignment = 1024;
- const uint32_t body_plane_offset =
- ALIGN(header_plane_size, body_plane_alignment);
- const uint32_t total_size =
- body_plane_offset + body_plane_size;
+ const uint32_t body_plane_offset = ALIGN(header_plane_size, body_plane_alignment);
+ const uint32_t total_size = body_plane_offset + body_plane_size;
bo->strides[0] = width_in_blocks * block_width * pixel_size;
bo->sizes[0] = total_size;
for (i = 0; i < drv->backend->combos.size; i++) {
combo = &drv->backend->combos.data[i];
if (combo->format == item->format) {
- if (item->modifier ==
- DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) {
- flags = BO_USE_RENDERING | BO_USE_SCANOUT |
- BO_USE_TEXTURE;
+ if (item->modifier == DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) {
+ flags = BO_USE_RENDERING | BO_USE_SCANOUT | BO_USE_TEXTURE;
metadata.modifier = item->modifier;
metadata.tiling = 0;
metadata.priority = 2;
- ret = drv_add_combination(drv, item[i].format,
- &metadata, flags);
+ ret = drv_add_combination(drv, item[i].format, &metadata, flags);
if (ret)
return ret;
} else {
metadata.priority = 1;
metadata.modifier = DRM_FORMAT_MOD_NONE;
- ret = drv_add_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats), &metadata,
+ ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
BO_COMMON_USE_MASK);
if (ret)
return ret;
- drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
items = drv_query_kms(drv, &num_items);
if (!items || !num_items)
return false;
}
-static int rockchip_bo_create_with_modifiers(struct bo *bo,
- uint32_t width, uint32_t height,
- uint32_t format,
- const uint64_t *modifiers,
+static int rockchip_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
+ uint32_t format, const uint64_t *modifiers,
uint32_t count)
{
int ret;
uint32_t aligned_height = DIV_ROUND_UP(h_mbs * 16 * 3, 2);
drv_bo_from_format(bo, aligned_width, height, format);
- bo->total_size = bo->strides[0] * aligned_height
- + w_mbs * h_mbs * 128;
+ bo->total_size = bo->strides[0] * aligned_height + w_mbs * h_mbs * 128;
} else if (width <= 2560 &&
- has_modifier(modifiers, count,
- DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) {
+ has_modifier(modifiers, count, DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) {
/* If the caller has decided they can use AFBC, always
* pick that */
afbc_bo_from_format(bo, width, height, format);
* luma plane to 128 bytes.
*/
stride = drv_stride_from_format(format, width, 0);
- if (format == DRM_FORMAT_YVU420 ||
- format == DRM_FORMAT_YVU420_ANDROID)
+ if (format == DRM_FORMAT_YVU420 || format == DRM_FORMAT_YVU420_ANDROID)
stride = ALIGN(stride, 128);
else
stride = ALIGN(stride, 64);
memset(&gem_create, 0, sizeof(gem_create));
gem_create.size = bo->total_size;
- ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE,
- &gem_create);
+ ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE, &gem_create);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed "
- "(size=%llu)\n", gem_create.size);
+ "(size=%llu)\n",
+ gem_create.size);
return ret;
}
return 0;
}
-static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
uint64_t modifiers[] = { DRM_FORMAT_MOD_NONE };
- return rockchip_bo_create_with_modifiers(bo, width, height, format,
- modifiers, ARRAY_SIZE(modifiers));
+ return rockchip_bo_create_with_modifiers(bo, width, height, format, modifiers,
+ ARRAY_SIZE(modifiers));
}
static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane)
memset(&gem_map, 0, sizeof(gem_map));
gem_map.handle = bo->handles[0].u32;
- ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET,
- &gem_map);
+ ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET, &gem_map);
if (ret) {
- fprintf(stderr,
- "drv: DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET failed\n");
+ fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET failed\n");
return MAP_FAILED;
}
data->length = bo->total_size;
- return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
- bo->drv->fd, gem_map.offset);
+ return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
+ gem_map.offset);
}
static uint32_t rockchip_resolve_format(uint32_t format)
}
}
-struct backend backend_rockchip =
-{
+struct backend backend_rockchip = {
.name = "rockchip",
.init = rockchip_init,
.bo_create = rockchip_bo_create,
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
-#include <xf86drm.h>
#include <tegra_drm.h>
+#include <xf86drm.h>
#include "drv_priv.h"
#include "helpers.h"
#define NV_DEFAULT_BLOCK_HEIGHT_LOG2 4
#define NV_PREFERRED_PAGE_SIZE (128 * 1024)
+// clang-format off
enum nv_mem_kind
{
NV_MEM_KIND_PITCH = 0,
TEGRA_READ_TILED_BUFFER = 0,
TEGRA_WRITE_TILED_BUFFER = 1,
};
+// clang-format on
struct tegra_private_map_data {
void *tiled;
void *untiled;
};
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
static int compute_block_height_log2(int height)
{
return block_height_log2;
}
-static void compute_layout_blocklinear(int width, int height, int format,
- enum nv_mem_kind *kind,
- uint32_t *block_height_log2,
- uint32_t *stride, uint32_t *size)
+static void compute_layout_blocklinear(int width, int height, int format, enum nv_mem_kind *kind,
+ uint32_t *block_height_log2, uint32_t *stride,
+ uint32_t *size)
{
int pitch = drv_stride_from_format(format, width, 0);
/* Compute padded height. */
*block_height_log2 = compute_block_height_log2(height);
int block_height = 1 << *block_height_log2;
- int padded_height =
- ALIGN(height, NV_BLOCKLINEAR_GOB_HEIGHT * block_height);
+ int padded_height = ALIGN(height, NV_BLOCKLINEAR_GOB_HEIGHT * block_height);
int bytes = pitch * padded_height;
*size = bytes;
}
-static void compute_layout_linear(int width, int height, int format,
- uint32_t *stride, uint32_t *size)
+static void compute_layout_linear(int width, int height, int format, uint32_t *stride,
+ uint32_t *size)
{
*stride = ALIGN(drv_stride_from_format(format, width, 0), 64);
*size = *stride * height;
}
-static void transfer_tile(struct bo *bo, uint8_t *tiled, uint8_t *untiled,
- enum tegra_map_type type, uint32_t bytes_per_pixel,
- uint32_t gob_top, uint32_t gob_left,
+static void transfer_tile(struct bo *bo, uint8_t *tiled, uint8_t *untiled, enum tegra_map_type type,
+ uint32_t bytes_per_pixel, uint32_t gob_top, uint32_t gob_left,
uint32_t gob_size_pixels)
{
uint8_t *tmp;
}
}
-static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled,
- uint8_t *untiled, enum tegra_map_type type)
+static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled, uint8_t *untiled,
+ enum tegra_map_type type)
{
- uint32_t gob_width, gob_height, gob_size_bytes, gob_size_pixels,
- gob_count_x, gob_count_y, gob_top, gob_left;
+ uint32_t gob_width, gob_height, gob_size_bytes, gob_size_pixels, gob_count_x, gob_count_y,
+ gob_top, gob_left;
uint32_t i, j, offset;
uint8_t *tmp;
uint32_t bytes_per_pixel = drv_stride_from_format(bo->format, 1, 0);
* where 0 <= n <= 4.
*/
gob_width = DIV_ROUND_UP(NV_BLOCKLINEAR_GOB_WIDTH, bytes_per_pixel);
- gob_height = NV_BLOCKLINEAR_GOB_HEIGHT *
- (1 << NV_DEFAULT_BLOCK_HEIGHT_LOG2);
+ gob_height = NV_BLOCKLINEAR_GOB_HEIGHT * (1 << NV_DEFAULT_BLOCK_HEIGHT_LOG2);
/* Calculate the height from maximum possible gob height */
- while (gob_height > NV_BLOCKLINEAR_GOB_HEIGHT
- && gob_height >= 2 * bo->height)
+ while (gob_height > NV_BLOCKLINEAR_GOB_HEIGHT && gob_height >= 2 * bo->height)
gob_height /= 2;
gob_size_bytes = gob_height * NV_BLOCKLINEAR_GOB_WIDTH;
tmp = tiled + offset;
gob_left = i * gob_width;
- transfer_tile(bo, tmp, untiled, type, bytes_per_pixel,
- gob_top, gob_left, gob_size_pixels);
+ transfer_tile(bo, tmp, untiled, type, bytes_per_pixel, gob_top, gob_left,
+ gob_size_pixels);
offset += gob_size_bytes;
}
metadata.priority = 1;
metadata.modifier = DRM_FORMAT_MOD_NONE;
- ret = drv_add_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats), &metadata,
+ ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
flags);
if (ret)
return ret;
- drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
- BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
flags &= ~BO_USE_SW_WRITE_OFTEN;
flags &= ~BO_USE_SW_READ_OFTEN;
metadata.tiling = NV_MEM_KIND_C32_2CRA;
metadata.priority = 2;
- ret = drv_add_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats), &metadata,
+ ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
flags);
if (ret)
return ret;
- drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
- BO_USE_SCANOUT);
- drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
- BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_SCANOUT);
+ drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_SCANOUT);
return 0;
}
-static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
uint32_t size, stride, block_height_log2 = 0;
enum nv_mem_kind kind = NV_MEM_KIND_PITCH;
struct drm_tegra_gem_create gem_create;
int ret;
- if (flags & (BO_USE_CURSOR | BO_USE_LINEAR |
- BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
+ if (flags & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
compute_layout_linear(width, height, format, &stride, &size);
else
- compute_layout_blocklinear(width, height, format, &kind,
- &block_height_log2, &stride, &size);
+ compute_layout_blocklinear(width, height, format, &kind, &block_height_log2,
+ &stride, &size);
memset(&gem_create, 0, sizeof(gem_create));
gem_create.size = size;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_TEGRA_GEM_CREATE, &gem_create);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_TEGRA_GEM_CREATE failed "
- "(size=%zu)\n", size);
+ "(size=%zu)\n",
+ size);
return ret;
}
gem_tile.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
gem_tile.value = block_height_log2;
- ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_SET_TILING,
- &gem_tile, sizeof(gem_tile));
+ ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_SET_TILING, &gem_tile,
+ sizeof(gem_tile));
if (ret < 0) {
drv_gem_bo_destroy(bo);
return ret;
}
/* Encode blocklinear parameters for EGLImage creation. */
- bo->tiling = (kind & 0xff) |
- ((block_height_log2 & 0xf) << 8);
+ bo->tiling = (kind & 0xff) | ((block_height_log2 & 0xf) << 8);
bo->format_modifiers[0] = fourcc_mod_code(NV, bo->tiling);
}
memset(&gem_map, 0, sizeof(gem_map));
gem_map.handle = bo->handles[0].u32;
- ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_MMAP, &gem_map,
- sizeof(gem_map));
+ ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_MMAP, &gem_map, sizeof(gem_map));
if (ret < 0) {
fprintf(stderr, "drv: DRM_TEGRA_GEM_MMAP failed\n");
return MAP_FAILED;
}
- void *addr = mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
- bo->drv->fd, gem_map.offset);
+ void *addr = mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
+ gem_map.offset);
data->length = bo->total_size;
priv->untiled = calloc(1, bo->total_size);
priv->tiled = addr;
data->priv = priv;
- transfer_tiled_memory(bo, priv->tiled, priv->untiled,
- TEGRA_READ_TILED_BUFFER);
+ transfer_tiled_memory(bo, priv->tiled, priv->untiled, TEGRA_READ_TILED_BUFFER);
addr = priv->untiled;
}
{
if (data->priv) {
struct tegra_private_map_data *priv = data->priv;
- transfer_tiled_memory(bo, priv->tiled, priv->untiled,
- TEGRA_WRITE_TILED_BUFFER);
+ transfer_tiled_memory(bo, priv->tiled, priv->untiled, TEGRA_WRITE_TILED_BUFFER);
data->addr = priv->tiled;
free(priv->untiled);
free(priv);
return munmap(data->addr, data->length);
}
-struct backend backend_tegra =
-{
+struct backend backend_tegra = {
.name = "tegra",
.init = tegra_init,
.bo_create = tegra_bo_create,
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
static int udl_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-struct backend backend_udl =
-{
+struct backend backend_udl = {
.name = "udl",
.init = udl_init,
.bo_create = drv_dumb_bo_create,
#define UTIL_H
#define MAX(A, B) ((A) > (B) ? (A) : (B))
-#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A)))
+#define ARRAY_SIZE(A) (sizeof(A) / sizeof(*(A)))
#define PUBLIC __attribute__((visibility("default")))
-#define ALIGN(A, B) (((A) + (B) - 1) / (B) * (B))
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define ALIGN(A, B) (((A) + (B)-1) / (B) * (B))
+#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d))
#endif
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
+ DRM_FORMAT_XRGB8888 };
static int vc4_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
int ret;
size_t plane;
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_VC4_CREATE_BO, &bo_create);
if (ret) {
fprintf(stderr, "drv: DRM_IOCTL_VC4_GEM_CREATE failed "
- "(size=%zu)\n", bo->total_size);
+ "(size=%zu)\n",
+ bo->total_size);
return ret;
}
memset(&bo_map, 0, sizeof(bo_map));
bo_map.handle = bo->handles[0].u32;
- ret = drmCommandWriteRead(bo->drv->fd, DRM_VC4_MMAP_BO, &bo_map,
- sizeof(bo_map));
+ ret = drmCommandWriteRead(bo->drv->fd, DRM_VC4_MMAP_BO, &bo_map, sizeof(bo_map));
if (ret) {
fprintf(stderr, "drv: DRM_VC4_MMAP_BO failed\n");
return MAP_FAILED;
data->length = bo->total_size;
- return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
- bo->drv->fd, bo_map.offset);
+ return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
+ bo_map.offset);
}
-struct backend backend_vc4 =
-{
+struct backend backend_vc4 = {
.name = "vc4",
.init = vc4_init,
.bo_create = vc4_bo_create,
#define MESA_LLVMPIPE_TILE_ORDER 6
#define MESA_LLVMPIPE_TILE_SIZE (1 << MESA_LLVMPIPE_TILE_ORDER)
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
- DRM_FORMAT_YVU420_ANDROID
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
+ DRM_FORMAT_XRGB8888, DRM_FORMAT_YVU420_ANDROID };
static int vgem_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-static int vgem_bo_create(struct bo *bo, uint32_t width, uint32_t height,
- uint32_t format, uint32_t flags)
+static int vgem_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+ uint32_t flags)
{
int ret = drv_dumb_bo_create(bo, ALIGN(width, MESA_LLVMPIPE_TILE_SIZE),
- ALIGN(height, MESA_LLVMPIPE_TILE_SIZE),
- format, flags);
+ ALIGN(height, MESA_LLVMPIPE_TILE_SIZE), format, flags);
return ret;
}
}
}
-struct backend backend_vgem =
-{
+struct backend backend_vgem = {
.name = "vgem",
.init = vgem_init,
.bo_create = vgem_bo_create,
.bo_map = drv_dumb_bo_map,
.resolve_format = vgem_resolve_format,
};
-
#include "helpers.h"
#include "util.h"
-static const uint32_t supported_formats[] = {
- DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
-};
+static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
static int virtio_gpu_init(struct driver *drv)
{
- return drv_add_linear_combinations(drv, supported_formats,
- ARRAY_SIZE(supported_formats));
+ return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
}
-struct backend backend_virtio_gpu =
-{
+struct backend backend_virtio_gpu = {
.name = "virtio_gpu",
.init = virtio_gpu_init,
.bo_create = drv_dumb_bo_create,
.bo_import = drv_prime_bo_import,
.bo_map = drv_dumb_bo_map,
};
-