blob: bfb2e7baaf365810e19fccb0100f238695aa06e2 [file] [log] [blame]
John Stultz499db602018-03-13 16:51:12 -07001/*
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +03002 * Copyright (C) 2020 The Android Open Source Project
John Stultz499db602018-03-13 16:51:12 -07003 *
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
Sean Paul468a7542024-07-16 19:50:58 +000017#define LOG_TAG "drmhwc"
John Stultz499db602018-03-13 16:51:12 -070018
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030019#include "BufferInfoMaliHisi.h"
John Stultz499db602018-03-13 16:51:12 -070020
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030021#include <xf86drm.h>
22#include <xf86drmMode.h>
23
24#include <cinttypes>
25
John Stultz499db602018-03-13 16:51:12 -070026#include "gralloc_priv.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020027#include "utils/log.h"
John Stultz499db602018-03-13 16:51:12 -070028
John Stultzdf35a812018-05-31 17:37:21 -070029#define MALI_ALIGN(value, base) (((value) + ((base)-1)) & ~((base)-1))
John Stultz499db602018-03-13 16:51:12 -070030
31namespace android {
32
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030033LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliHisi);
John Stultz499db602018-03-13 16:51:12 -070034
Victor Chonga9ed46a2019-04-11 06:23:28 +010035#if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
36 defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030037uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers(uint64_t flags,
38 bool is_rgb) {
Ayan Kumar Haldercc5fca42019-01-14 12:47:12 +000039 uint64_t features = 0UL;
40
41 if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC)
42 features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16;
43
44 if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK)
45 features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE);
46
47 if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK)
48 features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8;
49
50 if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS)
51 features |= AFBC_FORMAT_MOD_TILED;
52
53 if (features) {
54 if (is_rgb)
55 features |= AFBC_FORMAT_MOD_YTR;
56
57 return DRM_FORMAT_MOD_ARM_AFBC(features);
58 }
59
60 return 0;
61}
John Stultz65c988d2019-02-27 23:34:53 -080062#else
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030063uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers(
64 uint64_t /* flags */, bool /* is_rgb */) {
John Stultz65c988d2019-02-27 23:34:53 -080065 return 0;
66}
67#endif
Ayan Kumar Haldercc5fca42019-01-14 12:47:12 +000068
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020069auto BufferInfoMaliHisi::GetBoInfo(buffer_handle_t handle)
70 -> std::optional<BufferInfo> {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020071 bool is_rgb = false;
Sean Paul54589d22018-08-24 16:58:35 -040072
Roman Stratiienkod21071f2021-03-09 21:56:50 +020073 const auto *hnd = (private_handle_t const *)handle;
John Stultz499db602018-03-13 16:51:12 -070074 if (!hnd)
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020075 return {};
John Stultz499db602018-03-13 16:51:12 -070076
Sean Paul54589d22018-08-24 16:58:35 -040077 if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020078 return {};
Sean Paul54589d22018-08-24 16:58:35 -040079
Roman Stratiienkoa7913de2022-10-20 13:18:57 +030080 const uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
Roman Stratiienkof63726c2019-11-06 15:03:12 +020081 if (fmt == DRM_FORMAT_INVALID)
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020082 return {};
83
84 BufferInfo bi{};
John Stultz499db602018-03-13 16:51:12 -070085
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030086 is_rgb = IsDrmFormatRgb(fmt);
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020087 bi.modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format,
88 is_rgb);
Ayan Kumar Haldercc5fca42019-01-14 12:47:12 +000089
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020090 bi.width = hnd->width;
91 bi.height = hnd->height;
92 bi.format = fmt;
93 bi.pitches[0] = hnd->byte_stride;
94 bi.prime_fds[0] = hnd->share_fd;
95 bi.offsets[0] = 0;
John Stultz499db602018-03-13 16:51:12 -070096
John Stultzdf35a812018-05-31 17:37:21 -070097 switch (fmt) {
98 case DRM_FORMAT_YVU420: {
99 int align = 128;
100 if (hnd->usage &
101 (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK))
102 align = 16;
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300103 const int adjusted_height = MALI_ALIGN(hnd->height, 2);
104 const int y_size = adjusted_height * hnd->byte_stride;
105 const int vu_stride = MALI_ALIGN(hnd->byte_stride / 2, align);
106 const int v_size = vu_stride * (adjusted_height / 2);
John Stultzdf35a812018-05-31 17:37:21 -0700107
108 /* V plane*/
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +0200109 bi.prime_fds[1] = hnd->share_fd;
110 bi.pitches[1] = vu_stride;
111 bi.offsets[1] = y_size;
John Stultzdf35a812018-05-31 17:37:21 -0700112 /* U plane */
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +0200113 bi.prime_fds[2] = hnd->share_fd;
114 bi.pitches[2] = vu_stride;
115 bi.offsets[2] = y_size + v_size;
John Stultzdf35a812018-05-31 17:37:21 -0700116 break;
117 }
118 default:
119 break;
120 }
121
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +0200122 return bi;
Alexey Firago18ec6882018-11-21 23:47:05 +0300123}
124
Sean Paulf72cccd2018-08-27 13:59:08 -0400125} // namespace android