4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <sys/types.h>
23 #include <sys/socket.h>
31 #include <X11/Xatom.h>
33 #include <X11/Xutil.h>
34 #include <X11/extensions/Xcomposite.h>
35 #include <X11/extensions/XShm.h>
40 #include <Ecore_Evas.h>
41 #include <Ecore_Input_Evas.h>
42 #include <Elementary.h>
43 #include <glib-object.h>
48 #ifdef WEARABLE_PROFILE
49 #include <proc_stat.h>
51 #include "appcore-internal.h"
52 #include "appcore-efl.h"
53 #include "virtual_canvas.h"
55 #define SYSMAN_MAXSTR 100
56 #define SYSMAN_MAXARG 16
57 #define SYSNOTI_SOCKET_PATH "/tmp/sn"
58 #define RETRY_READ_COUNT 10
60 #define PREDEF_BACKGRD "backgrd"
61 #define PREDEF_FOREGRD "foregrd"
74 char *argv[SYSMAN_MAXARG];
79 static bool resource_reclaiming = TRUE;
80 static int tmp_val = 0;
87 Ecore_Event_Handler *hshow;
88 Ecore_Event_Handler *hhide;
89 Ecore_Event_Handler *hvchange;
90 Ecore_Event_Handler *hcmsg; /* WM_ROTATE */
92 Ecore_Timer *mftimer; /* Ecore Timer for memory flushing */
94 struct appcore_ops *ops;
95 void (*mfcb) (void); /* Memory Flushing Callback */
100 int (*rot_cb) (enum appcore_rm, void *);
102 enum appcore_rm rot_mode;
105 static struct ui_priv priv;
107 static const char *_ae_name[AE_MAX] = {
108 [AE_UNKNOWN] = "UNKNOWN",
109 [AE_CREATE] = "CREATE",
110 [AE_TERMINATE] = "TERMINATE",
111 [AE_PAUSE] = "PAUSE",
112 [AE_RESUME] = "RESUME",
113 [AE_RESET] = "RESET",
114 [AE_LOWMEM_POST] = "LOWMEM_POST",
115 [AE_MEM_FLUSH] = "MEM_FLUSH",
118 static const char *_as_name[] = {
120 [AS_CREATED] = "CREATED",
121 [AS_RUNNING] = "RUNNING",
122 [AS_PAUSED] = "PAUSED",
123 [AS_DYING] = "DYING",
126 static bool b_active = 0;
132 static struct ui_wm_rotate wm_rotate;
134 static inline int send_int(int fd, int val)
136 return write(fd, &val, sizeof(int));
139 static inline int send_str(int fd, char *str)
145 ret = write(fd, &len, sizeof(int));
148 if (len > SYSMAN_MAXSTR)
150 write(fd, &len, sizeof(int));
151 ret = write(fd, str, len);
156 static int sysnoti_send(struct sysnoti *msg)
163 struct sockaddr_un clientaddr;
166 client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
167 if (client_sockfd == -1) {
168 _ERR("%s: socket create failed\n", __FUNCTION__);
171 bzero(&clientaddr, sizeof(clientaddr));
172 clientaddr.sun_family = AF_UNIX;
173 strncpy(clientaddr.sun_path, SYSNOTI_SOCKET_PATH, sizeof(clientaddr.sun_path) - 1);
174 client_len = sizeof(clientaddr);
176 if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) <
178 _ERR("%s: connect failed\n", __FUNCTION__);
179 close(client_sockfd);
183 send_int(client_sockfd, msg->pid);
184 send_int(client_sockfd, msg->cmd);
185 send_str(client_sockfd, msg->type);
186 send_str(client_sockfd, msg->path);
187 send_int(client_sockfd, msg->argc);
188 for (i = 0; i < msg->argc; i++)
189 send_str(client_sockfd, msg->argv[i]);
191 while (retry_count < RETRY_READ_COUNT) {
192 r = read(client_sockfd, &result, sizeof(int));
194 if (errno == EINTR) {
195 _ERR("Re-read for error(EINTR)");
199 _ERR("Read fail for str length");
206 if (retry_count == RETRY_READ_COUNT) {
207 _ERR("Read retry failed");
210 close(client_sockfd);
214 static int _call_predef_action(const char *type, int num, ...)
223 if (type == NULL || num > SYSMAN_MAXARG) {
228 msg = malloc(sizeof(struct sysnoti));
231 /* Do something for not enought memory error */
236 msg->cmd = CALL_SYSMAN_ACTION;
237 msg->type = (char *)type;
241 va_start(argptr, num);
242 for (i = 0; i < num; i++) {
243 args = va_arg(argptr, char *);
248 ret = sysnoti_send(msg);
254 static int _inform_foregrd(void)
257 snprintf(buf, sizeof(buf), "%d", getpid());
258 return _call_predef_action(PREDEF_FOREGRD, 1, buf);
261 static int _inform_backgrd(void)
264 snprintf(buf, sizeof(buf), "%d", getpid());
265 return _call_predef_action(PREDEF_BACKGRD, 1, buf);
270 char appid[APPID_MAX];
273 static void _capture_and_make_file(Ecore_X_Window win, int pid, const char *package);
275 static int WIN_COMP(gconstpointer data1, gconstpointer data2)
277 struct win_node *a = (struct win_node *)data1;
278 struct win_node *b = (struct win_node *)data2;
279 return (int)((a->win)-(b->win));
282 GSList *g_winnode_list = NULL;
284 #if defined(MEMORY_FLUSH_ACTIVATE)
285 static Eina_Bool __appcore_memory_flush_cb(void *data)
287 struct ui_priv *ui = (struct ui_priv *)data;
289 appcore_flush_memory();
292 return ECORE_CALLBACK_CANCEL;
295 static int __appcore_low_memory_post_cb(struct ui_priv *ui)
297 if (ui->state == AS_PAUSED) {
298 // appcore_flush_memory();
306 static void __appcore_timer_add(struct ui_priv *ui)
308 ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
311 static void __appcore_timer_del(struct ui_priv *ui)
314 ecore_timer_del(ui->mftimer);
321 static int __appcore_low_memory_post_cb(ui_priv *ui)
326 #define __appcore_timer_add(ui) 0
327 #define __appcore_timer_del(ui) 0
331 static void __appcore_efl_memory_flush_cb(void)
333 //_DBG("[APP %d] __appcore_efl_memory_flush_cb()", _pid);
334 elm_cache_all_flush();
337 static void __do_app(enum app_event event, void *data, bundle * b)
340 struct ui_priv *ui = data;
342 _ret_if(ui == NULL || event >= AE_MAX);
343 _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
344 _as_name[ui->state]);
346 if (event == AE_MEM_FLUSH) {
351 if (event == AE_LOWMEM_POST) {
352 if (__appcore_low_memory_post_cb(ui) == 0)
356 if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
357 __appcore_timer_del(ui);
359 if (event == AE_TERMINATE) {
360 _DBG("[APP %d] TERMINATE", _pid);
361 ui->state = AS_DYING;
366 _ret_if(ui->ops == NULL);
370 _DBG("[APP %d] RESET", _pid);
371 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]",
374 r = ui->ops->reset(b, ui->ops->data);
375 ui->state = AS_RUNNING;
376 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
380 if (ui->state == AS_RUNNING) {
381 _DBG("[APP %d] PAUSE", _pid);
383 r = ui->ops->pause(ui->ops->data);
384 ui->state = AS_PAUSED;
385 if(r >= 0 && resource_reclaiming == TRUE)
386 __appcore_timer_add(ui);
388 /* TODO : rotation stop */
389 //r = appcore_pause_rotation_cb();
390 #ifdef WEARABLE_PROFILE
391 proc_group_change_status(PROC_CGROUP_SET_BACKGRD, getpid(), NULL);
398 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
400 if (ui->state == AS_PAUSED) {
401 _DBG("[APP %d] RESUME", _pid);
403 r = ui->ops->resume(ui->ops->data);
404 ui->state = AS_RUNNING;
406 /*TODO : rotation start*/
407 //r = appcore_resume_rotation_cb();
408 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
410 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
412 #ifdef WEARABLE_PROFILE
413 proc_group_change_status(PROC_CGROUP_SET_FOREGRD, getpid(), NULL);
425 static struct ui_ops efl_ops = {
431 static bool __check_visible(void)
434 struct win_node *entry = NULL;
436 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
438 //_DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
439 if(entry->bfobscured == FALSE)
445 static bool __check_skip(Ecore_X_Window xwin)
448 Ecore_X_Window_State *state;
451 ret = ecore_x_netwm_window_state_get(xwin, &state, &num);
452 _DBG("ret(%d), win(%x), state(%x), num(%d)", ret, xwin, state, num);
454 for (i = 0; i < num; i++) {
455 _DBG("state[%d] : %d", i, state[i]);
457 case ECORE_X_WINDOW_STATE_SKIP_TASKBAR:
461 case ECORE_X_WINDOW_STATE_SKIP_PAGER:
475 static bool __exist_win(unsigned int win)
477 struct win_node temp;
482 f = g_slist_find_custom(g_winnode_list, &temp, WIN_COMP);
491 static bool __add_win(unsigned int win)
496 t = calloc(1, sizeof(struct win_node));
501 t->bfobscured = FALSE;
503 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
505 f = g_slist_find_custom(g_winnode_list, t, WIN_COMP);
509 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
514 g_winnode_list = g_slist_append(g_winnode_list, t);
520 static bool __delete_win(unsigned int win)
522 struct win_node temp;
527 f = g_slist_find_custom(g_winnode_list, &temp, WIN_COMP);
530 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
535 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
542 static bool __update_win(unsigned int win, bool bfobscured)
544 struct win_node temp;
549 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
554 f = g_slist_find_custom(g_winnode_list, &temp, WIN_COMP);
558 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
562 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
566 t = calloc(1, sizeof(struct win_node));
571 t->bfobscured = bfobscured;
573 g_winnode_list = g_slist_append(g_winnode_list, t);
580 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
581 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
583 static int __check_wm_rotation_support(void)
585 _DBG("Disable window manager rotation");
588 Ecore_X_Window root, win, win2;
591 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
592 _WM_WINDOW_ROTATION_SUPPORTED =
593 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
596 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
597 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
598 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
601 root = ecore_x_window_root_first_get();
602 ret = ecore_x_window_prop_xid_get(root,
603 _WM_WINDOW_ROTATION_SUPPORTED,
606 if ((ret == 1) && (win))
608 ret = ecore_x_window_prop_xid_get(win,
609 _WM_WINDOW_ROTATION_SUPPORTED,
612 if ((ret == 1) && (win2 == win))
620 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
623 struct win_node *entry = NULL;
626 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
629 ecore_x_window_prop_card32_set(entry->win,
630 _WM_WINDOW_ROTATION_SUPPORTED,
635 ecore_x_window_prop_card32_set(win,
636 _WM_WINDOW_ROTATION_SUPPORTED,
641 Ecore_X_Atom atom_parent;
643 static Eina_Bool __show_cb(void *data, int type, void *event)
645 Ecore_X_Event_Window_Show *ev;
647 Ecore_X_Window parent;
651 ret = ecore_x_window_prop_window_get(ev->win, atom_parent, &parent, 1);
654 // This is child window. Skip!!!
655 return ECORE_CALLBACK_PASS_ON;
658 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
660 if (!__exist_win((unsigned int)ev->win)) {
662 if ((priv.wm_rot_supported) && (1 == priv.rot_started)) {
663 __set_wm_rotation_support(ev->win, 1);
665 __add_win((unsigned int)ev->win);
668 __update_win((unsigned int)ev->win, FALSE);
670 return ECORE_CALLBACK_RENEW;
673 static Eina_Bool __hide_cb(void *data, int type, void *event)
675 Ecore_X_Event_Window_Hide *ev;
680 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
682 if (__exist_win((unsigned int)ev->win)) {
683 __delete_win((unsigned int)ev->win);
685 bvisibility = __check_visible();
686 if (!bvisibility && b_active == 1) {
687 _DBG(" Go to Pasue state \n");
689 __do_app(AE_PAUSE, data, NULL);
691 _capture_and_make_file(ev->win, getpid(), appid);
692 } else if ( aul_is_subapp() ) {
693 _capture_and_make_file(ev->win, getpid(), appcore_get_caller_appid());
698 return ECORE_CALLBACK_RENEW;
701 static Eina_Bool __visibility_cb(void *data, int type, void *event)
703 Ecore_X_Event_Window_Visibility_Change *ev;
708 __update_win((unsigned int)ev->win, ev->fully_obscured);
709 bvisibility = __check_visible();
711 if (bvisibility && b_active == 0) {
712 _DBG(" Go to Resume state\n");
715 __do_app(AE_RESUME, data, NULL);
717 } else if (!bvisibility && b_active == 1) {
718 _DBG(" Go to Pasue state \n");
720 __do_app(AE_PAUSE, data, NULL);
722 _capture_and_make_file(ev->win, getpid(), appid);
723 } else if ( aul_is_subapp() ) {
724 _capture_and_make_file(ev->win, getpid(), appcore_get_caller_appid());
727 _DBG(" No change state \n");
729 return ECORE_CALLBACK_RENEW;
734 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
736 struct ui_priv *ui = (struct ui_priv *)data;
737 Ecore_X_Event_Client_Message *e = event;
739 if (!ui) return ECORE_CALLBACK_PASS_ON;
740 if (e->format != 32) return ECORE_CALLBACK_PASS_ON;
741 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
742 if ((0 == ui->wm_rot_supported) ||
743 (0 == ui->rot_started) ||
744 (NULL == ui->rot_cb)) {
745 return ECORE_CALLBACK_PASS_ON;
749 switch (e->data.l[1])
751 case 0: rm = APPCORE_RM_PORTRAIT_NORMAL; break;
752 case 90: rm = APPCORE_RM_LANDSCAPE_REVERSE; break;
753 case 180: rm = APPCORE_RM_PORTRAIT_REVERSE; break;
754 case 270: rm = APPCORE_RM_LANDSCAPE_NORMAL; break;
755 default: rm = APPCORE_RM_UNKNOWN; break;
760 if (APPCORE_RM_UNKNOWN != rm) {
761 ui->rot_cb(rm, ui->rot_cb_data);
765 return ECORE_CALLBACK_PASS_ON;
768 static void __add_climsg_cb(struct ui_priv *ui)
772 atom_parent = ecore_x_atom_get("_E_PARENT_BORDER_WINDOW");
779 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
781 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
783 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
784 __visibility_cb, ui);
786 /* Add client message callback for WM_ROTATE */
787 if(!__check_wm_rotation_support())
790 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __cmsg_cb, ui);
791 ui->wm_rot_supported = 1;
792 appcore_set_wm_rotation(&wm_rotate);
796 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
802 if (argc == NULL || argv == NULL) {
803 _ERR("argc/argv is NULL");
809 elm_init(*argc, *argv);
811 hwacc = getenv("HWACC");
813 _DBG("elm_config_preferred_engine_set is not called");
814 } else if(strcmp(hwacc, "USE") == 0) {
815 elm_config_preferred_engine_set("opengl_x11");
816 _DBG("elm_config_preferred_engine_set : opengl_x11");
817 } else if(strcmp(hwacc, "NOT_USE") == 0) {
818 elm_config_preferred_engine_set("software_x11");
819 _DBG("elm_config_preferred_engine_set : software_x11");
821 _DBG("elm_config_preferred_engine_set is not called");
824 tm_tmp = getenv("TASKMANAGE");
826 _DBG("taskmanage is null");
828 } else if(strcmp(tm_tmp, "false") == 0) {
829 _DBG("taskmanage is false");
832 _DBG("taskmanage is true %s", tm_tmp);
836 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
837 _retv_if(r == -1, -1);
839 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
840 if (ui->ops && ui->ops->create) {
841 r = ui->ops->create(ui->ops->data);
843 _ERR("create() return error");
848 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
851 ui->state = AS_CREATED;
858 static void __after_loop(struct ui_priv *ui)
860 appcore_unset_rotation_cb();
863 if (ui->ops && ui->ops->terminate)
864 ui->ops->terminate(ui->ops->data);
867 ecore_event_handler_del(ui->hshow);
869 ecore_event_handler_del(ui->hhide);
871 ecore_event_handler_del(ui->hvchange);
873 __appcore_timer_del(ui);
878 static int __set_data(struct ui_priv *ui, const char *name,
879 struct appcore_ops *ops)
882 _ERR("Mainloop already started");
887 if (name == NULL || name[0] == '\0') {
888 _ERR("Invalid name");
899 ui->name = strdup(name);
900 _retv_if(ui->name == NULL, -1);
904 ui->mfcb = __appcore_efl_memory_flush_cb;
909 ui->wm_rot_supported = 0;
912 ui->rot_cb_data = NULL;
913 ui->rot_mode = APPCORE_RM_UNKNOWN;
918 static void __unset_data(struct ui_priv *ui)
921 free((void *)ui->name);
923 memset(ui, 0, sizeof(struct ui_priv));
927 static int __wm_set_rotation_cb(int (*cb) (enum appcore_rm, void *), void *data)
934 if ((priv.wm_rot_supported) && (0 == priv.rot_started)) {
935 __set_wm_rotation_support(0, 1);
939 priv.rot_cb_data = data;
940 priv.rot_started = 1;
945 static int __wm_unset_rotation_cb(void)
947 if ((priv.wm_rot_supported) && (1 == priv.rot_started)) {
948 __set_wm_rotation_support(0, 0);
952 priv.rot_cb_data = NULL;
953 priv.rot_started = 0;
958 static int __wm_get_rotation_state(enum appcore_rm *curr)
965 *curr = priv.rot_mode;
970 static int __wm_pause_rotation_cb(void)
972 if ((1 == priv.rot_started) && (priv.wm_rot_supported)) {
973 __set_wm_rotation_support(0, 0);
976 priv.rot_started = 0;
981 static int __wm_resume_rotation_cb(void)
983 if ((0 == priv.rot_started) && (priv.wm_rot_supported)) {
984 __set_wm_rotation_support(0, 1);
987 priv.rot_started = 1;
992 static struct ui_wm_rotate wm_rotate = {
993 __wm_set_rotation_cb,
994 __wm_unset_rotation_cb,
995 __wm_get_rotation_state,
996 __wm_pause_rotation_cb,
997 __wm_resume_rotation_cb
1000 static Window _get_parent_window(Window id)
1007 if (!XQueryTree(ecore_x_display_get(), id, &root, &parent, &children, &num)) {
1018 static Window _find_capture_window(Window id, Visual **visual, int *depth, int *width, int *height)
1020 XWindowAttributes attr;
1022 Window orig_id = id;
1031 if (!XGetWindowAttributes(ecore_x_display_get(), id, &attr)) {
1035 parent = _get_parent_window(id);
1037 if (attr.map_state == IsViewable
1038 && attr.override_redirect == True
1039 && attr.class == InputOutput && parent == attr.root) {
1040 *depth = attr.depth;
1041 *width = attr.width;
1042 *height = attr.height;
1043 *visual = attr.visual;
1046 } while (parent != attr.root && parent != 0);
1048 XGetWindowAttributes(ecore_x_display_get(), orig_id, &attr);
1049 *depth = attr.depth;
1050 *width = attr.width;
1051 *height = attr.height;
1052 *visual = attr.visual;
1058 static char *_capture_window(Window id, Visual *visual, int width, int height, int depth, int *size)
1063 char *captured_img = NULL;
1065 /* (depth >> 3) + 1 == 4 byte */
1067 shmget(IPC_PRIVATE, width * height * ((depth >> 3) + 1),
1075 si.readOnly = False;
1076 si.shmaddr = shmat(si.shmid, NULL, 0);
1078 if (si.shmaddr == (char *)-1) {
1080 shmctl(si.shmid, IPC_RMID, 0);
1084 xim = XShmCreateImage(ecore_x_display_get(), visual, depth, ZPixmap, NULL, &si,
1089 shmctl(si.shmid, IPC_RMID, 0);
1094 img_size = xim->bytes_per_line * xim->height;
1095 xim->data = si.shmaddr;
1097 XSync(ecore_x_display_get(), False);
1098 XShmAttach(ecore_x_display_get(), &si);
1099 XShmGetImage(ecore_x_display_get(), id, xim, 0, 0, 0xFFFFFFFF);
1100 XSync(ecore_x_display_get(), False);
1102 captured_img = calloc(1, img_size);
1104 memcpy(captured_img, xim->data, img_size);
1109 XShmDetach(ecore_x_display_get(), &si);
1114 shmctl(si.shmid, IPC_RMID, 0);
1118 return captured_img;
1122 #define _WND_REQUEST_ANGLE_IDX 0
1123 #define _WND_CURR_ANGLE_IDX 1
1124 int _get_angle(Ecore_X_Window win)
1131 int angle[2] = {-1, -1};
1132 unsigned char* prop_data = NULL;
1134 ret = ecore_x_window_prop_property_get(win,
1135 ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
1136 ECORE_X_ATOM_CARDINAL,
1141 if (prop_data) free(prop_data);
1146 memcpy(&angle, prop_data, sizeof (int) *count);
1150 after= angle[_WND_REQUEST_ANGLE_IDX];
1151 before = angle[_WND_CURR_ANGLE_IDX];
1154 if (-1 == after) after = 0;
1159 static void _rotate_img(Evas_Object *image_object, int angle, int cx, int cy)
1163 _ret_if(NULL == image_object);
1165 em = evas_map_new(4);
1166 _ret_if(NULL == em);
1168 evas_map_util_points_populate_from_object(em, image_object);
1169 evas_map_util_rotate(em, (double) angle, cx, cy);
1171 evas_object_map_set(image_object, em);
1172 evas_object_map_enable_set(image_object, EINA_TRUE);
1177 #define EXTENSION_LEN 128
1178 #define CAPTURE_FILE_PATH "/opt/share/app_capture"
1179 bool _make_capture_file(const char *package, int width, int height, char *img, int angle)
1184 Evas_Object *image_object;
1185 int canvas_width, canvas_height;
1189 _retv_if(NULL == package, false);
1191 len = strlen(package) + EXTENSION_LEN;
1192 filename = malloc(len);
1193 _retv_if(NULL == filename, false);
1194 snprintf(filename, len, CAPTURE_FILE_PATH"/%s.jpg", package);
1196 if (90 == angle || 270 == angle) {
1197 canvas_width = height;
1198 canvas_height = width;
1200 canvas_width = width;
1201 canvas_height = height;
1204 e = virtual_canvas_create(canvas_width, canvas_height);
1205 goto_if(NULL == e, error);
1207 image_object = evas_object_image_add(e);
1208 goto_if(NULL == image_object, error);
1210 evas_object_image_size_set(image_object, width, height);
1211 evas_object_image_data_set(image_object, img);
1212 evas_object_image_data_update_add(image_object, 0, 0, width, height);
1213 evas_object_resize(image_object, width, height);
1214 evas_object_image_filled_set(image_object, EINA_TRUE);
1217 cx = canvas_width - width / 2;
1218 cy = canvas_height / 2;
1219 mx = canvas_width - width;
1227 cy = canvas_height / 2;
1232 evas_object_move(image_object, mx, 0);
1233 _rotate_img(image_object, angle, cx, cy);
1234 evas_object_show(image_object);
1236 if (access(CAPTURE_FILE_PATH, F_OK) != 0) {
1237 mkdir(CAPTURE_FILE_PATH, 0777);
1239 goto_if(false == virtual_canvas_flush_to_file(e, filename, canvas_width, canvas_height), error);
1241 evas_object_del(image_object);
1242 virtual_canvas_destroy(e);
1252 virtual_canvas_destroy(e);
1254 if (!image_object) break;
1255 evas_object_del(image_object);
1261 int __resize8888(const char* pDataIn, char* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight)
1269 char* pOutput = pDataOut;
1270 char* pOut = pDataOut;
1271 const char* pIn = NULL;
1272 int *pColLUT = malloc(sizeof(int) * outWidth);
1274 /* Calculate X Scale factor */
1275 scaleX = inWidth * 256 / outWidth;
1276 /* Calculate Y Scale factor, aspect ratio is not maintained */
1277 scaleY = inHeight * 256 / outHeight;
1278 for (j = 0; j < outWidth; j++)
1280 /* Get input index based on column scale factor */
1281 /* To get more optimization, this is calculated once and
1282 * is placed in a LUT and used for indexing
1284 pColLUT [j] = ((j * scaleX) >> 8) * 4;
1287 for (i = 0; i < outHeight; i++)
1289 /* Get input routWidth index based on routWidth scale factor */
1290 iRow = (i * scaleY >> 8) * inWidth * 4;
1291 /* Loop could be unrolled for more optimization */
1292 for (j = 0; j < (outWidth); j++)
1294 /* Get input index based on column scale factor */
1295 iIndex = iRow + pColLUT [j];
1296 pIn = pDataIn + iIndex;
1309 static void _capture_and_make_file(Ecore_X_Window win, int pid, const char *package)
1312 Window redirected_id;
1314 int width, height, depth;
1315 int width_out, height_out;
1321 redirected_id = _find_capture_window(win, &visual, &depth, &width, &height);
1322 _ret_if(redirected_id == (Window) -1 ||
1323 redirected_id == (Window) 0);
1325 SECURE_LOGD("Capture : win[%x] -> redirected win[%x] for %s[%d]", win, redirected_id, package, pid);
1327 img = _capture_window(redirected_id, visual, width, height, depth, &size);
1328 _ret_if(NULL == img);
1330 width_out = width/2;
1331 height_out = height/2;
1333 if ( width_out < 1 || height_out < 1 ) {
1338 __resize8888(img, img, width, height, width_out, height_out);
1340 angle = _get_angle(win);
1341 if (false == _make_capture_file(package, width_out, height_out, img, angle)) {
1342 _ERR("cannot a capture file for the package of [%s]", package);
1349 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1350 struct appcore_ops *ops)
1353 GSList *iter = NULL;
1354 struct win_node *entry = NULL;
1358 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1361 aul_app_get_appid_bypid(pid, appid, APPID_MAX);
1363 r = __set_data(&priv, name, ops);
1364 _retv_if(r == -1, -1);
1366 r = __before_loop(&priv, argc, argv);
1368 __unset_data(&priv);
1374 aul_status_update(STATUS_DYING);
1376 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
1378 if(__check_skip(entry->win) == FALSE)
1384 _capture_and_make_file(entry->win, pid, appid);
1388 __after_loop(&priv);
1390 __unset_data(&priv);
1395 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1397 resource_reclaiming = enable;
1402 EXPORT_API int appcore_set_app_state(int state)