blob: 9daf542b5e031f67f1a3b62402da00f72aae55e5 [file] [log] [blame]
Neil Armstrong17d3c8b2019-04-25 15:17:22 +00001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030017#define LOG_TAG "hwc-bufferinfo-mali-meson"
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000018
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030019#include "BufferInfoMaliMeson.h"
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000020
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030021#include <xf86drm.h>
22#include <xf86drmMode.h>
23
24#include <cinttypes>
25
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000026#include "gralloc_priv.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020027#include "utils/log.h"
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000028
29namespace android {
30
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030031LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMeson);
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000032
33#if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
34 defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030035uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
36 uint64_t flags) {
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000037 uint64_t features = 0UL;
38
Neil Armstrong6a1c38d2019-10-10 09:35:57 +000039 if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC) {
40 if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK)
41 features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8;
42 else
43 features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16;
44 }
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000045
46 if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK)
47 features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE);
48
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000049 if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS)
50 features |= AFBC_FORMAT_MOD_TILED;
51
52 if (features)
53 return DRM_FORMAT_MOD_ARM_AFBC(features | AFBC_FORMAT_MOD_YTR);
54
55 return 0;
56}
57#else
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030058uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000059 uint64_t /* flags */) {
60 return 0;
61}
62#endif
63
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030064int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle,
65 hwc_drm_bo_t *bo) {
Roman Stratiienkod21071f2021-03-09 21:56:50 +020066 const auto *hnd = (private_handle_t const *)handle;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000067 if (!hnd)
68 return -EINVAL;
69
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000070 if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
71 return -EINVAL;
72
Roman Stratiienkof63726c2019-11-06 15:03:12 +020073 uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
74 if (fmt == DRM_FORMAT_INVALID)
75 return -EINVAL;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000076
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030077 bo->modifiers[0] = BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
Roman Stratiienko4163efc2019-12-06 12:30:28 +020078 hnd->internal_format);
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000079
80 bo->width = hnd->width;
81 bo->height = hnd->height;
82 bo->hal_format = hnd->req_format;
83 bo->format = fmt;
84 bo->usage = hnd->usage;
Roman Stratiienko4163efc2019-12-06 12:30:28 +020085 bo->prime_fds[0] = hnd->share_fd;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000086 bo->pitches[0] = hnd->byte_stride;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000087 bo->offsets[0] = 0;
88
Roman Stratiienko4163efc2019-12-06 12:30:28 +020089 return 0;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000090}
91
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000092} // namespace android