1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
5 * Copyright (c) 2022 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/devel-api/threading/mutex.h>
23 #include <dali/integration-api/scene.h>
24 #include <dali/public-api/signals/connection-tracker.h>
25 #include <dali/public-api/signals/dali-signal.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>
36 class TriggerEventInterface;
43 class AdaptorInternalServices;
46 * Window interface of render surface.
48 class WindowRenderSurface : public Dali::RenderSurfaceInterface, public ConnectionTracker
52 using RotationFinishedSignalType = Signal<void()> ; ///<The signal of window rotation's finished.
53 using OutputSignalType = Signal<void()>;
54 using DamagedRectsContainer = std::vector<Rect<int>>;
57 * @brief 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();
72 * @brief Get the native window handle
74 * @return The native window handle
76 Any GetNativeWindow();
79 * @brief Get the native window id
81 * @return The native window id
83 int GetNativeWindowId();
91 * @brief Sets the render notification trigger to call when render thread is completed a frame
93 * @param renderNotification to use
95 void SetRenderNotification(TriggerEventInterface* renderNotification);
98 * @brief Sets whether the surface is transparent or not.
100 * @param[in] transparent Whether the surface is transparent
102 void SetTransparency(bool transparent);
105 * @brief Request surface rotation
107 * @param[in] angle A new angle of the surface
108 * @param[in] positionSize A new position and size of the surface
110 void RequestRotation(int angle, PositionSize positionSize);
113 * @brief Gets the window base object
115 * @return The window base object
117 WindowBase* GetWindowBase();
120 * @brief Intiailize Ime Surface for Ime window rendering.
121 * It sets one flag and callback function for Ime window rendering
122 * This callback function calls one special native window function for ready to commit buffer.
123 * The special function notify to display server.
124 * It is only used for Ime window.
126 void InitializeImeSurface();
129 * @brief Sets the necessary for window rotation acknowledge.
130 * After this function called, SendRotationCompletedAcknowledgement() should be called to complete window rotation.
131 * More detail description is written in DevelWindow::SetNeedsRotationCompletedAcknowledgement().
133 * @param[in] window The window instance.
134 * @param[in] needAcknowledgement the flag is true if window rotation acknowledgement is sent.
136 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
139 * @brief Updates window surface's position and size.
140 * It is just to update the local variable in window surface.
141 * This function is only called when window's position or size is changed by display server.
143 * @param[in] positionSize The updated window surface's position and size.
145 void UpdatePositionSize(Dali::PositionSize positionSize);
148 * @brief Moves the window to the specified position.
150 * @param positionSize The new position of the window.
152 void Move(Dali::PositionSize positionSize);
155 * @brief This signal is emitted when the output is transformed.
157 OutputSignalType& OutputTransformedSignal();
160 * @brief This signal is emitted when a rotation job is finished.
162 RotationFinishedSignalType& RotationFinishedSignal();
164 public: // from Dali::RenderSurfaceInterface
166 * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
168 PositionSize GetPositionSize() const override;
171 * @copydoc Dali::RenderSurfaceInterface::GetDpi()
173 void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
176 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceOrientation()
178 int GetSurfaceOrientation() const override;
181 * @copydoc Dali::RenderSurfaceInterface::GetScreenOrientation()
183 int GetScreenOrientation() const override;
186 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
188 void InitializeGraphics() override;
191 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
193 void CreateSurface() override;
196 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
198 void DestroySurface() override;
201 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
203 bool ReplaceGraphicsSurface() override;
206 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
208 void MoveResize(Dali::PositionSize positionSize) override;
211 * @copydoc Dali::RenderSurfaceInterface::StartRender()
213 void StartRender() override;
216 * @copydoc Dali::RenderSurfaceInterface::PreRender()
218 bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) override;
221 * @copydoc Dali::RenderSurfaceInterface::PostRender()
223 void PostRender() override;
226 * @copydoc Dali::RenderSurfaceInterface::StopRender()
228 void StopRender() override;
231 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
233 void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) override;
236 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
238 void ReleaseLock() override;
241 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
243 Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
246 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
248 void MakeContextCurrent() override;
251 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
253 Integration::DepthBufferAvailable GetDepthBufferRequired() override;
256 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
258 Integration::StencilBufferAvailable GetStencilBufferRequired() override;
262 * @brief Second stage construction
264 void Initialize(Any surface);
267 * @brief Notify output is transformed.
269 void OutputTransformed();
272 * @brief Used as the callback for the post render.
273 * It is used both window rotation and supporting Ime window
275 void ProcessPostRender();
278 * @brief Used as the callback for the frame rendered / presented.
280 void ProcessFrameCallback();
283 * @brief Called when our event file descriptor has been written to.
285 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
286 * @param[in] fileDescriptor The file descriptor
288 void OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor);
291 * @brief Set the buffer damage rects.
293 * @param[in] damagedRects List of damaged rects
294 * @param[in] clippingRect The rect to clip rendered scene
296 void SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
299 * @brief Swap buffers.
301 * @param[in] damagedRects List of damaged rects
303 void SwapBuffers(const std::vector<Rect<int>>& damagedRects);
307 WindowRenderSurface(const WindowRenderSurface&) = delete;
310 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
313 struct FrameCallbackInfo
315 FrameCallbackInfo(Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd)
317 fileDescriptorMonitor(),
320 // Transfer owership of the CallbackBase
321 for(auto&& iter : callbackList)
323 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
329 // Delete FileDescriptorMonitor before close fd.
330 fileDescriptorMonitor.reset();
331 close(fileDescriptor);
334 Dali::Integration::Scene::FrameCallbackContainer callbacks;
335 std::unique_ptr<FileDescriptorMonitor> fileDescriptorMonitor;
339 using FrameCallbackInfoContainer = std::vector<std::unique_ptr<FrameCallbackInfo>>;
343 Dali::DisplayConnection* mDisplayConnection;
344 PositionSize mPositionSize; ///< Position
345 std::unique_ptr<WindowBase> mWindowBase;
346 ThreadSynchronizationInterface* mThreadSynchronization;
347 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
348 std::unique_ptr<TriggerEventInterface> mPostRenderTrigger; ///< Post render callback function
349 std::unique_ptr<TriggerEventInterface> mFrameRenderedTrigger;
350 GraphicsInterface* mGraphics; ///< Graphics interface
351 EGLSurface mEGLSurface;
352 EGLContext mEGLContext;
353 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
354 OutputSignalType mOutputTransformedSignal; ///< The signal of screen rotation occurs
355 RotationFinishedSignalType mWindowRotationFinishedSignal; ///< The signal of window rotation's finished
356 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
357 DamagedRectsContainer mBufferDamagedRects;
359 int mWindowRotationAngle;
360 int mScreenRotationAngle;
361 uint32_t mDpiHorizontal;
362 uint32_t mDpiVertical;
363 std::vector<Rect<int>> mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass. These rects are rotated by scene orientation.
364 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
365 bool mIsImeWindowSurface;
366 bool mNeedWindowRotationAcknowledgement;
367 bool mIsWindowOrientationChanging;
369 }; // class WindowRenderSurface
371 } // namespace Adaptor
373 } // namespace Internal
377 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H