aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Stratiienko <roman.o.stratiienko@globallogic.com>2022-05-03 18:31:13 +0300
committerRoman Stratiienko <roman.o.stratiienko@globallogic.com>2022-05-09 18:19:45 +0300
commit5f21dbc6f381d54b483a904799d850f6f9571a8e (patch)
tree661ce6fe5fe796c35b8b8e716ae1031e2e6009b4
parentcf80b9b1586c7344c1b9955a4c1a83028efb89e3 (diff)
downloaddrm_hwcomposer-5f21dbc6f381d54b483a904799d850f6f9571a8e.tar.gz
drm_hwcomposer: Allow accessing ResourceManager from DrmDevce
This is useful for accessing the main lock from drm / compositor related code blocks. Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
-rw-r--r--drm/DrmDevice.cpp19
-rw-r--r--drm/DrmDevice.h18
-rw-r--r--drm/ResourceManager.cpp17
-rw-r--r--drm/ResourceManager.h1
4 files changed, 39 insertions, 16 deletions
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index fd4589e..5e160d4 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -28,12 +28,29 @@
#include "drm/DrmAtomicStateManager.h"
#include "drm/DrmPlane.h"
+#include "drm/ResourceManager.h"
#include "utils/log.h"
#include "utils/properties.h"
namespace android {
-DrmDevice::DrmDevice() {
+auto DrmDevice::CreateInstance(std::string const &path,
+ ResourceManager *res_man)
+ -> std::unique_ptr<DrmDevice> {
+ if (!IsKMSDev(path.c_str())) {
+ return {};
+ }
+
+ auto device = std::unique_ptr<DrmDevice>(new DrmDevice(res_man));
+
+ if (device->Init(path.c_str()) != 0) {
+ return {};
+ }
+
+ return device;
+}
+
+DrmDevice::DrmDevice(ResourceManager *res_man) : res_man_(res_man) {
drm_fb_importer_ = std::make_unique<DrmFbImporter>(*this);
}
diff --git a/drm/DrmDevice.h b/drm/DrmDevice.h
index f2530ee..4cf0132 100644
--- a/drm/DrmDevice.h
+++ b/drm/DrmDevice.h
@@ -31,18 +31,23 @@ namespace android {
class DrmFbImporter;
class DrmPlane;
+class ResourceManager;
class DrmDevice {
public:
- DrmDevice();
~DrmDevice() = default;
- auto Init(const char *path) -> int;
+ static auto CreateInstance(std::string const &path, ResourceManager *res_man)
+ -> std::unique_ptr<DrmDevice>;
auto GetFd() const {
return fd_.Get();
}
+ auto &GetResMan() {
+ return *res_man_;
+ }
+
auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &;
auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &;
auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &;
@@ -69,8 +74,6 @@ class DrmDevice {
return *drm_fb_importer_;
}
- static auto IsKMSDev(const char *path) -> bool;
-
auto FindCrtcById(uint32_t id) const -> DrmCrtc * {
for (const auto &crtc : crtcs_) {
if (crtc->GetId() == id) {
@@ -95,6 +98,11 @@ class DrmDevice {
DrmProperty *property) const;
private:
+ explicit DrmDevice(ResourceManager *res_man);
+ auto Init(const char *path) -> int;
+
+ static auto IsKMSDev(const char *path) -> bool;
+
UniqueFd fd_;
std::vector<std::unique_ptr<DrmConnector>> connectors_;
@@ -109,6 +117,8 @@ class DrmDevice {
bool HasAddFb2ModifiersSupport_{};
std::unique_ptr<DrmFbImporter> drm_fb_importer_;
+
+ ResourceManager *const res_man_;
};
} // namespace android
diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp
index ddf59dd..53e98dc 100644
--- a/drm/ResourceManager.cpp
+++ b/drm/ResourceManager.cpp
@@ -58,7 +58,10 @@ void ResourceManager::Init() {
int path_len = property_get("vendor.hwc.drm.device", path_pattern,
"/dev/dri/card%");
if (path_pattern[path_len - 1] != '%') {
- AddDrmDevice(std::string(path_pattern));
+ auto dev = DrmDevice::CreateInstance(path_pattern, this);
+ if (dev) {
+ drms_.emplace_back(std::move(dev));
+ }
} else {
path_pattern[path_len - 1] = '\0';
for (int idx = 0;; ++idx) {
@@ -69,8 +72,9 @@ void ResourceManager::Init() {
if (stat(path.str().c_str(), &buf) != 0)
break;
- if (DrmDevice::IsKMSDev(path.str().c_str())) {
- AddDrmDevice(path.str());
+ auto dev = DrmDevice::CreateInstance(path.str(), this);
+ if (dev) {
+ drms_.emplace_back(std::move(dev));
}
}
}
@@ -108,13 +112,6 @@ void ResourceManager::DeInit() {
initialized_ = false;
}
-int ResourceManager::AddDrmDevice(const std::string &path) {
- auto drm = std::make_unique<DrmDevice>();
- int ret = drm->Init(path.c_str());
- drms_.push_back(std::move(drm));
- return ret;
-}
-
auto ResourceManager::GetTimeMonotonicNs() -> int64_t {
struct timespec ts {};
clock_gettime(CLOCK_MONOTONIC, &ts);
diff --git a/drm/ResourceManager.h b/drm/ResourceManager.h
index 88ba878..144d00e 100644
--- a/drm/ResourceManager.h
+++ b/drm/ResourceManager.h
@@ -59,7 +59,6 @@ class ResourceManager {
static auto GetTimeMonotonicNs() -> int64_t;
private:
- auto AddDrmDevice(std::string const &path) -> int;
auto GetOrderedConnectors() -> std::vector<DrmConnector *>;
void UpdateFrontendDisplays();
void DetachAllFrontendDisplays();