- Separate initialization from dpms_is_available() to init_dpms().
- Integrate dpms exit sequence into exit_dpms() for poweroff.
- Delete pointer 'wl_glib_data' and use pointer 'info' instead,
which are practically same.
- Fix usage of disconnect_interface_with_dpms() considering
GSource finalize.
Change-Id: I7579b7338ee263b4c991cc8a055cefc0eb392f02
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
return 0;
}
-static gboolean lcd_on_wm_ready(gpointer data)
+static gboolean delayed_init_dpms(gpointer data)
{
int timeout;
- if (!check_wm_ready())
+ if (!init_dpms())
return G_SOURCE_CONTINUE;
switch (pm_cur_state) {
return G_SOURCE_REMOVE;
}
-static void add_timer_for_wm_ready(void)
+static void add_timer_for_init_dpms(void)
{
- guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL);
+ guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL);
if (id == 0)
- _E("Failed to add wm_ready timeout.");
+ _E("Failed to add init_dpms timeout.");
}
/**
int ret, i;
unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS);
int timeout = 0;
- bool wm_ready;
_I("Start power manager.");
/* wm_ready needs to be checked
* since display manager can be launched later than deviced.
* In the case, display cannot be turned on at the first booting */
- wm_ready = check_wm_ready();
- if (wm_ready)
+ // wm_ready = check_wm_ready();
+ if (init_dpms())
lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT);
else
- add_timer_for_wm_ready();
+ add_timer_for_init_dpms();
if (display_conf.lcd_always_on) {
_I("LCD always on.");
backlight_update();
- g_main_loop_unref(dpms_loop);
- g_main_context_unref(dpms_context);
+ exit_dpms();
ops = find_device("touchscreen");
if (!check_default(ops))
return 0;
}
-static gboolean lcd_on_wm_ready(gpointer data)
+static gboolean delayed_init_dpms(gpointer data)
{
int timeout;
- if (!check_wm_ready())
+ if (!init_dpms())
return G_SOURCE_CONTINUE;
switch (pm_cur_state) {
return G_SOURCE_REMOVE;
}
-static void add_timer_for_wm_ready(void)
+static void add_timer_for_init_dpms(void)
{
- guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL);
+ guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL);
if (id == 0)
- _E("Failed to add wm_ready timeout.");
+ _E("Failed to add init_dpms timeout.");
}
/**
int ret, i;
unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS);
int timeout = 0;
- bool wm_ready;
_I("Start power manager.");
/* wm_ready needs to be checked
* since display manager can be launched later than deviced.
* In the case, display cannot be turned on at the first booting */
- wm_ready = check_wm_ready();
- if (wm_ready)
+ // wm_ready = check_wm_ready();
+ if (init_dpms())
lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT);
else
- add_timer_for_wm_ready();
+ add_timer_for_init_dpms();
if (display_conf.lcd_always_on) {
_I("LCD always on.");
backlight_update();
- g_main_loop_unref(dpms_loop);
- g_main_context_unref(dpms_context);
+ exit_dpms();
ops = find_device("touchscreen");
if (!check_default(ops))
return 0;
}
-static gboolean lcd_on_wm_ready(gpointer data)
+static gboolean delayed_init_dpms(gpointer data)
{
int timeout;
- if (!check_wm_ready())
+ if (!init_dpms())
return G_SOURCE_CONTINUE;
switch (pm_cur_state) {
return G_SOURCE_REMOVE;
}
-static void add_timer_for_wm_ready(void)
+static void add_timer_for_init_dpms(void)
{
- guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL);
+ guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL);
if (id == 0)
- _E("Failed to add wm_ready timeout.");
+ _E("Failed to add init_dpms timeout.");
}
/**
int ret, i;
unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS);
int timeout = 0;
- bool wm_ready;
_I("Start power manager.");
/* wm_ready needs to be checked
* since display manager can be launched later than deviced.
* In the case, display cannot be turned on at the first booting */
- wm_ready = check_wm_ready();
- if (wm_ready)
+ // wm_ready = check_wm_ready();
+ if (init_dpms())
lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT);
else
- add_timer_for_wm_ready();
+ add_timer_for_init_dpms();
if (display_conf.lcd_always_on) {
_I("LCD always on.");
backlight_update();
- g_main_loop_unref(dpms_loop);
- g_main_context_unref(dpms_context);
+ exit_dpms();
ops = find_device("touchscreen");
if (!check_default(ops))
return 0;
}
-static gboolean lcd_on_wm_ready(gpointer data)
+static gboolean delayed_init_dpms(gpointer data)
{
int timeout;
- if (!check_wm_ready())
+ if (!init_dpms())
return G_SOURCE_CONTINUE;
switch (pm_cur_state) {
return G_SOURCE_REMOVE;
}
-static void add_timer_for_wm_ready(void)
+static void add_timer_for_init_dpms(void)
{
- guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL);
+ guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL);
if (id == 0)
- _E("Failed to add wm_ready timeout.");
+ _E("Failed to add init_dpms timeout.");
}
/**
int ret, i;
unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS);
int timeout = 0;
- bool wm_ready;
_I("Start power manager.");
/* wm_ready needs to be checked
* since display manager can be launched later than deviced.
* In the case, display cannot be turned on at the first booting */
- wm_ready = check_wm_ready();
- if (wm_ready)
+ // wm_ready = check_wm_ready();
+ if (init_dpms())
lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT);
else
- add_timer_for_wm_ready();
+ add_timer_for_init_dpms();
if (display_conf.lcd_always_on) {
_I("LCD always on.");
backlight_update();
- g_main_loop_unref(dpms_loop);
- g_main_context_unref(dpms_context);
+ exit_dpms();
ops = find_device("touchscreen");
if (!check_default(ops))
#include "core/log.h"
#include "display/util.h"
+#include "display/display-dpms.h"
#define DPMS_GET_TIMEOUT 10 /* milisecond */
uint32_t dpms_mode;
} wl_glib_info;
-wl_glib_info *info = NULL;
+static wl_glib_info *info = NULL;
-bool wm_is_ready;
+static bool wm_is_ready;
static bool dpms_connected;
-static GSource *wl_glib_data = NULL;
-GMainLoop *dpms_loop;
-GMainContext *dpms_context;
+static GMainLoop *dpms_loop;
+static GMainContext *dpms_context;
static bool dpms_get_state_done;
static void dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error)
return G_SOURCE_REMOVE;
}
-void disconnect_interface_with_dpms(void)
+static void disconnect_interface_with_dpms(wl_glib_info *info)
{
if (!dpms_connected)
return;
wl_display_disconnect(info->wl_disp);
info->wl_disp= NULL;
}
-
- if (wl_glib_data) {
- g_source_destroy(wl_glib_data);
- g_source_unref(wl_glib_data);
- wl_glib_data = NULL;
- }
}
static const struct tizen_dpms_manager_listener dpms_listener = {
info->wl_output= wl_registry_bind(registry, name, &wl_output_interface, 2);
if (!info->wl_output) {
_E("Failed to bind registry.");
- disconnect_interface_with_dpms();
+ g_source_destroy((GSource *)info);
+ exit_dpms();
+ return;
}
_D("Get wl_output.");
} else if (strcmp(interface, "tizen_dpms_manager") == 0) {
info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1);
if (!info->tz_dpms_mng) {
_E("Failed to bind registry.");
- disconnect_interface_with_dpms();
- } else
- tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info);
+ g_source_destroy((GSource *)info);
+ exit_dpms();
+ return;
+ }
+ tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info);
_D("Get dpms manager.");
}
}
_E("Source is NULL.");
return;
}
- info = (wl_glib_info *)source;
- disconnect_interface_with_dpms();
+ disconnect_interface_with_dpms((wl_glib_info *)source);
return;
}
.finalize = wl_glib_client_finalize,
};
-GSource* wl_glib_client_init(void)
+static bool wl_glib_client_init(void)
{
int ret;
goto err;
}
- dpms_context = g_main_context_new();
- dpms_loop = g_main_loop_new(dpms_context, false);
-
info->gfd.events = G_IO_IN | G_IO_ERR;
info->gfd.revents = 0;
g_source_attach(&info->gsource, dpms_context);
g_source_unref(&info->gsource);
- return &info->gsource;
+ return true;
err:
- if (info) {
- disconnect_interface_with_dpms();
+ if (info)
g_source_unref(&info->gsource);
- }
- return NULL;
+ return false;
}
-bool check_wm_ready(void)
+static bool check_wm_ready(void)
{
if (access("/run/.wm_ready", F_OK) == 0) {
_I("Window manager is ready.");
return false;
}
-bool connect_interface_with_dpms(void)
-{
- wl_glib_data = wl_glib_client_init();
- if (!wl_glib_data) {
- _E("Failed to init client.");
- return false;
- }
-
- return true;
-}
-
static bool dpms_is_available(void)
{
/* Check window manager */
return false;
}
- /* Try to connect interface with dpms, because window manager is ready */
- if (!dpms_connected) {
- _D("call connect_interface_with_dpms()");
- dpms_connected = connect_interface_with_dpms();
- return dpms_connected;
- }
-
- return true;
+ return dpms_connected;
}
void dpms_set_state(int on)
else
return -ETIMEDOUT;
}
+
+bool init_dpms(void)
+{
+ if (dpms_connected)
+ return true;
+
+ if (!check_wm_ready())
+ return false;
+
+ _I("Init dpms.");
+ dpms_context = g_main_context_new();
+ dpms_loop = g_main_loop_new(dpms_context, false);
+
+ dpms_connected = wl_glib_client_init();
+ if (!dpms_connected) {
+ g_main_loop_unref(dpms_loop);
+ dpms_loop = NULL;
+
+ g_main_context_unref(dpms_context);
+ dpms_context = NULL;
+ }
+
+ return dpms_connected;
+}
+
+void exit_dpms(void)
+{
+ _I("Exit dpms.");
+ if (dpms_loop) {
+ g_main_loop_unref(dpms_loop);
+ dpms_loop = NULL;
+ }
+
+ if (dpms_context) {
+ g_main_context_unref(dpms_context);
+ dpms_context = NULL;
+ }
+}
#ifndef __DISPLAY_DPMS_H__
#define __DISPLAY_DPMS_H__
-bool check_wm_ready(void);
-bool dpms_is_available(void);
-bool connect_interface_with_dpms(void);
-void disconnect_interface_with_dpms(void);
void dpms_set_state(int on);
int dpms_get_state(void);
-
-extern GMainLoop *dpms_loop;
-extern GMainContext *dpms_context;
+bool init_dpms(void);
+void exit_dpms(void);
#endif /* __DISPLAY_DPMS_H__ */