OSDN Git Service

drm_hwcomposer: Use gralloc0::perform API by minigbm bufferinfo getter
authorRoman Stratiienko <roman.o.stratiienko@globallogic.com>
Tue, 30 Nov 2021 15:48:16 +0000 (17:48 +0200)
committerRoman Stratiienko <roman.o.stratiienko@globallogic.com>
Mon, 6 Dec 2021 11:22:34 +0000 (13:22 +0200)
Using of internals of cros_gralloc_handle isn't recommended, since
it can be changed at any time. Meanwhile minigbm provides another
API to access buffer information based on gralloc0 perform() call.

ChromiumOS are using this API by mesa3d and other related projects.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Android.bp
bufferinfo/legacy/BufferInfoMinigbm.cpp
tests/test_include/cros_gralloc_handle.h [deleted file]

index 87e2efd..4df2b07 100644 (file)
@@ -136,7 +136,6 @@ cc_library_shared {
         ":drm_hwcomposer_common",
         "bufferinfo/legacy/BufferInfoMinigbm.cpp",
     ],
-    include_dirs: ["external/minigbm/cros_gralloc"],
 }
 
 // Used by hwcomposer.drm_imagination
index 93b9e98..777c2b7 100644 (file)
 #include <cerrno>
 #include <cstring>
 
-#include "cros_gralloc_handle.h"
 #include "utils/log.h"
-
-#define DRM_FORMAT_YVU420_ANDROID fourcc_code('9', '9', '9', '7')
-
 namespace android {
 
 LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm);
 
+constexpr int CROS_GRALLOC_DRM_GET_FORMAT = 1;
+constexpr int CROS_GRALLOC_DRM_GET_DIMENSIONS = 2;
+constexpr int CROS_GRALLOC_DRM_GET_BUFFER_INFO = 4;
+constexpr int CROS_GRALLOC_DRM_GET_USAGE = 5;
+
+struct cros_gralloc0_buffer_info {
+  uint32_t drm_fourcc;
+  int num_fds;
+  int fds[4];
+  uint64_t modifier;
+  int offset[4];
+  int stride[4];
+};
+
 int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
-  auto *gr_handle = (cros_gralloc_handle *)handle;
-  if (!gr_handle)
+  if (handle == nullptr) {
+    return -EINVAL;
+  }
+
+  uint32_t width{};
+  uint32_t height{};
+  if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_DIMENSIONS, handle,
+                        &width, &height) != 0) {
+    ALOGE(
+        "CROS_GRALLOC_DRM_GET_DIMENSIONS operation has failed. "
+        "Please ensure you are using the latest minigbm.");
+    return -EINVAL;
+  }
+
+  int32_t droid_format{};
+  if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_FORMAT, handle,
+                        &droid_format) != 0) {
+    ALOGE(
+        "CROS_GRALLOC_DRM_GET_FORMAT operation has failed. "
+        "Please ensure you are using the latest minigbm.");
     return -EINVAL;
+  }
+
+  uint32_t usage{};
+  if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_USAGE, handle, &usage) !=
+      0) {
+    ALOGE(
+        "CROS_GRALLOC_DRM_GET_USAGE operation has failed. "
+        "Please ensure you are using the latest minigbm.");
+    return -EINVAL;
+  }
+
+  struct cros_gralloc0_buffer_info info {};
+  if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_BUFFER_INFO, handle,
+                        &info) != 0) {
+    ALOGE(
+        "CROS_GRALLOC_DRM_GET_BUFFER_INFO operation has failed. "
+        "Please ensure you are using the latest minigbm.");
+    return -EINVAL;
+  }
 
-  bo->width = gr_handle->width;
-  bo->height = gr_handle->height;
-  bo->hal_format = gr_handle->droid_format;
+  bo->width = width;
+  bo->height = height;
 
-  bo->format = gr_handle->format;
-  if (bo->format == DRM_FORMAT_YVU420_ANDROID)
-    bo->format = DRM_FORMAT_YVU420;
+  bo->hal_format = droid_format;
 
-  bo->usage = gr_handle->usage;
+  bo->format = info.drm_fourcc;
+  bo->usage = usage;
 
-  for (int i = 0; i < gr_handle->num_planes; i++) {
-    bo->modifiers[i] = gr_handle->format_modifier;
-    bo->prime_fds[i] = gr_handle->fds[i];
-    bo->pitches[i] = gr_handle->strides[i];
-    bo->offsets[i] = gr_handle->offsets[i];
+  for (int i = 0; i < info.num_fds; i++) {
+    bo->modifiers[i] = info.modifier;
+    bo->prime_fds[i] = info.fds[i];
+    bo->pitches[i] = info.stride[i];
+    bo->offsets[i] = info.offset[i];
   }
 
   return 0;
@@ -67,6 +112,13 @@ int BufferInfoMinigbm::ValidateGralloc() {
     return -EINVAL;
   }
 
+  if (gralloc_->perform == nullptr) {
+    ALOGE(
+        "CrOS gralloc has no perform call implemented. Please upgrade your "
+        "minigbm.");
+    return -EINVAL;
+  }
+
   return 0;
 }
 
diff --git a/tests/test_include/cros_gralloc_handle.h b/tests/test_include/cros_gralloc_handle.h
deleted file mode 100644 (file)
index d77d777..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// clang-format off
-/*
- * Copyright 2016 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.
- */
-
-#ifndef CROS_GRALLOC_HANDLE_H
-#define CROS_GRALLOC_HANDLE_H
-
-#include <cstdint>
-#include <cutils/native_handle.h>
-
-#define DRV_MAX_PLANES 4
-#define DRV_MAX_FDS (DRV_MAX_PLANES + 1)
-
-struct cros_gralloc_handle : public native_handle_t {
-       /*
-        * File descriptors must immediately follow the native_handle_t base and used file
-        * descriptors must be packed at the beginning of this array to work with
-        * native_handle_clone().
-        *
-        * This field contains 'num_planes' plane file descriptors followed by an optional metadata
-        * reserved region file descriptor if 'reserved_region_size' is greater than zero.
-        */
-       int32_t fds[DRV_MAX_FDS];
-       uint32_t strides[DRV_MAX_PLANES];
-       uint32_t offsets[DRV_MAX_PLANES];
-       uint32_t sizes[DRV_MAX_PLANES];
-       uint32_t id;
-       uint32_t width;
-       uint32_t height;
-       uint32_t format; /* DRM format */
-       uint32_t tiling;
-       uint64_t format_modifier;
-       uint64_t use_flags; /* Buffer creation flags */
-       uint32_t magic;
-       uint32_t pixel_stride;
-       int32_t droid_format;
-       int32_t usage; /* Android usage. */
-       uint32_t num_planes;
-       uint64_t reserved_region_size;
-       uint64_t total_size; /* Total allocation size */
-       /*
-        * Name is a null terminated char array located at handle->base.data[handle->name_offset].
-        */
-       uint32_t name_offset;
-} __attribute__((packed));
-
-typedef const struct cros_gralloc_handle *cros_gralloc_handle_t;
-
-#endif
-// clang-format on