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 "wm_client.hpp"
\r
21 #include "request.hpp"
\r
22 #include "json_helper.hpp"
\r
24 #define LC_AREA_PATH "/etc/areas.db"
\r
25 #define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"
\r
26 #define LC_DEFAULT_AREA "normal.full"
\r
30 using std::shared_ptr;
\r
34 LayerControl* g_lc_ctxt;
\r
36 static void createCallback_static(ilmObjectType object,
\r
41 static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);
\r
44 static void surfaceCallback_static(t_ilm_surface surface,
\r
45 struct ilmSurfaceProperties* surface_prop,
\r
46 t_ilm_notification_mask mask)
\r
48 g_lc_ctxt->dispatchPropertyChangeEvent(surface, surface_prop, mask);
\r
51 static void layerCallback_static(t_ilm_layer layer,
\r
52 struct ilmLayerProperties* layer_prop,
\r
53 t_ilm_notification_mask mask)
\r
55 g_lc_ctxt->dispatchPropertyChangeEvent(layer, layer_prop, mask);
\r
58 LayerControl::LayerControl(const std::string& root)
\r
60 string area_path = root + LC_AREA_PATH;
\r
61 string layer_path= root + LC_LAYER_SETTING_PATH;
\r
62 // load layers.setting.json
\r
63 WMError ret = this->loadLayerSetting(layer_path);
\r
64 assert(ret == WMError::SUCCESS);
\r
66 ret = this->loadAreaDb(area_path);
\r
67 assert(ret == WMError::SUCCESS);
\r
70 WMError LayerControl::init(const LayerControlCallbacks& cb)
\r
72 ilmErrorTypes rc = ilm_init();
\r
77 while (rc != ILM_SUCCESS)
\r
82 HMI_ERROR("Could not connect to compositor");
\r
85 HMI_ERROR("Wait to start weston ...");
\r
89 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
91 // Get current screen setting
\r
92 rc = ilm_getScreenIDs(&num, &ids);
\r
94 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
96 for(unsigned i = 0; i < num; i++)
\r
98 HMI_INFO("get screen: %d", ids[i]);
\r
100 // Currently, 0 is only available
\r
101 this->screenID = ids[0];
\r
103 rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);
\r
105 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
107 // Register Callback from ILM
\r
109 ilm_registerNotification(createCallback_static, this);
\r
111 return WMError::SUCCESS;
\r
114 HMI_ERROR("Failed to initialize. Terminate WM");
\r
116 return WMError::FAIL;
\r
119 void LayerControl::createNewLayer(unsigned id)
\r
121 HMI_INFO("create new ID :%d", id);
\r
122 struct rect rct = this->area2size[LC_DEFAULT_AREA];
\r
123 ilm_layerCreateWithDimension(&id, rct.w, rct.h);
\r
124 ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);
\r
125 ilm_layerSetDestinationRectangle(id, rct.x, rct.y, rct.w, rct.h);
\r
126 ilm_layerSetOpacity(id, 1.0);
\r
127 ilm_layerSetVisibility(id, ILM_TRUE);
\r
128 ilm_commitChanges();
\r
131 unsigned LayerControl::getNewLayerID(const string& role, string* layer_name)
\r
134 for(const auto& l: this->wm_layers)
\r
136 ret = l->getNewLayerID(role);
\r
139 *layer_name = l->layerName();
\r
146 struct rect LayerControl::getAreaSize(const std::string& area)
\r
148 return area2size[area];
\r
151 void LayerControl::setupArea(double scaling)
\r
154 this->scaling = scaling;
\r
156 rct = this->area2size["normal.full"];
\r
157 this->area2size["normalfull"] = rct;
\r
158 this->area2size["normal"] = rct;
\r
160 for (auto &i : this->area2size)
\r
162 i.second.x = static_cast<int>(scaling * i.second.x + 0.5);
\r
163 i.second.y = static_cast<int>(scaling * i.second.y + 0.5);
\r
164 i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
\r
165 i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
\r
167 HMI_DEBUG("wm:lm", "area:%s size(after) : x:%d y:%d w:%d h:%d",
\r
168 i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
\r
172 Screen LayerControl::getScreenInfo()
\r
174 return Screen(this->screen_prop.screenWidth, this->screen_prop.screenHeight);
\r
177 double LayerControl::scale()
\r
179 return this->scaling;
\r
182 WMError LayerControl::updateLayer(LayerState& layer_state)
\r
184 return WMError::SUCCESS;
\r
187 WMError LayerControl::commitChange()
\r
189 WMError rc = WMError::SUCCESS;
\r
190 vector<unsigned> ivi_l_ids;
\r
191 for(const auto& l : this->wm_layers)
\r
193 auto state = l->getLayerState();
\r
194 for(const auto& id : state.getIviIdList())
\r
196 ivi_l_ids.push_back(id);
\r
199 t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
\r
200 if(id_array == nullptr)
\r
202 HMI_WARNING("short memory");
\r
203 this->undoUpdate();
\r
204 return WMError::FAIL;
\r
207 for(const auto& i : ivi_l_ids)
\r
209 id_array[count] = i;
\r
212 ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
\r
213 if(ret != ILM_SUCCESS)
\r
215 this->undoUpdate();
\r
216 rc = WMError::FAIL;
\r
222 void LayerControl::undoUpdate() {}
\r
224 WMError LayerControl::loadLayerSetting(const string &path)
\r
226 HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);
\r
228 json_object *json_obj, *json_cfg;
\r
229 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
232 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
233 return WMError::FAIL;
\r
235 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
237 if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
\r
239 HMI_ERROR("Parse Error!!");
\r
240 return WMError::FAIL;
\r
243 int len = json_object_array_length(json_cfg);
\r
244 HMI_DEBUG("json_cfg len:%d", len);
\r
246 for (int i = 0; i < len; i++)
\r
248 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
249 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
251 this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));
\r
254 return WMError::SUCCESS;
\r
257 WMError LayerControl::loadAreaDb(const std::string& path)
\r
260 json_object *json_obj;
\r
261 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
264 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
265 return WMError::FAIL;
\r
267 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
270 json_object *json_cfg;
\r
271 if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))
\r
273 HMI_ERROR("Parse Error!!");
\r
274 return WMError::FAIL;
\r
277 int len = json_object_array_length(json_cfg);
\r
278 HMI_DEBUG("json_cfg len:%d", len);
\r
281 for (int i = 0; i < len; i++)
\r
283 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
284 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
286 area = jh::getStringFromJson(json_tmp, "name");
\r
287 if (nullptr == area)
\r
289 HMI_ERROR("Parse Error!!");
\r
290 return WMError::FAIL;
\r
292 HMI_DEBUG("> area:%s", area);
\r
294 json_object *json_rect;
\r
295 if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))
\r
297 HMI_ERROR("Parse Error!!");
\r
298 return WMError::FAIL;
\r
300 HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));
\r
302 struct rect area_size;
\r
303 area_size.x = jh::getIntFromJson(json_rect, "x");
\r
304 area_size.y = jh::getIntFromJson(json_rect, "y");
\r
305 area_size.w = jh::getIntFromJson(json_rect, "w");
\r
306 area_size.h = jh::getIntFromJson(json_rect, "h");
\r
308 this->area2size[area] = area_size;
\r
312 for (const auto& itr : this->area2size)
\r
314 HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
\r
315 itr.first.c_str(), itr.second.x, itr.second.y,
\r
316 itr.second.w, itr.second.h);
\r
319 // Release json_object
\r
320 json_object_put(json_obj);
\r
322 return WMError::SUCCESS;
\r
325 WMError LayerControl::layoutChange(const WMAction& action)
\r
327 WMError ret = WMError::FAIL;
\r
328 if (action.visible == TaskVisible::INVISIBLE)
\r
330 // Visibility is not change -> no redraw is required
\r
331 return WMError::SUCCESS;
\r
333 if(action.client == nullptr)
\r
335 HMI_SEQ_ERROR(action.req_num, "client may vanish");
\r
336 return WMError::NOT_REGISTERED;
\r
338 unsigned layer = action.client->layerID();
\r
341 // WMError ret = this->setLayerSize(layer, action.area);
\r
342 auto rect = this->getAreaSize(action.area);
\r
343 ilmErrorTypes err = ilm_layerSetDestinationRectangle(layer, rect.x, rect.y, rect.w, rect.h);
\r
344 if(err == ILM_SUCCESS)
\r
346 ret = WMError::SUCCESS;
\r
351 WMError LayerControl::visibilityChange(const WMAction& action)
\r
353 WMError ret = WMError::FAIL;
\r
354 if(action.client == nullptr)
\r
356 HMI_SEQ_ERROR(action.req_num, "client may vanish");
\r
357 return WMError::NOT_REGISTERED;
\r
360 if (action.visible != TaskVisible::INVISIBLE)
\r
362 ret = this->makeVisible(action.client);
\r
366 ret = this->makeInvisible(action.client);
\r
371 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
\r
374 if (ILM_SURFACE == object)
\r
378 ilmSurfaceProperties sp;
\r
380 rc = ilm_getPropertiesOfSurface(id, &sp);
\r
381 if(rc != ILM_SUCCESS)
\r
383 // this->cb->surfaceCreated(pid, id);
\r
384 ilm_surfaceAddNotification(id, surfaceCallback_static);
\r
385 ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
\r
389 // this->cb->surfaceDestroyed(id);
\r
392 if (ILM_LAYER == object)
\r
396 ilm_layerAddNotification(id, layerCallback_static);
\r
397 // this->cb->layerCreated(id);
\r
401 // this->cb->layerDestroyed(id); // Means Application is dead.
\r
406 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
407 struct ilmSurfaceProperties* sprop,
\r
408 t_ilm_notification_mask mask)
\r
410 pid_t pid = sprop->creatorPid;
\r
411 HMI_DEBUG("pid : %d", pid);
\r
413 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
415 //this->cb->surfaceVisibilityChanged(id, sprop->visibility);
\r
417 if (ILM_NOTIFICATION_OPACITY & mask)
\r
420 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
423 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
425 // this->cb->surfaceSourceRectChanged(id, )
\r
427 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
429 // this->cb->surfaceSourceRectChanged(id, )
\r
431 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
434 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
436 /* application being down */
\r
437 // m_appLayers.remove(pid);
\r
439 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
441 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
442 qDebug(" surfaceProperties %d", surface);
\r
443 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
444 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
446 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
447 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
448 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
450 ilmErrorTypes result;
\r
451 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
454 configureAppSurface(surface,
\r
455 surfaceProperties->origSourceWidth,
\r
456 surfaceProperties->origSourceHeight);
\r
458 result = ilm_layerAddSurface(layer, surface);
\r
459 if (result != ILM_SUCCESS) {
\r
460 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
462 ilm_commitChanges();
\r
469 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
470 struct ilmLayerProperties* lprop,
\r
471 t_ilm_notification_mask mask)
\r
473 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
475 //this->cb->layerVisibilityChanged(id, sprop->visibility);
\r
477 if (ILM_NOTIFICATION_OPACITY & mask)
\r
480 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
483 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
485 // this->cb->surfaceSourceRectChanged(id, )
\r
487 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
489 // this->cb->surfaceSourceRectChanged(id, )
\r
491 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
494 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
496 /* application being down */
\r
497 // m_appLayers.remove(pid);
\r
499 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
501 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
502 qDebug(" surfaceProperties %d", surface);
\r
503 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
504 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
506 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
507 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
508 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
510 ilmErrorTypes result;
\r
511 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
514 configureAppSurface(surface,
\r
515 surfaceProperties->origSourceWidth,
\r
516 surfaceProperties->origSourceHeight);
\r
518 result = ilm_layerAddSurface(layer, surface);
\r
519 if (result != ILM_SUCCESS) {
\r
520 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
522 ilm_commitChanges();
\r
529 WMError LayerControl::makeVisible(const shared_ptr<WMClient> client)
\r
531 WMError ret = WMError::FAIL;
\r
532 // Don't check here the client is not nullptr
\r
533 unsigned layer = client->layerID();
\r
534 bool contains;// = this->checkBackGround(action.client->role());
\r
537 shared_ptr<WMLayer> l;
\r
538 // Move background from back ground layer
\r
539 for(const auto& wm_layer : this->wm_layers)
\r
541 if(wm_layer->layerName() == "BackGroundLayer")
\r
543 //wm_layer.removeLayer(layer);
\r
547 if(wm_layer->checkIDBelongTo(layer))
\r
555 // make invisible first
\r
556 ilm_layerSetVisibility(layer, 0);
\r
557 ilm_commitChanges();
\r
558 //l->addLayer(layer);
\r
561 for(const auto& wm_layer : this->wm_layers)
\r
564 //l->makeVisible(layer);
\r
570 WMError LayerControl::makeInvisible(const shared_ptr<WMClient> client)
\r
572 WMError ret = WMError::FAIL;
\r
573 // Don't check here the client is not nullptr
\r
574 unsigned layer = client->layerID();
\r
575 bool contains;// = this->checkBackGround(client->role());
\r
578 // Pop from background
\r