aboutsummaryrefslogtreecommitdiff
path: root/drm
diff options
context:
space:
mode:
authorRoman Stratiienko <roman.o.stratiienko@globallogic.com>2021-10-25 22:54:20 +0300
committerRoman Stratiienko <roman.o.stratiienko@globallogic.com>2021-11-10 19:30:24 +0200
commit1e053b4e1913beeddc74b423cbd3a753192822c0 (patch)
tree0574a41802b58be8de9a050a507c55383ce22674 /drm
parent2a1f1ae02d31dcb0ca39de2da103539cb7e4aae7 (diff)
downloaddrm_hwcomposer-1e053b4e1913beeddc74b423cbd3a753192822c0.tar.gz
drm_hwcomposer: Make uevent listener standalone
1. DRM event listener doesn't work in this conditions, uevent blocks the thread and non-blocking select() doesn't make any sense. Remove DRM event handling for now. 2. UEvent listeren is common for all DrmDevices, therefore put it into ResourceManager class. Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Diffstat (limited to 'drm')
-rw-r--r--drm/DrmDevice.cpp16
-rw-r--r--drm/DrmDevice.h8
-rw-r--r--drm/ResourceManager.cpp6
-rw-r--r--drm/ResourceManager.h11
-rw-r--r--drm/UEventListener.cpp (renamed from drm/DrmEventListener.cpp)68
-rw-r--r--drm/UEventListener.h (renamed from drm/DrmEventListener.h)39
6 files changed, 39 insertions, 109 deletions
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index 1753ddc..0f5f581 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -111,15 +111,11 @@ static std::vector<DrmConnector *> make_primary_display_candidates(
return primary_candidates;
}
-DrmDevice::DrmDevice() : event_listener_(this) {
+DrmDevice::DrmDevice() {
self.reset(this);
mDrmFbImporter = std::make_unique<DrmFbImporter>(self);
}
-DrmDevice::~DrmDevice() {
- event_listener_.Exit();
-}
-
std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) {
/* TODO: Use drmOpenControl here instead */
fd_ = UniqueFd(open(path, O_RDWR | O_CLOEXEC));
@@ -326,12 +322,6 @@ std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) {
if (ret)
return std::make_tuple(ret, 0);
- ret = event_listener_.Init();
- if (ret) {
- ALOGE("Can't initialize event listener %d", ret);
- return std::make_tuple(ret, 0);
- }
-
for (auto &conn : connectors_) {
ret = CreateDisplayPipe(conn.get());
if (ret) {
@@ -526,10 +516,6 @@ auto DrmDevice::RegisterUserPropertyBlob(void *data, size_t length) const
});
}
-DrmEventListener *DrmDevice::event_listener() {
- return &event_listener_;
-}
-
int DrmDevice::GetProperty(uint32_t obj_id, uint32_t obj_type,
const char *prop_name, DrmProperty *property) const {
drmModeObjectPropertiesPtr props = nullptr;
diff --git a/drm/DrmDevice.h b/drm/DrmDevice.h
index 81c60cd..c08c766 100644
--- a/drm/DrmDevice.h
+++ b/drm/DrmDevice.h
@@ -25,7 +25,6 @@
#include "DrmConnector.h"
#include "DrmCrtc.h"
#include "DrmEncoder.h"
-#include "DrmEventListener.h"
#include "DrmFbImporter.h"
#include "DrmPlane.h"
#include "utils/UniqueFd.h"
@@ -38,7 +37,7 @@ class DrmPlane;
class DrmDevice {
public:
DrmDevice();
- ~DrmDevice();
+ ~DrmDevice() = default;
std::tuple<int, int> Init(const char *path, int num_displays);
@@ -67,7 +66,6 @@ class DrmDevice {
DrmConnector *AvailableWritebackConnector(int display) const;
DrmCrtc *GetCrtcForDisplay(int display) const;
DrmPlane *GetPlane(uint32_t id) const;
- DrmEventListener *event_listener();
int GetCrtcProperty(const DrmCrtc &crtc, const char *prop_name,
DrmProperty *property) const;
@@ -83,9 +81,6 @@ class DrmDevice {
-> DrmModeUserPropertyBlobUnique;
bool HandlesDisplay(int display) const;
- void RegisterHotplugHandler(DrmEventHandler *handler) {
- event_listener_.RegisterHotplugHandler(handler);
- }
bool HasAddFb2ModifiersSupport() const {
return HasAddFb2ModifiersSupport_;
@@ -114,7 +109,6 @@ class DrmDevice {
std::vector<std::unique_ptr<DrmEncoder>> encoders_;
std::vector<std::unique_ptr<DrmCrtc>> crtcs_;
std::vector<std::unique_ptr<DrmPlane>> planes_;
- DrmEventListener event_listener_;
std::pair<uint32_t, uint32_t> min_resolution_;
std::pair<uint32_t, uint32_t> max_resolution_;
diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp
index c55d6b8..8baa4cb 100644
--- a/drm/ResourceManager.cpp
+++ b/drm/ResourceManager.cpp
@@ -70,6 +70,12 @@ int ResourceManager::Init() {
return -EINVAL;
}
+ ret = uevent_listener_.Init();
+ if (ret) {
+ ALOGE("Can't initialize event listener %d", ret);
+ return ret;
+ }
+
return 0;
}
diff --git a/drm/ResourceManager.h b/drm/ResourceManager.h
index d9e0712..5ffe92c 100644
--- a/drm/ResourceManager.h
+++ b/drm/ResourceManager.h
@@ -20,6 +20,7 @@
#include <string.h>
#include "DrmDevice.h"
+#include "UEventListener.h"
#include "DrmFbImporter.h"
namespace android {
@@ -29,6 +30,10 @@ class ResourceManager {
ResourceManager();
ResourceManager(const ResourceManager &) = delete;
ResourceManager &operator=(const ResourceManager &) = delete;
+ ~ResourceManager() {
+ uevent_listener_.Exit();
+ }
+
int Init();
DrmDevice *GetDrmDevice(int display);
const std::vector<std::unique_ptr<DrmDevice>> &getDrmDevices() const {
@@ -41,6 +46,10 @@ class ResourceManager {
return scale_with_gpu_;
}
+ UEventListener *GetUEventListener() {
+ return &uevent_listener_;
+ }
+
private:
int AddDrmDevice(std::string const &path);
@@ -48,6 +57,8 @@ class ResourceManager {
std::vector<std::unique_ptr<DrmDevice>> drms_;
bool scale_with_gpu_{};
+
+ UEventListener uevent_listener_;
};
} // namespace android
diff --git a/drm/DrmEventListener.cpp b/drm/UEventListener.cpp
index 53e7032..eae0608 100644
--- a/drm/DrmEventListener.cpp
+++ b/drm/UEventListener.cpp
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#define LOG_TAG "hwc-drm-event-listener"
+#define LOG_TAG "hwc-uevent-listener"
-#include "DrmEventListener.h"
+#include "UEventListener.h"
#include <linux/netlink.h>
#include <sys/socket.h>
@@ -26,7 +26,6 @@
#include <cerrno>
#include <cstring>
-#include "DrmDevice.h"
#include "utils/log.h"
/* Originally defined in system/core/libsystem/include/system/graphics.h */
@@ -34,11 +33,10 @@
namespace android {
-DrmEventListener::DrmEventListener(DrmDevice *drm)
- : Worker("drm-event-listener", HAL_PRIORITY_URGENT_DISPLAY), drm_(drm) {
-}
+UEventListener::UEventListener()
+ : Worker("uevent-listener", HAL_PRIORITY_URGENT_DISPLAY){};
-int DrmEventListener::Init() {
+int UEventListener::Init() {
uevent_fd_ = UniqueFd(
socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT));
if (!uevent_fd_) {
@@ -57,44 +55,13 @@ int DrmEventListener::Init() {
return -errno;
}
- // NOLINTNEXTLINE(readability-isolate-declaration)
- FD_ZERO(&fds_);
- FD_SET(drm_->fd(), &fds_);
- FD_SET(uevent_fd_.Get(), &fds_);
- max_fd_ = std::max(drm_->fd(), uevent_fd_.Get());
-
return InitWorker();
}
-void DrmEventListener::RegisterHotplugHandler(DrmEventHandler *handler) {
- assert(!hotplug_handler_);
- hotplug_handler_.reset(handler);
-}
-
-void DrmEventListener::FlipHandler(int /* fd */, unsigned int /* sequence */,
- unsigned int tv_sec, unsigned int tv_usec,
- void *user_data) {
- auto *handler = (DrmEventHandler *)user_data;
- if (!handler)
- return;
-
- handler->HandleEvent((uint64_t)tv_sec * 1000 * 1000 + tv_usec);
- delete handler; // NOLINT(cppcoreguidelines-owning-memory)
-}
-
-void DrmEventListener::UEventHandler() {
+void UEventListener::Routine() {
char buffer[1024];
ssize_t ret = 0;
- struct timespec ts {};
-
- uint64_t timestamp = 0;
- ret = clock_gettime(CLOCK_MONOTONIC, &ts);
- if (!ret)
- timestamp = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
- else
- ALOGE("Failed to get monotonic clock on hotplug %zd", ret);
-
while (true) {
ret = read(uevent_fd_.Get(), &buffer, sizeof(buffer));
if (ret == 0)
@@ -120,26 +87,9 @@ void DrmEventListener::UEventHandler() {
i += strlen(event) + 1;
}
- if (drm_event && hotplug_event)
- hotplug_handler_->HandleEvent(timestamp);
- }
-}
-
-void DrmEventListener::Routine() {
- int ret = 0;
- do {
- ret = select(max_fd_ + 1, &fds_, nullptr, nullptr, nullptr);
- } while (ret == -1 && errno == EINTR);
-
- if (FD_ISSET(drm_->fd(), &fds_)) {
- drmEventContext event_context =
- {.version = 2,
- .vblank_handler = nullptr,
- .page_flip_handler = DrmEventListener::FlipHandler};
- drmHandleEvent(drm_->fd(), &event_context);
+ if (drm_event && hotplug_event && hotplug_handler_) {
+ hotplug_handler_();
+ }
}
-
- if (FD_ISSET(uevent_fd_.Get(), &fds_))
- UEventHandler();
}
} // namespace android
diff --git a/drm/DrmEventListener.h b/drm/UEventListener.h
index f1f7310..048eb40 100644
--- a/drm/DrmEventListener.h
+++ b/drm/UEventListener.h
@@ -14,51 +14,34 @@
* limitations under the License.
*/
-#ifndef ANDROID_DRM_EVENT_LISTENER_H_
-#define ANDROID_DRM_EVENT_LISTENER_H_
+#ifndef ANDROID_UEVENT_LISTENER_H_
+#define ANDROID_UEVENT_LISTENER_H_
+
+#include <functional>
#include "utils/UniqueFd.h"
#include "utils/Worker.h"
namespace android {
-class DrmDevice;
-
-class DrmEventHandler {
- public:
- DrmEventHandler() {
- }
- virtual ~DrmEventHandler() {
- }
-
- virtual void HandleEvent(uint64_t timestamp_us) = 0;
-};
-
-class DrmEventListener : public Worker {
+class UEventListener : public Worker {
public:
- DrmEventListener(DrmDevice *drm);
- virtual ~DrmEventListener() {
- }
+ UEventListener();
+ virtual ~UEventListener() = default;
int Init();
- void RegisterHotplugHandler(DrmEventHandler *handler);
-
- static void FlipHandler(int fd, unsigned int sequence, unsigned int tv_sec,
- unsigned int tv_usec, void *user_data);
+ void RegisterHotplugHandler(std::function<void()> hotplug_handler) {
+ hotplug_handler_ = hotplug_handler;
+ }
protected:
virtual void Routine();
private:
- void UEventHandler();
-
- fd_set fds_{};
UniqueFd uevent_fd_;
- int max_fd_ = -1;
- DrmDevice *drm_;
- std::unique_ptr<DrmEventHandler> hotplug_handler_;
+ std::function<void()> hotplug_handler_;
};
} // namespace android