diff options
author | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-07-07 17:22:46 +0900 |
---|---|---|
committer | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-07-11 17:26:55 +0900 |
commit | 8ab10aaafc6fb3dc7bbad755dce9b4bdaa41f287 (patch) | |
tree | e766e0b4b1bb894c5511ed6d1e71a4ac389415d6 /src | |
parent | 6e8ca74a266a224d2754a5f2ed0e228fec2e5c96 (diff) |
Enable scaling to fit various screen resolutions
Since the AGL HomeScreen of CES2018 assumes that the screen
resolution is 1080x1920px, the graphics of it partially
corrupted with others.
To fix this issue, now the AGL window manager automatically
scales size according to "scaling" value in setting.json
By default(even if "scaling" is not set), this scaling keeps
'fullscreen' aspect rate in area.db("aspect_fit")
User can select 3 options.
- "aspect_fit" : Scale aspect rate of 'fullscreen' in area.db.(default)
- "display_fit": Force to scale to display size.
- "none" or others
: Set size just as area.db
Bug-AGL: SPEC-1568
Bug-AGL: SPEC-1569
Change-Id: Ia08c0ebb2d71ae8f89a90088e181381c3ba3562d
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/layers.cpp | 60 | ||||
-rw-r--r-- | src/layers.hpp | 2 | ||||
-rw-r--r-- | src/wayland_ivi_wm.cpp | 5 | ||||
-rw-r--r-- | src/wayland_ivi_wm.hpp | 1 | ||||
-rw-r--r-- | src/window_manager.cpp | 24 | ||||
-rw-r--r-- | src/window_manager.hpp | 6 | ||||
-rw-r--r-- | src/wm_config.cpp | 91 | ||||
-rw-r--r-- | src/wm_config.hpp | 43 |
9 files changed, 212 insertions, 22 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 42b81b7..ee398e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ add_library(${TARGETS_WM} MODULE layers.cpp wm_client.cpp wm_error.cpp + wm_config.cpp applist.cpp request.cpp) @@ -112,6 +113,7 @@ add_custom_command(TARGET ${TARGETS_WM} POST_BUILD COMMAND cp -f ${PROJECT_SOURCE_DIR}/layers.json ${PROJECT_BINARY_DIR}/package/root/etc COMMAND cp -f ${PROJECT_SOURCE_DIR}/src/db/old_roles.db ${PROJECT_BINARY_DIR}/package/root/etc COMMAND cp -f ${PROJECT_SOURCE_DIR}/src/db/areas.db ${PROJECT_BINARY_DIR}/package/root/etc + COMMAND cp -f ${PROJECT_SOURCE_DIR}/conf/setting.json ${PROJECT_BINARY_DIR}/package/root/etc ) add_custom_target(package DEPENDS ${PROJECT_BINARY_DIR}/package/root diff --git a/src/layers.cpp b/src/layers.cpp index f73daf2..b961157 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -181,24 +181,60 @@ json layer_map::to_json() const return j; } -void layer_map::setupArea(int output_w, int output_h) +compositor::rect layer_map::getAreaSize(const std::string &area) +{ + return area2size[area]; +} + +const compositor::rect layer_map::getScaleDestRect( + int to_w, int to_h, const std::string &aspect_setting) { compositor::rect rct; + rct.x = 0; + rct.y = 0; + rct.w = to_w; + rct.h = to_h; + HMI_NOTICE("wm:lm", + "Scaling:'%s'. Check 'fullscreen' is set.", aspect_setting.c_str()); + // Base is "fullscreen". Crash me if "fullscreen" is not set + compositor::rect base = this->area2size.at("fullscreen"); + HMI_DEBUG("wm:lm", "Output size, width: %d, height: %d / fullscreen width: %d, height: %d", + to_w, to_h, base.w, base.h); + // If full_rct.w or full_rct.h == 0, crash me on purpose + double scale_rate_w = double(to_w) / double(base.w); + double scale_rate_h = double(to_h) / double(base.h); + double scale; + if (scale_rate_h < scale_rate_w) + { + scale = scale_rate_h; + } + else + { + scale = scale_rate_w; + } + HMI_DEBUG("wm", "set scale: %5.2f", scale); - rct = this->area2size["normal.full"]; - this->area2size["normalfull"] = rct; - this->area2size["normal"] = rct; + // Scaling + if (aspect_setting == "aspect_fit") + { + // offset + rct.x = (to_w - scale * base.w) / 2; + rct.y = (to_h - scale * base.h) / 2; - for (auto &i : this->area2size) + // scaling + rct.w = base.w * scale; + rct.h = base.h * scale; + } + else if (aspect_setting == "display_fit") { - HMI_DEBUG("wm:lm", "area:%s size(after) : x:%d y:%d w:%d h:%d", - i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h); + // offset is none + // scaling + rct.w = base.w * scale_rate_w; + rct.h = base.h * scale_rate_h; } -} - -compositor::rect layer_map::getAreaSize(const std::string &area) -{ - return area2size[area]; + HMI_DEBUG("wm:lm", "offset x: %d, y: %d", rct.x, rct.y); + HMI_DEBUG("wm:lm", "after scaling w: %d, h: %d", rct.w, rct.h); + return rct; } int layer_map::loadAreaDb() diff --git a/src/layers.hpp b/src/layers.hpp index b6dd67f..adfd733 100644 --- a/src/layers.hpp +++ b/src/layers.hpp @@ -114,8 +114,8 @@ struct layer_map } json to_json() const; - void setupArea(int output_w, int output_h); compositor::rect getAreaSize(const std::string &area); + const compositor::rect getScaleDestRect(int output_w, int output_h, const std::string &aspect_setting); int loadAreaDb(); private: diff --git a/src/wayland_ivi_wm.cpp b/src/wayland_ivi_wm.cpp index 6a1c84a..75ecbbd 100644 --- a/src/wayland_ivi_wm.cpp +++ b/src/wayland_ivi_wm.cpp @@ -435,6 +435,11 @@ void layer::set_visibility(uint32_t visibility) ivi_wm_set_layer_visibility(this->parent->proxy.get(), this->id, visibility); } +void layer::set_source_rectangle(int32_t x, int32_t y, int32_t width, int32_t height) +{ + ivi_wm_set_layer_source_rectangle(this->parent->proxy.get(), this->id, x, y, width, height); +} + void layer::set_destination_rectangle(int32_t x, int32_t y, int32_t width, int32_t height) { diff --git a/src/wayland_ivi_wm.hpp b/src/wayland_ivi_wm.hpp index cd69623..06c1e1b 100644 --- a/src/wayland_ivi_wm.hpp +++ b/src/wayland_ivi_wm.hpp @@ -197,6 +197,7 @@ struct layer : public controller_child // Requests void set_visibility(uint32_t visibility); + void set_source_rectangle(int32_t x, int32_t y, int32_t width, int32_t height); void set_destination_rectangle(int32_t x, int32_t y, int32_t width, int32_t height); void add_surface(uint32_t surface_id); diff --git a/src/window_manager.cpp b/src/window_manager.cpp index de322df..eadf7ff 100644 --- a/src/window_manager.cpp +++ b/src/window_manager.cpp @@ -19,6 +19,7 @@ #include "window_manager.hpp" #include "json_helper.hpp" +#include "wm_config.hpp" #include "applist.hpp" extern "C" @@ -146,6 +147,7 @@ WindowManager::WindowManager(wl::display *d) int WindowManager::init() { + int ret; if (!this->display->ok()) { return -1; @@ -201,7 +203,8 @@ int WindowManager::init() // Third level objects this->display->roundtrip(); - return init_layers(); + ret = init_layers(); + return ret; } int WindowManager::dispatch_pending_events() @@ -654,12 +657,22 @@ int WindowManager::init_layers() return -1; } + WMConfig wm_config; + wm_config.loadConfigs(); + auto &c = this->controller; auto &o = this->outputs.front(); auto &s = c->screens.begin()->second; auto &layers = c->layers; + this->layers.loadAreaDb(); + const compositor::rect base = this->layers.getAreaSize("fullscreen"); + + const std::string aspect_setting = wm_config.getConfigAspect(); + const compositor::rect scale_rect = + this->layers.getScaleDestRect(o->width, o->height, aspect_setting); + // Write output dimensions to ivi controller... c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)}; c->physical_size = compositor::size{uint32_t(o->physical_width), @@ -674,9 +687,11 @@ int WindowManager::init_layers() // Quick and dirty setup of layers for (auto const &i : this->layers.mapping) { - c->layer_create(i.second.layer_id, o->width, o->height); + c->layer_create(i.second.layer_id, scale_rect.w, scale_rect.h); auto &l = layers[i.second.layer_id]; - l->set_destination_rectangle(0, 0, o->width, o->height); + l->set_source_rectangle(0, 0, base.w, base.h); + l->set_destination_rectangle( + scale_rect.x, scale_rect.y, scale_rect.w, scale_rect.h); l->set_visibility(1); HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"", i.second.name.c_str(), i.second.layer_id, i.second.role.c_str()); @@ -687,9 +702,6 @@ int WindowManager::init_layers() this->layout_commit(); - this->layers.loadAreaDb(); - this->layers.setupArea(o->width, o->height); - return 0; } diff --git a/src/window_manager.hpp b/src/window_manager.hpp index 66e0d4b..0fb1805 100644 --- a/src/window_manager.hpp +++ b/src/window_manager.hpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef TMCAGLWM_APP_HPP -#define TMCAGLWM_APP_HPP +#ifndef WINDOW_MANAGER_HPP +#define WINDOW_MANAGER_HPP #include <atomic> #include <memory> @@ -283,4 +283,4 @@ class WindowManager } // namespace wm -#endif // TMCAGLWM_APP_HPP +#endif // WINDOW_MANAGER_HPP diff --git a/src/wm_config.cpp b/src/wm_config.cpp new file mode 100644 index 0000000..f91fedd --- /dev/null +++ b/src/wm_config.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../include/hmi-debug.h" +#include "json_helper.hpp" +#include "wm_config.hpp" + +using std::string; + +namespace wm +{ + +WMConfig::WMConfig(){} + +WMConfig::~WMConfig() +{ + json_object_put(j_setting_conf); +} + +WMError WMConfig::loadConfigs() +{ + WMError ret; + char const *pRoot = getenv("AFM_APP_INSTALL_DIR"); + string root_path = pRoot; + if (root_path.length() == 0) + { + HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined"); + } + ret = this->loadSetting(root_path); + + return ret; +} + +const string WMConfig::getConfigAspect() +{ + json_object *j; + string ret; + if (!json_object_object_get_ex(this->j_setting_conf, "settings", &j)) + { + ret = "aspect_fit"; + } + else + { + const char* scaling = jh::getStringFromJson(j, "scaling"); + if(scaling == nullptr) + { + ret = "aspect_fit"; + } + else + { + ret = scaling; + } + } + return ret; +} + +/* + ***** Private Functions ***** + */ + +WMError WMConfig::loadSetting(const string &path) +{ + string setting_path = path; + int iret = -1; + WMError ret = SUCCESS; + + if (setting_path.length() != 0) + { + setting_path = path + string("/etc/setting.json"); + iret = jh::inputJsonFilie(setting_path.c_str(), &this->j_setting_conf); + if (iret < 0) + ret = FAIL; + } + + return ret; +} + +} // namespace wm diff --git a/src/wm_config.hpp b/src/wm_config.hpp new file mode 100644 index 0000000..68051b4 --- /dev/null +++ b/src/wm_config.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WM_CONFIG_HPP +#define WM_CONFIG_HPP +#include <string> +#include "wm_error.hpp" + +struct json_object; + +namespace wm +{ + +class WMConfig { +public: + WMConfig(); + ~WMConfig(); + WMConfig(const WMConfig &) = delete; + WMConfig &operator=(const WMConfig &) = delete; + WMError loadConfigs(); + const std::string getConfigAspect(); + + private: + WMError loadSetting(const std::string &path); + // private variable + json_object *j_setting_conf; +}; + +} // namespace wm +#endif // WM_CONFIG_HPP
\ No newline at end of file |