John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 1 | /* |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 2 | * Copyright (C) 2020 The Android Open Source Project |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 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 Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 17 | #define LOG_TAG "hwc-bufferinfo-mali-hisi" |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 18 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 19 | #include "BufferInfoMaliHisi.h" |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 20 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 21 | #include <log/log.h> |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 22 | #include <xf86drm.h> |
| 23 | #include <xf86drmMode.h> |
| 24 | |
| 25 | #include <cinttypes> |
| 26 | |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 27 | #include "gralloc_priv.h" |
| 28 | |
John Stultz | df35a81 | 2018-05-31 17:37:21 -0700 | [diff] [blame] | 29 | #define MALI_ALIGN(value, base) (((value) + ((base)-1)) & ~((base)-1)) |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 33 | LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliHisi); |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 34 | |
Victor Chong | a9ed46a | 2019-04-11 06:23:28 +0100 | [diff] [blame] | 35 | #if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \ |
| 36 | defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16) |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 37 | uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers(uint64_t flags, |
| 38 | bool is_rgb) { |
Ayan Kumar Halder | cc5fca4 | 2019-01-14 12:47:12 +0000 | [diff] [blame] | 39 | 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 Stultz | 65c988d | 2019-02-27 23:34:53 -0800 | [diff] [blame] | 62 | #else |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 63 | uint64_t BufferInfoMaliHisi::ConvertGrallocFormatToDrmModifiers( |
| 64 | uint64_t /* flags */, bool /* is_rgb */) { |
John Stultz | 65c988d | 2019-02-27 23:34:53 -0800 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | #endif |
Ayan Kumar Halder | cc5fca4 | 2019-01-14 12:47:12 +0000 | [diff] [blame] | 68 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 69 | int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle, |
| 70 | hwc_drm_bo_t *bo) { |
Ayan Kumar Halder | cc5fca4 | 2019-01-14 12:47:12 +0000 | [diff] [blame] | 71 | bool is_rgb; |
Sean Paul | 54589d2 | 2018-08-24 16:58:35 -0400 | [diff] [blame] | 72 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 73 | private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>( |
| 74 | handle); |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 75 | if (!hnd) |
| 76 | return -EINVAL; |
| 77 | |
Sean Paul | 54589d2 | 2018-08-24 16:58:35 -0400 | [diff] [blame] | 78 | if (!(hnd->usage & GRALLOC_USAGE_HW_FB)) |
Alexey Firago | c385afe | 2018-11-27 14:17:55 +0300 | [diff] [blame] | 79 | return -EINVAL; |
Sean Paul | 54589d2 | 2018-08-24 16:58:35 -0400 | [diff] [blame] | 80 | |
Roman Stratiienko | f63726c | 2019-11-06 15:03:12 +0200 | [diff] [blame] | 81 | uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format); |
| 82 | if (fmt == DRM_FORMAT_INVALID) |
| 83 | return -EINVAL; |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 84 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame^] | 85 | is_rgb = IsDrmFormatRgb(fmt); |
| 86 | bo->modifiers[0] = ConvertGrallocFormatToDrmModifiers(hnd->internal_format, |
| 87 | is_rgb); |
Ayan Kumar Halder | cc5fca4 | 2019-01-14 12:47:12 +0000 | [diff] [blame] | 88 | |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 89 | bo->width = hnd->width; |
| 90 | bo->height = hnd->height; |
John Stultz | 616fb22 | 2018-08-24 16:08:57 -0700 | [diff] [blame] | 91 | bo->hal_format = hnd->req_format; |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 92 | bo->format = fmt; |
| 93 | bo->usage = hnd->usage; |
John Stultz | a451483 | 2018-08-24 16:27:36 -0700 | [diff] [blame] | 94 | bo->pixel_stride = hnd->stride; |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 95 | bo->pitches[0] = hnd->byte_stride; |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 96 | bo->prime_fds[0] = hnd->share_fd; |
John Stultz | 499db60 | 2018-03-13 16:51:12 -0700 | [diff] [blame] | 97 | bo->offsets[0] = 0; |
| 98 | |
John Stultz | df35a81 | 2018-05-31 17:37:21 -0700 | [diff] [blame] | 99 | switch (fmt) { |
| 100 | case DRM_FORMAT_YVU420: { |
| 101 | int align = 128; |
| 102 | if (hnd->usage & |
| 103 | (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) |
| 104 | align = 16; |
| 105 | int adjusted_height = MALI_ALIGN(hnd->height, 2); |
| 106 | int y_size = adjusted_height * hnd->byte_stride; |
| 107 | int vu_stride = MALI_ALIGN(hnd->byte_stride / 2, align); |
| 108 | int v_size = vu_stride * (adjusted_height / 2); |
| 109 | |
| 110 | /* V plane*/ |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 111 | bo->prime_fds[1] = hnd->share_fd; |
John Stultz | df35a81 | 2018-05-31 17:37:21 -0700 | [diff] [blame] | 112 | bo->pitches[1] = vu_stride; |
| 113 | bo->offsets[1] = y_size; |
| 114 | /* U plane */ |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 115 | bo->prime_fds[2] = hnd->share_fd; |
John Stultz | df35a81 | 2018-05-31 17:37:21 -0700 | [diff] [blame] | 116 | bo->pitches[2] = vu_stride; |
| 117 | bo->offsets[2] = y_size + v_size; |
| 118 | break; |
| 119 | } |
| 120 | default: |
| 121 | break; |
| 122 | } |
| 123 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 124 | bo->with_modifiers = true; |
Ayan Kumar Halder | cc5fca4 | 2019-01-14 12:47:12 +0000 | [diff] [blame] | 125 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 126 | return 0; |
Alexey Firago | 18ec688 | 2018-11-21 23:47:05 +0300 | [diff] [blame] | 127 | } |
| 128 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 129 | } // namespace android |