1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_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/public-api/signals/connection-tracker.h>
23 #include <dali/public-api/signals/dali-signal.h>
24 #include <dali/devel-api/threading/mutex.h>
25 #include <dali/integration-api/scene.h>
29 #include <dali/integration-api/adaptor-framework/egl-interface.h>
30 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
31 #include <dali/internal/graphics/common/graphics-interface.h>
32 #include <dali/internal/system/common/file-descriptor-monitor.h>
37 class TriggerEventInterface;
45 class AdaptorInternalServices;
48 * Window interface of render surface.
50 class WindowRenderSurface : public Dali::RenderSurfaceInterface, public ConnectionTracker
54 using OutputSignalType = Signal< void ( ) >;
55 using DamagedRectsContainer = std::list< std::vector< Rect< int > > >;
58 * Uses an window surface to render to.
59 * @param [in] positionSize the position and size of the surface
60 * @param [in] surface can be a window or pixmap.
61 * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
63 WindowRenderSurface( Dali::PositionSize positionSize, Any surface, bool isTransparent = false );
68 virtual ~WindowRenderSurface();
73 * @brief Get the native window handle
74 * @return The native window handle
76 Any GetNativeWindow();
79 * @brief Get the native window id
80 * @return The native window id
82 int GetNativeWindowId();
90 * @brief Sets the render notification trigger to call when render thread is completed a frame
91 * @param renderNotification to use
93 void SetRenderNotification( TriggerEventInterface* renderNotification );
96 * @brief Sets whether the surface is transparent or not.
97 * @param[in] transparent Whether the surface is transparent
99 void SetTransparency( bool transparent );
102 * Request surface rotation
103 * @param[in] angle A new angle of the surface
104 * @param[in] width A new width of the surface
105 * @param[in] height A new height of the surface
107 void RequestRotation( int angle, int width, int height );
110 * @brief Gets the window base object
111 * @return The window base object
113 WindowBase* GetWindowBase();
116 * @brief This signal is emitted when the output is transformed.
118 OutputSignalType& OutputTransformedSignal();
120 public: // from Dali::RenderSurfaceInterface
123 * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
125 PositionSize GetPositionSize() const override;
129 void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
132 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
134 void InitializeGraphics() override;
137 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
139 void CreateSurface() override;
142 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
144 void DestroySurface() override;
147 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
149 bool ReplaceGraphicsSurface() override;
152 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
154 void MoveResize( Dali::PositionSize positionSize) override;
157 * @copydoc Dali::RenderSurfaceInterface::StartRender()
159 void StartRender() override;
162 * @copydoc Dali::RenderSurfaceInterface::PreRender()
164 bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
167 * @copydoc Dali::RenderSurfaceInterface::PostRender()
169 void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
172 * @copydoc Dali::RenderSurfaceInterface::StopRender()
174 void StopRender() override;
177 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
179 void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
182 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
184 void ReleaseLock() override;
187 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
189 Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
192 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
194 void MakeContextCurrent() override;
197 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
199 Integration::DepthBufferAvailable GetDepthBufferRequired() override;
202 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
204 Integration::StencilBufferAvailable GetStencilBufferRequired() override;
209 * @brief Second stage construction
211 void Initialize( Any surface );
214 * Notify output is transformed.
216 void OutputTransformed();
219 * @brief Used as the callback for the rotation-trigger.
221 void ProcessRotationRequest();
224 * @brief Used as the callback for the frame rendered / presented.
226 void ProcessFrameCallback();
229 * @brief Called when our event file descriptor has been written to.
230 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
231 * @param[in] fileDescriptor The file descriptor
233 void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
236 * @brief Set the buffer damage rects.
237 * @param[in] damagedRects List of damaged rects
238 * @param[in] clippingRect The rect to clip rendered scene
240 void SetBufferDamagedRects( const std::vector< Rect< int > >& damagedRects, Rect< int >& clippingRect );
243 * @brief Swap buffers.
244 * @param[in] damagedRects List of damaged rects
246 void SwapBuffers( const std::vector<Rect<int>>& damagedRects );
251 WindowRenderSurface(const WindowRenderSurface&) = delete;
254 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
258 struct FrameCallbackInfo
260 FrameCallbackInfo( Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd )
262 fileDescriptorMonitor(),
265 // Transfer owership of the CallbackBase
266 for( auto&& iter : callbackList )
268 callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
274 // Delete FileDescriptorMonitor before close fd.
275 fileDescriptorMonitor.release();
276 close( fileDescriptor );
279 Dali::Integration::Scene::FrameCallbackContainer callbacks;
280 std::unique_ptr< FileDescriptorMonitor > fileDescriptorMonitor;
284 using FrameCallbackInfoContainer = std::vector< std::unique_ptr< FrameCallbackInfo > >;
289 Dali::DisplayConnection* mDisplayConnection;
290 PositionSize mPositionSize; ///< Position
291 std::unique_ptr< WindowBase > mWindowBase;
292 ThreadSynchronizationInterface* mThreadSynchronization;
293 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
294 TriggerEventInterface* mRotationTrigger;
295 std::unique_ptr< TriggerEventInterface > mFrameRenderedTrigger;
296 GraphicsInterface* mGraphics; ///< Graphics interface
297 EGLSurface mEGLSurface;
298 EGLContext mEGLContext;
299 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
300 OutputSignalType mOutputTransformedSignal;
301 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
302 DamagedRectsContainer mBufferDamagedRects;
305 int mScreenRotationAngle;
306 uint32_t mDpiHorizontal;
307 uint32_t mDpiVertical;
308 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
309 bool mRotationSupported;
310 bool mRotationFinished;
311 bool mScreenRotationFinished;
312 bool mResizeFinished;
314 }; // class WindowRenderSurface
316 } // namespace Adaptor
318 } // namespace internal
322 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H