blob: 93b9e98b245d482ade86c01dfd42a536a4e3f96d [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
Alistair Strachan71edaca2018-05-02 17:01:49 -070027#include "cros_gralloc_handle.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020028#include "utils/log.h"
Alistair Strachan71edaca2018-05-02 17:01:49 -070029
Roman Stratiienko6e6a93a2020-12-13 17:41:04 +020030#define DRM_FORMAT_YVU420_ANDROID fourcc_code('9', '9', '9', '7')
31
Alistair Strachan71edaca2018-05-02 17:01:49 -070032namespace android {
33
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030034LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm);
Alistair Strachan71edaca2018-05-02 17:01:49 -070035
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030036int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020037 auto *gr_handle = (cros_gralloc_handle *)handle;
Alistair Strachan71edaca2018-05-02 17:01:49 -070038 if (!gr_handle)
39 return -EINVAL;
40
Alistair Strachan71edaca2018-05-02 17:01:49 -070041 bo->width = gr_handle->width;
42 bo->height = gr_handle->height;
John Stultz616fb222018-08-24 16:08:57 -070043 bo->hal_format = gr_handle->droid_format;
Roman Stratiienko6e6a93a2020-12-13 17:41:04 +020044
Alistair Strachan71edaca2018-05-02 17:01:49 -070045 bo->format = gr_handle->format;
Roman Stratiienko6e6a93a2020-12-13 17:41:04 +020046 if (bo->format == DRM_FORMAT_YVU420_ANDROID)
47 bo->format = DRM_FORMAT_YVU420;
48
Alistair Strachan71edaca2018-05-02 17:01:49 -070049 bo->usage = gr_handle->usage;
Roman Stratiienko6e6a93a2020-12-13 17:41:04 +020050
51 for (int i = 0; i < gr_handle->num_planes; i++) {
52 bo->modifiers[i] = gr_handle->format_modifier;
53 bo->prime_fds[i] = gr_handle->fds[i];
54 bo->pitches[i] = gr_handle->strides[i];
55 bo->offsets[i] = gr_handle->offsets[i];
56 }
Alistair Strachan71edaca2018-05-02 17:01:49 -070057
Roman Stratiienko4163efc2019-12-06 12:30:28 +020058 return 0;
Alistair Strachan71edaca2018-05-02 17:01:49 -070059}
60
Roman Stratiienko39d8f7e2021-11-30 17:06:44 +020061constexpr char cros_gralloc_module_name[] = "CrOS Gralloc";
62
63int BufferInfoMinigbm::ValidateGralloc() {
64 if (strcmp(gralloc_->common.name, cros_gralloc_module_name) != 0) {
65 ALOGE("Gralloc name isn't valid: Expected: \"%s\", Actual: \"%s\"",
66 cros_gralloc_module_name, gralloc_->common.name);
67 return -EINVAL;
68 }
69
70 return 0;
71}
72
Sean Paulf72cccd2018-08-27 13:59:08 -040073} // namespace android