1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
5 * Copyright (c) 2021 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
51 using OutputSignalType = Signal<void()>;
52 using DamagedRectsContainer = std::list<std::vector<Rect<int>>>;
55 * Uses an window surface to render to.
56 * @param [in] positionSize the position and size of the surface
57 * @param [in] surface can be a window or pixmap.
58 * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
60 WindowRenderSurface(Dali::PositionSize positionSize, Any surface, bool isTransparent = false);
65 virtual ~WindowRenderSurface();
69 * @brief Get the native window handle
70 * @return The native window handle
72 Any GetNativeWindow();
75 * @brief Get the native window id
76 * @return The native window id
78 int GetNativeWindowId();
86 * @brief Sets the render notification trigger to call when render thread is completed a frame
87 * @param renderNotification to use
89 void SetRenderNotification(TriggerEventInterface* renderNotification);
92 * @brief Sets whether the surface is transparent or not.
93 * @param[in] transparent Whether the surface is transparent
95 void SetTransparency(bool transparent);
98 * Request surface rotation
99 * @param[in] angle A new angle of the surface
100 * @param[in] positionSize A new position and size of the surface
102 void RequestRotation(int angle, PositionSize positionSize);
105 * @brief Gets the window base object
106 * @return The window base object
108 WindowBase* GetWindowBase();
111 * @brief Intiailize Ime Surface for Ime window rendering.
113 * It sets one flag and callback function for Ime window rendering
114 * This callback function calls one special native window function for ready to commit buffer.
115 * The special function notify to display server.
116 * It is only used for Ime window.
118 void InitializeImeSurface();
121 * @brief Sets the necessary for window rotation acknowledge.
122 * After this function called, SendRotationCompletedAcknowledgement() should be called to complete window rotation.
124 * More detail description is written in DevelWindow::SetNeedsRotationCompletedAcknowledgement().
126 * @param[in] window The window instance.
127 * @param[in] needAcknowledgement the flag is true if window rotation acknowledgement is sent.
129 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
132 * @brief Updates window surface's position and size.
133 * It is just to update the local variable in window surface.
134 * This function is only called when window's position or size is changed by display server.
136 * @param[in] positionSize The updated window surface's position and size.
138 void UpdatePositionSize(Dali::PositionSize positionSize);
141 * @brief This signal is emitted when the output is transformed.
143 OutputSignalType& OutputTransformedSignal();
145 public: // from Dali::RenderSurfaceInterface
147 * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
149 PositionSize GetPositionSize() const override;
153 void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
156 * @copydoc Dali::RenderSurfaceInterface::GetOrientation()
158 int GetOrientation() const override;
161 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
163 void InitializeGraphics() override;
166 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
168 void CreateSurface() override;
171 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
173 void DestroySurface() override;
176 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
178 bool ReplaceGraphicsSurface() override;
181 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
183 void MoveResize(Dali::PositionSize positionSize) override;
186 * @copydoc Dali::RenderSurfaceInterface::StartRender()
188 void StartRender() override;
191 * @copydoc Dali::RenderSurfaceInterface::PreRender()
193 bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) override;
196 * @copydoc Dali::RenderSurfaceInterface::PostRender()
198 void PostRender() override;
201 * @copydoc Dali::RenderSurfaceInterface::StopRender()
203 void StopRender() override;
206 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
208 void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) override;
211 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
213 void ReleaseLock() override;
216 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
218 Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
221 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
223 void MakeContextCurrent() override;
226 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
228 Integration::DepthBufferAvailable GetDepthBufferRequired() override;
231 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
233 Integration::StencilBufferAvailable GetStencilBufferRequired() override;
237 * @brief Second stage construction
239 void Initialize(Any surface);
242 * Notify output is transformed.
244 void OutputTransformed();
247 * @brief Used as the callback for the post render.
248 * It is used both window rotation and supporting Ime window
250 void ProcessPostRender();
253 * @brief Used as the callback for the frame rendered / presented.
255 void ProcessFrameCallback();
258 * @brief Called when our event file descriptor has been written to.
259 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
260 * @param[in] fileDescriptor The file descriptor
262 void OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor);
265 * @brief Set the buffer damage rects.
266 * @param[in] damagedRects List of damaged rects
267 * @param[in] clippingRect The rect to clip rendered scene
269 void SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
272 * @brief Swap buffers.
273 * @param[in] damagedRects List of damaged rects
275 void SwapBuffers(const std::vector<Rect<int>>& damagedRects);
279 WindowRenderSurface(const WindowRenderSurface&) = delete;
282 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
285 struct FrameCallbackInfo
287 FrameCallbackInfo(Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd)
289 fileDescriptorMonitor(),
292 // Transfer owership of the CallbackBase
293 for(auto&& iter : callbackList)
295 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
301 // Delete FileDescriptorMonitor before close fd.
302 fileDescriptorMonitor.release();
303 close(fileDescriptor);
306 Dali::Integration::Scene::FrameCallbackContainer callbacks;
307 std::unique_ptr<FileDescriptorMonitor> fileDescriptorMonitor;
311 using FrameCallbackInfoContainer = std::vector<std::unique_ptr<FrameCallbackInfo>>;
315 Dali::DisplayConnection* mDisplayConnection;
316 PositionSize mPositionSize; ///< Position
317 std::unique_ptr<WindowBase> mWindowBase;
318 ThreadSynchronizationInterface* mThreadSynchronization;
319 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
320 std::unique_ptr<TriggerEventInterface> mPostRenderTrigger; ///< Post render callback function
321 std::unique_ptr<TriggerEventInterface> mFrameRenderedTrigger;
322 GraphicsInterface* mGraphics; ///< Graphics interface
323 EGLSurface mEGLSurface;
324 EGLContext mEGLContext;
325 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
326 OutputSignalType mOutputTransformedSignal;
327 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
328 DamagedRectsContainer mBufferDamagedRects;
330 int mWindowRotationAngle;
331 int mScreenRotationAngle;
332 uint32_t mDpiHorizontal;
333 uint32_t mDpiVertical;
334 std::vector<Rect<int>> mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass
335 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
336 bool mWindowRotationFinished;
337 bool mScreenRotationFinished;
338 bool mResizeFinished;
339 bool mDefaultScreenRotationAvailable;
340 bool mIsImeWindowSurface;
341 bool mNeedWindowRotationAcknowledgement;
343 }; // class WindowRenderSurface
345 } // namespace Adaptor
347 } // namespace Internal
351 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H