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