drm_hwcomposer: Set return type to std::optional for BufferInfoGetters
This is a bit of code modernization. Further changes will require indication
that buffer_info is valid, and using std::optional is the most correct
approach to do that.
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/bufferinfo/legacy/BufferInfoImagination.cpp b/bufferinfo/legacy/BufferInfoImagination.cpp
index 6823a74..1858ddb 100644
--- a/bufferinfo/legacy/BufferInfoImagination.cpp
+++ b/bufferinfo/legacy/BufferInfoImagination.cpp
@@ -29,22 +29,24 @@
LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination);
-int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle,
- BufferInfo *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->prime_fds[0] = hnd->fd[0];
- bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
+ 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
@@ -53,14 +55,14 @@
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 4066d11..635e3b5 100644
--- a/bufferinfo/legacy/BufferInfoImagination.h
+++ b/bufferinfo/legacy/BufferInfoImagination.h
@@ -27,7 +27,7 @@
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, BufferInfo *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 3bea3f2..ac71ec0 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.cpp
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -162,13 +162,16 @@
return true;
}
-int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, BufferInfo *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 {};
- bo->width = gr_handle->width;
- bo->height = gr_handle->height;
+ BufferInfo bi{};
+
+ bi.width = gr_handle->width;
+ bi.height = gr_handle->height;
#if GRALLOC_HANDLE_VERSION < 4
static std::once_flag once;
@@ -178,34 +181,34 @@
});
#endif
#if GRALLOC_HANDLE_VERSION == 4
- bo->modifiers[0] = gr_handle->modifier;
+ bi.modifiers[0] = gr_handle->modifier;
#endif
- bo->prime_fds[0] = gr_handle->prime_fd;
+ bi.prime_fds[0] = gr_handle->prime_fd;
if (is_yuv(gr_handle->format)) {
- if (!GetYuvPlaneInfo(gr_handle->format, 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 (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 17ee5fb..7f5b08c 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.h
+++ b/bufferinfo/legacy/BufferInfoLibdrm.h
@@ -26,7 +26,7 @@
class BufferInfoLibdrm : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
int ValidateGralloc() override;
private:
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.cpp b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
index 7a75075..1c7f4d0 100644
--- a/bufferinfo/legacy/BufferInfoMaliHisi.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
@@ -66,30 +66,33 @@
}
#endif
-int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle, BufferInfo *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);
+ bi.modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format,
+ is_rgb);
- bo->width = hnd->width;
- bo->height = hnd->height;
- bo->format = fmt;
- bo->pitches[0] = hnd->byte_stride;
- bo->prime_fds[0] = hnd->share_fd;
- bo->offsets[0] = 0;
+ 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: {
@@ -103,20 +106,20 @@
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 e809d06..cc37491 100644
--- a/bufferinfo/legacy/BufferInfoMaliHisi.h
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.h
@@ -27,7 +27,7 @@
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, BufferInfo *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 569148b..2e10460 100644
--- a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
@@ -32,24 +32,26 @@
LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMediatek);
-int BufferInfoMaliMediatek::ConvertBoInfo(buffer_handle_t handle,
- BufferInfo *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;
+ return {};
- bo->width = hnd->width;
- bo->height = hnd->height;
- bo->format = fmt;
- bo->prime_fds[0] = hnd->share_fd;
- bo->pitches[0] = hnd->byte_stride;
- bo->offsets[0] = 0;
+ BufferInfo bi{};
- return 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 bi;
}
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.h b/bufferinfo/legacy/BufferInfoMaliMediatek.h
index 5b48019..43d987a 100644
--- a/bufferinfo/legacy/BufferInfoMaliMediatek.h
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.h
@@ -27,7 +27,7 @@
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, BufferInfo *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 08f7717..cadc2bc 100644
--- a/bufferinfo/legacy/BufferInfoMaliMeson.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
@@ -61,29 +61,32 @@
}
#endif
-int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle, BufferInfo *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->format = fmt;
- 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 {};
}
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.h b/bufferinfo/legacy/BufferInfoMaliMeson.h
index 3bd126d..3b6fab0 100644
--- a/bufferinfo/legacy/BufferInfoMaliMeson.h
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.h
@@ -26,7 +26,7 @@
class BufferInfoMaliMeson : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, BufferInfo *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 60795b1..c5a9e98 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.cpp
+++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp
@@ -43,11 +43,14 @@
int stride[4];
};
-int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, BufferInfo *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 @@
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 @@
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 @@
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,22 +85,22 @@
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->format = info.drm_fourcc;
+ 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 16cbf2c..40d9926 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.h
+++ b/bufferinfo/legacy/BufferInfoMinigbm.h
@@ -26,7 +26,7 @@
class BufferInfoMinigbm : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) override;
+ auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
int ValidateGralloc() override;
};