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 <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/debug.h>
26 #include <ecore-wl-types.h>
27 #include <trigger-event.h>
28 #include <gl/egl-implementation.h>
29 #include <base/display-connection.h>
34 #if defined(DEBUG_ENABLED)
35 extern Debug::Filter* gRenderSurfaceLogFilter;
44 const int MINIMUM_DIMENSION_CHANGE( 1 ); ///< Minimum change for window to be considered to have moved
46 } // unnamed namespace
48 WindowRenderSurface::WindowRenderSurface( Dali::PositionSize positionSize,
50 const std::string& name,
52 : EcoreWlRenderSurface( positionSize, surface, name, isTransparent ),
53 mNeedToApproveDeiconify(false)
55 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
59 WindowRenderSurface::~WindowRenderSurface()
63 ecore_wl_window_free( mWlWindow );
67 Ecore_Wl_Window* WindowRenderSurface::GetDrawable()
69 // already an e-core type
73 Any WindowRenderSurface::GetSurface()
75 // already an e-core type
76 return Any( mWlWindow );
79 Ecore_Wl_Window* WindowRenderSurface::GetWlWindow()
84 void WindowRenderSurface::RequestToApproveDeiconify()
86 mNeedToApproveDeiconify = true;
89 void WindowRenderSurface::InitializeEgl( EglInterface& eglIf )
91 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
93 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
95 eglImpl.ChooseConfig(true, mColorDepth);
98 void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf )
100 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
102 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
104 // create the EGL surface
105 ecore_wl_window_surface_create(mWlWindow);
106 mEglWindow = wl_egl_window_create(ecore_wl_window_surface_get(mWlWindow), mPosition.width, mPosition.height);
107 eglImpl.CreateSurfaceWindow( (EGLNativeWindowType)mEglWindow, mColorDepth ); // reinterpret_cast does not compile
110 void WindowRenderSurface::DestroyEglSurface( EglInterface& eglIf )
112 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
114 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
115 eglImpl.DestroySurface();
116 wl_egl_window_destroy(mEglWindow);
120 bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& egl )
122 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
124 wl_egl_window_destroy(mEglWindow);
125 mEglWindow = wl_egl_window_create(ecore_wl_window_surface_get(mWlWindow), mPosition.width, mPosition.height);
127 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
128 return eglImpl.ReplaceSurfaceWindow( (EGLNativeWindowType)mEglWindow ); // reinterpret_cast does not compile
131 void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize )
133 bool needToMove = false;
134 bool needToResize = false;
137 if( (fabs(positionSize.x - mPosition.x) > MINIMUM_DIMENSION_CHANGE) ||
138 (fabs(positionSize.y - mPosition.y) > MINIMUM_DIMENSION_CHANGE) )
144 if( (fabs(positionSize.width - mPosition.width) > MINIMUM_DIMENSION_CHANGE) ||
145 (fabs(positionSize.height - mPosition.height) > MINIMUM_DIMENSION_CHANGE) )
152 ecore_wl_window_move(mWlWindow, positionSize.x, positionSize.y);
153 mPosition = positionSize;
157 ecore_wl_window_resize(mWlWindow, positionSize.width, positionSize.height, 0);
158 mPosition = positionSize;
163 void WindowRenderSurface::Map()
165 ecore_wl_window_show(mWlWindow);
168 void WindowRenderSurface::StartRender()
172 bool WindowRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
174 // nothing to do for windows
178 void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, unsigned int deltaTime, bool replacingSurface )
180 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
181 eglImpl.SwapBuffers();
183 // When the window is deiconified, it approves the deiconify operation to window manager after rendering
184 if(mNeedToApproveDeiconify)
186 // SwapBuffer is desychronized. So make sure to sychronize when window is deiconified.
187 glAbstraction.Finish();
191 mNeedToApproveDeiconify = false;
195 void WindowRenderSurface::StopRender()
199 void WindowRenderSurface::SetViewMode( ViewMode viewMode )
204 void WindowRenderSurface::CreateWlRenderable()
206 // if width or height are zero, go full screen.
207 if ( (mPosition.width == 0) || (mPosition.height == 0) )
209 // Default window size == screen size
213 ecore_wl_screen_size_get( &mPosition.width, &mPosition.height );
216 mWlWindow = ecore_wl_window_new( 0, mPosition.x, mPosition.y, mPosition.width, mPosition.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW );
218 if ( mWlWindow == 0 )
220 DALI_ASSERT_ALWAYS(0 && "Failed to create X window");
226 void WindowRenderSurface::UseExistingRenderable( unsigned int surfaceId )
228 mWlWindow = AnyCast< Ecore_Wl_Window* >( surfaceId );
231 void WindowRenderSurface::ReleaseLock()