summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Stratiienko <roman.stratiienko@globallogic.com>2019-10-17 17:42:36 +0300
committerRoman Stratiienko <roman.stratiienko@globallogic.com>2019-11-11 15:59:16 +0200
commite3ed48d728aad123f0c460f8fc087297a98e0c08 (patch)
treea34559bd0ca4dd9f34259f13c70019626390b786
parentf63726cabf3f1c940230e7b96fd514fca6dfb906 (diff)
drm_hwcomposer: Add Imagination platform support
External Android.bp file should be created in order to build this module: ``` cc_library_shared { name: "hwcomposer.drm_imagination", defaults: ["hwcomposer.drm_defaults"], srcs: [":drm_hwcomposer_platformimagination"], whole_static_libs: ["drm_hwcomposer"], shared_libs: ["libion"], include_dirs: [ "path/to/imgtec/include/files", ], } ``` libion is needed to make ion.h header visible `linux/ion.h`. Signed-off-by: Roman Stratiienko <roman.stratiienko@globallogic.com>
-rw-r--r--Android.bp9
-rw-r--r--platform/platformimagination.cpp81
-rw-r--r--platform/platformimagination.h22
3 files changed, 112 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp
index 5681cb7..85be0b5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -110,6 +110,15 @@ cc_library_shared {
include_dirs: ["external/minigbm/cros_gralloc"],
}
+// Used by hwcomposer.drm_imagination
+filegroup {
+ name: "drm_hwcomposer_platformimagination",
+ srcs: [
+ "platform/platformdrmgeneric.cpp",
+ "platform/platformimagination.cpp",
+ ],
+}
+
// Used by hwcomposer.drm_hikey and hwcomposer.drm_hikey960
filegroup {
name: "drm_hwcomposer_platformhisi",
diff --git a/platform/platformimagination.cpp b/platform/platformimagination.cpp
new file mode 100644
index 0000000..b94ca0b
--- /dev/null
+++ b/platform/platformimagination.cpp
@@ -0,0 +1,81 @@
+#define LOG_TAG "hwc-platform-imagination"
+
+#include "platformimagination.h"
+#include <drm/drm_fourcc.h>
+#include <log/log.h>
+#include <xf86drm.h>
+
+#include "img_gralloc1_public.h"
+
+namespace android {
+
+Importer *Importer::CreateInstance(DrmDevice *drm) {
+ ImaginationImporter *importer = new ImaginationImporter(drm);
+ if (!importer)
+ return NULL;
+
+ int ret = importer->Init();
+ if (ret) {
+ ALOGE("Failed to initialize the Imagination importer %d", ret);
+ delete importer;
+ return NULL;
+ }
+ return importer;
+}
+
+int ImaginationImporter::ImportBuffer(buffer_handle_t handle,
+ hwc_drm_bo_t *bo) {
+ IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle;
+ if (!hnd)
+ return -EINVAL;
+
+ uint32_t gem_handle;
+ int ret = drmPrimeFDToHandle(drm_->fd(), hnd->fd[0], &gem_handle);
+ if (ret) {
+ ALOGE("failed to import prime fd %d ret=%d", hnd->fd[0], ret);
+ return ret;
+ }
+
+ /* Extra bits are responsible for buffer compression and memory layout */
+ if (hnd->iFormat & ~0x10f) {
+ ALOGE("Special buffer formats are not supported");
+ return -EINVAL;
+ }
+
+ memset(bo, 0, sizeof(hwc_drm_bo_t));
+ bo->width = hnd->iWidth;
+ bo->height = hnd->iHeight;
+ bo->usage = hnd->usage;
+ bo->gem_handles[0] = gem_handle;
+ bo->pitches[0] = ALIGN(hnd->iWidth, HW_ALIGN) * hnd->uiBpp >> 3;
+
+ switch (hnd->iFormat) {
+#ifdef HAL_PIXEL_FORMAT_BGRX_8888
+ case HAL_PIXEL_FORMAT_BGRX_8888:
+ bo->format = DRM_FORMAT_XRGB8888;
+ break;
+#endif
+ default:
+ bo->format = ConvertHalFormatToDrm(hnd->iFormat & 0xf);
+ if (bo->format == DRM_FORMAT_INVALID) {
+ ALOGE("Cannot convert hal format to drm format %u", hnd->iFormat);
+ return -EINVAL;
+ }
+ }
+
+ 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 ret: %d", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
+ std::unique_ptr<Planner> planner(new Planner);
+ planner->AddStage<PlanStageGreedy>();
+ return planner;
+}
+} // namespace android
diff --git a/platform/platformimagination.h b/platform/platformimagination.h
new file mode 100644
index 0000000..85dfc45
--- /dev/null
+++ b/platform/platformimagination.h
@@ -0,0 +1,22 @@
+#ifndef PLATFORMIMAGINATION_H
+#define PLATFORMIMAGINATION_H
+
+#include "drmdevice.h"
+#include "platform.h"
+#include "platformdrmgeneric.h"
+
+#include <stdatomic.h>
+
+#include <hardware/gralloc.h>
+
+namespace android {
+
+class ImaginationImporter : public DrmGenericImporter {
+ public:
+ using DrmGenericImporter::DrmGenericImporter;
+
+ int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
+};
+} // namespace android
+
+#endif // PLATFORMIMAGINATION_H