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 typedef Signal< void ( ) > OutputSignalType;
57 * Uses an window surface to render to.
58 * @param [in] positionSize the position and size of the surface
59 * @param [in] surface can be a window or pixmap.
60 * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
62 WindowRenderSurface( Dali::PositionSize positionSize, Any surface, bool isTransparent = false );
67 virtual ~WindowRenderSurface();
72 * @brief Get the native window handle
73 * @return The native window handle
75 Any GetNativeWindow();
78 * @brief Get the native window id
79 * @return The native window id
81 int GetNativeWindowId();
89 * @brief Sets the render notification trigger to call when render thread is completed a frame
90 * @param renderNotification to use
92 void SetRenderNotification( TriggerEventInterface* renderNotification );
95 * @brief Sets whether the surface is transparent or not.
96 * @param[in] transparent Whether the surface is transparent
98 void SetTransparency( bool transparent );
101 * Request surface rotation
102 * @param[in] angle A new angle of the surface
103 * @param[in] width A new width of the surface
104 * @param[in] height A new height of the surface
106 void RequestRotation( int angle, int width, int height );
109 * @brief Gets the window base object
110 * @return The window base object
112 WindowBase* GetWindowBase();
115 * @brief This signal is emitted when the output is transformed.
117 OutputSignalType& OutputTransformedSignal();
119 public: // from Dali::RenderSurfaceInterface
122 * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
124 virtual PositionSize GetPositionSize() const override;
128 virtual void GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical ) override;
131 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
133 virtual void InitializeGraphics() override;
136 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
138 virtual void CreateSurface() override;
141 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
143 virtual void DestroySurface() override;
146 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
148 virtual bool ReplaceGraphicsSurface() override;
151 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
153 virtual void MoveResize( Dali::PositionSize positionSize) override;
156 * @copydoc Dali::RenderSurfaceInterface::StartRender()
158 virtual void StartRender() override;
161 * @copydoc Dali::RenderSurfaceInterface::PreRender()
163 virtual bool PreRender( bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect ) override;
166 * @copydoc Dali::RenderSurfaceInterface::PostRender()
168 virtual void PostRender( bool renderToFbo, bool replacingSurface, bool resizingSurface, const std::vector<Rect<int>>& damagedRects ) override;
171 * @copydoc Dali::RenderSurfaceInterface::StopRender()
173 virtual void StopRender() override;
176 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
178 virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) override;
181 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
183 virtual void ReleaseLock() override;
186 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
188 virtual Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
191 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
193 virtual void MakeContextCurrent() override;
196 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
198 virtual Integration::DepthBufferAvailable GetDepthBufferRequired() override;
201 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
203 virtual Integration::StencilBufferAvailable GetStencilBufferRequired() override;
208 * @brief Second stage construction
210 void Initialize( Any surface );
213 * Notify output is transformed.
215 void OutputTransformed();
218 * @brief Used as the callback for the rotation-trigger.
220 void ProcessRotationRequest();
223 * @brief Used as the callback for the frame rendered / presented.
225 void ProcessFrameCallback();
228 * @brief Called when our event file descriptor has been written to.
229 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
230 * @param[in] fileDescriptor The file descriptor
232 void OnFileDescriptorEventDispatched( FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor );
237 WindowRenderSurface(const WindowRenderSurface&) = delete;
240 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
244 struct FrameCallbackInfo
246 FrameCallbackInfo( Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd )
248 fileDescriptorMonitor(),
251 // Transfer owership of the CallbackBase
252 for( auto&& iter : callbackList )
254 callbacks.push_back( std::make_pair( std::move( iter.first ), iter.second ) );
260 // Delete FileDescriptorMonitor before close fd.
261 fileDescriptorMonitor.release();
262 close( fileDescriptor );
265 Dali::Integration::Scene::FrameCallbackContainer callbacks;
266 std::unique_ptr< FileDescriptorMonitor > fileDescriptorMonitor;
270 using FrameCallbackInfoContainer = std::vector< std::unique_ptr< FrameCallbackInfo > >;
275 Dali::DisplayConnection* mDisplayConnection;
276 PositionSize mPositionSize; ///< Position
277 std::unique_ptr< WindowBase > mWindowBase;
278 ThreadSynchronizationInterface* mThreadSynchronization;
279 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
280 TriggerEventInterface* mRotationTrigger;
281 std::unique_ptr< TriggerEventInterface > mFrameRenderedTrigger;
282 GraphicsInterface* mGraphics; ///< Graphics interface
283 EGLSurface mEGLSurface;
284 EGLContext mEGLContext;
285 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
286 OutputSignalType mOutputTransformedSignal;
287 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
290 int mScreenRotationAngle;
291 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
292 bool mRotationSupported;
293 bool mRotationFinished;
294 bool mScreenRotationFinished;
295 bool mResizeFinished;
297 uint32_t mDpiHorizontal;
298 uint32_t mDpiVertical;
300 }; // class WindowRenderSurface
302 } // namespace Adaptor
304 } // namespace internal
308 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H