drm_hwcomposer: refactor platform directory
Motivation:
Platform term meaning used in drm_hwcomposer does not correspond to the
content of the platform directory. Platform directory consists of:
1. Buffer information getters for different gralloc (currently called platform).
2. Composition planner logic (which has flaws and should be reworked into
layer->plane mapping during validation stage logic).
3. DrmGenericImpoter with reference counting logic.
Android-11 IMapper@4 metadata API offers a generic way to access buffer
information which makes other gralloc buffer information getters obsolete.
Legacy getters should be maintained for some time until all known users
will migrate to Mapper@4 API.
Implementation:
1. Split 'PlatformImporter' logic to 'Importer' only and 'Buffer Getter' logic.
a. Remove buffer_handle_t parameter from ImportBuffer(). Instead user should
get BufferInfo using ConvertBoInfo to struct hwc_drm_bo_t, then use it for
ImportBuffer().
b. Move DrmGenericImporter.{cpp/h} into the drm directory.
2. Isolate planner code in single file and move it to compositor directory as
compositor/Planner.{cpp/h}
3. Rename platform definition
a. Rename platform directory to bufferinfo.
b. Rename/move bufferinfo/platorm*.{cpp,h} getters to
bufferinfo/legacy/BufferInfo*.{cpp,h}. Align class names/includes.
4. Split legacy/metadata getters logic.
a. Apply existing bufferinfogetter base class only for legacy getters.
b. Combine legacy/generic gettera under new base class.
c. Create a placeholder for generic(metadata) getter.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
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