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/BufferInfoMapperMetadata.cpp b/bufferinfo/BufferInfoMapperMetadata.cpp
index 70bd2da..bdacb74 100644
--- a/bufferinfo/BufferInfoMapperMetadata.cpp
+++ b/bufferinfo/BufferInfoMapperMetadata.cpp
@@ -86,55 +86,63 @@
return 0;
}
-int BufferInfoMapperMetadata::ConvertBoInfo(buffer_handle_t handle,
- BufferInfo *bo) {
+auto BufferInfoMapperMetadata::GetBoInfo(buffer_handle_t handle)
+ -> std::optional<BufferInfo> {
GraphicBufferMapper &mapper = GraphicBufferMapper::getInstance();
if (handle == nullptr)
- return -EINVAL;
+ return {};
- int err = mapper.getPixelFormatFourCC(handle, &bo->format);
+ BufferInfo bi{};
+
+ 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;
}
- return GetFds(handle, bo);
+ err = GetFds(handle, &bi);
+ if (err != 0) {
+ ALOGE("Failed to get fds (err=%d)", err);
+ return {};
+ }
+
+ return bi;
}
} // namespace android