2 * Copyright (c) 2016 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>
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 ),
55 mNeedToApproveDeiconify( false )
57 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
61 WindowRenderSurface::~WindowRenderSurface()
63 if( mEglWindow != NULL )
65 wl_egl_window_destroy(mEglWindow);
71 ecore_wl_window_free( mWlWindow );
75 Ecore_Wl_Window* WindowRenderSurface::GetDrawable()
77 // already an e-core type
81 Any WindowRenderSurface::GetSurface()
83 // already an e-core type
84 return Any( mWlWindow );
87 Ecore_Wl_Window* WindowRenderSurface::GetWlWindow()
92 void WindowRenderSurface::RequestToApproveDeiconify()
94 mNeedToApproveDeiconify = true;
97 void WindowRenderSurface::InitializeEgl( EglInterface& eglIf )
99 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
101 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
103 eglImpl.ChooseConfig(true, mColorDepth);
106 void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf )
108 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
110 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
112 // Temporary code for opaque window. We have to modify it after wayland team finish the work.
113 if( mColorDepth == COLOR_DEPTH_32 )
115 ecore_wl_window_alpha_set( mWlWindow, true );
119 ecore_wl_window_alpha_set( mWlWindow, false );
122 // create the EGL surface
123 ecore_wl_window_surface_create(mWlWindow);
124 mEglWindow = wl_egl_window_create(ecore_wl_window_surface_get(mWlWindow), mPosition.width, mPosition.height);
125 eglImpl.CreateSurfaceWindow( (EGLNativeWindowType)mEglWindow, mColorDepth ); // reinterpret_cast does not compile
128 void WindowRenderSurface::DestroyEglSurface( EglInterface& eglIf )
130 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
132 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
133 eglImpl.DestroySurface();
135 if( mEglWindow != NULL )
137 wl_egl_window_destroy(mEglWindow);
142 bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& egl )
144 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
146 if( mEglWindow != NULL )
148 wl_egl_window_destroy(mEglWindow);
152 // Temporary code for opaque window. We have to modify it after wayland team finish the work.
153 if( mColorDepth == COLOR_DEPTH_32 )
155 ecore_wl_window_alpha_set( mWlWindow, true );
159 ecore_wl_window_alpha_set( mWlWindow, false );
162 mEglWindow = wl_egl_window_create(ecore_wl_window_surface_get(mWlWindow), mPosition.width, mPosition.height);
164 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
165 return eglImpl.ReplaceSurfaceWindow( (EGLNativeWindowType)mEglWindow ); // reinterpret_cast does not compile
168 void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize )
170 bool needToMove = false;
171 bool needToResize = false;
174 if( (fabs(positionSize.x - mPosition.x) > MINIMUM_DIMENSION_CHANGE) ||
175 (fabs(positionSize.y - mPosition.y) > MINIMUM_DIMENSION_CHANGE) )
181 if( (fabs(positionSize.width - mPosition.width) > MINIMUM_DIMENSION_CHANGE) ||
182 (fabs(positionSize.height - mPosition.height) > MINIMUM_DIMENSION_CHANGE) )
189 ecore_wl_window_move(mWlWindow, positionSize.x, positionSize.y);
190 mPosition = positionSize;
194 ecore_wl_window_resize(mWlWindow, positionSize.width, positionSize.height, 0);
195 mPosition = positionSize;
200 void WindowRenderSurface::Map()
202 ecore_wl_window_show(mWlWindow);
205 void WindowRenderSurface::StartRender()
209 bool WindowRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
211 // nothing to do for windows
215 void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface )
217 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
218 eglImpl.SwapBuffers();
220 if( mRenderNotification )
222 mRenderNotification->Trigger();
225 // When the window is deiconified, it approves the deiconify operation to window manager after rendering
226 if(mNeedToApproveDeiconify)
228 // SwapBuffer is desychronized. So make sure to sychronize when window is deiconified.
229 glAbstraction.Finish();
233 mNeedToApproveDeiconify = false;
237 void WindowRenderSurface::StopRender()
241 void WindowRenderSurface::SetViewMode( ViewMode viewMode )
246 void WindowRenderSurface::CreateWlRenderable()
248 // if width or height are zero, go full screen.
249 if ( (mPosition.width == 0) || (mPosition.height == 0) )
251 // Default window size == screen size
255 ecore_wl_screen_size_get( &mPosition.width, &mPosition.height );
258 mWlWindow = ecore_wl_window_new( 0, mPosition.x, mPosition.y, mPosition.width, mPosition.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW );
260 if ( mWlWindow == 0 )
262 DALI_ASSERT_ALWAYS(0 && "Failed to create X window");
266 void WindowRenderSurface::UseExistingRenderable( unsigned int surfaceId )
268 mWlWindow = AnyCast< Ecore_Wl_Window* >( surfaceId );
271 void WindowRenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& /* threadSynchronization */ )
276 void WindowRenderSurface::ReleaseLock()