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/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";