Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 17 | #define LOG_TAG "hwc-bufferinfo-minigbm" |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 18 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 19 | #include "BufferInfoMinigbm.h" |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 20 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 21 | #include <xf86drm.h> |
| 22 | #include <xf86drmMode.h> |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 23 | |
Roman Stratiienko | 1e053b4 | 2021-10-25 22:54:20 +0300 | [diff] [blame] | 24 | #include <cerrno> |
Roman Stratiienko | 39d8f7e | 2021-11-30 17:06:44 +0200 | [diff] [blame] | 25 | #include <cstring> |
Roman Stratiienko | 1e053b4 | 2021-10-25 22:54:20 +0300 | [diff] [blame] | 26 | |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 27 | #include "utils/log.h" |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 30 | LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm); |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 31 | |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 32 | constexpr int CROS_GRALLOC_DRM_GET_FORMAT = 1; |
| 33 | constexpr int CROS_GRALLOC_DRM_GET_DIMENSIONS = 2; |
| 34 | constexpr int CROS_GRALLOC_DRM_GET_BUFFER_INFO = 4; |
| 35 | constexpr int CROS_GRALLOC_DRM_GET_USAGE = 5; |
| 36 | |
| 37 | struct cros_gralloc0_buffer_info { |
| 38 | uint32_t drm_fourcc; |
| 39 | int num_fds; |
| 40 | int fds[4]; |
| 41 | uint64_t modifier; |
| 42 | int offset[4]; |
| 43 | int stride[4]; |
| 44 | }; |
| 45 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 46 | int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) { |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 47 | if (handle == nullptr) { |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 48 | return -EINVAL; |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 49 | } |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 50 | |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 51 | uint32_t width{}; |
| 52 | uint32_t height{}; |
| 53 | if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_DIMENSIONS, handle, |
| 54 | &width, &height) != 0) { |
| 55 | ALOGE( |
| 56 | "CROS_GRALLOC_DRM_GET_DIMENSIONS operation has failed. " |
| 57 | "Please ensure you are using the latest minigbm."); |
| 58 | return -EINVAL; |
| 59 | } |
Roman Stratiienko | 6e6a93a | 2020-12-13 17:41:04 +0200 | [diff] [blame] | 60 | |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 61 | int32_t droid_format{}; |
| 62 | if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_FORMAT, handle, |
| 63 | &droid_format) != 0) { |
| 64 | ALOGE( |
| 65 | "CROS_GRALLOC_DRM_GET_FORMAT operation has failed. " |
| 66 | "Please ensure you are using the latest minigbm."); |
| 67 | return -EINVAL; |
| 68 | } |
Roman Stratiienko | 6e6a93a | 2020-12-13 17:41:04 +0200 | [diff] [blame] | 69 | |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 70 | uint32_t usage{}; |
| 71 | if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_USAGE, handle, &usage) != |
| 72 | 0) { |
| 73 | ALOGE( |
| 74 | "CROS_GRALLOC_DRM_GET_USAGE operation has failed. " |
| 75 | "Please ensure you are using the latest minigbm."); |
| 76 | return -EINVAL; |
| 77 | } |
Roman Stratiienko | 6e6a93a | 2020-12-13 17:41:04 +0200 | [diff] [blame] | 78 | |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 79 | struct cros_gralloc0_buffer_info info {}; |
| 80 | if (gralloc_->perform(gralloc_, CROS_GRALLOC_DRM_GET_BUFFER_INFO, handle, |
| 81 | &info) != 0) { |
| 82 | ALOGE( |
| 83 | "CROS_GRALLOC_DRM_GET_BUFFER_INFO operation has failed. " |
| 84 | "Please ensure you are using the latest minigbm."); |
| 85 | return -EINVAL; |
| 86 | } |
| 87 | |
| 88 | bo->width = width; |
| 89 | bo->height = height; |
| 90 | |
| 91 | bo->hal_format = droid_format; |
| 92 | |
| 93 | bo->format = info.drm_fourcc; |
| 94 | bo->usage = usage; |
| 95 | |
| 96 | for (int i = 0; i < info.num_fds; i++) { |
| 97 | bo->modifiers[i] = info.modifier; |
| 98 | bo->prime_fds[i] = info.fds[i]; |
| 99 | bo->pitches[i] = info.stride[i]; |
| 100 | bo->offsets[i] = info.offset[i]; |
Roman Stratiienko | 6e6a93a | 2020-12-13 17:41:04 +0200 | [diff] [blame] | 101 | } |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 102 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 103 | return 0; |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Roman Stratiienko | 39d8f7e | 2021-11-30 17:06:44 +0200 | [diff] [blame] | 106 | constexpr char cros_gralloc_module_name[] = "CrOS Gralloc"; |
| 107 | |
| 108 | int BufferInfoMinigbm::ValidateGralloc() { |
| 109 | if (strcmp(gralloc_->common.name, cros_gralloc_module_name) != 0) { |
| 110 | ALOGE("Gralloc name isn't valid: Expected: \"%s\", Actual: \"%s\"", |
| 111 | cros_gralloc_module_name, gralloc_->common.name); |
| 112 | return -EINVAL; |
| 113 | } |
| 114 | |
Roman Stratiienko | 5621f5f | 2021-11-30 17:48:16 +0200 | [diff] [blame^] | 115 | if (gralloc_->perform == nullptr) { |
| 116 | ALOGE( |
| 117 | "CrOS gralloc has no perform call implemented. Please upgrade your " |
| 118 | "minigbm."); |
| 119 | return -EINVAL; |
| 120 | } |
| 121 | |
Roman Stratiienko | 39d8f7e | 2021-11-30 17:06:44 +0200 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 125 | } // namespace android |