aboutsummaryrefslogtreecommitdiff
path: root/bufferinfo
diff options
context:
space:
mode:
Diffstat (limited to 'bufferinfo')
-rw-r--r--bufferinfo/BufferInfoGetter.cpp136
-rw-r--r--bufferinfo/BufferInfoGetter.h77
-rw-r--r--bufferinfo/BufferInfoMapperMetadata.cpp49
-rw-r--r--bufferinfo/BufferInfoMapperMetadata.h34
-rw-r--r--bufferinfo/legacy/BufferInfoImagination.cpp67
-rw-r--r--bufferinfo/legacy/BufferInfoImagination.h34
-rw-r--r--bufferinfo/legacy/BufferInfoLibdrm.cpp198
-rw-r--r--bufferinfo/legacy/BufferInfoLibdrm.h37
-rw-r--r--bufferinfo/legacy/BufferInfoMaliHisi.cpp129
-rw-r--r--bufferinfo/legacy/BufferInfoMaliHisi.h37
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMediatek.cpp59
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMediatek.h34
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMeson.cpp96
-rw-r--r--bufferinfo/legacy/BufferInfoMaliMeson.h36
-rw-r--r--bufferinfo/legacy/BufferInfoMinigbm.cpp49
-rw-r--r--bufferinfo/legacy/BufferInfoMinigbm.h34
16 files changed, 1106 insertions, 0 deletions
diff --git a/bufferinfo/BufferInfoGetter.cpp b/bufferinfo/BufferInfoGetter.cpp
new file mode 100644
index 0000000..8b3f1a4
--- /dev/null
+++ b/bufferinfo/BufferInfoGetter.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#define LOG_TAG "hwc-buffer-info-getter"
+
+#include "BufferInfoGetter.h"
+
+#if PLATFORM_SDK_VERSION >= 30
+#include "BufferInfoMapperMetadata.h"
+#endif
+
+#include <cutils/properties.h>
+#include <gralloc_handle.h>
+#include <hardware/gralloc.h>
+#include <log/log.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+namespace android {
+
+BufferInfoGetter *BufferInfoGetter::GetInstance() {
+ static std::unique_ptr<BufferInfoGetter> inst;
+ if (inst == nullptr) {
+#if PLATFORM_SDK_VERSION >= 30
+ inst.reset(BufferInfoMapperMetadata::CreateInstance());
+ if (inst == nullptr) {
+ ALOGW(
+ "Generic buffer getter is not available. Falling back to legacy...");
+#endif
+ inst.reset(LegacyBufferInfoGetter::CreateInstance());
+#if PLATFORM_SDK_VERSION >= 30
+ }
+#endif
+ }
+
+ return inst.get();
+}
+
+bool BufferInfoGetter::IsHandleUsable(buffer_handle_t handle) {
+ hwc_drm_bo_t bo;
+ memset(&bo, 0, sizeof(hwc_drm_bo_t));
+
+ if (ConvertBoInfo(handle, &bo) != 0)
+ return false;
+
+ if (bo.prime_fds[0] == 0)
+ return false;
+
+ return true;
+}
+
+int LegacyBufferInfoGetter::Init() {
+ int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
+ (const hw_module_t **)&gralloc_);
+ if (ret) {
+ ALOGE("Failed to open gralloc module");
+ return ret;
+ }
+
+ ALOGI("Using %s gralloc module: %s\n", gralloc_->common.name,
+ gralloc_->common.author);
+
+ return 0;
+}
+
+uint32_t LegacyBufferInfoGetter::ConvertHalFormatToDrm(uint32_t hal_format) {
+ switch (hal_format) {
+ case HAL_PIXEL_FORMAT_RGB_888:
+ return DRM_FORMAT_BGR888;
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ return DRM_FORMAT_ARGB8888;
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ return DRM_FORMAT_XBGR8888;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ return DRM_FORMAT_ABGR8888;
+ case HAL_PIXEL_FORMAT_RGB_565:
+ return DRM_FORMAT_BGR565;
+ case HAL_PIXEL_FORMAT_YV12:
+ return DRM_FORMAT_YVU420;
+ default:
+ ALOGE("Cannot convert hal format to drm format %u", hal_format);
+ return DRM_FORMAT_INVALID;
+ }
+}
+
+uint32_t BufferInfoGetter::DrmFormatToBitsPerPixel(uint32_t drm_format) {
+ switch (drm_format) {
+ case DRM_FORMAT_ARGB8888:
+ case DRM_FORMAT_XBGR8888:
+ case DRM_FORMAT_ABGR8888:
+ return 32;
+ case DRM_FORMAT_BGR888:
+ return 24;
+ case DRM_FORMAT_BGR565:
+ return 16;
+ case DRM_FORMAT_YVU420:
+ return 12;
+ default:
+ ALOGE("Cannot convert hal format %u to bpp (returning 32)", drm_format);
+ return 32;
+ }
+}
+
+bool BufferInfoGetter::IsDrmFormatRgb(uint32_t drm_format) {
+ switch (drm_format) {
+ case DRM_FORMAT_ARGB8888:
+ case DRM_FORMAT_XBGR8888:
+ case DRM_FORMAT_ABGR8888:
+ case DRM_FORMAT_BGR888:
+ case DRM_FORMAT_BGR565:
+ return true;
+ default:
+ return false;
+ }
+}
+
+__attribute__((weak)) LegacyBufferInfoGetter *
+LegacyBufferInfoGetter::CreateInstance() {
+ ALOGE("No legacy buffer info getters available");
+ return nullptr;
+}
+
+} // namespace android
diff --git a/bufferinfo/BufferInfoGetter.h b/bufferinfo/BufferInfoGetter.h
new file mode 100644
index 0000000..78c29ff
--- /dev/null
+++ b/bufferinfo/BufferInfoGetter.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#ifndef ANDROID_BUFFERINFOGETTER_H_
+#define ANDROID_BUFFERINFOGETTER_H_
+
+#include <drm/drm_fourcc.h>
+#include <hardware/gralloc.h>
+
+#include "drm/DrmDevice.h"
+#include "drmhwcgralloc.h"
+
+#ifndef DRM_FORMAT_INVALID
+#define DRM_FORMAT_INVALID 0
+#endif
+
+namespace android {
+
+class BufferInfoGetter {
+ public:
+ virtual ~BufferInfoGetter() {
+ }
+
+ virtual int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) = 0;
+
+ bool IsHandleUsable(buffer_handle_t handle);
+
+ static BufferInfoGetter *GetInstance();
+
+ static uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
+ static bool IsDrmFormatRgb(uint32_t drm_format);
+};
+
+class LegacyBufferInfoGetter : public BufferInfoGetter {
+ public:
+ using BufferInfoGetter::BufferInfoGetter;
+
+ int Init();
+
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override = 0;
+
+ static LegacyBufferInfoGetter *CreateInstance();
+
+ static uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
+ const gralloc_module_t *gralloc_;
+};
+
+#define LEGACY_BUFFER_INFO_GETTER(getter_) \
+ LegacyBufferInfoGetter *LegacyBufferInfoGetter::CreateInstance() { \
+ auto *instance = new getter_(); \
+ if (!instance) \
+ return NULL; \
+ \
+ int ret = instance->Init(); \
+ if (ret) { \
+ ALOGE("Failed to initialize the " #getter_ " getter %d", ret); \
+ delete instance; \
+ return NULL; \
+ } \
+ return instance; \
+ }
+
+} // namespace android
+#endif
diff --git a/bufferinfo/BufferInfoMapperMetadata.cpp b/bufferinfo/BufferInfoMapperMetadata.cpp
new file mode 100644
index 0000000..2725802
--- /dev/null
+++ b/bufferinfo/BufferInfoMapperMetadata.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#if PLATFORM_SDK_VERSION >= 30
+
+#define LOG_TAG "hwc-bufferinfo-mappermetadata"
+
+#include "BufferInfoMapperMetadata.h"
+
+#include <drm/drm_fourcc.h>
+#include <inttypes.h>
+#include <log/log.h>
+#include <ui/GraphicBufferMapper.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+using android::hardware::graphics::common::V1_1::BufferUsage;
+
+namespace android {
+
+BufferInfoGetter *BufferInfoMapperMetadata::CreateInstance() {
+ if (GraphicBufferMapper::getInstance().getMapperVersion() <
+ GraphicBufferMapper::GRALLOC_4)
+ return nullptr;
+
+ return new BufferInfoMapperMetadata();
+}
+
+int BufferInfoMapperMetadata::ConvertBoInfo(buffer_handle_t /*handle*/,
+ hwc_drm_bo_t * /*bo*/) {
+ return -EINVAL;
+}
+
+} // namespace android
+
+#endif
diff --git a/bufferinfo/BufferInfoMapperMetadata.h b/bufferinfo/BufferInfoMapperMetadata.h
new file mode 100644
index 0000000..49c788a
--- /dev/null
+++ b/bufferinfo/BufferInfoMapperMetadata.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#ifndef PLATFORMIMAGINATION_H
+#define PLATFORMIMAGINATION_H
+
+#include "bufferinfo/BufferInfoGetter.h"
+
+namespace android {
+
+class BufferInfoMapperMetadata : public BufferInfoGetter {
+ public:
+ using BufferInfoGetter::BufferInfoGetter;
+
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+
+ static BufferInfoGetter *CreateInstance();
+};
+} // namespace android
+
+#endif // PLATFORMIMAGINATION_H
diff --git a/bufferinfo/legacy/BufferInfoImagination.cpp b/bufferinfo/legacy/BufferInfoImagination.cpp
new file mode 100644
index 0000000..3d04a4b
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoImagination.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#define LOG_TAG "hwc-bufferinfo-imagination"
+
+#include "BufferInfoImagination.h"
+
+#include <log/log.h>
+#include <xf86drm.h>
+
+#include "img_gralloc1_public.h"
+
+namespace android {
+
+LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination);
+
+int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
+ IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle;
+ if (!hnd)
+ return -EINVAL;
+
+ /* Extra bits are responsible for buffer compression and memory layout */
+ if (hnd->iFormat & ~0x10f) {
+ ALOGV("Special buffer formats are not supported");
+ return -EINVAL;
+ }
+
+ 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;
+ bo->pixel_stride = hnd->aiStride[0];
+
+ switch (hnd->iFormat) {
+#ifdef HAL_PIXEL_FORMAT_BGRX_8888
+ case HAL_PIXEL_FORMAT_BGRX_8888:
+ bo->format = DRM_FORMAT_XRGB8888;
+ break;
+#endif
+ default:
+ bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
+ if (bo->format == DRM_FORMAT_INVALID) {
+ ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoImagination.h b/bufferinfo/legacy/BufferInfoImagination.h
new file mode 100644
index 0000000..765b279
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoImagination.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#ifndef BUFFERINFOIMAGINATION_H
+#define BUFFERINFOIMAGINATION_H
+
+#include <hardware/gralloc.h>
+
+#include "bufferinfo/BufferInfoGetter.h"
+
+namespace android {
+
+class BufferInfoImagination : public LegacyBufferInfoGetter {
+ public:
+ using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
+
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+};
+} // namespace android
+
+#endif // PLATFORMIMAGINATION_H
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp
new file mode 100644
index 0000000..872ee19
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#define LOG_TAG "hwc-bufferinfo-libdrm"
+
+#include "BufferInfoLibdrm.h"
+
+#include <cutils/properties.h>
+#include <gralloc_handle.h>
+#include <hardware/gralloc.h>
+#include <log/log.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+namespace android {
+
+LEGACY_BUFFER_INFO_GETTER(BufferInfoLibdrm);
+
+enum chroma_order {
+ YCbCr,
+ YCrCb,
+};
+
+struct droid_yuv_format {
+ /* Lookup keys */
+ int native; /* HAL_PIXEL_FORMAT_ */
+ enum chroma_order chroma_order; /* chroma order is {Cb, Cr} or {Cr, Cb} */
+ int chroma_step; /* Distance in bytes between subsequent chroma pixels. */
+
+ /* Result */
+ int fourcc; /* DRM_FORMAT_ */
+};
+
+/* The following table is used to look up a DRI image FourCC based
+ * on native format and information contained in android_ycbcr struct. */
+static const struct droid_yuv_format droid_yuv_formats[] = {
+ /* Native format, YCrCb, Chroma step, DRI image FourCC */
+ {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12},
+ {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420},
+ {HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420},
+ {HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420},
+ /* HACK: See droid_create_image_from_prime_fds() and
+ * https://issuetracker.google.com/32077885. */
+ {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12},
+ {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420},
+ {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420},
+ {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV},
+ {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888},
+};
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+static int get_fourcc_yuv(int native, enum chroma_order chroma_order,
+ int chroma_step) {
+ for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i)
+ if (droid_yuv_formats[i].native == native &&
+ droid_yuv_formats[i].chroma_order == chroma_order &&
+ droid_yuv_formats[i].chroma_step == chroma_step)
+ return droid_yuv_formats[i].fourcc;
+
+ return -1;
+}
+
+static bool is_yuv(int native) {
+ for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i)
+ if (droid_yuv_formats[i].native == native)
+ return true;
+
+ return false;
+}
+
+bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
+ struct android_ycbcr ycbcr;
+ enum chroma_order chroma_order;
+ int ret;
+
+ if (!gralloc_->lock_ycbcr) {
+ static std::once_flag once;
+ std::call_once(once,
+ []() { ALOGW("Gralloc does not support lock_ycbcr()"); });
+ return false;
+ }
+
+ memset(&ycbcr, 0, sizeof(ycbcr));
+ ret = gralloc_->lock_ycbcr(gralloc_, handle, 0, 0, 0, 0, 0, &ycbcr);
+ if (ret) {
+ ALOGW("gralloc->lock_ycbcr failed: %d", ret);
+ return false;
+ }
+ gralloc_->unlock(gralloc_, handle);
+
+ /* When lock_ycbcr's usage argument contains no SW_READ/WRITE flags
+ * it will return the .y/.cb/.cr pointers based on a NULL pointer,
+ * so they can be interpreted as offsets. */
+ bo->offsets[0] = (size_t)ycbcr.y;
+ /* We assume here that all the planes are located in one DMA-buf. */
+ if ((size_t)ycbcr.cr < (size_t)ycbcr.cb) {
+ chroma_order = YCrCb;
+ bo->offsets[1] = (size_t)ycbcr.cr;
+ bo->offsets[2] = (size_t)ycbcr.cb;
+ } else {
+ chroma_order = YCbCr;
+ bo->offsets[1] = (size_t)ycbcr.cb;
+ bo->offsets[2] = (size_t)ycbcr.cr;
+ }
+
+ /* .ystride is the line length (in bytes) of the Y plane,
+ * .cstride is the line length (in bytes) of any of the remaining
+ * Cb/Cr/CbCr planes, assumed to be the same for Cb and Cr for fully
+ * planar formats. */
+ bo->pitches[0] = ycbcr.ystride;
+ bo->pitches[1] = bo->pitches[2] = ycbcr.cstride;
+
+ /* .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);
+ if (bo->format == -1) {
+ ALOGW(
+ "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = "
+ "%d",
+ bo->hal_format, chroma_order == YCbCr ? "YCbCr" : "YCrCb",
+ (int)ycbcr.chroma_step);
+ return false;
+ }
+
+ /*
+ * Since this is EGL_NATIVE_BUFFER_ANDROID don't assume that
+ * the single-fd case cannot happen. So handle eithe single
+ * fd or fd-per-plane case:
+ */
+ if (num_fds == 1) {
+ bo->prime_fds[2] = bo->prime_fds[1] = bo->prime_fds[0];
+ } else {
+ int expected_planes = (ycbcr.chroma_step == 2) ? 2 : 3;
+ if (num_fds != expected_planes)
+ return false;
+ }
+
+ return true;
+}
+
+int BufferInfoLibdrm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *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;
+ std::call_once(once, []() {
+ ALOGE(
+ "libdrm < v2.4.97 has broken gralloc_handle structure. Please update.");
+ });
+#endif
+#if GRALLOC_HANDLE_VERSION == 4
+ bo->modifiers[0] = gr_handle->modifier;
+ bo->with_modifiers = gr_handle->modifier != DRM_FORMAT_MOD_NONE &&
+ gr_handle->modifier != DRM_FORMAT_MOD_INVALID;
+#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))
+ return -EINVAL;
+ } else {
+ bo->pitches[0] = gr_handle->stride;
+ bo->offsets[0] = 0;
+ bo->format = ConvertHalFormatToDrm(gr_handle->format);
+ if (bo->format == DRM_FORMAT_INVALID)
+ return -EINVAL;
+ }
+
+ bo->pixel_stride = (gr_handle->stride * 8) /
+ DrmFormatToBitsPerPixel(bo->format);
+
+ return 0;
+}
+
+} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.h b/bufferinfo/legacy/BufferInfoLibdrm.h
new file mode 100644
index 0000000..4d37d00
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoLibdrm.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#ifndef BUFFERINFOLIBDRM_H_
+#define BUFFERINFOLIBDRM_H_
+
+#include <hardware/gralloc.h>
+
+#include "bufferinfo/BufferInfoGetter.h"
+
+namespace android {
+
+class BufferInfoLibdrm : public LegacyBufferInfoGetter {
+ public:
+ using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+
+ private:
+ bool GetYuvPlaneInfo(int num_fds, buffer_handle_t handle, hwc_drm_bo_t *bo);
+};
+
+} // namespace android
+
+#endif
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.cpp b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
new file mode 100644
index 0000000..98b2786
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#define LOG_TAG "hwc-bufferinfo-mali-hisi"
+
+#include "BufferInfoMaliHisi.h"
+
+#include <log/log.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include <cinttypes>
+
+#include "gralloc_priv.h"
+
+#define MALI_ALIGN(value, base) (((value) + ((base)-1)) & ~((base)-1))
+
+namespace android {
+
+LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliHisi);
+
+#if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
+ defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
+uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers(uint64_t flags,
+ bool is_rgb) {
+ uint64_t features = 0UL;
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC)
+ features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16;
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK)
+ features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE);
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK)
+ features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8;
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS)
+ features |= AFBC_FORMAT_MOD_TILED;
+
+ if (features) {
+ if (is_rgb)
+ features |= AFBC_FORMAT_MOD_YTR;
+
+ return DRM_FORMAT_MOD_ARM_AFBC(features);
+ }
+
+ return 0;
+}
+#else
+uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers(
+ uint64_t /* flags */, bool /* is_rgb */) {
+ return 0;
+}
+#endif
+
+int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
+ bool is_rgb;
+
+ private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
+ handle);
+ if (!hnd)
+ return -EINVAL;
+
+ if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
+ return -EINVAL;
+
+ uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
+ if (fmt == DRM_FORMAT_INVALID)
+ return -EINVAL;
+
+ is_rgb = IsDrmFormatRgb(fmt);
+ bo->modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format,
+ is_rgb);
+
+ bo->width = hnd->width;
+ bo->height = hnd->height;
+ bo->hal_format = hnd->req_format;
+ bo->format = fmt;
+ bo->usage = hnd->usage;
+ bo->pixel_stride = hnd->stride;
+ bo->pitches[0] = hnd->byte_stride;
+ bo->prime_fds[0] = hnd->share_fd;
+ bo->offsets[0] = 0;
+
+ switch (fmt) {
+ case DRM_FORMAT_YVU420: {
+ int align = 128;
+ if (hnd->usage &
+ (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK))
+ align = 16;
+ int adjusted_height = MALI_ALIGN(hnd->height, 2);
+ int y_size = adjusted_height * hnd->byte_stride;
+ int vu_stride = MALI_ALIGN(hnd->byte_stride / 2, align);
+ 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;
+ /* U plane */
+ bo->prime_fds[2] = hnd->share_fd;
+ bo->pitches[2] = vu_stride;
+ bo->offsets[2] = y_size + v_size;
+ break;
+ }
+ default:
+ break;
+ }
+
+ bo->with_modifiers = true;
+
+ return 0;
+}
+
+} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliHisi.h b/bufferinfo/legacy/BufferInfoMaliHisi.h
new file mode 100644
index 0000000..698a0d3
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMaliHisi.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#ifndef BUFFERINFOMALIHISI_H_
+#define BUFFERINFOMALIHISI_H_
+
+#include <hardware/gralloc.h>
+
+#include "bufferinfo/BufferInfoGetter.h"
+
+namespace android {
+
+class BufferInfoMaliHisi : public LegacyBufferInfoGetter {
+ public:
+ using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
+
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+
+ private:
+ uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb);
+};
+} // namespace android
+
+#endif
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.cpp b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
new file mode 100644
index 0000000..594b582
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#define LOG_TAG "hwc-bufferinfo-mali-mediatek"
+
+#include "BufferInfoMaliMediatek.h"
+
+#include <hardware/gralloc.h>
+#include <log/log.h>
+#include <stdatomic.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include <cinttypes>
+
+#include "gralloc_priv.h"
+
+namespace android {
+
+LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMediatek);
+
+int BufferInfoMaliMediatek::ConvertBoInfo(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
+ private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
+ handle);
+ if (!hnd)
+ return -EINVAL;
+
+ uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
+ if (fmt == DRM_FORMAT_INVALID)
+ return -EINVAL;
+
+ 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->pixel_stride = hnd->stride;
+ bo->prime_fds[0] = hnd->share_fd;
+ bo->pitches[0] = hnd->byte_stride;
+ bo->offsets[0] = 0;
+
+ return 0;
+}
+
+} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMediatek.h b/bufferinfo/legacy/BufferInfoMaliMediatek.h
new file mode 100644
index 0000000..1204818
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMaliMediatek.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#ifndef BUFFERINFOMALIMTK_H_
+#define BUFFERINFOMALIMTK_H_
+
+#include <hardware/gralloc.h>
+
+#include "bufferinfo/BufferInfoGetter.h"
+
+namespace android {
+
+class BufferInfoMaliMediatek : public LegacyBufferInfoGetter {
+ public:
+ using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
+
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+};
+} // namespace android
+
+#endif
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.cpp b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
new file mode 100644
index 0000000..2f1ca21
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#define LOG_TAG "hwc-bufferinfo-mali-meson"
+
+#include "BufferInfoMaliMeson.h"
+
+#include <log/log.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include <cinttypes>
+
+#include "gralloc_priv.h"
+
+namespace android {
+
+LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMeson);
+
+#if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
+ defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
+uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
+ uint64_t flags) {
+ uint64_t features = 0UL;
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC) {
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK)
+ features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8;
+ else
+ features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16;
+ }
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK)
+ features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE);
+
+ if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS)
+ features |= AFBC_FORMAT_MOD_TILED;
+
+ if (features)
+ return DRM_FORMAT_MOD_ARM_AFBC(features | AFBC_FORMAT_MOD_YTR);
+
+ return 0;
+}
+#else
+uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
+ uint64_t /* flags */) {
+ return 0;
+}
+#endif
+
+int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
+ private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
+ handle);
+ if (!hnd)
+ return -EINVAL;
+
+ if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
+ return -EINVAL;
+
+ uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
+ if (fmt == DRM_FORMAT_INVALID)
+ return -EINVAL;
+
+ bo->modifiers[0] = BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
+ hnd->internal_format);
+
+ bo->width = hnd->width;
+ bo->height = hnd->height;
+ bo->hal_format = hnd->req_format;
+ bo->format = fmt;
+ bo->usage = hnd->usage;
+ bo->pixel_stride = hnd->stride;
+ bo->prime_fds[0] = hnd->share_fd;
+ bo->pitches[0] = hnd->byte_stride;
+ bo->offsets[0] = 0;
+
+ bo->with_modifiers = true;
+
+ return 0;
+}
+
+} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMaliMeson.h b/bufferinfo/legacy/BufferInfoMaliMeson.h
new file mode 100644
index 0000000..ce5d3f9
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMaliMeson.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#ifndef BUFFERINFOMALIHISI_H_
+#define BUFFERINFOMALIHISI_H_
+
+#include <hardware/gralloc.h>
+
+#include "bufferinfo/BufferInfoGetter.h"
+
+namespace android {
+
+class BufferInfoMaliMeson : public LegacyBufferInfoGetter {
+ public:
+ using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+
+ private:
+ uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags);
+};
+} // namespace android
+
+#endif
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.cpp b/bufferinfo/legacy/BufferInfoMinigbm.cpp
new file mode 100644
index 0000000..67a85cb
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMinigbm.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#define LOG_TAG "hwc-bufferinfo-minigbm"
+
+#include "BufferInfoMinigbm.h"
+
+#include <log/log.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include "cros_gralloc_handle.h"
+
+namespace android {
+
+LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm);
+
+int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
+ cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
+ if (!gr_handle)
+ return -EINVAL;
+
+ bo->width = gr_handle->width;
+ bo->height = gr_handle->height;
+ bo->hal_format = gr_handle->droid_format;
+ bo->format = gr_handle->format;
+ bo->usage = gr_handle->usage;
+ bo->pixel_stride = gr_handle->pixel_stride;
+ bo->prime_fds[0] = gr_handle->fds[0];
+ bo->pitches[0] = gr_handle->strides[0];
+ bo->offsets[0] = gr_handle->offsets[0];
+
+ return 0;
+}
+
+} // namespace android
diff --git a/bufferinfo/legacy/BufferInfoMinigbm.h b/bufferinfo/legacy/BufferInfoMinigbm.h
new file mode 100644
index 0000000..bff9d74
--- /dev/null
+++ b/bufferinfo/legacy/BufferInfoMinigbm.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#ifndef BUFFERINFOMINIGBM_H_
+#define BUFFERINFOMINIGBM_H_
+
+#include <hardware/gralloc.h>
+
+#include "bufferinfo/BufferInfoGetter.h"
+
+namespace android {
+
+class BufferInfoMinigbm : public LegacyBufferInfoGetter {
+ public:
+ using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
+ int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+};
+
+} // namespace android
+
+#endif