#define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_RENDER_SURFACE_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
+// EXTERNAL INCLUDES
+#include <dali/devel-api/threading/mutex.h>
+#include <dali/integration-api/scene.h>
+#include <dali/public-api/signals/connection-tracker.h>
+#include <dali/public-api/signals/dali-signal.h>
+#include <unistd.h>
+
// INTERNAL INCLUDES
-#include <dali/integration-api/render-surface.h>
+#include <dali/integration-api/adaptor-framework/egl-interface.h>
+#include <dali/integration-api/adaptor-framework/render-surface-interface.h>
+#include <dali/internal/graphics/common/graphics-interface.h>
+#include <dali/internal/system/common/file-descriptor-monitor.h>
namespace Dali
{
-
class TriggerEventInterface;
namespace Internal
{
namespace Adaptor
{
+class WindowBase;
+class AdaptorInternalServices;
/**
* Window interface of render surface.
*/
-class WindowRenderSurface : public Dali::RenderSurface
+class WindowRenderSurface : public Dali::RenderSurfaceInterface, public ConnectionTracker
{
public:
+ using OutputSignalType = Signal<void()>;
+ using DamagedRectsContainer = std::list<std::vector<Rect<int>>>;
/**
- * @brief Default constructor
- */
- WindowRenderSurface() = default;
+ * Uses an window surface to render to.
+ * @param [in] positionSize the position and size of the surface
+ * @param [in] surface can be a window or pixmap.
+ * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit
+ */
+ WindowRenderSurface(Dali::PositionSize positionSize, Any surface, bool isTransparent = false);
/**
* @brief Destructor
*/
- virtual ~WindowRenderSurface() = default;
+ virtual ~WindowRenderSurface();
public: // API
+ /**
+ * @brief Get the native window handle
+ * @return The native window handle
+ */
+ Any GetNativeWindow();
/**
- * @brief Get the render surface the adaptor is using to render to.
- * @return reference to current render surface
+ * @brief Get the native window id
+ * @return The native window id
*/
- virtual Any GetWindow() = 0;
+ int GetNativeWindowId();
/**
* @brief Map window
*/
- virtual void Map() = 0;
+ void Map();
/**
* @brief Sets the render notification trigger to call when render thread is completed a frame
* @param renderNotification to use
*/
- virtual void SetRenderNotification( TriggerEventInterface* renderNotification ) = 0;
+ void SetRenderNotification(TriggerEventInterface* renderNotification);
/**
* @brief Sets whether the surface is transparent or not.
* @param[in] transparent Whether the surface is transparent
*/
- virtual void SetTransparency( bool transparent ) = 0;
+ void SetTransparency(bool transparent);
/**
* Request surface rotation
* @param[in] width A new width of the surface
* @param[in] height A new height of the surface
*/
- virtual void RequestRotation( int angle, int width, int height ) = 0;
+ void RequestRotation(int angle, int width, int height);
-protected:
+ /**
+ * @brief Gets the window base object
+ * @return The window base object
+ */
+ WindowBase* GetWindowBase();
+
+ /**
+ * @brief Intiailize Ime Surface for Ime window rendering.
+ *
+ * It sets one flag and callback function for Ime window rendering
+ * This callback function calls one special native window function for ready to commit buffer.
+ * The special function notify to display server.
+ * It is only used for Ime window.
+ */
+ void InitializeImeSurface();
+
+ /**
+ * @brief Sets the necessary for window rotation acknowledge.
+ * After this function called, SendRotationCompletedAcknowledgement() should be called to complete window rotation.
+ *
+ * More detail description is written in DevelWindow::SetNeedsRotationCompletedAcknowledgement().
+ *
+ * @param[in] window The window instance.
+ * @param[in] needAcknowledgement the flag is true if window rotation acknowledgement is sent.
+ */
+ void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
+
+ /**
+ * @brief This signal is emitted when the output is transformed.
+ */
+ OutputSignalType& OutputTransformedSignal();
+
+public: // from Dali::RenderSurfaceInterface
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::GetPositionSize()
+ */
+ PositionSize GetPositionSize() const override;
+
+ /**
+ */
+ void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
/**
+ * @copydoc Dali::RenderSurfaceInterface::GetOrientation()
+ */
+ int GetOrientation() const override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::InitializeGraphics()
+ */
+ void InitializeGraphics() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::CreateSurface()
+ */
+ void CreateSurface() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::DestroySurface()
+ */
+ void DestroySurface() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::ReplaceGraphicsSurface()
+ */
+ bool ReplaceGraphicsSurface() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::MoveResize()
+ */
+ void MoveResize(Dali::PositionSize positionSize) override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::StartRender()
+ */
+ void StartRender() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::PreRender()
+ */
+ bool PreRender(bool resizingSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect) override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::PostRender()
+ */
+ void PostRender() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::StopRender()
+ */
+ void StopRender() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::SetThreadSynchronization
+ */
+ void SetThreadSynchronization(ThreadSynchronizationInterface& threadSynchronization) override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::ReleaseLock()
+ */
+ void ReleaseLock() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::GetSurfaceType()
+ */
+ Dali::RenderSurfaceInterface::Type GetSurfaceType() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::MakeContextCurrent()
+ */
+ void MakeContextCurrent() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::GetDepthBufferRequired()
+ */
+ Integration::DepthBufferAvailable GetDepthBufferRequired() override;
+
+ /**
+ * @copydoc Dali::RenderSurfaceInterface::GetStencilBufferRequired()
+ */
+ Integration::StencilBufferAvailable GetStencilBufferRequired() override;
+
+private:
+ /**
* @brief Second stage construction
*/
- virtual void Initialize( Any surface ) = 0;
+ void Initialize(Any surface);
/**
- * @brief Create window
+ * Notify output is transformed.
*/
- virtual void CreateRenderable() = 0;
+ void OutputTransformed();
/**
- * @brief Use an existing render surface
- * @param surfaceId the id of the surface
+ * @brief Used as the callback for the post render.
+ * It is used both window rotation and supporting Ime window
*/
- virtual void UseExistingRenderable( unsigned int surfaceId ) = 0;
+ void ProcessPostRender();
-protected:
+ /**
+ * @brief Used as the callback for the frame rendered / presented.
+ */
+ void ProcessFrameCallback();
+
+ /**
+ * @brief Called when our event file descriptor has been written to.
+ * @param[in] eventBitMask bit mask of events that occured on the file descriptor
+ * @param[in] fileDescriptor The file descriptor
+ */
+ void OnFileDescriptorEventDispatched(FileDescriptorMonitor::EventType eventBitMask, int fileDescriptor);
+
+ /**
+ * @brief Set the buffer damage rects.
+ * @param[in] damagedRects List of damaged rects
+ * @param[in] clippingRect The rect to clip rendered scene
+ */
+ void SetBufferDamagedRects(const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
+
+ /**
+ * @brief Swap buffers.
+ * @param[in] damagedRects List of damaged rects
+ */
+ void SwapBuffers(const std::vector<Rect<int>>& damagedRects);
+protected:
// Undefined
WindowRenderSurface(const WindowRenderSurface&) = delete;
// Undefined
WindowRenderSurface& operator=(const WindowRenderSurface& rhs) = delete;
+private:
+ struct FrameCallbackInfo
+ {
+ FrameCallbackInfo(Dali::Integration::Scene::FrameCallbackContainer& callbackList, int fd)
+ : callbacks(),
+ fileDescriptorMonitor(),
+ fileDescriptor(fd)
+ {
+ // Transfer owership of the CallbackBase
+ for(auto&& iter : callbackList)
+ {
+ callbacks.push_back(std::make_pair(std::move(iter.first), iter.second));
+ }
+ }
+
+ ~FrameCallbackInfo()
+ {
+ // Delete FileDescriptorMonitor before close fd.
+ fileDescriptorMonitor.release();
+ close(fileDescriptor);
+ }
+
+ Dali::Integration::Scene::FrameCallbackContainer callbacks;
+ std::unique_ptr<FileDescriptorMonitor> fileDescriptorMonitor;
+ int fileDescriptor;
+ };
+
+ using FrameCallbackInfoContainer = std::vector<std::unique_ptr<FrameCallbackInfo>>;
+
+private: // Data
+ EglInterface* mEGL;
+ Dali::DisplayConnection* mDisplayConnection;
+ PositionSize mPositionSize; ///< Position
+ std::unique_ptr<WindowBase> mWindowBase;
+ ThreadSynchronizationInterface* mThreadSynchronization;
+ TriggerEventInterface* mRenderNotification; ///< Render notification trigger
+ std::unique_ptr<TriggerEventInterface> mPostRenderTrigger; ///< Post render callback function
+ std::unique_ptr<TriggerEventInterface> mFrameRenderedTrigger;
+ GraphicsInterface* mGraphics; ///< Graphics interface
+ EGLSurface mEGLSurface;
+ EGLContext mEGLContext;
+ ColorDepth mColorDepth; ///< Color depth of surface (32 bit or 24 bit)
+ OutputSignalType mOutputTransformedSignal;
+ FrameCallbackInfoContainer mFrameCallbackInfoContainer;
+ DamagedRectsContainer mBufferDamagedRects;
+ Dali::Mutex mMutex;
+ int mWindowRotationAngle;
+ int mScreenRotationAngle;
+ uint32_t mDpiHorizontal;
+ uint32_t mDpiVertical;
+ std::vector<Rect<int>> mDamagedRects{}; ///< Keeps collected damaged render items rects for one render pass
+ bool mOwnSurface; ///< Whether we own the surface (responsible for deleting it)
+ bool mWindowRotationFinished;
+ bool mScreenRotationFinished;
+ bool mResizeFinished;
+ bool mDefaultScreenRotationAvailable;
+ bool mIsImeWindowSurface;
+ bool mNeedWindowRotationAcknowledgement;
+
}; // class WindowRenderSurface
} // namespace Adaptor
-} // namespace internal
+} // namespace Internal
} // namespace Dali