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