From patchwork Fri Feb 9 00:40:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 127747 Delivered-To: patches@linaro.org Received: by 10.46.124.24 with SMTP id x24csp117848ljc; Thu, 8 Feb 2018 16:40:17 -0800 (PST) X-Received: by 2002:a17:902:6a89:: with SMTP id n9-v6mr774473plk.212.1518136817051; Thu, 08 Feb 2018 16:40:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518136817; cv=none; d=google.com; s=arc-20160816; b=oUfHFUra7hoTQgqGZZU3IeWLEaTwFSbbWnn59+UYLc2IAeJ37oJQo4CAEiQLirSE7P eNOkyGtfve9UHrbOi6NDy0zr9tuftfOeCc2z/ALugLL54mV3NQfsDqCS0536MJj8CZZD 7d8jWkklVEqdOj31sFJEjQ4VywnPzn78Y0CCydYI70j011lJ0g8a9o4umjMR87rZ6VJr i811D0m35uJgO92gS0xa0QPqvM08XI3PIK4enu9QssLLH8EeFAE8TdwBj+14Y71vUxec bQYNyTHeF/K7xv1dBlYzTBLgkkAgXlxmC5KXDsoh7w1pjd/j0XJ80HbIE5ndlL47vDGn iCgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=8vMTrYyKQYG9zOnyuQfKa48l3j82y7rnJUoefx5qM4k=; b=p7kPW4aRPdDC7cCERNtFydpD1yx6PyiRE1DwFM/E9PGXYSn6Q0u4uSE5fS81xmDJsQ VyTjOeeCT/WglryXvbwoc9tzzA/mStsyxNn6XJw+BoM4NC70K4Y4miZ/BAWEtGVFSc+A qBSqQujxTZ6nAMKWmTM5GQJoccQbHk8lStMYKL3RfpxbGGqvjiXWL75XKh1nm1lFjZ31 6FlZCqJP8YchCbB+ix+p9usvoF+ogSr9VPFxnerz1oOYiTITRNfhZ0BabFlIOQ1kwLX/ fy12leWYr1xLBvCAoArF+FivXDhj/g5cWlWxx5J9v8fueZXb0XhIb7XtllhgsQxwpIC9 vFcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kdXorqci; 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 g7sor259074pgf.13.2018.02.08.16.40.16 for (Google Transport Security); Thu, 08 Feb 2018 16:40:16 -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=kdXorqci; 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; bh=8vMTrYyKQYG9zOnyuQfKa48l3j82y7rnJUoefx5qM4k=; b=kdXorqciK2//cvltgCMHXdsP8ZNgC0JosDmfOtk66JcjhnFAzOKcvDvg12v6zlQ2Zk oJGfoa24+J/vX6elJJ9468y48EbbX2gMrZYOpLcXYU17cmo+0AFlsG3aIXgV3ALUtNKZ kyPJWd28z5h0+ix7b+yJ4P8h0WkN+kwyl3mUs= 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; bh=8vMTrYyKQYG9zOnyuQfKa48l3j82y7rnJUoefx5qM4k=; b=dtGaBjfe6d1DU4FIKoH/gtfwJFVSReqnYuryv7K3vbvCA8qOt4hFVHgPgovs0pMrny ky+GNqpEE3c7YLwVV2aVAwOOsBMT1Bjd3EDEBStZbWPFwVQo/CARzV5uFe1gV5EHQar+ 554K1BlctCc4BpgNXtMZrdwaTmKscdx8GWAk1PliXKMuULFK7YZ2nyuWt5USovZ1H+Ul xsJbem1QrPFHIINuS/P9v5jSrkBjbZyrUHSq98cbAfwQZTF5rYj2GWJNGYmiCEbOSRFu v+iWyWCGnzcvd+6i2WoTOe8M3Ie7Hpddwc/+SmGKjJEID1UuAPIrdA4GeznCsSloo6DI xqvg== X-Gm-Message-State: APf1xPD8bjW2WKNu/v4FOqGslr3g7T46JoblAhyadDLU/LBynGr2wi5X ck5ohtyOFQLSUY0Q4AE937QSX3up X-Google-Smtp-Source: AH8x225AZ3Zmh8GtKhRcy++ZZAqNtPNoC82T+OtkNYS2S9VrQ0lFboY8BS55rZE8UXWohjLEB+pOqA== X-Received: by 10.101.81.68 with SMTP id g4mr796349pgq.276.1518136816349; Thu, 08 Feb 2018 16:40:16 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id s5sm6859716pfg.29.2018.02.08.16.40.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Feb 2018 16:40:15 -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 Subject: [RFC][PATCH v3] drm_hwcomposer: Add platformhisi buffer importer for hikey and hikey960 Date: Thu, 8 Feb 2018 16:40:05 -0800 Message-Id: <1518136805-2341-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 This allows for importing buffers allocated from the hikey and hikey960 gralloc implelementations. Feedback or comments would be greatly appreciated! Cc: Marissa Wall Cc: Sean Paul Cc: Dmitry Shmidt Cc: Robert Foss Cc: Matt Szczesiak Cc: Liviu Dudau Cc: David Hanna Cc: Rob Herring Change-Id: I81abdd4d1dc7d9f2ef31078c91679b532d3262fd Signed-off-by: John Stultz --- The full patchset I'm testing with can be found here: https://github.com/johnstultz-work/drm_hwcomposer/commits/drm_hwc 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) --- Android.mk | 13 +++++ platformdrmgeneric.h | 2 +- platformhisi.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++ platformhisi.h | 48 +++++++++++++++++++ 4 files changed, 194 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..5f17c20 --- /dev/null +++ b/platformhisi.cpp @@ -0,0 +1,132 @@ +/* + * 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 { + +#ifdef USE_HISI_IMPORTER +// static +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; +} +#endif + +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 attr[] = { + EGL_WIDTH, hnd->width, + EGL_HEIGHT, hnd->height, + EGL_LINUX_DRM_FOURCC_EXT, (EGLint)DrmGenericImporter::ConvertHalFormatToDrm(hnd->req_format), + 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; + } + + memset(bo, 0, sizeof(hwc_drm_bo_t)); + bo->width = hnd->width; + bo->height = hnd->height; + bo->format = DrmGenericImporter::ConvertHalFormatToDrm(hnd->req_format); + 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; +} + +#ifdef USE_HISI_IMPORTER +std::unique_ptr Planner::CreateInstance(DrmResources *) { + std::unique_ptr planner(new Planner); + planner->AddStage(); + return planner; +} +#endif + +} + + 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