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
33 LayerControl* g_lc_ctxt;
\r
35 static void createCallback_static(ilmObjectType object,
\r
40 static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);
\r
43 static void surfaceCallback_static(t_ilm_surface surface,
\r
44 struct ilmSurfaceProperties* surface_prop,
\r
45 t_ilm_notification_mask mask)
\r
47 g_lc_ctxt->dispatchPropertyChangeEvent(surface, surface_prop, mask);
\r
50 static void layerCallback_static(t_ilm_layer layer,
\r
51 struct ilmLayerProperties* layer_prop,
\r
52 t_ilm_notification_mask mask)
\r
54 g_lc_ctxt->dispatchPropertyChangeEvent(layer, layer_prop, mask);
\r
57 LayerControl::LayerControl(const std::string& root)
\r
59 string area_path = root + LC_AREA_PATH;
\r
60 string layer_path= root + LC_LAYER_SETTING_PATH;
\r
61 // load layers.setting.json
\r
62 WMError ret = this->loadLayerSetting(layer_path);
\r
63 assert(ret == WMError::SUCCESS);
\r
65 ret = this->loadAreaDb(area_path);
\r
66 assert(ret == WMError::SUCCESS);
\r
69 WMError LayerControl::init(const LayerControlCallbacks& cb)
\r
71 ilmErrorTypes rc = ilm_init();
\r
76 while (rc != ILM_SUCCESS)
\r
81 HMI_ERROR("Could not connect to compositor");
\r
84 HMI_ERROR("Wait to start weston ...");
\r
88 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
90 // Get current screen setting
\r
91 rc = ilm_getScreenIDs(&num, &ids);
\r
93 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
95 for(unsigned i = 0; i < num; i++)
\r
97 HMI_INFO("get screen: %d", ids[i]);
\r
99 // Currently, 0 is only available
\r
100 this->screenID = ids[0];
\r
102 rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);
\r
104 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
106 // Register Callback from ILM
\r
108 ilm_registerNotification(createCallback_static, this);
\r
110 return WMError::SUCCESS;
\r
113 HMI_ERROR("Failed to initialize. Terminate WM");
\r
115 return WMError::FAIL;
\r
118 void LayerControl::createNewLayer(unsigned id)
\r
120 HMI_INFO("create new ID :%d", id);
\r
121 struct rect rct = this->area2size[LC_DEFAULT_AREA];
\r
122 ilm_layerCreateWithDimension(&id, rct.w, rct.h);
\r
123 ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);
\r
124 ilm_layerSetDestinationRectangle(id, rct.x, rct.y, rct.w, rct.h);
\r
125 ilm_layerSetOpacity(id, 1.0);
\r
126 ilm_layerSetVisibility(id, ILM_TRUE);
\r
127 ilm_commitChanges();
\r
130 unsigned LayerControl::getNewLayerID(const string& role, string* layer_name)
\r
133 for(const auto& l: this->wm_layers)
\r
135 ret = l->getNewLayerID(role);
\r
138 *layer_name = l->layerName();
\r
145 struct rect LayerControl::getAreaSize(const std::string& area)
\r
147 return area2size[area];
\r
150 void LayerControl::setupArea(double scaling)
\r
153 this->scaling = scaling;
\r
155 rct = this->area2size["normal.full"];
\r
156 this->area2size["normalfull"] = rct;
\r
157 this->area2size["normal"] = rct;
\r
159 for (auto &i : this->area2size)
\r
161 i.second.x = static_cast<int>(scaling * i.second.x + 0.5);
\r
162 i.second.y = static_cast<int>(scaling * i.second.y + 0.5);
\r
163 i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
\r
164 i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
\r
166 HMI_DEBUG("wm:lm", "area:%s size(after) : x:%d y:%d w:%d h:%d",
\r
167 i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
\r
171 Screen LayerControl::getScreenInfo()
\r
173 return Screen(this->screen_prop.screenWidth, this->screen_prop.screenHeight);
\r
176 double LayerControl::scale()
\r
178 return this->scaling;
\r
181 WMError LayerControl::updateLayer(LayerState& layer_state)
\r
183 return WMError::SUCCESS;
\r
186 WMError LayerControl::commitChange()
\r
188 WMError rc = WMError::SUCCESS;
\r
189 vector<unsigned> ivi_l_ids;
\r
190 for(const auto& l : this->wm_layers)
\r
192 auto state = l->getLayerState();
\r
193 for(const auto& id : state.getIviIdList())
\r
195 ivi_l_ids.push_back(id);
\r
198 t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
\r
199 if(id_array == nullptr)
\r
201 HMI_WARNING("short memory");
\r
202 this->undoUpdate();
\r
203 return WMError::FAIL;
\r
206 for(const auto& i : ivi_l_ids)
\r
208 id_array[count] = i;
\r
211 ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
\r
212 if(ret != ILM_SUCCESS)
\r
214 this->undoUpdate();
\r
215 rc = WMError::FAIL;
\r
221 void LayerControl::undoUpdate() {}
\r
223 WMError LayerControl::loadLayerSetting(const string &path)
\r
225 HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);
\r
227 json_object *json_obj, *json_cfg;
\r
228 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
231 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
232 return WMError::FAIL;
\r
234 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
236 if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
\r
238 HMI_ERROR("Parse Error!!");
\r
239 return WMError::FAIL;
\r
242 int len = json_object_array_length(json_cfg);
\r
243 HMI_DEBUG("json_cfg len:%d", len);
\r
245 for (int i = 0; i < len; i++)
\r
247 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
248 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
250 this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));
\r
253 return WMError::SUCCESS;
\r
256 WMError LayerControl::loadAreaDb(const std::string& path)
\r
259 json_object *json_obj;
\r
260 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
263 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
264 return WMError::FAIL;
\r
266 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
269 json_object *json_cfg;
\r
270 if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))
\r
272 HMI_ERROR("Parse Error!!");
\r
273 return WMError::FAIL;
\r
276 int len = json_object_array_length(json_cfg);
\r
277 HMI_DEBUG("json_cfg len:%d", len);
\r
280 for (int i = 0; i < len; i++)
\r
282 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
283 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
285 area = jh::getStringFromJson(json_tmp, "name");
\r
286 if (nullptr == area)
\r
288 HMI_ERROR("Parse Error!!");
\r
289 return WMError::FAIL;
\r
291 HMI_DEBUG("> area:%s", area);
\r
293 json_object *json_rect;
\r
294 if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))
\r
296 HMI_ERROR("Parse Error!!");
\r
297 return WMError::FAIL;
\r
299 HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));
\r
301 struct rect area_size;
\r
302 area_size.x = jh::getIntFromJson(json_rect, "x");
\r
303 area_size.y = jh::getIntFromJson(json_rect, "y");
\r
304 area_size.w = jh::getIntFromJson(json_rect, "w");
\r
305 area_size.h = jh::getIntFromJson(json_rect, "h");
\r
307 this->area2size[area] = area_size;
\r
311 for (const auto& itr : this->area2size)
\r
313 HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
\r
314 itr.first.c_str(), itr.second.x, itr.second.y,
\r
315 itr.second.w, itr.second.h);
\r
318 // Release json_object
\r
319 json_object_put(json_obj);
\r
321 return WMError::SUCCESS;
\r
324 WMError LayerControl::layoutChange(const WMAction& action)
\r
326 WMError ret = WMError::FAIL;
\r
327 if (action.visible == TaskVisible::INVISIBLE)
\r
329 // Visibility is not change -> no redraw is required
\r
330 return WMError::SUCCESS;
\r
332 if(action.client == nullptr)
\r
334 HMI_SEQ_ERROR(action.req_num, "client may vanish");
\r
335 return WMError::NOT_REGISTERED;
\r
337 unsigned layer = action.client->layerID();
\r
340 // WMError ret = this->setLayerSize(layer, action.area);
\r
341 auto rect = this->getAreaSize(action.area);
\r
342 ilmErrorTypes err = ilm_layerSetDestinationRectangle(layer, rect.x, rect.y, rect.w, rect.h);
\r
343 if(err == ILM_SUCCESS)
\r
345 ret = WMError::SUCCESS;
\r
350 WMError LayerControl::visibilityChange(const WMAction& action)
\r
352 WMError ret = WMError::FAIL;
\r
353 if(action.client == nullptr)
\r
355 HMI_SEQ_ERROR(action.req_num, "client may vanish");
\r
356 return WMError::NOT_REGISTERED;
\r
359 if (action.visible != TaskVisible::INVISIBLE)
\r
361 ret = this->makeVisible(action.client.get());
\r
365 ret = this->makeInvisible(action.client.get());
\r
370 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
\r
373 if (ILM_SURFACE == object)
\r
377 ilmSurfaceProperties sp;
\r
379 rc = ilm_getPropertiesOfSurface(id, &sp);
\r
380 if(rc != ILM_SUCCESS)
\r
382 // this->cb->surfaceCreated(pid, id);
\r
383 ilm_surfaceAddNotification(id, surfaceCallback_static);
\r
384 ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
\r
388 // this->cb->surfaceDestroyed(id);
\r
391 if (ILM_LAYER == object)
\r
395 ilm_layerAddNotification(id, layerCallback_static);
\r
396 // this->cb->layerCreated(id);
\r
400 // this->cb->layerDestroyed(id); // Means Application is dead.
\r
405 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
406 struct ilmSurfaceProperties* sprop,
\r
407 t_ilm_notification_mask mask)
\r
409 pid_t pid = sprop->creatorPid;
\r
410 HMI_DEBUG("pid : %d", pid);
\r
412 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
414 //this->cb->surfaceVisibilityChanged(id, sprop->visibility);
\r
416 if (ILM_NOTIFICATION_OPACITY & mask)
\r
419 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
422 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
424 // this->cb->surfaceSourceRectChanged(id, )
\r
426 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
428 // this->cb->surfaceSourceRectChanged(id, )
\r
430 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
433 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
435 /* application being down */
\r
436 // m_appLayers.remove(pid);
\r
438 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
440 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
441 qDebug(" surfaceProperties %d", surface);
\r
442 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
443 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
445 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
446 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
447 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
449 ilmErrorTypes result;
\r
450 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
453 configureAppSurface(surface,
\r
454 surfaceProperties->origSourceWidth,
\r
455 surfaceProperties->origSourceHeight);
\r
457 result = ilm_layerAddSurface(layer, surface);
\r
458 if (result != ILM_SUCCESS) {
\r
459 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
461 ilm_commitChanges();
\r
468 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
469 struct ilmLayerProperties* lprop,
\r
470 t_ilm_notification_mask mask)
\r
472 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
474 //this->cb->layerVisibilityChanged(id, sprop->visibility);
\r
476 if (ILM_NOTIFICATION_OPACITY & mask)
\r
479 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
482 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
484 // this->cb->surfaceSourceRectChanged(id, )
\r
486 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
488 // this->cb->surfaceSourceRectChanged(id, )
\r
490 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
493 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
495 /* application being down */
\r
496 // m_appLayers.remove(pid);
\r
498 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
500 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
501 qDebug(" surfaceProperties %d", surface);
\r
502 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
503 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
505 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
506 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
507 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
509 ilmErrorTypes result;
\r
510 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
513 configureAppSurface(surface,
\r
514 surfaceProperties->origSourceWidth,
\r
515 surfaceProperties->origSourceHeight);
\r
517 result = ilm_layerAddSurface(layer, surface);
\r
518 if (result != ILM_SUCCESS) {
\r
519 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
521 ilm_commitChanges();
\r
528 WMError LayerControl::makeVisible(const WMClient* client)
\r
530 WMError ret = WMError::FAIL;
\r
531 // Don't check here the client is not nullptr
\r
532 unsigned layer = client->layerID();
\r
533 bool contains;// = this->checkBackGround(action.client->role());
\r
536 std::shared_ptr<WMLayer> l;
\r
537 // Move background from back ground layer
\r
538 for(const auto& wm_layer : this->wm_layers)
\r
540 if(wm_layer->layerName() == "BackGroundLayer")
\r
542 //wm_layer.removeLayer(layer);
\r
546 if(wm_layer->checkIDBelongTo(layer))
\r
554 // make invisible first
\r
555 ilm_layerSetVisibility(layer, 0);
\r
556 ilm_commitChanges();
\r
557 //l->addLayer(layer);
\r
560 for(const auto& wm_layer : this->wm_layers)
\r
563 //l->makeVisible(layer);
\r
569 WMError LayerControl::makeInvisible(const WMClient* client)
\r
571 WMError ret = WMError::FAIL;
\r
572 // Don't check here the client is not nullptr
\r
573 unsigned layer = client->layerID();
\r
574 bool contains;// = this->checkBackGround(client->role());
\r
577 // Pop from background
\r