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] width A new width of the surface
101 * @param[in] height A new height of the surface
103 void RequestRotation(int angle, int width, int height);
106 * @brief Gets the window base object
107 * @return The window base object
109 WindowBase* GetWindowBase();
112 * @brief Intiailize Ime Surface for Ime window rendering.
114 * It sets one flag and callback function for Ime window rendering
115 * This callback function calls one special native window function for ready to commit buffer.
116 * The special function notify to display server.
117 * It is only used for Ime window.
119 void InitializeImeSurface();
122 * @brief This signal is emitted when the output is transformed.
124 OutputSignalType& OutputTransformedSignal();
126 public: // from Dali::RenderSurfaceInterface
128 * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
130 PositionSize GetPositionSize() const override;
134 void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
137 * @copydoc Dali::RenderSurfaceInterface::GetOrientation()
139 int GetOrientation() const override;
142 * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
144 void InitializeGraphics() override;
147 * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
149 void CreateSurface() override;
152 * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
154 void DestroySurface() override;
157 * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
159 bool ReplaceGraphicsSurface() override;
162 * @copydoc Dali::RenderSurfaceInterface::MoveResize()
164 void MoveResize(Dali::PositionSize positionSize) override;
167 * @copydoc Dali::RenderSurfaceInterface::StartRender()
169 void StartRender() override;
172 * @copydoc Dali::RenderSurfaceInterface::PreRender()
174 bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) override;
177 * @copydoc Dali::RenderSurfaceInterface::PostRender()
179 void PostRender() override;
182 * @copydoc Dali::RenderSurfaceInterface::StopRender()
184 void StopRender() override;
187 * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
189 void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) override;
192 * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
194 void ReleaseLock() override;
197 * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
199 Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
202 * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
204 void MakeContextCurrent() override;
207 * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
209 Integration::DepthBufferAvailable GetDepthBufferRequired() override;
212 * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
214 Integration::StencilBufferAvailable GetStencilBufferRequired() override;
218 * @brief Second stage construction
220 void Initialize(Any surface);
223 * Notify output is transformed.
225 void OutputTransformed();
228 * @brief Used as the callback for the post render.
229 * It is used both window rotation and supporting Ime window
231 void ProcessPostRender();
234 * @brief Used as the callback for the frame rendered / presented.
236 void ProcessFrameCallback();
239 * @brief Called when our event file descriptor has been written to.
240 * @param[in] eventBitMask bit mask of events that occured on the file descriptor
241 * @param[in] fileDescriptor The file descriptor
243 void OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor);
246 * @brief Set the buffer damage rects.
247 * @param[in] damagedRects List of damaged rects
248 * @param[in] clippingRect The rect to clip rendered scene
250 void SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
253 * @brief Swap buffers.
254 * @param[in] damagedRects List of damaged rects
256 void SwapBuffers(const std::vector<Rect<int>>& damagedRects);
260 WindowRenderSurface(const WindowRenderSurface&) = delete;
263 WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
266 struct FrameCallbackInfo
268 FrameCallbackInfo(Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd)
270 fileDescriptorMonitor(),
273 // Transfer owership of the CallbackBase
274 for(auto&& iter : callbackList)
276 callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
282 // Delete FileDescriptorMonitor before close fd.
283 fileDescriptorMonitor.release();
284 close(fileDescriptor);
287 Dali::Integration::Scene::FrameCallbackContainer callbacks;
288 std::unique_ptr<FileDescriptorMonitor> fileDescriptorMonitor;
292 using FrameCallbackInfoContainer = std::vector<std::unique_ptr<FrameCallbackInfo>>;
296 Dali::DisplayConnection* mDisplayConnection;
297 PositionSize mPositionSize; ///< Position
298 std::unique_ptr<WindowBase> mWindowBase;
299 ThreadSynchronizationInterface* mThreadSynchronization;
300 TriggerEventInterface* mRenderNotification; ///< Render notification trigger
301 std::unique_ptr<TriggerEventInterface> mPostRenderTrigger; ///< Post render callback function
302 std::unique_ptr<TriggerEventInterface> mFrameRenderedTrigger;
303 GraphicsInterface* mGraphics; ///< Graphics interface
304 EGLSurface mEGLSurface;
305 EGLContext mEGLContext;
306 ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
307 OutputSignalType mOutputTransformedSignal;
308 FrameCallbackInfoContainer mFrameCallbackInfoContainer;
309 DamagedRectsContainer mBufferDamagedRects;
311 int mWindowRotationAngle;
312 int mScreenRotationAngle;
313 uint32_t mDpiHorizontal;
314 uint32_t mDpiVertical;
315 std::vector<Rect<int>> mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass
316 bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
317 bool mWindowRotationFinished;
318 bool mScreenRotationFinished;
319 bool mResizeFinished;
320 bool mDefaultScreenRotationAvailable;
321 bool mIsImeWindowSurface;
323 }; // class WindowRenderSurface
325 } // namespace Adaptor
327 } // namespace Internal
331 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H