Merge "Implemented the Handle assignment operators properly" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / pixmap-render-surface-wl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "pixmap-render-surface.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <ecore-wl-types.h>
27 #include <trigger-event.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 #if defined(DEBUG_ENABLED)
39 extern Debug::Filter* gRenderSurfaceLogFilter;
40 #endif
41
42 namespace ECore
43 {
44
45 PixmapRenderSurface::PixmapRenderSurface( Dali::PositionSize positionSize,
46                               Any surface,
47                               Any display,
48                               const std::string& name,
49                               bool isTransparent)
50 : RenderSurface( Dali::RenderSurface::PIXMAP, positionSize, surface, display, name, isTransparent )
51 {
52   Init( surface );
53 }
54
55 PixmapRenderSurface::~PixmapRenderSurface()
56 {
57   // release the surface if we own one
58   if( mOwnSurface )
59   {
60     // if we did create the pixmap, delete the pixmap
61     DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::General, "Own pixmap (%x) freed\n", mX11Pixmap );
62   }
63 }
64
65 Dali::RenderSurface::SurfaceType PixmapRenderSurface::GetType()
66 {
67   return Dali::RenderSurface::PIXMAP;
68 }
69
70 Any PixmapRenderSurface::GetSurface()
71 {
72   return Any( NULL );
73 }
74
75 void PixmapRenderSurface::InitializeEgl( EglInterface& eglIf )
76 {
77   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
78
79   EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
80   eglImpl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
81
82   eglImpl.ChooseConfig(false, mColorDepth);
83 }
84
85 void PixmapRenderSurface::CreateEglSurface( EglInterface& eglIf )
86 {
87   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
88
89   //EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
90
91   // create the EGL surface
92   // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
93   // FIXME
94 }
95
96 void PixmapRenderSurface::DestroyEglSurface( EglInterface& eglIf )
97 {
98   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
99
100   EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
101   eglImpl.DestroySurface();
102 }
103
104 bool PixmapRenderSurface::ReplaceEGLSurface( EglInterface& eglIf )
105 {
106   DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter );
107
108   EglImplementation& eglImpl = static_cast<EglImplementation&>( eglIf );
109   eglImpl.InitializeGles( reinterpret_cast< EGLNativeDisplayType >( mMainDisplay ) );
110
111   // a new surface for the new pixmap
112   // need to cast to X handle as in 64bit system ECore handle is 32 bit whereas EGLnative and XWindow are 64 bit
113   // FIXME
114   return false;
115 }
116
117 bool PixmapRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& )
118 {
119   // nothing to do for pixmaps
120   return true;
121 }
122
123 void PixmapRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, unsigned int timeDelta, SyncMode syncMode )
124 {
125   // flush gl instruction queue
126   glAbstraction.Flush();
127
128   // create damage for client applications which wish to know the update timing
129   if( mRenderNotification )
130   {
131     // use notification trigger
132     // Tell the event-thread to render the pixmap
133     mRenderNotification->Trigger();
134   }
135   else
136   {
137     // as a fallback, send damage event. This is needed until livebox is fixed to
138     // stop using damage events for render
139     // FIXME
140   }
141
142   // Do render synchronisation
143   DoRenderSync( timeDelta, syncMode );
144 }
145
146 void PixmapRenderSurface::CreateWlRenderable()
147 {
148   // check we're creating one with a valid size
149   DALI_ASSERT_ALWAYS( mPosition.width > 0 && mPosition.height > 0 && "Pixmap size is invalid" );
150
151   // FIXME
152 }
153
154 void PixmapRenderSurface::UseExistingRenderable( unsigned int surfaceId )
155 {
156 }
157
158 void PixmapRenderSurface::RenderSync()
159 {
160   {
161     boost::unique_lock< boost::mutex > lock( mSyncMutex );
162     mSyncReceived = true;
163   }
164
165   // wake render thread if it was waiting for the notify
166   mSyncNotify.notify_all();
167 }
168
169 } // namespace ECore
170
171 } // namespace Adaptor
172
173 } // namespace Internal
174
175 } // namespace Dali