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