WindowRenderSurface and EventHandler refactoring
[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) 2018 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 // INTERNAL INCLUDES
22 #include <dali/integration-api/render-surface.h>
23 #include <dali/integration-api/egl-interface.h>
24
25 // EXTERNAL INCLUDES
26 #include <dali/public-api/signals/connection-tracker.h>
27 #include <memory>
28
29 namespace Dali
30 {
31
32 class TriggerEventInterface;
33
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38
39 class WindowBase;
40
41 /**
42  * Window interface of render surface.
43  */
44 class WindowRenderSurface : public Dali::RenderSurface, public ConnectionTracker
45 {
46 public:
47
48   /**
49     * Uses an window surface to render to.
50     * @param [in] positionSize the position and size of the surface
51     * @param [in] surface can be a window or pixmap.
52     * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
53     */
54   WindowRenderSurface( Dali::PositionSize positionSize, Any surface, bool isTransparent = false );
55
56   /**
57    * @brief Destructor
58    */
59   virtual ~WindowRenderSurface();
60
61 public: // API
62
63   /**
64    * @brief Get the native window handle
65    * @return The native window handle
66    */
67   Any GetNativeWindow();
68
69   /**
70    * @brief Get the native window id
71    * @return The native window id
72    */
73   int GetNativeWindowId();
74
75   /**
76    * @brief Map window
77    */
78   void Map();
79
80   /**
81    * @brief Sets the render notification trigger to call when render thread is completed a frame
82    * @param renderNotification to use
83    */
84   void SetRenderNotification( TriggerEventInterface* renderNotification );
85
86   /**
87    * @brief Sets whether the surface is transparent or not.
88    * @param[in] transparent Whether the surface is transparent
89    */
90   void SetTransparency( bool transparent );
91
92   /**
93    * Request surface rotation
94    * @param[in] angle A new angle of the surface
95    * @param[in] width A new width of the surface
96    * @param[in] height A new height of the surface
97    */
98   void RequestRotation( int angle, int width, int height );
99
100   /**
101    * @brief Gets the window base object
102    * @return The window base object
103    */
104   WindowBase* GetWindowBase();
105
106 public: // from Dali::RenderSurface
107
108   /**
109    * @copydoc Dali::RenderSurface::GetPositionSize()
110    */
111   virtual PositionSize GetPositionSize() const override;
112
113   /**
114    * @copydoc Dali::RenderSurface::GetDpi()
115    */
116   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
117
118   /**
119    * @copydoc Dali::RenderSurface::InitializeEgl()
120    */
121   virtual void InitializeEgl( EglInterface& egl ) override;
122
123   /**
124    * @copydoc Dali::RenderSurface::CreateEglSurface()
125    */
126   virtual void CreateEglSurface( EglInterface& egl ) override;
127
128   /**
129    * @copydoc Dali::RenderSurface::DestroyEglSurface()
130    */
131   virtual void DestroyEglSurface( EglInterface& egl ) override;
132
133   /**
134    * @copydoc Dali::RenderSurface::ReplaceEGLSurface()
135    */
136   virtual bool ReplaceEGLSurface( EglInterface& egl ) override;
137
138   /**
139    * @copydoc Dali::RenderSurface::MoveResize()
140    */
141   virtual void MoveResize( Dali::PositionSize positionSize) override;
142
143   /**
144    * @copydoc Dali::RenderSurface::SetViewMode()
145    */
146   virtual void SetViewMode( ViewMode viewMode ) override;
147
148   /**
149    * @copydoc Dali::RenderSurface::StartRender()
150    */
151   virtual void StartRender() override;
152
153   /**
154    * @copydoc Dali::RenderSurface::PreRender()
155    */
156   virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, bool resizingSurface ) override;
157
158   /**
159    * @copydoc Dali::RenderSurface::PostRender()
160    */
161   virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, Dali::DisplayConnection* displayConnection, bool replacingSurface, bool resizingSurface ) override;
162
163   /**
164    * @copydoc Dali::RenderSurface::StopRender()
165    */
166   virtual void StopRender() override;
167
168   /**
169    * @copydoc Dali::RenderSurface::SetThreadSynchronization
170    */
171   virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
172
173   /**
174    * @copydoc Dali::RenderSurface::ReleaseLock()
175    */
176   virtual void ReleaseLock() override;
177
178   /**
179    * @copydoc Dali::RenderSurface::GetSurfaceType()
180    */
181   virtual RenderSurface::Type GetSurfaceType() override;
182
183 private:
184
185   /**
186    * @brief Second stage construction
187    */
188   void Initialize( Any surface );
189
190   /**
191    * Notify output is transformed.
192    */
193   void OutputTransformed();
194
195   /**
196    * @brief Used as the callback for the rotation-trigger.
197    */
198   void ProcessRotationRequest();
199
200 protected:
201
202   // Undefined
203   WindowRenderSurface(const WindowRenderSurface&) = delete;
204
205   // Undefined
206   WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
207
208 private: // Data
209
210   PositionSize                    mPositionSize;       ///< Position
211   std::unique_ptr< WindowBase >   mWindowBase;
212   ThreadSynchronizationInterface* mThreadSynchronization;
213   TriggerEventInterface*          mRenderNotification; ///< Render notification trigger
214   TriggerEventInterface*          mRotationTrigger;
215   ColorDepth                      mColorDepth;         ///< Color depth of surface (32 bit or 24 bit)
216   int                             mRotationAngle;
217   int                             mScreenRotationAngle;
218   bool                            mOwnSurface;         ///< Whether we own the surface (responsible for deleting it)
219   bool                            mRotationSupported;
220   bool                            mRotationFinished;
221   bool                            mScreenRotationFinished;
222   bool                            mResizeFinished;
223
224 }; // class WindowRenderSurface
225
226 } // namespace Adaptor
227
228 } // namespace internal
229
230 } // namespace Dali
231
232 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H