Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / pixmap-render-surface.h
1 #ifndef __DALI_INTERNAL_ECORE_X_PIXMAP_RENDER_SURFACE_H__
2 #define __DALI_INTERNAL_ECORE_X_PIXMAP_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 // INTERNAL INCLUDES
22 #include <ecore-x-render-surface.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace Adaptor
31 {
32 class TriggerEvent;
33
34 namespace ECore
35 {
36
37 /**
38  * Ecore X11 implementation of render surface.
39  */
40 class PixmapRenderSurface : public RenderSurface
41 {
42 public:
43
44   /**
45     * Uses an X11 surface to render to.
46     * @param [in] positionSize the position and size of the surface
47     * @param [in] surface can be a X-window or X-pixmap (type must be unsigned int).
48     * @param [in] display connection to X-server if the surface is a X window or pixmap (type must be void * to X display struct)
49     * @param [in] name optional name of surface passed in
50     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
51     */
52   PixmapRenderSurface( Dali::PositionSize positionSize,
53                        Any surface,
54                        Any display,
55                        const std::string& name,
56                        bool isTransparent = false);
57
58   /**
59    * @copydoc Dali::Internal::Adaptor::ECore::RenderSurface::~RenderSurface
60    */
61   virtual ~PixmapRenderSurface();
62
63 public: // API
64
65   /**
66    * @copydoc Dali::Internal::Adaptor::ECore::RenderSurface::GetDrawable()
67    */
68   virtual Ecore_X_Drawable GetDrawable();
69
70 public: // from Dali::RenderSurface
71
72   /**
73    * @copydoc Dali::RenderSurface::GetType()
74    */
75   virtual Dali::RenderSurface::SurfaceType GetType();
76
77   /**
78    * @copydoc Dali::RenderSurface::GetSurface()
79    */
80   virtual Any GetSurface();
81
82 public: // from Internal::Adaptor::RenderSurface
83
84   /**
85    * @copydoc Dali::Internal::Adaptor::RenderSurface::InitializeEgl()
86    */
87   virtual void InitializeEgl( EglInterface& egl );
88
89   /**
90    * @copydoc Dali::Internal::Adaptor::RenderSurface::CreateEglSurface()
91    */
92   virtual void CreateEglSurface( EglInterface& egl );
93
94   /**
95    * @copydoc Dali::Internal::Adaptor::RenderSurface::DestroyEglSurface()
96    */
97   virtual void DestroyEglSurface( EglInterface& egl );
98
99   /**
100    * @copydoc Dali::Internal::Adaptor::RenderSurface::ReplaceEGLSurface()
101    */
102   virtual bool ReplaceEGLSurface( EglInterface& egl );
103
104   /**
105    * @copydoc Dali::Internal::Adaptor::RenderSurface::StartRender()
106    */
107   virtual void StartRender();
108
109   /**
110    * @copydoc Dali::Internal::Adaptor::RenderSurface::PreRender()
111    */
112   virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction );
113
114   /**
115    * @copydoc Dali::Internal::Adaptor::RenderSurface::PostRender()
116    */
117   virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, unsigned int timeDelta, bool replacingSurface );
118
119   /**
120    * @copydoc Dali::Internal::Adaptor::RenderSurface::StopRender()
121    */
122   virtual void StopRender();
123
124 private:
125   enum SyncMode
126   {
127     SYNC_MODE_NONE,
128     SYNC_MODE_WAIT
129   };
130
131   /**
132    * Set the sync mode.
133    * @param[in] syncMode The sync mode
134    */
135   void SetSyncMode( SyncMode syncMode );
136
137   /**
138    * If sync mode is WAIT, then acquire a lock. This prevents render thread from
139    * continuing until the pixmap has been drawn by the compositor.
140    * It must be released for rendering to continue.
141    * @param[in] syncMode The sync mode
142    */
143   void AcquireLock( SyncMode syncMode );
144
145   /**
146    * Release any locks.
147    */
148   void ReleaseLock();
149
150   /**
151    * Create XPixmap
152    */
153   virtual void CreateXRenderable();
154
155   /**
156    * @copydoc Dali::Internal::Adaptor::ECore::RenderSurface::UseExistingRenderable
157    */
158   virtual void UseExistingRenderable( unsigned int surfaceId );
159
160 private: // Data
161
162   Ecore_X_Pixmap   mX11Pixmap;    ///< X-Pixmap
163   SyncMode         mSyncMode;     ///< Stores whether the post render should block waiting for compositor
164   boost::mutex                mSyncMutex;  ///< mutex to lock during waiting sync
165   boost::condition_variable   mSyncNotify; ///< condition to notify main thread that pixmap was flushed to onscreen
166   bool             mSyncReceived; ///< true, when a pixmap sync has occurred, (cleared after reading)
167 };
168
169 } // namespace ECore
170
171 } // namespace Adaptor
172
173 } // namespace internal
174
175 } // namespace Dali
176
177 #endif // __DALI_INTERNAL_ECORE_X_PIXMAP_RENDER_SURFACE_H__