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