support the output change handler 30/65530/1
authorBoram Park <boram1288.park@samsung.com>
Thu, 24 Mar 2016 11:49:53 +0000 (20:49 +0900)
committerBoram Park <boram1288.park@samsung.com>
Mon, 11 Apr 2016 10:32:59 +0000 (19:32 +0900)
Change-Id: Icc9887e49f39fb6a8dddcf8a61d32b5f6c8e07aa

include/tdm.h
include/tdm_backend.h
src/tdm.c
src/tdm_display.c
src/tdm_private.h

index 9d82ebc..04cbcb5 100644 (file)
@@ -66,6 +66,24 @@ typedef enum
 } tdm_display_capability;
 
 /**
+ * @brief The output change enumeration of #tdm_output_change_handler
+ */
+typedef enum {
+       TDM_OUTPUT_CHANGE_CONNECTION    = (1 << 0), /**< connection chagne */
+       TDM_OUTPUT_CHANGE_DPMS          = (1 << 1), /**< dpms change */
+} tdm_output_change_type;
+
+/**
+ * @brief The output change handler
+ * @details This handler will be called when the status of a output object is
+ * changed in runtime.
+ */
+typedef void (*tdm_output_change_handler)(tdm_output *output,
+                                          tdm_output_change_type type,
+                                          tdm_value value,
+                                          void *user_data);
+
+/**
  * @brief Initialize a display object
  * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value.
  * @return A display object
@@ -234,6 +252,32 @@ tdm_error
 tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status);
 
 /**
+ * @brief Add a output change handler
+ * @details The handler will be called when the status of a
+ * output object is changed. connection, DPMS, etc.
+ * @param[in] output A output object
+ * @param[in] func A output change handler
+ * @param[in] user_data The user data
+ * @return #TDM_ERROR_NONE if success. Otherwise, error value.
+ */
+tdm_error
+tdm_output_add_change_handler(tdm_output *output,
+                              tdm_output_change_handler func,
+                              void *user_data);
+
+/**
+ * @brief Remove a output change handler
+ * @param[in] output A output object
+ * @param[in] func A output change handler
+ * @param[in] user_data The user data
+ * @return #TDM_ERROR_NONE if success. Otherwise, error value.
+ */
+void
+tdm_output_remove_change_handler(tdm_output *output,
+                                 tdm_output_change_handler func,
+                                 void *user_data);
+
+/**
  * @brief Get the connection type of a output object.
  * @param[in] output A output object
  * @param[out] type The connection type.
index 0fe68c8..e5837b9 100644 (file)
@@ -63,6 +63,15 @@ extern "C" {
 typedef void tdm_backend_data;
 
 /**
+ * @brief The output status handler
+ * @details This handler will be called when the status of a output object is
+ * changed in runtime.
+ */
+typedef void (*tdm_output_status_handler)(tdm_output *output,
+                                          tdm_output_conn_status status,
+                                          void *user_data);
+
+/**
  * @brief The display capabilities structure of a backend module
  * @see The display_get_capabilitiy() function of #tdm_func_display
  */
@@ -459,6 +468,19 @@ typedef struct _tdm_func_output {
         */
        tdm_capture *(*output_create_capture)(tdm_output *output, tdm_error *error);
 
+       /**
+        * @brief Set a output connection status handler
+        * @details The handler will be called when the connection status of a
+        * output object is changed.
+        * @param[in] output A output object
+        * @param[in] func A output status handler
+        * @param[in] user_data The user data
+        * @return #TDM_ERROR_NONE if success. Otherwise, error value.
+        */
+       tdm_error (*output_set_status_handler)(tdm_output *output,
+                                              tdm_output_status_handler func,
+                                              void *user_data);
+
        void (*reserved1)(void);
        void (*reserved2)(void);
        void (*reserved3)(void);
index 0023e7e..4c2e9f6 100644 (file)
--- a/src/tdm.c
+++ b/src/tdm.c
@@ -122,6 +122,7 @@ _tdm_display_destroy_private_output(tdm_private_output *private_output)
        tdm_private_capture *c = NULL, *cc = NULL;
        tdm_private_vblank_handler *v = NULL, *vv = NULL;
        tdm_private_commit_handler *m = NULL, *mm = NULL;
+       tdm_private_change_handler *h = NULL, *hh = NULL;
 
        LIST_DEL(&private_output->link);
 
@@ -137,6 +138,11 @@ _tdm_display_destroy_private_output(tdm_private_output *private_output)
                free(m);
        }
 
+       LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list, link) {
+               LIST_DEL(&h->link);
+               free(h);
+       }
+
        LIST_FOR_EACH_ENTRY_SAFE(c, cc, &private_output->capture_list, link)
        tdm_capture_destroy_internal(c);
 
@@ -356,6 +362,21 @@ failed_update:
        return ret;
 }
 
+static void
+_tdm_output_cb_status(tdm_output *output, tdm_output_conn_status status,
+                      void *user_data)
+{
+       tdm_private_output *private_output = user_data;
+       tdm_value value;
+
+       TDM_RETURN_IF_FAIL(private_output);
+
+       value.u32 = status;
+       tdm_output_call_change_handler_internal(private_output,
+                                               TDM_OUTPUT_CHANGE_CONNECTION,
+                                               value);
+}
+
 static tdm_error
 _tdm_display_update_output(tdm_private_display *private_display,
                            tdm_output *output_backend, int pipe)
@@ -381,6 +402,16 @@ _tdm_display_update_output(tdm_private_display *private_display,
                LIST_INITHEAD(&private_output->capture_list);
                LIST_INITHEAD(&private_output->vblank_handler_list);
                LIST_INITHEAD(&private_output->commit_handler_list);
+               LIST_INITHEAD(&private_output->change_handler_list);
+
+               if (func_output->output_set_status_handler) {
+                       private_output->regist_change_cb = 1;
+                       ret = func_output->output_set_status_handler(output_backend,
+                                                                    _tdm_output_cb_status,
+                                                                    private_output);
+                       if (ret != TDM_ERROR_NONE)
+                               goto failed_update;
+               }
        } else
                _tdm_display_destroy_caps_output(&private_output->caps);
 
index f730f11..54e44f6 100644 (file)
@@ -101,6 +101,40 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     private_output = private_layer->private_output; \
     private_display = private_output->private_display
 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+struct type_name {
+       int type;
+       const char *name;
+};
+
+#define type_name_fn(res) \
+const char * res##_str(int type) {                     \
+       unsigned int i;                                 \
+       for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
+               if (res##_names[i].type == type)        \
+                       return res##_names[i].name;     \
+       }                                               \
+       return "(invalid)";                             \
+}
+
+struct type_name dpms_names[] = {
+       { TDM_OUTPUT_DPMS_ON, "on" },
+       { TDM_OUTPUT_DPMS_STANDBY, "standby" },
+       { TDM_OUTPUT_DPMS_SUSPEND, "suspend" },
+       { TDM_OUTPUT_DPMS_OFF, "off" },
+};
+
+static type_name_fn(dpms)
+
+struct type_name status_names[] = {
+       { TDM_OUTPUT_CONN_STATUS_DISCONNECTED, "disconnected" },
+       { TDM_OUTPUT_CONN_STATUS_CONNECTED, "connected" },
+       { TDM_OUTPUT_CONN_STATUS_MODE_SETTED, "mode_setted" },
+};
+
+static type_name_fn(status)
+
 EXTERN tdm_error
 tdm_display_get_capabilities(tdm_display *dpy,
                              tdm_display_capability *capabilities)
@@ -380,6 +414,73 @@ tdm_output_get_conn_status(tdm_output *output, tdm_output_conn_status *status)
 }
 
 EXTERN tdm_error
+tdm_output_add_change_handler(tdm_output *output,
+                              tdm_output_change_handler func,
+                              void *user_data)
+{
+       tdm_private_change_handler *change_handler;
+       OUTPUT_FUNC_ENTRY();
+
+       TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+       pthread_mutex_lock(&private_display->lock);
+
+       if (!private_output->regist_change_cb) {
+               _pthread_mutex_unlock(&private_display->lock);
+               TDM_DBG("failed: not implemented!!");
+               return TDM_ERROR_NOT_IMPLEMENTED;
+       }
+
+       change_handler = calloc(1, sizeof(tdm_private_change_handler));
+       if (!change_handler) {
+               TDM_ERR("failed: alloc memory");
+               _pthread_mutex_unlock(&private_display->lock);
+               return TDM_ERROR_OUT_OF_MEMORY;
+       }
+
+       LIST_ADD(&change_handler->link, &private_output->change_handler_list);
+       change_handler->private_output = private_output;
+       change_handler->func = func;
+       change_handler->user_data = user_data;
+
+       _pthread_mutex_unlock(&private_display->lock);
+
+       return ret;
+}
+
+EXTERN void
+tdm_output_remove_change_handler(tdm_output *output,
+                                 tdm_output_change_handler func,
+                                 void *user_data)
+{
+       tdm_private_display *private_display;
+       tdm_private_output *private_output;
+       tdm_private_change_handler *h = NULL, *hh = NULL;
+
+       TDM_RETURN_IF_FAIL(output != NULL);
+       TDM_RETURN_IF_FAIL(func != NULL);
+
+       private_output = (tdm_private_output*)output;
+       private_display = private_output->private_display;
+
+       _pthread_mutex_lock(&private_display->lock);
+
+       LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list, link) {
+               if (h->func != func || h->user_data != user_data)
+                       continue;
+
+               LIST_DEL(&h->link);
+               free(h);
+
+               _pthread_mutex_unlock(&private_display->lock);
+
+               return;
+       }
+
+       _pthread_mutex_unlock(&private_display->lock);
+}
+
+EXTERN tdm_error
 tdm_output_get_output_type(tdm_output *output, tdm_output_type *type)
 {
        OUTPUT_FUNC_ENTRY();
@@ -902,6 +1003,35 @@ tdm_output_create_capture(tdm_output *output, tdm_error *error)
        return capture;
 }
 
+INTERN void
+tdm_output_call_change_handler_internal(tdm_private_output *private_output,
+                                        tdm_output_change_type type,
+                                        tdm_value value)
+{
+       tdm_private_change_handler *change_handler;
+       tdm_private_display *private_display;
+
+       TDM_RETURN_IF_FAIL(private_output);
+
+       private_display = private_output->private_display;
+
+       if (type & TDM_OUTPUT_CHANGE_CONNECTION)
+               TDM_INFO("output(%d) changed: %s",
+                        private_output->pipe, status_str(value.u32));
+       if (type & TDM_OUTPUT_CHANGE_DPMS)
+               TDM_INFO("output(%d) changed: dpms %s",
+                        private_output->pipe, dpms_str(value.u32));
+
+       _pthread_mutex_unlock(&private_display->lock);
+
+       LIST_FOR_EACH_ENTRY(change_handler, &private_output->change_handler_list, link) {
+               change_handler->func(private_output, type,
+                                    value, change_handler->user_data);
+       }
+
+       _pthread_mutex_lock(&private_display->lock);
+}
+
 EXTERN tdm_error
 tdm_layer_get_capabilities(tdm_layer *layer, tdm_layer_capability *capabilities)
 {
index 1c0009d..bef8fd0 100644 (file)
@@ -163,6 +163,7 @@ typedef struct _tdm_private_capture tdm_private_capture;
 typedef struct _tdm_private_event tdm_private_event;
 typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
 typedef struct _tdm_private_commit_handler tdm_private_commit_handler;
+typedef struct _tdm_private_change_handler tdm_private_change_handler;
 
 struct _tdm_private_display {
        pthread_mutex_t lock;
@@ -208,11 +209,13 @@ struct _tdm_private_output {
 
        int regist_vblank_cb;
        int regist_commit_cb;
+       int regist_change_cb;
 
        struct list_head layer_list;
        struct list_head capture_list;
        struct list_head vblank_handler_list;
        struct list_head commit_handler_list;
+       struct list_head change_handler_list;
 
        void **layers_ptr;
 };
@@ -280,6 +283,14 @@ struct _tdm_private_commit_handler {
        void *user_data;
 };
 
+struct _tdm_private_change_handler {
+       struct list_head link;
+
+       tdm_private_output *private_output;
+       tdm_output_change_handler func;
+       void *user_data;
+};
+
 typedef struct _tdm_buffer_info {
        tbm_surface_h buffer;
 
@@ -293,6 +304,11 @@ typedef struct _tdm_buffer_info {
        struct list_head link;
 } tdm_buffer_info;
 
+void
+tdm_output_call_change_handler_internal(tdm_private_output *private_output,
+                                        tdm_output_change_type type,
+                                        tdm_value value);
+
 tdm_private_pp *
 tdm_pp_create_internal(tdm_private_display *private_display, tdm_error *error);
 void