tpl: Added a new API tpl_surface_get() 87/165687/3
authorjoonbum.ko <joonbum.ko@samsung.com>
Tue, 2 Jan 2018 04:25:03 +0000 (13:25 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Wed, 3 Jan 2018 09:25:28 +0000 (18:25 +0900)
 - tpl_surface_t *tpl_surface_get(tpl_display_t *display, tpl_handle_t handle)

 - Like tpl_display_get(), it will find and return if there is a tpl_surface that was
  created in the given native handle at runtime.
 - Avoid creating multiple tpl_surfaces with the same native handle.

Change-Id: Ia2b7a7ddef32153c47ba11dea4e08130fd36cb56
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl.h
src/tpl_surface.c

index 0ebf067..27a3ba9 100644 (file)
--- a/src/tpl.h
+++ b/src/tpl.h
@@ -396,6 +396,28 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle,
                                   tpl_surface_type_t type, tbm_format format);
 
 /**
+ * Get TPL surface object for the given native surface.
+ *
+ * If there's already existing TPL surface for the given native surface,
+ * then return the existed TPL surface.
+ *
+ * This API is not incremented the reference count of found TPL surface object.
+ * To ensure that the obtained TPL surface is safe to use, it must be increased
+ *  the ref count by using tpl_object_reference().
+ * When it becomes unnecessary, it should be decreased by using tpl_object_unreference().
+ *
+ * @param display TPL display used to create TPL surface with given handle.
+ * @param handle Handle to the native surface.
+ * @return pointer to TPL surface if it has already been created, NULL otherwise.
+ *
+ * @see tpl_surface_create()
+ * @see tpl_object_reference()
+ * @see tpl_object_unreference()
+ */
+tpl_surface_t *
+tpl_surface_get(tpl_display_t *display, tpl_handle_t handle);
+
+/**
  * Get the TPL display where the given TPL surface was created from.
  *
  * @param surface surface to get display.
index a7a6b1e..2252f15 100644 (file)
@@ -36,13 +36,6 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle,
                return NULL;
        }
 
-       surface = __tpl_runtime_find_surface(display->backend.type, handle);
-       if (surface) {
-               TPL_LOG_F("[REUSE] tpl_display_t(%p) tpl_surface_t(%p) native_handle(%p) format(%d)",
-                                 display, surface, handle, format);
-               return surface;
-       }
-
        surface = (tpl_surface_t *) calloc(1, sizeof(tpl_surface_t));
        if (!surface) {
                TPL_ERR("Failed to allocate memory for surface!");
@@ -89,6 +82,30 @@ tpl_surface_create(tpl_display_t *display, tpl_handle_t handle,
        return surface;
 }
 
+tpl_surface_t *
+tpl_surface_get(tpl_display_t *display, tpl_handle_t handle)
+{
+       tpl_surface_t *surface = NULL;
+
+       if (!display) {
+               TPL_ERR("Display is NULL!");
+               return NULL;
+       }
+
+       if (!handle) {
+               TPL_ERR("Handle is NULL!");
+               return NULL;
+       }
+
+       surface = __tpl_runtime_find_surface(display->backend.type, handle);
+       if (surface) {
+               TPL_LOG_F("[REUSE] tpl_display_t(%p) tpl_surface_t(%p) native_handle(%p)",
+                                 display, surface, handle);
+       }
+
+       return surface;
+}
+
 tpl_display_t *
 tpl_surface_get_display(tpl_surface_t *surface)
 {