blob: 1858ddbcd6407711bcd2bbefa543904d55bafe03 [file] [log] [blame]
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +03001/*
2 * Copyright (C) 2020 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-bufferinfo-imagination"
18
19#include "BufferInfoImagination.h"
20
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030021#include <xf86drm.h>
22
Roman Stratiienko1e053b42021-10-25 22:54:20 +030023#include <cerrno>
24
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030025#include "img_gralloc1_public.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020026#include "utils/log.h"
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030027
28namespace android {
29
30LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination);
31
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020032auto BufferInfoImagination::GetBoInfo(buffer_handle_t handle)
33 -> std::optional<BufferInfo> {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020034 auto *hnd = (IMG_native_handle_t *)handle;
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030035 if (!hnd)
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020036 return {};
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030037
38 /* Extra bits are responsible for buffer compression and memory layout */
39 if (hnd->iFormat & ~0x10f) {
40 ALOGV("Special buffer formats are not supported");
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020041 return {};
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030042 }
43
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020044 BufferInfo bi{};
45
46 bi.width = hnd->iWidth;
47 bi.height = hnd->iHeight;
48 bi.prime_fds[0] = hnd->fd[0];
49 bi.pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030050
51 switch (hnd->iFormat) {
52#ifdef HAL_PIXEL_FORMAT_BGRX_8888
53 case HAL_PIXEL_FORMAT_BGRX_8888:
54 bo->format = DRM_FORMAT_XRGB8888;
55 break;
56#endif
57 default:
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020058 bi.format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
59 if (bi.format == DRM_FORMAT_INVALID) {
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030060 ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat);
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020061 return {};
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030062 }
63 }
64
Roman Stratiienkoe9fbd8d2022-02-21 13:03:29 +020065 return bi;
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030066}
67
68} // namespace android