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/integration-api/scene.h>
28 #include <dali/integration-api/adaptor-framework/egl-interface.h>
29 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
30 #include <dali/internal/graphics/common/graphics-interface.h>
31 #include <dali/internal/system/common/file-descriptor-monitor.h>
36 class TriggerEventInterface;
44 class AdaptorInternalServices;
47 * Window interface of render surface.
49 class WindowRenderSurface : public Dali::RenderSurfaceInterface, public ConnectionTracker
53 typedef Signal< void ( ) > OutputSignalType;
56 * Uses an window surface to render to.
57 * @param [in] positionSize the position and size of the surface
58 * @param [in] surface can be a window or pixmap.
59 * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
61 WindowRenderSurface( Dali::PositionSize positionSize, Any surface, bool isTransparent = false );
66 virtual ~WindowRenderSurface();
71 * @brief Get the native window handle
72 * @return The native window handle
74 Any GetNativeWindow();
77 * @brief Get the native window id
78 * @return The native window id
80 int GetNativeWindowId();
88 * @brief Sets the render notification trigger to call when render thread is completed a frame
89 * @param renderNotification to use
91 void SetRenderNotification( TriggerEventInterface* renderNotification );
94 * @brief Sets whether the surface is transparent or not.
95 * @param[in] transparent Whether the surface is transparent
97 void SetTransparency( bool transparent );
100 * Request surface rotation
101 * @param[in] angle A new angle of the surface
102 * @param[in] width A new width of the surface
103 * @param[in] height A new height of the surface
105 void RequestRotation( int angle, int width, int height );
108 * @brief Gets the window base object
109 * @return The window base object
111 WindowBase* GetWindowBase();
114 * @brief This signal is emitted when the output is transformed.
116 OutputSignalType& OutputTransformedSignal();
118 public: // from Dali::RenderSurfaceInterface
121 * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
123 virtual PositionSize GetPositionSize() const override;
127 virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
130 * @brief Return the orientation of the surface.
131 * @return The orientation
133 virtual int GetOrientation() const override;
136 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
138 virtual void InitializeGraphics() override;
141 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
143 virtual void CreateSurface() override;
146 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
148 virtual void DestroySurface() override;
151 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
153 virtual bool ReplaceGraphicsSurface() override;
156 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
158 virtual void MoveResize( Dali::PositionSize positionSize) override;
161 * @copydoc Dali::RenderSurfaceInterface::StartRender()
163 virtual void StartRender() override;
166 * @copydoc Dali::RenderSurfaceInterface::PreRender()
168 virtual bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
171 * @copydoc Dali::RenderSurfaceInterface::PostRender()
173 virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
176 * @copydoc Dali::RenderSurfaceInterface::StopRender()
178 virtual void StopRender() override;
181 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
183 virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
186 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
188 virtual void ReleaseLock() override;
191 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
193 virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
196 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
198 virtual void MakeContextCurrent() override;
201 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
203 virtual Integration::DepthBufferAvailable GetDepthBufferRequired() override;
206 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
208 virtual Integration::StencilBufferAvailable GetStencilBufferRequired() override;
213 * @brief Second stage construction
215 void Initialize( Any surface );
218 * Notify output is transformed.
220 void OutputTransformed();
223 * @brief Used as the callback for the rotation-trigger.
225 void ProcessRotationRequest();
228 * @brief Used as the callback for the frame rendered / presented.
230 void ProcessFrameCallback();
233 * @brief Called when our event file descriptor has been written to.
234 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
235 * @param[in] fileDescriptor The file descriptor
237 void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
242 WindowRenderSurface(const WindowRenderSurface&) = delete;
245 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
249 struct FrameCallbackInfo
251 FrameCallbackInfo( Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd )
253 fileDescriptorMonitor(),
256 // Transfer owership of the CallbackBase
257 for( auto&& iter : callbackList )
259 callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
265 // Delete FileDescriptorMonitor before close fd.
266 fileDescriptorMonitor.release();
267 close( fileDescriptor );
270 Dali::Integration::Scene::FrameCallbackContainer callbacks;
271 std::unique_ptr< FileDescriptorMonitor > fileDescriptorMonitor;
275 using FrameCallbackInfoContainer = std::vector< std::unique_ptr< FrameCallbackInfo > >;
280 Dali::DisplayConnection* mDisplayConnection;
281 PositionSize mPositionSize; ///< Position
282 std::unique_ptr< WindowBase > mWindowBase;
283 ThreadSynchronizationInterface* mThreadSynchronization;
284 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
285 TriggerEventInterface* mRotationTrigger;
286 std::unique_ptr< TriggerEventInterface > mFrameRenderedTrigger;
287 GraphicsInterface* mGraphics; ///< Graphics interface
288 EGLSurface mEGLSurface;
289 EGLContext mEGLContext;
290 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
291 OutputSignalType mOutputTransformedSignal;
292 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
294 int mScreenRotationAngle;
295 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
296 bool mRotationSupported;
297 bool mRotationFinished;
298 bool mScreenRotationFinished;
299 bool mResizeFinished;
301 uint32_t mDpiHorizontal;
302 uint32_t mDpiVertical;
304 }; // class WindowRenderSurface
306 } // namespace Adaptor
308 } // namespace internal
312 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H