weston-ivi-shell: change order of transmitting notification;
[profile/ivi/wayland-ivi-extension.git] / weston-ivi-shell / src / ivi-controller.c
index 1d654de..e050292 100755 (executable)
@@ -28,9 +28,9 @@
 #include <linux/input.h>
 #include <cairo.h>
 
-#include "compositor.h"
+#include "weston/compositor.h"
 #include "ivi-controller-server-protocol.h"
-#include "weston-layout.h"
+#include "ivi-layout-export.h"
 
 struct ivishell;
 struct ivilayer;
@@ -51,22 +51,26 @@ struct ivisurface {
     struct wl_client *client;
     struct ivishell *shell;
     uint32_t update_count;
-    struct weston_layout_surface *layout_surface;
+    struct ivi_layout_surface *layout_surface;
     struct wl_listener surface_destroy_listener;
     struct wl_list list_layer;
+    uint32_t controller_surface_count;
+    int can_be_removed;
 };
 
 struct ivilayer {
     struct wl_list link;
     struct ivishell *shell;
-    struct weston_layout_layer *layout_layer;
+    struct ivi_layout_layer *layout_layer;
     struct wl_list list_screen;
+    uint32_t controller_layer_count;
+    int layer_canbe_removed;
 };
 
 struct iviscreen {
     struct wl_list link;
     struct ivishell *shell;
-    struct weston_layout_screen *layout_screen;
+    struct ivi_layout_screen *layout_screen;
     struct weston_output *output;
 };
 
@@ -150,6 +154,7 @@ struct ivishell {
     int previous_state;
     int event_restriction;
 };
+static void surface_event_remove(struct ivi_layout_surface *, void *);
 
 static void
 destroy_ivicontroller_surface(struct wl_resource *resource)
@@ -158,21 +163,34 @@ destroy_ivicontroller_surface(struct wl_resource *resource)
     struct ivishell *shell = ivisurf->shell;
     struct ivicontroller_surface *ctrlsurf = NULL;
     struct ivicontroller_surface *next = NULL;
-    uint32_t id_surface = 0;
-
-    id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
+    int is_removed = 0;
 
     wl_list_for_each_safe(ctrlsurf, next,
                           &shell->list_controller_surface, link) {
-        if (id_surface != ctrlsurf->id_surface) {
+
+        if (resource != ctrlsurf->resource) {
             continue;
         }
 
-        wl_list_remove(&ctrlsurf->link);
+        if (!wl_list_empty(&ctrlsurf->link)) {
+            wl_list_remove(&ctrlsurf->link);
+        }
+
+        is_removed = 1;
         free(ctrlsurf);
         ctrlsurf = NULL;
+        --ivisurf->controller_surface_count;
         break;
     }
+
+    if ((is_removed) && (ivisurf->controller_surface_count == 0)) {
+        if (ivisurf->can_be_removed) {
+            free(ivisurf);
+        }
+        else {
+            ivisurf->can_be_removed = 1;
+        }
+    }
 }
 
 static void
@@ -184,19 +202,28 @@ destroy_ivicontroller_layer(struct wl_resource *resource)
     struct ivicontroller_layer *next = NULL;
     uint32_t id_layer = 0;
 
-    id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
+    id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
 
     wl_list_for_each_safe(ctrllayer, next,
                           &shell->list_controller_layer, link) {
-        if (id_layer != ctrllayer->id_layer) {
+
+        if (resource != ctrllayer->resource) {
             continue;
         }
 
         wl_list_remove(&ctrllayer->link);
+        --ivilayer->controller_layer_count;
+        ivi_controller_layer_send_destroyed(ctrllayer->resource);
         free(ctrllayer);
         ctrllayer = NULL;
         break;
     }
+
+    if ((ivilayer->layout_layer != NULL) &&
+        (ivilayer->controller_layer_count == 0) &&
+        (ivilayer->layer_canbe_removed == 1)) {
+        ivi_layout_layerRemove(ivilayer->layout_layer);
+    }
 }
 
 static void
@@ -214,6 +241,11 @@ destroy_ivicontroller_screen(struct wl_resource *resource)
             continue;
         }
 #endif
+
+        if (resource != ctrlscrn->resource) {
+            continue;
+        }
+
         wl_list_remove(&ctrlscrn->link);
         free(ctrlscrn);
         ctrlscrn = NULL;
@@ -239,7 +271,7 @@ get_surface(struct wl_list *list_surf, uint32_t id_surface)
     uint32_t ivisurf_id = 0;
 
     wl_list_for_each(ivisurf, list_surf, link) {
-        ivisurf_id = weston_layout_getIdOfSurface(ivisurf->layout_surface);
+        ivisurf_id = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
         if (ivisurf_id == id_surface) {
             return ivisurf;
         }
@@ -255,7 +287,7 @@ get_layer(struct wl_list *list_layer, uint32_t id_layer)
     uint32_t ivilayer_id = 0;
 
     wl_list_for_each(ivilayer, list_layer, link) {
-        ivilayer_id = weston_layout_getIdOfLayer(ivilayer->layout_layer);
+        ivilayer_id = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
         if (ivilayer_id == id_layer) {
             return ivilayer;
         }
@@ -313,9 +345,10 @@ controller_screen_create(struct ivishell *shell,
 
 static void
 send_surface_add_event(struct ivisurface *ivisurf,
-                       struct wl_resource *resource)
+                       struct wl_resource *resource,
+                       enum ivi_layout_notification_mask mask)
 {
-    weston_layout_layer_ptr *pArray = NULL;
+    struct ivi_layout_layer **pArray = NULL;
     uint32_t length = 0;
     int32_t ans = 0;
     int i = 0;
@@ -325,9 +358,10 @@ send_surface_add_event(struct ivisurface *ivisurf,
     struct ivilayer *ivilayer = NULL;
     struct ivishell *shell = ivisurf->shell;
     uint32_t id_layout_layer = 0;
+    struct wl_client *surface_client = wl_resource_get_client(resource);
     int found = 0;
 
-    ans = weston_layout_getLayersUnderSurface(ivisurf->layout_surface,
+    ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
                                           &length, &pArray);
     if (0 != ans) {
         weston_log("failed to get layers at send_surface_add_event\n");
@@ -335,66 +369,39 @@ send_surface_add_event(struct ivisurface *ivisurf,
     }
 
     /* Send Null to cancel added surface */
-    wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
-        for (i = 0, found = 0; i < (int)length; i++) {
-            if (pArray[i] == link_layer->layer->layout_layer) {
-                /* No need to send event, if new layer doesn't be added. */
-                found = 1;
-                break;
-            }
-        }
-        if (found != 0) {
-            continue;
+    if (mask & IVI_NOTIFICATION_REMOVE) {
+        wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
+            ivi_controller_surface_send_layer(resource, NULL);
         }
-
-        ivi_controller_surface_send_layer(resource, NULL);
-        wl_list_remove(&link_layer->link);
-        free(link_layer);
-        link_layer = NULL;
     }
-
-    for (i = 0; i < (int)length; i++) {
-        found = 0;
-        wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
-            if (pArray[i] == link_layer->layer->layout_layer) {
-                /* No need to send event, if new layer doesn't be added. */
-                found = 1;
-                break;
+    else if (mask & IVI_NOTIFICATION_ADD) {
+        for (i = 0; i < (int)length; i++) {
+            /* Send new surface event */
+            ivilayer = NULL;
+            wl_list_for_each(ivilayer, &shell->list_layer, link) {
+                if (ivilayer->layout_layer == pArray[i]) {
+                    break;
+                }
             }
-        }
-        if (found != -1) {
-            continue;
-        }
 
-        /* Create list_layer */
-        link_layer = calloc(1, sizeof(*link_layer));
-        if (NULL == link_layer) {
-            continue;
-        }
-        wl_list_init(&link_layer->link);
-        link_layer->layer = NULL;
-        wl_list_for_each(ivilayer, &shell->list_layer, link) {
-            if (ivilayer->layout_layer == pArray[i]) {
-                link_layer->layer = ivilayer;
-                break;
+            if (ivilayer == NULL) {
+                continue;
             }
-        }
 
-        if (link_layer->layer == NULL) {
-            free(link_layer);
-            link_layer = NULL;
-            continue;
-        }
-        wl_list_insert(&ivisurf->list_layer, &link_layer->link);
+            id_layout_layer =
+                ivi_layout_getIdOfLayer(ivilayer->layout_layer);
+            wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
+                if (id_layout_layer != ctrllayer->id_layer) {
+                    continue;
+                }
 
-        /* Send new surface event */
-        id_layout_layer =
-            weston_layout_getIdOfLayer(link_layer->layer->layout_layer);
-        wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
-            if (id_layout_layer != ctrllayer->id_layer) {
-                continue;
+                struct wl_client *layer_client = wl_resource_get_client(ctrllayer->resource);
+                if (surface_client != layer_client) {
+                    continue;
+                }
+
+                ivi_controller_surface_send_layer(resource, ctrllayer->resource);
             }
-            ivi_controller_surface_send_layer(resource, ctrllayer->resource);
         }
     }
 
@@ -405,7 +412,7 @@ send_surface_add_event(struct ivisurface *ivisurf,
 static void
 send_surface_event(struct wl_resource *resource,
                    struct ivisurface *ivisurf,
-                   struct weston_layout_SurfaceProperties *prop,
+                   struct ivi_layout_SurfaceProperties *prop,
                    uint32_t mask)
 {
     if (mask & IVI_NOTIFICATION_OPACITY) {
@@ -434,15 +441,73 @@ send_surface_event(struct wl_resource *resource,
         ivi_controller_surface_send_pixelformat(resource,
                                                 prop->pixelformat);
     }
+    if (mask & IVI_NOTIFICATION_REMOVE) {
+        send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_REMOVE);
+    }
+    if (mask & IVI_NOTIFICATION_ADD) {
+        send_surface_add_event(ivisurf, resource, IVI_NOTIFICATION_ADD);
+    }
+}
+
+static void
+update_surface_prop(struct ivisurface *ivisurf,
+                    uint32_t mask)
+{
+    struct ivi_layout_layer **pArray = NULL;
+    uint32_t length = 0;
+    int32_t ans = 0;
+    int i = 0;
+    struct ivishell *shell = ivisurf->shell;
+
+    ans = ivi_layout_getLayersUnderSurface(ivisurf->layout_surface,
+                                          &length, &pArray);
+    if (0 != ans) {
+        weston_log("failed to get layers at send_surface_add_event\n");
+        return;
+    }
+
+    if (mask & IVI_NOTIFICATION_REMOVE) {
+        struct link_layer *link_layer = NULL;
+        struct link_layer *next = NULL;
+
+        wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
+            wl_list_remove(&link_layer->link);
+            free(link_layer);
+            link_layer = NULL;
+        }
+    }
     if (mask & IVI_NOTIFICATION_ADD) {
-        send_surface_add_event(ivisurf, resource);
+        for (i = 0; i < (int)length; ++i) {
+            /* Create list_layer */
+            struct ivilayer *ivilayer = NULL;
+            struct link_layer *link_layer = calloc(1, sizeof(*link_layer));
+            if (NULL == link_layer) {
+                continue;
+            }
+            wl_list_init(&link_layer->link);
+            link_layer->layer = NULL;
+            wl_list_for_each(ivilayer, &shell->list_layer, link) {
+                if (ivilayer->layout_layer == pArray[i]) {
+                    link_layer->layer = ivilayer;
+                    break;
+                }
+            }
+
+            if (link_layer->layer == NULL) {
+                free(link_layer);
+                link_layer = NULL;
+                continue;
+            }
+
+            wl_list_insert(&ivisurf->list_layer, &link_layer->link);
+        }
     }
 }
 
 static void
-send_surface_prop(struct weston_layout_surface *layout_surface,
-                  struct weston_layout_SurfaceProperties *prop,
-                  enum weston_layout_notification_mask mask,
+send_surface_prop(struct ivi_layout_surface *layout_surface,
+                  struct ivi_layout_SurfaceProperties *prop,
+                  enum ivi_layout_notification_mask mask,
                   void *userdata)
 {
     struct ivisurface *ivisurf = userdata;
@@ -450,7 +515,7 @@ send_surface_prop(struct weston_layout_surface *layout_surface,
     struct ivicontroller_surface *ctrlsurf = NULL;
     uint32_t id_surface = 0;
 
-    id_surface = weston_layout_getIdOfSurface(layout_surface);
+    id_surface = ivi_layout_getIdOfSurface(layout_surface);
 
     wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
         if (id_surface != ctrlsurf->id_surface) {
@@ -458,13 +523,16 @@ send_surface_prop(struct weston_layout_surface *layout_surface,
         }
         send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
     }
+
+    update_surface_prop(ivisurf, mask);
 }
 
 static void
 send_layer_add_event(struct ivilayer *ivilayer,
-                     struct wl_resource *resource)
+                     struct wl_resource *resource,
+                     enum ivi_layout_notification_mask mask)
 {
-    weston_layout_screen_ptr *pArray = NULL;
+    struct ivi_layout_screen **pArray = NULL;
     uint32_t length = 0;
     int32_t ans = 0;
     int i = 0;
@@ -472,11 +540,10 @@ send_layer_add_event(struct ivilayer *ivilayer,
     struct link_screen *next = NULL;
     struct iviscreen *iviscrn = NULL;
     struct ivishell *shell = ivilayer->shell;
-    int found = 0;
     struct wl_client *client = wl_resource_get_client(resource);
     struct wl_resource *resource_output = NULL;
 
-    ans = weston_layout_getScreensUnderLayer(ivilayer->layout_layer,
+    ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
                                           &length, &pArray);
     if (0 != ans) {
         weston_log("failed to get screens at send_layer_add_event\n");
@@ -484,64 +551,31 @@ send_layer_add_event(struct ivilayer *ivilayer,
     }
 
     /* Send Null to cancel added layer */
-    wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
-        for (i = 0, found = 0; i < (int)length; i++) {
-            if (pArray[i] == link_scrn->screen->layout_screen) {
-                /* No need to send event, if new layer doesn't be added. */
-                found = 1;
-                break;
-            }
+    if (mask & IVI_NOTIFICATION_REMOVE) {
+        wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
+            ivi_controller_layer_send_screen(resource, NULL);
         }
-        if (found != 0) {
-            continue;
-        }
-
-        ivi_controller_layer_send_screen(resource, NULL);
-        wl_list_remove(&link_scrn->link);
-        free(link_scrn);
-        link_scrn = NULL;
     }
-
-    for (i = 0; i < (int)length; i++) {
-        found = 0;
-        wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
-            if (pArray[i] == link_scrn->screen->layout_screen) {
-                /* No need to send event, if new screen doesn't be added. */
-                found = 1;
-                break;
+    else if (mask & IVI_NOTIFICATION_ADD) {
+        for (i = 0; i < (int)length; i++) {
+            /* Send new layer event */
+            iviscrn = NULL;
+            wl_list_for_each(iviscrn, &shell->list_screen, link) {
+                if (iviscrn->layout_screen == pArray[i]) {
+                    break;
+                }
             }
-        }
-        if (found != 0) {
-            continue;
-        }
 
-        /* Create list_screen */
-        link_scrn = calloc(1, sizeof(*link_scrn));
-        if (NULL == link_scrn) {
-            continue;
-        }
-        wl_list_init(&link_scrn->link);
-        link_scrn->screen = NULL;
-        wl_list_for_each(iviscrn, &shell->list_screen, link) {
-            if (iviscrn->layout_screen == pArray[i]) {
-                link_scrn->screen = iviscrn;
-                break;
+            if (iviscrn == NULL) {
+                continue;
             }
-        }
 
-        if (link_scrn->screen == NULL) {
-            free(link_scrn);
-            link_scrn = NULL;
-            continue;
-        }
-        wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
-
-        /* Send new layer event */
-        resource_output =
-            wl_resource_find_for_client(&iviscrn->output->resource_list,
-                                 client);
-        if (resource_output != NULL) {
-            ivi_controller_layer_send_screen(resource, resource_output);
+            resource_output =
+                wl_resource_find_for_client(&iviscrn->output->resource_list,
+                                     client);
+            if (resource_output != NULL) {
+                ivi_controller_layer_send_screen(resource, resource_output);
+            }
         }
     }
 
@@ -552,7 +586,7 @@ send_layer_add_event(struct ivilayer *ivilayer,
 static void
 send_layer_event(struct wl_resource *resource,
                  struct ivilayer *ivilayer,
-                 struct weston_layout_LayerProperties *prop,
+                 struct ivi_layout_LayerProperties *prop,
                  uint32_t mask)
 {
     if (mask & IVI_NOTIFICATION_OPACITY) {
@@ -581,15 +615,75 @@ send_layer_event(struct wl_resource *resource,
         ivi_controller_layer_send_visibility(resource,
                                           prop->visibility);
     }
+    if (mask & IVI_NOTIFICATION_REMOVE) {
+        send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_REMOVE);
+    }
     if (mask & IVI_NOTIFICATION_ADD) {
-        send_layer_add_event(ivilayer, resource);
+        send_layer_add_event(ivilayer, resource, IVI_NOTIFICATION_ADD);
     }
 }
 
 static void
-send_layer_prop(struct weston_layout_layer *layer,
-                struct weston_layout_LayerProperties *prop,
-                enum weston_layout_notification_mask mask,
+update_layer_prop(struct ivilayer *ivilayer,
+                  enum ivi_layout_notification_mask mask)
+{
+    struct ivi_layout_screen **pArray = NULL;
+    uint32_t length = 0;
+    int32_t ans = 0;
+    struct link_screen *link_scrn = NULL;
+    struct link_screen *next = NULL;
+
+    ans = ivi_layout_getScreensUnderLayer(ivilayer->layout_layer,
+                                          &length, &pArray);
+    if (0 != ans) {
+        weston_log("failed to get screens at send_layer_add_event\n");
+        return;
+    }
+
+    /* Send Null to cancel added layer */
+    if (mask & IVI_NOTIFICATION_REMOVE) {
+        wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
+            wl_list_remove(&link_scrn->link);
+            free(link_scrn);
+            link_scrn = NULL;
+        }
+    }
+    if (mask & IVI_NOTIFICATION_ADD) {
+        int i = 0;
+        for (i = 0; i < (int)length; i++) {
+            struct ivishell *shell = ivilayer->shell;
+            struct iviscreen *iviscrn = NULL;
+            /* Create list_screen */
+            link_scrn = calloc(1, sizeof(*link_scrn));
+            if (NULL == link_scrn) {
+                continue;
+            }
+            wl_list_init(&link_scrn->link);
+            link_scrn->screen = NULL;
+            wl_list_for_each(iviscrn, &shell->list_screen, link) {
+                if (iviscrn->layout_screen == pArray[i]) {
+                    link_scrn->screen = iviscrn;
+                    break;
+                }
+            }
+
+            if (link_scrn->screen == NULL) {
+                free(link_scrn);
+                link_scrn = NULL;
+                continue;
+            }
+            wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
+        }
+    }
+
+    free(pArray);
+    pArray = NULL;
+}
+
+static void
+send_layer_prop(struct ivi_layout_layer *layer,
+                struct ivi_layout_LayerProperties *prop,
+                enum ivi_layout_notification_mask mask,
                 void *userdata)
 {
     struct ivilayer *ivilayer = userdata;
@@ -597,13 +691,15 @@ send_layer_prop(struct weston_layout_layer *layer,
     struct ivishell *shell = ivilayer->shell;
     uint32_t id_layout_layer = 0;
 
-    id_layout_layer = weston_layout_getIdOfLayer(layer);
+    id_layout_layer = ivi_layout_getIdOfLayer(layer);
     wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
         if (id_layout_layer != ctrllayer->id_layer) {
             continue;
         }
         send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
     }
+
+    update_layer_prop(ivilayer, mask);
 }
 
 static void
@@ -613,7 +709,7 @@ controller_surface_set_opacity(struct wl_client *client,
 {
     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
+    ivi_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
 }
 
 static void
@@ -626,7 +722,7 @@ controller_surface_set_source_rectangle(struct wl_client *client,
 {
     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
+    ivi_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
             (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
 }
 
@@ -640,7 +736,7 @@ controller_surface_set_destination_rectangle(struct wl_client *client,
 {
     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
+    ivi_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
             (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
 }
 
@@ -651,7 +747,7 @@ controller_surface_set_visibility(struct wl_client *client,
 {
     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
+    ivi_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
 }
 
 static void
@@ -673,7 +769,7 @@ controller_surface_set_orientation(struct wl_client *client,
 {
     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
+    ivi_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
 }
 
 static void
@@ -683,7 +779,7 @@ controller_surface_screenshot(struct wl_client *client,
 {
     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
+    ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
 }
 
 static void
@@ -705,24 +801,9 @@ controller_surface_destroy(struct wl_client *client,
               struct wl_resource *resource,
               int32_t destroy_scene_object)
 {
-    struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
-    struct ivishell *shell = ivisurf->shell;
-    struct ivicontroller_surface *ctrlsurf = NULL;
-    uint32_t id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
     (void)client;
     (void)destroy_scene_object;
-
-    wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
-        if (ctrlsurf->id_surface != id_surface) {
-            continue;
-        }
-
-        if (!wl_list_empty(&ctrlsurf->link)) {
-            wl_list_remove(&ctrlsurf->link);
-        }
-        wl_resource_destroy(resource);
-        break;
-    }
+    wl_resource_destroy(resource);
 }
 
 static void
@@ -759,7 +840,7 @@ controller_layer_set_source_rectangle(struct wl_client *client,
 {
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_layerSetSourceRectangle(ivilayer->layout_layer,
+    ivi_layout_layerSetSourceRectangle(ivilayer->layout_layer,
            (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
 }
 
@@ -773,7 +854,7 @@ controller_layer_set_destination_rectangle(struct wl_client *client,
 {
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
+    ivi_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
             (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
 }
 
@@ -784,7 +865,7 @@ controller_layer_set_visibility(struct wl_client *client,
 {
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
+    ivi_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
 }
 
 static void
@@ -794,7 +875,7 @@ controller_layer_set_opacity(struct wl_client *client,
 {
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
+    ivi_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
 }
 
 static void
@@ -817,7 +898,7 @@ controller_layer_set_orientation(struct wl_client *client,
 {
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
+    ivi_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
 }
 
 static void
@@ -826,7 +907,7 @@ controller_layer_clear_surfaces(struct wl_client *client,
 {
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
+    ivi_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
 }
 
 static void
@@ -837,7 +918,7 @@ controller_layer_add_surface(struct wl_client *client,
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
     (void)client;
-    weston_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
+    ivi_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
 }
 
 static void
@@ -848,7 +929,7 @@ controller_layer_remove_surface(struct wl_client *client,
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
     (void)client;
-    weston_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
+    ivi_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
 }
 
 static void
@@ -867,7 +948,7 @@ controller_layer_set_render_order(struct wl_client *client,
                                   struct wl_array *id_surfaces)
 {
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
-    struct weston_layout_surface **layoutsurf_array = NULL;
+    struct ivi_layout_surface **layoutsurf_array = NULL;
     struct ivisurface *ivisurf = NULL;
     uint32_t *id_surface = NULL;
     uint32_t id_layout_surface = 0;
@@ -876,7 +957,7 @@ controller_layer_set_render_order(struct wl_client *client,
 
     wl_array_for_each(id_surface, id_surfaces) {
         wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
-            id_layout_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
+            id_layout_surface = ivi_layout_getIdOfSurface(ivisurf->layout_surface);
             if (*id_surface == id_layout_surface) {
                 layoutsurf_array[i] = ivisurf->layout_surface;
                 i++;
@@ -885,7 +966,7 @@ controller_layer_set_render_order(struct wl_client *client,
         }
     }
 
-    weston_layout_layerSetRenderOrder(ivilayer->layout_layer,
+    ivi_layout_layerSetRenderOrder(ivilayer->layout_layer,
                                    layoutsurf_array, id_surfaces->size);
     free(layoutsurf_array);
 }
@@ -898,23 +979,19 @@ controller_layer_destroy(struct wl_client *client,
     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
     struct ivishell *shell = ivilayer->shell;
     struct ivicontroller_layer *ctrllayer = NULL;
-    uint32_t id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
+    struct ivicontroller_layer *next = NULL;
+    uint32_t id_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
     (void)client;
     (void)destroy_scene_object;
 
-    wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
+    ivilayer->layer_canbe_removed = 1;
+    wl_list_for_each_safe(ctrllayer, next, &shell->list_controller_layer, link) {
         if (ctrllayer->id_layer != id_layer) {
             continue;
         }
 
-        if (!wl_list_empty(&ctrllayer->link)) {
-            wl_list_remove(&ctrllayer->link);
-        }
-        wl_resource_destroy(resource);
-        break;
+        wl_resource_destroy(ctrllayer->resource);
     }
-
-    weston_layout_layerRemove(ivilayer->layout_layer);
 }
 
 static const
@@ -940,13 +1017,18 @@ controller_screen_destroy(struct wl_client *client,
     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
     struct ivicontroller_screen *ctrlscrn = NULL;
     struct ivicontroller_screen *next = NULL;
-//    uint32_t id_screen = weston_layout_getIdOfScreen(iviscrn->layout_screen);
+//    uint32_t id_screen = ivi_layout_getIdOfScreen(iviscrn->layout_screen);
     (void)client;
 
     wl_list_for_each_safe(ctrlscrn, next,
                           &iviscrn->shell->list_controller_screen, link) {
-// TODO : Only Single display
-        destroy_ivicontroller_screen(ctrlscrn->resource);
+        if (resource != ctrlscrn->resource) {
+            continue;
+        }
+
+        wl_list_remove(&ctrlscrn->link);
+        free(ctrlscrn);
+        ctrlscrn = NULL;
         wl_resource_destroy(ctrlscrn->resource);
         break;
     }
@@ -958,7 +1040,7 @@ controller_screen_clear(struct wl_client *client,
 {
     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
+    ivi_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
 }
 
 static void
@@ -969,7 +1051,7 @@ controller_screen_add_layer(struct wl_client *client,
     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
     struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
     (void)client;
-    weston_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
+    ivi_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
 }
 
 static void
@@ -979,7 +1061,7 @@ controller_screen_screenshot(struct wl_client *client,
 {
     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
     (void)client;
-    weston_layout_takeScreenshot(iviscrn->layout_screen, filename);
+    ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
 }
 
 static void
@@ -988,19 +1070,19 @@ controller_screen_set_render_order(struct wl_client *client,
                 struct wl_array *id_layers)
 {
     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
-    struct weston_layout_layer **layoutlayer_array = NULL;
+    struct ivi_layout_layer **layoutlayer_array = NULL;
     struct ivilayer *ivilayer = NULL;
     uint32_t *id_layer = NULL;
     uint32_t id_layout_layer = 0;
     int i = 0;
     (void)client;
 
-    *layoutlayer_array = (struct weston_layout_layer*)calloc(
+    *layoutlayer_array = (struct ivi_layout_layer*)calloc(
                             id_layers->size, sizeof(void*));
 
     wl_array_for_each(id_layer, id_layers) {
         wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
-            id_layout_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
+            id_layout_layer = ivi_layout_getIdOfLayer(ivilayer->layout_layer);
             if (*id_layer == id_layout_layer) {
                 layoutlayer_array[i] = ivilayer->layout_layer;
                 i++;
@@ -1009,7 +1091,7 @@ controller_screen_set_render_order(struct wl_client *client,
         }
     }
 
-    weston_layout_screenSetRenderOrder(iviscrn->layout_screen,
+    ivi_layout_screenSetRenderOrder(iviscrn->layout_screen,
                                     layoutlayer_array, id_layers->size);
     free(layoutlayer_array);
 }
@@ -1031,7 +1113,7 @@ controller_commit_changes(struct wl_client *client,
     (void)client;
     (void)resource;
 
-    ans = weston_layout_commitChanges();
+    ans = ivi_layout_commitChanges();
     if (ans < 0) {
         weston_log("Failed to commit changes at controller_commit_changes\n");
     }
@@ -1047,14 +1129,14 @@ controller_layer_create(struct wl_client *client,
 {
     struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
     struct ivishell *shell = ctrl->shell;
-    struct weston_layout_layer *layout_layer = NULL;
+    struct ivi_layout_layer *layout_layer = NULL;
     struct ivicontroller_layer *ctrllayer = NULL;
     struct ivilayer *ivilayer = NULL;
-    struct weston_layout_LayerProperties prop;
+    struct ivi_layout_LayerProperties prop;
 
     ivilayer = get_layer(&shell->list_layer, id_layer);
     if (ivilayer == NULL) {
-        layout_layer = weston_layout_layerCreateWithDimension(id_layer,
+        layout_layer = ivi_layout_layerCreateWithDimension(id_layer,
                            (uint32_t)width, (uint32_t)height);
         if (layout_layer == NULL) {
             weston_log("id_layer is already created\n");
@@ -1075,6 +1157,9 @@ controller_layer_create(struct wl_client *client,
         return;
     }
 
+    ++ivilayer->controller_layer_count;
+    ivilayer->layer_canbe_removed = 0;
+
     ctrllayer->shell = shell;
     ctrllayer->client = client;
     ctrllayer->id = id;
@@ -1095,14 +1180,20 @@ controller_layer_create(struct wl_client *client,
 
     memset(&prop, 0, sizeof prop);
 
-    weston_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
+    ivi_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
+    send_layer_event(ctrllayer->resource, ivilayer,
+                     &prop, IVI_NOTIFICATION_ALL);
+}
 
-    wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
-        if (id_layer != ctrllayer->id_layer) {
-            continue;
-        }
-        send_layer_event(ctrllayer->resource, ivilayer,
-                         &prop, IVI_NOTIFICATION_ALL);
+static void
+surface_event_content(struct ivi_layout_surface *layout_surface, int32_t content, void *userdata)
+{
+    struct ivishell *shell = userdata;
+    struct ivicontroller_surface *ctrlsurf = NULL;
+    uint32_t id_surface = 0;
+
+    if (content == 0) {
+        surface_event_remove(layout_surface, userdata);
     }
 }
 
@@ -1115,7 +1206,7 @@ controller_surface_create(struct wl_client *client,
     struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
     struct ivishell *shell = ctrl->shell;
     struct ivicontroller_surface *ctrlsurf = NULL;
-    struct weston_layout_SurfaceProperties prop;
+    struct ivi_layout_SurfaceProperties prop;
     struct ivisurface *ivisurf = NULL;
 
     ctrlsurf = calloc(1, sizeof *ctrlsurf);
@@ -1143,21 +1234,19 @@ controller_surface_create(struct wl_client *client,
         return;
     }
 
+    ++ivisurf->controller_surface_count;
+
     wl_resource_set_implementation(ctrlsurf->resource,
                                    &controller_surface_implementation,
                                    ivisurf, destroy_ivicontroller_surface);
 
     memset(&prop, 0, sizeof prop);
 
-    weston_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
+    ivi_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
+    ivi_layout_surfaceSetContentObserver(ivisurf->layout_surface, surface_event_content, shell);
 
-    wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
-        if (id_surface != ctrlsurf->id_surface) {
-            continue;
-        }
-        send_surface_event(ctrlsurf->resource, ivisurf,
-                           &prop, IVI_NOTIFICATION_ALL);
-    }
+    send_surface_event(ctrlsurf->resource, ivisurf,
+                       &prop, IVI_NOTIFICATION_ALL);
 }
 
 static const struct ivi_controller_interface controller_implementation = {
@@ -1179,22 +1268,6 @@ add_client_to_resources(struct ivishell *shell,
     uint32_t id_layout_surface = 0;
     uint32_t id_layout_layer = 0;
 
-    wl_list_for_each(ivisurf, &shell->list_surface, link) {
-        id_layout_surface =
-            weston_layout_getIdOfSurface(ivisurf->layout_surface);
-
-        ivi_controller_send_surface(controller->resource,
-                                    id_layout_surface);
-    }
-
-    wl_list_for_each(ivilayer, &shell->list_layer, link) {
-        id_layout_layer =
-            weston_layout_getIdOfLayer(ivilayer->layout_layer);
-
-        ivi_controller_send_layer(controller->resource,
-                                  id_layout_layer);
-    }
-
     wl_list_for_each(iviscrn, &shell->list_screen, link) {
         resource_output = wl_resource_find_for_client(
                 &iviscrn->output->resource_list, client);
@@ -1211,6 +1284,20 @@ add_client_to_resources(struct ivishell *shell,
                                    wl_resource_get_id(resource_output),
                                    ctrlscrn->resource);
     }
+    wl_list_for_each_reverse(ivilayer, &shell->list_layer, link) {
+        id_layout_layer =
+            ivi_layout_getIdOfLayer(ivilayer->layout_layer);
+
+        ivi_controller_send_layer(controller->resource,
+                                  id_layout_layer);
+    }
+    wl_list_for_each_reverse(ivisurf, &shell->list_surface, link) {
+        id_layout_surface =
+            ivi_layout_getIdOfSurface(ivisurf->layout_surface);
+
+        ivi_controller_send_surface(controller->resource,
+                                    id_layout_surface);
+    }
 }
 
 static void
@@ -1257,28 +1344,31 @@ create_screen(struct ivishell *shell, struct weston_output *output)
     iviscrn->output = output;
 
 // TODO : Only Single display
-    iviscrn->layout_screen = weston_layout_getScreenFromId(0);
+    iviscrn->layout_screen = ivi_layout_getScreenFromId(0);
 
     wl_list_init(&iviscrn->link);
 
     return iviscrn;
 }
 
-static void
-layer_event_create(struct weston_layout_layer *layout_layer,
-                     void *userdata)
+static struct ivilayer*
+create_layer(struct ivishell *shell,
+             struct ivi_layout_layer *layout_layer,
+             uint32_t id_layer)
 {
-    struct ivishell *shell = userdata;
-    struct ivicontroller *controller = NULL;
     struct ivilayer *ivilayer = NULL;
-    uint32_t id_layer = 0;
+    struct ivicontroller *controller = NULL;
 
-    id_layer = weston_layout_getIdOfLayer(layout_layer);
+    ivilayer = get_layer(&shell->list_layer, id_layer);
+    if (ivilayer != NULL) {
+        weston_log("id_layer is already created\n");
+        return NULL;
+    }
 
     ivilayer = calloc(1, sizeof *ivilayer);
-    if (!ivilayer) {
+    if (NULL == ivilayer) {
         weston_log("no memory to allocate client layer\n");
-        return;
+        return NULL;
     }
 
     ivilayer->shell = shell;
@@ -1287,17 +1377,71 @@ layer_event_create(struct weston_layout_layer *layout_layer,
     wl_list_insert(&shell->list_layer, &ivilayer->link);
     ivilayer->layout_layer = layout_layer;
 
-    weston_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
+    ivi_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
 
     wl_list_for_each(controller, &shell->list_controller, link) {
         ivi_controller_send_layer(controller->resource, id_layer);
     }
 
-    return;
+    return ivilayer;
+}
+
+static struct ivisurface*
+create_surface(struct ivishell *shell,
+               struct ivi_layout_surface *layout_surface,
+               uint32_t id_surface)
+{
+    struct ivisurface *ivisurf = NULL;
+    struct ivicontroller *controller = NULL;
+
+    ivisurf = get_surface(&shell->list_surface, id_surface);
+    if (ivisurf != NULL) {
+        weston_log("id_surface is already created\n");
+        return NULL;
+    }
+
+    ivisurf = calloc(1, sizeof *ivisurf);
+    if (ivisurf == NULL) {
+        weston_log("no memory to allocate client surface\n");
+        return NULL;
+    }
+
+    ivisurf->shell = shell;
+    ivisurf->layout_surface = layout_surface;
+    wl_list_init(&ivisurf->list_layer);
+    wl_list_init(&ivisurf->link);
+    wl_list_insert(&shell->list_surface, &ivisurf->link);
+
+    wl_list_for_each(controller, &shell->list_controller, link) {
+        ivi_controller_send_surface(controller->resource,
+                                    id_surface);
+    }
+
+    ivi_layout_surfaceAddNotification(layout_surface,
+                                    send_surface_prop, ivisurf);
+
+    return ivisurf;
+}
+
+static void
+layer_event_create(struct ivi_layout_layer *layout_layer,
+                     void *userdata)
+{
+    struct ivishell *shell = userdata;
+    struct ivilayer *ivilayer = NULL;
+    uint32_t id_layer = 0;
+
+    id_layer = ivi_layout_getIdOfLayer(layout_layer);
+
+    ivilayer = create_layer(shell, layout_layer, id_layer);
+    if (ivilayer == NULL) {
+        weston_log("failed to create layer");
+        return;
+    }
 }
 
 static void
-layer_event_remove(struct weston_layout_layer *layout_layer,
+layer_event_remove(struct ivi_layout_layer *layout_layer,
                      void *userdata)
 {
     struct ivishell *shell = userdata;
@@ -1305,6 +1449,7 @@ layer_event_remove(struct weston_layout_layer *layout_layer,
     struct ivilayer *ivilayer = NULL;
     struct ivilayer *next = NULL;
     uint32_t id_layer = 0;
+    int is_removed = 0;
 
     wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
         if (layout_layer != ivilayer->layout_layer) {
@@ -1312,64 +1457,45 @@ layer_event_remove(struct weston_layout_layer *layout_layer,
         }
 
         wl_list_remove(&ivilayer->link);
+
+        is_removed = 1;
         free(ivilayer);
         ivilayer = NULL;
         break;
     }
 
-    id_layer = weston_layout_getIdOfLayer(layout_layer);
+    if (is_removed) {
+        id_layer = ivi_layout_getIdOfLayer(layout_layer);
 
-    wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
-        if (id_layer != ctrllayer->id_layer) {
-            continue;
+        wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
+            if (id_layer != ctrllayer->id_layer) {
+                continue;
+            }
+            ivi_controller_layer_send_destroyed(ctrllayer->resource);
         }
-        ivi_controller_layer_send_destroyed(ctrllayer->resource);
     }
 }
 
 
 static void
-surface_event_create(struct weston_layout_surface *layout_surface,
+surface_event_create(struct ivi_layout_surface *layout_surface,
                      void *userdata)
 {
     struct ivishell *shell = userdata;
     struct ivisurface *ivisurf = NULL;
-    struct ivicontroller *controller = NULL;
     uint32_t id_surface = 0;
 
-    id_surface = weston_layout_getIdOfSurface(layout_surface);
+    id_surface = ivi_layout_getIdOfSurface(layout_surface);
 
-    ivisurf = get_surface(&shell->list_surface, id_surface);
-    if (ivisurf != NULL)
-    {
-        weston_log("id_surface is already created\n");
-        return;
-    }
-
-    ivisurf = calloc(1, sizeof *ivisurf);
+    ivisurf = create_surface(shell, layout_surface, id_surface);
     if (ivisurf == NULL) {
-        weston_log("no memory to allocate client surface\n");
+        weston_log("failed to create surface");
         return;
     }
-
-    ivisurf->shell = shell;
-    ivisurf->layout_surface = layout_surface;
-    wl_list_init(&ivisurf->list_layer);
-    wl_list_init(&ivisurf->link);
-    wl_list_insert(&shell->list_surface, &ivisurf->link);
-
-    wl_list_for_each(controller, &shell->list_controller, link) {
-        ivi_controller_send_surface(controller->resource,
-                                    id_surface);
-    }
-
-    weston_layout_surfaceAddNotification(layout_surface,
-                                    &send_surface_prop, ivisurf);
-
 }
 
 static void
-surface_event_remove(struct weston_layout_surface *layout_surface,
+surface_event_remove(struct ivi_layout_surface *layout_surface,
                      void *userdata)
 {
     struct ivishell *shell = userdata;
@@ -1377,6 +1503,7 @@ surface_event_remove(struct weston_layout_surface *layout_surface,
     struct ivisurface *ivisurf = NULL;
     struct ivisurface *next = NULL;
     uint32_t id_surface = 0;
+    int is_removed = 0;
 
     wl_list_for_each_safe(ivisurf, next, &shell->list_surface, link) {
         if (layout_surface != ivisurf->layout_surface) {
@@ -1384,32 +1511,41 @@ surface_event_remove(struct weston_layout_surface *layout_surface,
         }
 
         wl_list_remove(&ivisurf->link);
-        free(ivisurf);
-        ivisurf = NULL;
+        is_removed = 1;
+
+        if (ivisurf->controller_surface_count == 0) {
+            free(ivisurf);
+        }
+        else {
+            ivisurf->can_be_removed = 1;
+        }
+
         break;
     }
 
-    id_surface = weston_layout_getIdOfSurface(layout_surface);
+    if (is_removed) {
+        id_surface = ivi_layout_getIdOfSurface(layout_surface);
 
-    wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
-        if (id_surface != ctrlsurf->id_surface) {
-            continue;
+        wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
+            if (id_surface != ctrlsurf->id_surface) {
+                continue;
+            }
+            ivi_controller_surface_send_destroyed(ctrlsurf->resource);
         }
-        ivi_controller_surface_send_destroyed(ctrlsurf->resource);
     }
 }
 
 static void
-surface_event_configure(struct weston_layout_surface *layout_surface,
+surface_event_configure(struct ivi_layout_surface *layout_surface,
                         void *userdata)
 {
     struct ivishell *shell = userdata;
     struct ivisurface *ivisurf = NULL;
     struct ivicontroller_surface *ctrlsurf = NULL;
-    struct weston_layout_SurfaceProperties prop;
+    struct ivi_layout_SurfaceProperties prop;
     uint32_t id_surface = 0;
 
-    id_surface = weston_layout_getIdOfSurface(layout_surface);
+    id_surface = ivi_layout_getIdOfSurface(layout_surface);
 
     ivisurf = get_surface(&shell->list_surface, id_surface);
     if (ivisurf == NULL) {
@@ -1418,7 +1554,7 @@ surface_event_configure(struct weston_layout_surface *layout_surface,
     }
 
     memset(&prop, 0, sizeof prop);
-    weston_layout_getPropertiesOfSurface(layout_surface, &prop);
+    ivi_layout_getPropertiesOfSurface(layout_surface, &prop);
 
     wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
         if (id_surface != ctrlsurf->id_surface) {
@@ -1429,14 +1565,85 @@ surface_event_configure(struct weston_layout_surface *layout_surface,
     }
 }
 
+static int32_t
+check_layout_layers(struct ivishell *shell)
+{
+    struct ivi_layout_layer **pArray = NULL;
+    struct ivilayer *ivilayer = NULL;
+    uint32_t id_layer = 0;
+    uint32_t length = 0;
+    uint32_t i = 0;
+    int32_t ret = 0;
+
+    ret = ivi_layout_getLayers(&length, &pArray);
+    if(ret != 0) {
+        weston_log("failed to get layers at check_layout_layers\n");
+        return -1;
+    }
+
+    if (length == 0) {
+        /* if length is 0, pArray doesn't need to free.*/
+        return 0;
+    }
+
+    for (i = 0; i < length; i++) {
+        id_layer = ivi_layout_getIdOfLayer(pArray[i]);
+        ivilayer = create_layer(shell, pArray[i], id_layer);
+        if (ivilayer == NULL) {
+            weston_log("failed to create layer");
+        }
+    }
+
+    free(pArray);
+    pArray = NULL;
+
+    return 0;
+}
+
+static int32_t
+check_layout_surfaces(struct ivishell *shell)
+{
+    struct ivi_layout_surface **pArray = NULL;
+    struct ivisurface *ivisurf = NULL;
+    uint32_t id_surface = 0;
+    uint32_t length = 0;
+    uint32_t i = 0;
+    int32_t ret = 0;
+
+    ret = ivi_layout_getSurfaces(&length, &pArray);
+    if(ret != 0) {
+        weston_log("failed to get surfaces at check_layout_surfaces\n");
+        return -1;
+    }
+
+    if (length == 0) {
+        /* if length is 0, pArray doesn't need to free.*/
+        return 0;
+    }
+
+    for (i = 0; i < length; i++) {
+        id_surface = ivi_layout_getIdOfSurface(pArray[i]);
+        ivisurf = create_surface(shell, pArray[i], id_surface);
+        if (ivisurf == NULL) {
+            weston_log("failed to create surface");
+        }
+    }
+
+    free(pArray);
+    pArray = NULL;
+
+    return 0;
+}
+
 static void
 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
 {
     struct weston_output *output = NULL;
     struct iviscreen *iviscrn = NULL;
+    int32_t ret = 0;
+
     shell->compositor = ec;
 
-    wl_list_init(&ec->layer_list);
     wl_list_init(&shell->list_surface);
     wl_list_init(&shell->list_layer);
     wl_list_init(&shell->list_screen);
@@ -1454,12 +1661,22 @@ init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
         }
     }
 
-    weston_layout_setNotificationCreateLayer(layer_event_create, shell);
-    weston_layout_setNotificationRemoveLayer(layer_event_remove, shell);
+    ret = check_layout_layers(shell);
+    if (ret != 0) {
+        weston_log("failed to check_layout_layers");
+    }
+
+    ret = check_layout_surfaces(shell);
+    if (ret != 0) {
+        weston_log("failed to check_layout_surfaces");
+    }
+
+    ivi_layout_addNotificationCreateLayer(layer_event_create, shell);
+    ivi_layout_addNotificationRemoveLayer(layer_event_remove, shell);
 
-    weston_layout_setNotificationCreateSurface(surface_event_create, shell);
-    weston_layout_setNotificationRemoveSurface(surface_event_remove, shell);
-    weston_layout_setNotificationConfigureSurface(surface_event_configure, shell);
+    ivi_layout_addNotificationCreateSurface(surface_event_create, shell);
+    ivi_layout_addNotificationRemoveSurface(surface_event_remove, shell);
+    ivi_layout_addNotificationConfigureSurface(surface_event_configure, shell);
 }
 
 WL_EXPORT int