blob: 278eac5df26bac9ad122fddff52f63a46c2a8ee0 [file] [log] [blame]
Neil Armstrong17d3c8b2019-04-25 15:17:22 +00001/*
2 * Copyright (C) 2019 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-platform-meson"
18
19#include "platformmeson.h"
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000020
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000021#include <xf86drm.h>
22#include <xf86drmMode.h>
23#include <cinttypes>
24
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000025#include <log/log.h>
26#include "gralloc_priv.h"
27
28namespace android {
29
30Importer *Importer::CreateInstance(DrmDevice *drm) {
31 MesonImporter *importer = new MesonImporter(drm);
32 if (!importer)
33 return NULL;
34
35 int ret = importer->Init();
36 if (ret) {
37 ALOGE("Failed to initialize the meson importer %d", ret);
38 delete importer;
39 return NULL;
40 }
41 return importer;
42}
43
44#if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
45 defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
46uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags) {
47 uint64_t features = 0UL;
48
Neil Armstrong6a1c38d2019-10-10 09:35:57 +000049 if (flags & MALI_GRALLOC_INTFMT_AFBC_BASIC) {
50 if (flags & MALI_GRALLOC_INTFMT_AFBC_WIDEBLK)
51 features |= AFBC_FORMAT_MOD_BLOCK_SIZE_32x8;
52 else
53 features |= AFBC_FORMAT_MOD_BLOCK_SIZE_16x16;
54 }
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000055
56 if (flags & MALI_GRALLOC_INTFMT_AFBC_SPLITBLK)
57 features |= (AFBC_FORMAT_MOD_SPLIT | AFBC_FORMAT_MOD_SPARSE);
58
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000059 if (flags & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS)
60 features |= AFBC_FORMAT_MOD_TILED;
61
62 if (features)
63 return DRM_FORMAT_MOD_ARM_AFBC(features | AFBC_FORMAT_MOD_YTR);
64
65 return 0;
66}
67#else
68uint64_t MesonImporter::ConvertGrallocFormatToDrmModifiers(
69 uint64_t /* flags */) {
70 return 0;
71}
72#endif
73
Roman Stratiienko4163efc2019-12-06 12:30:28 +020074int MesonImporter::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000075 private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
76 handle);
77 if (!hnd)
78 return -EINVAL;
79
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000080 if (!(hnd->usage & GRALLOC_USAGE_HW_FB))
81 return -EINVAL;
82
Roman Stratiienkof63726c2019-11-06 15:03:12 +020083 uint32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
84 if (fmt == DRM_FORMAT_INVALID)
85 return -EINVAL;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000086
Roman Stratiienko4163efc2019-12-06 12:30:28 +020087 bo->modifiers[0] = MesonImporter::ConvertGrallocFormatToDrmModifiers(
88 hnd->internal_format);
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000089
90 bo->width = hnd->width;
91 bo->height = hnd->height;
92 bo->hal_format = hnd->req_format;
93 bo->format = fmt;
94 bo->usage = hnd->usage;
95 bo->pixel_stride = hnd->stride;
Roman Stratiienko4163efc2019-12-06 12:30:28 +020096 bo->prime_fds[0] = hnd->share_fd;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000097 bo->pitches[0] = hnd->byte_stride;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +000098 bo->offsets[0] = 0;
99
Roman Stratiienko4163efc2019-12-06 12:30:28 +0200100 bo->with_modifiers = true;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +0000101
Roman Stratiienko4163efc2019-12-06 12:30:28 +0200102 return 0;
Neil Armstrong17d3c8b2019-04-25 15:17:22 +0000103}
104
Neil Armstrong17d3c8b2019-04-25 15:17:22 +0000105} // namespace android