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