summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Foss <robert.foss@collabora.com>2017-02-20 17:37:37 -0500
committerRobert Foss <robert.foss@collabora.com>2017-03-24 18:32:42 -0400
commit1498f452480378c17ec5ec6a4abc4f0f26edfa66 (patch)
treef3fa5fc263b48ce9303106707f69d7bc431308e7
parent52e0d7a9c6dfb651993af4cb9a8ca4a9a4722be2 (diff)
downloaddrm_hwcomposer-1498f452480378c17ec5ec6a4abc4f0f26edfa66.tar.gz
drm_hwcomposer-1498f452480378c17ec5ec6a4abc4f0f26edfa66.tar.xz
drm_hwcomposer: Add support for VBlankHandler to DrmEventListener
VBlankHandler is being introduced as an alternative to VSync callbacks, since the atomic API supports it better using the DRM_VBLANK_EVENT flag. BUG=None TEST=make Change-Id: Ib7e0cdbb576c10f00b587e618e973a037063f018 Signed-off-by: Robert Foss <robert.foss@collabora.com>
-rw-r--r--drmeventlistener.cpp60
-rw-r--r--drmeventlistener.h14
-rw-r--r--vsyncworker.h7
3 files changed, 59 insertions, 22 deletions
diff --git a/drmeventlistener.cpp b/drmeventlistener.cpp
index 049ace2..bc9d090 100644
--- a/drmeventlistener.cpp
+++ b/drmeventlistener.cpp
@@ -63,20 +63,48 @@ int DrmEventListener::Init() {
return InitWorker();
}
-void DrmEventListener::RegisterHotplugHandler(DrmEventHandler *handler) {
+void DrmEventListener::RegisterHotplugHandler(std::shared_ptr<DrmEventHandler> handler) {
assert(!hotplug_handler_);
hotplug_handler_ = handler;
}
-void DrmEventListener::FlipHandler(int /* fd */, unsigned int /* sequence */,
- unsigned int tv_sec, unsigned int tv_usec,
- void *user_data) {
- DrmEventHandler *handler = (DrmEventHandler *)user_data;
- if (!handler)
+void DrmEventListener::VBlankHandler(int /* fd */, unsigned int /* sequence */,
+ unsigned int tv_sec, unsigned int tv_usec,
+ void *user_data)
+{
+ DrmResources *drm = (DrmResources *) user_data;
+ DrmEventListener *event_listener;
+ uint64_t timestamp;
+
+ if (!drm)
+ return;
+
+ event_listener = drm->event_listener();
+ if (!event_listener)
+ return;
+
+ auto vblank_handler = event_listener->vblank_handler_;
+ if (!vblank_handler)
return;
- handler->HandleEvent((uint64_t)tv_sec * 1000 * 1000 + tv_usec);
- delete handler;
+ if (!vblank_handler->enabled)
+ return;
+
+ timestamp = (uint64_t)tv_sec * 1000 * 1000 * 1000 +
+ (uint64_t)tv_usec * 1000;
+ vblank_handler->HandleEvent(timestamp);
+}
+
+void DrmEventListener::RegisterVBlankHandler(std::shared_ptr<DrmEventHandler> handler) {
+ assert(!vblank_handler_);
+ vblank_handler_ = handler;
+}
+
+void DrmEventListener::SetVBlankHandlerEnabled(int32_t enabled) {
+ if (!vblank_handler_)
+ return;
+
+ vblank_handler_->enabled = enabled;
}
void DrmEventListener::UEventHandler() {
@@ -101,7 +129,7 @@ void DrmEventListener::UEventHandler() {
}
if (!hotplug_handler_)
- continue;
+ return;
bool drm_event = false, hotplug_event = false;
for (int i = 0; i < ret;) {
@@ -121,6 +149,16 @@ void DrmEventListener::UEventHandler() {
void DrmEventListener::Routine() {
int ret;
+
+ drmVBlank vbl = {
+ .request = {
+ .type = (drmVBlankSeqType) (DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT),
+ .sequence = 1,
+ .signal = (unsigned long) drm_
+ }
+ };
+ drmWaitVBlank(drm_->fd(), &vbl);
+
do {
ret = select(max_fd_ + 1, &fds_, NULL, NULL, NULL);
} while (ret == -1 && errno == EINTR);
@@ -128,8 +166,8 @@ void DrmEventListener::Routine() {
if (FD_ISSET(drm_->fd(), &fds_)) {
drmEventContext event_context = {
.version = DRM_EVENT_CONTEXT_VERSION,
- .vblank_handler = NULL,
- .page_flip_handler = DrmEventListener::FlipHandler};
+ .vblank_handler = DrmEventListener::VBlankHandler,
+ .page_flip_handler = NULL};
drmHandleEvent(drm_->fd(), &event_context);
}
diff --git a/drmeventlistener.h b/drmeventlistener.h
index b4a3344..597c803 100644
--- a/drmeventlistener.h
+++ b/drmeventlistener.h
@@ -26,7 +26,9 @@ class DrmResources;
class DrmEventHandler {
public:
+ bool enabled;
DrmEventHandler() {
+ enabled = false;
}
virtual ~DrmEventHandler() {
}
@@ -42,10 +44,12 @@ class DrmEventListener : public Worker {
int Init();
- void RegisterHotplugHandler(DrmEventHandler *handler);
+ void RegisterHotplugHandler(std::shared_ptr<DrmEventHandler> handler);
- static void FlipHandler(int fd, unsigned int sequence, unsigned int tv_sec,
- unsigned int tv_usec, void *user_data);
+ static void VBlankHandler(int fd, unsigned int sequence, unsigned int tv_sec,
+ unsigned int tv_usec, void *user_data);
+ void RegisterVBlankHandler(std::shared_ptr<DrmEventHandler> handler);
+ void SetVBlankHandlerEnabled(int32_t enabled);
protected:
void InitRoutine(){};
@@ -59,7 +63,9 @@ class DrmEventListener : public Worker {
int max_fd_ = -1;
DrmResources *drm_;
- DrmEventHandler *hotplug_handler_ = NULL;
+ std::shared_ptr<DrmEventHandler> hotplug_handler_ = NULL;
+ std::shared_ptr<DrmEventHandler> vblank_handler_ = NULL;
+
};
}
diff --git a/vsyncworker.h b/vsyncworker.h
index f629adc..fcff6cb 100644
--- a/vsyncworker.h
+++ b/vsyncworker.h
@@ -28,13 +28,6 @@
namespace android {
-class VsyncCallback {
- public:
- virtual ~VsyncCallback() {
- }
- virtual void Callback(int display, int64_t timestamp) = 0;
-};
-
class VSyncWorker : public Worker {
public:
VSyncWorker();