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/math/vector4.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/object/any.h>
30 class DisplayConnection;
31 class ThreadSynchronizationInterface;
37 class AdaptorInternalServices;
38 class GraphicsInterface;
43 * @brief The position and size of the render surface.
45 typedef Dali::Rect<int> PositionSize;
48 * @brief Interface for a render surface onto which Dali draws.
50 * Dali::Adaptor requires a render surface to draw on to. This is
51 * usually a window in the native windowing system, or some other
52 * mapped pixel buffer.
54 * Dali::Application will automatically create a render surface using a window.
56 * The implementation of the factory method below should choose an appropriate
57 * implementation of RenderSurface for the given platform
60 class RenderSurfaceInterface
66 WINDOW_RENDER_SURFACE,
67 PIXMAP_RENDER_SURFACE,
73 * Inlined as this is a pure abstract interface
75 RenderSurfaceInterface()
76 : mAdaptor( nullptr ),
78 mDisplayConnection( nullptr ),
79 mDepthBufferRequired( Integration::DepthBufferAvailable::FALSE ),
80 mStencilBufferRequired( Integration::StencilBufferAvailable::FALSE )
84 * @brief Virtual Destructor.
85 * Inlined as this is a pure abstract interface
87 virtual ~RenderSurfaceInterface() {}
90 * @brief Return the size and position of the surface.
91 * @return The position and size
93 virtual Dali::PositionSize GetPositionSize() const = 0;
97 * @param[out] dpiHorizontal set to the horizontal dpi
98 * @param[out] dpiVertical set to the vertical dpi
100 virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) = 0;
103 * @brief InitializeGraphics the platform specific graphics surface interfaces
105 virtual void InitializeGraphics() = 0;
108 * @brief Creates the Surface
110 virtual void CreateSurface() = 0;
113 * @brief Destroys the Surface
115 virtual void DestroySurface() = 0;
118 * @brief Replace the Surface
119 * @return true if context was lost
121 virtual bool ReplaceGraphicsSurface() = 0;
124 * @brief Resizes the underlying surface.
125 * @param[in] The dimensions of the new position
127 virtual void MoveResize( Dali::PositionSize positionSize ) = 0;
130 * @brief Called when Render thread has started
132 virtual void StartRender() = 0;
135 * @brief Invoked by render thread before Core::Render
136 * If the operation fails, then Core::Render should not be called until there is
137 * a surface to render onto.
138 * @param[in] resizingSurface True if the surface is being resized
139 * @return True if the operation is successful, False if the operation failed
141 virtual bool PreRender( bool resizingSurface ) = 0;
144 * @brief Invoked by render thread after Core::Render
145 * @param[in] renderToFbo True if render to FBO.
146 * @param[in] replacingSurface True if the surface is being replaced.
147 * @param[in] resizingSurface True if the surface is being resized.
149 virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface ) = 0;
151 * @brief Invoked by render thread when the thread should be stop
153 virtual void StopRender() = 0;
156 * @brief Invoked by Event Thread when the compositor lock should be released and rendering should resume.
158 virtual void ReleaseLock() = 0;
161 * @brief Sets the ThreadSynchronizationInterface
163 * @param threadSynchronization The thread-synchronization implementation.
165 virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) = 0;
168 * @brief Gets the surface type
170 virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() = 0;
173 * @brief Makes the graphics context current
175 virtual void MakeContextCurrent() = 0;
178 * @brief Get whether the depth buffer is required
179 * @return TRUE if the depth buffer is required
181 virtual Integration::DepthBufferAvailable GetDepthBufferRequired() = 0;
184 * @brief Get whether the stencil buffer is required
185 * @return TRUE if the stencil buffer is required
187 virtual Integration::StencilBufferAvailable GetStencilBufferRequired() = 0;
191 void SetAdaptor( Dali::Internal::Adaptor::AdaptorInternalServices& adaptor )
196 void SetGraphicsInterface( Dali::Internal::Adaptor::GraphicsInterface& graphics )
198 mGraphics = &graphics;
201 void SetDisplayConnection( Dali::DisplayConnection& displayConnection )
203 mDisplayConnection = &displayConnection;
209 * @brief Undefined copy constructor. RenderSurface cannot be copied
211 RenderSurfaceInterface( const RenderSurfaceInterface& rhs );
214 * @brief Undefined assignment operator. RenderSurface cannot be copied
216 RenderSurfaceInterface& operator=( const RenderSurfaceInterface& rhs );
220 Dali::Internal::Adaptor::AdaptorInternalServices* mAdaptor;
221 Dali::Internal::Adaptor::GraphicsInterface* mGraphics;
222 Dali::DisplayConnection* mDisplayConnection;
226 Integration::DepthBufferAvailable mDepthBufferRequired; ///< Whether the depth buffer is required
227 Integration::StencilBufferAvailable mStencilBufferRequired; ///< Whether the stencil buffer is required
229 Vector4 mBackgroundColor; ///< The background color of the surface
234 #endif // DALI_RENDER_SURFACE_INTERFACE_H