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