Skip to content

Commit

Permalink
Merge branch 'upstream-ww22' into celadon-master
Browse files Browse the repository at this point in the history
  • Loading branch information
jennycao committed May 29, 2019
2 parents 84df689 + 3b59b47 commit a199ce0
Show file tree
Hide file tree
Showing 28 changed files with 729 additions and 66 deletions.
106 changes: 86 additions & 20 deletions common/core/gpudevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ GpuDevice::GpuDevice() : HWCThread(-8, "GpuDevice") {

GpuDevice::~GpuDevice() {
display_manager_.reset(nullptr);
HWCThread::Exit();

if (-1 != lock_fd_) {
close(lock_fd_);
lock_fd_ = -1;
}
}

void GpuDevice::ResetAllDisplayCommit(bool enable) {
if (enable == enable_all_display_)
return;
enable_all_display_ = enable;
size_t size = total_displays_.size();
for (size_t i = 0; i < size; i++)
total_displays_.at(i)->EnableDRMCommit(enable);
}

bool GpuDevice::Initialize() {
Expand Down Expand Up @@ -57,13 +72,18 @@ bool GpuDevice::Initialize() {
display_manager_->RemoveUnreservedPlanes();
}

lock_fd_ = open("/vendor/hwc.lock", O_RDONLY);
lock_fd_ = open(HWC_LOCK_FILE, O_RDONLY);
if (-1 != lock_fd_) {
if (!InitWorker()) {
ETRACE("Failed to initalize thread for GpuDevice. %s", PRINTERROR());
}
} else {
ITRACE("Failed to open " LOCK_DIR_PREFIX "/hwc.lock file!");
ETRACE("Failed to open %s", HWC_LOCK_FILE);
// HWC should become drm master and start to commit.
// if hwc.lock is not available
if (!display_manager_->IsDrmMasterByDefault())
display_manager_->setDrmMaster(true);
ResetAllDisplayCommit(true);
}

return true;
Expand Down Expand Up @@ -103,14 +123,42 @@ void GpuDevice::GetConnectedPhysicalDisplays(
}

bool GpuDevice::EnableDRMCommit(bool enable, uint32_t display_id) {
// TODO clean all display for commit status
size_t size = total_displays_.size();
bool ret = false;
if (size > display_id)
ret = total_displays_.at(display_id)->EnableDRMCommit(enable);
return ret;
}

bool GpuDevice::ResetDrmMaster(bool drop_master) {
bool ret = true;
if (drop_master) {
ResetAllDisplayCommit(false);
display_manager_->DropDrmMaster();
ITRACE("locking %s and monitoring if %s is unlocked.", HWC_LOCK_FILE,
HWC_LOCK_FILE);
// Resume GpuDevice thread to check hwc.lock and re-apply drm master.
lock_fd_ = open(HWC_LOCK_FILE, O_RDONLY);
if (-1 != lock_fd_) {
// Only resume GpuDevice thread for dropping DRM Master and
// the lock file exist.
Resume();
return !display_manager_->IsDrmMaster();
}
}
// In case of setDrmMaster or the lock file is not exist.
// Re-set DRM Master true.
display_manager_->setDrmMaster(false);
ResetAllDisplayCommit(true);
DisableWatch();

if (drop_master)
ret = !display_manager_->IsDrmMaster();
else
ret = display_manager_->IsDrmMaster();
return ret;
}

const std::vector<NativeDisplay *> &GpuDevice::GetAllDisplays() {
return total_displays_;
}
Expand Down Expand Up @@ -258,6 +306,7 @@ void GpuDevice::InitializePanorama(
panorama_sos_displays.at(0).at(sos_it));
virtualdisp->InitVirtualDisplay(1920, 1080);
i_available_panorama_displays.emplace_back(virtualdisp);
virtual_panorama_displays_.emplace_back(virtualdisp);
}

// Add the native displays
Expand All @@ -281,6 +330,8 @@ void GpuDevice::InitializePanorama(
// Skip the disconnected display here
i_available_panorama_displays.emplace_back(
temp_displays.at(panorama_displays.at(m).at(l)));
physical_panorama_displays_.emplace_back(
temp_displays.at(panorama_displays.at(m).at(l)));
// Add tag for panorama-ed displays
available_displays.at(panorama_displays.at(m).at(l)) = false;
}
Expand All @@ -297,14 +348,31 @@ void GpuDevice::InitializePanorama(
std::unique_ptr<MosaicDisplay> panorama(
new MosaicDisplay(i_available_panorama_displays));
panorama->SetPanoramaMode(true);
panorama->SetExtraDispInfo((int)panorama_displays.size(),
(int)panorama_sos_displays.size());
panorama->SetExtraDispInfo(&virtual_panorama_displays_,
&physical_panorama_displays_);
ptr_mosaicdisplay = (MosaicDisplay *)panorama.get();
panorama_displays_.emplace_back(std::move(panorama));
// Save the panorama to the final displays list
total_displays_.emplace_back(panorama_displays_.back().get());
}
}

bool GpuDevice::TriggerPanorama(uint32_t hotplug_simulation) {
bool ret = false;
if (ptr_mosaicdisplay) {
ret = ptr_mosaicdisplay->TriggerPanorama(hotplug_simulation);
}
return ret;
}

bool GpuDevice::ShutdownPanorama(uint32_t hotplug_simulation) {
bool ret = false;
if (ptr_mosaicdisplay) {
ret = ptr_mosaicdisplay->ShutdownPanorama(hotplug_simulation);
}
return ret;
}

#endif

void GpuDevice::ParseLogicalDisplaySetting(
Expand Down Expand Up @@ -967,8 +1035,6 @@ uint32_t GpuDevice::GetDisplayIDFromConnectorID(const uint32_t connector_id) {
}

void GpuDevice::HandleRoutine() {
bool update_ignored = false;

// Iniitialize resources to monitor external events.
// These can be two types:
// 1) We are showing splash screen and another App
Expand All @@ -978,23 +1044,20 @@ void GpuDevice::HandleRoutine() {
// we need to take control.
// TODO: Add splash screen support.
if (lock_fd_ != -1) {
display_manager_->IgnoreUpdates();
update_ignored = true;

if (flock(lock_fd_, LOCK_EX) != 0) {
ETRACE("Failed to wait on the hwc lock.");
ITRACE("Fail to grab the hwc lock.");
} else {
ITRACE("Successfully grabbed the hwc lock.");
// Set DRM master
if (!display_manager_->IsDrmMaster())
display_manager_->setDrmMaster(true);
// stop ignoring and force refresh
ResetAllDisplayCommit(true);
flock(lock_fd_, LOCK_UN);
close(lock_fd_);
lock_fd_ = -1;
}

display_manager_->setDrmMaster();

close(lock_fd_);
lock_fd_ = -1;
}

if (update_ignored)
display_manager_->ForceRefresh();
}

void GpuDevice::HandleWait() {
Expand All @@ -1004,7 +1067,10 @@ void GpuDevice::HandleWait() {
}

void GpuDevice::DisableWatch() {
HWCThread::Exit();
if (lock_fd_ != -1) {
close(lock_fd_);
lock_fd_ = -1;
}
}

GpuDevice &GpuDevice::getInstance() {
Expand Down
4 changes: 4 additions & 0 deletions common/core/logicaldisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ int LogicalDisplay::GetDisplayPipe() {
return physical_display_->GetDisplayPipe();
}

bool LogicalDisplay::EnableDRMCommit(bool enable) {
return physical_display_->EnableDRMCommit(enable);
}

bool LogicalDisplay::SetActiveConfig(uint32_t config) {
bool success = physical_display_->SetActiveConfig(config);
width_ = (physical_display_->Width()) / total_divisions_;
Expand Down
2 changes: 2 additions & 0 deletions common/core/logicaldisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class LogicalDisplay : public NativeDisplay {
bool GetDisplayConfigs(uint32_t *num_configs, uint32_t *configs) override;
bool GetDisplayName(uint32_t *size, char *name) override;

bool EnableDRMCommit(bool enable) override;

uint32_t GetXTranslation() override {
return (((physical_display_->Width()) / total_divisions_) * index_);
}
Expand Down
8 changes: 5 additions & 3 deletions common/core/logicaldisplaymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ bool LogicalDisplayManager::Present(std::vector<HwcLayer*>& source_layers,
}
}

uint32_t cursor_layers = cursor_layers_.size();
for (uint32_t j = 0; j < cursor_layers; j++) {
layers_.emplace_back(cursor_layers_.at(j));
layers_.insert(layers_.end(), cursor_layers_.begin(), cursor_layers_.end());

if (layers_.empty()) {
queued_displays_ = 0;
return true;
}

bool success = physical_display_->Present(layers_, retire_fence, call_back,
Expand Down
Loading

0 comments on commit a199ce0

Please sign in to comment.