blob: f8b4412d4dbc2eb89fbccbe91cee5a966f26bb3f [file] [log] [blame]
John Stultz499db602018-03-13 16:51:12 -07001/*
2 * Copyright (C) 2015 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-hisi"
18
19#include "drmresources.h"
20#include "platform.h"
21#include "platformhisi.h"
22
23
24#include <drm/drm_fourcc.h>
25#include <cinttypes>
26#include <stdatomic.h>
27#include <xf86drm.h>
28#include <xf86drmMode.h>
29
John Stultz9057a6f2018-04-26 12:05:55 -070030#include <log/log.h>
John Stultz499db602018-03-13 16:51:12 -070031#include <hardware/gralloc.h>
32#include "gralloc_priv.h"
33
34
35namespace android {
36
37Importer *Importer::CreateInstance(DrmResources *drm) {
38 HisiImporter *importer = new HisiImporter(drm);
39 if (!importer)
40 return NULL;
41
42 int ret = importer->Init();
43 if (ret) {
44 ALOGE("Failed to initialize the hisi importer %d", ret);
45 delete importer;
46 return NULL;
47 }
48 return importer;
49}
50
51HisiImporter::HisiImporter(DrmResources *drm) : DrmGenericImporter(drm), drm_(drm) {
52}
53
54HisiImporter::~HisiImporter() {
55}
56
57int HisiImporter::Init() {
58 int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
59 (const hw_module_t **)&gralloc_);
60 if (ret) {
61 ALOGE("Failed to open gralloc module %d", ret);
62 return ret;
63 }
64
65 if (strcasecmp(gralloc_->common.author, "ARM Ltd."))
66 ALOGW("Using non-ARM gralloc module: %s/%s\n", gralloc_->common.name,
67 gralloc_->common.author);
68
69 return 0;
70}
71
John Stultz499db602018-03-13 16:51:12 -070072int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
Rob Herringaf0d9752018-05-04 16:34:19 -050073 private_handle_t const *hnd =
74 reinterpret_cast<private_handle_t const *>(handle);
John Stultz499db602018-03-13 16:51:12 -070075 if (!hnd)
76 return -EINVAL;
77
78 uint32_t gem_handle;
79 int ret = drmPrimeFDToHandle(drm_->fd(), hnd->share_fd, &gem_handle);
80 if (ret) {
81 ALOGE("failed to import prime fd %d ret=%d", hnd->share_fd, ret);
82 return ret;
83 }
84
Rob Herringaf0d9752018-05-04 16:34:19 -050085 int32_t fmt = ConvertHalFormatToDrm(hnd->req_format);
John Stultz499db602018-03-13 16:51:12 -070086 if (fmt < 0)
87 return fmt;
88
89 memset(bo, 0, sizeof(hwc_drm_bo_t));
90 bo->width = hnd->width;
91 bo->height = hnd->height;
92 bo->format = fmt;
93 bo->usage = hnd->usage;
94 bo->pitches[0] = hnd->byte_stride;
95 bo->gem_handles[0] = gem_handle;
96 bo->offsets[0] = 0;
97
98 ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
99 bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
100 if (ret) {
101 ALOGE("could not create drm fb %d", ret);
102 return ret;
103 }
104
105 return ret;
106}
107
108std::unique_ptr<Planner> Planner::CreateInstance(DrmResources *) {
109 std::unique_ptr<Planner> planner(new Planner);
110 planner->AddStage<PlanStageGreedy>();
111 return planner;
112}
113}