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>
26 #include <tbm_bufmgr.h>
27 #include <tbm_surface_internal.h>
30 #include <dali/internal/system/common/trigger-event.h>
31 #include <dali/internal/graphics/gles20/egl-implementation.h>
32 #include <dali/internal/window-system/common/display-connection.h>
33 #include <dali/integration-api/thread-synchronization-interface.h>
41 #if defined(DEBUG_ENABLED)
42 Debug::Filter* gNativeSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_NATIVE_RENDER_SURFACE");
45 } // unnamed namespace
47 NativeRenderSurfaceEcoreWl::NativeRenderSurfaceEcoreWl( Dali::PositionSize positionSize, const std::string& name, bool isTransparent )
48 : mPosition( positionSize ),
50 mRenderNotification( NULL ),
51 mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
52 mTbmFormat( isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888 ),
54 mDrawableCompleted( false ),
56 mConsumeSurface( NULL ),
57 mThreadSynchronization( NULL )
59 ecore_wl_init( NULL );
60 CreateNativeRenderable();
61 setenv( "EGL_PLATFORM", "tbm", 1 );
64 NativeRenderSurfaceEcoreWl::~NativeRenderSurfaceEcoreWl()
66 // release the surface if we own one
73 tbm_surface_queue_destroy( mTbmQueue );
76 DALI_LOG_INFO( gNativeSurfaceLogFilter, Debug::General, "Own tbm surface queue destroy\n" );
80 Any NativeRenderSurfaceEcoreWl::GetDrawable()
82 return mConsumeSurface;
85 void NativeRenderSurfaceEcoreWl::SetRenderNotification( TriggerEventInterface* renderNotification )
87 mRenderNotification = renderNotification;
90 void NativeRenderSurfaceEcoreWl::WaitUntilSurfaceReplaced()
92 ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
93 while( !mDrawableCompleted )
95 mTbmSurfaceCondition.Wait( lock );
98 mDrawableCompleted = false;
101 PositionSize NativeRenderSurfaceEcoreWl::GetPositionSize() const
106 void NativeRenderSurfaceEcoreWl::InitializeEgl( EglInterface& egl )
108 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
109 unsetenv( "EGL_PLATFORM" );
111 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
113 eglImpl.ChooseConfig( true, mColorDepth );
116 void NativeRenderSurfaceEcoreWl::CreateEglSurface( EglInterface& egl )
118 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
120 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
122 eglImpl.CreateSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ), mColorDepth );
125 void NativeRenderSurfaceEcoreWl::DestroyEglSurface( EglInterface& egl )
127 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
129 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
130 eglImpl.DestroySurface();
133 bool NativeRenderSurfaceEcoreWl::ReplaceEGLSurface( EglInterface& egl )
135 DALI_LOG_TRACE_METHOD( gNativeSurfaceLogFilter );
142 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
144 return eglImpl.ReplaceSurfaceWindow( reinterpret_cast< EGLNativeWindowType >( mTbmQueue ) );
147 void NativeRenderSurfaceEcoreWl::MoveResize( Dali::PositionSize positionSize )
151 void NativeRenderSurfaceEcoreWl::SetViewMode( ViewMode viewMode )
155 void NativeRenderSurfaceEcoreWl::StartRender()
159 bool NativeRenderSurfaceEcoreWl::PreRender( EglInterface&, Integration::GlAbstraction&, bool )
161 // nothing to do for pixmaps
165 void NativeRenderSurfaceEcoreWl::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
167 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
168 eglImpl.SwapBuffers();
170 if( mThreadSynchronization )
172 mThreadSynchronization->PostRenderStarted();
175 if( tbm_surface_queue_can_acquire( mTbmQueue, 1 ) )
177 if( tbm_surface_queue_acquire( mTbmQueue, &mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE )
179 DALI_LOG_ERROR( "Failed to aquire a tbm_surface\n" );
184 tbm_surface_internal_ref( mConsumeSurface );
186 if( replacingSurface )
188 ConditionalWait::ScopedLock lock( mTbmSurfaceCondition );
189 mDrawableCompleted = true;
190 mTbmSurfaceCondition.Notify( lock );
193 // create damage for client applications which wish to know the update timing
194 if( !replacingSurface && mRenderNotification )
196 // use notification trigger
197 // Tell the event-thread to render the tbm_surface
198 mRenderNotification->Trigger();
201 if( mThreadSynchronization )
203 // wait until the event-thread completed to use the tbm_surface
204 mThreadSynchronization->PostRenderWaitForCompletion();
207 // release the consumed surface after post render was completed
211 void NativeRenderSurfaceEcoreWl::StopRender()
216 void NativeRenderSurfaceEcoreWl::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
218 mThreadSynchronization = &threadSynchronization;
221 RenderSurface::Type NativeRenderSurfaceEcoreWl::GetSurfaceType()
223 return RenderSurface::NATIVE_RENDER_SURFACE;
226 void NativeRenderSurfaceEcoreWl::ReleaseLock()
228 if( mThreadSynchronization )
230 mThreadSynchronization->PostRenderComplete();
234 void NativeRenderSurfaceEcoreWl::CreateNativeRenderable()
236 // check we're creating one with a valid size
237 DALI_ASSERT_ALWAYS( mPosition.width > 0 && mPosition.height > 0 && "tbm_surface size is invalid" );
239 mTbmQueue = tbm_surface_queue_create( 3, mPosition.width, mPosition.height, mTbmFormat, TBM_BO_DEFAULT );
251 void NativeRenderSurfaceEcoreWl::ReleaseDrawable()
253 if( mConsumeSurface )
255 tbm_surface_internal_unref( mConsumeSurface );
257 if( tbm_surface_internal_is_valid( mConsumeSurface ) )
259 tbm_surface_queue_release( mTbmQueue, mConsumeSurface );
261 mConsumeSurface = NULL;