} 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
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.
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
*/
*/
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);
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);
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);
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)
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);
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)
}
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();
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)
{
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;
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;
};
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;
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