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 WMError LayerControl::updateLayer(LayerState& layer_state)
\r
131 return WMError::SUCCESS;
\r
134 WMError LayerControl::commitChange()
\r
136 WMError rc = WMError::SUCCESS;
\r
137 vector<unsigned> ivi_l_ids;
\r
138 for(const auto& l : this->wm_layers)
\r
140 auto state = l->getLayerState();
\r
141 for(const auto& id : state.getIviIdList())
\r
143 ivi_l_ids.push_back(id);
\r
146 t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
\r
147 if(id_array == nullptr)
\r
149 HMI_WARNING("short memory");
\r
150 this->undoUpdate();
\r
151 return WMError::FAIL;
\r
154 for(const auto& i : ivi_l_ids)
\r
156 id_array[count] = i;
\r
159 ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
\r
160 if(ret != ILM_SUCCESS)
\r
162 this->undoUpdate();
\r
163 rc = WMError::FAIL;
\r
169 void LayerControl::undoUpdate() {}
\r
171 WMError LayerControl::loadLayerSetting(const string &path)
\r
173 HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);
\r
175 json_object *json_obj, *json_cfg;
\r
176 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
179 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
180 return WMError::FAIL;
\r
182 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
184 if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
\r
186 HMI_ERROR("Parse Error!!");
\r
187 return WMError::FAIL;
\r
190 int len = json_object_array_length(json_cfg);
\r
191 HMI_DEBUG("json_cfg len:%d", len);
\r
193 for (int i = 0; i < len; i++)
\r
195 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
196 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
198 this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));
\r
201 return WMError::SUCCESS;
\r
204 WMError LayerControl::loadAreaDb(const std::string& path)
\r
207 json_object *json_obj;
\r
208 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
\r
211 HMI_DEBUG("Could not open %s, so use default area information", path.c_str());
\r
212 return WMError::FAIL;
\r
214 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
\r
217 json_object *json_cfg;
\r
218 if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))
\r
220 HMI_ERROR("Parse Error!!");
\r
221 return WMError::FAIL;
\r
224 int len = json_object_array_length(json_cfg);
\r
225 HMI_DEBUG("json_cfg len:%d", len);
\r
228 for (int i = 0; i < len; i++)
\r
230 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
\r
231 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
\r
233 area = jh::getStringFromJson(json_tmp, "name");
\r
234 if (nullptr == area)
\r
236 HMI_ERROR("Parse Error!!");
\r
237 return WMError::FAIL;
\r
239 HMI_DEBUG("> area:%s", area);
\r
241 json_object *json_rect;
\r
242 if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))
\r
244 HMI_ERROR("Parse Error!!");
\r
245 return WMError::FAIL;
\r
247 HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));
\r
249 struct rect area_size;
\r
250 area_size.x = jh::getIntFromJson(json_rect, "x");
\r
251 area_size.y = jh::getIntFromJson(json_rect, "y");
\r
252 area_size.w = jh::getIntFromJson(json_rect, "w");
\r
253 area_size.h = jh::getIntFromJson(json_rect, "h");
\r
255 this->area2size[area] = area_size;
\r
259 for (const auto& itr : this->area2size)
\r
261 HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
\r
262 itr.first.c_str(), itr.second.x, itr.second.y,
\r
263 itr.second.w, itr.second.h);
\r
266 // Release json_object
\r
267 json_object_put(json_obj);
\r
269 return WMError::SUCCESS;
\r
272 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
\r
275 if (ILM_SURFACE == object)
\r
279 ilmSurfaceProperties sp;
\r
281 rc = ilm_getPropertiesOfSurface(id, &sp);
\r
282 if(rc != ILM_SUCCESS)
\r
284 // this->cb->surfaceCreated(pid, id);
\r
285 ilm_surfaceAddNotification(id, surfaceCallback_static);
\r
286 ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
\r
290 // this->cb->surfaceDestroyed(id);
\r
293 if (ILM_LAYER == object)
\r
297 ilm_layerAddNotification(id, layerCallback_static);
\r
298 // this->cb->layerCreated(id);
\r
302 // this->cb->layerDestroyed(id); // Means Application is dead.
\r
307 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
308 struct ilmSurfaceProperties* sprop,
\r
309 t_ilm_notification_mask mask)
\r
311 pid_t pid = sprop->creatorPid;
\r
312 HMI_DEBUG("pid : %d", pid);
\r
314 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
316 //this->cb->surfaceVisibilityChanged(id, sprop->visibility);
\r
318 if (ILM_NOTIFICATION_OPACITY & mask)
\r
321 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
324 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
326 // this->cb->surfaceSourceRectChanged(id, )
\r
328 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
330 // this->cb->surfaceSourceRectChanged(id, )
\r
332 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
335 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
337 /* application being down */
\r
338 // m_appLayers.remove(pid);
\r
340 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
342 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
343 qDebug(" surfaceProperties %d", surface);
\r
344 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
345 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
347 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
348 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
349 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
351 ilmErrorTypes result;
\r
352 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
355 configureAppSurface(surface,
\r
356 surfaceProperties->origSourceWidth,
\r
357 surfaceProperties->origSourceHeight);
\r
359 result = ilm_layerAddSurface(layer, surface);
\r
360 if (result != ILM_SUCCESS) {
\r
361 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
363 ilm_commitChanges();
\r
370 void LayerControl::dispatchPropertyChangeEvent(unsigned id,
\r
371 struct ilmLayerProperties* lprop,
\r
372 t_ilm_notification_mask mask)
\r
374 if (ILM_NOTIFICATION_VISIBILITY & mask)
\r
376 //this->cb->layerVisibilityChanged(id, sprop->visibility);
\r
378 if (ILM_NOTIFICATION_OPACITY & mask)
\r
381 if (ILM_NOTIFICATION_ORIENTATION & mask)
\r
384 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
\r
386 // this->cb->surfaceSourceRectChanged(id, )
\r
388 if (ILM_NOTIFICATION_DEST_RECT & mask)
\r
390 // this->cb->surfaceSourceRectChanged(id, )
\r
392 if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
\r
395 if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
\r
397 /* application being down */
\r
398 // m_appLayers.remove(pid);
\r
400 if (ILM_NOTIFICATION_CONFIGURED & mask)
\r
402 /* qDebug("ILM_NOTIFICATION_CONFIGURED");
\r
403 qDebug(" surfaceProperties %d", surface);
\r
404 qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
\r
405 qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
\r
407 if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
\r
408 addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
\r
409 configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
\r
411 ilmErrorTypes result;
\r
412 t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
\r
415 configureAppSurface(surface,
\r
416 surfaceProperties->origSourceWidth,
\r
417 surfaceProperties->origSourceHeight);
\r
419 result = ilm_layerAddSurface(layer, surface);
\r
420 if (result != ILM_SUCCESS) {
\r
421 qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
\r
423 ilm_commitChanges();
\r