From 824bfd42b0105b0aeffbc33a87285578abda2f3b Mon Sep 17 00:00:00 2001 From: "Bocklage, Jens" Date: Tue, 18 Oct 2016 18:18:13 +0200 Subject: [PATCH] WindowManager now handles application surfaces by its pids. Signed-off-by: Bocklage, Jens --- HomeScreen/src/layouthandler.cpp | 10 +- HomeScreen/src/main.cpp | 2 +- HomeScreen/src/popupwidget.cpp | 1 + WindowManager/src/main.cpp | 1 + WindowManager/src/windowmanager.cpp | 220 ++++++++++++++++++++++++++---------- WindowManager/src/windowmanager.hpp | 11 +- interfaces/windowmanager.xml | 4 +- test/commandlinetests.txt | 8 +- 8 files changed, 184 insertions(+), 73 deletions(-) diff --git a/HomeScreen/src/layouthandler.cpp b/HomeScreen/src/layouthandler.cpp index 647bc79..65e0194 100644 --- a/HomeScreen/src/layouthandler.cpp +++ b/HomeScreen/src/layouthandler.cpp @@ -38,7 +38,7 @@ void LayoutHandler::setUpLayouts() SimpleRect surfaceArea; const int SCREEN_WIDTH = 1080; - const int SCREEN_HEIGHT = 1080; + const int SCREEN_HEIGHT = 1920; const int STATUSBAR_HEIGHT = 60; const int STATUSBAR_WIDTH = SCREEN_WIDTH; @@ -77,7 +77,7 @@ void LayoutHandler::setUpLayouts() // bottom surface surfaceArea.x = 0; - surfaceArea.y = STATUSBAR_HEIGHT / 2; + surfaceArea.y = SCREEN_HEIGHT / 2; surfaceArea.width = SCREEN_WIDTH; surfaceArea.height = (SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT) / 2; @@ -133,7 +133,7 @@ void LayoutHandler::makeMeVisible(int pid) for (int i = 0; i < m_visibleApps.size(); ++i) { - mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(i, i); + mp_dBusWindowManagerProxy->setPidToLayoutArea(i, i); } } if (1 == availableLayouts.size()) @@ -146,7 +146,7 @@ void LayoutHandler::makeMeVisible(int pid) mp_dBusWindowManagerProxy->setLayoutById(availableLayouts.at(0)); for (int i = 0; i < m_visibleApps.size(); ++i) { - mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(i, i); + mp_dBusWindowManagerProxy->setPidToLayoutArea(i, i); } } if (1 < availableLayouts.size()) @@ -175,6 +175,6 @@ void LayoutHandler::setLayoutByName(QString layoutName) mp_dBusWindowManagerProxy->setLayoutByName(layoutName); for (int i = 0; i < m_visibleApps.size(); ++i) { - mp_dBusWindowManagerProxy->setSurfaceToLayoutArea(i, i); + mp_dBusWindowManagerProxy->setPidToLayoutArea(i, i); } } diff --git a/HomeScreen/src/main.cpp b/HomeScreen/src/main.cpp index 264468b..2701d34 100644 --- a/HomeScreen/src/main.cpp +++ b/HomeScreen/src/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationDomain("LinuxFoundation"); QCoreApplication::setOrganizationName("AutomotiveGradeLinux"); QCoreApplication::setApplicationName("HomeScreen"); - QCoreApplication::setApplicationVersion("0.3.0"); + QCoreApplication::setApplicationVersion("0.3.3"); QSurfaceFormat format; format.setDepthBufferSize(16); diff --git a/HomeScreen/src/popupwidget.cpp b/HomeScreen/src/popupwidget.cpp index e7226dd..6f7d9cb 100644 --- a/HomeScreen/src/popupwidget.cpp +++ b/HomeScreen/src/popupwidget.cpp @@ -72,6 +72,7 @@ void PopupWidget::showPopup(int /*type*/, const QString &text) void PopupWidget::showPopupComboBox(const QString &text, const QStringList &choices) { + mp_ui->comboBox_choice->clear(); m_sendComboBoxChoice = true; mp_ui->comboBox_choice->addItems(choices); mp_ui->comboBox_choice->show(); diff --git a/WindowManager/src/main.cpp b/WindowManager/src/main.cpp index 333d864..f3f5a71 100644 --- a/WindowManager/src/main.cpp +++ b/WindowManager/src/main.cpp @@ -33,6 +33,7 @@ int main(int argc, char *argv[]) qDBusRegisterMetaType >(); WindowManager *windowManager = new WindowManager(); + windowManager->start(); #ifdef __arm__ qDebug("Running on ARM architecture"); diff --git a/WindowManager/src/windowmanager.cpp b/WindowManager/src/windowmanager.cpp index d35db9b..dea17a1 100644 --- a/WindowManager/src/windowmanager.cpp +++ b/WindowManager/src/windowmanager.cpp @@ -29,8 +29,15 @@ WindowManager::WindowManager(QObject *parent) : QObject(parent), m_layouts(), m_layoutNames(), - m_currentLayout(-1) + m_currentLayout(-1), + m_homeScreenPid(-1), +#ifdef __arm__ + mp_surfaces(0), + mp_processLayers(0), +#endif + mp_layoutAreaToPidAssignment(0) { + qDebug("-=[WindowManager]=-"); qDebug("WindowManager"); // publish windowmanager interface mp_windowManagerAdaptor = new WindowmanagerAdaptor((QObject*)this); @@ -38,7 +45,12 @@ WindowManager::WindowManager(QObject *parent) : QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject("/windowmanager", this); dbus.registerService("org.agl.windowmanager"); +} +void WindowManager::start() +{ + qDebug("-=[start]=-"); + mp_layoutAreaToPidAssignment = new QMap; #ifdef __arm__ mp_processLayers = new QList; mp_surfaces = new QMap; @@ -50,19 +62,20 @@ WindowManager::WindowManager(QObject *parent) : myThis = this; err = ilm_registerNotification(WindowManager::notificationFunc_static, this); - - #endif } WindowManager::~WindowManager() { + qDebug("-=[~WindowManager]=-"); delete mp_windowManagerAdaptor; #ifdef __arm__ delete mp_surfaces; + delete mp_processLayers; ilm_destroy(); #endif + delete mp_layoutAreaToPidAssignment; } void WindowManager::dumpScene() @@ -88,13 +101,14 @@ void WindowManager::dumpScene() ++i; } - } #ifdef __arm__ void WindowManager::createNewLayer(int layerId) { + qDebug("-=[createNewLayer]=-"); + qDebug("layerId %d", layerId); ilmErrorTypes err; t_ilm_uint screenID = 0; @@ -105,26 +119,26 @@ void WindowManager::createNewLayer(int layerId) t_ilm_layer newLayerId = layerId; err = ilm_layerCreateWithDimension(&newLayerId, width, height); - qDebug("ilm_layerCreateWithDimension = %d", err); - qDebug("layerIdWallpaper = %d", newLayerId); - err = ilm_layerSetVisibility(newLayerId, true); - qDebug("ilm_layerSetVisibility = %d", err); - - t_ilm_float opacity = 1.0; + t_ilm_float opacity = 0.0; err = ilm_layerSetOpacity(newLayerId, opacity); + ilm_layerSetVisibility(newLayerId, ILM_FALSE); + ilm_commitChanges(); } void WindowManager::addSurfaceToLayer(int surfaceId, int layerId) { + qDebug("-=[addSurfaceToLayer]=-"); + qDebug("surfaceId %d", surfaceId); + qDebug("layerId %d", layerId); t_ilm_int length; t_ilm_layer* pArray; ilm_getLayerIDs(&length, &pArray); bool layerFound(false); - for (int i = 0; i< length; ++i) + for (int i = 0; i < length; ++i) { if (layerId == pArray[i]) { @@ -139,8 +153,15 @@ void WindowManager::addSurfaceToLayer(int surfaceId, int layerId) struct ilmSurfaceProperties surfaceProperties; ilm_getPropertiesOfSurface(surfaceId, &surfaceProperties); - qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth); - qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight); + //qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth); + //qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight); + + ilm_layerSetSourceRectangle(layerId, + 0, + 0, + surfaceProperties.origSourceWidth, + surfaceProperties.origSourceHeight); + ilm_commitChanges(); ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight); @@ -152,10 +173,96 @@ void WindowManager::addSurfaceToLayer(int surfaceId, int layerId) ilm_commitChanges(); } +void WindowManager::updateScreen() +{ + qDebug("-=[updateScreen]=-"); + int numberOfLayersToShow = 0; + + QMap >::iterator i = m_layouts.find(m_currentLayout); + if (m_layouts.end() != i) + { + numberOfLayersToShow += i.value().size(); + qDebug("the current layout provides %d render areas", i.value().size()); + } + else + { + qDebug("the current layout provides no render areas!"); + } + + + t_ilm_layer renderOrder[numberOfLayersToShow]; + int renderOrderCounter = 0; + + qDebug("show home screen app"); + if (-1 != m_homeScreenPid) + { + renderOrder[renderOrderCounter] = m_homeScreenPid; + ++renderOrderCounter; + + ilm_layerSetVisibility(m_homeScreenPid, ILM_TRUE); + t_ilm_float opacity = 1.0; + ilm_layerSetOpacity(m_homeScreenPid, opacity); + + // homescreen app always fullscreen in the back + t_ilm_uint screenID = 0; + t_ilm_uint width; + t_ilm_uint height; + + ilm_getScreenResolution(screenID, &width, &height); + + ilm_layerSetDestinationRectangle(m_homeScreenPid, + 0, + 0, + width, + height); + } + + + qDebug("show %d apps", numberOfLayersToShow); + for (int j = 0; j < numberOfLayersToShow; ++j) + { + int layerToShow = mp_layoutAreaToPidAssignment->find(j).value(); + if (layerToShow != m_homeScreenPid) + { + qDebug(" app no. %d: %d", j, layerToShow); + renderOrder[renderOrderCounter] = layerToShow; + ++renderOrderCounter; + + ilm_layerSetVisibility(layerToShow, ILM_TRUE); + t_ilm_float opacity = 1.0; + ilm_layerSetOpacity(layerToShow, opacity); + + qDebug(" layout area %d", j); + qDebug(" x: %d", m_layouts.find(m_currentLayout).value()[j].x); + qDebug(" x: %d", m_layouts.find(m_currentLayout).value()[j].y); + qDebug(" w: %d", m_layouts.find(m_currentLayout).value()[j].width); + qDebug(" h: %d", m_layouts.find(m_currentLayout).value()[j].height); + + ilm_layerSetDestinationRectangle(layerToShow, + m_layouts.find(m_currentLayout).value()[j].x, + m_layouts.find(m_currentLayout).value()[j].y, + m_layouts.find(m_currentLayout).value()[j].width, + m_layouts.find(m_currentLayout).value()[j].height); + } + } + + qDebug("renderOrder"); + for (int j = 0; j < renderOrderCounter; ++j) + { + qDebug(" %d: %d", j, renderOrder[j]); + } + + ilm_displaySetRenderOrder(0, renderOrder, renderOrderCounter); + + ilm_commitChanges(); +} + void WindowManager::notificationFunc_non_static(ilmObjectType object, t_ilm_uint id, t_ilm_bool created) { + qDebug("-=[notificationFunc_non_static]=-"); + qDebug("Notification from weston!"); if (ILM_SURFACE == object) { struct ilmSurfaceProperties surfaceProperties; @@ -163,19 +270,10 @@ void WindowManager::notificationFunc_non_static(ilmObjectType object, if (created) { qDebug("Surface created, ID: %d", id); + //qDebug("Surface created, ID: 0x%s", QString(QByteArray::number(id,16)).toStdString().c_str()); ilm_getPropertiesOfSurface(id, &surfaceProperties); qDebug(" origSourceWidth : %d", surfaceProperties.origSourceWidth); qDebug(" origSourceHeight: %d", surfaceProperties.origSourceHeight); - - addSurfaceToLayer(id, surfaceProperties.creatorPid); - - t_ilm_int length; - t_ilm_surface* pArray; - ilm_getSurfaceIDs(&length, &pArray); - ilm_layerSetRenderOrder(42, pArray, length); - - ilm_commitChanges(); - SurfaceInfo surfaceInfo; surfaceInfo.pid = surfaceProperties.creatorPid; QString procInfoFileName = QString("/proc/") + QString::number(surfaceInfo.pid) + QString("/comm"); @@ -184,49 +282,34 @@ void WindowManager::notificationFunc_non_static(ilmObjectType object, { QTextStream in(&procInfo); surfaceInfo.processName = in.readLine(); - qDebug("surface id %d, pid %d: %s", id, surfaceInfo.pid, surfaceInfo.processName.toStdString().c_str()); - } + qDebug(" creator pid %d %s", surfaceInfo.pid, surfaceInfo.processName.toStdString().c_str()); + addSurfaceToLayer(id, surfaceProperties.creatorPid); + + mp_surfaces->insert(id, surfaceInfo); + ilm_surfaceAddNotification(id, surfaceCallbackFunction_static); - mp_surfaces->insert(id, surfaceInfo); - ilm_surfaceAddNotification(id, surfaceCallbackFunction_static); + ilm_commitChanges(); + + if (0 == QString::compare("weston-fullscre", surfaceInfo.processName)) + { + qDebug("HomeScreen app detected"); + m_homeScreenPid = surfaceInfo.pid; + updateScreen(); + } + } + else + { + qDebug("no creator pid found. Ignoring surface!"); + } } else { qDebug("Surface destroyed, ID: %d", id); mp_surfaces->erase(mp_surfaces->find(id)); ilm_surfaceRemoveNotification(id); - } - // rearrange surfaces on screen - t_ilm_uint screenID = 0; - t_ilm_uint width; - t_ilm_uint height; - ilm_getScreenResolution(screenID, &width, &height); - - qDebug("%d surfaces to show", mp_surfaces->count()); - - QMap::const_iterator i = mp_surfaces->constBegin(); - int counter(0); - while (i != mp_surfaces->constEnd()) - { - qDebug("place surface %d at x: %f, y: %d, width: %f, height: %d", - i.key(), - counter * (width / (1.0 * mp_surfaces->count())), - 0, - width / (1.0 * mp_surfaces->count()), - height); - ilm_surfaceSetDestinationRectangle(i.key(), - counter * (width / (1.0 * mp_surfaces->count())), - 0, - width / (1.0 * mp_surfaces->count()), - height); - - ++i; - ++counter; + ilm_commitChanges(); } - - - ilm_commitChanges(); } if (ILM_LAYER == object) { @@ -249,6 +332,7 @@ void WindowManager::surfaceCallbackFunction_non_static(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask mask) { + qDebug("-=[surfaceCallbackFunction_non_static]=-"); qDebug("surfaceCallbackFunction_non_static changes for surface %d", surface); if (ILM_NOTIFICATION_VISIBILITY & mask) { @@ -287,6 +371,7 @@ void WindowManager::surfaceCallbackFunction_static(t_ilm_surface surface, int WindowManager::addLayout(int layoutId, const QString &layoutName, const QList &surfaceAreas) { + qDebug("-=[addLayout]=-"); m_layouts.insert(layoutId, surfaceAreas); m_layoutNames.insert(layoutId, layoutName); qDebug("addLayout %d %s, size %d", layoutId, layoutName.toStdString().c_str(), surfaceAreas.size()); @@ -298,6 +383,7 @@ int WindowManager::addLayout(int layoutId, const QString &layoutName, const QLis QList WindowManager::getAvailableLayouts(int numberOfAppSurfaces) { + qDebug("-=[getAvailableLayouts]=-"); QMap >::iterator i = m_layouts.begin(); QList result; @@ -317,6 +403,7 @@ QList WindowManager::getAvailableLayouts(int numberOfAppSurfaces) // maybe not needed anymore QList WindowManager::getAvailableSurfaces() { + qDebug("-=[getAvailableSurfaces]=-"); QList points; SimplePoint point; point.x = 1; @@ -334,23 +421,29 @@ QList WindowManager::getAvailableSurfaces() int WindowManager::getLayout() { + qDebug("-=[getLayout]=-"); return m_currentLayout; } QString WindowManager::getLayoutName(int layoutId) { + qDebug("-=[getLayoutName]=-"); return m_layoutNames.find(layoutId).value(); } void WindowManager::setLayoutById(int layoutId) { + qDebug("-=[setLayoutById]=-"); m_currentLayout = layoutId; + mp_layoutAreaToPidAssignment->clear(); + dumpScene(); } void WindowManager::setLayoutByName(const QString &layoutName) { + qDebug("-=[setLayoutByName]=-"); QMap::iterator i = m_layoutNames.begin(); while (i != m_layoutNames.constEnd()) { @@ -361,10 +454,21 @@ void WindowManager::setLayoutByName(const QString &layoutName) ++i; } + mp_layoutAreaToPidAssignment->clear(); + dumpScene(); } -void WindowManager::setSurfaceToLayoutArea(int surfaceId, int layoutAreaId) +void WindowManager::setPidToLayoutArea(int pid, int layoutAreaId) { + qDebug("-=[setPidToLayoutArea]=-"); + qDebug("pid %d", pid); + qDebug("layoutAreaId %d", layoutAreaId); + mp_layoutAreaToPidAssignment->insert(layoutAreaId, pid); + +#ifdef __arm__ + updateScreen(); +#endif + dumpScene(); } diff --git a/WindowManager/src/windowmanager.hpp b/WindowManager/src/windowmanager.hpp index 8fb716d..2a76a32 100644 --- a/WindowManager/src/windowmanager.hpp +++ b/WindowManager/src/windowmanager.hpp @@ -42,19 +42,22 @@ class WindowManager : public QObject public: explicit WindowManager(QObject *parent = 0); - QMutex callbackMutex; - ~WindowManager(); + + void start(); private: WindowmanagerAdaptor *mp_windowManagerAdaptor; QMap > m_layouts; QMap m_layoutNames; int m_currentLayout; void dumpScene(); + int m_homeScreenPid; #ifdef __arm__ void createNewLayer(int layerId); void addSurfaceToLayer(int surfaceId, int layerId); + void updateScreen(); + QMap *mp_surfaces; /* one layer per pid is created @@ -62,6 +65,8 @@ private: QList *mp_processLayers; #endif + QMap *mp_layoutAreaToPidAssignment; + public: static void* myThis; @@ -97,7 +102,7 @@ public Q_SLOTS: // METHODS QString getLayoutName(int layoutId); void setLayoutById(int layoutId); void setLayoutByName(const QString &layoutName); - void setSurfaceToLayoutArea(int surfaceId, int layoutAreaId); + void setPidToLayoutArea(int pid, int layoutAreaId); }; diff --git a/interfaces/windowmanager.xml b/interfaces/windowmanager.xml index 9c1e7fe..c86c8e7 100644 --- a/interfaces/windowmanager.xml +++ b/interfaces/windowmanager.xml @@ -35,8 +35,8 @@ - - + + diff --git a/test/commandlinetests.txt b/test/commandlinetests.txt index ff2bf7b..86a09cd 100644 --- a/test/commandlinetests.txt +++ b/test/commandlinetests.txt @@ -234,7 +234,7 @@ Preconditions: - WindowManager app is running Test: -$dbus-send --session --type=method_call --print-reply --dest=org.agl.windowmanager /windowmanager org.agl.windowmanager.getAvailableLayouts int32:1 +$dbus-send --session --type=method_call --print-reply --dest=org.agl.windowmanager /windowmanager org.agl.windowmanager.setLayoutById int32:1 Method: @@ -261,8 +261,8 @@ Test: $dbus-send --session --type=method_call --print-reply --dest=org.agl.windowmanager /windowmanager org.agl.windowmanager.getLayout Method: - - + + @@ -271,7 +271,7 @@ Preconditions: - WindowManager app is running Test: -$dbus-send --session --type=method_call --print-reply --dest=org.agl.windowmanager /windowmanager org.agl.windowmanager.setSurfaceToLayoutArea int32:1123 int32:1 +$dbus-send --session --type=method_call --print-reply --dest=org.agl.windowmanager /windowmanager org.agl.windowmanager.setPidToLayoutArea int32:1123 int32:1 Method: -- 2.16.6