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