[PATCH hwc v2 04/18] drm_hwcomposer: Add resource manager class

Alexandru Gheorghe alexandru-cosmin.gheorghe at arm.com
Wed Apr 11 15:22:15 UTC 2018


Add a resource manager object that is responsible for detecting all
kms devices and allocates unique display numbers for every detected
display.

This is controlled by the value of hwc.drm.device property, if it ends
with a %, it will try to open minor devices until and error is detected.
E.g: /dev/dri/card%

Additionally, this will be used for finding an available writeback
connector that will be used for the flattening of the currently
displayed scene.

Signed-off-by: Alexandru Gheorghe <alexandru-cosmin.gheorghe at arm.com>
---
 Android.mk          |  1 +
 resourcemanager.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 resourcemanager.h   | 29 ++++++++++++++++++++++
 3 files changed, 101 insertions(+)
 create mode 100644 resourcemanager.cpp
 create mode 100644 resourcemanager.h

diff --git a/Android.mk b/Android.mk
index 1add286..736fe24 100644
--- a/Android.mk
+++ b/Android.mk
@@ -52,6 +52,7 @@ LOCAL_C_INCLUDES := \
 
 LOCAL_SRC_FILES := \
 	autolock.cpp \
+	resourcemanager.cpp \
 	drmresources.cpp \
 	drmconnector.cpp \
 	drmcrtc.cpp \
diff --git a/resourcemanager.cpp b/resourcemanager.cpp
new file mode 100644
index 0000000..e7b654e
--- /dev/null
+++ b/resourcemanager.cpp
@@ -0,0 +1,71 @@
+#include "resourcemanager.h"
+#include <cutils/log.h>
+#include <cutils/properties.h>
+
+namespace android {
+
+ResourceManager::ResourceManager() : gralloc_(NULL) {
+}
+
+int ResourceManager::Init() {
+  char path_pattern[PROPERTY_VALUE_MAX];
+  property_get("hwc.drm.device", path_pattern, "/dev/dri/card%");
+
+  uint8_t minor = 0;
+  int last_display_index = 0;
+  int last_char = strlen(path_pattern) - 1;
+  do {
+    char path[PROPERTY_VALUE_MAX];
+    if (path_pattern[last_char] == '%') {
+      path_pattern[last_char] = '\0';
+      snprintf(path, PROPERTY_VALUE_MAX, "%s%d", path_pattern, minor);
+      path_pattern[last_char] = '%';
+    } else {
+      snprintf(path, PROPERTY_VALUE_MAX, "%s", path_pattern);
+    }
+    std::unique_ptr<DrmResources> drm = std::make_unique<DrmResources>();
+    last_display_index = drm->Init(this, path, last_display_index);
+    if (last_display_index < 0) {
+      break;
+    }
+    std::shared_ptr<Importer> importer;
+    importer.reset(Importer::CreateInstance(drm.get()));
+    if (!importer) {
+      ALOGE("Failed to create importer instance");
+      break;
+    }
+    importers_.push_back(importer);
+    drms_.push_back(std::move(drm));
+    minor++;
+    last_display_index++;
+  } while (path_pattern[last_char] == '%');
+
+  if (!drms_.size()) {
+    ALOGE("Failed to find any working drm device");
+    return -EINVAL;
+  }
+
+  return hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
+                       (const hw_module_t **)&gralloc_);
+}
+
+DrmResources *ResourceManager::GetDrmResources(int display) {
+  for (uint32_t i = 0; i < drms_.size(); i++) {
+    if (drms_[i]->HandlesDisplay(display))
+      return drms_[i].get();
+  }
+  return NULL;
+}
+
+std::shared_ptr<Importer> ResourceManager::GetImporter(int display) {
+  for (uint32_t i = 0; i < drms_.size(); i++) {
+    if (drms_[i]->HandlesDisplay(display))
+      return importers_[i];
+  }
+  return NULL;
+}
+
+const gralloc_module_t *ResourceManager::GetGralloc() {
+  return gralloc_;
+}
+}
diff --git a/resourcemanager.h b/resourcemanager.h
new file mode 100644
index 0000000..b8caa9a
--- /dev/null
+++ b/resourcemanager.h
@@ -0,0 +1,29 @@
+#ifndef RESOURCEMANAGER_H
+#define RESOURCEMANAGER_H
+
+#include "drmresources.h"
+#include "platform.h"
+
+namespace android {
+
+class DrmResources;
+class Importer;
+
+class ResourceManager {
+ public:
+  ResourceManager();
+  ResourceManager(const ResourceManager &) = delete;
+  ResourceManager &operator=(const ResourceManager &) = delete;
+  int Init();
+  DrmResources *GetDrmResources(int display);
+  std::shared_ptr<Importer> GetImporter(int display);
+  const gralloc_module_t *GetGralloc();
+
+ private:
+  std::vector<std::unique_ptr<DrmResources>> drms_;
+  std::vector<std::shared_ptr<Importer>> importers_;
+  const gralloc_module_t *gralloc_;
+};
+}
+
+#endif  // RESOURCEMANAGER_H
-- 
2.7.4



More information about the dri-devel mailing list