2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "window-render-surface.h"
22 #include <X11/Xatom.h>
24 #include <X11/Xutil.h>
26 #include <X11/extensions/Xfixes.h> // for damage notify
27 #include <X11/extensions/Xdamage.h> // for damage notify
29 #include <dali/integration-api/gl-abstraction.h>
30 #include <dali/integration-api/debug.h>
33 #include <ecore-x-types.h>
34 #include <trigger-event.h>
45 #if defined(DEBUG_ENABLED)
46 extern Debug::Filter* gRenderSurfaceLogFilter;
55 const int MINIMUM_DIMENSION_CHANGE( 1 ); ///< Minimum change for window to be considered to have moved
57 } // unnamed namespace
59 WindowRenderSurface::WindowRenderSurface( Dali::PositionSize positionSize,
62 const std::string& name,
64 : RenderSurface( Dali::RenderSurface::WINDOW, positionSize, surface, display, name, isTransparent ),
65 mNeedToApproveDeiconify(false)
67 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
71 WindowRenderSurface::~WindowRenderSurface()
75 ecore_x_window_free( mX11Window );
79 Ecore_X_Drawable WindowRenderSurface::GetDrawable()
81 // already an e-core type
82 return (Ecore_X_Drawable)mX11Window;
85 Dali::RenderSurface::SurfaceType WindowRenderSurface::GetType()
87 return Dali::RenderSurface::WINDOW;
90 Any WindowRenderSurface::GetSurface()
92 // already an e-core type
93 return Any( mX11Window );
96 Ecore_X_Window WindowRenderSurface::GetXWindow()
101 void WindowRenderSurface::RequestToApproveDeiconify()
103 mNeedToApproveDeiconify = true;
106 void WindowRenderSurface::InitializeEgl( EglInterface& eglIf )
108 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
110 EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
111 eglImpl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
113 eglImpl.ChooseConfig(true, mColorDepth);
116 void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf )
118 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
120 EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
122 // create the EGL surface
123 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
124 XWindow window = static_cast< XWindow>( mX11Window );
125 eglImpl.CreateSurfaceWindow( (EGLNativeWindowType)window, mColorDepth ); // reinterpret_cast does not compile
128 void WindowRenderSurface::DestroyEglSurface( EglInterface& eglIf )
130 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
132 EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
133 eglImpl.DestroySurface();
136 bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& eglIf )
138 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
140 EglImplementation& egl = static_cast<EglImplementation&>( eglIf );
141 egl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
143 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
144 XWindow window = static_cast< XWindow >( mX11Window );
145 return egl.ReplaceSurfaceWindow( (EGLNativeWindowType)window, // reinterpret_cast does not compile
146 reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
149 void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize )
151 bool needToMove = false;
152 bool needToResize = false;
155 if( (fabs(positionSize.x - mPosition.x) > MINIMUM_DIMENSION_CHANGE) ||
156 (fabs(positionSize.y - mPosition.y) > MINIMUM_DIMENSION_CHANGE) )
162 if( (fabs(positionSize.width - mPosition.width) > MINIMUM_DIMENSION_CHANGE) ||
163 (fabs(positionSize.height - mPosition.height) > MINIMUM_DIMENSION_CHANGE) )
168 if( needToMove && needToResize)
170 ecore_x_window_move_resize(mX11Window, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
171 mPosition = positionSize;
175 ecore_x_window_move(mX11Window, positionSize.x, positionSize.y);
176 mPosition = positionSize;
178 else if (needToResize)
180 ecore_x_window_resize(mX11Window, positionSize.width, positionSize.height);
181 mPosition = positionSize;
186 void WindowRenderSurface::Map()
188 ecore_x_window_show(mX11Window);
191 void WindowRenderSurface::StartRender()
195 bool WindowRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
197 // nothing to do for windows
201 void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, unsigned int, bool )
203 EglImplementation& eglImpl = static_cast<EglImplementation&>( egl );
204 eglImpl.SwapBuffers();
206 // When the window is deiconified, it approves the deiconify operation to window manager after rendering
207 if(mNeedToApproveDeiconify)
209 // SwapBuffer is desychronized. So make sure to sychronize when window is deiconified.
210 glAbstraction.Finish();
212 #ifndef DALI_PROFILE_UBUNTU
213 /* client sends immediately reply message using value 1 */
214 ecore_x_client_message32_send(mX11Window,
215 ECORE_X_ATOM_E_DEICONIFY_APPROVE,
216 ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
219 #endif // DALI_PROFILE_UBUNTU
223 mNeedToApproveDeiconify = false;
227 void WindowRenderSurface::StopRender()
231 void WindowRenderSurface::SetViewMode( ViewMode viewMode )
233 Ecore_X_Atom viewModeAtom( ecore_x_atom_get( "_E_COMP_3D_APP_WIN" ) );
235 if( viewModeAtom != None )
237 unsigned int value( static_cast<unsigned int>( viewMode ) );
238 ecore_x_window_prop_card32_set( mX11Window, viewModeAtom, &value, 1 );
242 void WindowRenderSurface::CreateXRenderable()
244 // if width or height are zero, go full screen.
245 if ( (mPosition.width == 0) || (mPosition.height == 0) )
247 // Default window size == screen size
251 ecore_x_screen_size_get( ecore_x_default_screen_get(), &mPosition.width, &mPosition.height );
254 if(mColorDepth == COLOR_DEPTH_32)
256 // create 32 bit window
257 mX11Window = ecore_x_window_argb_new( 0, mPosition.x, mPosition.y, mPosition.width, mPosition.height );
261 // create 24 bit window
262 mX11Window = ecore_x_window_new( 0, mPosition.x, mPosition.y, mPosition.width, mPosition.height );
265 if ( mX11Window == 0 )
267 DALI_ASSERT_ALWAYS(0 && "Failed to create X window");
270 // set up window title which will be helpful for debug utitilty
271 ecore_x_icccm_title_set( mX11Window, mTitle.c_str() );
272 ecore_x_netwm_name_set( mX11Window, mTitle.c_str() );
274 // set up etc properties to match with ecore-evas
276 if( ( id = getenv("DESKTOP_STARTUP_ID") ) )
278 ecore_x_netwm_startup_id_set( mX11Window, id );
281 ecore_x_icccm_hints_set( mX11Window,
283 ECORE_X_WINDOW_STATE_HINT_NORMAL, // initial_state
290 // we SHOULD guarantee the x11 window was created in x server.
294 void WindowRenderSurface::UseExistingRenderable( unsigned int surfaceId )
296 mX11Window = static_cast< Ecore_X_Window >( surfaceId );
299 void WindowRenderSurface::ReleaseLock()
306 } // namespace Adaptor
308 } // namespace Internal