[dali_2.3.38] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-system-ecore-wl2.cpp
1 /*
2  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // EXTERNAL_HEADERS
19 #include <Ecore_Wl2.h>
20 #include <dali/integration-api/adaptor-framework/adaptor.h>
21 #include <dali/integration-api/adaptor-framework/scene-holder.h>
22 #include <dali/integration-api/debug.h>
23
24 #include <dlog.h>
25
26 // INTERNAL HEADERS
27 #include <dali/devel-api/adaptor-framework/keyboard.h>
28 #include <dali/internal/adaptor/common/framework-factory.h>
29 #include <dali/internal/system/common/time-service.h>
30 #include <dali/internal/window-system/common/window-system.h>
31
32 #define START_DURATION_CHECK()                               \
33   uint32_t durationMilliSeconds = static_cast<uint32_t>(-1); \
34   uint32_t startTime, endTime;                               \
35   startTime = TimeService::GetMilliSeconds();
36
37 #define FINISH_DURATION_CHECK(functionName)                                             \
38   endTime              = TimeService::GetMilliSeconds();                                \
39   durationMilliSeconds = endTime - startTime;                                           \
40   if(durationMilliSeconds > 0)                                                          \
41   {                                                                                     \
42     DALI_LOG_DEBUG_INFO("%s : duration [%u ms]\n", functionName, durationMilliSeconds); \
43   }
44
45 namespace Dali
46 {
47 namespace Internal
48 {
49 namespace Adaptor
50 {
51 namespace WindowSystem
52 {
53 namespace
54 {
55 static int32_t gScreenWidth     = 0;
56 static int32_t gScreenHeight    = 0;
57 static bool    gGeometryHittest = false;
58 } // unnamed namespace
59
60 void Initialize()
61 {
62   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
63   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
64   {
65     print_log(DLOG_INFO, "DALI", "%s: %s(%d) > ecore_wl2_init()", __MODULE__, __func__, __LINE__);
66     ecore_wl2_init();
67   }
68 }
69
70 void Shutdown()
71 {
72   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
73   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
74   {
75     print_log(DLOG_INFO, "DALI", "%s: %s(%d) > ecore_wl2_shutdown()", __MODULE__, __func__, __LINE__);
76     ecore_wl2_shutdown();
77   }
78 }
79
80 void GetScreenSize(int32_t& width, int32_t& height)
81 {
82   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
83   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
84   {
85     if(gScreenWidth == 0 || gScreenHeight == 0)
86     {
87       Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL);
88       if(display)
89       {
90         START_DURATION_CHECK();
91         ecore_wl2_display_screen_size_get(display, &gScreenWidth, &gScreenHeight);
92         FINISH_DURATION_CHECK("ecore_wl2_display_screen_size_get");
93
94         // Since dali adaptor doesn't initialize this time, we should use dlog.
95         print_log(DLOG_INFO, "DALI", "%s: %s(%d) > GetScreenSize() for display(%p) return %d x %d", __MODULE__, __func__, __LINE__, display, gScreenWidth, gScreenHeight);
96
97         DALI_ASSERT_ALWAYS((gScreenWidth > 0) && "screen width is 0");
98         DALI_ASSERT_ALWAYS((gScreenHeight > 0) && "screen height is 0");
99       }
100       else
101       {
102         // Since dali adaptor doesn't initialize this time, we should use dlog.
103         print_log(DLOG_INFO, "DALI", "%s: %s(%d) > GetScreenSize() but display is null", __MODULE__, __func__, __LINE__);
104       }
105     }
106   }
107   width  = gScreenWidth;
108   height = gScreenHeight;
109 }
110
111 void UpdateScreenSize()
112 {
113   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
114   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
115   {
116     Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL);
117     if(display)
118     {
119       START_DURATION_CHECK();
120       ecore_wl2_display_screen_size_get(display, &gScreenWidth, &gScreenHeight);
121       FINISH_DURATION_CHECK("ecore_wl2_display_screen_size_get");
122
123       // Since dali adaptor doesn't initialize this time, we should use dlog.
124       print_log(DLOG_INFO, "DALI", "%s: %s(%d) > UpdateScreenSize() for display(%p) return %d x %d", __MODULE__, __func__, __LINE__, display, gScreenWidth, gScreenHeight);
125     }
126     else
127     {
128       // Since dali adaptor doesn't initialize this time, we should use dlog.
129       print_log(DLOG_INFO, "DALI", "%s: %s(%d) > UpdateScreenSize() but display is null", __MODULE__, __func__, __LINE__);
130     }
131   }
132 }
133
134 bool SetKeyboardRepeatInfo(float rate, float delay)
135 {
136   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
137   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
138   {
139     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
140     return ecore_wl2_input_keyboard_repeat_set(input, static_cast<double>(rate), static_cast<double>(delay));
141   }
142   return false;
143 }
144
145 bool GetKeyboardRepeatInfo(float& rate, float& delay)
146 {
147   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
148   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
149   {
150     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
151     double           rateVal, delayVal;
152     bool             ret = ecore_wl2_input_keyboard_repeat_get(input, &rateVal, &delayVal);
153     rate                 = static_cast<float>(rateVal);
154     delay                = static_cast<float>(delayVal);
155
156     return ret;
157   }
158   return false;
159 }
160
161 bool SetKeyboardHorizontalRepeatInfo(float rate, float delay)
162 {
163 #ifdef OVER_TIZEN_VERSION_8
164   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
165   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
166   {
167     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
168     return ecore_wl2_input_keyboard_horizontal_way_repeat_set(input, static_cast<double>(rate), static_cast<double>(delay));
169   }
170   return false;
171 #else
172   return SetKeyboardRepeatInfo(rate, delay);
173 #endif
174 }
175
176 bool GetKeyboardHorizontalRepeatInfo(float& rate, float& delay)
177 {
178 #ifdef OVER_TIZEN_VERSION_8
179   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
180   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
181   {
182     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
183     double           rateVal, delayVal;
184     bool             ret = ecore_wl2_input_keyboard_horizontal_way_repeat_get(input, &rateVal, &delayVal);
185     rate                 = static_cast<float>(rateVal);
186     delay                = static_cast<float>(delayVal);
187
188     return ret;
189   }
190   return false;
191 #else
192   return GetKeyboardRepeatInfo(rate, delay);
193 #endif
194 }
195
196 bool SetKeyboardVerticalRepeatInfo(float rate, float delay)
197 {
198 #ifdef OVER_TIZEN_VERSION_8
199   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
200   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
201   {
202     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
203     return ecore_wl2_input_keyboard_vertical_way_repeat_set(input, static_cast<double>(rate), static_cast<double>(delay));
204   }
205   return false;
206 #else
207   return SetKeyboardRepeatInfo(rate, delay);
208 #endif
209 }
210
211 bool GetKeyboardVerticalRepeatInfo(float& rate, float& delay)
212 {
213 #ifdef OVER_TIZEN_VERSION_8
214   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
215   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
216   {
217     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
218     double           rateVal, delayVal;
219     bool             ret = ecore_wl2_input_keyboard_vertical_way_repeat_get(input, &rateVal, &delayVal);
220     rate                 = static_cast<float>(rateVal);
221     delay                = static_cast<float>(delayVal);
222
223     return ret;
224   }
225   return false;
226 #else
227   return GetKeyboardRepeatInfo(rate, delay);
228 #endif
229 }
230
231 void SetGeometryHittestEnabled(bool enable)
232 {
233   DALI_LOG_RELEASE_INFO("GeometryHittest : %d \n", enable);
234   if(gGeometryHittest != enable && Dali::Adaptor::IsAvailable())
235   {
236     Dali::SceneHolderList sceneHolders = Dali::Adaptor::Get().GetSceneHolders();
237     for(auto iter = sceneHolders.begin(); iter != sceneHolders.end(); ++iter)
238     {
239       if(*iter)
240       {
241         (*iter).SetGeometryHittestEnabled(enable);
242       }
243     }
244   }
245   gGeometryHittest = enable;
246 }
247
248 bool IsGeometryHittestEnabled()
249 {
250   return gGeometryHittest;
251 }
252
253 } // namespace WindowSystem
254
255 } // namespace Adaptor
256
257 } // namespace Internal
258
259 } // namespace Dali
260
261 #pragma GCC diagnostic pop