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