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 * 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();
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] positionSize A new position and size of the surface
104 void RequestRotation(int angle, PositionSize positionSize);
107 * @brief Gets the window base object
108 * @return The window base object
110 WindowBase* GetWindowBase();
113 * @brief Intiailize Ime Surface for Ime window rendering.
115 * It sets one flag and callback function for Ime window rendering
116 * This callback function calls one special native window function for ready to commit buffer.
117 * The special function notify to display server.
118 * It is only used for Ime window.
120 void InitializeImeSurface();
123 * @brief Sets the necessary for window rotation acknowledge.
124 * After this function called, SendRotationCompletedAcknowledgement() should be called to complete window rotation.
126 * More detail description is written in DevelWindow::SetNeedsRotationCompletedAcknowledgement().
128 * @param[in] window The window instance.
129 * @param[in] needAcknowledgement the flag is true if window rotation acknowledgement is sent.
131 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
134 * @brief Updates window surface's position and size.
135 * It is just to update the local variable in window surface.
136 * This function is only called when window's position or size is changed by display server.
138 * @param[in] positionSize The updated window surface's position and size.
140 void UpdatePositionSize(Dali::PositionSize positionSize);
143 * @brief This signal is emitted when the output is transformed.
145 OutputSignalType& OutputTransformedSignal();
148 * @brief This signal is emitted when a rotation job is finished.
150 RotationFinishedSignalType& RotationFinishedSignal();
152 public: // from Dali::RenderSurfaceInterface
154 * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
156 PositionSize GetPositionSize() const override;
160 void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
163 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceOrientation()
165 int GetSurfaceOrientation() const override;
168 * @copydoc Dali::RenderSurfaceInterface::GetScreenOrientation()
170 int GetScreenOrientation() const override;
173 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
175 void InitializeGraphics() override;
178 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
180 void CreateSurface() override;
183 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
185 void DestroySurface() override;
188 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
190 bool ReplaceGraphicsSurface() override;
193 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
195 void MoveResize(Dali::PositionSize positionSize) override;
198 * @copydoc Dali::RenderSurfaceInterface::StartRender()
200 void StartRender() override;
203 * @copydoc Dali::RenderSurfaceInterface::PreRender()
205 bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) override;
208 * @copydoc Dali::RenderSurfaceInterface::PostRender()
210 void PostRender() override;
213 * @copydoc Dali::RenderSurfaceInterface::StopRender()
215 void StopRender() override;
218 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
220 void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) override;
223 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
225 void ReleaseLock() override;
228 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
230 Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
233 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
235 void MakeContextCurrent() override;
238 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
240 Integration::DepthBufferAvailable GetDepthBufferRequired() override;
243 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
245 Integration::StencilBufferAvailable GetStencilBufferRequired() override;
249 * @brief Second stage construction
251 void Initialize(Any surface);
254 * Notify output is transformed.
256 void OutputTransformed();
259 * @brief Used as the callback for the post render.
260 * It is used both window rotation and supporting Ime window
262 void ProcessPostRender();
265 * @brief Used as the callback for the frame rendered / presented.
267 void ProcessFrameCallback();
270 * @brief Called when our event file descriptor has been written to.
271 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
272 * @param[in] fileDescriptor The file descriptor
274 void OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor);
277 * @brief Set the buffer damage rects.
278 * @param[in] damagedRects List of damaged rects
279 * @param[in] clippingRect The rect to clip rendered scene
281 void SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
284 * @brief Swap buffers.
285 * @param[in] damagedRects List of damaged rects
287 void SwapBuffers(const std::vector<Rect<int>>& damagedRects);
291 WindowRenderSurface(const WindowRenderSurface&) = delete;
294 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
297 struct FrameCallbackInfo
299 FrameCallbackInfo(Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd)
301 fileDescriptorMonitor(),
304 // Transfer owership of the CallbackBase
305 for(auto&& iter : callbackList)
307 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
313 // Delete FileDescriptorMonitor before close fd.
314 fileDescriptorMonitor.release();
315 close(fileDescriptor);
318 Dali::Integration::Scene::FrameCallbackContainer callbacks;
319 std::unique_ptr<FileDescriptorMonitor> fileDescriptorMonitor;
323 using FrameCallbackInfoContainer = std::vector<std::unique_ptr<FrameCallbackInfo>>;
327 Dali::DisplayConnection* mDisplayConnection;
328 PositionSize mPositionSize; ///< Position
329 std::unique_ptr<WindowBase> mWindowBase;
330 ThreadSynchronizationInterface* mThreadSynchronization;
331 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
332 std::unique_ptr<TriggerEventInterface> mPostRenderTrigger; ///< Post render callback function
333 std::unique_ptr<TriggerEventInterface> mFrameRenderedTrigger;
334 GraphicsInterface* mGraphics; ///< Graphics interface
335 EGLSurface mEGLSurface;
336 EGLContext mEGLContext;
337 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
338 OutputSignalType mOutputTransformedSignal; ///< The signal of screen rotation occurs
339 RotationFinishedSignalType mWindowRotationFinishedSignal; ///< The signal of window rotation's finished
340 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
341 DamagedRectsContainer mBufferDamagedRects;
343 int mWindowRotationAngle;
344 int mScreenRotationAngle;
345 uint32_t mDpiHorizontal;
346 uint32_t mDpiVertical;
347 std::vector<Rect<int>> mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass. These rects are rotated by scene orientation.
348 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
349 bool mIsImeWindowSurface;
350 bool mNeedWindowRotationAcknowledgement;
351 bool mIsWindowOrientationChanging;
353 }; // class WindowRenderSurface
355 } // namespace Adaptor
357 } // namespace Internal
361 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H