2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 #include "wm_layer_control.hpp"
\r
19 #include "wm_layer.hpp"
\r
20 #include "json_helper.hpp"
\r
22 #define LC_AREA_PATH "/etc/areas.db"
\r
23 #define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"
\r
30 LayerControl* g_lc_ctxt;
\r
32 static void createCallback_static(ilmObjectType object,
\r
37 static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);
\r
40 static void surfaceCallback_static(t_ilm_surface surface,
\r
41 struct ilmSurfaceProperties* surface_prop,
\r
42 t_ilm_notification_mask mask)
\r
44 g_lc_ctxt->dispatchPropertyChangeEvent(surface, surface_prop, mask);
\r
47 static void layerCallback_static(t_ilm_layer layer,
\r
48 struct ilmLayerProperties* layer_prop,
\r
49 t_ilm_notification_mask mask)
\r
51 g_lc_ctxt->dispatchPropertyChangeEvent(layer, layer_prop, mask);
\r
54 LayerControl::LayerControl(const std::string& root)
\r
56 string area_path = root + LC_AREA_PATH;
\r
57 string layer_path= root + LC_LAYER_SETTING_PATH;
\r
58 // load layers.setting.json
\r
59 WMError ret = this->loadLayerSetting(layer_path);
\r
60 assert(ret == WMError::SUCCESS);
\r
62 ret = this->loadAreaDb(area_path);
\r
63 assert(ret == WMError::SUCCESS);
\r
66 WMError LayerControl::init(const LayerControlCallbacks& cb)
\r
68 ilmErrorTypes rc = ilm_init();
\r
73 while (rc != ILM_SUCCESS)
\r
78 HMI_ERROR("Could not connect to compositor");
\r
81 HMI_ERROR("Wait to start weston ...");
\r
85 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
87 // Get current screen setting
\r
88 rc = ilm_getScreenIDs(&num, &ids);
\r
90 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
92 for(unsigned i = 0; i < num; i++)
\r
94 HMI_INFO("get screen: %d", ids[i]);
\r
96 // Currently, 0 is only available
\r
97 this->screenID = ids[0];
\r
99 rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);
\r
101 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
103 // Register Callback from ILM
\r
105 ilm_registerNotification(createCallback_static, this);
\r
107 return WMError::SUCCESS;
\r
110 HMI_ERROR("Failed to initialize. Terminate WM");
\r
112 return WMError::FAIL;
\r
115 unsigned LayerControl::getNewLayerID(const string& role)
\r
118 for(const auto& l: this->wm_layers)
\r
120 ret = l->getNewLayerID(role);
\r
129 struct rect LayerControl::getAreaSize(const std::string& area)
\r
131 return area2size[area];
\r
134 void LayerControl::setupArea(double scaling)
\r
138 rct = this->area2size["normal.full"];
\r
139 this->area2size["normalfull"] = rct;
\r
140 this->area2size["normal"] = rct;
\r
142 for (auto &i : this->area2size)
\r
144 i.second.x = static_cast<int>(scaling * i.second.x + 0.5);
\r
145 i.second.y = static_cast<int>(scaling * i.second.y + 0.5);
\r
146 i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
\r
147 i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
\r
149 HMI_DEBUG("wm:lm", "area:%s size(after) : x:%d y:%d w:%d h:%d",
\r
150 i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
\r
154 Screen LayerControl::getScreenInfo()
\r
156 return Screen(this->screen_prop.screenWidth, this->screen_prop.screenHeight);
\r
159 WMError LayerControl::updateLayer(LayerState& layer_state)
\r
161 return WMError::SUCCESS;
\r
164 WMError LayerControl::commitChange()
\r
166 WMError rc = WMError::SUCCESS;
\r
167 vector<unsigned> ivi_l_ids;
\r
168 for(const auto& l : this->wm_layers)
\r
170 auto state = l->getLayerState();
\r
171 for(const auto& id : state.getIviIdList())
\r
173 ivi_l_ids.push_back(id);
\r
176 t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
\r
177 if(id_array == nullptr)
\r
179 HMI_WARNING("short memory");
\r
180 this->undoUpdate();
\r
181 return WMError::FAIL;
\r
184 for(const auto& i : ivi_l_ids)
\r
186 id_array[count] = i;
\r
189 ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
\r
190 if(ret != ILM_SUCCESS)
\r
192 this->undoUpdate();
\r
193 rc = WMError::FAIL;
\r
199 void LayerControl::undoUpdate() {}
\r
201 WMError LayerControl::loadLayerSetting(const string &path)
\r
203 HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);
\r
205 json_object *json_obj, *json_cfg;
\r
206 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
209 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
210 return WMError::FAIL;
\r
212 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
214 if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
\r
216 HMI_ERROR("Parse Error!!");
\r
217 return WMError::FAIL;
\r
220 int len = json_object_array_length(json_cfg);
\r
221 HMI_DEBUG("json_cfg len:%d", len);
\r
223 for (int i = 0; i < len; i++)
\r
225 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
226 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
228 this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));
\r
231 return WMError::SUCCESS;
\r
234 WMError LayerControl::loadAreaDb(const std::string& path)
\r
237 json_object *json_obj;
\r
238 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
241 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
242 return WMError::FAIL;
\r
244 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
247 json_object *json_cfg;
\r
248 if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))
\r
250 HMI_ERROR("Parse Error!!");
\r
251 return WMError::FAIL;
\r
254 int len = json_object_array_length(json_cfg);
\r
255 HMI_DEBUG("json_cfg len:%d", len);
\r
258 for (int i = 0; i < len; i++)
\r
260 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
261 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
263 area = jh::getStringFromJson(json_tmp, "name");
\r
264 if (nullptr == area)
\r
266 HMI_ERROR("Parse Error!!");
\r
267 return WMError::FAIL;
\r
269 HMI_DEBUG("> area:%s", area);
\r
271 json_object *json_rect;
\r
272 if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))
\r
274 HMI_ERROR("Parse Error!!");
\r
275 return WMError::FAIL;
\r
277 HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));
\r
279 struct rect area_size;
\r
280 area_size.x = jh::getIntFromJson(json_rect, "x");
\r
281 area_size.y = jh::getIntFromJson(json_rect, "y");
\r
282 area_size.w = jh::getIntFromJson(json_rect, "w");
\r
283 area_size.h = jh::getIntFromJson(json_rect, "h");
\r
285 this->area2size[area] = area_size;
\r
289 for (const auto& itr : this->area2size)
\r
291 HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
\r
292 itr.first.c_str(), itr.second.x, itr.second.y,
\r
293 itr.second.w, itr.second.h);
\r
296 // Release json_object
\r
297 json_object_put(json_obj);
\r
299 return WMError::SUCCESS;
\r
302 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
\r
305 if (ILM_SURFACE == object)
\r
309 ilmSurfaceProperties sp;
\r
311 rc = ilm_getPropertiesOfSurface(id, &sp);
\r
312 if(rc != ILM_SUCCESS)
\r
314 // this->cb->surfaceCreated(pid, id);
\r
315 ilm_surfaceAddNotification(id, surfaceCallback_static);
\r
316 ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
\r
320 // this->cb->surfaceDestroyed(id);
\r
323 if (ILM_LAYER == object)
\r
327 ilm_layerAddNotification(id, layerCallback_static);
\r
328 // this->cb->layerCreated(id);
\r
332 // this->cb->layerDestroyed(id); // Means Application is dead.
\r
337 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
338 struct ilmSurfaceProperties* sprop,
\r
339 t_ilm_notification_mask mask)
\r
341 pid_t pid = sprop->creatorPid;
\r
342 HMI_DEBUG("pid : %d", pid);
\r
344 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
346 //this->cb->surfaceVisibilityChanged(id, sprop->visibility);
\r
348 if (ILM_NOTIFICATION_OPACITY & mask)
\r
351 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
354 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
356 // this->cb->surfaceSourceRectChanged(id, )
\r
358 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
360 // this->cb->surfaceSourceRectChanged(id, )
\r
362 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
365 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
367 /* application being down */
\r
368 // m_appLayers.remove(pid);
\r
370 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
372 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
373 qDebug(" surfaceProperties %d", surface);
\r
374 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
375 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
377 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
378 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
379 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
381 ilmErrorTypes result;
\r
382 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
385 configureAppSurface(surface,
\r
386 surfaceProperties->origSourceWidth,
\r
387 surfaceProperties->origSourceHeight);
\r
389 result = ilm_layerAddSurface(layer, surface);
\r
390 if (result != ILM_SUCCESS) {
\r
391 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
393 ilm_commitChanges();
\r
400 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
401 struct ilmLayerProperties* lprop,
\r
402 t_ilm_notification_mask mask)
\r
404 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
406 //this->cb->layerVisibilityChanged(id, sprop->visibility);
\r
408 if (ILM_NOTIFICATION_OPACITY & mask)
\r
411 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
414 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
416 // this->cb->surfaceSourceRectChanged(id, )
\r
418 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
420 // this->cb->surfaceSourceRectChanged(id, )
\r
422 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
425 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
427 /* application being down */
\r
428 // m_appLayers.remove(pid);
\r
430 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
432 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
433 qDebug(" surfaceProperties %d", surface);
\r
434 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
435 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
437 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
438 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
439 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
441 ilmErrorTypes result;
\r
442 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
445 configureAppSurface(surface,
\r
446 surfaceProperties->origSourceWidth,
\r
447 surfaceProperties->origSourceHeight);
\r
449 result = ilm_layerAddSurface(layer, surface);
\r
450 if (result != ILM_SUCCESS) {
\r
451 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
453 ilm_commitChanges();
\r