drm_hwcomposer: Move include/drmhwcgralloc.h to bufferinfo/BufferInfo.h
... to emphasize its purpose.
- Rename struct HwcDrmBo -> struct BufferInfo
- Remove unused BufferInfo::acquire_fence, BufferInfo::hal_format and
BufferInfo::usage fields
Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/bufferinfo/BufferInfo.h b/bufferinfo/BufferInfo.h
new file mode 100644
index 0000000..ab714cf
--- /dev/null
+++ b/bufferinfo/BufferInfo.h
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+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];
+};
diff --git a/bufferinfo/BufferInfoGetter.cpp b/bufferinfo/BufferInfoGetter.cpp
index 0cfd7e5..57dc7f1 100644
--- a/bufferinfo/BufferInfoGetter.cpp
+++ b/bufferinfo/BufferInfoGetter.cpp
@@ -49,8 +49,7 @@
}
bool BufferInfoGetter::IsHandleUsable(buffer_handle_t handle) {
- hwc_drm_bo_t bo;
- memset(&bo, 0, sizeof(hwc_drm_bo_t));
+ BufferInfo bo{};
if (ConvertBoInfo(handle, &bo) != 0) {
return false;
diff --git a/bufferinfo/BufferInfoGetter.h b/bufferinfo/BufferInfoGetter.h
index 59184a4..d86a5b4 100644
--- a/bufferinfo/BufferInfoGetter.h
+++ b/bufferinfo/BufferInfoGetter.h
@@ -20,8 +20,8 @@
#include <drm/drm_fourcc.h>
#include <hardware/gralloc.h>
+#include "BufferInfo.h"
#include "drm/DrmDevice.h"
-#include "drmhwcgralloc.h"
#ifndef DRM_FORMAT_INVALID
#define DRM_FORMAT_INVALID 0
@@ -33,7 +33,7 @@
public:
virtual ~BufferInfoGetter() = default;
- virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0;
+ virtual int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) = 0;
bool IsHandleUsable(buffer_handle_t handle);
diff --git a/bufferinfo/BufferInfoMapperMetadata.cpp b/bufferinfo/BufferInfoMapperMetadata.cpp
index 2f08a76..70bd2da 100644
--- a/bufferinfo/BufferInfoMapperMetadata.cpp
+++ b/bufferinfo/BufferInfoMapperMetadata.cpp
@@ -46,7 +46,7 @@
* 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 @@
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) {
@@ -87,28 +87,12 @@
}
int BufferInfoMapperMetadata::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+ BufferInfo *bo) {
GraphicBufferMapper &mapper = GraphicBufferMapper::getInstance();
if (handle == nullptr)
return -EINVAL;
- 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);
-
- err = mapper.getPixelFormatFourCC(handle, &bo->format);
+ int err = mapper.getPixelFormatFourCC(handle, &bo->format);
if (err != 0) {
ALOGE("Failed to get FourCC format err=%d", err);
return err;
diff --git a/bufferinfo/BufferInfoMapperMetadata.h b/bufferinfo/BufferInfoMapperMetadata.h
index d335705..6ab29d3 100644
--- a/bufferinfo/BufferInfoMapperMetadata.h
+++ b/bufferinfo/BufferInfoMapperMetadata.h
@@ -25,9 +25,9 @@
public:
using BufferInfoGetter::BufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) 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..6823a74 100644
--- a/bufferinfo/legacy/BufferInfoImagination.cpp
+++ b/bufferinfo/legacy/BufferInfoImagination.cpp
@@ -30,7 +30,7 @@
LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination);
int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+ BufferInfo *bo) {
auto *hnd = (IMG_native_handle_t *)handle;
if (!hnd)
return -EINVAL;
@@ -43,10 +43,8 @@
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;
switch (hnd->iFormat) {
#ifdef HAL_PIXEL_FORMAT_BGRX_8888
diff --git a/bufferinfo/legacy/BufferInfoImagination.h b/bufferinfo/legacy/BufferInfoImagination.h
index 765b279..4066d11 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, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) override;
};
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp
index 6baf6bb..3bea3f2 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.cpp
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -91,8 +91,8 @@
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 @@
/* .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,13 @@
return true;
}
-int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) {
gralloc_handle_t *gr_handle = gralloc_handle(handle);
if (!gr_handle)
return -EINVAL;
bo->width = gr_handle->width;
bo->height = gr_handle->height;
- bo->hal_format = gr_handle->format;
#if GRALLOC_HANDLE_VERSION < 4
static std::once_flag once;
@@ -182,11 +181,10 @@
bo->modifiers[0] = gr_handle->modifier;
#endif
- bo->usage = gr_handle->usage;
bo->prime_fds[0] = gr_handle->prime_fd;
if (is_yuv(gr_handle->format)) {
- if (!GetYuvPlaneInfo(handle->numFds, handle, bo))
+ if (!GetYuvPlaneInfo(gr_handle->format, handle->numFds, handle, bo))
return -EINVAL;
} else {
bo->pitches[0] = gr_handle->stride;
@@ -195,7 +193,7 @@
/* 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;
break;
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.h b/bufferinfo/legacy/BufferInfoLibdrm.h
index cad8add..17ee5fb 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.h
+++ b/bufferinfo/legacy/BufferInfoLibdrm.h
@@ -26,11 +26,12 @@
class BufferInfoLibdrm : public LegacyBufferInfoGetter {
public:
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
- int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) 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..7a75075 100644
--- a/bufferinfo/legacy/BufferInfoMaliHisi.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
@@ -66,8 +66,7 @@
}
#endif
-int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) {
bool is_rgb = false;
const auto *hnd = (private_handle_t const *)handle;
@@ -87,9 +86,7 @@
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;
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.h b/bufferinfo/legacy/BufferInfoMaliHisi.h
index 698a0d3..e809d06 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, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) 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..569148b 100644
--- a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
@@ -33,7 +33,7 @@
LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMediatek);
int BufferInfoMaliMediatek::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+ BufferInfo *bo) {
const auto *hnd = (private_handle_t const *)handle;
if (!hnd)
return -EINVAL;
@@ -44,9 +44,7 @@
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;
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.h b/bufferinfo/legacy/BufferInfoMaliMediatek.h
index 1204818..5b48019 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, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) override;
};
} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.cpp b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
index 9daf542..08f7717 100644
--- a/bufferinfo/legacy/BufferInfoMaliMeson.cpp
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
@@ -61,8 +61,7 @@
}
#endif
-int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle,
- hwc_drm_bo_t *bo) {
+int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) {
const auto *hnd = (private_handle_t const *)handle;
if (!hnd)
return -EINVAL;
@@ -79,9 +78,7 @@
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;
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.h b/bufferinfo/legacy/BufferInfoMaliMeson.h
index ce5d3f9..3bd126d 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, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) override;
private:
uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags);
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.cpp b/bufferinfo/legacy/BufferInfoMinigbm.cpp
index 777c2b7..60795b1 100644
--- a/bufferinfo/legacy/BufferInfoMinigbm.cpp
+++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp
@@ -43,7 +43,7 @@
int stride[4];
};
-int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) {
if (handle == nullptr) {
return -EINVAL;
}
@@ -88,10 +88,7 @@
bo->width = width;
bo->height = height;
- bo->hal_format = droid_format;
-
bo->format = info.drm_fourcc;
- bo->usage = usage;
for (int i = 0; i < info.num_fds; i++) {
bo->modifiers[i] = info.modifier;
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.h b/bufferinfo/legacy/BufferInfoMinigbm.h
index 04cc2ae..16cbf2c 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, hwc_drm_bo_t *bo) override;
+ int ConvertBoInfo(buffer_handle_t handle, BufferInfo *bo) override;
int ValidateGralloc() override;
};