Android-x86
Fork

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-drm_hwcomposer: コミット

external/drm_hwcomposer


コミットメタ情報

リビジョン71edaca727572bdcc60c6c7e12cb7fb74dfd4947 (tree)
日時2018-05-03 23:48:56
作者Alistair Strachan <astrachan@goog...>
コミッターSean Paul

ログメッセージ

drm_hwcomposer: Add platform backend for minigbm

This adds support for the chromiumos (not AOSP) version of minigbm. Like
hisi, the gralloc handle is not the same as the common libdrm handle
(just yet), so we do need a separate backend for now.

Tested with a pending change to the 'cuttlefish' android virtual device
in AOSP with its custom gralloc switched to minigbm.

Cc: John Stultz <john.stultz@linaro.org>
Cc: Rob Herring <rob.herring@linaro.org>
Cc: Sean Paul <seanpaul@google.com>
Cc: Greg Hartman <ghartman@google.com>
Tested-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Alistair Strachan <astrachan@google.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>

変更サマリ

差分

--- a/Android.mk
+++ b/Android.mk
@@ -80,15 +80,16 @@ ifeq ($(TARGET_PRODUCT),hikey960)
8080 LOCAL_CPPFLAGS += -DUSE_HISI_IMPORTER
8181 LOCAL_SRC_FILES += platformhisi.cpp
8282 LOCAL_C_INCLUDES += device/linaro/hikey/gralloc960/
83-else
84-ifeq ($(TARGET_PRODUCT),hikey)
83+else ifeq ($(TARGET_PRODUCT),hikey)
8584 LOCAL_CPPFLAGS += -DUSE_HISI_IMPORTER
8685 LOCAL_SRC_FILES += platformhisi.cpp
8786 LOCAL_C_INCLUDES += device/linaro/hikey/gralloc/
87+else ifeq ($(strip $(BOARD_DRM_HWCOMPOSER_BUFFER_IMPORTER)),minigbm)
88+LOCAL_SRC_FILES += platformminigbm.cpp
89+LOCAL_C_INCLUDES += external/minigbm/cros_gralloc/
8890 else
8991 LOCAL_CPPFLAGS += -DUSE_DRM_GENERIC_IMPORTER
9092 endif
91-endif
9293
9394 LOCAL_MODULE := hwcomposer.drm
9495 LOCAL_MODULE_TAGS := optional
--- /dev/null
+++ b/platformminigbm.cpp
@@ -0,0 +1,122 @@
1+/*
2+ * Copyright (C) 2018 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-drm-minigbm"
18+
19+#include "drmresources.h"
20+#include "platform.h"
21+#include "platformminigbm.h"
22+
23+#include <drm/drm_fourcc.h>
24+#include <xf86drm.h>
25+#include <xf86drmMode.h>
26+
27+#include <log/log.h>
28+#include <hardware/gralloc.h>
29+
30+#include "cros_gralloc_handle.h"
31+
32+namespace android {
33+
34+Importer *Importer::CreateInstance(DrmResources *drm) {
35+ DrmMinigbmImporter *importer = new DrmMinigbmImporter(drm);
36+ if (!importer)
37+ return NULL;
38+
39+ int ret = importer->Init();
40+ if (ret) {
41+ ALOGE("Failed to initialize the minigbm importer %d", ret);
42+ delete importer;
43+ return NULL;
44+ }
45+ return importer;
46+}
47+
48+DrmMinigbmImporter::DrmMinigbmImporter(DrmResources *drm) : DrmGenericImporter(drm), drm_(drm) {
49+}
50+
51+DrmMinigbmImporter::~DrmMinigbmImporter() {
52+}
53+
54+int DrmMinigbmImporter::Init() {
55+ int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
56+ (const hw_module_t **)&gralloc_);
57+ if (ret) {
58+ ALOGE("Failed to open gralloc module %d", ret);
59+ return ret;
60+ }
61+
62+ if (strcasecmp(gralloc_->common.author, "Chrome OS"))
63+ ALOGW("Using non-minigbm gralloc module: %s/%s\n", gralloc_->common.name,
64+ gralloc_->common.author);
65+
66+ return 0;
67+}
68+
69+EGLImageKHR DrmMinigbmImporter::ImportImage(EGLDisplay egl_display, buffer_handle_t handle) {
70+ cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
71+ if (!gr_handle)
72+ return NULL;
73+ EGLint attr[] = {
74+ EGL_WIDTH, (EGLint)gr_handle->width,
75+ EGL_HEIGHT, (EGLint)gr_handle->height,
76+ EGL_LINUX_DRM_FOURCC_EXT, (EGLint)gr_handle->format,
77+ EGL_DMA_BUF_PLANE0_FD_EXT, gr_handle->fds[0],
78+ EGL_DMA_BUF_PLANE0_PITCH_EXT, (EGLint)gr_handle->strides[0],
79+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, (EGLint)gr_handle->offsets[0],
80+ EGL_NONE,
81+ };
82+ return eglCreateImageKHR(egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attr);
83+}
84+
85+int DrmMinigbmImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
86+ cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
87+ if (!gr_handle)
88+ return -EINVAL;
89+
90+ uint32_t gem_handle;
91+ int ret = drmPrimeFDToHandle(drm_->fd(), gr_handle->fds[0], &gem_handle);
92+ if (ret) {
93+ ALOGE("failed to import prime fd %d ret=%d", gr_handle->fds[0], ret);
94+ return ret;
95+ }
96+
97+ memset(bo, 0, sizeof(hwc_drm_bo_t));
98+ bo->width = gr_handle->width;
99+ bo->height = gr_handle->height;
100+ bo->format = gr_handle->format;
101+ bo->usage = gr_handle->usage;
102+ bo->pitches[0] = gr_handle->strides[0];
103+ bo->offsets[0] = gr_handle->offsets[0];
104+ bo->gem_handles[0] = gem_handle;
105+
106+ ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
107+ bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
108+ if (ret) {
109+ ALOGE("could not create drm fb %d", ret);
110+ return ret;
111+ }
112+
113+ return ret;
114+}
115+
116+std::unique_ptr<Planner> Planner::CreateInstance(DrmResources *) {
117+ std::unique_ptr<Planner> planner(new Planner);
118+ planner->AddStage<PlanStageGreedy>();
119+ return planner;
120+}
121+
122+}
--- /dev/null
+++ b/platformminigbm.h
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright (C) 2018 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+#ifndef ANDROID_PLATFORM_DRM_MINIGBM_H_
18+#define ANDROID_PLATFORM_DRM_MINIGBM_H_
19+
20+#include "drmresources.h"
21+#include "platform.h"
22+#include "platformdrmgeneric.h"
23+
24+#include <hardware/gralloc.h>
25+
26+namespace android {
27+
28+class DrmMinigbmImporter : public DrmGenericImporter {
29+ public:
30+ DrmMinigbmImporter(DrmResources *drm);
31+ ~DrmMinigbmImporter() override;
32+
33+ int Init();
34+
35+ EGLImageKHR ImportImage(EGLDisplay egl_display, buffer_handle_t handle) override;
36+ int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
37+
38+ private:
39+ DrmResources *drm_;
40+
41+ const gralloc_module_t *gralloc_;
42+};
43+
44+}
45+
46+#endif
旧リポジトリブラウザで表示