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
24 #define LC_DEFAULT_AREA "normal.full"
\r
31 LayerControl* g_lc_ctxt;
\r
33 static void createCallback_static(ilmObjectType object,
\r
38 static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);
\r
41 static void surfaceCallback_static(t_ilm_surface surface,
\r
42 struct ilmSurfaceProperties* surface_prop,
\r
43 t_ilm_notification_mask mask)
\r
45 g_lc_ctxt->dispatchPropertyChangeEvent(surface, surface_prop, mask);
\r
48 static void layerCallback_static(t_ilm_layer layer,
\r
49 struct ilmLayerProperties* layer_prop,
\r
50 t_ilm_notification_mask mask)
\r
52 g_lc_ctxt->dispatchPropertyChangeEvent(layer, layer_prop, mask);
\r
55 LayerControl::LayerControl(const std::string& root)
\r
57 string area_path = root + LC_AREA_PATH;
\r
58 string layer_path= root + LC_LAYER_SETTING_PATH;
\r
59 // load layers.setting.json
\r
60 WMError ret = this->loadLayerSetting(layer_path);
\r
61 assert(ret == WMError::SUCCESS);
\r
63 ret = this->loadAreaDb(area_path);
\r
64 assert(ret == WMError::SUCCESS);
\r
67 WMError LayerControl::init(const LayerControlCallbacks& cb)
\r
69 ilmErrorTypes rc = ilm_init();
\r
74 while (rc != ILM_SUCCESS)
\r
79 HMI_ERROR("Could not connect to compositor");
\r
82 HMI_ERROR("Wait to start weston ...");
\r
86 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
88 // Get current screen setting
\r
89 rc = ilm_getScreenIDs(&num, &ids);
\r
91 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
93 for(unsigned i = 0; i < num; i++)
\r
95 HMI_INFO("get screen: %d", ids[i]);
\r
97 // Currently, 0 is only available
\r
98 this->screenID = ids[0];
\r
100 rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);
\r
102 if(rc != ILM_SUCCESS) goto lc_init_error;
\r
104 // Register Callback from ILM
\r
106 ilm_registerNotification(createCallback_static, this);
\r
108 return WMError::SUCCESS;
\r
111 HMI_ERROR("Failed to initialize. Terminate WM");
\r
113 return WMError::FAIL;
\r
116 void LayerControl::createNewLayer(unsigned id)
\r
118 HMI_INFO("create new ID :%d", id);
\r
119 struct rect rct = this->area2size[LC_DEFAULT_AREA];
\r
120 ilm_layerCreateWithDimension(&id, rct.w, rct.h);
\r
121 ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);
\r
122 ilm_layerSetDestinationRectangle(id, rct.x, rct.y, rct.w, rct.h);
\r
123 ilm_layerSetOpacity(id, 1.0);
\r
124 ilm_layerSetVisibility(id, ILM_TRUE);
\r
125 ilm_commitChanges();
\r
128 unsigned LayerControl::getNewLayerID(const string& role, string* layer_name)
\r
131 for(const auto& l: this->wm_layers)
\r
133 ret = l->getNewLayerID(role);
\r
136 *layer_name = l->layerName();
\r
143 struct rect LayerControl::getAreaSize(const std::string& area)
\r
145 return area2size[area];
\r
148 void LayerControl::setupArea(double scaling)
\r
151 this->scaling = scaling;
\r
153 rct = this->area2size["normal.full"];
\r
154 this->area2size["normalfull"] = rct;
\r
155 this->area2size["normal"] = rct;
\r
157 for (auto &i : this->area2size)
\r
159 i.second.x = static_cast<int>(scaling * i.second.x + 0.5);
\r
160 i.second.y = static_cast<int>(scaling * i.second.y + 0.5);
\r
161 i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
\r
162 i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
\r
164 HMI_DEBUG("wm:lm", "area:%s size(after) : x:%d y:%d w:%d h:%d",
\r
165 i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
\r
169 Screen LayerControl::getScreenInfo()
\r
171 return Screen(this->screen_prop.screenWidth, this->screen_prop.screenHeight);
\r
174 double LayerControl::scale()
\r
176 return this->scaling;
\r
179 WMError LayerControl::updateLayer(LayerState& layer_state)
\r
181 return WMError::SUCCESS;
\r
184 WMError LayerControl::commitChange()
\r
186 WMError rc = WMError::SUCCESS;
\r
187 vector<unsigned> ivi_l_ids;
\r
188 for(const auto& l : this->wm_layers)
\r
190 auto state = l->getLayerState();
\r
191 for(const auto& id : state.getIviIdList())
\r
193 ivi_l_ids.push_back(id);
\r
196 t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
\r
197 if(id_array == nullptr)
\r
199 HMI_WARNING("short memory");
\r
200 this->undoUpdate();
\r
201 return WMError::FAIL;
\r
204 for(const auto& i : ivi_l_ids)
\r
206 id_array[count] = i;
\r
209 ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
\r
210 if(ret != ILM_SUCCESS)
\r
212 this->undoUpdate();
\r
213 rc = WMError::FAIL;
\r
219 void LayerControl::undoUpdate() {}
\r
221 WMError LayerControl::loadLayerSetting(const string &path)
\r
223 HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);
\r
225 json_object *json_obj, *json_cfg;
\r
226 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
229 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
230 return WMError::FAIL;
\r
232 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
234 if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
\r
236 HMI_ERROR("Parse Error!!");
\r
237 return WMError::FAIL;
\r
240 int len = json_object_array_length(json_cfg);
\r
241 HMI_DEBUG("json_cfg len:%d", len);
\r
243 for (int i = 0; i < len; i++)
\r
245 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
246 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
248 this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));
\r
251 return WMError::SUCCESS;
\r
254 WMError LayerControl::loadAreaDb(const std::string& path)
\r
257 json_object *json_obj;
\r
258 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
261 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
262 return WMError::FAIL;
\r
264 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
267 json_object *json_cfg;
\r
268 if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))
\r
270 HMI_ERROR("Parse Error!!");
\r
271 return WMError::FAIL;
\r
274 int len = json_object_array_length(json_cfg);
\r
275 HMI_DEBUG("json_cfg len:%d", len);
\r
278 for (int i = 0; i < len; i++)
\r
280 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
281 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
283 area = jh::getStringFromJson(json_tmp, "name");
\r
284 if (nullptr == area)
\r
286 HMI_ERROR("Parse Error!!");
\r
287 return WMError::FAIL;
\r
289 HMI_DEBUG("> area:%s", area);
\r
291 json_object *json_rect;
\r
292 if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))
\r
294 HMI_ERROR("Parse Error!!");
\r
295 return WMError::FAIL;
\r
297 HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));
\r
299 struct rect area_size;
\r
300 area_size.x = jh::getIntFromJson(json_rect, "x");
\r
301 area_size.y = jh::getIntFromJson(json_rect, "y");
\r
302 area_size.w = jh::getIntFromJson(json_rect, "w");
\r
303 area_size.h = jh::getIntFromJson(json_rect, "h");
\r
305 this->area2size[area] = area_size;
\r
309 for (const auto& itr : this->area2size)
\r
311 HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
\r
312 itr.first.c_str(), itr.second.x, itr.second.y,
\r
313 itr.second.w, itr.second.h);
\r
316 // Release json_object
\r
317 json_object_put(json_obj);
\r
319 return WMError::SUCCESS;
\r
322 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
\r
325 if (ILM_SURFACE == object)
\r
329 ilmSurfaceProperties sp;
\r
331 rc = ilm_getPropertiesOfSurface(id, &sp);
\r
332 if(rc != ILM_SUCCESS)
\r
334 // this->cb->surfaceCreated(pid, id);
\r
335 ilm_surfaceAddNotification(id, surfaceCallback_static);
\r
336 ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
\r
340 // this->cb->surfaceDestroyed(id);
\r
343 if (ILM_LAYER == object)
\r
347 ilm_layerAddNotification(id, layerCallback_static);
\r
348 // this->cb->layerCreated(id);
\r
352 // this->cb->layerDestroyed(id); // Means Application is dead.
\r
357 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
358 struct ilmSurfaceProperties* sprop,
\r
359 t_ilm_notification_mask mask)
\r
361 pid_t pid = sprop->creatorPid;
\r
362 HMI_DEBUG("pid : %d", pid);
\r
364 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
366 //this->cb->surfaceVisibilityChanged(id, sprop->visibility);
\r
368 if (ILM_NOTIFICATION_OPACITY & mask)
\r
371 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
374 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
376 // this->cb->surfaceSourceRectChanged(id, )
\r
378 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
380 // this->cb->surfaceSourceRectChanged(id, )
\r
382 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
385 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
387 /* application being down */
\r
388 // m_appLayers.remove(pid);
\r
390 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
392 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
393 qDebug(" surfaceProperties %d", surface);
\r
394 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
395 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
397 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
398 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
399 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
401 ilmErrorTypes result;
\r
402 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
405 configureAppSurface(surface,
\r
406 surfaceProperties->origSourceWidth,
\r
407 surfaceProperties->origSourceHeight);
\r
409 result = ilm_layerAddSurface(layer, surface);
\r
410 if (result != ILM_SUCCESS) {
\r
411 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
413 ilm_commitChanges();
\r
420 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
421 struct ilmLayerProperties* lprop,
\r
422 t_ilm_notification_mask mask)
\r
424 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
426 //this->cb->layerVisibilityChanged(id, sprop->visibility);
\r
428 if (ILM_NOTIFICATION_OPACITY & mask)
\r
431 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
434 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
436 // this->cb->surfaceSourceRectChanged(id, )
\r
438 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
440 // this->cb->surfaceSourceRectChanged(id, )
\r
442 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
445 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
447 /* application being down */
\r
448 // m_appLayers.remove(pid);
\r
450 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
452 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
453 qDebug(" surfaceProperties %d", surface);
\r
454 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
455 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
457 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
458 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
459 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
461 ilmErrorTypes result;
\r
462 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
465 configureAppSurface(surface,
\r
466 surfaceProperties->origSourceWidth,
\r
467 surfaceProperties->origSourceHeight);
\r
469 result = ilm_layerAddSurface(layer, surface);
\r
470 if (result != ILM_SUCCESS) {
\r
471 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
473 ilm_commitChanges();
\r