Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 1 | /* |
| 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 Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 21 | #include <xf86drm.h> |
| 22 | |
| 23 | #include "img_gralloc1_public.h" |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame^] | 24 | #include "utils/log.h" |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination); |
| 29 | |
| 30 | int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle, |
| 31 | hwc_drm_bo_t *bo) { |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 32 | auto *hnd = (IMG_native_handle_t *)handle; |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 33 | if (!hnd) |
| 34 | return -EINVAL; |
| 35 | |
| 36 | /* Extra bits are responsible for buffer compression and memory layout */ |
| 37 | if (hnd->iFormat & ~0x10f) { |
| 38 | ALOGV("Special buffer formats are not supported"); |
| 39 | return -EINVAL; |
| 40 | } |
| 41 | |
| 42 | bo->width = hnd->iWidth; |
| 43 | bo->height = hnd->iHeight; |
| 44 | bo->usage = hnd->usage; |
| 45 | bo->prime_fds[0] = hnd->fd[0]; |
| 46 | bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3; |
| 47 | bo->hal_format = hnd->iFormat; |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 48 | |
| 49 | switch (hnd->iFormat) { |
| 50 | #ifdef HAL_PIXEL_FORMAT_BGRX_8888 |
| 51 | case HAL_PIXEL_FORMAT_BGRX_8888: |
| 52 | bo->format = DRM_FORMAT_XRGB8888; |
| 53 | break; |
| 54 | #endif |
| 55 | default: |
| 56 | bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf); |
| 57 | if (bo->format == DRM_FORMAT_INVALID) { |
| 58 | ALOGV("Cannot convert hal format to drm format %u", hnd->iFormat); |
| 59 | return -EINVAL; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | } // namespace android |