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