Refator screen connector provider 72/269972/3
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 24 Jan 2022 02:30:35 +0000 (11:30 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 24 Jan 2022 02:38:09 +0000 (11:38 +0900)
The libscreen_connector_provider is implemented using c++.

Change-Id: I9025455cd8319c331fa0fb80d115ca282b8c1b79
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
screen_connector_provider/CMakeLists.txt
screen_connector_provider/include/screen_connector_provider.h
screen_connector_provider/log_private.hh [new file with mode: 0644]
screen_connector_provider/remote_surface_manager.cc [new file with mode: 0644]
screen_connector_provider/remote_surface_manager.hh [new file with mode: 0644]
screen_connector_provider/remote_surface_provider.cc [new file with mode: 0644]
screen_connector_provider/remote_surface_provider.hh [new file with mode: 0644]
screen_connector_provider/screen_connector_provider.cc [new file with mode: 0644]
screen_connector_provider/src/screen_connector_provider.c [deleted file]

index b97f44b..2638e8d 100644 (file)
@@ -1,4 +1,4 @@
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}
   SCREEN_CONNECTOR_PROVIDER_SRCS)
 
 ADD_LIBRARY(${TARGET_SCREEN_CONNECTOR_PROVIDER} SHARED
index b240859..a0e9710 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
  *
- * Licensed under the Apache License, Version 2.0 (the License);
+ * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
@@ -19,6 +19,7 @@
 
 #include <wayland-client.h>
 #include <tizen-remote-surface-client-protocol.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -48,15 +49,21 @@ typedef enum {
                TIZEN_REMOTE_SURFACE_INPUT_EVENT_FILTER_KEY_ALL,
 } screen_connector_input_type_e;
 
-typedef struct screen_connector_provider_s *screen_connector_provider_h;
+typedef void *screen_connector_provider_h;
+
 int screen_connector_provider_remote_enable(const char *id,
                struct wl_surface *surface);
+
 screen_connector_provider_h screen_connector_provider_create(const char *id,
                struct wl_surface *surface);
+
 int screen_connector_provider_set_event_filter(
                screen_connector_provider_h provider, unsigned int filter);
+
 int screen_connector_provider_destroy(screen_connector_provider_h provider);
+
 int screen_connector_provider_init(void);
+
 int screen_connector_provider_fini(void);
 
 #ifdef __cplusplus
diff --git a/screen_connector_provider/log_private.hh b/screen_connector_provider/log_private.hh
new file mode 100644 (file)
index 0000000..5d05ab2
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LOG_PRIVATE_HH_
+#define LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "SC_PROVIDER"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif  // LOG_PRIVATE_HH_
diff --git a/screen_connector_provider/remote_surface_manager.cc b/screen_connector_provider/remote_surface_manager.cc
new file mode 100644 (file)
index 0000000..4880285
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "remote_surface_manager.hh"
+
+#include "log_private.hh"
+
+namespace screen_connector {
+namespace provider {
+
+RemoteSurfaceManager& RemoteSurfaceManager::GetInst() {
+  static RemoteSurfaceManager inst;
+  return inst;
+}
+
+bool RemoteSurfaceManager::Init() {
+  if (ref_ > 0) {
+    ref_++;
+    return true;
+  }
+
+  if (!ecore_wl2_init()) {
+    _E("ecore_wl2_init() is failed");
+    return false;
+  }
+
+  auto* display = ecore_wl2_display_connect(nullptr);
+  if (display == nullptr) {
+    _E("ecore_wl2_display_connect() is failed");
+    ecore_wl2_shutdown();
+    return false;
+  }
+
+  struct wl_registry* registry = ecore_wl2_display_registry_get(display);
+  if (registry == nullptr) {
+    _E("ecore_wl2_display_registry_get() is failed");
+    ecore_wl2_display_disconnect(display);
+    ecore_wl2_shutdown();
+    return false;
+  }
+
+  Eina_Iterator* globals = ecore_wl2_display_globals_get(display);
+  if (globals == nullptr) {
+    _E("ecore_wl2_display_globals_get() is failed");
+    ecore_wl2_display_disconnect(display);
+    ecore_wl2_shutdown();
+    return false;
+  }
+
+  std::unique_ptr<Eina_Iterator, decltype(eina_iterator_free)*> globals_auto(
+     globals, eina_iterator_free);
+
+  Ecore_Wl2_Global* global;
+  EINA_ITERATOR_FOREACH(globals, global) {
+    if (!strcmp(global->interface, "tizen_remote_surface_manager")) {
+      rsm_ = static_cast<struct tizen_remote_surface_manager*>(
+          wl_registry_bind(registry, global->id,
+              &tizen_remote_surface_manager_interface,
+              global->version < 6 ? global->version : 6));
+    }
+  }
+
+  if (rsm_ == nullptr) {
+    _E("Failed to get tizen_remote_surface_manager");
+    ecore_wl2_display_disconnect(display);
+    ecore_wl2_shutdown();
+    return false;
+  }
+
+  ref_++;
+  return false;
+}
+
+void RemoteSurfaceManager::Fini() {
+  if (ref_ > 1) {
+    ref_--;
+    return;
+  }
+
+  Dispose();
+}
+
+void RemoteSurfaceManager::Dispose() {
+  if (ref_ == 0)
+    return;
+
+  providers_.clear();
+
+  if (rsm_ != nullptr) {
+    tizen_remote_surface_manager_destroy(rsm_);
+    rsm_ = nullptr;
+  }
+
+  _E("Disconnect wl2 display");
+  ecore_wl2_display_disconnect(ecore_wl2_connected_display_get(nullptr));
+  ecore_wl2_shutdown();
+  ref_.exchange(0);
+}
+
+RemoteSurfaceProvider* RemoteSurfaceManager::CreateProvider(std::string id,
+    struct wl_surface* surface) {
+  if (rsm_ == nullptr) {
+    _E("tizen_remote_surface_manager is not ready");
+    return nullptr;
+  }
+
+  if (id.empty()) {
+    _E("Invalid parameter");
+    return nullptr;
+  }
+
+  auto* rsm_wrapper = static_cast<struct wl_proxy*>(
+      wl_proxy_create_wrapper(rsm_));
+  if (rsm_wrapper == nullptr) {
+    _E("wl_proxy_create_wrapper() is failed");
+    return nullptr;
+  }
+  auto rsm_wrapper_auto =
+    std::unique_ptr<struct wl_proxy, decltype(wl_proxy_wrapper_destroy)*>(
+        rsm_wrapper, wl_proxy_wrapper_destroy);
+
+  struct wl_display* display = ecore_wl2_display_get(
+      ecore_wl2_connected_display_get(nullptr));
+  if (display == nullptr) {
+    _E("ecore_wl2_display_get() is failed");
+    return nullptr;
+  }
+
+  struct wl_event_queue* queue = wl_display_create_queue(display);
+  auto queue_auto =
+      std::unique_ptr<struct wl_event_queue, decltype(wl_event_queue_destroy)*>(
+          queue, wl_event_queue_destroy);
+  wl_proxy_set_queue(rsm_wrapper, queue);
+
+  auto* win = ecore_wl2_window_surface_find(surface);
+  if (win == nullptr) {
+    _E("ecore_wl2_window_surface_find() is failed");
+    return nullptr;
+  }
+
+  auto* rsp = tizen_remote_surface_manager_create_provider(
+      reinterpret_cast<struct tizen_remote_surface_manager*>(rsm_wrapper),
+      surface);
+  if (rsp == nullptr) {
+    _E("tizen_remote_surface_manager_create_provider() is failed");
+    return nullptr;
+  }
+  auto rsp_auto =
+      std::unique_ptr<struct tizen_remote_surface_provider,
+                      decltype(tizen_remote_surface_provider_destroy)*>(
+          rsp, tizen_remote_surface_provider_destroy);
+
+  auto* provider = new RemoteSurfaceProvider(rsp, id, surface, win);
+  if (provider == nullptr) {
+    _E("Out of memory");
+    return nullptr;
+  }
+  rsp_auto.release();
+
+  static const struct tizen_remote_surface_provider_listener listener = {
+    RemoteSurfaceManager::ResourceIdCb,
+    RemoteSurfaceManager::VisibilityCb,
+  };
+  tizen_remote_surface_provider_add_listener(rsp, &listener, provider);
+  wl_display_roundtrip_queue(display, queue);
+  wl_proxy_set_queue(reinterpret_cast<struct wl_proxy*>(rsp), nullptr);
+  _D("remote surface(%p) is enabled", surface);
+  return provider;
+}
+
+void RemoteSurfaceManager::Insert(std::string id,
+    std::unique_ptr<RemoteSurfaceProvider> provider) {
+  providers_[std::move(id)] = std::move(provider);
+}
+
+bool RemoteSurfaceManager::Remove(const std::string& id) {
+  auto found = providers_.find(id);
+  if (found == providers_.end())
+    return false;
+
+  providers_.erase(found);
+  return true;
+}
+
+RemoteSurfaceManager::RemoteSurfaceManager() = default;
+
+RemoteSurfaceManager::~RemoteSurfaceManager() {
+  Dispose();
+}
+
+void RemoteSurfaceManager::ResourceIdCb(void* user_data,
+    struct tizen_remote_surface_provider* provider, uint32_t res_id) {
+  auto* rsp = static_cast<RemoteSurfaceProvider*>(user_data);
+  if (rsp == nullptr)
+    return;
+
+  rsp->SetResourceId(res_id);
+}
+
+void RemoteSurfaceManager::VisibilityCb(void* user_data,
+    struct tizen_remote_surface_provider* provider, uint32_t visibility) {
+  auto* rsp = static_cast<RemoteSurfaceProvider*>(user_data);
+  if (rsp == nullptr)
+    return;
+
+  rsp->SetVisibilityChangeEvent(visibility);
+}
+
+}  // namespace provider
+}  // namespace screen_connector
diff --git a/screen_connector_provider/remote_surface_manager.hh b/screen_connector_provider/remote_surface_manager.hh
new file mode 100644 (file)
index 0000000..ca48a77
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef REMOTE_SURFACE_MANAGER_HH_
+#define REMOTE_SURFACE_MANAGER_HH_
+
+#include <tizen-remote-surface-client-protocol.h>
+#include <wayland-client.h>
+#include <wayland-extension/tizen-extension-client-protocol.h>
+
+#include <atomic>
+#include <map>
+#include <memory>
+#include <string>
+
+#include "remote_surface_provider.hh"
+
+namespace screen_connector {
+namespace provider {
+
+class RemoteSurfaceManager {
+ public:
+  RemoteSurfaceManager(const RemoteSurfaceManager&) = delete;
+  RemoteSurfaceManager& operator = (const RemoteSurfaceManager&) = delete;
+
+  static RemoteSurfaceManager& GetInst();
+  bool Init();
+  void Fini();
+
+  RemoteSurfaceProvider* CreateProvider(std::string id,
+      struct wl_surface* surface);
+  void Insert(std::string id, std::unique_ptr<RemoteSurfaceProvider> provider);
+  bool Remove(const std::string& id);
+
+ private:
+  RemoteSurfaceManager();
+  ~RemoteSurfaceManager();
+  void Dispose();
+
+  static void ResourceIdCb(void* user_data,
+      struct tizen_remote_surface_provider* provider, uint32_t res_id);
+  static void VisibilityCb(void* user_data,
+      struct tizen_remote_surface_provider* provider, uint32_t visibility);
+
+ private:
+  std::atomic<int> ref_ { 0 };
+  struct tizen_remote_surface_manager* rsm_ = nullptr;
+  std::map<std::string, std::unique_ptr<RemoteSurfaceProvider>> providers_;
+};
+
+}  // namespace provider
+}  // namespace screen_connector
+
+#endif  // REMOTE_SURFACE_MANAGER_HH_
diff --git a/screen_connector_provider/remote_surface_provider.cc b/screen_connector_provider/remote_surface_provider.cc
new file mode 100644 (file)
index 0000000..466478d
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "remote_surface_provider.hh"
+
+#include <aul_screen_connector.h>
+
+#include "log_private.hh"
+
+namespace screen_connector {
+namespace provider {
+
+RemoteSurfaceProvider::RemoteSurfaceProvider(
+    struct tizen_remote_surface_provider* rsp, std::string id,
+    struct wl_surface* surface, Ecore_Wl2_Window* win)
+    : Handle<struct tizen_remote_surface_provider*>(rsp, true),
+      id_(std::move(id)), surface_(surface), win_(win) {
+}
+
+RemoteSurfaceProvider::~RemoteSurfaceProvider() {
+  if (GetRaw() != nullptr)
+    tizen_remote_surface_provider_destroy(GetRaw());
+}
+
+const std::string& RemoteSurfaceProvider::GetId() const {
+  return id_;
+}
+
+void RemoteSurfaceProvider::SetResourceId(uint32_t res_id) {
+  _D("%s : %u", id_.c_str(), res_id);
+  res_id_ = res_id;
+  aul_screen_connector_add_app_screen(id_.c_str(), res_id_);
+}
+
+int RemoteSurfaceProvider::SetInputEventFilter(uint32_t filter) {
+  if (tizen_remote_surface_provider_get_version(GetRaw()) <
+      TIZEN_REMOTE_SURFACE_PROVIDER_SET_INPUT_EVENT_FILTER_SINCE_VERSION) {
+    _E("Unsupported operation");
+    return -1;
+  }
+
+  tizen_remote_surface_provider_set_input_event_filter(GetRaw(), filter);
+  return 0;
+}
+
+void RemoteSurfaceProvider::SetVisibilityChangeEvent(uint32_t visibility) {
+  Ecore_Wl2_Event_Window_Visibility_Change* event =
+    static_cast<Ecore_Wl2_Event_Window_Visibility_Change*>(
+        calloc(1, sizeof(Ecore_Wl2_Event_Window_Visibility_Change)));
+  if (event == nullptr) {
+    _E("Out of memory");
+    return;
+  }
+
+  event->win = ecore_wl2_window_id_get(win_);
+  if (visibility == TIZEN_REMOTE_SURFACE_PROVIDER_VISIBILITY_TYPE_VISIBLE)
+    event->fully_obscured = 0;
+  else
+    event->fully_obscured = 1;
+
+  _D("Visibility: %u", visibility);
+  ecore_event_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, event, nullptr,
+      nullptr);
+}
+
+}  // namespace provider
+}  // namespace screen_connector
diff --git a/screen_connector_provider/remote_surface_provider.hh b/screen_connector_provider/remote_surface_provider.hh
new file mode 100644 (file)
index 0000000..f8c4e30
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef REMOTE_SURFACE_PROVIDER_HH_
+#define REMOTE_SURFACE_PROVIDER_HH_
+
+#include <Ecore_Wl2.h>
+#include <tizen-remote-surface-client-protocol.h>
+#include <wayland-client.h>
+#include <wayland-extension/tizen-extension-client-protocol.h>
+
+#include <string>
+
+#include "screen_connector_common/handle.h"
+
+namespace screen_connector {
+namespace provider {
+
+class RemoteSurfaceProvider
+    : public Handle<struct tizen_remote_surface_provider*> {
+ public:
+  RemoteSurfaceProvider(struct tizen_remote_surface_provider* rsp,
+      std::string id, struct wl_surface* surface, Ecore_Wl2_Window* win);
+  virtual ~RemoteSurfaceProvider();
+
+  const std::string& GetId() const;
+
+  void SetResourceId(uint32_t res_id);
+  int SetInputEventFilter(uint32_t filter);
+  void SetVisibilityChangeEvent(uint32_t visibility);
+
+ private:
+  std::string id_;
+  struct wl_surface* surface_;
+  Ecore_Wl2_Window* win_;
+  uint32_t res_id_ = 0;
+};
+
+}  // namespace provider
+}  // namespace screen_connector
+
+#endif  // REMOTE_SURFACE_PROVIDER_HH_
diff --git a/screen_connector_provider/screen_connector_provider.cc b/screen_connector_provider/screen_connector_provider.cc
new file mode 100644 (file)
index 0000000..16207d6
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2016 - 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/screen_connector_provider.h"
+
+#include "log_private.hh"
+#include "remote_surface_manager.hh"
+#include "screen_connector_common/export.h"
+
+using namespace screen_connector::provider;
+
+EXPORT screen_connector_provider_h screen_connector_provider_create(
+    const char* id, struct wl_surface* surface) {
+  if (id == nullptr || surface == nullptr) {
+    _E("Invalid parameter");
+    return nullptr;
+  }
+
+  return RemoteSurfaceManager::GetInst().CreateProvider(id, surface);
+}
+
+EXPORT int screen_connector_provider_remote_enable(const char* id,
+    struct wl_surface* surface) {
+  if (id == nullptr || surface == nullptr) {
+    _E("Invalid parameter");
+    return -1;
+  }
+
+  auto& manager = RemoteSurfaceManager::GetInst();
+  auto* provider = manager.CreateProvider(id, surface);
+  if (provider == nullptr)
+    return -1;
+
+  manager.Insert(id, std::unique_ptr<RemoteSurfaceProvider>(provider));
+  return 0;
+}
+
+EXPORT int screen_connector_provider_set_event_filter(
+    screen_connector_provider_h provider, unsigned int filter) {
+  if (provider == nullptr) {
+    _E("Invalid parameter");
+    return -1;
+  }
+
+  auto* handle = static_cast<RemoteSurfaceProvider*>(provider);
+  return handle->SetInputEventFilter(static_cast<uint32_t>(filter));
+}
+
+EXPORT int screen_connector_provider_destroy(
+    screen_connector_provider_h provider) {
+  if (provider == nullptr) {
+    _E("Invalid parameter");
+    return -1;
+  }
+
+  auto* handle = static_cast<RemoteSurfaceProvider*>(provider);
+  if (RemoteSurfaceManager::GetInst().Remove(handle->GetId()))
+    return 0;
+
+  delete handle;
+  return 0;
+}
+
+EXPORT int screen_connector_provider_init(void) {
+  return RemoteSurfaceManager::GetInst().Init();
+}
+
+EXPORT int screen_connector_provider_fini(void) {
+  RemoteSurfaceManager::GetInst().Fini();
+  return 0;
+}
diff --git a/screen_connector_provider/src/screen_connector_provider.c b/screen_connector_provider/src/screen_connector_provider.c
deleted file mode 100755 (executable)
index 9b2e7cc..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <glib.h>
-#include <sys/mman.h>
-#include <tizen.h>
-#include <dlog.h>
-#include <wayland-client.h>
-#include <Ecore_Wl2.h>
-#include <wayland-extension/tizen-extension-client-protocol.h>
-#include <tizen-remote-surface-client-protocol.h>
-#include <aul_screen_connector.h>
-
-#include "screen_connector_provider.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "SC_PROVIDER"
-
-static int __init_count;
-static struct tizen_remote_surface_manager *__rsm;
-static GList *__providers;
-
-struct screen_connector_provider_s {
-       struct wl_surface *surface;
-       struct tizen_remote_surface_provider *rsp;
-       char *id;
-       Ecore_Wl2_Window *win;
-};
-
-static void __rsp_resource_id_cb(void *data, struct tizen_remote_surface_provider *provider, uint32_t res_id)
-{
-       struct screen_connector_provider_s *remote = (struct screen_connector_provider_s *)data;
-
-       if (remote == NULL) {
-               LOGE("null remote");
-               return;
-       }
-
-       LOGD("add app screen : %s, %d", remote->id, res_id);
-       aul_screen_connector_add_app_screen(remote->id, res_id);
-}
-
-static void __rsp_visibility_cb(void *data, struct tizen_remote_surface_provider *provider, uint32_t visibility)
-{
-       struct screen_connector_provider_s *remote = (struct screen_connector_provider_s *)data;
-       Ecore_Wl2_Event_Window_Visibility_Change *ev;
-
-       ev = calloc(1, sizeof(Ecore_Wl2_Event_Window_Visibility_Change));
-       if (!ev) {
-               LOGE("out of memory");
-               return;
-       }
-
-       ev->win = ecore_wl2_window_id_get(remote->win);
-
-       if (visibility == TIZEN_REMOTE_SURFACE_PROVIDER_VISIBILITY_TYPE_VISIBLE)
-               ev->fully_obscured = 0;
-       else
-               ev->fully_obscured = 1;
-
-       LOGD("visibility changed:%d", visibility);
-
-       ecore_event_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, ev, NULL, NULL);
-}
-
-static const struct tizen_remote_surface_provider_listener __rsp_listener = {
-       __rsp_resource_id_cb,
-       __rsp_visibility_cb,
-};
-
-EXPORT_API screen_connector_provider_h screen_connector_provider_create(const char *id, struct wl_surface *surface)
-{
-       struct screen_connector_provider_s *remote = NULL;
-       struct wl_display *display;
-       struct wl_event_queue *queue = NULL;
-       struct wl_display *rsm_wrapper = NULL;
-
-       if (!__rsm) {
-               LOGE("__rsm is not ready");
-               goto out;
-       }
-
-       if (!surface || !id) {
-               LOGE("invalid parameter");
-               goto out;
-       }
-
-       rsm_wrapper = wl_proxy_create_wrapper(__rsm);
-       if (!rsm_wrapper) {
-               LOGE("failed to create wl display wrapper");
-               goto out;
-       }
-
-       display = ecore_wl2_display_get(ecore_wl2_connected_display_get(NULL));
-       if (!display) {
-               LOGE("Fail to get");
-               goto out;
-       }
-
-       queue = wl_display_create_queue(display);
-       wl_proxy_set_queue((struct wl_proxy *)rsm_wrapper, queue);
-
-       remote = (struct screen_connector_provider_s *)malloc(sizeof(struct screen_connector_provider_s));
-       if (!remote) {
-               LOGE("out of memory");
-               goto out;
-       }
-
-       remote->surface = surface;
-       remote->win = ecore_wl2_window_surface_find(surface);
-       if (!remote->win) {
-               LOGE("failed to find win");
-               free(remote);
-               remote = NULL;
-               goto out;
-       }
-
-       remote->rsp = tizen_remote_surface_manager_create_provider((struct tizen_remote_surface_manager *)rsm_wrapper, surface);
-       if (!remote->rsp) {
-               LOGE("failed to create provider");
-               free(remote);
-               remote = NULL;
-               goto out;
-       }
-
-       remote->id = strdup(id);
-       if (!remote->id) {
-               LOGE("out of memory");
-               tizen_remote_surface_provider_destroy(remote->rsp);
-               free(remote);
-               remote = NULL;
-               goto out;
-       }
-
-       tizen_remote_surface_provider_add_listener(remote->rsp, &__rsp_listener, remote);
-       wl_display_roundtrip_queue(display, queue);
-       wl_proxy_set_queue((struct wl_proxy *)remote->rsp, NULL);
-       LOGD("surface remote enabled");
-
-out:
-       if (queue)
-               wl_event_queue_destroy(queue);
-
-       if (rsm_wrapper)
-               wl_proxy_wrapper_destroy(rsm_wrapper);
-
-       return remote;
-}
-
-EXPORT_API int screen_connector_provider_remote_enable(const char *id, struct wl_surface *surface)
-{
-       screen_connector_provider_h handle;
-
-       handle = screen_connector_provider_create(id, surface);
-       if (!handle)
-               return -1;
-
-       __providers = g_list_append(__providers, handle);
-
-       return 0;
-}
-
-EXPORT_API int screen_connector_provider_set_event_filter(screen_connector_provider_h provider, unsigned int filter)
-{
-       if (!provider) {
-               LOGE("invalid arguments");
-               return -1;
-       }
-
-       if (tizen_remote_surface_provider_get_version(provider->rsp) <
-               TIZEN_REMOTE_SURFACE_PROVIDER_SET_INPUT_EVENT_FILTER_SINCE_VERSION) {
-               LOGE("unsupported operation");
-               return -1;
-       }
-
-       tizen_remote_surface_provider_set_input_event_filter(provider->rsp, filter);
-
-       return 0;
-}
-
-static void __destroy_provider(gpointer data)
-{
-       screen_connector_provider_h provider;
-
-       provider = (screen_connector_provider_h)data;
-
-       if (provider->rsp)
-               tizen_remote_surface_provider_destroy(provider->rsp);
-       if (provider->id)
-               free(provider->id);
-       free(provider);
-}
-
-EXPORT_API int screen_connector_provider_destroy(screen_connector_provider_h provider)
-{
-       if (!provider) {
-               LOGE("Invalid parameter");
-               return -1;
-       }
-
-       __providers = g_list_remove(__providers, provider);
-       __destroy_provider(provider);
-
-       return 0;
-}
-
-static void __shutdown_ecore_wl2_display()
-{
-       LOGE("disconnect wl2_display");
-       ecore_wl2_display_disconnect(ecore_wl2_connected_display_get(NULL));
-       ecore_wl2_shutdown();
-}
-
-EXPORT_API int screen_connector_provider_init(void)
-{
-       struct wl_registry *registry;
-       Ecore_Wl2_Global *global;
-       Eina_Iterator *globals;
-
-       if (__init_count > 0) {
-               __init_count++;
-               return 0;
-       }
-
-       if (!ecore_wl2_init()) {
-               LOGE("could not wl2 init");
-               return -1;
-       }
-
-       ecore_wl2_display_connect(NULL);
-       registry = ecore_wl2_display_registry_get(
-                       ecore_wl2_connected_display_get(NULL));
-       globals = ecore_wl2_display_globals_get(
-                       ecore_wl2_connected_display_get(NULL));
-
-       if (!registry || !globals) {
-               LOGE("could not get registry(%p) or global list(%p)", registry,
-                               globals);
-               __shutdown_ecore_wl2_display();
-               eina_iterator_free(globals);
-               return -1;
-       }
-
-       EINA_ITERATOR_FOREACH(globals, global) {
-               if (!strcmp(global->interface, "tizen_remote_surface_manager")) {
-                       __rsm = wl_registry_bind(registry, global->id,
-                               &tizen_remote_surface_manager_interface,
-                               global->version < 6 ? global->version : 6);
-               }
-       }
-
-       if (!__rsm) {
-               LOGE("could not get remote surface manager");
-               __shutdown_ecore_wl2_display();
-               eina_iterator_free(globals);
-               return -1;
-       }
-       eina_iterator_free(globals);
-       __init_count++;
-
-       return 0;
-}
-
-EXPORT_API int screen_connector_provider_fini(void)
-{
-       if (__init_count > 1) {
-               __init_count--;
-               return 0;
-       } else if (__init_count == 0) {
-               return 0;
-       }
-
-       if (__providers) {
-               g_list_free_full(__providers, __destroy_provider);
-               __providers = NULL;
-       }
-
-       if (__rsm) {
-               tizen_remote_surface_manager_destroy(__rsm);
-               __rsm = NULL;
-       }
-
-       __shutdown_ecore_wl2_display();
-
-       __init_count--;
-       return 0;
-}