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 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
132 virtual void InitializeGraphics() override;
135 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
137 virtual void CreateSurface() override;
140 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
142 virtual void DestroySurface() override;
145 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
147 virtual bool ReplaceGraphicsSurface() override;
150 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
152 virtual void MoveResize( Dali::PositionSize positionSize) override;
155 * @copydoc Dali::RenderSurfaceInterface::StartRender()
157 virtual void StartRender() override;
160 * @copydoc Dali::RenderSurfaceInterface::PreRender()
162 virtual bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
165 * @copydoc Dali::RenderSurfaceInterface::PostRender()
167 virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
170 * @copydoc Dali::RenderSurfaceInterface::StopRender()
172 virtual void StopRender() override;
175 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
177 virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
180 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
182 virtual void ReleaseLock() override;
185 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
187 virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
190 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
192 virtual void MakeContextCurrent() override;
195 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
197 virtual Integration::DepthBufferAvailable GetDepthBufferRequired() override;
200 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
202 virtual Integration::StencilBufferAvailable GetStencilBufferRequired() override;
207 * @brief Second stage construction
209 void Initialize( Any surface );
212 * Notify output is transformed.
214 void OutputTransformed();
217 * @brief Used as the callback for the rotation-trigger.
219 void ProcessRotationRequest();
222 * @brief Used as the callback for the frame rendered / presented.
224 void ProcessFrameCallback();
227 * @brief Called when our event file descriptor has been written to.
228 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
229 * @param[in] fileDescriptor The file descriptor
231 void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
236 WindowRenderSurface(const WindowRenderSurface&) = delete;
239 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
243 struct FrameCallbackInfo
245 FrameCallbackInfo( Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd )
247 fileDescriptorMonitor(),
250 // Transfer owership of the CallbackBase
251 for( auto&& iter : callbackList )
253 callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
259 // Delete FileDescriptorMonitor before close fd.
260 fileDescriptorMonitor.release();
261 close( fileDescriptor );
264 Dali::Integration::Scene::FrameCallbackContainer callbacks;
265 std::unique_ptr< FileDescriptorMonitor > fileDescriptorMonitor;
269 using FrameCallbackInfoContainer = std::vector< std::unique_ptr< FrameCallbackInfo > >;
274 Dali::DisplayConnection* mDisplayConnection;
275 PositionSize mPositionSize; ///< Position
276 std::unique_ptr< WindowBase > mWindowBase;
277 ThreadSynchronizationInterface* mThreadSynchronization;
278 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
279 TriggerEventInterface* mRotationTrigger;
280 std::unique_ptr< TriggerEventInterface > mFrameRenderedTrigger;
281 GraphicsInterface* mGraphics; ///< Graphics interface
282 EGLSurface mEGLSurface;
283 EGLContext mEGLContext;
284 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
285 OutputSignalType mOutputTransformedSignal;
286 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
288 int mScreenRotationAngle;
289 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
290 bool mRotationSupported;
291 bool mRotationFinished;
292 bool mScreenRotationFinished;
293 bool mResizeFinished;
295 uint32_t mDpiHorizontal;
296 uint32_t mDpiVertical;
298 }; // class WindowRenderSurface
300 } // namespace Adaptor
302 } // namespace internal
306 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H