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>
38 #if defined(DEBUG_ENABLED)
39 extern Debug::Filter* gRenderSurfaceLogFilter;
48 const int MINIMUM_DIMENSION_CHANGE( 1 ); ///< Minimum change for window to be considered to have moved
50 } // unnamed namespace
52 WindowRenderSurface::WindowRenderSurface( Dali::PositionSize positionSize,
55 const std::string& name,
57 : RenderSurface( Dali::RenderSurface::WINDOW, positionSize, surface, display, name, isTransparent ),
58 mNeedToApproveDeiconify(false)
60 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
64 WindowRenderSurface::~WindowRenderSurface()
68 ecore_wl_window_free( mWlWindow );
72 Ecore_Wl_Window* WindowRenderSurface::GetDrawable()
74 // already an e-core type
78 Dali::RenderSurface::SurfaceType WindowRenderSurface::GetType()
80 return Dali::RenderSurface::WINDOW;
83 Any WindowRenderSurface::GetSurface()
85 // already an e-core type
86 return Any( mWlWindow );
89 Ecore_Wl_Window* WindowRenderSurface::GetWlWindow()
94 void WindowRenderSurface::RequestToApproveDeiconify()
96 mNeedToApproveDeiconify = true;
99 void WindowRenderSurface::InitializeEgl( EglInterface& eglIf )
101 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
103 EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
104 eglImpl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
106 eglImpl.ChooseConfig(true, mColorDepth);
109 void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf )
111 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
113 EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
115 // create the EGL surface
116 ecore_wl_window_surface_create(mWlWindow);
117 mEglWindow = wl_egl_window_create(ecore_wl_window_surface_get(mWlWindow), mPosition.width, mPosition.height);
118 eglImpl.CreateSurfaceWindow( (EGLNativeWindowType)mEglWindow, mColorDepth ); // reinterpret_cast does not compile
121 void WindowRenderSurface::DestroyEglSurface( EglInterface& eglIf )
123 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
125 EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
126 eglImpl.DestroySurface();
127 wl_egl_window_destroy(mEglWindow);
131 bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& eglIf )
133 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
135 EglImplementation& egl = static_cast<EglImplementation&>( eglIf );
136 egl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
138 wl_egl_window_destroy(mEglWindow);
139 mEglWindow = wl_egl_window_create(ecore_wl_window_surface_get(mWlWindow), mPosition.width, mPosition.height);
140 return egl.ReplaceSurfaceWindow( (EGLNativeWindowType)mEglWindow, // reinterpret_cast does not compile
141 reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
144 void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize )
146 bool needToMove = false;
147 bool needToResize = false;
150 if( (fabs(positionSize.x - mPosition.x) > MINIMUM_DIMENSION_CHANGE) ||
151 (fabs(positionSize.y - mPosition.y) > MINIMUM_DIMENSION_CHANGE) )
157 if( (fabs(positionSize.width - mPosition.width) > MINIMUM_DIMENSION_CHANGE) ||
158 (fabs(positionSize.height - mPosition.height) > MINIMUM_DIMENSION_CHANGE) )
165 ecore_wl_window_move(mWlWindow, positionSize.x, positionSize.y);
166 mPosition = positionSize;
170 ecore_wl_window_resize(mWlWindow, positionSize.width, positionSize.height, 0);
171 mPosition = positionSize;
176 void WindowRenderSurface::Map()
178 ecore_wl_window_show(mWlWindow);
181 void WindowRenderSurface::StartRender()
185 bool WindowRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
187 // nothing to do for windows
191 void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, unsigned int, bool )
193 EglImplementation& eglImpl = static_cast<EglImplementation&>( egl );
194 eglImpl.SwapBuffers();
196 // When the window is deiconified, it approves the deiconify operation to window manager after rendering
197 if(mNeedToApproveDeiconify)
199 // SwapBuffer is desychronized. So make sure to sychronize when window is deiconified.
200 glAbstraction.Finish();
202 mNeedToApproveDeiconify = false;
206 void WindowRenderSurface::StopRender()
210 void WindowRenderSurface::SetViewMode( ViewMode viewMode )
214 void WindowRenderSurface::CreateWlRenderable()
216 // if width or height are zero, go full screen.
217 if ( (mPosition.width == 0) || (mPosition.height == 0) )
219 // Default window size == screen size
223 ecore_wl_screen_size_get( &mPosition.width, &mPosition.height );
226 mWlWindow = ecore_wl_window_new( 0, mPosition.x, mPosition.y, mPosition.width, mPosition.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW );
228 if ( mWlWindow == 0 )
230 DALI_ASSERT_ALWAYS(0 && "Failed to create X window");
234 void WindowRenderSurface::UseExistingRenderable( unsigned int surfaceId )
236 mWlWindow = AnyCast< Ecore_Wl_Window* >( surfaceId );
239 void WindowRenderSurface::ReleaseLock()
246 } // namespace Adaptor
248 } // namespace Internal