diff options
author | Takashi Matsuzawa <tmatsuzawa@xevo.com> | 2017-07-31 22:06:38 +0900 |
---|---|---|
committer | Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com> | 2017-08-07 11:02:55 +0900 |
commit | eeedc5e9e67917bd3346dbe5332e667757a3b28d (patch) | |
tree | e11ed643ae15f72e22c269bf334985ef1d2abe12 | |
parent | 3df0464a5ff50fa6af9b69df862cdac3f9b89756 (diff) |
Add scaling mode to demo screenicefish_8.99.5icefish_8.99.4icefish_8.99.3icefish_8.99.2icefish_8.99.1icefish/8.99.5icefish/8.99.4icefish/8.99.3icefish/8.99.2icefish/8.99.1halibut_8.0.6halibut_8.0.5halibut_8.0.4halibut_8.0.3halibut_8.0.2halibut_8.0.1halibut_8.0.0halibut_7.99.3halibut_7.99.2halibut_7.99.1halibut_7.90.0halibut/8.0.6halibut/8.0.5halibut/8.0.4halibut/8.0.3halibut/8.0.2halibut/8.0.1halibut/8.0.0halibut/7.99.3halibut/7.99.2halibut/7.99.1halibut/7.90.0guppy_6.99.4guppy_6.99.3guppy_6.99.2guppy_6.99.1guppy_6.90.0guppy/6.99.4guppy/6.99.3guppy/6.99.2guppy/6.99.1guppy/6.90.0flounder_5.99.6flounder_5.99.5flounder_5.99.4flounder_5.99.3flounder_5.99.2flounder_5.99.1flounder/5.99.6flounder/5.99.5flounder/5.99.4flounder/5.99.3flounder/5.99.2flounder/5.99.1eel_4.99.3eel_4.99.2eel_4.99.1eel/4.99.3eel/4.99.2eel/4.99.18.99.58.99.48.99.38.99.28.99.18.0.68.0.58.0.48.0.38.0.28.0.18.0.07.99.37.99.27.99.17.90.06.99.46.99.36.99.26.99.16.90.05.99.65.99.55.99.45.99.35.99.25.99.14.99.34.99.24.99.1halibut
Bug-AGL: SPEC-791
Avoid demo screen being stretched and distorted on non full-HD display.
Instead, we should fit it on target display but also keeping demo screen aspect ratio.
This change has no impact on fiull-HD displays since the behavior is the same.
In addition to "fit" option (now default), "stretch" (previous default) and "no" modes are provided for convenience.
Update:
Add content modes that seems to be common.
Instead of integer value but string ids are used to specify desired mode.
Update2:
Do not rely on copmiler for redundant calls to strcmp
Use signed type to avoid redundant type casting
Update3:
Fixing typo, adding comments, error case handling
Update4: (Tadao Tanikawa)
Calculating the geometry of layer (named root layer) once when
WindowManager initialized and each app's layer inherits it.
Update5: (Tadao Tanikawa)
Clean up compiler warnings
Update6: (Tadao Tanikawa)
Clean up compiler warnings
Change-Id: Ibb797ebea65062fdda7eccc5b7fc246a6b602e98
Signed-off-by: Takashi Matsuzawa <tmatsuzawa@xevo.com>
Signed-off-by: Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com>
-rw-r--r-- | windowmanager/src/windowmanager.cpp | 139 | ||||
-rw-r--r-- | windowmanager/src/windowmanager.hpp | 18 |
2 files changed, 123 insertions, 34 deletions
diff --git a/windowmanager/src/windowmanager.cpp b/windowmanager/src/windowmanager.cpp index ea5a279..588f7d4 100644 --- a/windowmanager/src/windowmanager.cpp +++ b/windowmanager/src/windowmanager.cpp @@ -54,10 +54,11 @@ WindowManager::WindowManager(int displayId, QObject *parent) : mp_layoutAreaToSurfaceIdAssignment(0), m_currentLayout(-1), m_screenId(displayId), - m_screenWidth(0), - m_screenHeight(0) + m_screen() #ifdef HAVE_IVI_LAYERMANAGEMENT_API , + m_layerSrc(0, 0, WINDOWMANAGER_HOMESCREEN_WIDTH, WINDOWMANAGER_HOMESCREEN_HEIGHT), + m_layerDest(), m_appSurfaces(), m_appLayers(), #if !defined(NO_PROCESS_GROUP) || !defined(NO_PROCESS_SESSION) @@ -99,7 +100,18 @@ void WindowManager::start() myThis = this; - ilm_getScreenResolution(m_screenId, &m_screenWidth, &m_screenHeight); + t_ilm_uint width, height; + ilm_getScreenResolution(m_screenId, &width, &height); + m_screen.setWidth(width); + m_screen.setHeight(height); + + const char *mode = secure_getenv("CONTENT_MODE"); + if (!mode) { + qDebug("CONTENT_MODE not specified. Falling back to aspect-fit"); + mode = "aspect-fit"; + } + + setRootGeometry(mode); createNewLayer(WINDOWMANAGER_LAYER_POPUP); createNewLayer(WINDOWMANAGER_LAYER_HOMESCREEN_OVERLAY); @@ -207,26 +219,101 @@ void WindowManager::createNewLayer(int layerId) qDebug(" layerId %d", layerId); t_ilm_layer newLayerId = layerId; + + // Currently the dimension of layer for apps inherits the root layer's. ilm_layerCreateWithDimension(&newLayerId, - WINDOWMANAGER_HOMESCREEN_WIDTH, - WINDOWMANAGER_HOMESCREEN_HEIGHT); + m_layerSrc.width(), + m_layerSrc.height()); ilm_commitChanges(); ilm_layerSetSourceRectangle(newLayerId, - 0, - 0, - WINDOWMANAGER_HOMESCREEN_WIDTH, - WINDOWMANAGER_HOMESCREEN_HEIGHT); + m_layerSrc.x(), + m_layerSrc.y(), + m_layerSrc.width(), + m_layerSrc.height()); + ilm_layerSetDestinationRectangle(newLayerId, - 0, - 0, - m_screenWidth, - m_screenHeight); + m_layerDest.x(), + m_layerDest.y(), + m_layerDest.width(), + m_layerDest.height()); ilm_commitChanges(); ilm_layerSetOpacity(newLayerId, 1.0); ilm_layerSetVisibility(newLayerId, ILM_TRUE); ilm_commitChanges(); } + +void WindowManager::setRootGeometry(const char *mode) +{ + // To calculate layer management parameters + + // Calcurate parameters based on the content mode id given + // May return false if parameter check, etc. fails (currently not done). + + if (!strcmp("scale-to-fill", mode)) { + // scale, ignore aspect ratio + m_layerDest.setRect(0, 0, m_screen.width(), m_screen.height()); + } + else if (!strcmp("aspect-fit", mode) || !strcmp("aspect-fill", mode)) { + // scale, keeping aspect ratio + QSize size = m_layerSrc.size(); + + if (!strcmp("aspect-fit", mode)) { + size.scale(m_screen, Qt::KeepAspectRatio); + } else { + size.scale(m_screen, Qt::KeepAspectRatioByExpanding); + } + + m_layerDest.setSize(size); + m_layerDest.moveCenter(QPoint(m_screen.width() / 2, m_screen.height() / 2)); + } + else { + // other modes without scaling + m_layerDest.setSize(m_layerSrc.size()); + + // At first, move to center, then move to proper position + m_layerDest.moveCenter(QPoint(m_screen.width() / 2, m_screen.height() / 2)); + + if (!strcmp("center", mode)) { + ; + } + else if (!strcmp("top", mode)) { + m_layerDest.moveTop(0); + } + else if (!strcmp("bottom", mode)) { + m_layerDest.moveBottom(m_screen.height()); + } + else if (!strcmp("left", mode)) { + m_layerDest.moveLeft(0); + } + else if (!strcmp("right", mode)) { + m_layerDest.moveRight(m_screen.width()); + } + else if (!strcmp("top-left", mode)) { + m_layerDest.moveTo(0,0); + } + else if (!strcmp("top-right", mode)) { + m_layerDest.moveTopRight(QPoint(m_screen.width(), 0)); + } + else if (!strcmp("bottom-left", mode)) { + m_layerDest.moveBottomLeft(QPoint(0, m_screen.height())); + } + else if (!strcmp("bottom-right", mode)) { + m_layerDest.moveBottomRight(QPoint(m_screen.width(), m_screen.height())); + } + else { + // fallback + qDebug("Mode \"%s\" not known, fallingback to aspect-fit", mode); + setRootGeometry("aspect-fit"); + return; + } + } + + qDebug("layer src=%dx%d dest=(%d,%d) %dx%d", + m_layerSrc.width(), m_layerSrc.height(), + m_layerDest.x(), m_layerDest.y(), m_layerDest.width(), m_layerDest.height()); +} + t_ilm_layer WindowManager::getAppLayerID(pid_t pid) { t_ilm_layer layer_id; @@ -264,9 +351,7 @@ void WindowManager::addSurface(t_ilm_surface surfaceId) t_ilm_layer WindowManager::addSurfaceToAppLayer(pid_t pid, int surfaceId) { - struct ilmSurfaceProperties surfaceProperties; t_ilm_layer layer_id; - int found = 0; qDebug("-=[addSurfaceToAppLayer]=-"); qDebug(" surfaceId %d", surfaceId); @@ -330,7 +415,7 @@ void WindowManager::addSurfaceToLayer(int surfaceId, int layerId) ilm_commitChanges(); } -void WindowManager::configureHomeScreenMainSurface(t_ilm_surface surface, t_ilm_int width, t_ilm_int height) +void WindowManager::configureHomeScreenMainSurface(t_ilm_surface surface, t_ilm_uint width, t_ilm_uint height) { // homescreen app always fullscreen in the back ilm_surfaceSetDestinationRectangle(surface, 0, 0, @@ -343,7 +428,7 @@ void WindowManager::configureHomeScreenMainSurface(t_ilm_surface surface, t_ilm_ ilm_commitChanges(); } -void WindowManager::configureAppSurface(pid_t pid, t_ilm_surface surface, t_ilm_int width, t_ilm_int height) +void WindowManager::configureAppSurface(t_ilm_surface surface, t_ilm_uint width, t_ilm_uint height) { /* Dirty hack! cut & paste from HomeScreen/src/layouthandler.cpp */ const int SCREEN_WIDTH = 1080; @@ -354,15 +439,15 @@ void WindowManager::configureAppSurface(pid_t pid, t_ilm_surface surface, t_ilm_ const int TOPAREA_X = 0; const int TOPAREA_Y = 0; const int MEDIAAREA_HEIGHT = 215; - const int MEDIAAREA_WIDTH = SCREEN_WIDTH; - const int MEDIAAREA_X = 0; const int MEDIAAREA_Y = SCREEN_HEIGHT - MEDIAAREA_HEIGHT; - ilm_surfaceSetDestinationRectangle(surface, - 0, - TOPAREA_HEIGHT, - SCREEN_WIDTH, - SCREEN_HEIGHT - TOPAREA_HEIGHT - MEDIAAREA_HEIGHT); + const t_ilm_int APPAREA_X = TOPAREA_X; + const t_ilm_int APPAREA_Y = TOPAREA_Y + TOPAREA_HEIGHT; + const t_ilm_uint APPAREA_WIDTH = TOPAREA_WIDTH; + const t_ilm_uint APPAREA_HEIGHT = MEDIAAREA_Y - APPAREA_Y; + + ilm_surfaceSetDestinationRectangle(surface, APPAREA_X, APPAREA_Y, + APPAREA_WIDTH, APPAREA_HEIGHT); ilm_surfaceSetSourceRectangle(surface, 0, 0, width, height); ilm_surfaceSetOpacity(surface, 1.0); ilm_surfaceSetVisibility(surface, ILM_TRUE); /* Hack to avoid blank screen when switch apps */ @@ -395,8 +480,6 @@ void WindowManager::notificationFunc_non_static(ilmObjectType object, qDebug("Notification from weston!"); if (ILM_SURFACE == object) { - struct ilmSurfaceProperties surfaceProperties; - if (created) { if (WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID == id) @@ -429,7 +512,7 @@ void WindowManager::notificationFunc_non_static(ilmObjectType object, void WindowManager::notificationFunc_static(ilmObjectType object, t_ilm_uint id, t_ilm_bool created, - void* user_data) + void*) { static_cast<WindowManager*>(WindowManager::myThis)->notificationFunc_non_static(object, id, created); } @@ -490,7 +573,7 @@ void WindowManager::surfaceCallbackFunction_non_static(t_ilm_surface surface, t_ilm_layer layer = addSurfaceToAppLayer(pid, surface); if (layer != 0) { - configureAppSurface(pid, surface, + configureAppSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight); diff --git a/windowmanager/src/windowmanager.hpp b/windowmanager/src/windowmanager.hpp index 12643e7..a06f840 100644 --- a/windowmanager/src/windowmanager.hpp +++ b/windowmanager/src/windowmanager.hpp @@ -26,6 +26,7 @@ #ifdef HAVE_IVI_LAYERMANAGEMENT_API #include <ilm/ilm_control.h> #endif + class WindowManager : public QObject { Q_OBJECT @@ -43,12 +44,15 @@ private: int m_currentLayout; int m_screenId; - unsigned int m_screenWidth; - unsigned int m_screenHeight; + QSize m_screen; void dumpScene(); #ifdef HAVE_IVI_LAYERMANAGEMENT_API + /* The geometry of layer as destination|source */ + QRect m_layerSrc; + QRect m_layerDest; + t_ilm_layer* m_showLayers; QMap<pid_t, t_ilm_surface> m_appSurfaces; QMap<pid_t, t_ilm_layer> m_appLayers; @@ -59,20 +63,22 @@ private: QList<QString> m_keepApps; /* Apps needs to keep rendering */ QList<pid_t> m_bgApps; + pid_t m_pending_to_show; + + void setRootGeometry(const char *mode); + t_ilm_layer* getLayerRenderOrder(int& num_layers); void createNewLayer(const int layerId); t_ilm_layer getAppLayerID(const pid_t pid); - pid_t m_pending_to_show; - void addSurface(const t_ilm_surface surfaceId); t_ilm_layer addSurfaceToAppLayer(pid_t pid, const int surfaceId); void addSurfaceToLayer(const int surfaceId, const int layerId); - void configureHomeScreenMainSurface(const t_ilm_surface surface, const t_ilm_int width, const t_ilm_int height); - void configureAppSurface(const pid_t pid, const t_ilm_surface surface, const t_ilm_int width, const t_ilm_int height); + void configureHomeScreenMainSurface(const t_ilm_surface surface, const t_ilm_uint width, const t_ilm_uint height); + void configureAppSurface(const t_ilm_surface surface, const t_ilm_uint width, const t_ilm_uint height); void renderLayers(); void checkBackgroundApps(const QString &app_id, int app_pid); |