OSDN Git Service

minigbm: add clang-format and presubmit hooks
authorGurchetan Singh <gurchetansingh@chromium.org>
Sat, 11 Mar 2017 00:25:23 +0000 (16:25 -0800)
committerchrome-bot <chrome-bot@chromium.org>
Fri, 31 Mar 2017 17:40:27 +0000 (10:40 -0700)
Running the presubmit.sh script will apply our rules to every file in
the repo. Exclude gbm.h from the formatting requirements since this file
was taken from other open-source projects, and diffing will be easier
without our formatting rules.

In addition, special case drivers where the order of includes matters.

BUG=none
TEST=Verified the following commands succeed:

emerge-cyan minigbm/arc-cros-gralloc
emerge-oak minigbm/arc-cros-gralloc
emerge-veyron_minnie-cheets minigbm/arc-cros-gralloc
emerge-peach_pi minigbm
emerge-nyan_big minigbm
emerge-jadeite minigbm

Change-Id: I6ce93fb1930da254d13d5017766c17341870ccc9
Reviewed-on: https://chromium-review.googlesource.com/447319
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
32 files changed:
.clang-format [new file with mode: 0644]
PRESUBMIT.cfg [new file with mode: 0644]
amdgpu.c
cirrus.c
cros_gralloc/cros_alloc_device.cc
cros_gralloc/cros_gralloc.h
cros_gralloc/cros_gralloc_handle.h
cros_gralloc/cros_gralloc_helpers.cc
cros_gralloc/cros_gralloc_helpers.h
cros_gralloc/cros_gralloc_module.cc
drv.c
drv.h
drv_priv.h
evdi.c
exynos.c
gbm.c
gbm_priv.h
gma500.c
helpers.c
helpers.h
i915.c
marvell.c
mediatek.c
nouveau.c
presubmit.sh [new file with mode: 0755]
rockchip.c
tegra.c
udl.c
util.h
vc4.c
vgem.c
virtio_gpu.c

diff --git a/.clang-format b/.clang-format
new file mode 100644 (file)
index 0000000..6628ecd
--- /dev/null
@@ -0,0 +1,15 @@
+# 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
diff --git a/PRESUBMIT.cfg b/PRESUBMIT.cfg
new file mode 100644 (file)
index 0000000..4f84392
--- /dev/null
@@ -0,0 +1,5 @@
+# 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
index 59242e9..1fd9d13 100644 (file)
--- a/amdgpu.c
+++ b/amdgpu.c
@@ -4,14 +4,14 @@
  * 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"
@@ -22,6 +22,7 @@
 #define CIASICIDGFXENGINE_SOUTHERNISLAND 0x0000000A
 #endif
 
+// clang-format off
 #define mmCC_RB_BACKEND_DISABLE                0x263d
 #define mmGB_TILE_MODE0                        0x2644
 #define mmGB_MACROTILE_MODE0           0x2664
@@ -38,15 +39,14 @@ enum {
        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;
@@ -64,18 +64,16 @@ static int amdgpu_set_metadata(int fd, uint32_t handle,
                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;
@@ -83,8 +81,7 @@ static int amdgpu_read_mm_regs(int fd, unsigned 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)
@@ -95,19 +92,16 @@ 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;
 
@@ -116,13 +110,11 @@ static int amdgpu_query_gpu(int fd, struct amdgpu_gpu_info *gpu_info)
        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;
 
@@ -140,22 +132,20 @@ static ADDR_E_RETURNCODE ADDR_API free_sys_mem(const ADDR_FREESYSMEM_INPUT *in)
        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;
@@ -182,13 +172,12 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
        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 */
@@ -212,16 +201,13 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
                /* 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;
@@ -230,16 +216,16 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
 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);
 
@@ -254,11 +240,10 @@ static void *amdgpu_addrlib_init(int fd)
 
        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;
 
@@ -298,25 +283,20 @@ static int amdgpu_init(struct driver *drv)
        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;
@@ -328,24 +308,19 @@ static int amdgpu_init(struct driver *drv)
        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;
@@ -359,31 +334,27 @@ static void amdgpu_close(struct driver *drv)
        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;
@@ -396,8 +367,8 @@ static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height,
        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;
@@ -406,8 +377,7 @@ static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height,
 
        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;
 }
@@ -427,8 +397,8 @@ static void *amdgpu_bo_map(struct bo *bo, struct map_info *data, size_t plane)
        }
        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 = {
@@ -442,4 +412,3 @@ struct backend backend_amdgpu = {
 };
 
 #endif
-
index 3df1930..bcd308b 100644 (file)
--- a/cirrus.c
+++ b/cirrus.c
@@ -8,18 +8,15 @@
 #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,
index 86d5e34..6477c0d 100644 (file)
@@ -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;
index a24b862..deca856 100644 (file)
@@ -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);
index 63b9da9..e2c0bcc 100644 (file)
@@ -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
index ed998e8..ed0a25a 100644 (file)
@@ -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);
index 7ba3a9a..0d79f92 100644 (file)
@@ -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
index ebc9c62..0101342 100644 (file)
@@ -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 constmodule,
-                                       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 constmodule,
+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,
 };
diff --git a/drv.c b/drv.c
index cfeb4b5..e94c2a8 100644 (file)
--- a/drv.c
+++ b/drv.c
@@ -64,8 +64,7 @@ static struct backend *drv_get_backend(int fd)
 #ifdef DRV_AMDGPU
                &backend_amdgpu,
 #endif
-               &backend_cirrus,
-               &backend_evdi,
+               &backend_cirrus,   &backend_evdi,
 #ifdef DRV_EXYNOS
                &backend_exynos,
 #endif
@@ -90,11 +89,10 @@ static struct backend *drv_get_backend(int fd)
 #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];
@@ -109,7 +107,7 @@ struct driver *drv_create(int fd)
        struct driver *drv;
        int ret;
 
-       drv = (struct driver *) calloc(1, sizeof(*drv));
+       drv = (struct driver *)calloc(1, sizeof(*drv));
 
        if (!drv)
                return NULL;
@@ -134,8 +132,8 @@ struct driver *drv_create(int fd)
        /* 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;
 
@@ -183,14 +181,12 @@ int drv_get_fd(struct driver *drv)
        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;
 
@@ -202,20 +198,18 @@ struct combination *drv_get_combination(struct driver *drv, uint32_t format,
        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;
@@ -234,8 +228,8 @@ struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height,
        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;
@@ -263,10 +257,8 @@ struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height,
        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;
@@ -282,8 +274,7 @@ struct bo *drv_bo_create_with_modifiers(struct driver *drv,
        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);
@@ -300,7 +291,6 @@ struct bo *drv_bo_create_with_modifiers(struct driver *drv,
        return bo;
 }
 
-
 void drv_bo_destroy(struct bo *bo)
 {
        size_t plane;
@@ -351,9 +341,8 @@ struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data)
        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;
@@ -368,7 +357,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
        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;
        }
@@ -385,18 +374,17 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
        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)
@@ -457,11 +445,9 @@ int drv_bo_get_plane_fd(struct bo *bo, size_t plane)
        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)
@@ -484,7 +470,7 @@ 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)
 {
-        assert(plane < bo->num_planes);
+       assert(plane < bo->num_planes);
        return bo->format_modifiers[plane];
 }
 
@@ -563,8 +549,7 @@ size_t drv_num_planes_from_format(uint32_t format)
        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;
diff --git a/drv.h b/drv.h
index 02c45fa..18e9233 100644 (file)
--- a/drv.h
+++ b/drv.h
@@ -16,6 +16,7 @@ extern "C" {
 
 #define DRV_MAX_PLANES 4
 
+// clang-format off
 /* Use flags */
 #define BO_USE_NONE                    0
 #define BO_USE_SCANOUT                 (1ull << 0)
@@ -52,6 +53,7 @@ extern "C" {
                           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;
@@ -83,97 +85,64 @@ struct map_info {
        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
 }
index d37532a..8884ea7 100644 (file)
@@ -14,8 +14,7 @@
 
 #include "drv.h"
 
-struct bo
-{
+struct bo {
        struct driver *drv;
        uint32_t width;
        uint32_t height;
@@ -64,21 +63,17 @@ struct combinations {
        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;
diff --git a/evdi.c b/evdi.c
index f9b05dc..dbdb79f 100644 (file)
--- a/evdi.c
+++ b/evdi.c
@@ -8,18 +8,14 @@
 #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,
@@ -27,4 +23,3 @@ struct backend backend_evdi =
        .bo_import = drv_prime_bo_import,
        .bo_map = drv_dumb_bo_map,
 };
-
index f79ac79..a18261e 100644 (file)
--- a/exynos.c
+++ b/exynos.c
@@ -6,29 +6,29 @@
 
 #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;
 
@@ -66,7 +66,8 @@ static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height,
                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;
                }
 
@@ -76,16 +77,13 @@ static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height,
        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);
                }
        }
 
@@ -96,8 +94,7 @@ cleanup_planes:
  * 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,
diff --git a/gbm.c b/gbm.c
index fb50286..ab576cf 100644 (file)
--- a/gbm.c
+++ b/gbm.c
 #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);
@@ -49,7 +44,7 @@ PUBLIC struct gbm_device *gbm_create_device(int fd)
 {
        struct gbm_device *gbm;
 
-       gbm = (struct gbm_device*) malloc(sizeof(*gbm));
+       gbm = (struct gbm_device *)malloc(sizeof(*gbm));
 
        if (!gbm)
                return NULL;
@@ -69,12 +64,10 @@ PUBLIC void gbm_device_destroy(struct gbm_device *gbm)
        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;
@@ -92,8 +85,7 @@ PUBLIC struct gbm_bo *gbm_surface_lock_front_buffer(struct gbm_surface *surface)
        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)
 {
 }
 
@@ -101,7 +93,7 @@ static struct gbm_bo *gbm_bo_new(struct gbm_device *gbm, uint32_t format)
 {
        struct gbm_bo *bo;
 
-       bo = (struct gbm_bo*) calloc(1, sizeof(*bo));
+       bo = (struct gbm_bo *)calloc(1, sizeof(*bo));
        if (!bo)
                return NULL;
 
@@ -111,9 +103,8 @@ static struct gbm_bo *gbm_bo_new(struct gbm_device *gbm, uint32_t format)
        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;
 
@@ -125,8 +116,7 @@ PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width,
        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);
@@ -136,12 +126,9 @@ PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width,
        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;
 
@@ -150,9 +137,7 @@ PUBLIC struct gbm_bo *gbm_bo_create_with_modifiers(struct gbm_device *gbm,
        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);
@@ -174,9 +159,8 @@ PUBLIC void gbm_bo_destroy(struct gbm_bo *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;
@@ -210,14 +194,10 @@ gbm_bo_import(struct gbm_device *gbm, uint32_t type,
                        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++)
@@ -246,132 +226,110 @@ gbm_bo_import(struct gbm_device *gbm, uint32_t type,
        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;
 }
index eb29f1b..3dc1e59 100644 (file)
@@ -8,23 +8,20 @@
 #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;
index fe4df1a..93d1bb8 100644 (file)
--- a/gma500.c
+++ b/gma500.c
@@ -8,18 +8,14 @@
 #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,
index 800d314..3022a08 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -18,8 +18,8 @@
 #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) {
@@ -105,8 +105,7 @@ static uint32_t bpp_from_format(uint32_t format, size_t plane)
 
 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);
 }
 
@@ -115,15 +114,14 @@ uint32_t drv_bo_get_stride_in_pixels(struct bo *bo)
  */
 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;
 }
@@ -133,8 +131,7 @@ uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane)
  * 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;
@@ -146,19 +143,17 @@ int drv_bo_from_format(struct bo *bo, uint32_t stride,
 
        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;
@@ -208,7 +203,8 @@ int drv_dumb_bo_destroy(struct bo *bo)
        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;
        }
 
@@ -236,7 +232,7 @@ int drv_gem_bo_destroy(struct bo *bo)
                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;
                }
        }
@@ -254,12 +250,12 @@ int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data)
                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,
@@ -303,43 +299,38 @@ void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane)
                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)
@@ -352,15 +343,14 @@ 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;
 
@@ -376,9 +366,8 @@ int drv_add_combination(struct driver *drv, uint32_t format,
        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;
@@ -391,16 +380,15 @@ int drv_add_combinations(struct driver *drv, const uint32_t *formats,
        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;
        }
@@ -443,8 +431,7 @@ struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items)
                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;
 
@@ -485,8 +472,7 @@ struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items)
                        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;
@@ -505,7 +491,6 @@ struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items)
 
                drmModeFreeObjectProperties(props);
                drmModeFreePlane(plane);
-
        }
 
        drmModeFreePlaneResources(resources);
@@ -519,8 +504,7 @@ out:
        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;
@@ -532,8 +516,7 @@ int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
        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;
        /*
@@ -543,10 +526,8 @@ int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
         * 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)
@@ -557,8 +538,6 @@ int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
                        combo = &drv->backend->combos.data[j];
                        if (items[i].format == combo->format)
                                combo->usage |= BO_USE_SCANOUT;
-
-
                }
        }
 
index 5acd01f..ebe6987 100644 (file)
--- a/helpers.h
+++ b/helpers.h
 #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
diff --git a/i915.c b/i915.c
index b744d38..b7f591c 100644 (file)
--- a/i915.c
+++ b/i915.c
 #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;
 
@@ -65,9 +61,9 @@ static int i915_add_kms_item(struct driver *drv, const struct kms_item *item)
                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) {
@@ -91,22 +87,18 @@ static int i915_add_combinations(struct driver *drv)
        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;
@@ -115,8 +107,7 @@ static int i915_add_combinations(struct driver *drv)
        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;
@@ -124,9 +115,8 @@ static int i915_add_combinations(struct driver *drv)
        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;
 
@@ -146,8 +136,8 @@ static int i915_add_combinations(struct driver *drv)
        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;
@@ -168,7 +158,7 @@ static int i915_align_dimensions(struct bo *bo, uint32_t tiling,
                if (i915->gen == 3) {
                        horizontal_alignment = 512;
                        vertical_alignment = 8;
-               } else  {
+               } else {
                        horizontal_alignment = 128;
                        vertical_alignment = 32;
                }
@@ -235,8 +225,8 @@ static void i915_close(struct driver *drv)
        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;
@@ -248,8 +238,7 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
        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;
@@ -260,8 +249,7 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
         * 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;
        }
@@ -281,8 +269,7 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
 
        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);
@@ -300,12 +287,12 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
 
        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;
@@ -350,8 +337,8 @@ static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data)
         */
        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]) {
                        /*
@@ -369,8 +356,7 @@ static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data)
                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;
@@ -426,8 +412,7 @@ static uint32_t i915_resolve_format(uint32_t format)
        }
 }
 
-struct backend backend_i915 =
-{
+struct backend backend_i915 = {
        .name = "i915",
        .init = i915_init,
        .close = i915_close,
index 90f2cd8..d39e264 100644 (file)
--- a/marvell.c
+++ b/marvell.c
 #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,
index ab59e9a..e018b36 100644 (file)
@@ -6,30 +6,30 @@
 
 #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;
@@ -50,7 +50,8 @@ static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height,
        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;
        }
 
@@ -70,14 +71,14 @@ static void *mediatek_bo_map(struct bo *bo, struct map_info *data, size_t plane)
 
        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)
@@ -93,8 +94,7 @@ 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,
index 66fa132..aa832c2 100644 (file)
--- a/nouveau.c
+++ b/nouveau.c
@@ -8,18 +8,14 @@
 #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,
diff --git a/presubmit.sh b/presubmit.sh
new file mode 100755 (executable)
index 0000000..735b6b3
--- /dev/null
@@ -0,0 +1,9 @@
+#!/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 {} +
index 42d3f76..4d10581 100644 (file)
@@ -7,25 +7,23 @@
 #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;
@@ -55,10 +53,8 @@ static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height,
         * 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;
@@ -82,16 +78,13 @@ static int rockchip_add_kms_item(struct driver *drv, const struct kms_item *item
        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 {
@@ -114,16 +107,13 @@ static int rockchip_init(struct driver *drv)
        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)
@@ -152,10 +142,8 @@ static bool has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier
        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;
@@ -170,11 +158,9 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
                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);
@@ -193,8 +179,7 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
                 * 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);
@@ -205,12 +190,12 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
        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;
        }
 
@@ -220,13 +205,13 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
        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)
@@ -242,18 +227,16 @@ 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)
@@ -269,8 +252,7 @@ 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,
diff --git a/tegra.c b/tegra.c
index 00e1eaa..c2b9a6c 100644 (file)
--- a/tegra.c
+++ b/tegra.c
@@ -9,8 +9,8 @@
 #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"
@@ -26,6 +26,7 @@
 #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,
@@ -37,15 +38,14 @@ enum tegra_map_type {
        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)
 {
@@ -65,10 +65,9 @@ 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);
 
@@ -78,8 +77,7 @@ static void compute_layout_blocklinear(int width, int height, int format,
        /* 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;
 
@@ -94,16 +92,15 @@ static void compute_layout_blocklinear(int width, int height, int format,
        *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;
@@ -129,11 +126,11 @@ static void transfer_tile(struct bo *bo, uint8_t *tiled, uint8_t *untiled,
        }
 }
 
-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);
@@ -143,11 +140,9 @@ static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled,
         * 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;
@@ -163,8 +158,8 @@ static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled,
                        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;
                }
@@ -181,16 +176,13 @@ static int tegra_init(struct driver *drv)
        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;
@@ -199,33 +191,29 @@ static int tegra_init(struct driver *drv)
        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;
@@ -234,7 +222,8 @@ static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height,
        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;
        }
 
@@ -251,16 +240,15 @@ static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height,
                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);
        }
 
@@ -276,15 +264,14 @@ static void *tegra_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 = 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;
 
@@ -293,8 +280,7 @@ static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane)
                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;
        }
 
@@ -305,8 +291,7 @@ static int tegra_bo_unmap(struct bo *bo, struct map_info *data)
 {
        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);
@@ -316,8 +301,7 @@ static int tegra_bo_unmap(struct bo *bo, struct map_info *data)
        return munmap(data->addr, data->length);
 }
 
-struct backend backend_tegra =
-{
+struct backend backend_tegra = {
        .name = "tegra",
        .init = tegra_init,
        .bo_create = tegra_bo_create,
diff --git a/udl.c b/udl.c
index 42a8739..dffd5f5 100644 (file)
--- a/udl.c
+++ b/udl.c
@@ -8,18 +8,14 @@
 #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,
diff --git a/util.h b/util.h
index 696b996..fd61d9b 100644 (file)
--- a/util.h
+++ b/util.h
@@ -8,9 +8,9 @@
 #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
diff --git a/vc4.c b/vc4.c
index 7036de7..9103b8a 100644 (file)
--- a/vc4.c
+++ b/vc4.c
 #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;
@@ -48,7 +46,8 @@ static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height,
        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;
        }
 
@@ -66,8 +65,7 @@ static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane)
        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;
@@ -75,12 +73,11 @@ static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane)
 
        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,
diff --git a/vgem.c b/vgem.c
index 4139989..2b6fbcd 100644 (file)
--- a/vgem.c
+++ b/vgem.c
 #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;
 }
 
@@ -44,8 +40,7 @@ static uint32_t vgem_resolve_format(uint32_t format)
        }
 }
 
-struct backend backend_vgem =
-{
+struct backend backend_vgem = {
        .name = "vgem",
        .init = vgem_init,
        .bo_create = vgem_bo_create,
@@ -54,4 +49,3 @@ struct backend backend_vgem =
        .bo_map = drv_dumb_bo_map,
        .resolve_format = vgem_resolve_format,
 };
-
index b455cf5..238c117 100644 (file)
@@ -8,18 +8,14 @@
 #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,
@@ -27,4 +23,3 @@ struct backend backend_virtio_gpu =
        .bo_import = drv_prime_bo_import,
        .bo_map = drv_dumb_bo_map,
 };
-