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