Revert "[Tizen] Apply screen rotation to create window"
[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) 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/public-api/signals/connection-tracker.h>
23 #include <dali/public-api/signals/dali-signal.h>
24 #include <dali/devel-api/threading/mutex.h>
25 #include <dali/integration-api/scene.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
37 class TriggerEventInterface;
38
39 namespace Internal
40 {
41 namespace Adaptor
42 {
43
44 class WindowBase;
45 class AdaptorInternalServices;
46
47 /**
48  * Window interface of render surface.
49  */
50 class WindowRenderSurface : public Dali::RenderSurfaceInterface, public ConnectionTracker
51 {
52 public:
53
54   using OutputSignalType = Signal< void ( ) >;
55   using DamagedRectsContainer = std::list< std::vector< Rect< int > > >;
56
57   /**
58     * Uses an window surface to render to.
59     * @param [in] positionSize the position and size of the surface
60     * @param [in] surface can be a window or pixmap.
61     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
62     */
63   WindowRenderSurface( Dali::PositionSize positionSize, Any surface, bool isTransparent = false );
64
65   /**
66    * @brief Destructor
67    */
68   virtual ~WindowRenderSurface();
69
70 public: // API
71
72   /**
73    * @brief Get the native window handle
74    * @return The native window handle
75    */
76   Any GetNativeWindow();
77
78   /**
79    * @brief Get the native window id
80    * @return The native window id
81    */
82   int GetNativeWindowId();
83
84   /**
85    * @brief Map window
86    */
87   void Map();
88
89   /**
90    * @brief Sets the render notification trigger to call when render thread is completed a frame
91    * @param renderNotification to use
92    */
93   void SetRenderNotification( TriggerEventInterface* renderNotification );
94
95   /**
96    * @brief Sets whether the surface is transparent or not.
97    * @param[in] transparent Whether the surface is transparent
98    */
99   void SetTransparency( bool transparent );
100
101   /**
102    * Request surface rotation
103    * @param[in] angle A new angle of the surface
104    * @param[in] width A new width of the surface
105    * @param[in] height A new height of the surface
106    */
107   void RequestRotation( int angle, int width, int height );
108
109   /**
110    * @brief Gets the window base object
111    * @return The window base object
112    */
113   WindowBase* GetWindowBase();
114
115   /**
116    * @brief This signal is emitted when the output is transformed.
117    */
118   OutputSignalType& OutputTransformedSignal();
119
120 public: // from Dali::RenderSurfaceInterface
121
122   /**
123    * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
124    */
125   PositionSize GetPositionSize() const override;
126
127   /**
128    */
129   void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
130
131   /**
132    * @brief Return the orientation of the surface.
133    * @return The orientation
134    */
135   virtual int GetOrientation() const override;
136
137   /**
138    * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
139    */
140   void InitializeGraphics() override;
141
142   /**
143    * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
144    */
145   void CreateSurface() override;
146
147   /**
148    * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
149    */
150   void DestroySurface() override;
151
152   /**
153    * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
154    */
155   bool ReplaceGraphicsSurface() override;
156
157   /**
158    * @copydoc Dali::RenderSurfaceInterface::MoveResize()
159    */
160   void MoveResize( Dali::PositionSize positionSize) override;
161
162   /**
163    * @copydoc Dali::RenderSurfaceInterface::StartRender()
164    */
165   void StartRender() override;
166
167   /**
168    * @copydoc Dali::RenderSurfaceInterface::PreRender()
169    */
170   bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
171
172   /**
173    * @copydoc Dali::RenderSurfaceInterface::PostRender()
174    */
175   void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
176
177   /**
178    * @copydoc Dali::RenderSurfaceInterface::StopRender()
179    */
180   void StopRender() override;
181
182   /**
183    * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
184    */
185   void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
186
187   /**
188    * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
189    */
190   void ReleaseLock() override;
191
192   /**
193    * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
194    */
195   Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
196
197   /**
198    * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
199    */
200   void MakeContextCurrent() override;
201
202   /**
203    * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
204    */
205   Integration::DepthBufferAvailable GetDepthBufferRequired() override;
206
207   /**
208    * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
209    */
210   Integration::StencilBufferAvailable GetStencilBufferRequired() override;
211
212 private:
213
214   /**
215    * @brief Second stage construction
216    */
217   void Initialize( Any surface );
218
219   /**
220    * Notify output is transformed.
221    */
222   void OutputTransformed();
223
224   /**
225    * @brief Used as the callback for the rotation-trigger.
226    */
227   void ProcessRotationRequest();
228
229   /**
230    * @brief Used as the callback for the frame rendered / presented.
231    */
232   void ProcessFrameCallback();
233
234   /**
235    * @brief Called when our event file descriptor has been written to.
236    * @param[in] eventBitMask bit mask of events that occured on the file descriptor
237    * @param[in] fileDescriptor The file descriptor
238    */
239   void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
240
241   /**
242    * @brief Set the buffer damage rects.
243    * @param[in] damagedRects List of damaged rects
244    * @param[in] clippingRect The rect to clip rendered scene
245    */
246   void SetBufferDamagedRects( const std::vector< Rect< int > >& damagedRects, Rect< int >& clippingRect );
247
248   /**
249    * @brief Swap buffers.
250    * @param[in] damagedRects List of damaged rects
251    */
252   void SwapBuffers( const std::vector<Rect<int>>& damagedRects );
253
254 protected:
255
256   // Undefined
257   WindowRenderSurface(const WindowRenderSurface&) = delete;
258
259   // Undefined
260   WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
261
262 private:
263
264   struct FrameCallbackInfo
265   {
266     FrameCallbackInfo( Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd )
267     : callbacks(),
268       fileDescriptorMonitor(),
269       fileDescriptor( fd )
270     {
271       // Transfer owership of the CallbackBase
272       for( auto&& iter : callbackList )
273       {
274         callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
275       }
276     }
277
278     ~FrameCallbackInfo()
279     {
280       // Delete FileDescriptorMonitor before close fd.
281       fileDescriptorMonitor.release();
282       close( fileDescriptor );
283     }
284
285     Dali::Integration::Scene::FrameCallbackContainer callbacks;
286     std::unique_ptr< FileDescriptorMonitor > fileDescriptorMonitor;
287     int fileDescriptor;
288   };
289
290   using FrameCallbackInfoContainer = std::vector< std::unique_ptr< FrameCallbackInfo > >;
291
292 private: // Data
293
294   EglInterface*                   mEGL;
295   Dali::DisplayConnection*        mDisplayConnection;
296   PositionSize                    mPositionSize;       ///< Position
297   std::unique_ptr< WindowBase >   mWindowBase;
298   ThreadSynchronizationInterface* mThreadSynchronization;
299   TriggerEventInterface*          mRenderNotification; ///< Render notification trigger
300   TriggerEventInterface*          mRotationTrigger;
301   std::unique_ptr< TriggerEventInterface > mFrameRenderedTrigger;
302   GraphicsInterface*              mGraphics;           ///< Graphics interface
303   EGLSurface                      mEGLSurface;
304   EGLContext                      mEGLContext;
305   ColorDepth                      mColorDepth;         ///< Color depth of surface (32 bit or 24 bit)
306   OutputSignalType                mOutputTransformedSignal;
307   FrameCallbackInfoContainer      mFrameCallbackInfoContainer;
308   DamagedRectsContainer           mBufferDamagedRects;
309   Dali::Mutex                     mMutex;
310   int                             mRotationAngle;
311   int                             mScreenRotationAngle;
312   uint32_t                        mDpiHorizontal;
313   uint32_t                        mDpiVertical;
314   bool                            mOwnSurface;         ///< Whether we own the surface (responsible for deleting it)
315   bool                            mRotationSupported;
316   bool                            mRotationFinished;
317   bool                            mScreenRotationFinished;
318   bool                            mResizeFinished;
319
320 }; // class WindowRenderSurface
321
322 } // namespace Adaptor
323
324 } // namespace internal
325
326 } // namespace Dali
327
328 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H