[dali_1.0.7] Merge branch 'tizen'
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / ecore-x-render-surface.h
1 #ifndef __DALI_INTERNAL_ECORE_X_RENDER_SURFACE_H__
2 #define __DALI_INTERNAL_ECORE_X_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_X.h>
25 #include <dali/public-api/common/dali-common.h>
26
27 // INTERNAL INCLUDES
28 #include <render-surface-impl.h>
29 #include <ecore-x-types.h>
30 #include <gl/egl-implementation.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40 class TriggerEvent;
41
42 namespace ECore
43 {
44
45 /**
46  * Ecore X11 implementation of render surface.
47  * @todo change namespace to ECore_X11 as the class
48  * is no longer pure X11.
49  */
50 class DALI_IMPORT_API RenderSurface : public Internal::Adaptor::RenderSurface
51 {
52 public:
53   /**
54     * Uses an X11 surface to render to.
55     * @param [in] type the type of surface passed in
56     * @param [in] positionSize the position and size of the surface
57     * @param [in] surface can be a X-window or X-pixmap (type must be unsigned int).
58     * @param [in] display connection to X-server if the surface is a X window or pixmap (type must be void * to X display struct)
59     * @param [in] name optional name of surface passed in
60     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
61     */
62   RenderSurface( SurfaceType type,
63                  Dali::PositionSize positionSize,
64                  Any surface,
65                  Any display,
66                  const std::string& name,
67                  bool isTransparent = false);
68
69   /**
70    * Destructor.
71    * Will delete the display, if it has ownership.
72    * Will delete the window/pixmap if it has owner ship
73    */
74   virtual ~RenderSurface();
75
76 protected:
77   /**
78    * Second stage construction
79    * Creates the surface (window, pixmap or native buffer)
80    */
81   void Init( Any surface );
82
83 public: // API
84
85   /**
86    * @return the Ecore X window handle
87    */
88   Ecore_X_Window GetXWindow();
89
90   /**
91    * @return the Main X display
92    */
93   XDisplay* GetMainDisplay();
94
95   /**
96    * Sets the render notification trigger to call when render thread is completed a frame
97    * @param renderNotification to use
98    */
99   void SetRenderNotification( TriggerEvent* renderNotification );
100
101   /**
102    * Get the surface as an Ecore_X_drawable
103    */
104   virtual Ecore_X_Drawable GetDrawable();
105
106 public: // from Dali::RenderSurface
107
108   /**
109    * @copydoc Dali::RenderSurface::GetType()
110    */
111   virtual Dali::RenderSurface::SurfaceType GetType() = 0;
112
113   /**
114    * @copydoc Dali::RenderSurface::GetSurface()
115    */
116   virtual Any GetSurface() = 0;
117
118   /**
119    * @copydoc Dali::RenderSurface::GetDisplay()
120    */
121   virtual Any GetDisplay();
122
123   /**
124    * @copydoc Dali::RenderSurface::GetPositionSize()
125    */
126   virtual PositionSize GetPositionSize() const;
127
128   /**
129    * @copydoc Dali::RenderSurface::SetRenderMode()
130    */
131   virtual void SetRenderMode(RenderMode mode);
132
133   /**
134    * @copydoc Dali::RenderSurface::GetRenderMode()
135    */
136   virtual RenderMode GetRenderMode() const;
137
138 public:  // from Internal::Adaptor::RenderSurface
139
140   /**
141    * @copydoc Dali::Internal::Adaptor::RenderSurface::CreateEglSurface()
142    */
143   virtual void CreateEglSurface( EglInterface& egl ) = 0;
144
145   /**
146    * @copydoc Dali::Internal::Adaptor::RenderSurface::DestroyEglSurface()
147    */
148   virtual void DestroyEglSurface( EglInterface& egl ) = 0;
149
150   /**
151    * @copydoc Dali::Internal::Adaptor::RenderSurface::ReplaceEGLSurface()
152    */
153   virtual bool ReplaceEGLSurface( EglInterface& egl ) = 0;
154
155   /**
156    * @copydoc Dali::Internal::Adaptor::RenderSurface::MoveResize()
157    */
158   virtual void MoveResize( Dali::PositionSize positionSize);
159
160   /**
161    * @copydoc Dali::Internal::Adaptor::RenderSurface::GetDpi()
162    */
163   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) const;
164
165   /**
166    * @copydoc Dali::Internal::Adaptor::RenderSurface::Map()
167    */
168   virtual void Map();
169
170   /**
171    * @copydoc Dali::Internal::Adaptor::RenderSurface::TransferDisplayOwner()
172    */
173   virtual void TransferDisplayOwner( Internal::Adaptor::RenderSurface& newSurface );
174
175   /**
176    * @copydoc Dali::Internal::Adaptor::RenderSurface::ConsumeEvents()
177    */
178   virtual void ConsumeEvents();
179
180   /**
181    * @copydoc Dali::Internal::Adaptor::RenderSurface::RenderSync()
182    */
183   virtual void RenderSync();
184
185   /**
186    * @copydoc Dali::Internal::Adaptor::RenderSurface::SetViewMode()
187    */
188   void SetViewMode( ViewMode );
189
190   /**
191    * @copydoc Dali::Internal::Adaptor::RenderSurface::PreRender()
192    */
193   virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction ) = 0;
194
195   /**
196    * @copydoc Dali::Internal::Adaptor::RenderSurface::PostRender()
197    */
198   virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, unsigned int timeDelta, SyncMode syncMode ) = 0;
199
200   /**
201    * @copydoc Dali::Internal::Adaptor::RenderSurface::StopRender()
202    */
203   virtual void StopRender();
204
205   /**
206    * @copydoc Dali::Internal::Adaptor::RenderSurface::SetSyncMode()
207    */
208   virtual void SetSyncMode( SyncMode syncMode ) { mSyncMode = syncMode; }
209
210 private:
211
212   /**
213    * Sets the display, if display parameter is empty it opens a new display
214    * @param display
215    */
216   void SetDisplay( Any display );
217
218   /**
219    * Get the surface id if the surface parameter is not empty
220    * @param surface Any containing a surface id, or can be empty
221    * @return surface id, or zero if surface is empty
222    */
223   unsigned int GetSurfaceId( Any surface ) const;
224
225 protected:
226
227   /**
228    * Create XRenderable
229    */
230   virtual void CreateXRenderable() = 0;
231
232   /**
233    * Use an existing render surface
234    * @param surfaceId the id of the surface
235    */
236   virtual void UseExistingRenderable( unsigned int surfaceId ) = 0;
237
238   /**
239    * Perform render sync
240    * @param[in] currentTime Current time in microseconds
241    * @param[in] syncMode Wait for RenderSync (from Adaptor) flag. A member of SyncMode
242    */
243   void DoRenderSync( unsigned int timeDelta, SyncMode syncMode );
244
245 protected: // Data
246
247   XDisplay*                   mMainDisplay;        ///< X-connection for rendering
248   Ecore_X_Window              mRootWindow;         ///< X-Root window
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_X_RENDER_SURFACE_H__