Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #define LOG_TAG "hwc-platform-meson" |
| 18 | |
| 19 | #include "platformmeson.h" |
| 20 | #include "drmdevice.h" |
| 21 | #include "platform.h" |
| 22 | |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 23 | #include <stdatomic.h> |
| 24 | #include <xf86drm.h> |
| 25 | #include <xf86drmMode.h> |
| 26 | #include <cinttypes> |
| 27 | |
| 28 | #include <hardware/gralloc.h> |
| 29 | #include <log/log.h> |
| 30 | #include "gralloc_priv.h" |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | Importer *Importer::CreateInstance(DrmDevice *drm) { |
| 35 | MesonImporter *importer = new MesonImporter(drm); |
| 36 | if (!importer) |
| 37 | return NULL; |
| 38 | |
| 39 | int ret = importer->Init(); |
| 40 | if (ret) { |
| 41 | ALOGE("Failed to initialize the meson importer %d", ret); |
| 42 | delete importer; |
| 43 | return NULL; |
| 44 | } |
| 45 | return importer; |
| 46 | } |
| 47 | |
| 48 | #if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \ |
| 49 | defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16) |
| 50 | uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags) { |
| 51 | uint64_t features = 0UL; |
| 52 | |
Neil Armstrong | 6a1c38d | 2019-10-10 09:35:57 +0000 | [diff] [blame] | 53 | if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC) { |
| 54 | if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK) |
| 55 | features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8; |
| 56 | else |
| 57 | features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16; |
| 58 | } |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 59 | |
| 60 | if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK) |
| 61 | features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE); |
| 62 | |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 63 | if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS) |
| 64 | features |= AFBC_FORMAT_MOD_TILED; |
| 65 | |
| 66 | if (features) |
| 67 | return DRM_FORMAT_MOD_ARM_AFBC(features | AFBC_FORMAT_MOD_YTR); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | #else |
| 72 | uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers( |
| 73 | uint64_t /* flags */) { |
| 74 | return 0; |
| 75 | } |
| 76 | #endif |
| 77 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame^] | 78 | int MesonImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 79 | private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>( |
| 80 | handle); |
| 81 | if (!hnd) |
| 82 | return -EINVAL; |
| 83 | |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 84 | if (!(hnd->usage & GRALLOC_USAGE_HW_FB)) |
| 85 | return -EINVAL; |
| 86 | |
Roman Stratiienko | f63726c | 2019-11-06 15:03:12 +0200 | [diff] [blame] | 87 | uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format); |
| 88 | if (fmt == DRM_FORMAT_INVALID) |
| 89 | return -EINVAL; |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 90 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame^] | 91 | bo->modifiers[0] = MesonImporter::ConvertGrallocFormatToDrmModifiers( |
| 92 | hnd->internal_format); |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 93 | |
| 94 | bo->width = hnd->width; |
| 95 | bo->height = hnd->height; |
| 96 | bo->hal_format = hnd->req_format; |
| 97 | bo->format = fmt; |
| 98 | bo->usage = hnd->usage; |
| 99 | bo->pixel_stride = hnd->stride; |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame^] | 100 | bo->prime_fds[0] = hnd->share_fd; |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 101 | bo->pitches[0] = hnd->byte_stride; |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 102 | bo->offsets[0] = 0; |
| 103 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame^] | 104 | bo->with_modifiers = true; |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 105 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame^] | 106 | return 0; |
Neil Armstrong | 17d3c8b | 2019-04-25 15:17:22 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) { |
| 110 | std::unique_ptr<Planner> planner(new Planner); |
| 111 | planner->AddStage<PlanStageGreedy>(); |
| 112 | return planner; |
| 113 | } |
| 114 | } // namespace android |