2 * Copyright (c) 2017 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 <dali/internal/window-system/tizen-wayland/ecore-wl/window-render-surface-ecore-wl.h>
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/wayland/wl-types.h>
27 #include <dali/internal/graphics/gles20/egl-implementation.h>
28 #include <dali/internal/adaptor/common/adaptor-impl.h>
29 #include <dali/integration-api/trigger-event-factory-interface.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 ),
56 mThreadSynchronization( NULL ),
57 mRotationTrigger( NULL ),
59 mScreenRotationAngle( 0 ),
60 mRotationSupported( false ),
61 mRotationFinished( true ),
62 mScreenRotationFinished( true ),
63 mResizeFinished( true )
65 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
69 WindowRenderSurface::~WindowRenderSurface()
71 if( mEglWindow != NULL )
73 DALI_LOG_RELEASE_INFO("Egl window is destroyed by WindowRenderSurface Destructor\n");
74 wl_egl_window_destroy(mEglWindow);
80 ecore_wl_window_free( mWlWindow );
83 if( mRotationTrigger )
85 delete mRotationTrigger;
90 Ecore_Wl_Window* WindowRenderSurface::GetDrawable()
92 // already an e-core type
96 Any WindowRenderSurface::GetSurface()
98 // already an e-core type
99 return Any( mWlWindow );
102 Ecore_Wl_Window* WindowRenderSurface::GetWlWindow()
107 void WindowRenderSurface::RequestRotation( int angle, int width, int height )
109 if( !mRotationSupported )
111 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: Rotation is not supported!\n" );
115 if( !mRotationTrigger )
117 TriggerEventFactoryInterface& triggerFactory = Internal::Adaptor::Adaptor::GetImplementation( Adaptor::Get() ).GetTriggerEventFactoryInterface();
118 mRotationTrigger = triggerFactory.CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessRotationRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
121 mPositionSize.width = width;
122 mPositionSize.height = height;
124 mRotationAngle = angle;
125 mRotationFinished = false;
127 ecore_wl_window_rotation_set( mWlWindow, mRotationAngle );
129 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle );
132 void WindowRenderSurface::OutputTransformed()
136 if( ecore_wl_window_ignore_output_transform_get( mWlWindow ) )
142 transform = ecore_wl_output_transform_get( ecore_wl_window_output_find( mWlWindow ) );
145 mScreenRotationAngle = transform * 90;
146 mScreenRotationFinished = false;
148 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OutputTransformed: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle );
151 void WindowRenderSurface::SetTransparency( bool transparent )
153 ecore_wl_window_alpha_set( mWlWindow, transparent );
156 void WindowRenderSurface::InitializeEgl( EglInterface& eglIf )
158 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
160 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
162 eglImpl.ChooseConfig(true, mColorDepth);
165 void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf )
167 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
169 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
171 // create the EGL window
172 if( mScreenRotationAngle == 0 || mScreenRotationAngle == 180 )
174 mEglWindow = wl_egl_window_create( mWlSurface, mPositionSize.width, mPositionSize.height );
178 mEglWindow = wl_egl_window_create( mWlSurface, mPositionSize.height, mPositionSize.width );
181 EGLNativeWindowType windowType( mEglWindow );
182 eglImpl.CreateSurfaceWindow( windowType, mColorDepth );
185 wl_egl_window_capability capability = static_cast< wl_egl_window_capability >( wl_egl_window_get_capabilities( mEglWindow ) );
186 if( capability == WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED )
188 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::CreateEglSurface: capability = %d\n", capability );
189 mRotationSupported = true;
192 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::CreateEglSurface: w = %d h = %d angle = %d screen rotation = %d\n", mPositionSize.width, mPositionSize.height, mRotationAngle, mScreenRotationAngle );
195 void WindowRenderSurface::DestroyEglSurface( EglInterface& eglIf )
197 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
199 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
200 eglImpl.DestroySurface();
202 if( mEglWindow != NULL )
204 DALI_LOG_RELEASE_INFO("Egl window is destroyed by WindowRenderSurface::DestroyEglSurface()\n");
205 wl_egl_window_destroy(mEglWindow);
210 bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& egl )
212 DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
214 if( mEglWindow != NULL )
216 DALI_LOG_RELEASE_INFO("Egl window is destroyed by WindowRenderSurface::ReplaceEGLSurface()\n");
217 wl_egl_window_destroy(mEglWindow);
221 if( mScreenRotationAngle == 0 || mScreenRotationAngle == 180 )
223 mEglWindow = wl_egl_window_create( mWlSurface, mPositionSize.width, mPositionSize.height );
227 mEglWindow = wl_egl_window_create( mWlSurface, mPositionSize.height, mPositionSize.width );
230 // Set screen rotation
231 mScreenRotationFinished = false;
233 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
234 EGLNativeWindowType windowType( mEglWindow );
235 return eglImpl.ReplaceSurfaceWindow( windowType );
238 void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize )
240 bool needToMove = false;
241 bool needToResize = false;
244 if( (fabs(positionSize.x - mPositionSize.x) > MINIMUM_DIMENSION_CHANGE) ||
245 (fabs(positionSize.y - mPositionSize.y) > MINIMUM_DIMENSION_CHANGE) )
251 if( (fabs(positionSize.width - mPositionSize.width) > MINIMUM_DIMENSION_CHANGE) ||
252 (fabs(positionSize.height - mPositionSize.height) > MINIMUM_DIMENSION_CHANGE) )
259 ecore_wl_window_position_set( mWlWindow, positionSize.x, positionSize.y );
263 ecore_wl_window_update_size( mWlWindow, positionSize.width, positionSize.height );
264 mResizeFinished = false;
267 mPositionSize = positionSize;
269 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::MoveResize: %d, %d, %d, %d\n", mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height );
272 void WindowRenderSurface::Map()
274 ecore_wl_window_show(mWlWindow);
277 void WindowRenderSurface::StartRender()
281 bool WindowRenderSurface::PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, bool resizingSurface )
283 if( resizingSurface )
285 #ifdef OVER_TIZEN_VERSION_4
286 // Window rotate or screen rotate
287 if( !mRotationFinished || !mScreenRotationFinished )
289 wl_egl_window_rotation rotation;
290 wl_output_transform bufferTransform;
291 int totalAngle = (mRotationAngle + mScreenRotationAngle) % 360;
297 rotation = ROTATION_0;
298 bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
303 rotation = ROTATION_270;
304 bufferTransform = WL_OUTPUT_TRANSFORM_90;
309 rotation = ROTATION_180;
310 bufferTransform = WL_OUTPUT_TRANSFORM_180;
315 rotation = ROTATION_90;
316 bufferTransform = WL_OUTPUT_TRANSFORM_270;
321 rotation = ROTATION_0;
322 bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
327 wl_egl_window_set_rotation( mEglWindow, rotation );
329 wl_egl_window_set_buffer_transform( mEglWindow, bufferTransform );
331 // Reset only screen rotation flag
332 mScreenRotationFinished = true;
334 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: Set rotation [%d] [%d]\n", mRotationAngle, mScreenRotationAngle );
337 // Only window rotate
338 if( !mRotationFinished )
340 wl_output_transform windowTransform;
342 switch( mRotationAngle )
346 windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
351 windowTransform = WL_OUTPUT_TRANSFORM_90;
356 windowTransform = WL_OUTPUT_TRANSFORM_180;
361 windowTransform = WL_OUTPUT_TRANSFORM_270;
366 windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
371 wl_egl_window_set_window_transform( mEglWindow, windowTransform );
376 if( !mResizeFinished )
378 wl_egl_window_resize( mEglWindow, mPositionSize.width, mPositionSize.height, mPositionSize.x, mPositionSize.y );
379 mResizeFinished = true;
381 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: Set resize\n" );
388 void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
390 if( resizingSurface )
392 if( !mRotationFinished )
394 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PostRender: Trigger rotation event\n" );
396 mRotationTrigger->Trigger();
398 if( mThreadSynchronization )
400 // Wait until the event-thread complete the rotation event processing
401 mThreadSynchronization->PostRenderWaitForCompletion();
406 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
407 eglImpl.SwapBuffers();
409 if( mRenderNotification )
411 mRenderNotification->Trigger();
415 void WindowRenderSurface::StopRender()
419 void WindowRenderSurface::SetViewMode( ViewMode viewMode )
424 void WindowRenderSurface::CreateWlRenderable()
426 // if width or height are zero, go full screen.
427 if ( (mPositionSize.width == 0) || (mPositionSize.height == 0) )
429 // Default window size == screen size
433 ecore_wl_screen_size_get( &mPositionSize.width, &mPositionSize.height );
436 mWlWindow = ecore_wl_window_new( 0, mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW );
438 if ( mWlWindow == 0 )
440 DALI_ASSERT_ALWAYS(0 && "Failed to create Wayland window");
443 mWlSurface = ecore_wl_window_surface_create( mWlWindow );
445 if( mColorDepth == COLOR_DEPTH_32 )
447 ecore_wl_window_alpha_set( mWlWindow, true );
451 ecore_wl_window_alpha_set( mWlWindow, false );
454 // Get output transform
455 if( !ecore_wl_window_ignore_output_transform_get( mWlWindow ) )
457 Ecore_Wl_Output* output = ecore_wl_window_output_find( mWlWindow );
459 int transform = ecore_wl_output_transform_get( output );
461 mScreenRotationAngle = transform * 90;
462 mScreenRotationFinished = false;
466 void WindowRenderSurface::UseExistingRenderable( unsigned int surfaceId )
468 mWlWindow = AnyCast< Ecore_Wl_Window* >( surfaceId );
471 void WindowRenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
473 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::SetThreadSynchronization: called\n" );
475 mThreadSynchronization = &threadSynchronization;
478 void WindowRenderSurface::ReleaseLock()
483 void WindowRenderSurface::ProcessRotationRequest()
485 mRotationFinished = true;
487 ecore_wl_window_rotation_change_done_send( mWlWindow );
489 DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::ProcessRotationRequest: Rotation Done\n" );
491 if( mThreadSynchronization )
493 mThreadSynchronization->PostRenderComplete();