Merge "Implemented the Handle assignment operators properly" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / ecore-wl-render-surface.h
1 #ifndef __DALI_INTERNAL_ECORE_WL_RENDER_SURFACE_H__
2 #define __DALI_INTERNAL_ECORE_WL_RENDER_SURFACE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23 #include <boost/thread.hpp>
24 #include <Ecore.h>
25 #include <Ecore_Wayland.h>
26 #include <dali/public-api/common/dali-common.h>
27
28 // INTERNAL INCLUDES
29 #include <render-surface-impl.h>
30 #include <ecore-wl-types.h>
31 #include <gl/egl-implementation.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41 class TriggerEvent;
42
43 namespace ECore
44 {
45
46 /**
47  * Ecore Wayland implementation of render surface.
48  * @todo change namespace to ECore_Wayland as the class
49  * is no longer pure Wayland.
50  */
51 class DALI_IMPORT_API RenderSurface : public Internal::Adaptor::RenderSurface
52 {
53 public:
54   /**
55     * Uses an Wayland surface to render to.
56     * @param [in] type the type of surface passed in
57     * @param [in] positionSize the position and size of the surface
58     * @param [in] surface can be a X-window or X-pixmap (type must be unsigned int).
59     * @param [in] display connection to X-server if the surface is a X window or pixmap (type must be void * to X display struct)
60     * @param [in] name optional name of surface passed in
61     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
62     */
63   RenderSurface( SurfaceType type,
64                  Dali::PositionSize positionSize,
65                  Any surface,
66                  Any display,
67                  const std::string& name,
68                  bool isTransparent = false);
69
70   /**
71    * Destructor.
72    * Will delete the display, if it has ownership.
73    * Will delete the window/pixmap if it has owner ship
74    */
75   virtual ~RenderSurface();
76
77 protected:
78   /**
79    * Second stage construction
80    * Creates the surface (window, pixmap or native buffer)
81    */
82   void Init( Any surface );
83
84 public: // API
85
86   /**
87    * @return the Ecore X window handle
88    */
89   Ecore_Wl_Window* GetWlWindow();
90
91   /**
92    * @return the Main X display
93    */
94   WlDisplay* GetMainDisplay();
95
96   /**
97    * Sets the render notification trigger to call when render thread is completed a frame
98    * @param renderNotification to use
99    */
100   void SetRenderNotification( TriggerEvent* renderNotification );
101
102   /**
103    * Get the surface as an Ecore_X_drawable
104    */
105   virtual Ecore_Wl_Window* GetDrawable();
106
107 public: // from Dali::RenderSurface
108
109   /**
110    * @copydoc Dali::RenderSurface::GetType()
111    */
112   virtual Dali::RenderSurface::SurfaceType GetType() = 0;
113
114   /**
115    * @copydoc Dali::RenderSurface::GetSurface()
116    */
117   virtual Any GetSurface() = 0;
118
119   /**
120    * @copydoc Dali::RenderSurface::GetDisplay()
121    */
122   virtual Any GetDisplay();
123
124   /**
125    * @copydoc Dali::RenderSurface::GetPositionSize()
126    */
127   virtual PositionSize GetPositionSize() const;
128
129   /**
130    * @copydoc Dali::RenderSurface::SetRenderMode()
131    */
132   virtual void SetRenderMode(RenderMode mode);
133
134   /**
135    * @copydoc Dali::RenderSurface::GetRenderMode()
136    */
137   virtual RenderMode GetRenderMode() const;
138
139 public:  // from Internal::Adaptor::RenderSurface
140
141   /**
142    * @copydoc Dali::Internal::Adaptor::RenderSurface::CreateEglSurface()
143    */
144   virtual void CreateEglSurface( EglInterface& egl ) = 0;
145
146   /**
147    * @copydoc Dali::Internal::Adaptor::RenderSurface::DestroyEglSurface()
148    */
149   virtual void DestroyEglSurface( EglInterface& egl ) = 0;
150
151   /**
152    * @copydoc Dali::Internal::Adaptor::RenderSurface::ReplaceEGLSurface()
153    */
154   virtual bool ReplaceEGLSurface( EglInterface& egl ) = 0;
155
156   /**
157    * @copydoc Dali::Internal::Adaptor::RenderSurface::MoveResize()
158    */
159   virtual void MoveResize( Dali::PositionSize positionSize);
160
161   /**
162    * @copydoc Dali::Internal::Adaptor::RenderSurface::GetDpi()
163    */
164   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) const;
165
166   /**
167    * @copydoc Dali::Internal::Adaptor::RenderSurface::Map()
168    */
169   virtual void Map();
170
171   /**
172    * @copydoc Dali::Internal::Adaptor::RenderSurface::TransferDisplayOwner()
173    */
174   virtual void TransferDisplayOwner( Internal::Adaptor::RenderSurface& newSurface );
175
176   /**
177    * @copydoc Dali::Internal::Adaptor::RenderSurface::ConsumeEvents()
178    */
179   virtual void ConsumeEvents();
180
181   /**
182    * @copydoc Dali::Internal::Adaptor::RenderSurface::RenderSync()
183    */
184   virtual void RenderSync();
185
186   /**
187    * @copydoc Dali::Internal::Adaptor::RenderSurface::SetViewMode()
188    */
189   void SetViewMode( ViewMode );
190
191   /**
192    * @copydoc Dali::Internal::Adaptor::RenderSurface::PreRender()
193    */
194   virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction ) = 0;
195
196   /**
197    * @copydoc Dali::Internal::Adaptor::RenderSurface::PostRender()
198    */
199   virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, unsigned int timeDelta, SyncMode syncMode ) = 0;
200
201   /**
202    * @copydoc Dali::Internal::Adaptor::RenderSurface::StopRender()
203    */
204   virtual void StopRender();
205
206   /**
207    * @copydoc Dali::Internal::Adaptor::RenderSurface::SetSyncMode()
208    */
209   virtual void SetSyncMode( SyncMode syncMode ) { mSyncMode = syncMode; }
210
211 private:
212
213   /**
214    * Sets the display, if display parameter is empty it opens a new display
215    * @param display
216    */
217   void SetDisplay( Any display );
218
219   /**
220    * Get the surface id if the surface parameter is not empty
221    * @param surface Any containing a surface id, or can be empty
222    * @return surface id, or zero if surface is empty
223    */
224   unsigned int GetSurfaceId( Any surface ) const;
225
226 protected:
227
228   /**
229    * Create XRenderable
230    */
231   virtual void CreateWlRenderable() = 0;
232
233   /**
234    * Use an existing render surface
235    * @param surfaceId the id of the surface
236    */
237   virtual void UseExistingRenderable( unsigned int surfaceId ) = 0;
238
239   /**
240    * Perform render sync
241    * @param[in] currentTime Current time in microseconds
242    * @param[in] syncMode Wait for RenderSync (from Adaptor) flag. A member of SyncMode
243    */
244   void DoRenderSync( unsigned int timeDelta, SyncMode syncMode );
245
246 protected: // Data
247
248   WlDisplay*                  mMainDisplay;        ///< Wayland-connection for rendering
249   SurfaceType                 mType;               ///< type of renderable
250   PositionSize                mPosition;           ///< Position
251   std::string                 mTitle;              ///< Title of window which shows from "xinfo -topvwins" command
252   ColorDepth                  mColorDepth;         ///< Color depth of surface (32 bit or 24 bit)
253   RenderMode                  mRenderMode;         ///< Render mode for pixmap surface type
254   TriggerEvent*               mRenderNotification; ///< Render notificatin trigger
255   boost::mutex                mSyncMutex;          ///< mutex to lock during waiting sync
256   boost::condition_variable   mSyncNotify;         ///< condition to notify main thread that pixmap was flushed to onscreen
257   SyncMode                    mSyncMode;
258   bool                        mSyncReceived;       ///< true, when a pixmap sync has occurred, (cleared after reading)
259   bool                        mOwnSurface;         ///< Whether we own the surface (responsible for deleting it)
260   bool                        mOwnDisplay;         ///< Whether we own the display (responsible for deleting it)
261   bool                        mIsStopped;          ///< Render should be stopped
262 };
263
264 } // namespace ECore
265
266 } // namespace Adaptor
267
268 } // namespace internal
269
270 } // namespace Dali
271
272 #endif // __DALI_INTERNAL_ECORE_WL_RENDER_SURFACE_H__