[M85 Migration][Rendering] Force gpu acceleration
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / public / ewk_main.cc
1 /*
2  * Copyright (C) 2009-2010 ProFUSION embedded systems
3  * Copyright (C) 2009-2016 Samsung Electronics. All rights reserved.
4  * Copyright (C) 2012 Intel Corporation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20
21 #include "ewk_main_internal.h"
22
23 #include <Ecore.h>
24 #include <Ecore_Evas.h>
25 #include <Ecore_IMF.h>
26 #include <Edje.h>
27 #include <Eina.h>
28 #include <Evas.h>
29
30 #include "command_line_efl.h"
31 #include "eweb_context.h"
32 #include "ewk_global_data.h"
33 #include "ewk_log_internal.h"
34 #include "ewk_view.h"
35 #include "private/webview_delegate_ewk.h"
36 #include "private/ewk_context_private.h"
37 #include "private/ewk_private.h"
38 #include "private/ewk_main_private.h"
39
40 #include "ecore_x_wayland_wrapper.h"
41
42 static int _ewkInitCount = 0;
43
44 /////////////////////////////////////////////////////////////////////////////
45 //private function declaration here
46 static void _ewk_init_web_engine(void);
47 static void _ewk_shutdown_web_engine(void);
48 static void _ewk_force_acceleration() __attribute__((constructor));
49
50 extern std::string g_homeDirectory;
51
52 /**
53  * \var     _ewk_log_dom
54  * @brief   the log domain identifier that is used with EINA's macros
55  */
56 int _ewk_log_dom = -1;
57 #if defined(USE_WAYLAND) && TIZEN_VERSION_AT_LEAST(5, 0, 0)
58 Ecore_Wl2_Display* _ecore_wl2_display = NULL;
59 #endif
60
61 int ewk_init(void)
62 {
63   if (_ewkInitCount)
64     return ++_ewkInitCount;
65
66   if (!eina_init()) {
67     ERR("could not init eina.");
68     goto error_eina;
69   }
70
71   _ewk_log_dom = eina_log_domain_register("ewebview-blink", EINA_COLOR_ORANGE);
72   if (_ewk_log_dom < 0) {
73     EINA_LOG_ERR("could not register log domain 'ewebview-blink'");
74     goto error_log_domain;
75   }
76
77   if (!evas_init()) {
78     ERR("could not init evas.");
79     goto error_evas;
80   }
81
82   if (!ecore_init()) {
83     ERR("could not init ecore.");
84     goto error_ecore;
85   }
86
87   if (!ecore_evas_init()) {
88     ERR("could not init ecore_evas.");
89     goto error_ecore_evas;
90   }
91
92   if (!ecore_imf_init()) {
93     ERR("could not init ecore_imf.");
94     goto error_ecore_imf;
95   }
96
97 #if defined(USE_WAYLAND)
98 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
99   if (!ecore_wl2_init()) {
100 #else
101   if (!ecore_wl_init(0)) {
102 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
103     ERR("could not init ecore_wl.");
104     goto error_ecore_wl;
105   }
106 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
107   if (!_ecore_wl2_display)
108     _ecore_wl2_display = ecore_wl2_display_connect(NULL);
109 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
110 #else
111   if (!ecore_x_init(0)) {
112     ERR("could not init ecore_x.");
113     goto error_ecore_x;
114   }
115 #endif
116
117   if (!edje_init()) {
118     ERR("Could not init edje.");
119     goto error_edje;
120   }
121
122   _ewk_init_web_engine();
123   return ++_ewkInitCount;
124
125 error_edje:
126 #if defined(USE_WAYLAND)
127 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
128   if (_ecore_wl2_display) {
129     ecore_wl2_display_disconnect(_ecore_wl2_display);
130     _ecore_wl2_display = NULL;
131     ecore_wl2_shutdown();
132   }
133 #else
134   ecore_wl_shutdown();
135 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
136 error_ecore_wl:
137 #else
138   ecore_x_shutdown();
139 error_ecore_x:
140 #endif
141   ecore_imf_shutdown();
142 error_ecore_imf:
143   ecore_evas_shutdown();
144 error_ecore_evas:
145   ecore_shutdown();
146 error_ecore:
147   evas_shutdown();
148 error_evas:
149   eina_log_domain_unregister(_ewk_log_dom);
150   _ewk_log_dom = -1;
151 error_log_domain:
152   eina_shutdown();
153 error_eina:
154   return 0;
155 }
156
157 int ewk_shutdown(void)
158 {
159   if (!_ewkInitCount || --_ewkInitCount)
160       return _ewkInitCount;
161
162   _ewk_shutdown_web_engine();
163
164   edje_shutdown();
165 #if defined(USE_WAYLAND)
166 #if TIZEN_VERSION_AT_LEAST(5, 0, 0)
167   if (_ecore_wl2_display) {
168     ecore_wl2_display_disconnect(_ecore_wl2_display);
169     _ecore_wl2_display = NULL;
170     ecore_wl2_shutdown();
171   }
172 #else
173   ecore_wl_shutdown();
174 #endif  // TIZEN_VERSION_AT_LEAST(5, 0, 0)
175 #else
176   ecore_x_shutdown();
177 #endif
178   ecore_imf_shutdown();
179   ecore_evas_shutdown();
180   ecore_shutdown();
181   evas_shutdown();
182   eina_log_domain_unregister(_ewk_log_dom);
183   _ewk_log_dom = -1;
184   eina_shutdown();
185
186   return 0;
187 }
188
189 void ewk_set_arguments(int argc, char** argv)
190 {
191     CommandLineEfl::Init(argc, argv);
192 }
193
194 void ewk_process_model_set(Ewk_Process_Model process_model)
195 {
196   LOG_EWK_API_MOCKUP();
197 }
198
199 void ewk_memory_optimization_mode_enable(void)
200 {
201   LOG_EWK_API_MOCKUP();
202 }
203
204 void ewk_home_directory_set(const char* path)
205 {
206   if (!path)
207     g_homeDirectory.clear();
208   else
209     g_homeDirectory = path;
210 }
211
212 /////////////////////////////////////////////////////////////////////////////////////////////
213 //Private functions implementations for ewk_main module
214
215 //Initialize web engine
216 void _ewk_init_web_engine()
217 {
218 }
219
220 void _ewk_shutdown_web_engine(void)
221 {
222   //TODO: any web engine destroy to be done here
223   CommandLineEfl::Shutdown();
224   Ewk_Context::DefaultContextRelease();
225   EwkGlobalData::Delete();
226 }
227
228 void _ewk_force_acceleration()
229 {
230   // Chromium-efl port does not support s/w mode. So we need to set h/w mode
231   // before creating elm_window. To do this, make constructor function which is
232   // called at library loading time and set "ELM_ACCEL=hw" here. If not, native
233   // app which does not call elm_config_accel_preference_set() function will
234   // fail to execute.
235   setenv("ELM_ACCEL", "hw", 1);
236 }
237