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