Revert "[Tizen] Do not call ProcessCoreEventsFromIdle repeatedly"
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / windows / window-render-surface-ecore-win.cpp
1 /*\r
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  *\r
16  */\r
17 \r
18 // CLASS HEADER\r
19 #include <dali/internal/window-system/windows/window-render-surface-ecore-win.h>\r
20 \r
21 // EXTERNAL INCLUDES\r
22 //#include <X11/Xatom.h>\r
23 //#include <X11/Xlib.h>\r
24 //#include <X11/Xutil.h>\r
25 //\r
26 //#include <X11/extensions/Xfixes.h> // for damage notify\r
27 //#include <X11/extensions/Xdamage.h> // for damage notify\r
28 \r
29 #include <dali/integration-api/gl-abstraction.h>\r
30 #include <dali/integration-api/debug.h>\r
31 \r
32 // INTERNAL INCLUDES\r
33 #include <dali/internal/window-system/windows/ecore-win-types.h>\r
34 #include <dali/internal/system/common/trigger-event.h>\r
35 #include <dali/internal/graphics/gles20/egl-implementation.h>\r
36 #include <dali/internal/window-system/common/display-connection.h>\r
37 \r
38 namespace Dali\r
39 {\r
40 namespace Internal\r
41 {\r
42 namespace Adaptor\r
43 {\r
44 \r
45 namespace\r
46 {\r
47 \r
48 const int MINIMUM_DIMENSION_CHANGE( 1 ); ///< Minimum change for window to be considered to have moved\r
49 \r
50 #if defined(DEBUG_ENABLED)\r
51 Debug::Filter* gWindowRenderSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_WINDOW_RENDER_SURFACE_ECORE_X");\r
52 #endif\r
53 \r
54 } // unnamed namespace\r
55 \r
56 WindowRenderSurfaceEcoreWin::WindowRenderSurfaceEcoreWin( Dali::PositionSize positionSize,\r
57                                           Any surface,\r
58                                           const std::string& name,\r
59                                           const std::string& className,\r
60                                           bool isTransparent)\r
61 : mTitle( name ),\r
62   mClassName( className ),\r
63   mPosition( positionSize ),\r
64   mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),\r
65   mWinWindow( 0 ),\r
66   mOwnSurface( false ),\r
67   mNeedToApproveDeiconify( false )\r
68 {\r
69   DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );\r
70   Initialize( surface );\r
71 }\r
72 \r
73 WindowRenderSurfaceEcoreWin::~WindowRenderSurfaceEcoreWin()\r
74 {\r
75   if( mOwnSurface )\r
76   {\r
77     //ecore_x_window_free( mWinWindow );\r
78   }\r
79 }\r
80 \r
81 void WindowRenderSurfaceEcoreWin::Initialize( Any surface )\r
82 {\r
83   // see if there is a surface in Any surface\r
84   unsigned int surfaceId = GetSurfaceId( surface );\r
85 \r
86   // if the surface is empty, create a new one.\r
87   if( surfaceId == 0 )\r
88   {\r
89     // we own the surface about to created\r
90     mOwnSurface = true;\r
91     CreateRenderable();\r
92   }\r
93   else\r
94   {\r
95     // XLib should already be initialized so no point in calling XInitThreads\r
96     UseExistingRenderable( surfaceId );\r
97   }\r
98 }\r
99 \r
100 Ecore_Win_Window WindowRenderSurfaceEcoreWin::GetWinWindow()\r
101 {\r
102   return mWinWindow;\r
103 }\r
104 \r
105 void WindowRenderSurfaceEcoreWin::RequestToApproveDeiconify()\r
106 {\r
107   mNeedToApproveDeiconify = true;\r
108 }\r
109 \r
110 Any WindowRenderSurfaceEcoreWin::GetWindow()\r
111 {\r
112   return mWinWindow;\r
113 }\r
114 \r
115 void WindowRenderSurfaceEcoreWin::Map()\r
116 {\r
117   //ecore_x_window_show( mWinWindow );\r
118 }\r
119 \r
120 void WindowRenderSurfaceEcoreWin::SetRenderNotification( TriggerEventInterface* renderNotification )\r
121 {\r
122 }\r
123 \r
124 void WindowRenderSurfaceEcoreWin::SetTransparency( bool transparent )\r
125 {\r
126 }\r
127 \r
128 void WindowRenderSurfaceEcoreWin::RequestRotation( int angle, int width, int height )\r
129 {\r
130 }\r
131 \r
132 PositionSize WindowRenderSurfaceEcoreWin::GetPositionSize() const\r
133 {\r
134   return mPosition;\r
135 }\r
136 \r
137 void WindowRenderSurfaceEcoreWin::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )\r
138 {\r
139   // calculate DPI \r
140   float xres, yres;\r
141 \r
142   //// 1 inch = 25.4 millimeters\r
143   Win32WindowSystem::GetDPI( xres, yres );\r
144 \r
145   xres *= 1.5;\r
146   yres *= 1.5;\r
147 \r
148   dpiHorizontal = int( xres + 0.5f );  // rounding\r
149   dpiVertical = int( yres + 0.5f );\r
150 }\r
151 \r
152 void WindowRenderSurfaceEcoreWin::InitializeEgl( EglInterface& eglIf )\r
153 {\r
154   DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );\r
155 \r
156   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );\r
157 \r
158   eglImpl.ChooseConfig(true, mColorDepth);\r
159 }\r
160 \r
161 void WindowRenderSurfaceEcoreWin::CreateEglSurface( EglInterface& eglIf )\r
162 {\r
163   DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );\r
164 \r
165   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );\r
166 \r
167   // create the EGL surface\r
168   // need to create X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit\r
169   XWindow window( mWinWindow );\r
170   eglImpl.CreateSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( window ), mColorDepth );\r
171 }\r
172 \r
173 void WindowRenderSurfaceEcoreWin::DestroyEglSurface( EglInterface& eglIf )\r
174 {\r
175   DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );\r
176 \r
177   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );\r
178   eglImpl.DestroySurface();\r
179 }\r
180 \r
181 bool WindowRenderSurfaceEcoreWin::ReplaceEGLSurface( EglInterface& egl )\r
182 {\r
183   DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );\r
184 \r
185   // need to create X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit\r
186   XWindow window( mWinWindow );\r
187   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );\r
188 \r
189   return eglImpl.ReplaceSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( window ) );\r
190 }\r
191 \r
192 void WindowRenderSurfaceEcoreWin::MoveResize( Dali::PositionSize positionSize )\r
193 {\r
194   SetWindowPos( (HWND)mWinWindow, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height, SWP_NOZORDER | SWP_NOACTIVATE );\r
195 }\r
196 \r
197 void WindowRenderSurfaceEcoreWin::SetViewMode( ViewMode viewMode )\r
198 {\r
199 }\r
200 \r
201 void WindowRenderSurfaceEcoreWin::StartRender()\r
202 {\r
203 }\r
204 \r
205 bool WindowRenderSurfaceEcoreWin::PreRender( EglInterface&, Integration::GlAbstraction&, bool )\r
206 {\r
207   // nothing to do for windows\r
208   return true;\r
209 }\r
210 \r
211 void WindowRenderSurfaceEcoreWin::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, Dali::DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )\r
212 {\r
213   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );\r
214   eglImpl.SwapBuffers();\r
215 \r
216   // When the window is deiconified, it approves the deiconify operation to window manager after rendering\r
217   if( mNeedToApproveDeiconify )\r
218   {\r
219     // SwapBuffer is desychronized. So make sure to sychronize when window is deiconified.\r
220     glAbstraction.Finish();\r
221 \r
222     XDisplay* display = AnyCast<XDisplay *>( displayConnection->GetDisplay() );\r
223 \r
224     mNeedToApproveDeiconify = false;\r
225   }\r
226 }\r
227 \r
228 void WindowRenderSurfaceEcoreWin::StopRender()\r
229 {\r
230 }\r
231 \r
232 void WindowRenderSurfaceEcoreWin::SetThreadSynchronization( ThreadSynchronizationInterface& /* threadSynchronization */ )\r
233 {\r
234   // Nothing to do.\r
235 }\r
236 \r
237 void WindowRenderSurfaceEcoreWin::ReleaseLock()\r
238 {\r
239   // Nothing to do.\r
240 }\r
241 \r
242 RenderSurface::Type WindowRenderSurfaceEcoreWin::GetSurfaceType()\r
243 {\r
244   return WINDOW_RENDER_SURFACE;\r
245 }\r
246 \r
247 void WindowRenderSurfaceEcoreWin::CreateRenderable()\r
248 {\r
249   // if width or height are zero, go full screen.\r
250   if( ( mPosition.width == 0 ) || ( mPosition.height == 0 ) )\r
251   {\r
252     // Default window size == screen size\r
253     mPosition.x = 0;\r
254     mPosition.y = 0;\r
255 \r
256     char *strWidth = std::getenv( "DALI_WINDOW_WIDTH" );\r
257     if( NULL == strWidth )\r
258     {\r
259       mPosition.width = 480;\r
260     }\r
261     else\r
262     {\r
263       mPosition.width = atoi( strWidth );\r
264     }\r
265 \r
266     char *strHeight = std::getenv( "DALI_WINDOW_HEIGHT" );\r
267     if( NULL == strHeight )\r
268     {\r
269       mPosition.height = 800;\r
270     }\r
271     else\r
272     {\r
273       mPosition.height = atoi( strHeight );\r
274     }\r
275   }\r
276 \r
277   long pWnd1 = Win32WindowSystem::CreateWinWindow( mTitle.c_str(), mTitle.c_str(), mPosition.x, mPosition.y, mPosition.width, mPosition.height, NULL );\r
278 \r
279   //ÏÔʾ´°¿Ú\r
280   Win32WindowSystem::ShowWindow( pWnd1 );\r
281 \r
282   mWinWindow = (Ecore_Win_Window)pWnd1;\r
283   if( mWinWindow == 0 )\r
284   {\r
285     DALI_ASSERT_ALWAYS( 0 && "Failed to create X window" );\r
286   }\r
287 }\r
288 \r
289 void WindowRenderSurfaceEcoreWin::UseExistingRenderable( unsigned int surfaceId )\r
290 {\r
291   mWinWindow = static_cast< Ecore_Win_Window >( surfaceId );\r
292 }\r
293 \r
294 unsigned int WindowRenderSurfaceEcoreWin::GetSurfaceId( Any surface ) const\r
295 {\r
296   unsigned int surfaceId = 0;
297
298   if ( surface.Empty() == false )
299   {
300     // check we have a valid type
301     DALI_ASSERT_ALWAYS( ( (surface.GetType() == typeid (XWindow) ) ||
302                           (surface.GetType() == typeid (Ecore_Win_Window) ) )
303                         && "Surface type is invalid" );
304
305     if ( surface.GetType() == typeid (Ecore_Win_Window) )
306     {
307       surfaceId = AnyCast<Ecore_Win_Window>( surface );
308     }
309     else
310     {
311       surfaceId = AnyCast<unsigned int>(surface);
312     }
313   }
314   return surfaceId;\r
315 }\r
316 \r
317 } // namespace Adaptor\r
318 \r
319 } // namespace internal\r
320 \r
321 } // namespace Dali\r