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/windows/pixmap-render-surface-ecore-win.h>
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/threading/mutex.h>
25 #include <Win32WindowSystem.h>
28 #include <dali/integration-api/thread-synchronization-interface.h>
29 #include <dali/internal/system/common/trigger-event.h>
30 #include <dali/internal/window-system/common/display-connection.h>
39 #if defined(DEBUG_ENABLED)
40 Debug::Filter* gPixmapRenderSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_PIXMAP_RENDER_SURFACE_ECORE_X");
45 static const int INITIAL_PRODUCE_BUFFER_INDEX = 0;
46 static const int INITIAL_CONSUME_BUFFER_INDEX = 1;
49 PixmapRenderSurfaceEcoreWin::PixmapRenderSurfaceEcoreWin(Dali::PositionSize positionSize,
51 const std::string& name,
53 : mPosition( positionSize ),
55 mRenderNotification( NULL ),
56 mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
58 mProduceBufferIndex( INITIAL_PRODUCE_BUFFER_INDEX ),
59 mConsumeBufferIndex( INITIAL_CONSUME_BUFFER_INDEX ),
60 mThreadSynchronization(NULL)
62 for( int i = 0; i != BUFFER_COUNT; ++i )
68 Initialize( surface );
71 PixmapRenderSurfaceEcoreWin::~PixmapRenderSurfaceEcoreWin()
73 // release the surface if we own one
76 // for (int i = 0; i < BUFFER_COUNT; ++i)
78 // Ecore_X_Pixmap pixmap = mX11Pixmaps[i];
80 // // if we did create the pixmap, delete the pixmap
81 // DALI_LOG_INFO( gPixmapRenderSurfaceLogFilter, Debug::General, "Own pixmap (%x) freed\n", pixmap );
82 // ecore_x_pixmap_free( pixmap );
87 void PixmapRenderSurfaceEcoreWin::Initialize( Any surface )
89 // see if there is a surface in Any surface
90 unsigned int surfaceId = GetSurfaceId( surface );
92 // if the surface is empty, create a new one.
95 // we own the surface about to created
101 // XLib should already be initialized so no point in calling XInitThreads
102 UseExistingRenderable( surfaceId );
106 Any PixmapRenderSurfaceEcoreWin::GetSurface()
108 //Ecore_X_Pixmap pixmap = 0;
110 // ConditionalWait::ScopedLock lock( mPixmapCondition );
111 // pixmap = mX11Pixmaps[mProduceBufferIndex];
117 void PixmapRenderSurfaceEcoreWin::SetRenderNotification(TriggerEventInterface* renderNotification)
119 mRenderNotification = renderNotification;
122 PositionSize PixmapRenderSurfaceEcoreWin::GetPositionSize() const
127 void PixmapRenderSurfaceEcoreWin::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
132 //// 1 inch = 25.4 millimeters
133 Win32WindowSystem::GetDPI( xres, yres );
138 dpiHorizontal = int( xres + 0.5f ); // rounding
139 dpiVertical = int( yres + 0.5f );
142 void PixmapRenderSurfaceEcoreWin::InitializeEgl( EglInterface& egl )
144 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
146 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
148 eglImpl.ChooseConfig(false, mColorDepth);
151 void PixmapRenderSurfaceEcoreWin::CreateEglSurface( EglInterface& egl )
153 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
155 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
157 for (int i = 0; i < BUFFER_COUNT; ++i)
159 // create the EGL surface
160 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
161 XPixmap pixmap = static_cast<XPixmap>( mX11Pixmaps[i] );
162 mEglSurfaces[i] = eglImpl.CreateSurfacePixmap( EGLNativePixmapType( pixmap ), mColorDepth ); // reinterpret_cast does not compile
166 void PixmapRenderSurfaceEcoreWin::DestroyEglSurface( EglInterface& egl )
168 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
170 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
172 for (int i = 0; i < BUFFER_COUNT; ++i)
174 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
175 XPixmap pixmap = static_cast<XPixmap>( mX11Pixmaps[i] );
176 eglImpl.MakeCurrent( EGLNativePixmapType( pixmap ), mEglSurfaces[i] );
177 eglImpl.DestroySurface();
181 bool PixmapRenderSurfaceEcoreWin::ReplaceEGLSurface( EglInterface& egl )
183 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
185 bool contextLost = false;
187 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
189 for (int i = 0; i < BUFFER_COUNT; ++i)
191 // a new surface for the new pixmap
192 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
193 XPixmap pixmap = static_cast<XPixmap>( mX11Pixmaps[i] );
194 contextLost = eglImpl.ReplaceSurfacePixmap( EGLNativePixmapType( pixmap ), mEglSurfaces[i] ); // reinterpret_cast does not compile
197 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
198 XPixmap pixmap = static_cast<XPixmap>( mX11Pixmaps[mProduceBufferIndex] );
199 eglImpl.MakeCurrent( EGLNativePixmapType( pixmap ), mEglSurfaces[mProduceBufferIndex] );
204 void PixmapRenderSurfaceEcoreWin::StartRender()
208 bool PixmapRenderSurfaceEcoreWin::PreRender( EglInterface& egl, Integration::GlAbstraction&, bool )
210 // Nothing to do for pixmaps
214 void PixmapRenderSurfaceEcoreWin::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, Dali::DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
218 void PixmapRenderSurfaceEcoreWin::StopRender()
223 void PixmapRenderSurfaceEcoreWin::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
225 mThreadSynchronization = &threadSynchronization;
228 void PixmapRenderSurfaceEcoreWin::ReleaseLock()
230 if( mThreadSynchronization )
232 mThreadSynchronization->PostRenderComplete();
236 RenderSurface::Type PixmapRenderSurfaceEcoreWin::GetSurfaceType()
238 return RenderSurface::PIXMAP_RENDER_SURFACE;
241 void PixmapRenderSurfaceEcoreWin::CreateRenderable()
245 void PixmapRenderSurfaceEcoreWin::UseExistingRenderable( unsigned int surfaceId )
249 unsigned int PixmapRenderSurfaceEcoreWin::GetSurfaceId( Any surface ) const
254 } // namespace Adaptor
256 } // namespace internal