Revert "[Tizen] Add screen and client rotation itself function"
[platform/core/uifw/dali-adaptor.git] / dali / integration-api / adaptor-framework / render-surface-interface.h
1 #ifndef DALI_RENDER_SURFACE_INTERFACE_H
2 #define DALI_RENDER_SURFACE_INTERFACE_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/integration-api/core-enumerations.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/math/rect.h>
26 #include <dali/public-api/object/any.h>
27 #include <dali/public-api/object/weak-handle.h>
28 #include <dali/integration-api/scene.h>
29
30 namespace Dali
31 {
32
33 class DisplayConnection;
34 class ThreadSynchronizationInterface;
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40 class AdaptorInternalServices;
41 class GraphicsInterface;
42 }
43 }
44
45 /**
46  * @brief The position and size of the render surface.
47  */
48 typedef Dali::Rect<int> PositionSize;
49
50 /**
51  * @brief Interface for a render surface onto which Dali draws.
52  *
53  * Dali::Adaptor requires a render surface to draw on to. This is
54  * usually a window in the native windowing system, or some other
55  * mapped pixel buffer.
56  *
57  * Dali::Application will automatically create a render surface using a window.
58  *
59  * The implementation of the factory method below should choose an appropriate
60  * implementation of RenderSurface for the given platform
61  */
62
63 class RenderSurfaceInterface
64 {
65 public:
66
67   enum Type
68   {
69     WINDOW_RENDER_SURFACE,
70     PIXMAP_RENDER_SURFACE,
71     NATIVE_RENDER_SURFACE
72   };
73
74   /**
75    * @brief Constructor
76    * Inlined as this is a pure abstract interface
77    */
78   RenderSurfaceInterface()
79   : mAdaptor( nullptr ),
80     mGraphics( nullptr ),
81     mDisplayConnection( nullptr ),
82     mScene(),
83     mDepthBufferRequired( Integration::DepthBufferAvailable::FALSE ),
84     mStencilBufferRequired( Integration::StencilBufferAvailable::FALSE )
85   {}
86
87   /**
88    * @brief Virtual Destructor.
89    * Inlined as this is a pure abstract interface
90    */
91   virtual ~RenderSurfaceInterface() {}
92
93   /**
94    * @brief Return the size and position of the surface.
95    * @return The position and size
96    */
97   virtual Dali::PositionSize GetPositionSize() const = 0;
98
99   /**
100    * @brief Get DPI
101    * @param[out] dpiHorizontal set to the horizontal dpi
102    * @param[out] dpiVertical set to the vertical dpi
103    */
104   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) = 0;
105
106   /**
107    * @brief InitializeGraphics the platform specific graphics surface interfaces
108    */
109   virtual void InitializeGraphics() = 0;
110
111   /**
112    * @brief Creates the Surface
113    */
114   virtual void CreateSurface() = 0;
115
116   /**
117    * @brief Destroys the Surface
118    */
119   virtual void DestroySurface() = 0;
120
121   /**
122    * @brief Replace the Surface
123    * @return true if context was lost
124    */
125   virtual bool ReplaceGraphicsSurface() = 0;
126
127   /**
128    * @brief Resizes the underlying surface.
129    * @param[in] The dimensions of the new position
130    */
131   virtual void MoveResize( Dali::PositionSize positionSize ) = 0;
132
133   /**
134    * @brief Called when Render thread has started
135    */
136   virtual void StartRender() = 0;
137
138   /**
139    * @brief Invoked by render thread before Core::Render
140    * If the operation fails, then Core::Render should not be called until there is
141    * a surface to render onto.
142    * @param[in] resizingSurface True if the surface is being resized
143    * @param[in] damagedRects List of damaged rects this render pass
144    * @return True if the operation is successful, False if the operation failed
145    */
146   virtual bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) = 0;
147
148   /**
149    * @brief Invoked by render thread after Core::Render
150    * @param[in] renderToFbo True if render to FBO.
151    * @param[in] replacingSurface True if the surface is being replaced.
152    * @param[in] resizingSurface True if the surface is being resized.
153    */
154   virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) = 0;
155
156   /**
157    * @brief Invoked by render thread when the thread should be stop
158    */
159   virtual void StopRender() = 0;
160
161   /**
162    * @brief Invoked by Event Thread when the compositor lock should be released and rendering should resume.
163    */
164   virtual void ReleaseLock() = 0;
165
166   /**
167    * @brief Sets the ThreadSynchronizationInterface
168    *
169    * @param threadSynchronization The thread-synchronization implementation.
170    */
171   virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) = 0;
172
173   /**
174    * @brief Gets the surface type
175    */
176   virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() = 0;
177
178   /**
179    * @brief Makes the graphics context current
180    */
181   virtual void MakeContextCurrent() = 0;
182
183   /**
184    * @brief Get whether the depth buffer is required
185    * @return TRUE if the depth buffer is required
186    */
187   virtual Integration::DepthBufferAvailable GetDepthBufferRequired() = 0;
188
189   /**
190    * @brief Get whether the stencil buffer is required
191    * @return TRUE if the stencil buffer is required
192    */
193   virtual Integration::StencilBufferAvailable GetStencilBufferRequired() = 0;
194
195 public:
196
197   void SetAdaptor( Dali::Internal::Adaptor::AdaptorInternalServices& adaptor )
198   {
199     mAdaptor = &adaptor;
200   }
201
202   void SetGraphicsInterface( Dali::Internal::Adaptor::GraphicsInterface& graphics )
203   {
204     mGraphics = &graphics;
205   }
206
207   void SetDisplayConnection( Dali::DisplayConnection& displayConnection )
208   {
209     mDisplayConnection = &displayConnection;
210   }
211
212   /**
213    * @brief Sets a Scene that is rendered on this surface.
214    * @param scene The Scene object
215    */
216   void SetScene( Dali::Integration::Scene& scene )
217   {
218     mScene = scene;
219   }
220
221 private:
222
223   /**
224    * @brief Undefined copy constructor. RenderSurface cannot be copied
225    */
226   RenderSurfaceInterface( const RenderSurfaceInterface& rhs );
227
228   /**
229    * @brief Undefined assignment operator. RenderSurface cannot be copied
230    */
231   RenderSurfaceInterface& operator=( const RenderSurfaceInterface& rhs );
232
233 protected:
234
235   Dali::Internal::Adaptor::AdaptorInternalServices* mAdaptor;
236   Dali::Internal::Adaptor::GraphicsInterface* mGraphics;
237   Dali::DisplayConnection* mDisplayConnection;
238   WeakHandle< Dali::Integration::Scene > mScene;
239
240 private:
241
242   Integration::DepthBufferAvailable mDepthBufferRequired;       ///< Whether the depth buffer is required
243   Integration::StencilBufferAvailable mStencilBufferRequired;   ///< Whether the stencil buffer is required
244
245   Vector4 mBackgroundColor;                                     ///< The background color of the surface
246 };
247
248 } // namespace Dali
249
250 #endif // DALI_RENDER_SURFACE_INTERFACE_H