EOM / src /

eom.c

  1. /*
  2. * Samsung API
  3. * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the License);
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/license/
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an AS IS BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17.  
  18.  
  19.  
  20. #include <Ecore.h>
  21. #include <tizen.h>
  22. #include <time.h>
  23.  
  24. #include "log.h"
  25. #include "eom_sample.h"
  26. #include "main.h"
  27.  
  28. extern eom_error_e _eom_mirror_cb(void *data)
  29. {
  30. appdata_s *ad = NULL;
  31. viewdata_s *vd = NULL;
  32.  
  33. retv_if(!data, EOM_ERROR_INVALID_PARAMETER);
  34.  
  35. _D("Pressed mirror button");
  36.  
  37. ad = data;
  38. vd = ad->vd;
  39.  
  40. if (ad->support_external_display == EINA_FALSE)
  41. return EOM_ERROR_NONE;
  42.  
  43. if (ad->mode == EOM_OUTPUT_MODE_PRESENTATION)
  44. {
  45. elm_object_text_set(vd->text3, "<font_size=40><color=#ffffff>Mode : mirror</color></font_size>");
  46. ad->mode = EOM_OUTPUT_MODE_MIRROR;
  47. }
  48.  
  49. if (ad->connected == EINA_FALSE)
  50. {
  51. elm_object_text_set(vd->text2, "<font_size=40><color=#ffffff>Connect HDMI cable.</color></font_size>");
  52. return EOM_ERROR_NONE;
  53. }
  54.  
  55. if (ad->external_win)
  56. {
  57. vd->box_external = NULL;
  58. evas_object_del (ad->external_win);
  59. ad->external_win = NULL;
  60. }
  61.  
  62. return EOM_ERROR_NONE;
  63. }
  64.  
  65. void _set_external_window (void *data)
  66. {
  67. Evas_Object *box, *bg;
  68. appdata_s *ad = NULL;
  69. viewdata_s *vd = NULL;
  70.  
  71. ret_if(!data);
  72.  
  73. ad = (appdata_s*)data;
  74. vd = ad->vd;
  75.  
  76. // elm_win_aux_hint_add(ad->external_win, "wm.policy.win.user.geometry", "1");
  77.  
  78. box = elm_box_add (ad->external_win);
  79. evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  80. elm_win_resize_object_add(ad->external_win, box);
  81. evas_object_show (box);
  82.  
  83. bg = elm_bg_add(ad->external_win);
  84. evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  85. evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
  86. elm_bg_color_set(bg, 0, 0, 0);
  87. evas_object_show(bg);
  88.  
  89. evas_object_show (ad->external_win);
  90.  
  91. vd->box_external = box;
  92. }
  93.  
  94. static eom_error_e _eom_presentation_cb(void *data)
  95. {
  96. appdata_s *ad = NULL;
  97. viewdata_s *vd = NULL;
  98.  
  99. retv_if(!data, EOM_ERROR_INVALID_PARAMETER);
  100.  
  101. _D("Pressed presentation button");
  102.  
  103. ad = data;
  104. vd = ad->vd;
  105.  
  106. if (ad->support_external_display == EINA_FALSE)
  107. return EOM_ERROR_NONE;
  108.  
  109. if (ad->mode == EOM_OUTPUT_MODE_MIRROR)
  110. {
  111. elm_object_text_set(vd->text3, "<font_size=40><color=#ffffff>Mode : presentation</color></font_size>");
  112. ad->mode = EOM_OUTPUT_MODE_PRESENTATION;
  113. }
  114.  
  115. if (ad->connected == EINA_FALSE)
  116. {
  117. elm_object_text_set(vd->text2, "<font_size=40><color=#ffffff>Connect HDMI cable.</color></font_size>");
  118. return EOM_ERROR_NONE;
  119. }
  120.  
  121. if (!ad->external_win)
  122. {
  123. ad->external_win = elm_win_add(NULL, "external", ELM_WIN_BASIC);
  124. retv_if(!ad->external_win, EOM_ERROR_OUT_OF_MEMORY);
  125. if (eom_set_output_window(ad->output_id, ad->external_win) != EOM_ERROR_NONE)
  126. {
  127. vd->box_external = NULL;
  128. evas_object_del (ad->external_win);
  129. ad->external_win = NULL;
  130. _E("create external window fail\n");
  131. }
  132. else
  133. {
  134. _set_external_window(data);
  135. _D("create external window\n");
  136. }
  137. }
  138.  
  139. return EOM_ERROR_NONE;
  140. }
  141.  
  142. extern void eom_button_clicked(void *data, Evas_Object *obj, void *event_info)
  143. {
  144. const char *str = NULL;
  145. appdata_s *ad = NULL;
  146.  
  147. ret_if(!data);
  148. ret_if(!obj);
  149.  
  150. ad = data;
  151. str = elm_object_text_get(obj);
  152.  
  153. eom_error_e result = EOM_ERROR_NONE;
  154.  
  155. if (str && !strcmp(str, "MIRROR")) {
  156. result = _eom_mirror_cb(ad);
  157. retm_if(EOM_ERROR_NONE != result, "Failed to eom mirror: %d", result);
  158. } else {
  159. result = _eom_presentation_cb(ad);
  160. retm_if(EOM_ERROR_NONE != result, "Failed to eom presentation: %d", result);
  161. }
  162. }
  163.  
  164. static void sample_notify_cb_output_add (eom_output_id output_id, void *user_data)
  165. {
  166. appdata_s *ad = NULL;
  167. viewdata_s *vd = NULL;
  168.  
  169. ret_if(!user_data);
  170.  
  171. ad = (appdata_s*)user_data;
  172. vd = ad->vd;
  173.  
  174. if (ad->output_id != output_id)
  175. {
  176. _D("OUTPUT ADDED. SKIP. my output ID is %d\n", ad->output_id);
  177. return;
  178. }
  179. _D("output(%d) connected\n", output_id);
  180. elm_object_text_set(vd->text2, "<font_size=40><color=#ffffff>Connected.</color></font_size>");
  181.  
  182. ad->connected = EINA_TRUE;
  183.  
  184. if (ad->mode == EOM_OUTPUT_MODE_PRESENTATION)
  185. {
  186. if (!ad->external_win)
  187. {
  188. ad->external_win = elm_win_add(NULL, "external", ELM_WIN_BASIC);
  189. ret_if(!ad->external_win);
  190. if (eom_set_output_window(ad->output_id, ad->external_win) != EOM_ERROR_NONE)
  191. {
  192. vd->box_external = NULL;
  193. evas_object_del (ad->external_win);
  194. ad->external_win = NULL;
  195. _E("create external window fail\n");
  196. }
  197. else
  198. {
  199. _set_external_window(user_data);
  200. _D("create external window\n");
  201. }
  202. }
  203. }
  204. }
  205.  
  206.  
  207. static void sample_notify_cb_output_remove (eom_output_id output_id, void *user_data)
  208. {
  209. appdata_s *ad = NULL;
  210. viewdata_s *vd = NULL;
  211.  
  212. ret_if(!user_data);
  213.  
  214. ad = (appdata_s*)user_data;
  215. vd = ad->vd;
  216.  
  217. if (ad->output_id != output_id)
  218. {
  219. _D("OUTPUT REMOVED. SKIP. my output ID is %d\n", ad->output_id);
  220. return;
  221. }
  222. _D("output(%d) disconnected\n", output_id);
  223. elm_object_text_set(vd->text2, "<font_size=40><color=#ffffff>Disconnected.</color></font_size>");
  224.  
  225. ad->connected = EINA_FALSE;
  226.  
  227. if (ad->external_win)
  228. {
  229. vd->box_external = NULL;
  230. evas_object_del (ad->external_win);
  231. ad->external_win = NULL;
  232. _D("destory external window\n");
  233. }
  234. }
  235.  
  236. static void sample_notify_cb_mode_changed (eom_output_id output_id, void *user_data)
  237. {
  238. appdata_s *ad = NULL;
  239. eom_output_mode_e mode = EOM_OUTPUT_MODE_NONE;
  240.  
  241. ret_if(!user_data);
  242.  
  243. ad = (appdata_s*)user_data;
  244.  
  245. if (ad->output_id != output_id)
  246. {
  247. _D("MODE CHANGED. SKIP. my output ID is %d\n", ad->output_id);
  248. return;
  249. }
  250.  
  251. eom_get_output_mode(output_id, &mode);
  252. _D("output(%d) mode changed(%d)\n", output_id, mode);
  253. }
  254.  
  255. void _show_image (void *user_data)
  256. {
  257. Evas_Object *box, *image;
  258. appdata_s *ad = NULL;
  259. viewdata_s *vd = NULL;
  260.  
  261. ret_if(!user_data);
  262.  
  263. ad = (appdata_s*)user_data;
  264. vd = ad->vd;
  265.  
  266. if (!vd->box_external)
  267. {
  268. _E("no vd->box_external.\n");
  269. return;
  270. }
  271.  
  272. box = vd->box_external;
  273.  
  274. image = elm_image_add(ad->external_win);
  275. elm_image_file_set(image, BG_DIR, NULL);
  276. evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  277. evas_object_size_hint_align_set(image, EVAS_HINT_FILL, EVAS_HINT_FILL);
  278. elm_box_pack_end(box, image);
  279. evas_object_show(image);
  280.  
  281. evas_object_data_set(ad->external_win, "image_external", image);
  282.  
  283. evas_object_show(ad->external_win);
  284. }
  285.  
  286. static void sample_notify_cb_attribute_changed (eom_output_id output_id, void *user_data)
  287. {
  288. appdata_s *ad = NULL;
  289. viewdata_s *vd = NULL;
  290. eom_output_attribute_e attribute = EOM_OUTPUT_ATTRIBUTE_NONE;
  291. eom_output_attribute_state_e state = EOM_OUTPUT_ATTRIBUTE_STATE_NONE;
  292.  
  293. ret_if(!user_data);
  294.  
  295. ad = (appdata_s*)user_data;
  296. vd = ad->vd;
  297.  
  298. if (ad->output_id != output_id)
  299. {
  300. _D("ATTR CHANGED. SKIP. my output ID is %d\n", ad->output_id);
  301. return;
  302. }
  303.  
  304. eom_get_output_attribute(output_id, &attribute);
  305. eom_get_output_attribute_state(output_id, &state);
  306.  
  307. _D("output(%d) attribute changed(%d, %d)\n", output_id, attribute, state);
  308. if (state == EOM_OUTPUT_ATTRIBUTE_STATE_ACTIVE)
  309. {
  310. _D("active : show image\n");
  311. _show_image(user_data);
  312. }
  313. else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_INACTIVE)
  314. {
  315. _D("inactive : stop putimage & destroy external window\n");
  316.  
  317. if (ad->external_win)
  318. {
  319. vd->box_external = NULL;
  320. evas_object_del(ad->external_win);
  321. ad->external_win = NULL;
  322. }
  323. }
  324. else if (state == EOM_OUTPUT_ATTRIBUTE_STATE_LOST)
  325. {
  326. _D("lost : stop putimage & destroy external window & remove callbacks\n");
  327. if (ad->external_win)
  328. {
  329. vd->box_external = NULL;
  330. evas_object_del(ad->external_win);
  331. ad->external_win = NULL;
  332. }
  333.  
  334. eom_set_unset_cb(ad, EINA_FALSE);
  335. }
  336. }
  337.  
  338. extern void eom_set_unset_cb(void *data, Eina_Bool set)
  339. {
  340. appdata_s *ad = NULL;
  341.  
  342. ret_if(!data);
  343.  
  344. ad = data;
  345.  
  346. if (set == EINA_TRUE)
  347. {
  348. eom_set_output_added_cb(sample_notify_cb_output_add, ad);
  349. eom_set_output_removed_cb(sample_notify_cb_output_remove, ad);
  350. eom_set_mode_changed_cb(sample_notify_cb_mode_changed, ad);
  351. eom_set_attribute_changed_cb(sample_notify_cb_attribute_changed, ad);
  352. }
  353. else
  354. {
  355. eom_unset_output_added_cb(sample_notify_cb_output_add);
  356. eom_unset_output_removed_cb(sample_notify_cb_output_remove);
  357. eom_unset_mode_changed_cb(sample_notify_cb_mode_changed);
  358. eom_unset_attribute_changed_cb(sample_notify_cb_attribute_changed);
  359. }
  360.  
  361. }
  362.  
  363. /* End of file */