X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fwindow-system%2Fcommon%2Fwindow-render-surface.cpp;h=e4bb8901e0d6ac440ca5c50987897e12537868a3;hb=573600ba751204639c5ee68a528f2b72acf8385c;hp=7d73395e9b411ad4e6019d89f5e2579c0a38ba68;hpb=c6b8a535a007fc0724e0d0b0b539646ba4c4c896;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/window-system/common/window-render-surface.cpp b/dali/internal/window-system/common/window-render-surface.cpp index 7d73395..e4bb890 100644 --- a/dali/internal/window-system/common/window-render-surface.cpp +++ b/dali/internal/window-system/common/window-render-surface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -25,11 +25,15 @@ // INTERNAL INCLUDES #include #include -#include +#include #include +#include #include #include #include +#include +#include + namespace Dali { @@ -50,19 +54,27 @@ Debug::Filter* gWindowRenderSurfaceLogFilter = Debug::Filter::New(Debug::Verbose } // unnamed namespace WindowRenderSurface::WindowRenderSurface( Dali::PositionSize positionSize, Any surface, bool isTransparent ) -: mPositionSize( positionSize ), +: mEGL( nullptr ), + mDisplayConnection( nullptr ), + mPositionSize( positionSize ), mWindowBase(), mThreadSynchronization( NULL ), mRenderNotification( NULL ), mRotationTrigger( NULL ), + mGraphics( nullptr ), + mEGLSurface( nullptr ), + mEGLContext( nullptr ), mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ), + mOutputTransformedSignal(), mRotationAngle( 0 ), mScreenRotationAngle( 0 ), mOwnSurface( false ), mRotationSupported( false ), mRotationFinished( true ), mScreenRotationFinished( true ), - mResizeFinished( true ) + mResizeFinished( true ), + mDpiHorizontal( 0 ), + mDpiVertical( 0 ) { DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "Creating Window\n" ); Initialize( surface ); @@ -74,19 +86,24 @@ WindowRenderSurface::~WindowRenderSurface() { delete mRotationTrigger; } + + if ( mEGLSurface ) + { + DestroySurface(); + } } void WindowRenderSurface::Initialize( Any surface ) { - // if width or height are zero, go full screen. - if ( (mPositionSize.width == 0) || (mPositionSize.height == 0) ) - { - // Default window size == screen size - mPositionSize.x = 0; - mPositionSize.y = 0; + // If width or height are zero, go full screen. + if ( (mPositionSize.width == 0) || (mPositionSize.height == 0) ) + { + // Default window size == screen size + mPositionSize.x = 0; + mPositionSize.y = 0; - WindowSystem::GetScreenSize( mPositionSize.width, mPositionSize.height ); - } + WindowSystem::GetScreenSize( mPositionSize.width, mPositionSize.height ); + } // Create a window base auto windowFactory = Dali::Internal::Adaptor::GetWindowFactory(); @@ -100,6 +117,7 @@ void WindowRenderSurface::Initialize( Any surface ) if( mScreenRotationAngle != 0 ) { mScreenRotationFinished = false; + mResizeFinished = false; } } @@ -130,12 +148,6 @@ void WindowRenderSurface::SetTransparency( bool transparent ) void WindowRenderSurface::RequestRotation( int angle, int width, int height ) { - if( !mRotationSupported ) - { - DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::Rotate: Rotation is not supported!\n" ); - return; - } - if( !mRotationTrigger ) { TriggerEventFactoryInterface& triggerFactory = Internal::Adaptor::Adaptor::GetImplementation( Adaptor::Get() ).GetTriggerEventFactoryInterface(); @@ -158,6 +170,11 @@ WindowBase* WindowRenderSurface::GetWindowBase() return mWindowBase.get(); } +WindowBase::OutputSignalType& WindowRenderSurface::OutputTransformedSignal() +{ + return mOutputTransformedSignal; +} + PositionSize WindowRenderSurface::GetPositionSize() const { return mPositionSize; @@ -165,19 +182,50 @@ PositionSize WindowRenderSurface::GetPositionSize() const void WindowRenderSurface::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) { - mWindowBase->GetDpi( dpiHorizontal, dpiVertical ); + if( mDpiHorizontal == 0 || mDpiVertical == 0 ) + { + const char* environmentDpiHorizontal = std::getenv( DALI_ENV_DPI_HORIZONTAL ); + mDpiHorizontal = environmentDpiHorizontal ? std::atoi( environmentDpiHorizontal ) : 0; + + const char* environmentDpiVertical = std::getenv( DALI_ENV_DPI_VERTICAL ); + mDpiVertical = environmentDpiVertical ? std::atoi( environmentDpiVertical ) : 0; + + if( mDpiHorizontal == 0 || mDpiVertical == 0 ) + { + mWindowBase->GetDpi( mDpiHorizontal, mDpiVertical ); + } + } + + dpiHorizontal = mDpiHorizontal; + dpiVertical = mDpiVertical; +} + +int WindowRenderSurface::GetOrientation() const +{ + return mWindowBase->GetOrientation(); } -void WindowRenderSurface::InitializeEgl( EglInterface& eglIf ) +void WindowRenderSurface::InitializeGraphics() { - DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter ); - Internal::Adaptor::EglImplementation& eglImpl = static_cast( eglIf ); + mGraphics = &mAdaptor->GetGraphicsInterface(); + + auto eglGraphics = static_cast(mGraphics); + mEGL = &eglGraphics->GetEglInterface(); - eglImpl.ChooseConfig(true, mColorDepth); + if ( mEGLContext == NULL ) + { + // Create the OpenGL context for this window + Internal::Adaptor::EglImplementation& eglImpl = static_cast(*mEGL); + eglImpl.ChooseConfig(true, mColorDepth); + eglImpl.CreateWindowContext( mEGLContext ); + + // Create the OpenGL surface + CreateSurface(); + } } -void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf ) +void WindowRenderSurface::CreateSurface() { DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter ); @@ -193,29 +241,36 @@ void WindowRenderSurface::CreateEglSurface( EglInterface& eglIf ) height = mPositionSize.width; } - // create the EGL window + // Create the EGL window EGLNativeWindowType window = mWindowBase->CreateEglWindow( width, height ); - Internal::Adaptor::EglImplementation& eglImpl = static_cast( eglIf ); - eglImpl.CreateSurfaceWindow( window, mColorDepth ); + auto eglGraphics = static_cast(mGraphics); + + Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation(); + mEGLSurface = eglImpl.CreateSurfaceWindow( window, mColorDepth ); // Check rotation capability mRotationSupported = mWindowBase->IsEglWindowRotationSupported(); - DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::CreateEglSurface: w = %d h = %d angle = %d screen rotation = %d\n", mPositionSize.width, mPositionSize.height, mRotationAngle, mScreenRotationAngle ); + int screenWidth, screenHeight; + WindowSystem::GetScreenSize( screenWidth, screenHeight ); + DALI_LOG_RELEASE_INFO("WindowRenderSurface::CreateSurface: w = %d h = %d screenWidth = %d screenHeight = %d angle = %d screen rotation = %d\n", + mPositionSize.width, mPositionSize.height, screenWidth, screenHeight, mRotationAngle, mScreenRotationAngle ); } -void WindowRenderSurface::DestroyEglSurface( EglInterface& eglIf ) +void WindowRenderSurface::DestroySurface() { DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter ); - Internal::Adaptor::EglImplementation& eglImpl = static_cast( eglIf ); - eglImpl.DestroySurface(); + auto eglGraphics = static_cast(mGraphics); + + Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation(); + eglImpl.DestroySurface( mEGLSurface ); mWindowBase->DestroyEglWindow(); } -bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& egl ) +bool WindowRenderSurface::ReplaceGraphicsSurface() { DALI_LOG_TRACE_METHOD( gWindowRenderSurfaceLogFilter ); @@ -234,14 +289,16 @@ bool WindowRenderSurface::ReplaceEGLSurface( EglInterface& egl ) height = mPositionSize.width; } - // create the EGL window + // Create the EGL window EGLNativeWindowType window = mWindowBase->CreateEglWindow( width, height ); // Set screen rotation mScreenRotationFinished = false; - Internal::Adaptor::EglImplementation& eglImpl = static_cast( egl ); - return eglImpl.ReplaceSurfaceWindow( window ); + auto eglGraphics = static_cast(mGraphics); + + Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation(); + return eglImpl.ReplaceSurfaceWindow( window, mEGLSurface, mEGLContext ); } void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize ) @@ -249,14 +306,14 @@ void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize ) bool needToMove = false; bool needToResize = false; - // check moving + // Check moving if( (fabs(positionSize.x - mPositionSize.x) > MINIMUM_DIMENSION_CHANGE) || (fabs(positionSize.y - mPositionSize.y) > MINIMUM_DIMENSION_CHANGE) ) { needToMove = true; } - // check resizing + // Check resizing if( (fabs(positionSize.width - mPositionSize.width) > MINIMUM_DIMENSION_CHANGE) || (fabs(positionSize.height - mPositionSize.height) > MINIMUM_DIMENSION_CHANGE) ) { @@ -290,25 +347,21 @@ void WindowRenderSurface::MoveResize( Dali::PositionSize positionSize ) DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::MoveResize: %d, %d, %d, %d\n", mPositionSize.x, mPositionSize.y, mPositionSize.width, mPositionSize.height ); } -void WindowRenderSurface::SetViewMode( ViewMode viewMode ) -{ - mWindowBase->SetViewMode( viewMode ); -} - void WindowRenderSurface::StartRender() { } -bool WindowRenderSurface::PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, bool resizingSurface ) +bool WindowRenderSurface::PreRender( bool resizingSurface ) { + MakeContextCurrent(); + if( resizingSurface ) { -#ifdef OVER_TIZEN_VERSION_4 + int totalAngle = (mRotationAngle + mScreenRotationAngle) % 360; + // Window rotate or screen rotate if( !mRotationFinished || !mScreenRotationFinished ) { - int totalAngle = (mRotationAngle + mScreenRotationAngle) % 360; - mWindowBase->SetEglWindowRotation( totalAngle ); mWindowBase->SetEglWindowBufferTransform( totalAngle ); @@ -323,45 +376,81 @@ bool WindowRenderSurface::PreRender( EglInterface& egl, Integration::GlAbstracti { mWindowBase->SetEglWindowTransform( mRotationAngle ); } -#endif // Resize case - if( !mResizeFinished ) + if ( !mResizeFinished ) { - mWindowBase->ResizeEglWindow( mPositionSize ); + Dali::PositionSize positionSize; + positionSize.x = mPositionSize.x; + positionSize.y = mPositionSize.y; + if( totalAngle == 0 || totalAngle == 180 ) + { + positionSize.width = mPositionSize.width; + positionSize.height = mPositionSize.height; + } + else + { + positionSize.width = mPositionSize.height; + positionSize.height = mPositionSize.width; + } + + mWindowBase->ResizeEglWindow( positionSize ); mResizeFinished = true; DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PreRender: Set resize\n" ); } } + auto eglGraphics = static_cast(mGraphics); + if ( eglGraphics ) + { + GlImplementation& mGLES = eglGraphics->GetGlesInterface(); + mGLES.PreRender(); + } + return true; } -void WindowRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, Dali::DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface ) +void WindowRenderSurface::PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface ) { - if( resizingSurface ) + // Inform the gl implementation that rendering has finished before informing the surface + auto eglGraphics = static_cast(mGraphics); + if ( eglGraphics ) { - if( !mRotationFinished ) - { - DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PostRender: Trigger rotation event\n" ); - - mRotationTrigger->Trigger(); + GlImplementation& mGLES = eglGraphics->GetGlesInterface(); + mGLES.PostRender(); - if( mThreadSynchronization ) + if( renderToFbo ) + { + mGLES.Flush(); + mGLES.Finish(); + } + else + { + if( resizingSurface ) { - // Wait until the event-thread complete the rotation event processing - mThreadSynchronization->PostRenderWaitForCompletion(); + if( !mRotationFinished ) + { + DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::PostRender: Trigger rotation event\n" ); + + mRotationTrigger->Trigger(); + + if( mThreadSynchronization ) + { + // Wait until the event-thread complete the rotation event processing + mThreadSynchronization->PostRenderWaitForCompletion(); + } + } } } - } - Internal::Adaptor::EglImplementation& eglImpl = static_cast( egl ); - eglImpl.SwapBuffers(); + Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation(); + eglImpl.SwapBuffers( mEGLSurface ); - if( mRenderNotification ) - { - mRenderNotification->Trigger(); + if( mRenderNotification ) + { + mRenderNotification->Trigger(); + } } } @@ -381,17 +470,47 @@ void WindowRenderSurface::ReleaseLock() // Nothing to do. } -RenderSurface::Type WindowRenderSurface::GetSurfaceType() +Integration::RenderSurface::Type WindowRenderSurface::GetSurfaceType() { return RenderSurface::WINDOW_RENDER_SURFACE; } +void WindowRenderSurface::MakeContextCurrent() +{ + if ( mEGL != nullptr ) + { + mEGL->MakeContextCurrent( mEGLSurface, mEGLContext ); + } +} + +Integration::DepthBufferAvailable WindowRenderSurface::GetDepthBufferRequired() +{ + return mGraphics ? mGraphics->GetDepthBufferRequired() : Integration::DepthBufferAvailable::FALSE; +} + +Integration::StencilBufferAvailable WindowRenderSurface::GetStencilBufferRequired() +{ + return mGraphics ? mGraphics->GetStencilBufferRequired() : Integration::StencilBufferAvailable::FALSE; +} + void WindowRenderSurface::OutputTransformed() { - mScreenRotationAngle = mWindowBase->GetScreenRotationAngle(); - mScreenRotationFinished = false; + int screenRotationAngle = mWindowBase->GetScreenRotationAngle(); + + if( mScreenRotationAngle != screenRotationAngle ) + { + mScreenRotationAngle = screenRotationAngle; + mScreenRotationFinished = false; + mResizeFinished = false; - DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OutputTransformed: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle ); + mOutputTransformedSignal.Emit(); + + DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OutputTransformed: angle = %d screen rotation = %d\n", mRotationAngle, mScreenRotationAngle ); + } + else + { + DALI_LOG_INFO( gWindowRenderSurfaceLogFilter, Debug::Verbose, "WindowRenderSurface::OutputTransformed: Ignore output transform [%d]\n", mScreenRotationAngle ); + } } void WindowRenderSurface::ProcessRotationRequest()