Revert "[Tizen] Add screen and client rotation itself function"
[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    * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
133    */
134   void InitializeGraphics() override;
135
136   /**
137    * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
138    */
139   void CreateSurface() override;
140
141   /**
142    * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
143    */
144   void DestroySurface() override;
145
146   /**
147    * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
148    */
149   bool ReplaceGraphicsSurface() override;
150
151   /**
152    * @copydoc Dali::RenderSurfaceInterface::MoveResize()
153    */
154   void MoveResize( Dali::PositionSize positionSize) override;
155
156   /**
157    * @copydoc Dali::RenderSurfaceInterface::StartRender()
158    */
159   void StartRender() override;
160
161   /**
162    * @copydoc Dali::RenderSurfaceInterface::PreRender()
163    */
164   bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
165
166   /**
167    * @copydoc Dali::RenderSurfaceInterface::PostRender()
168    */
169   void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
170
171   /**
172    * @copydoc Dali::RenderSurfaceInterface::StopRender()
173    */
174   void StopRender() override;
175
176   /**
177    * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
178    */
179   void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
180
181   /**
182    * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
183    */
184   void ReleaseLock() override;
185
186   /**
187    * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
188    */
189   Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
190
191   /**
192    * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
193    */
194   void MakeContextCurrent() override;
195
196   /**
197    * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
198    */
199   Integration::DepthBufferAvailable GetDepthBufferRequired() override;
200
201   /**
202    * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
203    */
204   Integration::StencilBufferAvailable GetStencilBufferRequired() override;
205
206 private:
207
208   /**
209    * @brief Second stage construction
210    */
211   void Initialize( Any surface );
212
213   /**
214    * Notify output is transformed.
215    */
216   void OutputTransformed();
217
218   /**
219    * @brief Used as the callback for the rotation-trigger.
220    */
221   void ProcessRotationRequest();
222
223   /**
224    * @brief Used as the callback for the frame rendered / presented.
225    */
226   void ProcessFrameCallback();
227
228   /**
229    * @brief Called when our event file descriptor has been written to.
230    * @param[in] eventBitMask bit mask of events that occured on the file descriptor
231    * @param[in] fileDescriptor The file descriptor
232    */
233   void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
234
235   /**
236    * @brief Set the buffer damage rects.
237    * @param[in] damagedRects List of damaged rects
238    * @param[in] clippingRect The rect to clip rendered scene
239    */
240   void SetBufferDamagedRects( const std::vector< Rect< int > >& damagedRects, Rect< int >& clippingRect );
241
242   /**
243    * @brief Swap buffers.
244    * @param[in] damagedRects List of damaged rects
245    */
246   void SwapBuffers( const std::vector<Rect<int>>& damagedRects );
247
248 protected:
249
250   // Undefined
251   WindowRenderSurface(const WindowRenderSurface&) = delete;
252
253   // Undefined
254   WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
255
256 private:
257
258   struct FrameCallbackInfo
259   {
260     FrameCallbackInfo( Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd )
261     : callbacks(),
262       fileDescriptorMonitor(),
263       fileDescriptor( fd )
264     {
265       // Transfer owership of the CallbackBase
266       for( auto&& iter : callbackList )
267       {
268         callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
269       }
270     }
271
272     ~FrameCallbackInfo()
273     {
274       // Delete FileDescriptorMonitor before close fd.
275       fileDescriptorMonitor.release();
276       close( fileDescriptor );
277     }
278
279     Dali::Integration::Scene::FrameCallbackContainer callbacks;
280     std::unique_ptr< FileDescriptorMonitor > fileDescriptorMonitor;
281     int fileDescriptor;
282   };
283
284   using FrameCallbackInfoContainer = std::vector< std::unique_ptr< FrameCallbackInfo > >;
285
286 private: // Data
287
288   EglInterface*                   mEGL;
289   Dali::DisplayConnection*        mDisplayConnection;
290   PositionSize                    mPositionSize;       ///< Position
291   std::unique_ptr< WindowBase >   mWindowBase;
292   ThreadSynchronizationInterface* mThreadSynchronization;
293   TriggerEventInterface*          mRenderNotification; ///< Render notification trigger
294   TriggerEventInterface*          mRotationTrigger;
295   std::unique_ptr< TriggerEventInterface > mFrameRenderedTrigger;
296   GraphicsInterface*              mGraphics;           ///< Graphics interface
297   EGLSurface                      mEGLSurface;
298   EGLContext                      mEGLContext;
299   ColorDepth                      mColorDepth;         ///< Color depth of surface (32 bit or 24 bit)
300   OutputSignalType                mOutputTransformedSignal;
301   FrameCallbackInfoContainer      mFrameCallbackInfoContainer;
302   DamagedRectsContainer           mBufferDamagedRects;
303   Dali::Mutex                     mMutex;
304   int                             mRotationAngle;
305   int                             mScreenRotationAngle;
306   uint32_t                        mDpiHorizontal;
307   uint32_t                        mDpiVertical;
308   bool                            mOwnSurface;         ///< Whether we own the surface (responsible for deleting it)
309   bool                            mRotationSupported;
310   bool                            mRotationFinished;
311   bool                            mScreenRotationFinished;
312   bool                            mResizeFinished;
313
314 }; // class WindowRenderSurface
315
316 } // namespace Adaptor
317
318 } // namespace internal
319
320 } // namespace Dali
321
322 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H