blob: 777c2b72af7b3d5447f1ee817e7e6c73de6ce48a [file] [log] [blame]
Alistair Strachan71edaca2018-05-02 17:01:49 -07001/*
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 Stratiienkob2e9fe22020-10-03 10:52:36 +030017#define LOG_TAG "hwc-bufferinfo-minigbm"
Alistair Strachan71edaca2018-05-02 17:01:49 -070018
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030019#include "BufferInfoMinigbm.h"
Alistair Strachan71edaca2018-05-02 17:01:49 -070020
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030021#include <xf86drm.h>
22#include <xf86drmMode.h>
Alistair Strachan71edaca2018-05-02 17:01:49 -070023
Roman Stratiienko1e053b42021-10-25 22:54:20 +030024#include <cerrno>
Roman Stratiienko39d8f7e2021-11-30 17:06:44 +020025#include <cstring>
Roman Stratiienko1e053b42021-10-25 22:54:20 +030026
Roman Stratiienkod21071f2021-03-09 21:56:50 +020027#include "utils/log.h"
Alistair Strachan71edaca2018-05-02 17:01:49 -070028namespace android {
29
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030030LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm);
Alistair Strachan71edaca2018-05-02 17:01:49 -070031
Roman Stratiienko5621f5f2021-11-30 17:48:16 +020032constexpr int CROS_GRALLOC_DRM_GET_FORMAT = 1;
33constexpr int CROS_GRALLOC_DRM_GET_DIMENSIONS = 2;
34constexpr int CROS_GRALLOC_DRM_GET_BUFFER_INFO = 4;
35constexpr int CROS_GRALLOC_DRM_GET_USAGE = 5;
36
37struct 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 Stratiienkob2e9fe22020-10-03 10:52:36 +030046int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
Roman Stratiienko5621f5f2021-11-30 17:48:16 +020047 if (handle == nullptr) {
Alistair Strachan71edaca2018-05-02 17:01:49 -070048 return -EINVAL;
Roman Stratiienko5621f5f2021-11-30 17:48:16 +020049 }
Alistair Strachan71edaca2018-05-02 17:01:49 -070050
Roman Stratiienko5621f5f2021-11-30 17:48:16 +020051 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 Stratiienko6e6a93a2020-12-13 17:41:04 +020060
Roman Stratiienko5621f5f2021-11-30 17:48:16 +020061 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 Stratiienko6e6a93a2020-12-13 17:41:04 +020069
Roman Stratiienko5621f5f2021-11-30 17:48:16 +020070 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 Stratiienko6e6a93a2020-12-13 17:41:04 +020078
Roman Stratiienko5621f5f2021-11-30 17:48:16 +020079 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 Stratiienko6e6a93a2020-12-13 17:41:04 +0200101 }
Alistair Strachan71edaca2018-05-02 17:01:49 -0700102
Roman Stratiienko4163efc2019-12-06 12:30:28 +0200103 return 0;
Alistair Strachan71edaca2018-05-02 17:01:49 -0700104}
105
Roman Stratiienko39d8f7e2021-11-30 17:06:44 +0200106constexpr char cros_gralloc_module_name[] = "CrOS Gralloc";
107
108int 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 Stratiienko5621f5f2021-11-30 17:48:16 +0200115 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 Stratiienko39d8f7e2021-11-30 17:06:44 +0200122 return 0;
123}
124
Sean Paulf72cccd2018-08-27 13:59:08 -0400125} // namespace android