Merge "sdm: Fix multiple VBlank registration"

This commit is contained in:
Linux Build Service Account
2018-01-12 17:03:51 -08:00
committed by Gerrit - the friendly Code Review server
2 changed files with 23 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, The Linux Foundation. All rights reserved. * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@@ -182,7 +182,6 @@ DisplayError HWEventsDRM::Init(int display_type, HWEventHandler *event_handler,
static_cast<const HWDeviceDRM *>(hw_intf)->GetDRMDisplayToken(&token_); static_cast<const HWDeviceDRM *>(hw_intf)->GetDRMDisplayToken(&token_);
is_primary_ = static_cast<const HWDeviceDRM *>(hw_intf)->IsPrimaryDisplay(); is_primary_ = static_cast<const HWDeviceDRM *>(hw_intf)->IsPrimaryDisplay();
vsync_enabled_ = is_primary_;
DLOGI("Setup event handler for display %d, CRTC %d, Connector %d", DLOGI("Setup event handler for display %d, CRTC %d, Connector %d",
display_type, token_.crtc_id, token_.conn_id); display_type, token_.crtc_id, token_.conn_id);
@@ -198,6 +197,11 @@ DisplayError HWEventsDRM::Init(int display_type, HWEventHandler *event_handler,
return kErrorResources; return kErrorResources;
} }
if (is_primary_) {
RegisterVSync();
vsync_registered_ = true;
}
RegisterPanelDead(true); RegisterPanelDead(true);
RegisterIdleNotify(true); RegisterIdleNotify(true);
RegisterIdlePowerCollapse(true); RegisterIdlePowerCollapse(true);
@@ -220,15 +224,17 @@ DisplayError HWEventsDRM::Deinit() {
DisplayError HWEventsDRM::SetEventState(HWEvent event, bool enable, void *arg) { DisplayError HWEventsDRM::SetEventState(HWEvent event, bool enable, void *arg) {
switch (event) { switch (event) {
case HWEvent::VSYNC: case HWEvent::VSYNC: {
std::lock_guard<std::mutex> lock(vsync_mutex_);
if (!is_primary_) { if (!is_primary_) {
break; break;
} }
vsync_enabled_ = enable; vsync_enabled_ = enable;
if (enable) { if (vsync_enabled_ && !vsync_registered_) {
WakeUpEventThread(); RegisterVSync();
vsync_registered_ = true;
} }
break; } break;
default: default:
DLOGE("Event not supported"); DLOGE("Event not supported");
return kErrorNotSupported; return kErrorNotSupported;
@@ -295,11 +301,6 @@ void *HWEventsDRM::DisplayEventHandler() {
setpriority(PRIO_PROCESS, 0, kThreadPriorityUrgent); setpriority(PRIO_PROCESS, 0, kThreadPriorityUrgent);
while (!exit_threads_) { while (!exit_threads_) {
if (vsync_enabled_ && RegisterVSync() != kErrorNone) {
pthread_exit(0);
return nullptr;
}
int error = Sys::poll_(poll_fds_.data(), UINT32(poll_fds_.size()), -1); int error = Sys::poll_(poll_fds_.data(), UINT32(poll_fds_.size()), -1);
if (error <= 0) { if (error <= 0) {
DLOGW("poll failed. error = %s", strerror(errno)); DLOGW("poll failed. error = %s", strerror(errno));
@@ -469,6 +470,13 @@ void HWEventsDRM::HandleVSync(char *data) {
if (error != 0) { if (error != 0) {
DLOGE("drmHandleEvent failed: %i", error); DLOGE("drmHandleEvent failed: %i", error);
} }
std::lock_guard<std::mutex> lock(vsync_mutex_);
vsync_registered_ = false;
if (vsync_enabled_) {
RegisterVSync();
vsync_registered_ = true;
}
} }
void HWEventsDRM::HandlePanelDead(char *data) { void HWEventsDRM::HandlePanelDead(char *data) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, The Linux Foundation. All rights reserved. * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@@ -33,6 +33,7 @@
#include <drm_interface.h> #include <drm_interface.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <map> #include <map>
#include <mutex>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
@@ -94,6 +95,8 @@ class HWEventsDRM : public HWEventsInterface {
bool exit_threads_ = false; bool exit_threads_ = false;
uint32_t vsync_index_ = 0; uint32_t vsync_index_ = 0;
bool vsync_enabled_ = false; bool vsync_enabled_ = false;
bool vsync_registered_ = false;
std::mutex vsync_mutex_; // To protect vsync_enabled_ and vsync_registered_
uint32_t idle_notify_index_ = 0; uint32_t idle_notify_index_ = 0;
sde_drm::DRMDisplayToken token_ = {}; sde_drm::DRMDisplayToken token_ = {};
bool is_primary_ = false; bool is_primary_ = false;