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>
26 #include <Ecore_Wl2.h>
28 #include <Ecore_Wayland.h>
31 #include <tbm_bufmgr.h>
32 #include <tbm_surface_internal.h>
35 #include <dali/internal/system/common/trigger-event.h>
36 #include <dali/internal/graphics/gles20/egl-implementation.h>
37 #include <dali/internal/window-system/common/display-connection.h>
38 #include <dali/integration-api/thread-synchronization-interface.h>
46 #if defined(DEBUG_ENABLED)
47 Debug::Filter* gNativeSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_NATIVE_RENDER_SURFACE");
50 } // unnamed namespace
52 NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl( Dali::PositionSize positionSize, const std::string& name, bool isTransparent )
53 : mPosition( positionSize ),
55 mRenderNotification( NULL ),
56 mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
57 mTbmFormat( isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888 ),
59 mDrawableCompleted( false ),
61 mConsumeSurface( NULL ),
62 mThreadSynchronization( NULL )
67 ecore_wl_init( NULL );
70 CreateNativeRenderable();
71 setenv( "EGL_PLATFORM", "tbm", 1 );
74 NativeRenderSurfaceEcoreWl::~NativeRenderSurfaceEcoreWl()
76 // release the surface if we own one
83 tbm_surface_queue_destroy( mTbmQueue );
86 DALI_LOG_INFO( gNativeSurfaceLogFilter, Debug::General, "Own tbm surface queue destroy\n" );
96 Any NativeRenderSurfaceEcoreWl::GetDrawable()
98 return mConsumeSurface;
101 void NativeRenderSurfaceEcoreWl::SetRenderNotification( TriggerEventInterface* renderNotification )
103 mRenderNotification = renderNotification;
106 void NativeRenderSurfaceEcoreWl::WaitUntilSurfaceReplaced()
108 ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
109 while( !mDrawableCompleted )
111 mTbmSurfaceCondition.Wait( lock );
114 mDrawableCompleted = false;
117 PositionSize NativeRenderSurfaceEcoreWl::GetPositionSize() const
122 void NativeRenderSurfaceEcoreWl::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
127 // 1 inch = 25.4 millimeters
128 #ifdef ECORE_WAYLAND2
129 // TODO: Application should set dpi value in wayland2
133 xres = ecore_wl_dpi_get();
134 yres = ecore_wl_dpi_get();
137 dpiHorizontal = int( xres + 0.5f ); // rounding
138 dpiVertical = int( yres + 0.5f );
141 void NativeRenderSurfaceEcoreWl::InitializeEgl( EglInterface& egl )
143 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
144 unsetenv( "EGL_PLATFORM" );
146 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
148 eglImpl.ChooseConfig( true, mColorDepth );
151 void NativeRenderSurfaceEcoreWl::CreateEglSurface( EglInterface& egl )
153 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
155 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
157 eglImpl.CreateSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ), mColorDepth );
160 void NativeRenderSurfaceEcoreWl::DestroyEglSurface( EglInterface& egl )
162 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
164 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
165 eglImpl.DestroySurface();
168 bool NativeRenderSurfaceEcoreWl::ReplaceEGLSurface( EglInterface& egl )
170 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
177 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
179 return eglImpl.ReplaceSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ) );
182 void NativeRenderSurfaceEcoreWl::MoveResize( Dali::PositionSize positionSize )
186 void NativeRenderSurfaceEcoreWl::SetViewMode( ViewMode viewMode )
190 void NativeRenderSurfaceEcoreWl::StartRender()
194 bool NativeRenderSurfaceEcoreWl::PreRender( EglInterface&, Integration::GlAbstraction&, bool )
196 // nothing to do for pixmaps
200 void NativeRenderSurfaceEcoreWl::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
202 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
203 eglImpl.SwapBuffers();
205 if( mThreadSynchronization )
207 mThreadSynchronization->PostRenderStarted();
210 if( tbm_surface_queue_can_acquire( mTbmQueue, 1 ) )
212 if( tbm_surface_queue_acquire( mTbmQueue, &mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
214 DALI_LOG_ERROR( "Failed to aquire a tbm_surface\n" );
219 tbm_surface_internal_ref( mConsumeSurface );
221 if( replacingSurface )
223 ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
224 mDrawableCompleted = true;
225 mTbmSurfaceCondition.Notify( lock );
228 // create damage for client applications which wish to know the update timing
229 if( !replacingSurface && mRenderNotification )
231 // use notification trigger
232 // Tell the event-thread to render the tbm_surface
233 mRenderNotification->Trigger();
236 if( mThreadSynchronization )
238 // wait until the event-thread completed to use the tbm_surface
239 mThreadSynchronization->PostRenderWaitForCompletion();
242 // release the consumed surface after post render was completed
246 void NativeRenderSurfaceEcoreWl::StopRender()
251 void NativeRenderSurfaceEcoreWl::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
253 mThreadSynchronization = &threadSynchronization;
256 RenderSurface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
258 return RenderSurface::NATIVE_RENDER_SURFACE;
261 void NativeRenderSurfaceEcoreWl::ReleaseLock()
263 if( mThreadSynchronization )
265 mThreadSynchronization->PostRenderComplete();
269 void NativeRenderSurfaceEcoreWl::CreateNativeRenderable()
271 // check we're creating one with a valid size
272 DALI_ASSERT_ALWAYS( mPosition.width > 0 && mPosition.height > 0 && "tbm_surface size is invalid" );
274 mTbmQueue = tbm_surface_queue_create( 3, mPosition.width, mPosition.height, mTbmFormat, TBM_BO_DEFAULT );
286 void NativeRenderSurfaceEcoreWl::ReleaseDrawable()
288 if( mConsumeSurface )
290 tbm_surface_internal_unref( mConsumeSurface );
292 if( tbm_surface_internal_is_valid( mConsumeSurface ) )
294 tbm_surface_queue_release( mTbmQueue, mConsumeSurface );
296 mConsumeSurface = NULL;