2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "wm_layer_control.hpp"
19 #include "wm_layer.hpp"
20 #include "wm_client.hpp"
21 #include "request.hpp"
22 #include "json_helper.hpp"
24 #define LC_AREA_PATH "/etc/areas.json"
25 #define LC_LAYER_SETTING_PATH "/etc/layers_setting.json"
26 #define LC_DEFAULT_AREA "fullscreen"
27 #define BACK_GROUND_LAYER "BackGroundLayer"
31 using std::shared_ptr;
35 LayerControl* g_lc_ctxt;
37 static void createCallback_static(ilmObjectType object,
42 static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);
45 static void surfaceCallback_static(t_ilm_surface surface,
46 struct ilmSurfaceProperties* surface_prop,
47 t_ilm_notification_mask mask)
49 g_lc_ctxt->dispatchSurfacePropChangeEvent(surface, surface_prop, mask);
52 static void layerCallback_static(t_ilm_layer layer,
53 struct ilmLayerProperties* layer_prop,
54 t_ilm_notification_mask mask)
56 g_lc_ctxt->dispatchLayerPropChangeEvent(layer, layer_prop, mask);
59 LayerControl::LayerControl(const std::string& root, const std::string& ecu_name)
61 string area_path = root + LC_AREA_PATH;
62 string layer_path= root + LC_LAYER_SETTING_PATH;
63 // load layers.setting.json
64 WMError ret = this->loadLayerSetting(layer_path);
65 assert(ret == WMError::SUCCESS);
67 ret = this->loadAreasConfigFile(area_path, ecu_name);
68 assert(ret == WMError::SUCCESS);
71 WMError LayerControl::init(const LayerControlCallbacks& cb)
73 HMI_DEBUG("Initialize of ilm library and display");
77 ilmErrorTypes rc = ilm_init();
79 while (rc != ILM_SUCCESS)
84 HMI_ERROR("Could not connect to compositor");
87 HMI_ERROR("Wait to start weston ...");
91 if(rc != ILM_SUCCESS) goto lc_init_error;
93 // Get current screen setting
94 rc = ilm_getScreenIDs(&num, &ids);
96 if(rc != ILM_SUCCESS) goto lc_init_error;
98 for(unsigned i = 0; i < num; i++)
100 HMI_INFO("get screen: %d", ids[i]);
102 // Currently, 0 is only available
103 this->screenID = ids[0];
107 // TODO: set remote screen id
108 HMI_INFO("There is remote screen (id:%d)", ids[1]);
109 this->remoteScreenID = ids[1];
113 HMI_INFO("There is no remote screen");
114 this->remoteScreenID = -1;
117 rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);
119 if(rc != ILM_SUCCESS) goto lc_init_error;
121 // Register Callback to Window Manager and from ILM
123 ilm_registerNotification(createCallback_static, this);
125 return WMError::SUCCESS;
128 HMI_ERROR("Failed to initialize. Terminate WM");
130 return WMError::FAIL;
133 void LayerControl::createNewLayer(unsigned id)
135 HMI_INFO("create new ID :%d", id);
136 struct rect rct = this->area2size[LC_DEFAULT_AREA];
137 ilm_layerCreateWithDimension(&id, rct.w, rct.h);
138 //ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);
139 ilm_layerSetDestinationRectangle(id, this->offset_x, this->offset_y, rct.w, rct.h);
140 ilm_layerSetOpacity(id, 1.0);
141 ilm_layerSetVisibility(id, ILM_FALSE);
143 auto wm_layer = getWMLayer(id);
144 wm_layer->addLayerToState(id);
145 this->renderLayers();
146 this->renderLayersRemote();
149 void LayerControl::createNewRemoteLayer(unsigned id)
151 HMI_INFO("create new ID :%d (For remote layer)", id);
152 struct rect rct = {640, 720, 0, 0};
153 ilm_layerCreateWithDimension(&id, rct.w, rct.h);
154 //ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);
155 ilm_layerSetDestinationRectangle(id, this->offset_x, this->offset_y, rct.w, rct.h);
156 ilm_layerSetOpacity(id, 1.0);
157 ilm_layerSetVisibility(id, ILM_FALSE);
159 auto wm_layer = getWMLayer(id);
160 wm_layer->addLayerToState(id);
161 this->renderLayers();
162 this->renderLayersRemote();
165 unsigned LayerControl::getNewLayerID(const string& role, string* layer_name)
168 for(const auto& l: this->wm_layers)
170 ret = l->getNewLayerID(role);
173 *layer_name = l->layerName();
174 unsigned uid = l->getUuid();
175 this->lid2wmlid[ret] = uid;
182 shared_ptr<WMLayer> LayerControl::getWMLayer(unsigned layer)
184 unsigned uuid = this->lid2wmlid[layer];
185 return this->wm_layers[uuid];
188 std::shared_ptr<WMLayer> LayerControl::getWMLayer(std::string layer_name)
190 for(auto &l : this->wm_layers)
192 if(l->layerName() == layer_name)
200 struct rect LayerControl::getAreaSize(const std::string& area)
202 return area2size[area];
205 void LayerControl::setupArea(const rectangle& base_rct, double scaling)
207 this->scaling = scaling;
208 this->offset_x = base_rct.left();
209 this->offset_y = base_rct.top();
211 for (auto &i : this->area2size)
213 i.second.x = static_cast<int>(scaling * i.second.x + 0.5);
214 i.second.y = static_cast<int>(scaling * i.second.y + 0.5);
215 i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
216 i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
218 HMI_DEBUG("area:%s size(after) : x:%d y:%d w:%d h:%d",
219 i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
223 Screen LayerControl::getScreenInfo()
225 return Screen(this->screen_prop.screenWidth, this->screen_prop.screenHeight);
228 double LayerControl::scale()
230 return this->scaling;
233 WMError LayerControl::updateLayer(LayerState& layer_state)
235 return WMError::SUCCESS;
238 WMError LayerControl::renderLayers()
240 HMI_INFO("Commit change");
241 WMError rc = WMError::SUCCESS;
243 // Check the number of layers
244 vector<unsigned> ivi_l_ids;
245 for(auto& l : this->wm_layers)
247 auto state = l->getLayerState();
248 HMI_DEBUG("layer %s", l->layerName().c_str());
249 for(const auto& id : state.getIviIdList())
251 HMI_DEBUG("Add %d", id);
252 ivi_l_ids.push_back(id);
256 // Create render order
257 t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
258 if(id_array == nullptr)
260 HMI_WARNING("short memory");
262 return WMError::FAIL;
265 for(const auto& i : ivi_l_ids)
272 ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
273 if(ret != ILM_SUCCESS)
280 for(auto& l : this->wm_layers)
290 WMError LayerControl::renderLayersRemote()
292 HMI_INFO("Commit change");
293 WMError rc = WMError::SUCCESS;
295 if (0 > this->remoteScreenID)
300 // Check the number of layers
301 vector<unsigned> ivi_l_ids;
302 for(auto& l : this->wm_remote_layers)
304 auto state = l->getLayerState();
305 HMI_DEBUG("layer %s", l->layerName().c_str());
306 for(const auto& id : state.getIviIdList())
308 HMI_DEBUG("Add %d", id);
309 ivi_l_ids.push_back(id);
313 if (0 == ivi_l_ids.size())
315 ilm_displaySetRenderOrder(this->remoteScreenID, nullptr, 0);
319 // Create render order
320 t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
321 if(id_array == nullptr)
323 HMI_WARNING("short memory");
325 return WMError::FAIL;
328 for(const auto& i : ivi_l_ids)
335 ilmErrorTypes ret = ilm_displaySetRenderOrder(this->remoteScreenID, id_array, ivi_l_ids.size());
336 if(ret != ILM_SUCCESS)
343 for(auto& l : this->wm_remote_layers)
353 WMError LayerControl::setXDGSurfaceOriginSize(unsigned surface)
355 WMError ret = WMError::NOT_REGISTERED;
356 ilmSurfaceProperties prop;
357 ilmErrorTypes rc = ilm_getPropertiesOfSurface(surface, &prop);
358 if(rc == ILM_SUCCESS)
360 HMI_INFO("xdg surface info %d, %d", prop.origSourceWidth, prop.origSourceHeight);
361 ilm_surfaceSetSourceRectangle(surface, 0, 0, prop.origSourceWidth, prop.origSourceHeight);
362 ret = WMError::SUCCESS;
368 void LayerControl::undoUpdate()
370 for(auto& l : this->wm_layers)
376 WMError LayerControl::loadLayerSetting(const string &path)
378 HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path);
380 json_object *json_obj, *json_cfg;
381 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
384 HMI_ERROR("Could not open %s", path.c_str());
385 return WMError::FAIL;
387 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
389 if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
391 HMI_ERROR("Parse Error!!");
392 return WMError::FAIL;
395 int len = json_object_array_length(json_cfg);
396 HMI_DEBUG("json_cfg len:%d", len);
398 for (int i = 0; i < len; i++)
400 json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
401 HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
403 this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp, i));
405 json_object_put(json_obj);
407 return WMError::SUCCESS;
410 WMError LayerControl::loadAreasConfigFile(const std::string& path, const std::string& ecu_name)
412 // Load areas config file
413 json_object *json_obj;
414 int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
417 HMI_ERROR("Could not open %s", path.c_str());
418 return WMError::FAIL;
420 HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
423 json_object *json_cfg;
424 if (!json_object_object_get_ex(json_obj, "ecus", &json_cfg))
426 HMI_ERROR("Parse Error!!");
427 return WMError::FAIL;
430 int num_ecu = json_object_array_length(json_cfg);
431 HMI_DEBUG("json_cfg(ecus) len:%d", num_ecu);
433 const char* c_ecu_name;
434 json_object *json_ecu;
435 for (int i = 0; i < num_ecu; i++)
437 json_ecu= json_object_array_get_idx(json_cfg, i);
439 c_ecu_name = jh::getStringFromJson(json_ecu, "name");
440 if (nullptr == c_ecu_name)
442 HMI_ERROR("Parse Error!!");
443 return WMError::FAIL;
446 if (ecu_name == string(c_ecu_name))
458 HMI_ERROR("Areas for ecu:%s is NOT exist!!", ecu_name.c_str());
459 return WMError::FAIL;
463 if (!json_object_object_get_ex(json_ecu, "screens", &json_cfg))
465 HMI_ERROR("Parse Error!!");
466 return WMError::FAIL;
469 int num_screen = json_object_array_length(json_cfg);
470 HMI_DEBUG("json_cfg(screens) len:%d", num_screen);
473 json_object *json_screen;
474 for (int i = 0; i < num_screen; i++)
476 json_screen = json_object_array_get_idx(json_cfg, i);
477 HMI_INFO("json_cfg dump:%s", json_object_get_string(json_cfg));
479 // TODO: Currently only one display is connected to a ECU.
481 screen_id = jh::getIntFromJson(json_screen, "id");
484 json_object *json_tmp;
485 if (!json_object_object_get_ex(json_screen, "areas", &json_tmp))
487 HMI_ERROR("Parse Error!!");
488 return WMError::FAIL;
491 int num_area = json_object_array_length(json_tmp);
492 HMI_DEBUG("json_tmp(areas) len:%d", num_area);
495 for (int j = 0; j < num_area; j++)
497 json_object *json_area = json_object_array_get_idx(json_tmp, j);
499 area = jh::getStringFromJson(json_area, "name");
502 HMI_ERROR("Parse Error!!");
503 return WMError::FAIL;
505 HMI_DEBUG("> area:%s", area);
507 json_object *json_rect;
508 if (!json_object_object_get_ex(json_area, "rect", &json_rect))
510 HMI_ERROR("Parse Error!!");
511 return WMError::FAIL;
514 struct rect area_size;
515 area_size.x = jh::getIntFromJson(json_rect, "x");
516 area_size.y = jh::getIntFromJson(json_rect, "y");
517 area_size.w = jh::getIntFromJson(json_rect, "w");
518 area_size.h = jh::getIntFromJson(json_rect, "h");
520 this->area2size[area] = area_size;
524 for (const auto& itr : this->area2size)
526 HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
527 itr.first.c_str(), itr.second.x, itr.second.y,
528 itr.second.w, itr.second.h);
532 // Release json_object
533 json_object_put(json_obj);
535 return WMError::SUCCESS;
538 WMError LayerControl::layoutChange(const WMAction& action)
540 if ((action.visible == TaskVisible::INVISIBLE) ||
541 (action.visible == TaskVisible::REQ_REMOTE_VISIBLE) ||
542 (action.visible == TaskVisible::REQ_REMOTE_INVISIBLE))
544 // Visibility is not change -> no redraw is required
545 return WMError::SUCCESS;
547 if(action.client == nullptr)
549 HMI_SEQ_ERROR(action.req_num, "client may vanish");
550 return WMError::NOT_REGISTERED;
552 unsigned layer = action.client->layerID();
553 unsigned surface = action.client->surfaceID();
555 auto rect = this->getAreaSize(action.area);
556 HMI_DEBUG("Set layout %d, %d, %d, %d",rect.x, rect.y, rect.w, rect.h);
559 // Sometimes, ivi_wm_surface_size signal doesn't reach window manager,
560 // then, Window Manager can't set source size.
561 // This fixes it but it takes about 200ns(on R-Car M3) wastefully
562 ilmSurfaceProperties sp;
563 ilm_getPropertiesOfSurface(surface, &sp);
564 if(sp.origSourceHeight != sp.sourceHeight) {
565 HMI_SEQ_NOTICE(action.req_num, "WORK AROUND: set source size w:%d h%d", sp.origSourceWidth, sp.origSourceHeight);
566 ilm_surfaceSetSourceRectangle(surface, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
570 ilm_surfaceSetDestinationRectangle(surface, rect.x, rect.y, rect.w, rect.h);
572 for(auto &wm_layer: this->wm_layers)
574 // Store the state who is assigned to the area
575 if(wm_layer->hasLayerID(layer))
577 wm_layer->setAreaToState(action.client->appID(), action.area);
578 /* TODO: manipulate state directly
579 LayerState ls = wm_layer->getLayerState();
580 ls.setArea(action.client->appID(), action.area);
585 return WMError::SUCCESS;
588 WMError LayerControl::visibilityChange(const WMAction& action)
590 WMError ret = WMError::FAIL;
591 if(action.client == nullptr)
593 HMI_SEQ_ERROR(action.req_num, "client may vanish");
594 return WMError::NOT_REGISTERED;
597 if (action.visible == TaskVisible::VISIBLE)
599 ret = this->makeVisible(action.client);
601 else if (action.visible == TaskVisible::INVISIBLE)
603 ret = this->makeInvisible(action.client);
605 else if (action.visible == TaskVisible::REMOTE_VISIBLE)
607 ret = this->makeRemoteVisible(action.client);
609 else if (action.visible == TaskVisible::REMOTE_INVISIBLE)
611 ret = this->makeRemoteInvisible(action.client);
613 else // TaskVisible::REQ_REMOTE_VISIBLE || TaskVisible::REQ_REMOTE_INVISIBLE
615 // Visibility is not change
616 ret = WMError::SUCCESS;
622 void LayerControl::terminateApp(const shared_ptr<WMClient> client)
624 for(auto& l : this->wm_layers)
626 l->terminateApp(client->layerID());
630 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
632 if (ILM_SURFACE == object)
636 ilmSurfaceProperties sp;
638 rc = ilm_getPropertiesOfSurface(id, &sp);
639 if(rc != ILM_SUCCESS)
641 HMI_ERROR("Failed to get surface %d property due to %d", id, ilm_getError());
644 this->cb.surfaceCreated(sp.creatorPid, id);
645 ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
646 ilm_surfaceAddNotification(id, surfaceCallback_static);
647 ilm_surfaceSetVisibility(id, ILM_TRUE);
648 ilm_surfaceSetType(id, ILM_SURFACETYPE_DESKTOP);
652 this->cb.surfaceDestroyed(id);
655 if (ILM_LAYER == object)
659 ilm_layerAddNotification(id, layerCallback_static);
663 // Ignore here. Nothing to do currently.
664 // Process of application dead is handled by Window Manager
665 // from binder notification
670 void LayerControl::dispatchSurfacePropChangeEvent(unsigned id,
671 struct ilmSurfaceProperties* sprop,
672 t_ilm_notification_mask mask)
675 ILM_NOTIFICATION_CONTENT_AVAILABLE & ILM_NOTIFICATION_CONTENT_REMOVED
676 are not handled here, handled in create/destroy event
678 if (ILM_NOTIFICATION_VISIBILITY & mask)
680 HMI_DEBUG("surface %d turns visibility %d", id, sprop->visibility);
682 if (ILM_NOTIFICATION_OPACITY & mask)
684 HMI_DEBUG("surface %d turns opacity %f", id, sprop->opacity);
686 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
688 HMI_DEBUG("surface %d source rect changes", id);
690 if (ILM_NOTIFICATION_DEST_RECT & mask)
692 HMI_DEBUG("surface %d dest rect changes", id);
694 if (ILM_NOTIFICATION_CONFIGURED & mask)
696 HMI_DEBUG("surface %d size %d, %d, %d, %d", id,
697 sprop->sourceX, sprop->sourceY, sprop->origSourceWidth, sprop->origSourceHeight);
698 ilm_surfaceSetSourceRectangle(id, 0, 0, sprop->origSourceWidth, sprop->origSourceHeight);
702 void LayerControl::dispatchLayerPropChangeEvent(unsigned id,
703 struct ilmLayerProperties* lprop,
704 t_ilm_notification_mask mask)
706 if (ILM_NOTIFICATION_VISIBILITY & mask)
708 HMI_DEBUG("layer %d turns visibility %d", id, lprop->visibility);
710 if (ILM_NOTIFICATION_OPACITY & mask)
712 HMI_DEBUG("layer %d turns opacity %f", id, lprop->opacity);
714 if (ILM_NOTIFICATION_SOURCE_RECT & mask)
716 HMI_DEBUG("layer %d source rect changes", id);
718 if (ILM_NOTIFICATION_DEST_RECT & mask)
720 HMI_DEBUG("layer %d dest rect changes", id);
724 WMError LayerControl::makeVisible(const shared_ptr<WMClient> client)
726 WMError ret = WMError::SUCCESS;
727 // Don't check here the client is not nullptr
728 unsigned layer = client->layerID();
730 this->moveForeGround(client);
732 ilm_layerSetVisibility(layer, ILM_TRUE);
734 /* for(auto& wm_layer : this->wm_layers)
736 if(wm_layer->hasLayerID(layer))
738 LayerState ls = wm_layer->getLayerState();
743 // Move foreground from back ground layer
744 /* for(auto& wm_layer : this->wm_layers)
746 if(wm_layer->layerName() == "BackGroundLayer")
748 if(wm_layer->hasRole(client->role()))
750 LayerState ls = wm_layer->getLayerState();
751 ls.removeLayer(layer);
760 WMError LayerControl::makeInvisible(const shared_ptr<WMClient> client)
762 WMError ret = WMError::SUCCESS;
763 unsigned layer = client->layerID(); // Don't check here the client is not nullptr
765 bool mv_ok = this->moveBackGround(client);
769 HMI_INFO("make invisible client %s", client->appID().c_str());
770 ilm_layerSetVisibility(layer, ILM_FALSE);
773 //ilm_layerSetDestinationRectangle(layer, 0, 0, 0, 0);
775 /* for(auto& wm_layer : this->wm_layers)
777 if(wm_layer->hasLayerID(layer))
779 LayerState ls = wm_layer->getLayerState();
780 ls.removeLayer(layer);;
789 WMError LayerControl::makeRemoteVisible(const shared_ptr<WMClient> client)
791 WMError ret = WMError::SUCCESS;
792 unsigned layer = client->layerID(); // Don't check here the client is not nullptr
794 if (0 > this->remoteScreenID)
799 // TODO: Currently there is only one remote screen.
800 for (auto itr = this->wm_layers.begin(); itr != this->wm_layers.end(); ++itr)
802 if((*itr)->hasLayerID(layer))
804 HMI_DEBUG("Add layer:%d to remote screen:%d", layer, this->remoteScreenID);
805 this->wm_remote_layers.push_back(*itr);
806 this->wm_layers.erase(itr);
809 if (this->wm_layers.end() == itr)
811 HMI_DEBUG("iteretor indicates end of vector of wm_layers");
816 ilm_layerSetVisibility(layer, ILM_TRUE);
821 WMError LayerControl::makeRemoteInvisible(const shared_ptr<WMClient> client)
823 WMError ret = WMError::SUCCESS;
824 unsigned layer = client->layerID(); // Don't check here the client is not nullptr
826 if (0 > this->remoteScreenID)
831 // TODO: Currently there is only one remote screen.
832 for (auto itr = this->wm_remote_layers.begin();
833 itr != this->wm_remote_layers.end(); ++itr)
835 if((*itr)->hasLayerID(layer))
837 HMI_DEBUG("Remove layer:%d from remote screen:%d", layer, this->remoteScreenID);
838 this->wm_layers.push_back(*itr);
839 this->wm_remote_layers.erase(itr);
842 if (this->wm_remote_layers.end() == itr)
844 HMI_DEBUG("iteretor indicates end of vector of wm_remote_layers");
849 ilm_layerSetVisibility(layer, ILM_FALSE);
854 bool LayerControl::moveBackGround(const shared_ptr<WMClient> client)
858 // Move background from foreground layer
859 auto bg = this->getWMLayer(BACK_GROUND_LAYER);
862 HMI_DEBUG("client %s role %s", client->appID().c_str(), client->role().c_str());
863 unsigned layer = client->layerID();
864 if(bg->hasRole(client->role()))
866 HMI_INFO("%s go to background", client->appID().c_str());
867 bg->addLayerToState(layer);
868 auto wm_layer = this->getWMLayer(layer);
869 wm_layer->removeLayerFromState(layer);
870 /* TODO: manipulate state directly
871 LayerState bg_ls = bg->getLayerState();
872 bg_ls.addLayer(layer);
873 LayerState ls = wm_layer->getLayerState();
874 ls.removeLayer(layer); */
883 bool LayerControl::moveForeGround(const shared_ptr<WMClient> client)
887 // Move foreground from foreground layer
888 auto bg = this->getWMLayer(BACK_GROUND_LAYER);
891 if(bg->hasRole(client->role()))
893 unsigned layer = client->layerID();
894 HMI_INFO("%s go to foreground", client->appID().c_str());
895 bg->removeLayerFromState(layer);
896 auto wm_layer = this->getWMLayer(layer);
897 wm_layer->addLayerToState(layer);
898 /* TODO: manipulate state directly
899 LayerState bg_ls = bg->getLayerState();
900 bg_ls.removeLayer(layer);
901 LayerState ls = wm_layer->getLayerState();
902 ls.addLayer(layer); */