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>
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 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
59 WindowRenderSurface::~WindowRenderSurface()
61 if( mEglWindow != NULL )
63 wl_egl_window_destroy(mEglWindow);
69 ecore_wl_window_free( mWlWindow );
73 Ecore_Wl_Window* WindowRenderSurface::GetDrawable()
75 // already an e-core type
79 Any WindowRenderSurface::GetSurface()
81 // already an e-core type
82 return Any( mWlWindow );
85 Ecore_Wl_Window* WindowRenderSurface::GetWlWindow()
90 void WindowRenderSurface::InitializeEgl( EglInterface& eglIf )
92 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
94 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
96 eglImpl.ChooseConfig(true, mColorDepth);
99 void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf )
101 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
103 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
105 // Temporary code for opaque window. We have to modify it after wayland team finish the work.
106 if( mColorDepth == COLOR_DEPTH_32 )
108 ecore_wl_window_alpha_set( mWlWindow, true );
112 ecore_wl_window_alpha_set( mWlWindow, false );
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 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
126 eglImpl.DestroySurface();
128 if( mEglWindow != NULL )
130 wl_egl_window_destroy(mEglWindow);
135 bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& egl )
137 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
139 if( mEglWindow != NULL )
141 wl_egl_window_destroy(mEglWindow);
145 // Temporary code for opaque window. We have to modify it after wayland team finish the work.
146 if( mColorDepth == COLOR_DEPTH_32 )
148 ecore_wl_window_alpha_set( mWlWindow, true );
152 ecore_wl_window_alpha_set( mWlWindow, false );
155 mEglWindow = wl_egl_window_create(ecore_wl_window_surface_get(mWlWindow), mPosition.width, mPosition.height);
157 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
158 return eglImpl.ReplaceSurfaceWindow( (EGLNativeWindowType)mEglWindow ); // reinterpret_cast does not compile
161 void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize )
163 bool needToMove = false;
164 bool needToResize = false;
167 if( (fabs(positionSize.x - mPosition.x) > MINIMUM_DIMENSION_CHANGE) ||
168 (fabs(positionSize.y - mPosition.y) > MINIMUM_DIMENSION_CHANGE) )
174 if( (fabs(positionSize.width - mPosition.width) > MINIMUM_DIMENSION_CHANGE) ||
175 (fabs(positionSize.height - mPosition.height) > MINIMUM_DIMENSION_CHANGE) )
182 ecore_wl_window_move(mWlWindow, positionSize.x, positionSize.y);
183 mPosition = positionSize;
187 ecore_wl_window_resize(mWlWindow, positionSize.width, positionSize.height, 0);
188 mPosition = positionSize;
193 void WindowRenderSurface::Map()
195 ecore_wl_window_show(mWlWindow);
198 void WindowRenderSurface::StartRender()
202 bool WindowRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
204 // nothing to do for windows
208 void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface )
210 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
211 eglImpl.SwapBuffers();
213 if( mRenderNotification )
215 mRenderNotification->Trigger();
219 void WindowRenderSurface::StopRender()
223 void WindowRenderSurface::SetViewMode( ViewMode viewMode )
228 void WindowRenderSurface::CreateWlRenderable()
230 // if width or height are zero, go full screen.
231 if ( (mPosition.width == 0) || (mPosition.height == 0) )
233 // Default window size == screen size
237 ecore_wl_screen_size_get( &mPosition.width, &mPosition.height );
240 mWlWindow = ecore_wl_window_new( 0, mPosition.x, mPosition.y, mPosition.width, mPosition.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW );
242 if ( mWlWindow == 0 )
244 DALI_ASSERT_ALWAYS(0 && "Failed to create X window");
248 void WindowRenderSurface::UseExistingRenderable( unsigned int surfaceId )
250 mWlWindow = AnyCast< Ecore_Wl_Window* >( surfaceId );
253 void WindowRenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& /* threadSynchronization */ )
258 void WindowRenderSurface::ReleaseLock()