Return WMError instead of bool
[apps/agl-service-windowmanager.git] / src / wm_layer_control.cpp
index 86616e8..1d591f0 100644 (file)
@@ -69,10 +69,11 @@ LayerControl::LayerControl(const std::string& root)
 
 WMError LayerControl::init(const LayerControlCallbacks& cb)
 {
-    ilmErrorTypes rc = ilm_init();
+    HMI_DEBUG("Initialize of ilm library and display");
     t_ilm_uint num = 0;
     t_ilm_uint *ids;
     int cnt = 0;
+    ilmErrorTypes rc = ilm_init();
 
     while (rc != ILM_SUCCESS)
     {
@@ -84,7 +85,7 @@ WMError LayerControl::init(const LayerControlCallbacks& cb)
         }
         HMI_ERROR("Wait to start weston ...");
         sleep(1);
-        ilm_init();
+        rc = ilm_init();
     }
     if(rc != ILM_SUCCESS) goto lc_init_error;
 
@@ -124,8 +125,11 @@ void LayerControl::createNewLayer(unsigned id)
     ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);
     //ilm_layerSetDestinationRectangle(id, rct.x, rct.y, rct.w, rct.h);
     ilm_layerSetOpacity(id, 1.0);
-    ilm_layerSetVisibility(id, ILM_TRUE);
+    ilm_layerSetVisibility(id, ILM_FALSE);
     ilm_commitChanges();
+    auto wm_layer = getWMLayer(id);
+    wm_layer->addLayer(id);
+    this->commitChange();
 }
 
 unsigned LayerControl::getNewLayerID(const string& role, string* layer_name)
@@ -137,12 +141,20 @@ unsigned LayerControl::getNewLayerID(const string& role, string* layer_name)
         if(ret != 0)
         {
             *layer_name = l->layerName();
+            unsigned uid = l->getUuid();
+            this->lid2wmlid[ret] = uid;
             break;
         }
     }
     return ret;
 }
 
+shared_ptr<WMLayer> LayerControl::getWMLayer(unsigned layer)
+{
+    unsigned uuid = this->lid2wmlid[layer];
+    return this->wm_layers[uuid];
+}
+
 struct rect LayerControl::getAreaSize(const std::string& area)
 {
     return area2size[area];
@@ -164,7 +176,7 @@ void LayerControl::setupArea(double scaling)
         i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
         i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
 
-        HMI_DEBUG("wm:lm", "area:%s size(after) : x:%d y:%d w:%d h:%d",
+        HMI_DEBUG("area:%s size(after) : x:%d y:%d w:%d h:%d",
             i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
     }
 }
@@ -186,9 +198,10 @@ WMError LayerControl::updateLayer(LayerState& layer_state)
 
 WMError LayerControl::commitChange()
 {
+    HMI_INFO("Commit change");
     WMError rc = WMError::SUCCESS;
     vector<unsigned> ivi_l_ids;
-    for(const auto& l : this->wm_layers)
+    for(auto& l : this->wm_layers)
     {
         auto state = l->getLayerState();
         for(const auto& id : state.getIviIdList())
@@ -207,6 +220,7 @@ WMError LayerControl::commitChange()
     for(const auto& i : ivi_l_ids)
     {
         id_array[count] = i;
+        HMI_DEBUG("check render order %d", i);
         ++count;
     }
 
@@ -216,6 +230,7 @@ WMError LayerControl::commitChange()
         this->undoUpdate();
         rc = WMError::FAIL;
     }
+    ilm_commitChanges();
     delete id_array;
     return rc;
 }
@@ -249,8 +264,9 @@ WMError LayerControl::loadLayerSetting(const string &path)
         json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
         HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
 
-        this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp));
+        this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp, i));
     }
+    json_object_put(json_obj);
 
     return WMError::SUCCESS;
 }
@@ -379,7 +395,6 @@ WMError LayerControl::visibilityChange(const WMAction& action)
 
 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
 {
-    this->cb.test(id);
     if (ILM_SURFACE == object)
     {
         if (created)
@@ -389,9 +404,10 @@ void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool c
             rc = ilm_getPropertiesOfSurface(id, &sp);
             if(rc != ILM_SUCCESS)
                 return;
-            // this->cb->surfaceCreated(pid, id);
+            this->cb.surfaceCreated(sp.creatorPid, id);
             ilm_surfaceAddNotification(id, surfaceCallback_static);
             ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
+            ilm_surfaceSetVisibility(id, ILM_TRUE);
         }
         else
         {