[Tizen] Implement partial update
[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   {}
71
72   /**
73    * @brief Virtual Destructor.
74    * Inlined as this is a pure abstract interface
75    */
76   virtual ~RenderSurfaceInterface() {}
77
78   /**
79    * @brief Return the size and position of the surface.
80    * @return The position and size
81    */
82   virtual Dali::PositionSize GetPositionSize() const = 0;
83
84   /**
85    * @brief Get DPI
86    * @param[out] dpiHorizontal set to the horizontal dpi
87    * @param[out] dpiVertical set to the vertical dpi
88    */
89   virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) = 0;
90
91   /**
92    * @brief Return the orientation of the surface.
93    * @return The orientation
94    */
95   virtual int GetOrientation() const = 0;
96
97   /**
98    * @brief InitializeGraphics the platform specific graphics surface interfaces
99    */
100   virtual void InitializeGraphics() = 0;
101
102   /**
103    * @brief Creates the Surface
104    */
105   virtual void CreateSurface() = 0;
106
107   /**
108    * @brief Destroys the Surface
109    */
110   virtual void DestroySurface() = 0;
111
112   /**
113    * @brief Replace the Surface
114    * @return true if context was lost
115    */
116   virtual bool ReplaceGraphicsSurface() = 0;
117
118   /**
119    * @brief Resizes the underlying surface.
120    * @param[in] The dimensions of the new position
121    */
122   virtual void MoveResize( Dali::PositionSize positionSize ) = 0;
123
124   /**
125    * @brief Called when Render thread has started
126    */
127   virtual void StartRender() = 0;
128
129   /**
130    * @brief Invoked by render thread before Core::Render
131    * If the operation fails, then Core::Render should not be called until there is
132    * a surface to render onto.
133    * @param[in] resizingSurface True if the surface is being resized
134    * @return True if the operation is successful, False if the operation failed
135    */
136   virtual bool PreRender( bool resizingSurface ) = 0;
137
138   /**
139    * @brief Invoked by render thread after Core::Render
140    * @param[in] renderToFbo True if render to FBO.
141    * @param[in] replacingSurface True if the surface is being replaced.
142    * @param[in] resizingSurface True if the surface is being resized.
143    */
144   virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface ) = 0;
145   /**
146    * @brief Invoked by render thread when the thread should be stop
147    */
148   virtual void StopRender() = 0;
149
150   /**
151    * @brief Invoked by Event Thread when the compositor lock should be released and rendering should resume.
152    */
153   virtual void ReleaseLock() = 0;
154
155   /**
156    * @brief Sets the ThreadSynchronizationInterface
157    *
158    * @param threadSynchronization The thread-synchronization implementation.
159    */
160   virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) = 0;
161
162   /**
163    * @brief Gets the surface type
164    */
165   virtual Dali::Integration::RenderSurface::Type GetSurfaceType() = 0;
166
167   /**
168    * @brief Makes the graphics context current
169    */
170   virtual void MakeContextCurrent() = 0;
171
172   /**
173    * @brief Get whether the depth buffer is required
174    * @return TRUE if the depth buffer is required
175    */
176   virtual Integration::DepthBufferAvailable GetDepthBufferRequired() = 0;
177
178   /**
179    * @brief Get whether the stencil buffer is required
180    * @return TRUE if the stencil buffer is required
181    */
182   virtual Integration::StencilBufferAvailable GetStencilBufferRequired() = 0;
183
184   /**
185    * @brief Sets currentframe updated/damaged rects
186    */
187   virtual Rect<int32_t> SetDamagedRect( Rect<int32_t> damagedRect ) = 0;
188
189   /**
190    * @brief Gets buffer age
191    */
192   virtual int32_t GetBufferAge() = 0;
193
194 public:
195
196   void SetAdaptor( Dali::Internal::Adaptor::AdaptorInternalServices& adaptor )
197   {
198     mAdaptor = &adaptor;
199   }
200
201   void SetGraphicsInterface( Dali::Internal::Adaptor::GraphicsInterface& graphics )
202   {
203     mGraphics = &graphics;
204   }
205
206   void SetDisplayConnection( Dali::DisplayConnection& displayConnection )
207   {
208     mDisplayConnection = &displayConnection;
209   }
210
211 private:
212
213   /**
214    * @brief Undefined copy constructor. RenderSurface cannot be copied
215    */
216   RenderSurfaceInterface( const RenderSurfaceInterface& rhs );
217
218   /**
219    * @brief Undefined assignment operator. RenderSurface cannot be copied
220    */
221   RenderSurfaceInterface& operator=( const RenderSurfaceInterface& rhs );
222
223 protected:
224
225   Dali::Internal::Adaptor::AdaptorInternalServices* mAdaptor;
226   Dali::Internal::Adaptor::GraphicsInterface* mGraphics;
227   Dali::DisplayConnection* mDisplayConnection;
228
229 private:
230
231   Integration::DepthBufferAvailable mDepthBufferRequired;       ///< Whether the depth buffer is required
232   Integration::StencilBufferAvailable mStencilBufferRequired;   ///< Whether the stencil buffer is required
233
234   Vector4 mBackgroundColor;                                     ///< The background color of the surface
235 };
236
237 } // namespace Dali
238
239 #endif // DALI_RENDER_SURFACE_INTERFACE_H