2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "hwc-platform-hisi"
19 #include "drmresources.h"
21 #include "platformhisi.h"
24 #include <drm/drm_fourcc.h>
26 #include <stdatomic.h>
28 #include <xf86drmMode.h>
30 #include <cutils/log.h>
31 #include <hardware/gralloc.h>
32 #include "gralloc_priv.h"
37 Importer *Importer::CreateInstance(DrmResources *drm) {
38 HisiImporter *importer = new HisiImporter(drm);
42 int ret = importer->Init();
44 ALOGE("Failed to initialize the hisi importer %d", ret);
51 HisiImporter::HisiImporter(DrmResources *drm) : DrmGenericImporter(drm), drm_(drm) {
54 HisiImporter::~HisiImporter() {
57 int HisiImporter::Init() {
58 int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
59 (const hw_module_t **)&gralloc_);
61 ALOGE("Failed to open gralloc module %d", ret);
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);
72 EGLImageKHR HisiImporter::ImportImage(EGLDisplay egl_display, buffer_handle_t handle) {
73 private_handle_t const *hnd = reinterpret_cast < private_handle_t const *>(handle);
77 EGLint fmt = ConvertHalFormatToDrm(hnd->req_format);
82 EGL_WIDTH, hnd->width,
83 EGL_HEIGHT, hnd->height,
84 EGL_LINUX_DRM_FOURCC_EXT, fmt,
85 EGL_DMA_BUF_PLANE0_FD_EXT, hnd->share_fd,
86 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
87 EGL_DMA_BUF_PLANE0_PITCH_EXT, hnd->byte_stride,
90 return eglCreateImageKHR(egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attr);
93 int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
94 private_handle_t const *hnd = reinterpret_cast < private_handle_t const *>(handle);
99 int ret = drmPrimeFDToHandle(drm_->fd(), hnd->share_fd, &gem_handle);
101 ALOGE("failed to import prime fd %d ret=%d", hnd->share_fd, ret);
105 EGLint fmt = ConvertHalFormatToDrm(hnd->req_format);
109 memset(bo, 0, sizeof(hwc_drm_bo_t));
110 bo->width = hnd->width;
111 bo->height = hnd->height;
113 bo->usage = hnd->usage;
114 bo->pitches[0] = hnd->byte_stride;
115 bo->gem_handles[0] = gem_handle;
118 ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
119 bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
121 ALOGE("could not create drm fb %d", ret);
128 std::unique_ptr<Planner> Planner::CreateInstance(DrmResources *) {
129 std::unique_ptr<Planner> planner(new Planner);
130 planner->AddStage<PlanStageGreedy>();