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