Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / ubuntu-x11 / pixmap-render-surface-ecore-x.h
1 #ifndef __DALI_ECORE_X_PIXMAP_RENDER_SURFACE_H__
2 #define __DALI_ECORE_X_PIXMAP_RENDER_SURFACE_H__
3
4 /*
5  * Copyright (c) 2018 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 <dali/integration-api/egl-interface.h>
23 #include <dali/internal/graphics/gles20/egl-implementation.h>
24 #include <dali/internal/window-system/common/pixmap-render-surface.h>
25 #include <dali/internal/window-system/ubuntu-x11/ecore-x-types.h>
26 #include <dali/public-api/dali-adaptor-common.h>
27
28 // EXTERNAL INCLUDES
29 #include <dali/devel-api/threading/conditional-wait.h>
30 #include <Ecore_X.h>
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38
39 /**
40  * Ecore X11 Pixmap implementation of render surface.
41  */
42 class PixmapRenderSurfaceEcoreX : public PixmapRenderSurface
43 {
44 public:
45
46   /**
47     * Uses an X11 surface to render to.
48     * @param [in] positionSize the position and size of the surface
49     * @param [in] surface can be a X-window or X-pixmap (type must be unsigned int).
50     * @param [in] name optional name of surface passed in
51     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
52     */
53   PixmapRenderSurfaceEcoreX( Dali::PositionSize positionSize,
54                        Any surface,
55                        const std::string& name,
56                        bool isTransparent = false);
57
58   /**
59    * @brief Destructor
60    */
61   virtual ~PixmapRenderSurfaceEcoreX();
62
63 public: // from WindowRenderSurface
64
65   /**
66    * @copydoc Dali::Internal::Adaptor::PixmapRenderSurface::GetSurface()
67    */
68   virtual Any GetSurface() override;
69
70   /**
71    * @copydoc Dali::Internal::Adaptor::PixmapRenderSurface::SetRenderNotification()
72    */
73   virtual void SetRenderNotification( TriggerEventInterface* renderNotification ) override;
74
75 public: // from Dali::RenderSurface
76
77   /**
78    * @copydoc Dali::RenderSurface::GetPositionSize()
79    */
80   virtual PositionSize GetPositionSize() const override;
81
82   /**
83    * @copydoc Dali::RenderSurface::GetDpi()
84    */
85   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
86
87   /**
88    * @copydoc Dali::RenderSurface::InitializeEgl()
89    */
90   virtual void InitializeEgl( EglInterface& egl ) override;
91
92   /**
93    * @copydoc Dali::RenderSurface::CreateEglSurface()
94    */
95   virtual void CreateEglSurface( EglInterface& egl ) override;
96
97   /**
98    * @copydoc Dali::RenderSurface::DestroyEglSurface()
99    */
100   virtual void DestroyEglSurface( EglInterface& egl ) override;
101
102   /**
103    * @copydoc Dali::RenderSurface::ReplaceEGLSurface()
104    */
105   virtual bool ReplaceEGLSurface( EglInterface& egl ) override;
106
107   /**
108    * @copydoc Dali::RenderSurface::MoveResize()
109    */
110   virtual void MoveResize( Dali::PositionSize positionSize) override {}
111
112   /**
113    * @copydoc Dali::RenderSurface::SetViewMode()
114    */
115   void SetViewMode( ViewMode viewMode ) override {}
116
117   /**
118    * @copydoc Dali::RenderSurface::StartRender()
119    */
120   virtual void StartRender() override;
121
122   /**
123    * @copydoc Dali::RenderSurface::PreRender()
124    */
125   virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, bool resizingSurface ) override;
126
127   /**
128    * @copydoc Dali::RenderSurface::PostRender()
129    */
130   virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface );
131
132   /**
133    * @copydoc Dali::RenderSurface::StopRender()
134    */
135   virtual void StopRender() override;
136
137   /**
138    * @copydoc Dali::RenderSurface::SetThreadSynchronization
139    */
140   virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
141
142   /**
143    * @copydoc Dali::RenderSurface::GetSurfaceType()
144    */
145   virtual RenderSurface::Type GetSurfaceType() override;
146
147 private: // from PixmapRenderSurface
148
149   /**
150    * @copydoc Dali::RenderSurface::ReleaseLock()
151    */
152   virtual void ReleaseLock() override;
153
154   /**
155    * @copydoc Dali::Internal::Adaptor::PixmapRenderSurface::Initialize()
156    */
157   virtual void Initialize( Any surface ) override;
158
159   /**
160    * @copydoc Dali::Internal::Adaptor::PixmapRenderSurface::Initialize()
161    */
162   virtual void CreateRenderable() override;
163
164   /**
165    * @copydoc Dali::Internal::Adaptor::PixmapRenderSurface::Initialize()
166    */
167   virtual void UseExistingRenderable( unsigned int surfaceId ) override;
168
169 private:
170
171   /**
172    * Get the surface id if the surface parameter is not empty
173    * @param surface Any containing a surface id, or can be empty
174    * @return surface id, or zero if surface is empty
175    */
176   unsigned int GetSurfaceId( Any surface ) const;
177
178 private: // Data
179
180   static const int BUFFER_COUNT = 2;
181
182   PositionSize                    mPosition;               ///< Position
183   std::string                     mTitle;                  ///< Title of window which shows from "xinfo -topvwins" command
184   TriggerEventInterface*          mRenderNotification;     ///< Render notification trigger
185   ColorDepth                      mColorDepth;             ///< Color depth of surface (32 bit or 24 bit)
186   bool                            mOwnSurface;             ///< Whether we own the surface (responsible for deleting it)
187
188   int                             mProduceBufferIndex;
189   int                             mConsumeBufferIndex;
190   XPixmap                         mX11Pixmaps[BUFFER_COUNT];  ///< X-Pixmap
191   EGLSurface                      mEglSurfaces[BUFFER_COUNT];
192   ThreadSynchronizationInterface* mThreadSynchronization;     ///< A pointer to the thread-synchronization
193   ConditionalWait                 mPixmapCondition;           ///< condition to share pixmap
194 };
195
196 } // namespace Adaptor
197
198 } // namespace internal
199
200 } // namespace Dali
201
202 #endif // __DALI_ECORE_X_PIXMAP_RENDER_SURFACE_H__