/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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/internal/window-system/tizen-wayland/native-render-surface-ecore-wl.h>
// EXTERNAL INCLUDES
-#include <dali/integration-api/gl-abstraction.h>
#include <dali/integration-api/debug.h>
+#include <dali/integration-api/gl-abstraction.h>
#ifdef ECORE_WAYLAND2
#include <Ecore_Wl2.h>
#include <tbm_surface_internal.h>
// INTERNAL INCLUDES
+#include <dali/integration-api/adaptor-framework/thread-synchronization-interface.h>
+#include <dali/internal/adaptor/common/adaptor-impl.h>
+#include <dali/internal/adaptor/common/adaptor-internal-services.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
+#include <dali/internal/graphics/gles/egl-implementation.h>
#include <dali/internal/system/common/trigger-event.h>
-#include <dali/internal/graphics/gles20/egl-implementation.h>
#include <dali/internal/window-system/common/display-connection.h>
#include <dali/internal/window-system/common/window-system.h>
-#include <dali/integration-api/thread-synchronization-interface.h>
namespace Dali
{
-
namespace
{
-
#if defined(DEBUG_ENABLED)
Debug::Filter* gNativeSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_NATIVE_RENDER_SURFACE");
#endif
} // unnamed namespace
-NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl( Dali::PositionSize positionSize, bool isTransparent )
-: mPosition( positionSize ),
- mRenderNotification( NULL ),
- mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
- mTbmFormat( isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888 ),
- mOwnSurface( false ),
- mDrawableCompleted( false ),
- mTbmQueue( NULL ),
- mConsumeSurface( NULL ),
- mThreadSynchronization( NULL )
+NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl(SurfaceSize surfaceSize, Any surface, bool isTransparent)
+: mRenderNotification(NULL),
+ mGraphics(NULL),
+ mEGL(nullptr),
+ mEGLSurface(nullptr),
+ mEGLContext(nullptr),
+ mOwnSurface(false),
+ mDrawableCompleted(false),
+ mTbmQueue(NULL),
+ mConsumeSurface(NULL),
+ mThreadSynchronization(NULL)
{
Dali::Internal::Adaptor::WindowSystem::Initialize();
- CreateNativeRenderable();
- setenv( "EGL_PLATFORM", "tbm", 1 );
+ if(surface.Empty())
+ {
+ mSurfaceSize = surfaceSize;
+ mColorDepth = isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24;
+ mTbmFormat = isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888;
+ CreateNativeRenderable();
+ }
+ else
+ {
+ mTbmQueue = AnyCast<tbm_surface_queue_h>(surface);
+
+ uint16_t width = static_cast<uint16_t>(tbm_surface_queue_get_width(mTbmQueue));
+ uint16_t height = static_cast<uint16_t>(tbm_surface_queue_get_height(mTbmQueue));
+ mSurfaceSize = SurfaceSize(width, height);
+
+ mTbmFormat = tbm_surface_queue_get_format(mTbmQueue);
+
+ mColorDepth = (mTbmFormat == TBM_FORMAT_ARGB8888) ? COLOR_DEPTH_32 : COLOR_DEPTH_24;
+ }
}
NativeRenderSurfaceEcoreWl::~NativeRenderSurfaceEcoreWl()
{
+ if(mEGLSurface)
+ {
+ DestroySurface();
+ }
+
// release the surface if we own one
- if( mOwnSurface )
+ if(mOwnSurface)
{
ReleaseDrawable();
- if( mTbmQueue )
+ if(mTbmQueue)
{
- tbm_surface_queue_destroy( mTbmQueue );
+ tbm_surface_queue_destroy(mTbmQueue);
}
- DALI_LOG_INFO( gNativeSurfaceLogFilter, Debug::General, "Own tbm surface queue destroy\n" );
+ DALI_LOG_INFO(gNativeSurfaceLogFilter, Debug::General, "Own tbm surface queue destroy\n");
}
Dali::Internal::Adaptor::WindowSystem::Shutdown();
return mConsumeSurface;
}
-void NativeRenderSurfaceEcoreWl::SetRenderNotification( TriggerEventInterface* renderNotification )
+void NativeRenderSurfaceEcoreWl::SetRenderNotification(TriggerEventInterface* renderNotification)
{
mRenderNotification = renderNotification;
}
void NativeRenderSurfaceEcoreWl::WaitUntilSurfaceReplaced()
{
- ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
- while( !mDrawableCompleted )
+ ConditionalWait::ScopedLock lock(mTbmSurfaceCondition);
+ while(!mDrawableCompleted)
{
- mTbmSurfaceCondition.Wait( lock );
+ mTbmSurfaceCondition.Wait(lock);
}
mDrawableCompleted = false;
}
+Any NativeRenderSurfaceEcoreWl::GetNativeRenderable()
+{
+ return mTbmQueue;
+}
+
PositionSize NativeRenderSurfaceEcoreWl::GetPositionSize() const
{
- return mPosition;
+ return PositionSize(0, 0, static_cast<int>(mSurfaceSize.GetWidth()), static_cast<int>(mSurfaceSize.GetHeight()));
}
-void NativeRenderSurfaceEcoreWl::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
+void NativeRenderSurfaceEcoreWl::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
{
// calculate DPI
float xres, yres;
yres = ecore_wl_dpi_get();
#endif
- dpiHorizontal = int( xres + 0.5f ); // rounding
- dpiVertical = int( yres + 0.5f );
+ dpiHorizontal = int(xres + 0.5f); // rounding
+ dpiVertical = int(yres + 0.5f);
}
-void NativeRenderSurfaceEcoreWl::InitializeEgl( EglInterface& egl )
+int NativeRenderSurfaceEcoreWl::GetOrientation() const
{
- DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
- unsetenv( "EGL_PLATFORM" );
+ return 0;
+}
+
+void NativeRenderSurfaceEcoreWl::InitializeGraphics()
+{
+ DALI_LOG_TRACE_METHOD(gNativeSurfaceLogFilter);
+
+ mGraphics = &mAdaptor->GetGraphicsInterface();
+ auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics*>(mGraphics);
- Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+ mEGL = &eglGraphics->GetEglInterface();
- eglImpl.ChooseConfig( true, mColorDepth );
+ if(mEGLContext == NULL)
+ {
+ // Create the OpenGL context for this window
+ Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>(*mEGL);
+ eglImpl.CreateWindowContext(mEGLContext);
+
+ // Create the OpenGL surface
+ CreateSurface();
+ }
}
-void NativeRenderSurfaceEcoreWl::CreateEglSurface( EglInterface& egl )
+void NativeRenderSurfaceEcoreWl::CreateSurface()
{
- DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
+ DALI_LOG_TRACE_METHOD(gNativeSurfaceLogFilter);
- Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+ auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics*>(mGraphics);
+ Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
- eglImpl.CreateSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ), mColorDepth );
+ mEGLSurface = eglImpl.CreateSurfaceWindow(reinterpret_cast<EGLNativeWindowType>(mTbmQueue), mColorDepth);
}
-void NativeRenderSurfaceEcoreWl::DestroyEglSurface( EglInterface& egl )
+void NativeRenderSurfaceEcoreWl::DestroySurface()
{
- DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
+ DALI_LOG_TRACE_METHOD(gNativeSurfaceLogFilter);
+
+ auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics*>(mGraphics);
+ Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
- Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
- eglImpl.DestroySurface();
+ eglImpl.DestroySurface(mEGLSurface);
}
-bool NativeRenderSurfaceEcoreWl::ReplaceEGLSurface( EglInterface& egl )
+bool NativeRenderSurfaceEcoreWl::ReplaceGraphicsSurface()
{
- DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
+ DALI_LOG_TRACE_METHOD(gNativeSurfaceLogFilter);
- if( !mTbmQueue )
+ if(!mTbmQueue)
{
return false;
}
- Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
+ auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics*>(mGraphics);
+ Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
- return eglImpl.ReplaceSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ) );
+ return eglImpl.ReplaceSurfaceWindow(reinterpret_cast<EGLNativeWindowType>(mTbmQueue), mEGLSurface, mEGLContext);
}
-void NativeRenderSurfaceEcoreWl::MoveResize( Dali::PositionSize positionSize )
+void NativeRenderSurfaceEcoreWl::MoveResize(Dali::PositionSize positionSize)
{
-}
+ tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
-void NativeRenderSurfaceEcoreWl::SetViewMode( ViewMode viewMode )
-{
+ error = tbm_surface_queue_reset(mTbmQueue, positionSize.width, positionSize.height, mTbmFormat);
+
+ if(error != TBM_SURFACE_QUEUE_ERROR_NONE)
+ {
+ DALI_LOG_ERROR("Failed to resize tbm_surface_queue");
+ }
+
+ mSurfaceSize.SetWidth(static_cast<uint16_t>(positionSize.width));
+ mSurfaceSize.SetHeight(static_cast<uint16_t>(positionSize.height));
}
void NativeRenderSurfaceEcoreWl::StartRender()
{
}
-bool NativeRenderSurfaceEcoreWl::PreRender( EglInterface&, Integration::GlAbstraction&, bool )
+bool NativeRenderSurfaceEcoreWl::PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
{
- // nothing to do for pixmaps
+ //TODO: Need to support partial update
+ MakeContextCurrent();
return true;
}
-void NativeRenderSurfaceEcoreWl::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
+void NativeRenderSurfaceEcoreWl::PostRender(bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects)
{
- Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
- eglImpl.SwapBuffers();
-
- if( mThreadSynchronization )
+ auto eglGraphics = static_cast<Internal::Adaptor::EglGraphics*>(mGraphics);
+ if(eglGraphics)
{
- mThreadSynchronization->PostRenderStarted();
+ Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
+ eglImpl.SwapBuffers(mEGLSurface, damagedRects);
}
- if( tbm_surface_queue_can_acquire( mTbmQueue, 1 ) )
+ //TODO: Move calling tbm_surface_queue_acruie to OffscreenWindow and Scene in EvasPlugin
+ if(mOwnSurface)
{
- if( tbm_surface_queue_acquire( mTbmQueue, &mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
+ if(mThreadSynchronization)
{
- DALI_LOG_ERROR( "Failed to aquire a tbm_surface\n" );
- return;
+ mThreadSynchronization->PostRenderStarted();
}
- }
- tbm_surface_internal_ref( mConsumeSurface );
+ if(tbm_surface_queue_can_acquire(mTbmQueue, 1))
+ {
+ if(tbm_surface_queue_acquire(mTbmQueue, &mConsumeSurface) != TBM_SURFACE_QUEUE_ERROR_NONE)
+ {
+ DALI_LOG_ERROR("Failed to acquire a tbm_surface\n");
+ return;
+ }
+ }
- if( replacingSurface )
- {
- ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
- mDrawableCompleted = true;
- mTbmSurfaceCondition.Notify( lock );
- }
+ if(mConsumeSurface)
+ {
+ tbm_surface_internal_ref(mConsumeSurface);
+ }
- // create damage for client applications which wish to know the update timing
- if( !replacingSurface && mRenderNotification )
- {
- // use notification trigger
- // Tell the event-thread to render the tbm_surface
- mRenderNotification->Trigger();
- }
+ if(replacingSurface)
+ {
+ ConditionalWait::ScopedLock lock(mTbmSurfaceCondition);
+ mDrawableCompleted = true;
+ mTbmSurfaceCondition.Notify(lock);
+ }
+
+ // create damage for client applications which wish to know the update timing
+ if(!replacingSurface && mRenderNotification)
+ {
+ // use notification trigger
+ // Tell the event-thread to render the tbm_surface
+ mRenderNotification->Trigger();
+ }
- if( mThreadSynchronization )
+ if(mThreadSynchronization)
+ {
+ // wait until the event-thread completed to use the tbm_surface
+ mThreadSynchronization->PostRenderWaitForCompletion();
+ }
+
+ // release the consumed surface after post render was completed
+ ReleaseDrawable();
+ }
+ else
{
- // wait until the event-thread completed to use the tbm_surface
- mThreadSynchronization->PostRenderWaitForCompletion();
+ // create damage for client applications which wish to know the update timing
+ if(!replacingSurface && mRenderNotification)
+ {
+ // use notification trigger
+ // Tell the event-thread to render the tbm_surface
+ mRenderNotification->Trigger();
+ }
}
-
- // release the consumed surface after post render was completed
- ReleaseDrawable();
}
void NativeRenderSurfaceEcoreWl::StopRender()
ReleaseLock();
}
-void NativeRenderSurfaceEcoreWl::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
+void NativeRenderSurfaceEcoreWl::SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization)
{
mThreadSynchronization = &threadSynchronization;
}
-RenderSurface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
+Dali::RenderSurfaceInterface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
{
- return RenderSurface::NATIVE_RENDER_SURFACE;
+ return Dali::RenderSurfaceInterface::NATIVE_RENDER_SURFACE;
+}
+
+void NativeRenderSurfaceEcoreWl::MakeContextCurrent()
+{
+ if(mEGL != nullptr)
+ {
+ mEGL->MakeContextCurrent(mEGLSurface, mEGLContext);
+ }
+}
+
+Integration::DepthBufferAvailable NativeRenderSurfaceEcoreWl::GetDepthBufferRequired()
+{
+ return mGraphics ? mGraphics->GetDepthBufferRequired() : Integration::DepthBufferAvailable::FALSE;
+}
+
+Integration::StencilBufferAvailable NativeRenderSurfaceEcoreWl::GetStencilBufferRequired()
+{
+ return mGraphics ? mGraphics->GetStencilBufferRequired() : Integration::StencilBufferAvailable::FALSE;
}
void NativeRenderSurfaceEcoreWl::ReleaseLock()
{
- if( mThreadSynchronization )
+ if(mThreadSynchronization)
{
mThreadSynchronization->PostRenderComplete();
}
void NativeRenderSurfaceEcoreWl::CreateNativeRenderable()
{
+ int width = static_cast<int>(mSurfaceSize.GetWidth());
+ int height = static_cast<int>(mSurfaceSize.GetHeight());
+
// check we're creating one with a valid size
- DALI_ASSERT_ALWAYS( mPosition.width > 0 && mPosition.height > 0 && "tbm_surface size is invalid" );
+ DALI_ASSERT_ALWAYS(width > 0 && height > 0 && "tbm_surface size is invalid");
- mTbmQueue = tbm_surface_queue_create( 3, mPosition.width, mPosition.height, mTbmFormat, TBM_BO_DEFAULT );
+ mTbmQueue = tbm_surface_queue_create(3, width, height, mTbmFormat, TBM_BO_DEFAULT);
- if( mTbmQueue )
+ if(mTbmQueue)
{
mOwnSurface = true;
}
void NativeRenderSurfaceEcoreWl::ReleaseDrawable()
{
- if( mConsumeSurface )
+ if(mConsumeSurface)
{
- tbm_surface_internal_unref( mConsumeSurface );
+ tbm_surface_internal_unref(mConsumeSurface);
- if( tbm_surface_internal_is_valid( mConsumeSurface ) )
+ if(tbm_surface_internal_is_valid(mConsumeSurface))
{
- tbm_surface_queue_release( mTbmQueue, mConsumeSurface );
+ tbm_surface_queue_release(mTbmQueue, mConsumeSurface);
}
mConsumeSurface = NULL;
}