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-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>
27 #include <dali/integration-api/thread-synchronization-interface.h>
28 #include <dali/internal/system/common/trigger-event.h>
29 #include <dali/internal/window-system/common/display-connection.h>
30 #include <dali/internal/window-system/windows/platform-implement-win.h>
39 #if defined(DEBUG_ENABLED)
40 Debug::Filter* gPixmapRenderSurfaceLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_PIXMAP_RENDER_SURFACE_WIN");
45 static const int INITIAL_PRODUCE_BUFFER_INDEX = 0;
46 static const int INITIAL_CONSUME_BUFFER_INDEX = 1;
49 PixmapRenderSurfaceEcoreWin::PixmapRenderSurfaceEcoreWin( Dali::PositionSize positionSize, Any surface, bool isTransparent )
50 : mPosition( positionSize ),
51 mRenderNotification( NULL ),
52 mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ),
54 mProduceBufferIndex( INITIAL_PRODUCE_BUFFER_INDEX ),
55 mConsumeBufferIndex( INITIAL_CONSUME_BUFFER_INDEX ),
56 mThreadSynchronization(NULL)
58 for( int i = 0; i != BUFFER_COUNT; ++i )
64 Initialize( surface );
67 PixmapRenderSurfaceEcoreWin::~PixmapRenderSurfaceEcoreWin()
69 // release the surface if we own one
72 // for (int i = 0; i < BUFFER_COUNT; ++i)
74 // Ecore_X_Pixmap pixmap = mWinPixmaps[i];
76 // // if we did create the pixmap, delete the pixmap
77 // DALI_LOG_INFO( gPixmapRenderSurfaceLogFilter, Debug::General, "Own pixmap (%x) freed\n", pixmap );
78 // ecore_x_pixmap_free( pixmap );
83 void PixmapRenderSurfaceEcoreWin::Initialize( Any surface )
85 // see if there is a surface in Any surface
86 unsigned int surfaceId = GetSurfaceId( surface );
88 // if the surface is empty, create a new one.
91 // we own the surface about to created
97 // XLib should already be initialized so no point in calling XInitThreads
98 UseExistingRenderable( surfaceId );
102 Any PixmapRenderSurfaceEcoreWin::GetSurface()
104 //Ecore_X_Pixmap pixmap = 0;
106 // ConditionalWait::ScopedLock lock( mPixmapCondition );
107 // pixmap = mWinPixmaps[mProduceBufferIndex];
113 void PixmapRenderSurfaceEcoreWin::SetRenderNotification(TriggerEventInterface* renderNotification)
115 mRenderNotification = renderNotification;
118 PositionSize PixmapRenderSurfaceEcoreWin::GetPositionSize() const
123 void PixmapRenderSurfaceEcoreWin::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
128 //// 1 inch = 25.4 millimeters
129 WindowsPlatformImplement::GetDPI( xres, yres );
134 dpiHorizontal = int( xres + 0.5f ); // rounding
135 dpiVertical = int( yres + 0.5f );
138 void PixmapRenderSurfaceEcoreWin::InitializeEgl( EglInterface& egl )
140 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
142 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
144 eglImpl.ChooseConfig(false, mColorDepth);
147 void PixmapRenderSurfaceEcoreWin::CreateEglSurface( EglInterface& egl )
149 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
151 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
153 for (int i = 0; i < BUFFER_COUNT; ++i)
155 // create the EGL surface
156 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
157 WinPixmap pixmap = static_cast<WinPixmap>( mWinPixmaps[i] );
158 mEglSurfaces[i] = eglImpl.CreateSurfacePixmap( EGLNativePixmapType( pixmap ), mColorDepth ); // reinterpret_cast does not compile
162 void PixmapRenderSurfaceEcoreWin::DestroyEglSurface( EglInterface& egl )
164 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
166 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
168 for (int i = 0; i < BUFFER_COUNT; ++i)
170 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
171 WinPixmap pixmap = static_cast<WinPixmap>( mWinPixmaps[i] );
172 eglImpl.MakeCurrent( EGLNativePixmapType( pixmap ), mEglSurfaces[i] );
173 eglImpl.DestroySurface();
177 bool PixmapRenderSurfaceEcoreWin::ReplaceEGLSurface( EglInterface& egl )
179 DALI_LOG_TRACE_METHOD( gPixmapRenderSurfaceLogFilter );
181 bool contextLost = false;
183 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( egl );
185 for (int i = 0; i < BUFFER_COUNT; ++i)
187 // a new surface for the new pixmap
188 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
189 WinPixmap pixmap = static_cast<WinPixmap>( mWinPixmaps[i] );
190 contextLost = eglImpl.ReplaceSurfacePixmap( EGLNativePixmapType( pixmap ), mEglSurfaces[i] ); // reinterpret_cast does not compile
193 // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
194 WinPixmap pixmap = static_cast<WinPixmap>( mWinPixmaps[mProduceBufferIndex] );
195 eglImpl.MakeCurrent( EGLNativePixmapType( pixmap ), mEglSurfaces[mProduceBufferIndex] );
200 void PixmapRenderSurfaceEcoreWin::StartRender()
204 bool PixmapRenderSurfaceEcoreWin::PreRender( EglInterface& egl, Integration::GlAbstraction&, bool )
206 // Nothing to do for pixmaps
210 void PixmapRenderSurfaceEcoreWin::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, Dali::DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface )
214 void PixmapRenderSurfaceEcoreWin::StopRender()
219 void PixmapRenderSurfaceEcoreWin::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization )
221 mThreadSynchronization = &threadSynchronization;
224 void PixmapRenderSurfaceEcoreWin::ReleaseLock()
226 if( mThreadSynchronization )
228 mThreadSynchronization->PostRenderComplete();
232 RenderSurface::Type PixmapRenderSurfaceEcoreWin::GetSurfaceType()
234 return RenderSurface::PIXMAP_RENDER_SURFACE;
237 void PixmapRenderSurfaceEcoreWin::CreateRenderable()
241 void PixmapRenderSurfaceEcoreWin::UseExistingRenderable( unsigned int surfaceId )
245 unsigned int PixmapRenderSurfaceEcoreWin::GetSurfaceId( Any surface ) const
250 } // namespace Adaptor
252 } // namespace internal