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/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/math/rect.h>
26 #include <dali/public-api/object/any.h>
27 #include <dali/public-api/object/weak-handle.h>
28 #include <dali/integration-api/scene.h>
29 #include <dali/public-api/math/uint-16-pair.h>
34 class DisplayConnection;
35 class ThreadSynchronizationInterface;
41 class AdaptorInternalServices;
42 class GraphicsInterface;
47 * @brief The position and size of the render surface.
49 using PositionSize = Dali::Rect<int>;
50 using SurfaceSize = Uint16Pair;
53 * @brief Interface for a render surface onto which Dali draws.
55 * Dali::Adaptor requires a render surface to draw on to. This is
56 * usually a window in the native windowing system, or some other
57 * mapped pixel buffer.
59 * Dali::Application will automatically create a render surface using a window.
61 * The implementation of the factory method below should choose an appropriate
62 * implementation of RenderSurface for the given platform
65 class RenderSurfaceInterface
71 WINDOW_RENDER_SURFACE,
72 PIXMAP_RENDER_SURFACE,
78 * Inlined as this is a pure abstract interface
80 RenderSurfaceInterface()
81 : mAdaptor( nullptr ),
83 mDisplayConnection( nullptr ),
85 mDepthBufferRequired( Integration::DepthBufferAvailable::FALSE ),
86 mStencilBufferRequired( Integration::StencilBufferAvailable::FALSE )
90 * @brief Virtual Destructor.
91 * Inlined as this is a pure abstract interface
93 virtual ~RenderSurfaceInterface() {}
96 * @brief Return the size and position of the surface.
97 * @return The position and size
99 virtual Dali::PositionSize GetPositionSize() const = 0;
103 * @param[out] dpiHorizontal set to the horizontal dpi
104 * @param[out] dpiVertical set to the vertical dpi
106 virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) = 0;
109 * @brief InitializeGraphics the platform specific graphics surface interfaces
111 virtual void InitializeGraphics() = 0;
114 * @brief Creates the Surface
116 virtual void CreateSurface() = 0;
119 * @brief Destroys the Surface
121 virtual void DestroySurface() = 0;
124 * @brief Replace the Surface
125 * @return true if context was lost
127 virtual bool ReplaceGraphicsSurface() = 0;
130 * @brief Resizes the underlying surface.
131 * @param[in] The dimensions of the new position
133 virtual void MoveResize( Dali::PositionSize positionSize ) = 0;
136 * @brief Called when Render thread has started
138 virtual void StartRender() = 0;
141 * @brief Invoked by render thread before Core::Render
142 * If the operation fails, then Core::Render should not be called until there is
143 * a surface to render onto.
144 * @param[in] resizingSurface True if the surface is being resized
145 * @param[in] damagedRects List of damaged rects this render pass
146 * @return True if the operation is successful, False if the operation failed
148 virtual bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) = 0;
151 * @brief Invoked by render thread after Core::Render
152 * @param[in] renderToFbo True if render to FBO.
153 * @param[in] replacingSurface True if the surface is being replaced.
154 * @param[in] resizingSurface True if the surface is being resized.
156 virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) = 0;
159 * @brief Invoked by render thread when the thread should be stop
161 virtual void StopRender() = 0;
164 * @brief Invoked by Event Thread when the compositor lock should be released and rendering should resume.
166 virtual void ReleaseLock() = 0;
169 * @brief Sets the ThreadSynchronizationInterface
171 * @param threadSynchronization The thread-synchronization implementation.
173 virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) = 0;
176 * @brief Gets the surface type
178 virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() = 0;
181 * @brief Makes the graphics context current
183 virtual void MakeContextCurrent() = 0;
186 * @brief Get whether the depth buffer is required
187 * @return TRUE if the depth buffer is required
189 virtual Integration::DepthBufferAvailable GetDepthBufferRequired() = 0;
192 * @brief Get whether the stencil buffer is required
193 * @return TRUE if the stencil buffer is required
195 virtual Integration::StencilBufferAvailable GetStencilBufferRequired() = 0;
199 void SetAdaptor( Dali::Internal::Adaptor::AdaptorInternalServices& adaptor )
204 void SetGraphicsInterface( Dali::Internal::Adaptor::GraphicsInterface& graphics )
206 mGraphics = &graphics;
209 void SetDisplayConnection( Dali::DisplayConnection& displayConnection )
211 mDisplayConnection = &displayConnection;
215 * @brief Sets a Scene that is rendered on this surface.
216 * @param scene The Scene object
218 void SetScene( Dali::Integration::Scene& scene )
226 * @brief Undefined copy constructor. RenderSurface cannot be copied
228 RenderSurfaceInterface( const RenderSurfaceInterface& rhs );
231 * @brief Undefined assignment operator. RenderSurface cannot be copied
233 RenderSurfaceInterface& operator=( const RenderSurfaceInterface& rhs );
237 Dali::Internal::Adaptor::AdaptorInternalServices* mAdaptor;
238 Dali::Internal::Adaptor::GraphicsInterface* mGraphics;
239 Dali::DisplayConnection* mDisplayConnection;
240 WeakHandle< Dali::Integration::Scene > mScene;
244 Integration::DepthBufferAvailable mDepthBufferRequired; ///< Whether the depth buffer is required
245 Integration::StencilBufferAvailable mStencilBufferRequired; ///< Whether the stencil buffer is required
247 Vector4 mBackgroundColor; ///< The background color of the surface
252 #endif // DALI_RENDER_SURFACE_INTERFACE_H