2 * Copyright (c) 2018 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/native-render-surface-ecore-wl.h>
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/debug.h>
25 #include <Ecore_Wayland.h>
27 #include <tbm_bufmgr.h>
28 #include <tbm_surface_internal.h>
31 #include <dali/internal/system/common/trigger-event.h>
32 #include <dali/internal/graphics/gles20/egl-implementation.h>
33 #include <dali/internal/window-system/common/display-connection.h>
34 #include <dali/internal/window-system/common/window-system.h>
35 #include <dali/integration-api/thread-synchronization-interface.h>
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gNativeSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_NATIVE_RENDER_SURFACE");
47 } // unnamed namespace
49 NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl( Dali::PositionSize positionSize, bool isTransparent )
50 : mPosition( positionSize ),
51 mRenderNotification( NULL ),
52 mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
53 mTbmFormat( isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888 ),
55 mDrawableCompleted( false ),
57 mConsumeSurface( NULL ),
58 mThreadSynchronization( NULL )
60 Dali::Internal::Adaptor::WindowSystem::Initialize();
62 CreateNativeRenderable();
63 setenv( "EGL_PLATFORM", "tbm", 1 );
66 NativeRenderSurfaceEcoreWl::~NativeRenderSurfaceEcoreWl()
68 // release the surface if we own one
75 tbm_surface_queue_destroy( mTbmQueue );
78 DALI_LOG_INFO( gNativeSurfaceLogFilter, Debug::General, "Own tbm surface queue destroy\n" );
81 Dali::Internal::Adaptor::WindowSystem::Shutdown();
84 Any NativeRenderSurfaceEcoreWl::GetDrawable()
86 return mConsumeSurface;
89 void NativeRenderSurfaceEcoreWl::SetRenderNotification( TriggerEventInterface* renderNotification )
91 mRenderNotification = renderNotification;
94 void NativeRenderSurfaceEcoreWl::WaitUntilSurfaceReplaced()
96 ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
97 while( !mDrawableCompleted )
99 mTbmSurfaceCondition.Wait( lock );
102 mDrawableCompleted = false;
105 PositionSize NativeRenderSurfaceEcoreWl::GetPositionSize() const
110 void NativeRenderSurfaceEcoreWl::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
115 // 1 inch = 25.4 millimeters
116 xres = ecore_wl_dpi_get();
117 yres = ecore_wl_dpi_get();
119 dpiHorizontal = int( xres + 0.5f ); // rounding
120 dpiVertical = int( yres + 0.5f );
123 void NativeRenderSurfaceEcoreWl::InitializeEgl( EglInterface& egl )
125 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
126 unsetenv( "EGL_PLATFORM" );
128 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
130 eglImpl.ChooseConfig( true, mColorDepth );
133 void NativeRenderSurfaceEcoreWl::CreateEglSurface( EglInterface& egl )
135 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
137 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
139 eglImpl.CreateSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ), mColorDepth );
142 void NativeRenderSurfaceEcoreWl::DestroyEglSurface( EglInterface& egl )
144 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
146 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
147 eglImpl.DestroySurface();
150 bool NativeRenderSurfaceEcoreWl::ReplaceEGLSurface( EglInterface& egl )
152 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
159 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
161 return eglImpl.ReplaceSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ) );
164 void NativeRenderSurfaceEcoreWl::MoveResize( Dali::PositionSize positionSize )
168 void NativeRenderSurfaceEcoreWl::SetViewMode( ViewMode viewMode )
172 void NativeRenderSurfaceEcoreWl::StartRender()
176 bool NativeRenderSurfaceEcoreWl::PreRender( EglInterface&, Integration::GlAbstraction&, bool )
178 // nothing to do for pixmaps
182 void NativeRenderSurfaceEcoreWl::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
184 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
185 eglImpl.SwapBuffers();
187 if( mThreadSynchronization )
189 mThreadSynchronization->PostRenderStarted();
192 if( tbm_surface_queue_can_acquire( mTbmQueue, 1 ) )
194 if( tbm_surface_queue_acquire( mTbmQueue, &mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
196 DALI_LOG_ERROR( "Failed to aquire a tbm_surface\n" );
201 tbm_surface_internal_ref( mConsumeSurface );
203 if( replacingSurface )
205 ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
206 mDrawableCompleted = true;
207 mTbmSurfaceCondition.Notify( lock );
210 // create damage for client applications which wish to know the update timing
211 if( !replacingSurface && mRenderNotification )
213 // use notification trigger
214 // Tell the event-thread to render the tbm_surface
215 mRenderNotification->Trigger();
218 if( mThreadSynchronization )
220 // wait until the event-thread completed to use the tbm_surface
221 mThreadSynchronization->PostRenderWaitForCompletion();
224 // release the consumed surface after post render was completed
228 void NativeRenderSurfaceEcoreWl::StopRender()
233 void NativeRenderSurfaceEcoreWl::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
235 mThreadSynchronization = &threadSynchronization;
238 RenderSurface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
240 return RenderSurface::NATIVE_RENDER_SURFACE;
243 void NativeRenderSurfaceEcoreWl::ReleaseLock()
245 if( mThreadSynchronization )
247 mThreadSynchronization->PostRenderComplete();
251 void NativeRenderSurfaceEcoreWl::CreateNativeRenderable()
253 // check we're creating one with a valid size
254 DALI_ASSERT_ALWAYS( mPosition.width > 0 && mPosition.height > 0 && "tbm_surface size is invalid" );
256 mTbmQueue = tbm_surface_queue_create( 3, mPosition.width, mPosition.height, mTbmFormat, TBM_BO_DEFAULT );
268 void NativeRenderSurfaceEcoreWl::ReleaseDrawable()
270 if( mConsumeSurface )
272 tbm_surface_internal_unref( mConsumeSurface );
274 if( tbm_surface_internal_is_valid( mConsumeSurface ) )
276 tbm_surface_queue_release( mTbmQueue, mConsumeSurface );
278 mConsumeSurface = NULL;