[Tizen] Add to get the status whether window is rotating or not
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-render-surface.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_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/mutex.h>
23 #include <dali/integration-api/scene.h>
24 #include <dali/public-api/signals/connection-tracker.h>
25 #include <dali/public-api/signals/dali-signal.h>
26 #include <unistd.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/integration-api/adaptor-framework/egl-interface.h>
30 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
31 #include <dali/internal/graphics/common/graphics-interface.h>
32 #include <dali/internal/system/common/file-descriptor-monitor.h>
33
34 namespace Dali
35 {
36 class TriggerEventInterface;
37
38 namespace Internal
39 {
40 namespace Adaptor
41 {
42 class WindowBase;
43 class AdaptorInternalServices;
44
45 /**
46  * Window interface of render surface.
47  */
48 class WindowRenderSurface : public Dali::RenderSurfaceInterface, public ConnectionTracker
49 {
50 public:
51   using OutputSignalType      = Signal<void()>;
52   using DamagedRectsContainer = std::list<std::vector<Rect<int>>>;
53
54   /**
55     * Uses an window surface to render to.
56     * @param [in] positionSize the position and size of the surface
57     * @param [in] surface can be a window or pixmap.
58     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
59     */
60   WindowRenderSurface(Dali::PositionSize positionSize, Any surface, bool isTransparent = false);
61
62   /**
63    * @brief Destructor
64    */
65   virtual ~WindowRenderSurface();
66
67 public: // API
68   /**
69    * @brief Get the native window handle
70    * @return The native window handle
71    */
72   Any GetNativeWindow();
73
74   /**
75    * @brief Get the native window id
76    * @return The native window id
77    */
78   int GetNativeWindowId();
79
80   /**
81    * @brief Map window
82    */
83   void Map();
84
85   /**
86    * @brief Sets the render notification trigger to call when render thread is completed a frame
87    * @param renderNotification to use
88    */
89   void SetRenderNotification(TriggerEventInterface* renderNotification);
90
91   /**
92    * @brief Sets whether the surface is transparent or not.
93    * @param[in] transparent Whether the surface is transparent
94    */
95   void SetTransparency(bool transparent);
96
97   /**
98    * Request surface rotation
99    * @param[in] angle A new angle of the surface
100    * @param[in] positionSize A new position and size of the surface
101    */
102   void RequestRotation(int angle, PositionSize positionSize);
103
104   /**
105    * @brief Gets the window base object
106    * @return The window base object
107    */
108   WindowBase* GetWindowBase();
109
110   /**
111    * @brief Intiailize Ime Surface for Ime window rendering.
112    *
113    * It sets one flag and callback function for Ime window rendering
114    * This callback function calls one special native window function for ready to commit buffer.
115    * The special function notify to display server.
116    * It is only used for Ime window.
117    */
118   void InitializeImeSurface();
119
120   /**
121    * @brief Sets the necessary for window rotation acknowledge.
122    * After this function called, SendRotationCompletedAcknowledgement() should be called to complete window rotation.
123    *
124    * More detail description is written in DevelWindow::SetNeedsRotationCompletedAcknowledgement().
125    *
126    * @param[in] window The window instance.
127    * @param[in] needAcknowledgement the flag is true if window rotation acknowledgement is sent.
128    */
129   void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
130
131   /**
132    * @brief Updates window surface's position and size.
133    * It is just to update the local variable in window surface.
134    * This function is only called when window's position or size is changed by display server.
135    *
136    * @param[in] positionSize The updated window surface's position and size.
137    */
138   void UpdatePositionSize(Dali::PositionSize positionSize);
139
140   /**
141    * @brief Query whether window is rotating or not.
142    *
143    * @return true if window is rotating, false otherwise.
144    */
145   bool IsWindowRotating() const;
146
147   /**
148    * @brief This signal is emitted when the output is transformed.
149    */
150   OutputSignalType& OutputTransformedSignal();
151
152 public: // from Dali::RenderSurfaceInterface
153   /**
154    * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
155    */
156   PositionSize GetPositionSize() const override;
157
158   /**
159    */
160   void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
161
162   /**
163    * @copydoc Dali::RenderSurfaceInterface::GetOrientation()
164    */
165   int GetOrientation() const override;
166
167   /**
168    * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
169    */
170   void InitializeGraphics() override;
171
172   /**
173    * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
174    */
175   void CreateSurface() override;
176
177   /**
178    * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
179    */
180   void DestroySurface() override;
181
182   /**
183    * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
184    */
185   bool ReplaceGraphicsSurface() override;
186
187   /**
188    * @copydoc Dali::RenderSurfaceInterface::MoveResize()
189    */
190   void MoveResize(Dali::PositionSize positionSize) override;
191
192   /**
193    * @copydoc Dali::RenderSurfaceInterface::StartRender()
194    */
195   void StartRender() override;
196
197   /**
198    * @copydoc Dali::RenderSurfaceInterface::PreRender()
199    */
200   bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) override;
201
202   /**
203    * @copydoc Dali::RenderSurfaceInterface::PostRender()
204    */
205   void PostRender() override;
206
207   /**
208    * @copydoc Dali::RenderSurfaceInterface::StopRender()
209    */
210   void StopRender() override;
211
212   /**
213    * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
214    */
215   void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) override;
216
217   /**
218    * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
219    */
220   void ReleaseLock() override;
221
222   /**
223    * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
224    */
225   Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
226
227   /**
228    * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
229    */
230   void MakeContextCurrent() override;
231
232   /**
233    * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
234    */
235   Integration::DepthBufferAvailable GetDepthBufferRequired() override;
236
237   /**
238    * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
239    */
240   Integration::StencilBufferAvailable GetStencilBufferRequired() override;
241
242 private:
243   /**
244    * @brief Second stage construction
245    */
246   void Initialize(Any surface);
247
248   /**
249    * Notify output is transformed.
250    */
251   void OutputTransformed();
252
253   /**
254    * @brief Used as the callback for the post render.
255    * It is used both window rotation and supporting Ime window
256    */
257   void ProcessPostRender();
258
259   /**
260    * @brief Used as the callback for the frame rendered / presented.
261    */
262   void ProcessFrameCallback();
263
264   /**
265    * @brief Called when our event file descriptor has been written to.
266    * @param[in] eventBitMask bit mask of events that occured on the file descriptor
267    * @param[in] fileDescriptor The file descriptor
268    */
269   void OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor);
270
271   /**
272    * @brief Set the buffer damage rects.
273    * @param[in] damagedRects List of damaged rects
274    * @param[in] clippingRect The rect to clip rendered scene
275    */
276   void SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
277
278   /**
279    * @brief Swap buffers.
280    * @param[in] damagedRects List of damaged rects
281    */
282   void SwapBuffers(const std::vector<Rect<int>>& damagedRects);
283
284 protected:
285   // Undefined
286   WindowRenderSurface(const WindowRenderSurface&) = delete;
287
288   // Undefined
289   WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
290
291 private:
292   struct FrameCallbackInfo
293   {
294     FrameCallbackInfo(Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd)
295     : callbacks(),
296       fileDescriptorMonitor(),
297       fileDescriptor(fd)
298     {
299       // Transfer owership of the CallbackBase
300       for(auto&& iter : callbackList)
301       {
302         callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
303       }
304     }
305
306     ~FrameCallbackInfo()
307     {
308       // Delete FileDescriptorMonitor before close fd.
309       fileDescriptorMonitor.release();
310       close(fileDescriptor);
311     }
312
313     Dali::Integration::Scene::FrameCallbackContainer callbacks;
314     std::unique_ptr<FileDescriptorMonitor>           fileDescriptorMonitor;
315     int                                              fileDescriptor;
316   };
317
318   using FrameCallbackInfoContainer = std::vector<std::unique_ptr<FrameCallbackInfo>>;
319
320 private: // Data
321   EglInterface*                          mEGL;
322   Dali::DisplayConnection*               mDisplayConnection;
323   PositionSize                           mPositionSize; ///< Position
324   std::unique_ptr<WindowBase>            mWindowBase;
325   ThreadSynchronizationInterface*        mThreadSynchronization;
326   TriggerEventInterface*                 mRenderNotification; ///< Render notification trigger
327   std::unique_ptr<TriggerEventInterface> mPostRenderTrigger;  ///< Post render callback function
328   std::unique_ptr<TriggerEventInterface> mFrameRenderedTrigger;
329   GraphicsInterface*                     mGraphics; ///< Graphics interface
330   EGLSurface                             mEGLSurface;
331   EGLContext                             mEGLContext;
332   ColorDepth                             mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
333   OutputSignalType                       mOutputTransformedSignal;
334   FrameCallbackInfoContainer             mFrameCallbackInfoContainer;
335   DamagedRectsContainer                  mBufferDamagedRects;
336   Dali::Mutex                            mMutex;
337   int                                    mWindowRotationAngle;
338   int                                    mScreenRotationAngle;
339   uint32_t                               mDpiHorizontal;
340   uint32_t                               mDpiVertical;
341   std::vector<Rect<int>>                 mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass
342   bool                                   mOwnSurface;     ///< Whether we own the surface (responsible for deleting it)
343   bool                                   mWindowRotationFinished;
344   bool                                   mScreenRotationFinished;
345   bool                                   mResizeFinished;
346   bool                                   mDefaultScreenRotationAvailable;
347   bool                                   mIsImeWindowSurface;
348   bool                                   mNeedWindowRotationAcknowledgement;
349
350 }; // class WindowRenderSurface
351
352 } // namespace Adaptor
353
354 } // namespace Internal
355
356 } // namespace Dali
357
358 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H