[Tizen] Modify parameters of CreateNativeSurface()
[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/math/uint-16-pair.h>
28
29 namespace Dali
30 {
31
32 class DisplayConnection;
33 class ThreadSynchronizationInterface;
34
35 namespace Internal
36 {
37 namespace Adaptor
38 {
39 class AdaptorInternalServices;
40 class GraphicsInterface;
41 }
42 }
43
44 /**
45  * @brief The position and size of the render surface.
46  */
47 typedef Dali::Rect<int> PositionSize;
48 typedef Uint16Pair SurfaceSize;
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     mDepthBufferRequired( Integration::DepthBufferAvailable::FALSE ),
83     mStencilBufferRequired( Integration::StencilBufferAvailable::FALSE )
84   {}
85
86   /**
87    * @brief Virtual Destructor.
88    * Inlined as this is a pure abstract interface
89    */
90   virtual ~RenderSurfaceInterface() {}
91
92   /**
93    * @brief Return the size and position of the surface.
94    * @return The position and size
95    */
96   virtual Dali::PositionSize GetPositionSize() const = 0;
97
98   /**
99    * @brief Get DPI
100    * @param[out] dpiHorizontal set to the horizontal dpi
101    * @param[out] dpiVertical set to the vertical dpi
102    */
103   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) = 0;
104
105   /**
106    * @brief Return the orientation of the surface.
107    * @return The orientation
108    */
109   virtual int GetOrientation() const = 0;
110
111   /**
112    * @brief InitializeGraphics the platform specific graphics surface interfaces
113    */
114   virtual void InitializeGraphics() = 0;
115
116   /**
117    * @brief Creates the Surface
118    */
119   virtual void CreateSurface() = 0;
120
121   /**
122    * @brief Destroys the Surface
123    */
124   virtual void DestroySurface() = 0;
125
126   /**
127    * @brief Replace the Surface
128    * @return true if context was lost
129    */
130   virtual bool ReplaceGraphicsSurface() = 0;
131
132   /**
133    * @brief Resizes the underlying surface.
134    * @param[in] The dimensions of the new position
135    */
136   virtual void MoveResize( Dali::PositionSize positionSize ) = 0;
137
138   /**
139    * @brief Called when Render thread has started
140    */
141   virtual void StartRender() = 0;
142
143   /**
144    * @brief Invoked by render thread before Core::Render
145    * If the operation fails, then Core::Render should not be called until there is
146    * a surface to render onto.
147    * @param[in] resizingSurface True if the surface is being resized
148    * @param[in] damagedRects List of damaged rects this render pass
149    * @return True if the operation is successful, False if the operation failed
150    */
151   virtual bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) = 0;
152
153   /**
154    * @brief Invoked by render thread after Core::Render
155    * @param[in] renderToFbo True if render to FBO.
156    * @param[in] replacingSurface True if the surface is being replaced.
157    * @param[in] resizingSurface True if the surface is being resized.
158    */
159   virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) = 0;
160
161   /**
162    * @brief Invoked by render thread when the thread should be stop
163    */
164   virtual void StopRender() = 0;
165
166   /**
167    * @brief Invoked by Event Thread when the compositor lock should be released and rendering should resume.
168    */
169   virtual void ReleaseLock() = 0;
170
171   /**
172    * @brief Sets the ThreadSynchronizationInterface
173    *
174    * @param threadSynchronization The thread-synchronization implementation.
175    */
176   virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) = 0;
177
178   /**
179    * @brief Gets the surface type
180    */
181   virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() = 0;
182
183   /**
184    * @brief Makes the graphics context current
185    */
186   virtual void MakeContextCurrent() = 0;
187
188   /**
189    * @brief Get whether the depth buffer is required
190    * @return TRUE if the depth buffer is required
191    */
192   virtual Integration::DepthBufferAvailable GetDepthBufferRequired() = 0;
193
194   /**
195    * @brief Get whether the stencil buffer is required
196    * @return TRUE if the stencil buffer is required
197    */
198   virtual Integration::StencilBufferAvailable GetStencilBufferRequired() = 0;
199
200 public:
201
202   void SetAdaptor( Dali::Internal::Adaptor::AdaptorInternalServices& adaptor )
203   {
204     mAdaptor = &adaptor;
205   }
206
207   void SetGraphicsInterface( Dali::Internal::Adaptor::GraphicsInterface& graphics )
208   {
209     mGraphics = &graphics;
210   }
211
212   void SetDisplayConnection( Dali::DisplayConnection& displayConnection )
213   {
214     mDisplayConnection = &displayConnection;
215   }
216
217 private:
218
219   /**
220    * @brief Undefined copy constructor. RenderSurface cannot be copied
221    */
222   RenderSurfaceInterface( const RenderSurfaceInterface& rhs );
223
224   /**
225    * @brief Undefined assignment operator. RenderSurface cannot be copied
226    */
227   RenderSurfaceInterface& operator=( const RenderSurfaceInterface& rhs );
228
229 protected:
230
231   Dali::Internal::Adaptor::AdaptorInternalServices* mAdaptor;
232   Dali::Internal::Adaptor::GraphicsInterface* mGraphics;
233   Dali::DisplayConnection* mDisplayConnection;
234
235 private:
236
237   Integration::DepthBufferAvailable mDepthBufferRequired;       ///< Whether the depth buffer is required
238   Integration::StencilBufferAvailable mStencilBufferRequired;   ///< Whether the stencil buffer is required
239
240   Vector4 mBackgroundColor;                                     ///< The background color of the surface
241 };
242
243 } // namespace Dali
244
245 #endif // DALI_RENDER_SURFACE_INTERFACE_H