wayland-egl-tizen: Modified to do not create tizen_private. 91/264691/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Tue, 28 Sep 2021 07:59:37 +0000 (16:59 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 28 Sep 2021 07:59:39 +0000 (16:59 +0900)
 - tizen_private will be created by tpl_surface_create internally.
 - Calling any wl_egl_window_tizen APIs before calling
    tpl_surface_create will be ignored.

Change-Id: I5d5c195e27a2ea1d74e779fd6abc6025456e5df6
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/wayland-egl-tizen/wayland-egl-tizen.c

index bec3e92..737a324 100644 (file)
@@ -38,6 +38,7 @@
 #define WL_EGL_ERR(f, x...)            wl_egl_log_e("[ERROR]", f, ##x)
 #define WL_EGL_WARN(f, x...)   wl_egl_log_w("[WARN]", f, ##x)
 
+static int error_set = 0;
 
 static int
 _wl_egl_tizen_magic_check(struct tizen_private *private)
@@ -48,33 +49,45 @@ _wl_egl_tizen_magic_check(struct tizen_private *private)
        return 1;
 }
 
-void
-wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window,
-                                                                int rotation)
+static struct tizen_private*
+_wl_egl_tizen_get_tizen_private(struct wl_egl_window *egl_window)
 {
        struct tizen_private *private = NULL;
+
        if (egl_window == NULL) {
                WL_EGL_ERR("egl_window is NULL");
-               return;
+               return NULL;
        }
 
-       if (!egl_window->driver_private) {
-               private = tizen_private_create();
-               if (!private) {
-                       WL_EGL_ERR("Failed to create tizen_private.");
-                       return;
+       private = (struct tizen_private *)egl_window->driver_private;
+       if (private == NULL) {
+               if (!error_set) {
+                       WL_EGL_WARN("Should create tpl_surface with this wl_egl_window first.");
+                       WL_EGL_WARN("All wl_egl_window_tizen APIs will be ignored.");
+                       error_set = 1;
                }
+               return NULL;
+       }
 
-               egl_window->driver_private = (void *)private;
-       } else {
-               private = (struct tizen_private *)egl_window->driver_private;
-               if (!_wl_egl_tizen_magic_check(private)) {
-                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                               egl_window);
-                       return;
-               }
+       if (!_wl_egl_tizen_magic_check(private)) {
+               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                       egl_window);
+               return NULL;
        }
 
+       /* If tizen_private is created, the error_set is restored to zero. */
+       error_set = 0;
+
+       return private;
+}
+
+void
+wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window,
+                                                                int rotation)
+{
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return;
+
        if (private->rotation == rotation) {
                WL_EGL_WARN("wl_egl_window(%p) rotation(%d) already rotated",
                                        egl_window, rotation);
@@ -90,30 +103,10 @@ wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window,
 int
 wl_egl_window_tizen_get_capabilities(struct wl_egl_window *egl_window)
 {
-       struct tizen_private *private = NULL;
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
        int capabilities = WL_EGL_WINDOW_TIZEN_CAPABILITY_NONE;
 
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return -1;
-       }
-
-       if (!egl_window->driver_private) {
-               private = tizen_private_create();
-               if (!private) {
-                       WL_EGL_ERR("Failed to create tizen_private.");
-                       return -1;
-               }
-
-               egl_window->driver_private = (void *)private;
-       } else {
-               private = (struct tizen_private *)egl_window->driver_private;
-               if (!_wl_egl_tizen_magic_check(private)) {
-                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                               egl_window);
-                       return -1;
-               }
-       }
+       if (!private) return capabilities;
 
        if (private->get_rotation_capability)
                capabilities = private->get_rotation_capability(egl_window, egl_window->driver_private);
@@ -127,28 +120,8 @@ void
 wl_egl_window_tizen_set_buffer_transform(struct wl_egl_window *egl_window,
                                                                                 int wl_output_transform)
 {
-       struct tizen_private *private = NULL;
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return;
-       }
-
-       if (!egl_window->driver_private) {
-               private = tizen_private_create();
-               if (!private) {
-                       WL_EGL_ERR("Failed to create tizen_private.");
-                       return;
-               }
-
-               egl_window->driver_private = (void *)private;
-       } else {
-               private = (struct tizen_private *)egl_window->driver_private;
-               if (!_wl_egl_tizen_magic_check(private)) {
-                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                               egl_window);
-                       return;
-               }
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return;
 
        if (private->transform == wl_output_transform) {
                WL_EGL_WARN("wl_egl_window(%p) wl_output_transform(%d) already rotated",
@@ -163,28 +136,8 @@ void
 wl_egl_window_tizen_set_frontbuffer_mode(struct wl_egl_window *egl_window,
                                                                                 int set)
 {
-       struct tizen_private *private = NULL;
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return;
-       }
-
-       if (!egl_window->driver_private) {
-               private = tizen_private_create();
-               if (!private) {
-                       WL_EGL_ERR("Failed to create tizen_private.");
-                       return;
-               }
-
-               egl_window->driver_private = (void *)private;
-       } else {
-               private = (struct tizen_private *)egl_window->driver_private;
-               if (!_wl_egl_tizen_magic_check(private)) {
-                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                               egl_window);
-                       return;
-               }
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return;
 
        private->frontbuffer_mode = set;
 
@@ -197,28 +150,8 @@ void
 wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window,
                                                                                 int window_transform)
 {
-       struct tizen_private *private = NULL;
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return;
-       }
-
-       if (!egl_window->driver_private) {
-               private = tizen_private_create();
-               if (!private) {
-                       WL_EGL_ERR("Failed to create tizen_private.");
-                       return;
-               }
-
-               egl_window->driver_private = (void *)private;
-       } else {
-               private = (struct tizen_private *)egl_window->driver_private;
-               if (!_wl_egl_tizen_magic_check(private)) {
-                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                               egl_window);
-                       return;
-               }
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return;
 
        if (private->window_transform == window_transform) {
                WL_EGL_WARN("wl_egl_window(%p) window_transform(%d) already rotated",
@@ -232,28 +165,8 @@ wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window,
 unsigned int
 wl_egl_window_tizen_get_window_serial(struct wl_egl_window *egl_window)
 {
-       struct tizen_private *private = NULL;
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return 0;
-       }
-
-       if (!egl_window->driver_private) {
-               private = tizen_private_create();
-               if (!private) {
-                       WL_EGL_ERR("Failed to create tizen_private.");
-                       return 0;
-               }
-
-               egl_window->driver_private = (void *)private;
-       } else {
-               private = (struct tizen_private *)egl_window->driver_private;
-               if (!_wl_egl_tizen_magic_check(private)) {
-                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                               egl_window);
-                       return 0;
-               }
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return 0;
 
        return private->serial;
 }
@@ -262,23 +175,8 @@ void
 wl_egl_window_tizen_set_window_serial(struct wl_egl_window *egl_window,
                                                                          unsigned int serial)
 {
-       struct tizen_private *private = NULL;
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return;
-       }
-
-       private = egl_window->driver_private;
-       if (private == NULL) {
-               WL_EGL_ERR("wl_egl_window(%p) dirver_private is NULL", egl_window);
-               return;
-       }
-
-       if (!_wl_egl_tizen_magic_check(private)) {
-               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                       egl_window);
-               return;
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return;
 
        if (private->set_window_serial_callback)
                private->set_window_serial_callback(egl_window, egl_window->driver_private,
@@ -288,24 +186,8 @@ wl_egl_window_tizen_set_window_serial(struct wl_egl_window *egl_window,
 int
 wl_egl_window_tizen_create_commit_sync_fd(struct wl_egl_window *egl_window)
 {
-       struct tizen_private *private = NULL;
-
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return -1;
-       }
-
-       private = egl_window->driver_private;
-       if (private == NULL) {
-               WL_EGL_ERR("wl_egl_window(%p) dirver_private is NULL", egl_window);
-               return -1;
-       }
-
-       if (!_wl_egl_tizen_magic_check(private)) {
-               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                       egl_window);
-               return -1;
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return -1;
 
        if (private->create_commit_sync_fd)
                return private->create_commit_sync_fd(egl_window, egl_window->driver_private);
@@ -316,24 +198,8 @@ wl_egl_window_tizen_create_commit_sync_fd(struct wl_egl_window *egl_window)
 int
 wl_egl_window_tizen_create_presentation_sync_fd(struct wl_egl_window *egl_window)
 {
-       struct tizen_private *private = NULL;
-
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return -1;
-       }
-
-       private = egl_window->driver_private;
-       if (private == NULL) {
-               WL_EGL_ERR("wl_egl_window(%p) dirver_private is NULL", egl_window);
-               return -1;
-       }
-
-       if (!_wl_egl_tizen_magic_check(private)) {
-               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                       egl_window);
-               return -1;
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return -1;
 
        if (private->create_presentation_sync_fd)
                return private->create_presentation_sync_fd(egl_window, egl_window->driver_private);
@@ -345,24 +211,8 @@ int
 wl_egl_window_tizen_merge_sync_fds(struct wl_egl_window *egl_window,
                                                                   int sync_fd1, int sync_fd2)
 {
-       struct tizen_private *private = NULL;
-
-       if (egl_window == NULL) {
-               WL_EGL_ERR("egl_window is NULL");
-               return -1;
-       }
-
-       private = egl_window->driver_private;
-       if (private == NULL) {
-               WL_EGL_ERR("wl_egl_window(%p) dirver_private is NULL", egl_window);
-               return -1;
-       }
-
-       if (!_wl_egl_tizen_magic_check(private)) {
-               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
-                                       egl_window);
-               return -1;
-       }
+       struct tizen_private *private = _wl_egl_tizen_get_tizen_private(egl_window);
+       if (!private) return -1;
 
        if (private->merge_sync_fds)
                return private->merge_sync_fds(egl_window->driver_private, sync_fd1, sync_fd2);