[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] width A new width of the surface
101    * @param[in] height A new height of the surface
102    */
103   void RequestRotation(int angle, int width, int height);
104
105   /**
106    * @brief Gets the window base object
107    * @return The window base object
108    */
109   WindowBase* GetWindowBase();
110
111   /**
112    * @brief Intiailize Ime Surface for Ime window rendering.
113    *
114    * It sets one flag and callback function for Ime window rendering
115    * This callback function calls one special native window function for ready to commit buffer.
116    * The special function notify to display server.
117    * It is only used for Ime window.
118    */
119   void InitializeImeSurface();
120
121   /**
122    * @brief Sets the necessary for window rotation acknowledge.
123    * After this function called, SendRotationCompletedAcknowledgement() should be called to complete window rotation.
124    *
125    * More detail description is written in DevelWindow::SetNeedsRotationCompletedAcknowledgement().
126    *
127    * @param[in] window The window instance.
128    * @param[in] needAcknowledgement the flag is true if window rotation acknowledgement is sent.
129    */
130   void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
131
132   /**
133    * @brief Query whether window is rotating or not.
134    *
135    * @return true if window is rotating, false otherwise.
136    */
137   bool IsWindowRotating() const;
138
139   /**
140    * @brief This signal is emitted when the output is transformed.
141    */
142   OutputSignalType& OutputTransformedSignal();
143
144 public: // from Dali::RenderSurfaceInterface
145   /**
146    * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
147    */
148   PositionSize GetPositionSize() const override;
149
150   /**
151    */
152   void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
153
154   /**
155    * @copydoc Dali::RenderSurfaceInterface::GetOrientation()
156    */
157   int GetOrientation() const override;
158
159   /**
160    * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
161    */
162   void InitializeGraphics() override;
163
164   /**
165    * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
166    */
167   void CreateSurface() override;
168
169   /**
170    * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
171    */
172   void DestroySurface() override;
173
174   /**
175    * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
176    */
177   bool ReplaceGraphicsSurface() override;
178
179   /**
180    * @copydoc Dali::RenderSurfaceInterface::MoveResize()
181    */
182   void MoveResize(Dali::PositionSize positionSize) override;
183
184   /**
185    * @copydoc Dali::RenderSurfaceInterface::StartRender()
186    */
187   void StartRender() override;
188
189   /**
190    * @copydoc Dali::RenderSurfaceInterface::PreRender()
191    */
192   bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) override;
193
194   /**
195    * @copydoc Dali::RenderSurfaceInterface::PostRender()
196    */
197   void PostRender() override;
198
199   /**
200    * @copydoc Dali::RenderSurfaceInterface::StopRender()
201    */
202   void StopRender() override;
203
204   /**
205    * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
206    */
207   void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) override;
208
209   /**
210    * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
211    */
212   void ReleaseLock() override;
213
214   /**
215    * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
216    */
217   Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
218
219   /**
220    * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
221    */
222   void MakeContextCurrent() override;
223
224   /**
225    * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
226    */
227   Integration::DepthBufferAvailable GetDepthBufferRequired() override;
228
229   /**
230    * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
231    */
232   Integration::StencilBufferAvailable GetStencilBufferRequired() override;
233
234 private:
235   /**
236    * @brief Second stage construction
237    */
238   void Initialize(Any surface);
239
240   /**
241    * Notify output is transformed.
242    */
243   void OutputTransformed();
244
245   /**
246    * @brief Used as the callback for the post render.
247    * It is used both window rotation and supporting Ime window
248    */
249   void ProcessPostRender();
250
251   /**
252    * @brief Used as the callback for the frame rendered / presented.
253    */
254   void ProcessFrameCallback();
255
256   /**
257    * @brief Called when our event file descriptor has been written to.
258    * @param[in] eventBitMask bit mask of events that occured on the file descriptor
259    * @param[in] fileDescriptor The file descriptor
260    */
261   void OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor);
262
263   /**
264    * @brief Set the buffer damage rects.
265    * @param[in] damagedRects List of damaged rects
266    * @param[in] clippingRect The rect to clip rendered scene
267    */
268   void SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
269
270   /**
271    * @brief Swap buffers.
272    * @param[in] damagedRects List of damaged rects
273    */
274   void SwapBuffers(const std::vector<Rect<int>>& damagedRects);
275
276 protected:
277   // Undefined
278   WindowRenderSurface(const WindowRenderSurface&) = delete;
279
280   // Undefined
281   WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
282
283 private:
284   struct FrameCallbackInfo
285   {
286     FrameCallbackInfo(Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd)
287     : callbacks(),
288       fileDescriptorMonitor(),
289       fileDescriptor(fd)
290     {
291       // Transfer owership of the CallbackBase
292       for(auto&& iter : callbackList)
293       {
294         callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
295       }
296     }
297
298     ~FrameCallbackInfo()
299     {
300       // Delete FileDescriptorMonitor before close fd.
301       fileDescriptorMonitor.release();
302       close(fileDescriptor);
303     }
304
305     Dali::Integration::Scene::FrameCallbackContainer callbacks;
306     std::unique_ptr<FileDescriptorMonitor>           fileDescriptorMonitor;
307     int                                              fileDescriptor;
308   };
309
310   using FrameCallbackInfoContainer = std::vector<std::unique_ptr<FrameCallbackInfo>>;
311
312 private: // Data
313   EglInterface*                          mEGL;
314   Dali::DisplayConnection*               mDisplayConnection;
315   PositionSize                           mPositionSize; ///< Position
316   std::unique_ptr<WindowBase>            mWindowBase;
317   ThreadSynchronizationInterface*        mThreadSynchronization;
318   TriggerEventInterface*                 mRenderNotification; ///< Render notification trigger
319   std::unique_ptr<TriggerEventInterface> mPostRenderTrigger;  ///< Post render callback function
320   std::unique_ptr<TriggerEventInterface> mFrameRenderedTrigger;
321   GraphicsInterface*                     mGraphics; ///< Graphics interface
322   EGLSurface                             mEGLSurface;
323   EGLContext                             mEGLContext;
324   ColorDepth                             mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
325   OutputSignalType                       mOutputTransformedSignal;
326   FrameCallbackInfoContainer             mFrameCallbackInfoContainer;
327   DamagedRectsContainer                  mBufferDamagedRects;
328   Dali::Mutex                            mMutex;
329   int                                    mWindowRotationAngle;
330   int                                    mScreenRotationAngle;
331   uint32_t                               mDpiHorizontal;
332   uint32_t                               mDpiVertical;
333   std::vector<Rect<int>>                 mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass
334   bool                                   mOwnSurface;     ///< Whether we own the surface (responsible for deleting it)
335   bool                                   mWindowRotationFinished;
336   bool                                   mScreenRotationFinished;
337   bool                                   mResizeFinished;
338   bool                                   mDefaultScreenRotationAvailable;
339   bool                                   mIsImeWindowSurface;
340   bool                                   mNeedWindowRotationAcknowledgement;
341
342 }; // class WindowRenderSurface
343
344 } // namespace Adaptor
345
346 } // namespace Internal
347
348 } // namespace Dali
349
350 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H