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/BufferInfoGetter.cpp b/bufferinfo/BufferInfoGetter.cpp
index 57dc7f1..b42838d 100644
--- a/bufferinfo/BufferInfoGetter.cpp
+++ b/bufferinfo/BufferInfoGetter.cpp
@@ -49,15 +49,9 @@
 }
 
 bool BufferInfoGetter::IsHandleUsable(buffer_handle_t handle) {
-  BufferInfo bo{};
+  auto bo = GetBoInfo(handle);
 
-  if (ConvertBoInfo(handle, &bo) != 0) {
-    return false;
-  }
-  if (bo.prime_fds[0] == 0) {
-    return false;
-  }
-  return true;
+  return bo && bo->prime_fds[0] != 0;
 }
 
 int LegacyBufferInfoGetter::Init() {
diff --git a/bufferinfo/BufferInfoGetter.h b/bufferinfo/BufferInfoGetter.h
index d86a5b4..4d35faa 100644
--- a/bufferinfo/BufferInfoGetter.h
+++ b/bufferinfo/BufferInfoGetter.h
@@ -20,6 +20,8 @@
 #include <drm/drm_fourcc.h>
 #include <hardware/gralloc.h>
 
+#include <optional>
+
 #include "BufferInfo.h"
 #include "drm/DrmDevice.h"
 
@@ -33,7 +35,8 @@
  public:
   virtual ~BufferInfoGetter() = default;
 
-  virtual int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) = 0;
+  virtual auto GetBoInfo(buffer_handle_t handle)
+      -> std::optional<BufferInfo> = 0;
 
   bool IsHandleUsable(buffer_handle_t handle);
 
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
diff --git a/bufferinfo/BufferInfoMapperMetadata.h b/bufferinfo/BufferInfoMapperMetadata.h
index 6ab29d3..ab269dc 100644
--- a/bufferinfo/BufferInfoMapperMetadata.h
+++ b/bufferinfo/BufferInfoMapperMetadata.h
@@ -25,7 +25,7 @@
  public:
   using BufferInfoGetter::BufferInfoGetter;
 
-  int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) override;
+  auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
 
   int GetFds(buffer_handle_t handle, BufferInfo *bo);
 
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;
 };
 
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index 28f48f3..12ac44f 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -176,7 +176,7 @@
     return false;
   }
 
-  uint32_t format = layer->buffer_info.format;
+  uint32_t format = layer->buffer_info->format;
   if (!IsFormatSupported(format)) {
     ALOGV("Plane %d does not supports %c%c%c%c format", GetId(), format,
           format >> 8, format >> 16, format >> 24);
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index 2aec440..7279c02 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -598,13 +598,16 @@
 
   /* TODO: Do not update source_crop every call.
    * It makes sense to do it once after every hotplug event. */
-  BufferInfo bo{};
-  BufferInfoGetter::GetInstance()->ConvertBoInfo(target, &bo);
+  auto bi = BufferInfoGetter::GetInstance()->GetBoInfo(target);
+
+  if (!bi) {
+    return HWC2::Error::BadParameter;
+  }
 
   hwc_frect_t source_crop = {.left = 0.0F,
                              .top = 0.0F,
-                             .right = static_cast<float>(bo.width),
-                             .bottom = static_cast<float>(bo.height)};
+                             .right = static_cast<float>(bi->width),
+                             .bottom = static_cast<float>(bi->height)};
   client_layer_.SetLayerSourceCrop(source_crop);
 
   return HWC2::Error::None;
diff --git a/include/drmhwcomposer.h b/include/drmhwcomposer.h
index 211ffd2..5ddb220 100644
--- a/include/drmhwcomposer.h
+++ b/include/drmhwcomposer.h
@@ -22,6 +22,7 @@
 
 #include <cstdbool>
 #include <cstdint>
+#include <optional>
 #include <vector>
 
 #include "bufferinfo/BufferInfo.h"
@@ -62,7 +63,7 @@
 
 struct DrmHwcLayer {
   buffer_handle_t sf_handle = nullptr;
-  BufferInfo buffer_info{};
+  std::optional<BufferInfo> buffer_info;
   std::shared_ptr<DrmFbIdHandle> fb_id_handle;
 
   DrmHwcTransform transform{};
diff --git a/utils/hwcutils.cpp b/utils/hwcutils.cpp
index aec9bba..5aa9a3f 100644
--- a/utils/hwcutils.cpp
+++ b/utils/hwcutils.cpp
@@ -28,16 +28,15 @@
 namespace android {
 
 int DrmHwcLayer::ImportBuffer(DrmDevice *drm_device) {
-  buffer_info = BufferInfo{};
+  buffer_info = BufferInfoGetter::GetInstance()->GetBoInfo(sf_handle);
 
-  int ret = BufferInfoGetter::GetInstance()->ConvertBoInfo(sf_handle,
-                                                           &buffer_info);
-  if (ret != 0) {
-    ALOGE("Failed to convert buffer info %d", ret);
-    return ret;
+  if (!buffer_info) {
+    ALOGE("Failed to convert buffer info");
+    return -EINVAL;
   }
 
-  fb_id_handle = drm_device->GetDrmFbImporter().GetOrCreateFbId(&buffer_info);
+  fb_id_handle = drm_device->GetDrmFbImporter().GetOrCreateFbId(
+      &(*buffer_info));
   if (!fb_id_handle) {
     ALOGE("Failed to import buffer");
     return -EINVAL;