From patchwork Tue Mar 6 23:19:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 130835 Delivered-To: patches@linaro.org Received: by 10.46.66.2 with SMTP id p2csp4518817lja; Tue, 6 Mar 2018 15:19:26 -0800 (PST) X-Received: by 10.98.214.10 with SMTP id r10mr20529878pfg.8.1520378365921; Tue, 06 Mar 2018 15:19:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520378365; cv=none; d=google.com; s=arc-20160816; b=eDHs86Zh6dvFiJOATDBARu0+z+7KeBJIAnga4/69t7sqeyv1oO6IvwPNjQBsUNBYaf +SF43uhU9nIps7LCAC8l3SnPbNvtdF3zz2RS6nMn528kbHDQ7AXDGwnV2wfok4IgYtZv h+HHPqtExUgbaLKz96OEDqw0kPMvaDFiqN5mfvqA8c0f1BvdCKI8cLIIOn7OBOqyZ/Pc RIIifo/A9F0Bv8dCWRK/tZZ25+3iW/Vaqrz1fpZRmtsNilvVPj09T2SJkstVqKIMYZVG LsjsDusSpJoq4OsmIMtk5Fw6X1az6CU2RejJHXPBNpk8CbnkSRJYG5evVOpmj4IbwtEQ HAOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=l3FJUcF99eeGsyw7I9x1eekOGrjbdmKmwwz/3Mzo2Ok=; b=o52fRGJbH+iF6a/agcQAPiZG7UZiwVg0L+MImPFUlCTz4M0H0V0Nyu0s+/5UI55zhR Ko9yRjrRrWCtJJwd4FpYY9xg9KwtFy3ai5SbMyXVIBstf3VGvS4ujJMTL3I2soBldZAq ValSOknpl1QAzfgKRyihl0ktHjxN1uLq4MxDEBsxTrlUH02CMYzg50ag7NSNz0ec3X// 7+gxhO5zWZmm9Gf4pzbRSbZa7rkpfF+O+h8YjLdnSPFq+XYp43oitXPqNEWg13g2JhkN ezBTRKct1DNutXHaoSsukfzeWZzZCVQJ3TJTBwefZ32o8+qda36x8IKNJAotaGZUJC23 B+yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOENtKYp; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o32-v6sor5092541pld.0.2018.03.06.15.19.25 for (Google Transport Security); Tue, 06 Mar 2018 15:19:25 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gOENtKYp; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l3FJUcF99eeGsyw7I9x1eekOGrjbdmKmwwz/3Mzo2Ok=; b=gOENtKYp+yTUMAxHLxP33rFql4zGIiYJrkGIQufmqtTdcjAggo9+ThhKzla2GMRTiQ Inic9w+S8a0fVlntC4M62rxQrMebPzWFR8z/Wqyxs5ZmVYxxTWC0eESbevaxuqweW31X m2//M13BPakcZ0MNw+F7UXOdYVlQ5W8ZJyOhA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l3FJUcF99eeGsyw7I9x1eekOGrjbdmKmwwz/3Mzo2Ok=; b=DyPnNwUFTuxrJe2yYGaCLGeRBkw7TlZIBg6c19nARe1xl1Ph97OrI+yR/BffSsEU3g JIrCdN8M8UsaNY2o1ezATux56KwD2JII6nydbNkJXhRgm/+3eP4TGHGABBEAYBKxsgvJ LqjK6O3QNaNotXA2qRj8uW4xeGN5dMhhLfhR+wnBGr/rtJRlbcn8RhPe181q21U4BZPT 3k3oT6v2tQIpYKnHmIthGKbe6klInhewY6qGF6VY0VaKsVvlju2J87lrv5hwujzzL5Vu 95qBDtRi3xdhNc9Yo1CEClFAsozRyo17vBU7d44j82F67l2EWnhC4mVstuEyvznjCCfh T74Q== X-Gm-Message-State: APf1xPBGScvP1PEYHrYg8YU1wKrvlkj+mqFBwx2dotVbk83sURtgaqn8 birGxZDLHehQHuQnxnF3CSGFj8Kg X-Google-Smtp-Source: AG47ELu3dpS2UnmE9dEniS4j9muw4L2PbV7eptR+A5BefKpz0T5cYegxg0/vFsPAC4OqB2odKimDBQ== X-Received: by 2002:a17:902:7509:: with SMTP id i9-v6mr18746800pll.220.1520378365356; Tue, 06 Mar 2018 15:19:25 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id b4sm30854413pfa.3.2018.03.06.15.19.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Mar 2018 15:19:24 -0800 (PST) From: John Stultz To: dri-devel Cc: John Stultz , Marissa Wall , Sean Paul , Dmitry Shmidt , Robert Foss , Matt Szczesiak , Liviu Dudau , David Hanna , Rob Herring , Alexandru-Cosmin Gheorghe Subject: [RFC][PATCH 2/2 v4] drm_hwcomposer: Add platformhisi buffer importer for hikey and hikey960 Date: Tue, 6 Mar 2018 15:19:12 -0800 Message-Id: <1520378352-31260-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520378352-31260-1-git-send-email-john.stultz@linaro.org> References: <1520378352-31260-1-git-send-email-john.stultz@linaro.org> This allows for importing buffers allocated from the hikey and hikey960 gralloc implelementations. Cc: Marissa Wall Cc: Sean Paul Cc: Dmitry Shmidt Cc: Robert Foss Cc: Matt Szczesiak Cc: Liviu Dudau Cc: David Hanna Cc: Rob Herring Cc: Alexandru-Cosmin Gheorghe Signed-off-by: John Stultz --- v2: * Make platformhisi and the generic importer exclusive in the build * Fixup vendor check v3: * Unify format conversions * Subclass the platformdrmgeneric importer implementation to reduce code duplication * Rework to avoid board specific logic (tweak gralloc to be consistent between the two) v4: * Minor cleanups as suggested by Alexandru-Cosmin Gheorghe --- Android.mk | 13 +++++ platformdrmgeneric.h | 2 +- platformhisi.cpp | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ platformhisi.h | 48 ++++++++++++++++++ 4 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 platformhisi.cpp create mode 100644 platformhisi.h -- 2.7.4 diff --git a/Android.mk b/Android.mk index ee5b8bf..f37e4c3 100644 --- a/Android.mk +++ b/Android.mk @@ -74,7 +74,20 @@ LOCAL_CPPFLAGS += \ -DHWC2_USE_CPP11 \ -DHWC2_INCLUDE_STRINGIFICATION + +ifeq ($(TARGET_PRODUCT),hikey960) +LOCAL_CPPFLAGS += -DUSE_HISI_IMPORTER +LOCAL_SRC_FILES += platformhisi.cpp +LOCAL_C_INCLUDES += device/linaro/hikey/gralloc960/ +else +ifeq ($(TARGET_PRODUCT),hikey) +LOCAL_CPPFLAGS += -DUSE_HISI_IMPORTER +LOCAL_SRC_FILES += platformhisi.cpp +LOCAL_C_INCLUDES += device/linaro/hikey/gralloc/ +else LOCAL_CPPFLAGS += -DUSE_DRM_GENERIC_IMPORTER +endif +endif LOCAL_MODULE := hwcomposer.drm LOCAL_MODULE_TAGS := optional diff --git a/platformdrmgeneric.h b/platformdrmgeneric.h index 8376580..fbe059b 100644 --- a/platformdrmgeneric.h +++ b/platformdrmgeneric.h @@ -35,8 +35,8 @@ class DrmGenericImporter : public Importer { int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override; int ReleaseBuffer(hwc_drm_bo_t *bo) override; - private: uint32_t ConvertHalFormatToDrm(uint32_t hal_format); + private: DrmResources *drm_; diff --git a/platformhisi.cpp b/platformhisi.cpp new file mode 100644 index 0000000..16c5e6f --- /dev/null +++ b/platformhisi.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "hwc-platform-hisi" + +#include "drmresources.h" +#include "platform.h" +#include "platformhisi.h" + + +#include +#include +#include +#include +#include + +#include +#include +#include "gralloc_priv.h" + + +namespace android { + +Importer *Importer::CreateInstance(DrmResources *drm) { + HisiImporter *importer = new HisiImporter(drm); + if (!importer) + return NULL; + + int ret = importer->Init(); + if (ret) { + ALOGE("Failed to initialize the hisi importer %d", ret); + delete importer; + return NULL; + } + return importer; +} + +HisiImporter::HisiImporter(DrmResources *drm) : DrmGenericImporter(drm), drm_(drm) { +} + +HisiImporter::~HisiImporter() { +} + +int HisiImporter::Init() { + int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, + (const hw_module_t **)&gralloc_); + if (ret) { + ALOGE("Failed to open gralloc module %d", ret); + return ret; + } + + if (strcasecmp(gralloc_->common.author, "ARM Ltd.")) + ALOGW("Using non-ARM gralloc module: %s/%s\n", gralloc_->common.name, + gralloc_->common.author); + + return 0; +} + +EGLImageKHR HisiImporter::ImportImage(EGLDisplay egl_display, buffer_handle_t handle) { + private_handle_t const *hnd = reinterpret_cast < private_handle_t const *>(handle); + if (!hnd) + return NULL; + + EGLint fmt = ConvertHalFormatToDrm(hnd->req_format); + if (fmt < 0) + return NULL; + + EGLint attr[] = { + EGL_WIDTH, hnd->width, + EGL_HEIGHT, hnd->height, + EGL_LINUX_DRM_FOURCC_EXT, fmt, + EGL_DMA_BUF_PLANE0_FD_EXT, hnd->share_fd, + EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, + EGL_DMA_BUF_PLANE0_PITCH_EXT, hnd->byte_stride, + EGL_NONE, + }; + return eglCreateImageKHR(egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attr); +} + +int HisiImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) { + private_handle_t const *hnd = reinterpret_cast < private_handle_t const *>(handle); + if (!hnd) + return -EINVAL; + + uint32_t gem_handle; + int ret = drmPrimeFDToHandle(drm_->fd(), hnd->share_fd, &gem_handle); + if (ret) { + ALOGE("failed to import prime fd %d ret=%d", hnd->share_fd, ret); + return ret; + } + + EGLint fmt = ConvertHalFormatToDrm(hnd->req_format); + if (fmt < 0) + return fmt; + + memset(bo, 0, sizeof(hwc_drm_bo_t)); + bo->width = hnd->width; + bo->height = hnd->height; + bo->format = fmt; + bo->usage = hnd->usage; + bo->pitches[0] = hnd->byte_stride; + bo->gem_handles[0] = gem_handle; + bo->offsets[0] = 0; + + ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format, + bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0); + if (ret) { + ALOGE("could not create drm fb %d", ret); + return ret; + } + + return ret; +} + +std::unique_ptr Planner::CreateInstance(DrmResources *) { + std::unique_ptr planner(new Planner); + planner->AddStage(); + return planner; +} +} + + diff --git a/platformhisi.h b/platformhisi.h new file mode 100644 index 0000000..46f4595 --- /dev/null +++ b/platformhisi.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_PLATFORM_HISI_H_ +#define ANDROID_PLATFORM_HISI_H_ + +#include "drmresources.h" +#include "platform.h" +#include "platformdrmgeneric.h" + +#include + +#include + +namespace android { + +class HisiImporter : public DrmGenericImporter { + public: + HisiImporter(DrmResources *drm); + ~HisiImporter() override; + + int Init(); + + EGLImageKHR ImportImage(EGLDisplay egl_display, buffer_handle_t handle) override; + int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override; + + private: + + DrmResources *drm_; + + const gralloc_module_t *gralloc_; +}; +} + +#endif