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