a683a595a618d070244b8601e688c5407467ce22
[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/math/vector4.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/object/any.h>
26
27 namespace Dali
28 {
29
30 class DisplayConnection;
31 class ThreadSynchronizationInterface;
32
33 namespace Internal
34 {
35 namespace Adaptor
36 {
37 class AdaptorInternalServices;
38 class GraphicsInterface;
39 }
40 }
41
42 /**
43  * @brief The position and size of the render surface.
44  */
45 typedef Dali::Rect<int> PositionSize;
46
47 /**
48  * @brief Interface for a render surface onto which Dali draws.
49  *
50  * Dali::Adaptor requires a render surface to draw on to. This is
51  * usually a window in the native windowing system, or some other
52  * mapped pixel buffer.
53  *
54  * Dali::Application will automatically create a render surface using a window.
55  *
56  * The implementation of the factory method below should choose an appropriate
57  * implementation of RenderSurface for the given platform
58  */
59
60 class RenderSurfaceInterface
61 {
62 public:
63
64   enum Type
65   {
66     WINDOW_RENDER_SURFACE,
67     PIXMAP_RENDER_SURFACE,
68     NATIVE_RENDER_SURFACE
69   };
70
71   /**
72    * @brief Constructor
73    * Inlined as this is a pure abstract interface
74    */
75   RenderSurfaceInterface()
76   : mAdaptor( nullptr ),
77     mGraphics( nullptr ),
78     mDisplayConnection( nullptr ),
79     mDepthBufferRequired( Integration::DepthBufferAvailable::FALSE ),
80     mStencilBufferRequired( Integration::StencilBufferAvailable::FALSE )
81   {}
82
83   /**
84    * @brief Virtual Destructor.
85    * Inlined as this is a pure abstract interface
86    */
87   virtual ~RenderSurfaceInterface() {}
88
89   /**
90    * @brief Return the size and position of the surface.
91    * @return The position and size
92    */
93   virtual Dali::PositionSize GetPositionSize() const = 0;
94
95   /**
96    * @brief Get DPI
97    * @param[out] dpiHorizontal set to the horizontal dpi
98    * @param[out] dpiVertical set to the vertical dpi
99    */
100   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) = 0;
101
102   /**
103    * @brief Return the orientation of the surface.
104    * @return The orientation
105    */
106   virtual int GetOrientation() const = 0;
107
108   /**
109    * @brief InitializeGraphics the platform specific graphics surface interfaces
110    */
111   virtual void InitializeGraphics() = 0;
112
113   /**
114    * @brief Creates the Surface
115    */
116   virtual void CreateSurface() = 0;
117
118   /**
119    * @brief Destroys the Surface
120    */
121   virtual void DestroySurface() = 0;
122
123   /**
124    * @brief Replace the Surface
125    * @return true if context was lost
126    */
127   virtual bool ReplaceGraphicsSurface() = 0;
128
129   /**
130    * @brief Resizes the underlying surface.
131    * @param[in] The dimensions of the new position
132    */
133   virtual void MoveResize( Dali::PositionSize positionSize ) = 0;
134
135   /**
136    * @brief Called when Render thread has started
137    */
138   virtual void StartRender() = 0;
139
140   /**
141    * @brief Invoked by render thread before Core::Render
142    * If the operation fails, then Core::Render should not be called until there is
143    * a surface to render onto.
144    * @param[in] resizingSurface True if the surface is being resized
145    * @return True if the operation is successful, False if the operation failed
146    */
147   virtual bool PreRender( bool resizingSurface ) = 0;
148
149   /**
150    * @brief Invoked by render thread after Core::Render
151    * @param[in] renderToFbo True if render to FBO.
152    * @param[in] replacingSurface True if the surface is being replaced.
153    * @param[in] resizingSurface True if the surface is being resized.
154    */
155   virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface ) = 0;
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 private:
213
214   /**
215    * @brief Undefined copy constructor. RenderSurface cannot be copied
216    */
217   RenderSurfaceInterface( const RenderSurfaceInterface& rhs );
218
219   /**
220    * @brief Undefined assignment operator. RenderSurface cannot be copied
221    */
222   RenderSurfaceInterface& operator=( const RenderSurfaceInterface& rhs );
223
224 protected:
225
226   Dali::Internal::Adaptor::AdaptorInternalServices* mAdaptor;
227   Dali::Internal::Adaptor::GraphicsInterface* mGraphics;
228   Dali::DisplayConnection* mDisplayConnection;
229
230 private:
231
232   Integration::DepthBufferAvailable mDepthBufferRequired;       ///< Whether the depth buffer is required
233   Integration::StencilBufferAvailable mStencilBufferRequired;   ///< Whether the stencil buffer is required
234
235   Vector4 mBackgroundColor;                                     ///< The background color of the surface
236 };
237
238 } // namespace Dali
239
240 #endif // DALI_RENDER_SURFACE_INTERFACE_H