wayland: only create layers and surfaces when necessary
[staging/windowmanager.git] / src / wayland.cpp
index 01ac275..df601eb 100644 (file)
@@ -234,15 +234,21 @@ void controller::controller_screen(uint32_t id,
 
 void controller::controller_layer(uint32_t id) {
    logdebug("genivi::controller @ %p layer %u (%x)", this->proxy.get(), id, id);
-   auto &l = this->layers[id] = std::make_unique<struct layer>(id, this);
-   l->clear_surfaces();
+   if (this->layers.find(id) != this->layers.end()) {
+      logerror("Someone created a layer without asking US! (%d)", id);
+   } else {
+      auto &l = this->layers[id] = std::make_unique<struct layer>(id, this);
+      l->clear_surfaces();
+   }
 }
 
 void controller::controller_surface(uint32_t id) {
    logdebug("genivi::controller @ %p surface %u (%x)", this->proxy.get(), id,
             id);
-   this->surfaces[id] = std::make_unique<struct surface>(id, this);
-   this->chooks->surface_created(id);
+   if (this->surfaces.find(id) == this->surfaces.end()) {
+      this->surfaces[id] = std::make_unique<struct surface>(id, this);
+      this->chooks->surface_created(id);
+   }
 }
 
 void controller::controller_error(int32_t object_id, int32_t object_type,