aboutsummaryrefslogtreecommitdiff
path: root/bufferinfo
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:08:05 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:08:05 +0000
commitdc8559eade3cae25703b70f6e93417ff368b2c14 (patch)
tree0be8b55408ec891b7c275a1eb9e4f0310702b339 /bufferinfo
parent1d29a2e82fad8d0f4d00e62cbac070995ae40a43 (diff)
parent39e9dc65f3a608c85124d4014b07ede70680f18b (diff)
downloaddrm_hwcomposer-android14-mainline-sdkext-release.tar.gz
Change-Id: If430f272132aef6c1f7508bff477d243782cc7d2
Diffstat (limited to 'bufferinfo')
-rw-r--r--bufferinfo/BufferInfo.h57
-rw-r--r--bufferinfo/BufferInfoGetter.cpp24
-rw-r--r--bufferinfo/BufferInfoGetter.h11
-rw-r--r--bufferinfo/BufferInfoMapperMetadata.cpp60
-rw-r--r--bufferinfo/BufferInfoMapperMetadata.h4
-rw-r--r--bufferinfo/legacy/BufferInfoImagination.cpp30
-rw-r--r--bufferinfo/legacy/BufferInfoImagination.h2
-rw-r--r--bufferinfo/legacy/BufferInfoLibdrm.cpp45
-rw-r--r--bufferinfo/legacy/BufferInfoLibdrm.h5
-rw-r--r--bufferinfo/legacy/BufferInfoMaliHisi.cpp46
-rw-r--r--bufferinfo/legacy/BufferInfoMaliHisi.h2
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMediatek.cpp30
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMediatek.h2
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMeson.cpp30
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMeson.h2
-rw-r--r--bufferinfo/legacy/BufferInfoMinigbm.cpp34
-rw-r--r--bufferinfo/legacy/BufferInfoMinigbm.h2
17 files changed, 224 insertions, 162 deletions
diff --git a/bufferinfo/BufferInfo.h b/bufferinfo/BufferInfo.h
new file mode 100644
index 0000000..b2297f9
--- /dev/null
+++ b/bufferinfo/BufferInfo.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+
+constexpr int kBufferMaxPlanes = 4;
+
+enum class BufferColorSpace : int32_t {
+ kUndefined,
+ kItuRec601,
+ kItuRec709,
+ kItuRec2020,
+};
+
+enum class BufferSampleRange : int32_t {
+ kUndefined,
+ kFullRange,
+ kLimitedRange,
+};
+
+enum class BufferBlendMode : int32_t {
+ kUndefined,
+ kNone,
+ kPreMult,
+ kCoverage,
+};
+
+struct BufferInfo {
+ uint32_t width;
+ uint32_t height;
+ uint32_t format; /* DRM_FORMAT_* from drm_fourcc.h */
+ uint32_t pitches[kBufferMaxPlanes];
+ uint32_t offsets[kBufferMaxPlanes];
+ /* sizes[] is used only by mapper@4 metadata getter for internal purposes */
+ uint32_t sizes[kBufferMaxPlanes];
+ int prime_fds[kBufferMaxPlanes];
+ uint64_t modifiers[kBufferMaxPlanes];
+
+ BufferColorSpace color_space;
+ BufferSampleRange sample_range;
+ BufferBlendMode blend_mode;
+};
diff --git a/bufferinfo/BufferInfoGetter.cpp b/bufferinfo/BufferInfoGetter.cpp
index 0cfd7e5..95c1a23 100644
--- a/bufferinfo/BufferInfoGetter.cpp
+++ b/bufferinfo/BufferInfoGetter.cpp
@@ -22,9 +22,14 @@
#include "BufferInfoMapperMetadata.h"
#endif
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
+#include <mutex>
+
#include "utils/log.h"
#include "utils/properties.h"
@@ -48,17 +53,18 @@ BufferInfoGetter *BufferInfoGetter::GetInstance() {
return inst.get();
}
-bool BufferInfoGetter::IsHandleUsable(buffer_handle_t handle) {
- hwc_drm_bo_t bo;
- memset(&bo, 0, sizeof(hwc_drm_bo_t));
-
- if (ConvertBoInfo(handle, &bo) != 0) {
- return false;
+std::optional<BufferUniqueId> BufferInfoGetter::GetUniqueId(
+ buffer_handle_t handle) {
+ struct stat sb {};
+ if (fstat(handle->data[0], &sb) != 0) {
+ return {};
}
- if (bo.prime_fds[0] == 0) {
- return false;
+
+ if (sb.st_size == 0) {
+ return {};
}
- return true;
+
+ return static_cast<BufferUniqueId>(sb.st_ino);
}
int LegacyBufferInfoGetter::Init() {
diff --git a/bufferinfo/BufferInfoGetter.h b/bufferinfo/BufferInfoGetter.h
index 59184a4..5591296 100644
--- a/bufferinfo/BufferInfoGetter.h
+++ b/bufferinfo/BufferInfoGetter.h
@@ -20,8 +20,10 @@
#include <drm/drm_fourcc.h>
#include <hardware/gralloc.h>
+#include <optional>
+
+#include "BufferInfo.h"
#include "drm/DrmDevice.h"
-#include "drmhwcgralloc.h"
#ifndef DRM_FORMAT_INVALID
#define DRM_FORMAT_INVALID 0
@@ -29,13 +31,16 @@
namespace android {
+using BufferUniqueId = uint64_t;
+
class BufferInfoGetter {
public:
virtual ~BufferInfoGetter() = default;
- virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0;
+ virtual auto GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> = 0;
- bool IsHandleUsable(buffer_handle_t handle);
+ virtual std::optional<BufferUniqueId> GetUniqueId(buffer_handle_t handle);
static BufferInfoGetter *GetInstance();
diff --git a/bufferinfo/BufferInfoMapperMetadata.cpp b/bufferinfo/BufferInfoMapperMetadata.cpp
index 2f08a76..bdacb74 100644
--- a/bufferinfo/BufferInfoMapperMetadata.cpp
+++ b/bufferinfo/BufferInfoMapperMetadata.cpp
@@ -46,7 +46,7 @@ BufferInfoGetter *BufferInfoMapperMetadata::CreateInstance() {
* so that it can be overridden.
*/
int __attribute__((weak))
-BufferInfoMapperMetadata::GetFds(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+BufferInfoMapperMetadata::GetFds(buffer_handle_t handle, BufferInfo *bo) {
int fd_index = 0;
if (handle->numFds <= 0) {
@@ -54,7 +54,7 @@ BufferInfoMapperMetadata::GetFds(buffer_handle_t handle, hwc_drm_bo_t *bo) {
return android::BAD_VALUE;
}
- for (int i = 0; i < kHwcDrmBoMaxPlanes; i++) {
+ for (int i = 0; i < kBufferMaxPlanes; i++) {
/* If no size, we're out of usable planes */
if (bo->sizes[i] <= 0) {
if (i == 0) {
@@ -86,71 +86,63 @@ BufferInfoMapperMetadata::GetFds(buffer_handle_t handle, hwc_drm_bo_t *bo) {
return 0;
}
-int BufferInfoMapperMetadata::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+auto BufferInfoMapperMetadata::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
GraphicBufferMapper &mapper = GraphicBufferMapper::getInstance();
if (handle == nullptr)
- return -EINVAL;
+ return {};
- uint64_t usage = 0;
- int err = mapper.getUsage(handle, &usage);
- if (err != 0) {
- ALOGE("Failed to get usage err=%d", err);
- return err;
- }
- bo->usage = static_cast<uint32_t>(usage);
-
- ui::PixelFormat hal_format;
- err = mapper.getPixelFormatRequested(handle, &hal_format);
- if (err != 0) {
- ALOGE("Failed to get HAL Pixel Format err=%d", err);
- return err;
- }
- bo->hal_format = static_cast<uint32_t>(hal_format);
+ BufferInfo bi{};
- err = mapper.getPixelFormatFourCC(handle, &bo->format);
+ int err = mapper.getPixelFormatFourCC(handle, &bi.format);
if (err != 0) {
ALOGE("Failed to get FourCC format err=%d", err);
- return err;
+ return {};
}
- err = mapper.getPixelFormatModifier(handle, &bo->modifiers[0]);
+ err = mapper.getPixelFormatModifier(handle, &bi.modifiers[0]);
if (err != 0) {
ALOGE("Failed to get DRM Modifier err=%d", err);
- return err;
+ return {};
}
uint64_t width = 0;
err = mapper.getWidth(handle, &width);
if (err != 0) {
ALOGE("Failed to get Width err=%d", err);
- return err;
+ return {};
}
- bo->width = static_cast<uint32_t>(width);
+ bi.width = static_cast<uint32_t>(width);
uint64_t height = 0;
err = mapper.getHeight(handle, &height);
if (err != 0) {
ALOGE("Failed to get Height err=%d", err);
- return err;
+ return {};
}
- bo->height = static_cast<uint32_t>(height);
+ bi.height = static_cast<uint32_t>(height);
std::vector<ui::PlaneLayout> layouts;
err = mapper.getPlaneLayouts(handle, &layouts);
if (err != 0) {
ALOGE("Failed to get Plane Layouts err=%d", err);
- return err;
+ return {};
}
for (uint32_t i = 0; i < layouts.size(); i++) {
- bo->modifiers[i] = bo->modifiers[0];
- bo->pitches[i] = layouts[i].strideInBytes;
- bo->offsets[i] = layouts[i].offsetInBytes;
- bo->sizes[i] = layouts[i].totalSizeInBytes;
+ bi.modifiers[i] = bi.modifiers[0];
+ bi.pitches[i] = layouts[i].strideInBytes;
+ bi.offsets[i] = layouts[i].offsetInBytes;
+ bi.sizes[i] = layouts[i].totalSizeInBytes;
+ }
+
+ err = GetFds(handle, &bi);
+ if (err != 0) {
+ ALOGE("Failed to get fds (err=%d)", err);
+ return {};
}
- return GetFds(handle, bo);
+ return bi;
}
} // namespace android
diff --git a/bufferinfo/BufferInfoMapperMetadata.h b/bufferinfo/BufferInfoMapperMetadata.h
index d335705..ab269dc 100644
--- a/bufferinfo/BufferInfoMapperMetadata.h
+++ b/bufferinfo/BufferInfoMapperMetadata.h
@@ -25,9 +25,9 @@ class BufferInfoMapperMetadata : public BufferInfoGetter {
public:
using BufferInfoGetter::BufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
- int GetFds(buffer_handle_t handle, hwc_drm_bo_t *bo);
+ int GetFds(buffer_handle_t handle, BufferInfo *bo);
static BufferInfoGetter *CreateInstance();
};
diff --git a/bufferinfo/legacy/BufferInfoImagination.cpp b/bufferinfo/legacy/BufferInfoImagination.cpp
index 691dd14..6d917c2 100644
--- a/bufferinfo/legacy/BufferInfoImagination.cpp
+++ b/bufferinfo/legacy/BufferInfoImagination.cpp
@@ -29,40 +29,40 @@ namespace android {
LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination);
-int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+auto BufferInfoImagination::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
auto *hnd = (IMG_native_handle_t *)handle;
if (!hnd)
- return -EINVAL;
+ return {};
/* Extra bits are responsible for buffer compression and memory layout */
if (hnd->iFormat & ~0x10f) {
ALOGV("Special buffer formats are not supported");
- return -EINVAL;
+ return {};
}
- bo->width = hnd->iWidth;
- bo->height = hnd->iHeight;
- bo->usage = hnd->usage;
- bo->prime_fds[0] = hnd->fd[0];
- bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
- bo->hal_format = hnd->iFormat;
+ BufferInfo bi{};
+
+ bi.width = hnd->iWidth;
+ bi.height = hnd->iHeight;
+ bi.prime_fds[0] = hnd->fd[0];
+ bi.pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
switch (hnd->iFormat) {
#ifdef HAL_PIXEL_FORMAT_BGRX_8888
case HAL_PIXEL_FORMAT_BGRX_8888:
- bo->format = DRM_FORMAT_XRGB8888;
+ bi.format = DRM_FORMAT_XRGB8888;
break;
#endif
default:
- bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
- if (bo->format == DRM_FORMAT_INVALID) {
+ bi.format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
+ if (bi.format == DRM_FORMAT_INVALID) {
ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
- return -EINVAL;
+ return {};
}
}
- return 0;
+ return bi;
}
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoImagination.h b/bufferinfo/legacy/BufferInfoImagination.h
index 765b279..635e3b5 100644
--- a/bufferinfo/legacy/BufferInfoImagination.h
+++ b/bufferinfo/legacy/BufferInfoImagination.h
@@ -27,7 +27,7 @@ class BufferInfoImagination : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
};
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp
index 6baf6bb..ac71ec0 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.cpp
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -91,8 +91,8 @@ static bool is_yuv(uint32_t native) {
return false;
}
-bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+bool BufferInfoLibdrm::GetYuvPlaneInfo(uint32_t hal_format, int num_fds,
+ buffer_handle_t handle, BufferInfo *bo) {
struct android_ycbcr ycbcr {};
enum chroma_order chroma_order {};
int ret = 0;
@@ -136,12 +136,12 @@ bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle,
/* .chroma_step is the byte distance between the same chroma channel
* values of subsequent pixels, assumed to be the same for Cb and Cr. */
- bo->format = get_fourcc_yuv(bo->hal_format, chroma_order, ycbcr.chroma_step);
+ bo->format = get_fourcc_yuv(hal_format, chroma_order, ycbcr.chroma_step);
if (bo->format == UINT32_MAX) {
ALOGW(
"unsupported YUV format, native = %x, chroma_order = %s, chroma_step = "
"%d",
- bo->hal_format, chroma_order == kYCbCr ? "YCbCr" : "YCrCb",
+ hal_format, chroma_order == kYCbCr ? "YCbCr" : "YCrCb",
(int)ycbcr.chroma_step);
return false;
}
@@ -162,14 +162,16 @@ bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle,
return true;
}
-int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+auto BufferInfoLibdrm::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
gralloc_handle_t *gr_handle = gralloc_handle(handle);
if (!gr_handle)
- return -EINVAL;
+ return {};
+
+ BufferInfo bi{};
- bo->width = gr_handle->width;
- bo->height = gr_handle->height;
- bo->hal_format = gr_handle->format;
+ bi.width = gr_handle->width;
+ bi.height = gr_handle->height;
#if GRALLOC_HANDLE_VERSION < 4
static std::once_flag once;
@@ -179,35 +181,34 @@ int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
});
#endif
#if GRALLOC_HANDLE_VERSION == 4
- bo->modifiers[0] = gr_handle->modifier;
+ bi.modifiers[0] = gr_handle->modifier;
#endif
- bo->usage = gr_handle->usage;
- bo->prime_fds[0] = gr_handle->prime_fd;
+ bi.prime_fds[0] = gr_handle->prime_fd;
if (is_yuv(gr_handle->format)) {
- if (!GetYuvPlaneInfo(handle->numFds, handle, bo))
- return -EINVAL;
+ if (!GetYuvPlaneInfo(gr_handle->format, handle->numFds, handle, &bi))
+ return {};
} else {
- bo->pitches[0] = gr_handle->stride;
- bo->offsets[0] = 0;
+ bi.pitches[0] = gr_handle->stride;
+ bi.offsets[0] = 0;
/* FOSS graphic components (gbm_gralloc, mesa3d) are translating
* HAL_PIXEL_FORMAT_RGB_565 to DRM_FORMAT_RGB565 without swapping
* the R and B components. Same must be done here. */
- switch (bo->hal_format) {
+ switch (gr_handle->format) {
case HAL_PIXEL_FORMAT_RGB_565:
- bo->format = DRM_FORMAT_RGB565;
+ bi.format = DRM_FORMAT_RGB565;
break;
default:
- bo->format = ConvertHalFormatToDrm(gr_handle->format);
+ bi.format = ConvertHalFormatToDrm(gr_handle->format);
}
- if (bo->format == DRM_FORMAT_INVALID)
- return -EINVAL;
+ if (bi.format == DRM_FORMAT_INVALID)
+ return {};
}
- return 0;
+ return bi;
}
constexpr char gbm_gralloc_module_name[] = "GBM Memory Allocator";
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.h b/bufferinfo/legacy/BufferInfoLibdrm.h
index cad8add..7f5b08c 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.h
+++ b/bufferinfo/legacy/BufferInfoLibdrm.h
@@ -26,11 +26,12 @@ namespace android {
class BufferInfoLibdrm : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
int ValidateGralloc() override;
private:
- bool GetYuvPlaneInfo(int num_fds, buffer_handle_t handle, hwc_drm_bo_t *bo);
+ bool GetYuvPlaneInfo(uint32_t hal_format, int num_fds, buffer_handle_t handle,
+ BufferInfo *bo);
};
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.cpp b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
index 5fc413a..1c7f4d0 100644
--- a/bufferinfo/legacy/BufferInfoMaliHisi.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
@@ -66,33 +66,33 @@ uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers(
}
#endif
-int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+auto BufferInfoMaliHisi::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
bool is_rgb = false;
const auto *hnd = (private_handle_t const *)handle;
if (!hnd)
- return -EINVAL;
+ return {};
if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
- return -EINVAL;
+ return {};
uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
if (fmt == DRM_FORMAT_INVALID)
- return -EINVAL;
+ return {};
+
+ BufferInfo bi{};
is_rgb = IsDrmFormatRgb(fmt);
- bo->modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format,
- is_rgb);
-
- bo->width = hnd->width;
- bo->height = hnd->height;
- bo->hal_format = hnd->req_format;
- bo->format = fmt;
- bo->usage = hnd->usage;
- bo->pitches[0] = hnd->byte_stride;
- bo->prime_fds[0] = hnd->share_fd;
- bo->offsets[0] = 0;
+ bi.modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format,
+ is_rgb);
+
+ bi.width = hnd->width;
+ bi.height = hnd->height;
+ bi.format = fmt;
+ bi.pitches[0] = hnd->byte_stride;
+ bi.prime_fds[0] = hnd->share_fd;
+ bi.offsets[0] = 0;
switch (fmt) {
case DRM_FORMAT_YVU420: {
@@ -106,20 +106,20 @@ int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle,
int v_size = vu_stride * (adjusted_height / 2);
/* V plane*/
- bo->prime_fds[1] = hnd->share_fd;
- bo->pitches[1] = vu_stride;
- bo->offsets[1] = y_size;
+ bi.prime_fds[1] = hnd->share_fd;
+ bi.pitches[1] = vu_stride;
+ bi.offsets[1] = y_size;
/* U plane */
- bo->prime_fds[2] = hnd->share_fd;
- bo->pitches[2] = vu_stride;
- bo->offsets[2] = y_size + v_size;
+ bi.prime_fds[2] = hnd->share_fd;
+ bi.pitches[2] = vu_stride;
+ bi.offsets[2] = y_size + v_size;
break;
}
default:
break;
}
- return 0;
+ return bi;
}
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.h b/bufferinfo/legacy/BufferInfoMaliHisi.h
index 698a0d3..cc37491 100644
--- a/bufferinfo/legacy/BufferInfoMaliHisi.h
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.h
@@ -27,7 +27,7 @@ class BufferInfoMaliHisi : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
private:
uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb);
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
index 7e6f3a8..2e10460 100644
--- a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
@@ -32,26 +32,26 @@ namespace android {
LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMediatek);
-int BufferInfoMaliMediatek::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+auto BufferInfoMaliMediatek::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
const auto *hnd = (private_handle_t const *)handle;
if (!hnd)
- return -EINVAL;
+ return {};
uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
if (fmt == DRM_FORMAT_INVALID)
- return -EINVAL;
-
- bo->width = hnd->width;
- bo->height = hnd->height;
- bo->hal_format = hnd->req_format;
- bo->format = fmt;
- bo->usage = hnd->consumer_usage | hnd->producer_usage;
- bo->prime_fds[0] = hnd->share_fd;
- bo->pitches[0] = hnd->byte_stride;
- bo->offsets[0] = 0;
-
- return 0;
+ return {};
+
+ BufferInfo bi{};
+
+ bi.width = hnd->width;
+ bi.height = hnd->height;
+ bi.format = fmt;
+ bi.prime_fds[0] = hnd->share_fd;
+ bi.pitches[0] = hnd->byte_stride;
+ bi.offsets[0] = 0;
+
+ return bi;
}
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.h b/bufferinfo/legacy/BufferInfoMaliMediatek.h
index 1204818..43d987a 100644
--- a/bufferinfo/legacy/BufferInfoMaliMediatek.h
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.h
@@ -27,7 +27,7 @@ class BufferInfoMaliMediatek : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
};
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.cpp b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
index 9daf542..8160296 100644
--- a/bufferinfo/legacy/BufferInfoMaliMeson.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
@@ -61,32 +61,32 @@ uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
}
#endif
-int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+auto BufferInfoMaliMeson::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
const auto *hnd = (private_handle_t const *)handle;
if (!hnd)
- return -EINVAL;
+ return {};
if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
- return -EINVAL;
+ return {};
uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
if (fmt == DRM_FORMAT_INVALID)
- return -EINVAL;
+ return {};
- bo->modifiers[0] = BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
+ BufferInfo bi{};
+
+ bi.modifiers[0] = BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
hnd->internal_format);
- bo->width = hnd->width;
- bo->height = hnd->height;
- bo->hal_format = hnd->req_format;
- bo->format = fmt;
- bo->usage = hnd->usage;
- bo->prime_fds[0] = hnd->share_fd;
- bo->pitches[0] = hnd->byte_stride;
- bo->offsets[0] = 0;
+ bi.width = hnd->width;
+ bi.height = hnd->height;
+ bi.format = fmt;
+ bi.prime_fds[0] = hnd->share_fd;
+ bi.pitches[0] = hnd->byte_stride;
+ bi.offsets[0] = 0;
- return 0;
+ return bi;
}
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.h b/bufferinfo/legacy/BufferInfoMaliMeson.h
index ce5d3f9..3b6fab0 100644
--- a/bufferinfo/legacy/BufferInfoMaliMeson.h
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.h
@@ -26,7 +26,7 @@ namespace android {
class BufferInfoMaliMeson : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
private:
uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags);
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.cpp b/bufferinfo/legacy/BufferInfoMinigbm.cpp
index 777c2b7..c5a9e98 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.cpp
+++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp
@@ -43,11 +43,14 @@ struct cros_gralloc0_buffer_info {
int stride[4];
};
-int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+auto BufferInfoMinigbm::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
if (handle == nullptr) {
- return -EINVAL;
+ return {};
}
+ BufferInfo bi{};
+
uint32_t width{};
uint32_t height{};
if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_DIMENSIONS, handle,
@@ -55,7 +58,7 @@ int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
ALOGE(
"CROS_GRALLOC_DRM_GET_DIMENSIONS operation has failed. "
"Please ensure you are using the latest minigbm.");
- return -EINVAL;
+ return {};
}
int32_t droid_format{};
@@ -64,7 +67,7 @@ int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
ALOGE(
"CROS_GRALLOC_DRM_GET_FORMAT operation has failed. "
"Please ensure you are using the latest minigbm.");
- return -EINVAL;
+ return {};
}
uint32_t usage{};
@@ -73,7 +76,7 @@ int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
ALOGE(
"CROS_GRALLOC_DRM_GET_USAGE operation has failed. "
"Please ensure you are using the latest minigbm.");
- return -EINVAL;
+ return {};
}
struct cros_gralloc0_buffer_info info {};
@@ -82,25 +85,22 @@ int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
ALOGE(
"CROS_GRALLOC_DRM_GET_BUFFER_INFO operation has failed. "
"Please ensure you are using the latest minigbm.");
- return -EINVAL;
+ return {};
}
- bo->width = width;
- bo->height = height;
+ bi.width = width;
+ bi.height = height;
- bo->hal_format = droid_format;
-
- bo->format = info.drm_fourcc;
- bo->usage = usage;
+ bi.format = info.drm_fourcc;
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];
+ bi.modifiers[i] = info.modifier;
+ bi.prime_fds[i] = info.fds[i];
+ bi.pitches[i] = info.stride[i];
+ bi.offsets[i] = info.offset[i];
}
- return 0;
+ return bi;
}
constexpr char cros_gralloc_module_name[] = "CrOS Gralloc";
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.h b/bufferinfo/legacy/BufferInfoMinigbm.h
index 04cc2ae..40d9926 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.h
+++ b/bufferinfo/legacy/BufferInfoMinigbm.h
@@ -26,7 +26,7 @@ namespace android {
class BufferInfoMinigbm : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
int ValidateGralloc() override;
};