1 #ifndef DALI_RENDER_SURFACE_INTERFACE_H
2 #define DALI_RENDER_SURFACE_INTERFACE_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
33 class DisplayConnection;
34 class ThreadSynchronizationInterface;
40 class AdaptorInternalServices;
41 class GraphicsInterface;
42 } // namespace Adaptor
43 } // namespace Internal
46 * @brief The position and size of the render surface.
48 using PositionSize = Dali::Rect<int>;
49 using SurfaceSize = Uint16Pair;
52 * @brief Interface for a render surface onto which Dali draws.
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.
58 * Dali::Application will automatically create a render surface using a window.
60 * The implementation of the factory method below should choose an appropriate
61 * implementation of RenderSurface for the given platform
64 class RenderSurfaceInterface
69 WINDOW_RENDER_SURFACE,
70 PIXMAP_RENDER_SURFACE,
76 * Inlined as this is a pure abstract interface
78 RenderSurfaceInterface()
81 mDisplayConnection(nullptr),
83 mFullSwapNextFrame(true),
84 mDepthBufferRequired(Integration::DepthBufferAvailable::FALSE),
85 mStencilBufferRequired(Integration::StencilBufferAvailable::FALSE)
90 * @brief Virtual Destructor.
91 * Inlined as this is a pure abstract interface
93 virtual ~RenderSurfaceInterface()
98 * @brief Return the size and position of the surface.
99 * @return The position and size
101 virtual Dali::PositionSize GetPositionSize() const = 0;
105 * @param[out] dpiHorizontal set to the horizontal dpi
106 * @param[out] dpiVertical set to the vertical dpi
108 virtual void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) = 0;
111 * @brief InitializeGraphics the platform specific graphics surface interfaces
113 virtual void InitializeGraphics() = 0;
116 * @brief Creates the Surface
118 virtual void CreateSurface() = 0;
121 * @brief Destroys the Surface
123 virtual void DestroySurface() = 0;
126 * @brief Replace the Surface
127 * @return true if context was lost
129 virtual bool ReplaceGraphicsSurface() = 0;
132 * @brief Resizes the underlying surface.
133 * @param[in] The dimensions of the new position
135 virtual void MoveResize(Dali::PositionSize positionSize) = 0;
138 * @brief Called when Render thread has started
140 virtual void StartRender() = 0;
143 * @brief Invoked by render thread before Core::Render
144 * If the operation fails, then Core::Render should not be called until there is
145 * a surface to render onto.
146 * @param[in] resizingSurface True if the surface is being resized
147 * @param[in] damagedRects List of damaged rects this render pass
148 * @return True if the operation is successful, False if the operation failed
150 virtual bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) = 0;
153 * @brief Invoked by render thread after Core::Render
154 * @param[in] renderToFbo True if render to FBO.
155 * @param[in] replacingSurface True if the surface is being replaced.
156 * @param[in] resizingSurface True if the surface is being resized.
158 virtual void PostRender(bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects) = 0;
161 * @brief Invoked by render thread when the thread should be stop
163 virtual void StopRender() = 0;
166 * @brief Invoked by Event Thread when the compositor lock should be released and rendering should resume.
168 virtual void ReleaseLock() = 0;
171 * @brief Sets the ThreadSynchronizationInterface
173 * @param threadSynchronization The thread-synchronization implementation.
175 virtual void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) = 0;
178 * @brief Gets the surface type
180 virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() = 0;
183 * @brief Makes the graphics context current
185 virtual void MakeContextCurrent() = 0;
188 * @brief Get whether the depth buffer is required
189 * @return TRUE if the depth buffer is required
191 virtual Integration::DepthBufferAvailable GetDepthBufferRequired() = 0;
194 * @brief Get whether the stencil buffer is required
195 * @return TRUE if the stencil buffer is required
197 virtual Integration::StencilBufferAvailable GetStencilBufferRequired() = 0;
200 void SetAdaptor(Dali::Internal::Adaptor::AdaptorInternalServices& adaptor)
205 void SetGraphicsInterface(Dali::Internal::Adaptor::GraphicsInterface& graphics)
207 mGraphics = &graphics;
210 void SetDisplayConnection(Dali::DisplayConnection& displayConnection)
212 mDisplayConnection = &displayConnection;
216 * @brief Sets a Scene that is rendered on this surface.
217 * @param scene The Scene object
219 void SetScene(Dali::Integration::Scene& scene)
225 * @brief Forces full surface swap next frame, resets current partial update state.
227 void SetFullSwapNextFrame()
229 mFullSwapNextFrame = true;
234 * @brief Undefined copy constructor. RenderSurface cannot be copied
236 RenderSurfaceInterface(const RenderSurfaceInterface& rhs);
239 * @brief Undefined assignment operator. RenderSurface cannot be copied
241 RenderSurfaceInterface& operator=(const RenderSurfaceInterface& rhs);
244 Dali::Internal::Adaptor::AdaptorInternalServices* mAdaptor;
245 Dali::Internal::Adaptor::GraphicsInterface* mGraphics;
246 Dali::DisplayConnection* mDisplayConnection;
247 WeakHandle<Dali::Integration::Scene> mScene;
248 bool mFullSwapNextFrame; ///< Whether the full surface swap is required
251 Integration::DepthBufferAvailable mDepthBufferRequired; ///< Whether the depth buffer is required
252 Integration::StencilBufferAvailable mStencilBufferRequired; ///< Whether the stencil buffer is required
254 Vector4 mBackgroundColor; ///< The background color of the surface
259 #endif // DALI_RENDER_SURFACE_INTERFACE_H