From b7a64441efd3e185927c7a23f8d72f8bbe63bf46 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Thu, 30 Sep 2021 05:13:10 +0000 Subject: [PATCH] minigbm: refactor driver helpers 1. frontends access the driver via drv.h only 2. the renamed drv_helpers and drv_array_helpers are for driver only 3. remove extern "C" from drv_helpers.h given not exposed to gralloc 4. remove all redundant includes for those helpers BUG=b:199524294 TEST=CQ and gralloc builds on aosp Change-Id: I3f4d33076a6a8161804f1b7c26950ff5496507e9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3195651 Tested-by: Yiwei Zhang Reviewed-by: Chia-I Wu Commit-Queue: Yiwei Zhang --- Android.mk | 4 ++-- amdgpu.c | 2 +- cros_gralloc/cros_gralloc_buffer.h | 1 - cros_gralloc/cros_gralloc_driver.cc | 2 -- cros_gralloc/gralloc0/gralloc0.cc | 1 - cros_gralloc/gralloc4/CrosGralloc4Mapper.cc | 2 -- dri.c | 2 +- drv.c | 11 +++++++++-- drv.h | 3 +++ helpers_array.c => drv_array_helpers.c | 1 + helpers_array.h => drv_array_helpers.h | 7 +++++++ helpers.c => drv_helpers.c | 11 ++--------- helpers.h => drv_helpers.h | 17 +++++------------ dumb_driver.c | 2 +- i915.c | 2 +- mediatek.c | 2 +- msm.c | 2 +- rockchip.c | 2 +- vc4.c | 2 +- virtgpu.c | 1 - virtgpu_cross_domain.c | 2 +- virtgpu_virgl.c | 2 +- 22 files changed, 39 insertions(+), 42 deletions(-) rename helpers_array.c => drv_array_helpers.c (98%) rename helpers_array.h => drv_array_helpers.h (89%) rename helpers.c => drv_helpers.c (98%) rename helpers.h => drv_helpers.h (91%) diff --git a/Android.mk b/Android.mk index e45a898..451faea 100644 --- a/Android.mk +++ b/Android.mk @@ -11,10 +11,10 @@ MINIGBM_SRC := \ amdgpu.c \ dri.c \ drv.c \ + drv_array_helpers.c \ + drv_helpers.c \ dumb_driver.c \ exynos.c \ - helpers_array.c \ - helpers.c \ i915.c \ mediatek.c \ meson.c \ diff --git a/amdgpu.c b/amdgpu.c index da211ca..9b964a1 100644 --- a/amdgpu.c +++ b/amdgpu.c @@ -19,8 +19,8 @@ #include #include "dri.h" +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" // clang-format off diff --git a/cros_gralloc/cros_gralloc_buffer.h b/cros_gralloc/cros_gralloc_buffer.h index 9bc0ef0..3158454 100644 --- a/cros_gralloc/cros_gralloc_buffer.h +++ b/cros_gralloc/cros_gralloc_buffer.h @@ -7,7 +7,6 @@ #ifndef CROS_GRALLOC_BUFFER_H #define CROS_GRALLOC_BUFFER_H -#include "../drv.h" #include "cros_gralloc_helpers.h" class cros_gralloc_buffer diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index 70f261c..a2d47b4 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -13,8 +13,6 @@ #include #include -#include "../drv_priv.h" -#include "../helpers.h" #include "../util.h" // Constants taken from pipe_loader_drm.c in Mesa diff --git a/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc index 5f471d1..964f86e 100644 --- a/cros_gralloc/gralloc0/gralloc0.cc +++ b/cros_gralloc/gralloc0/gralloc0.cc @@ -4,7 +4,6 @@ * found in the LICENSE file. */ -#include "../../helpers.h" #include "../../util.h" #include "../cros_gralloc_driver.h" diff --git a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc index 327c8ca..8f952e1 100644 --- a/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc +++ b/cros_gralloc/gralloc4/CrosGralloc4Mapper.cc @@ -16,8 +16,6 @@ #include "cros_gralloc/cros_gralloc_helpers.h" #include "cros_gralloc/gralloc4/CrosGralloc4Utils.h" -#include "helpers.h" - using aidl::android::hardware::graphics::common::BlendMode; using aidl::android::hardware::graphics::common::Dataspace; using aidl::android::hardware::graphics::common::PlaneLayout; diff --git a/dri.c b/dri.c index f89bbed..8b55c32 100644 --- a/dri.c +++ b/dri.c @@ -18,8 +18,8 @@ #include #include "dri.h" +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" static const struct { diff --git a/drv.c b/drv.c index b50eea6..3a18fd0 100644 --- a/drv.c +++ b/drv.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -21,8 +20,8 @@ #include #endif +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" #ifdef DRV_AMDGPU @@ -703,6 +702,14 @@ size_t drv_bo_get_total_size(struct bo *bo) return bo->meta.total_size; } +/* + * Map internal fourcc codes back to standard fourcc codes. + */ +uint32_t drv_get_standard_fourcc(uint32_t fourcc_internal) +{ + return (fourcc_internal == DRM_FORMAT_YVU420_ANDROID) ? DRM_FORMAT_YVU420 : fourcc_internal; +} + uint32_t drv_resolve_format(struct driver *drv, uint32_t format, uint64_t use_flags) { if (drv->backend->resolve_format) diff --git a/drv.h b/drv.h index 99b4afd..037cc01 100644 --- a/drv.h +++ b/drv.h @@ -14,6 +14,7 @@ extern "C" { #include #include #include +#include #define DRV_MAX_PLANES 4 @@ -178,6 +179,8 @@ uint64_t drv_bo_get_use_flags(struct bo *bo); size_t drv_bo_get_total_size(struct bo *bo); +uint32_t drv_get_standard_fourcc(uint32_t fourcc_internal); + uint32_t drv_bytes_per_pixel_from_format(uint32_t format, size_t plane); uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane); diff --git a/helpers_array.c b/drv_array_helpers.c similarity index 98% rename from helpers_array.c rename to drv_array_helpers.c index 2ec9063..b4e7750 100644 --- a/helpers_array.c +++ b/drv_array_helpers.c @@ -3,6 +3,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#include "drv_array_helpers.h" #include #include diff --git a/helpers_array.h b/drv_array_helpers.h similarity index 89% rename from helpers_array.h rename to drv_array_helpers.h index 2893976..77544d3 100644 --- a/helpers_array.h +++ b/drv_array_helpers.h @@ -4,6 +4,11 @@ * found in the LICENSE file. */ +#ifndef DRV_ARRAY_HELPERS_H +#define DRV_ARRAY_HELPERS_H + +#include + struct drv_array; struct drv_array *drv_array_init(uint32_t item_size); @@ -20,3 +25,5 @@ uint32_t drv_array_size(struct drv_array *array); /* The array and all associated data will be freed. */ void drv_array_destroy(struct drv_array *array); + +#endif diff --git a/helpers.c b/drv_helpers.c similarity index 98% rename from helpers.c rename to drv_helpers.c index fc67bbf..3874251 100644 --- a/helpers.c +++ b/drv_helpers.c @@ -4,6 +4,8 @@ * found in the LICENSE file. */ +#include "drv_helpers.h" + #include #include #include @@ -15,7 +17,6 @@ #include #include "drv_priv.h" -#include "helpers.h" #include "util.h" struct planar_layout { @@ -572,14 +573,6 @@ bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier) return false; } -/* - * Map internal fourcc codes back to standard fourcc codes. - */ -uint32_t drv_get_standard_fourcc(uint32_t fourcc_internal) -{ - return (fourcc_internal == DRM_FORMAT_YVU420_ANDROID) ? DRM_FORMAT_YVU420 : fourcc_internal; -} - uint32_t drv_resolve_format_helper(uint32_t format, uint64_t use_flags) { switch (format) { diff --git a/helpers.h b/drv_helpers.h similarity index 91% rename from helpers.h rename to drv_helpers.h index f40432b..2913fb3 100644 --- a/helpers.h +++ b/drv_helpers.h @@ -4,22 +4,20 @@ * found in the LICENSE file. */ -#ifndef HELPERS_H -#define HELPERS_H - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef DRV_HELPERS_H +#define DRV_HELPERS_H #include #include "drv.h" -#include "helpers_array.h" +#include "drv_array_helpers.h" #ifndef PAGE_SIZE #define PAGE_SIZE 0x1000 #endif +struct format_metadata; + uint32_t drv_height_from_format(uint32_t format, uint32_t height, size_t plane); uint32_t drv_vertical_subsampling_from_format(uint32_t format, size_t plane); uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, size_t plane); @@ -46,12 +44,7 @@ int drv_modify_linear_combinations(struct driver *drv); uint64_t drv_pick_modifier(const uint64_t *modifiers, uint32_t count, const uint64_t *modifier_order, uint32_t order_count); bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier); -uint32_t drv_get_standard_fourcc(uint32_t fourcc_internal); uint32_t drv_resolve_format_helper(uint32_t format, uint64_t use_flags); uint64_t drv_resolve_use_flags_helper(struct driver *drv, uint32_t format, uint64_t use_flags); -#ifdef __cplusplus -} -#endif - #endif diff --git a/dumb_driver.c b/dumb_driver.c index f5a62aa..d94ca4e 100644 --- a/dumb_driver.c +++ b/dumb_driver.c @@ -4,8 +4,8 @@ * found in the LICENSE file. */ +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" #define INIT_DUMB_DRIVER(driver) \ diff --git a/i915.c b/i915.c index 0cd0a89..c4002ef 100644 --- a/i915.c +++ b/i915.c @@ -15,9 +15,9 @@ #include #include +#include "drv_helpers.h" #include "drv_priv.h" #include "external/i915_drm.h" -#include "helpers.h" #include "util.h" #define I915_CACHELINE_SIZE 64 diff --git a/mediatek.c b/mediatek.c index b25fa00..81f9441 100644 --- a/mediatek.c +++ b/mediatek.c @@ -19,8 +19,8 @@ #include // clang-format on +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" #define TILE_TYPE_LINEAR 0 diff --git a/msm.c b/msm.c index 694fd58..4bb889d 100644 --- a/msm.c +++ b/msm.c @@ -18,8 +18,8 @@ #include #include +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" /* Alignment values are based on SDM845 Gfx IP */ diff --git a/rockchip.c b/rockchip.c index 960023a..5de4977 100644 --- a/rockchip.c +++ b/rockchip.c @@ -14,8 +14,8 @@ #include #include +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" struct rockchip_private_map_data { diff --git a/vc4.c b/vc4.c index 5ea4bc3..9f6a679 100644 --- a/vc4.c +++ b/vc4.c @@ -13,8 +13,8 @@ #include #include +#include "drv_helpers.h" #include "drv_priv.h" -#include "helpers.h" #include "util.h" static const uint32_t render_target_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, diff --git a/virtgpu.c b/virtgpu.c index 802749b..db50b46 100644 --- a/virtgpu.c +++ b/virtgpu.c @@ -13,7 +13,6 @@ #include "drv_priv.h" #include "external/virtgpu_drm.h" -#include "helpers.h" #include "util.h" #include "virtgpu.h" diff --git a/virtgpu_cross_domain.c b/virtgpu_cross_domain.c index c999a4f..160704e 100644 --- a/virtgpu_cross_domain.c +++ b/virtgpu_cross_domain.c @@ -9,10 +9,10 @@ #include #include +#include "drv_helpers.h" #include "drv_priv.h" #include "external/virtgpu_cross_domain_protocol.h" #include "external/virtgpu_drm.h" -#include "helpers.h" #include "util.h" #include "virtgpu.h" diff --git a/virtgpu_virgl.c b/virtgpu_virgl.c index 82a39d9..9745288 100644 --- a/virtgpu_virgl.c +++ b/virtgpu_virgl.c @@ -12,11 +12,11 @@ #include #include +#include "drv_helpers.h" #include "drv_priv.h" #include "external/virgl_hw.h" #include "external/virgl_protocol.h" #include "external/virtgpu_drm.h" -#include "helpers.h" #include "util.h" #include "virtgpu.h"