/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <dali/integration-api/wayland/wl-types.h>
#include <dali/internal/graphics/gles20/egl-implementation.h>
#include <dali/internal/adaptor/common/adaptor-impl.h>
#include <dali/integration-api/trigger-event-factory-interface.h>
namespace Dali
{
-
-#if defined(DEBUG_ENABLED)
-extern Debug::Filter* gRenderSurfaceLogFilter;
-#endif
-
-namespace ECore
+namespace Internal
+{
+namespace Adaptor
{
namespace
const int MINIMUM_DIMENSION_CHANGE( 1 ); ///< Minimum change for window to be considered to have moved
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gWindowRenderSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_WINDOW_RENDER_SURFACE_ECORE_WL2");
+#endif
+
} // unnamed namespace
-WindowRenderSurface::WindowRenderSurface( Dali::PositionSize positionSize,
- Any surface,
- const std::string& name,
- bool isTransparent)
-: EcoreWlRenderSurface( positionSize, surface, name, isTransparent ),
+WindowRenderSurfaceEcoreWl2::WindowRenderSurfaceEcoreWl2( Dali::PositionSize positionSize,
+ Any surface,
+ const std::string& name,
+ bool isTransparent)
+: mTitle( name ),
+ mPositionSize( positionSize ),
mWlWindow( NULL ),
- mEcore_Wl2_display( NULL ),
mWlSurface( NULL ),
mEglWindow( NULL ),
mThreadSynchronization( NULL ),
+ mRenderNotification( NULL ),
mRotationTrigger( NULL ),
+ mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
mRotationAngle( 0 ),
mScreenRotationAngle( 0 ),
+ mOwnSurface( false ),
mRotationSupported( false ),
mRotationFinished( true ),
mScreenRotationFinished( true ),
mResizeFinished( true )
{
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
- Init( surface );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" );
+ Initialize( surface );
}
-WindowRenderSurface::~WindowRenderSurface()
+WindowRenderSurfaceEcoreWl2::~WindowRenderSurfaceEcoreWl2()
{
if( mEglWindow != NULL )
{
delete mRotationTrigger;
}
+ if( mOwnSurface )
+ {
+ ecore_wl2_shutdown();
+ }
+}
+
+void WindowRenderSurfaceEcoreWl2::Initialize( Any surface )
+{
+ // see if there is a surface in Any surface
+ unsigned int surfaceId = GetSurfaceId( surface );
+
+ // if the surface is empty, create a new one.
+ if( surfaceId == 0 )
+ {
+ // we own the surface about to created
+ ecore_wl2_init();
+ mOwnSurface = true;
+ CreateRenderable();
+ }
+ else
+ {
+ // XLib should already be initialized so no point in calling XInitThreads
+ UseExistingRenderable( surfaceId );
+ }
}
-Ecore_Wl2_Window* WindowRenderSurface::GetDrawable()
+Ecore_Wl2_Window* WindowRenderSurfaceEcoreWl2::GetWlWindow()
{
- // already an e-core type
return mWlWindow;
}
-Any WindowRenderSurface::GetSurface()
+void WindowRenderSurfaceEcoreWl2::OutputTransformed()
{
- // already an e-core type
- return Any( mWlWindow );
+ int transform;
+
+ if( ecore_wl2_window_ignore_output_transform_get( mWlWindow ) )
+ {
+ transform = 0;
+ }
+ else
+ {
+ transform = ecore_wl2_output_transform_get( ecore_wl2_window_output_find( mWlWindow ) );
+ }
+
+ mScreenRotationAngle = transform * 90;
+ mScreenRotationFinished = false;
+
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::OutputTransformed: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle );
}
-Ecore_Wl2_Window* WindowRenderSurface::GetWlWindow()
+Any WindowRenderSurfaceEcoreWl2::GetWindow()
{
return mWlWindow;
}
-void WindowRenderSurface::RequestRotation( int angle, int width, int height )
+void WindowRenderSurfaceEcoreWl2::Map()
+{
+ ecore_wl2_window_show( mWlWindow );
+}
+
+void WindowRenderSurfaceEcoreWl2::SetRenderNotification( TriggerEventInterface* renderNotification )
+{
+ mRenderNotification = renderNotification;
+}
+
+void WindowRenderSurfaceEcoreWl2::SetTransparency( bool transparent )
+{
+ ecore_wl2_window_alpha_set( mWlWindow, transparent );
+}
+
+void WindowRenderSurfaceEcoreWl2::RequestRotation( int angle, int width, int height )
{
if( !mRotationSupported )
{
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: Rotation is not supported!\n" );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::Rotate: Rotation is not supported!\n" );
return;
}
if( !mRotationTrigger )
{
TriggerEventFactoryInterface& triggerFactory = Internal::Adaptor::Adaptor::GetImplementation( Adaptor::Get() ).GetTriggerEventFactoryInterface();
- mRotationTrigger = triggerFactory.CreateTriggerEvent( MakeCallback( this, &WindowRenderSurface::ProcessRotationRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
+ mRotationTrigger = triggerFactory.CreateTriggerEvent( MakeCallback( this, &WindowRenderSurfaceEcoreWl2::ProcessRotationRequest ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
}
mPositionSize.width = width;
ecore_wl2_window_rotation_set( mWlWindow, mRotationAngle );
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::Rotate: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle );
}
-void WindowRenderSurface::OutputTransformed()
+PositionSize WindowRenderSurfaceEcoreWl2::GetPositionSize() const
{
- int transform;
+ return mPositionSize;
+}
- if( ecore_wl2_window_ignore_output_transform_get( mWlWindow ) )
- {
- transform = 0;
- }
- else
- {
- transform = ecore_wl2_output_transform_get( ecore_wl2_window_output_find( mWlWindow ) );
- }
+void WindowRenderSurfaceEcoreWl2::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
+{
+ // calculate DPI
+ float xres, yres;
- mScreenRotationAngle = transform * 90;
- mScreenRotationFinished = false;
+ Ecore_Wl2_Output* output = ecore_wl2_window_output_find( mWlWindow );
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OutputTransformed: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle );
-}
+ // 1 inch = 25.4 millimeters
+ xres = ecore_wl2_output_dpi_get( output );
+ yres = ecore_wl2_output_dpi_get( output );
-void WindowRenderSurface::SetTransparency( bool transparent )
-{
- ecore_wl2_window_alpha_set( mWlWindow, transparent );
+ dpiHorizontal = int( xres + 0.5f ); // rounding
+ dpiVertical = int( yres + 0.5f );
}
-void WindowRenderSurface::InitializeEgl( EglInterface& eglIf )
+void WindowRenderSurfaceEcoreWl2::InitializeEgl( EglInterface& eglIf )
{
- DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
+ DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );
Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
eglImpl.ChooseConfig(true, mColorDepth);
}
-void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf )
+void WindowRenderSurfaceEcoreWl2::CreateEglSurface( EglInterface& eglIf )
{
- DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
+ DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );
Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
wl_egl_window_capability capability = static_cast< wl_egl_window_capability >( wl_egl_window_get_capabilities( mEglWindow ) );
if( capability == WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED )
{
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::CreateEglSurface: capability = %d\n", capability );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::CreateEglSurface: capability = %d\n", capability );
mRotationSupported = true;
}
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::CreateEglSurface: w = %d h = %d angle = %d screen rotation = %d\n", mPositionSize.width, mPositionSize.height, mRotationAngle, mScreenRotationAngle );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::CreateEglSurface: w = %d h = %d angle = %d screen rotation = %d\n", mPositionSize.width, mPositionSize.height, mRotationAngle, mScreenRotationAngle );
}
-void WindowRenderSurface::DestroyEglSurface( EglInterface& eglIf )
+void WindowRenderSurfaceEcoreWl2::DestroyEglSurface( EglInterface& eglIf )
{
- DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
+ DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );
Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( eglIf );
eglImpl.DestroySurface();
}
}
-bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& egl )
+bool WindowRenderSurfaceEcoreWl2::ReplaceEGLSurface( EglInterface& egl )
{
- DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
+ DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter );
if( mEglWindow != NULL )
{
return eglImpl.ReplaceSurfaceWindow( windowType );
}
-void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize )
+void WindowRenderSurfaceEcoreWl2::MoveResize( Dali::PositionSize positionSize )
{
bool needToMove = false;
bool needToResize = false;
if( needToMove || needToResize )
{
ecore_wl2_window_geometry_set( mWlWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
- if (needToResize)
+
+ if( needToResize )
{
mResizeFinished = false;
}
mPositionSize = positionSize;
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::MoveResize: %d, %d, %d, %d\n", mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::MoveResize: %d, %d, %d, %d\n", mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height );
}
-void WindowRenderSurface::Map()
+void WindowRenderSurfaceEcoreWl2::SetViewMode( ViewMode viewMode )
{
- ecore_wl2_window_show(mWlWindow);
}
-void WindowRenderSurface::StartRender()
+void WindowRenderSurfaceEcoreWl2::StartRender()
{
}
-bool WindowRenderSurface::PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, bool resizingSurface )
+bool WindowRenderSurfaceEcoreWl2::PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, bool resizingSurface )
{
if( resizingSurface )
{
// Reset only screen rotation flag
mScreenRotationFinished = true;
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: Set rotation [%d] [%d]\n", mRotationAngle, mScreenRotationAngle );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::PreRender: Set rotation [%d] [%d]\n", mRotationAngle, mScreenRotationAngle );
}
// Only window rotate
wl_egl_window_resize( mEglWindow, mPositionSize.width, mPositionSize.height, mPositionSize.x, mPositionSize.y );
mResizeFinished = true;
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: Set resize\n" );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::PreRender: Set resize\n" );
}
}
return true;
}
-void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
+void WindowRenderSurfaceEcoreWl2::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
{
if( resizingSurface )
{
if( !mRotationFinished )
{
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PostRender: Trigger rotation event\n" );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::PostRender: Trigger rotation event\n" );
mRotationTrigger->Trigger();
}
}
-void WindowRenderSurface::StopRender()
+void WindowRenderSurfaceEcoreWl2::StopRender()
{
}
-void WindowRenderSurface::SetViewMode( ViewMode viewMode )
+void WindowRenderSurfaceEcoreWl2::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
{
- //FIXME
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::SetThreadSynchronization: called\n" );
+
+ mThreadSynchronization = &threadSynchronization;
}
-void WindowRenderSurface::CreateWlRenderable()
+void WindowRenderSurfaceEcoreWl2::ReleaseLock()
{
- // TODO ::
- // use default display name as getenv("WAYLAND_DISPLAY")
- // If specific name is needed,
- // the name will be changed and should change the code of using ecore_wl2_connected_display_get()
- // Because default name is used in ecore_wl2_connected_display_get()'s use case.
- if ( mEcore_Wl2_display == NULL )
- {
- mEcore_Wl2_display = ecore_wl2_display_connect(NULL);
- }
- if ( mEcore_Wl2_display == NULL )
+ // Nothing to do.
+}
+
+RenderSurface::Type WindowRenderSurfaceEcoreWl2::GetSurfaceType()
+{
+ return RenderSurface::WINDOW_RENDER_SURFACE;
+}
+
+void WindowRenderSurfaceEcoreWl2::CreateRenderable()
+{
+ Ecore_Wl2_Display* display = ecore_wl2_display_connect( NULL );
+ if ( !display )
{
- DALI_LOG_ERROR("Fail to connect ecore_wl2_display");
- return;
+ DALI_ASSERT_ALWAYS(0 && "Failed to get display");
}
// if width or height are zero, go full screen.
mPositionSize.x = 0;
mPositionSize.y = 0;
- ecore_wl2_display_screen_size_get( mEcore_Wl2_display, &mPositionSize.width, &mPositionSize.height );
+ ecore_wl2_display_screen_size_get( display, &mPositionSize.width, &mPositionSize.height );
}
- mWlWindow = ecore_wl2_window_new( mEcore_Wl2_display, NULL, mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height );
+ mWlWindow = ecore_wl2_window_new( display, NULL, mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height );
+
if ( mWlWindow == 0 )
{
DALI_ASSERT_ALWAYS(0 && "Failed to create Wayland window");
ecore_wl2_window_alpha_set( mWlWindow, false );
}
- ecore_wl2_window_type_set( mWlWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
+ ecore_wl2_window_type_set( mWlWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL );
// Get output transform
if( !ecore_wl2_window_ignore_output_transform_get( mWlWindow ) )
}
}
-void WindowRenderSurface::UseExistingRenderable( unsigned int surfaceId )
+void WindowRenderSurfaceEcoreWl2::UseExistingRenderable( unsigned int surfaceId )
{
mWlWindow = AnyCast< Ecore_Wl2_Window* >( surfaceId );
}
-void WindowRenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
+unsigned int WindowRenderSurfaceEcoreWl2::GetSurfaceId( Any surface ) const
{
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::SetThreadSynchronization: called\n" );
+ unsigned int surfaceId = 0;
- mThreadSynchronization = &threadSynchronization;
-}
+ if( surface.Empty() == false )
+ {
+ // check we have a valid type
+ DALI_ASSERT_ALWAYS( ( (surface.GetType() == typeid (Ecore_Wl2_Window *) ) )
+ && "Surface type is invalid" );
-void WindowRenderSurface::ReleaseLock()
-{
- // Nothing to do.
+ surfaceId = AnyCast<unsigned int>( surface );
+ }
+ return surfaceId;
}
-void WindowRenderSurface::ProcessRotationRequest()
+void WindowRenderSurfaceEcoreWl2::ProcessRotationRequest()
{
mRotationFinished = true;
ecore_wl2_window_rotation_change_done_send( mWlWindow, mRotationAngle, mPositionSize.width, mPositionSize.height );
- DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::ProcessRotationRequest: Rotation Done\n" );
+ DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurfaceEcoreWl2::ProcessRotationRequest: Rotation Done\n" );
if( mThreadSynchronization )
{
}
}
-} // namespace ECore
+} // namespace Adaptor
+
+} // namespace internal
} // namespace Dali