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