X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali%2Finternal%2Fupdate%2Fcommon%2Fscene-graph-scene.h;h=f1f0f5adde8d31c69e440bbb38ee865966dc6bf3;hb=9502baa1298289b85dcf263d723521ce6a400fd6;hp=221c42ef1e6dc80d900dd5481578104d4dc9a0e2;hpb=a8e17b031ea5832e46538d7091ab1970295d9d4a;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/common/scene-graph-scene.h b/dali/internal/update/common/scene-graph-scene.h index 221c42e..f1f0f5a 100644 --- a/dali/internal/update/common/scene-graph-scene.h +++ b/dali/internal/update/common/scene-graph-scene.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_SCENE_H /* - * Copyright (c) 2020 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. @@ -18,27 +18,70 @@ */ // INTERNAL INCLUDES +#include +#include #include -#include -#include +#include +#include #include +#include namespace Dali { - namespace Internal { - -class Context; +namespace Render +{ +class Renderer; +} namespace SceneGraph { class RenderInstructionContainer; +class Node; + +struct DirtyRect +{ + DirtyRect(Node* node, Render::Renderer* renderer, int32_t frame, Rect& rect) + : node(node), + renderer(renderer), + frame(frame), + rect(rect), + visited(true) + { + } + + DirtyRect() = default; + + bool operator<(const DirtyRect& rhs) const + { + if(node == rhs.node) + { + if(renderer == rhs.renderer) + { + return frame > rhs.frame; // Most recent rects come first + } + else + { + return renderer < rhs.renderer; + } + } + else + { + return node < rhs.node; + } + } + + Node* node{nullptr}; + Render::Renderer* renderer{nullptr}; + int32_t frame{0}; + Rect rect{}; + bool visited{true}; +}; class Scene { public: - /** * Constructor * @param[in] surface The render surface @@ -52,37 +95,273 @@ public: /** * Creates a scene object in the GPU. - * @param[in] context The GL context + * @param[in] graphicsController The graphics controller + * @param[in] depthBufferAvailable True if there is a depth buffer + * @param[in] stencilBufferAvailable True if there is a stencil buffer + */ + void Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable); + + /** + * Gets the render instructions for the scene + * @return the render instructions */ - void Initialize( Context& context ); + RenderInstructionContainer& GetRenderInstructions(); /** - * Called by RenderManager to inform the scene that the context has been destroyed + * @brief Adds a callback that is called when the frame rendering is done by the graphics driver. + * + * @param[in] callback The function to call + * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called. + * + * @note A callback of the following type may be used: + * @code + * void MyFunction( int frameId ); + * @endcode + * This callback will be deleted once it is called. + * + * @note Ownership of the callback is passed onto this class. */ - void GlContextDestroyed(); + void AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId); /** - * Gets the context holding the GL state of rendering for the scene - * @return the context + * @brief Adds a callback that is called when the frame is displayed on the display. + * + * @param[in] callback The function to call + * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called. + * + * @note A callback of the following type may be used: + * @code + * void MyFunction( int frameId ); + * @endcode + * This callback will be deleted once it is called. + * + * @note Ownership of the callback is passed onto this class. */ - Context* GetContext(); + void AddFramePresentedCallback(CallbackBase* callback, int32_t frameId); /** - * Gets the render instructions for the scene - * @return the render instructions + * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver. + * + * @param[out] callbacks The callback list */ - RenderInstructionContainer& GetRenderInstructions(); + void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks); -private: + /** + * @brief Gets the callback list that is called when the frame is displayed on the display. + * + * @param[out] callbacks The callback list + */ + void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks); + + /** + * @brief Sets whether rendering should be skipped or not. + * @param[in] skip true if rendering should be skipped. + */ + void SetSkipRendering(bool skip); + + /** + * @brief Query whether rendering should be skipped or not. + * @return true if rendering should be skipped, false otherwise. + */ + bool IsRenderingSkipped() const; + + /** + * Set the surface rectangle when surface is resized. + * + * @param[in] scene The resized scene. + * @param[in] rect The retangle representing the surface. + */ + void SetSurfaceRect(const Rect& rect); + + /** + * Get the surface rectangle. + * + * @return the current surface rectangle + */ + const Rect& GetSurfaceRect() const; + + /** + * Set the surface orientation when surface is rotated. + * + * @param[in] orientation The orientation value representing the surface. + */ + void SetSurfaceOrientation(int32_t orientation); + + /** + * Get the surface orientation. + * + * @return the current surface orientation + */ + int32_t GetSurfaceOrientation() const; + + /** + * Query wheter the surface rect is changed or not. + * @return true if the surface rect is changed. + */ + bool IsSurfaceRectChanged(); + + /** + * @brief Set the internal flag to acknowledge surface rotation. + */ + void SetRotationCompletedAcknowledgement(); + + /** + * @brief Query wheter is set to acknowledge for completing surface rotation. + * @return true it should be acknowledged. + */ + bool IsRotationCompletedAcknowledgementSet(); + + /** + * Set the render target of the surface + * + * @param[in] renderTarget The render target. + */ + void SetSurfaceRenderTarget(Graphics::RenderTarget* renderTarget) + { + mRenderTarget = renderTarget; + } + + /** + * Get the render target created for the scene + * + * @return the render target + */ + [[nodiscard]] Graphics::RenderTarget* GetSurfaceRenderTarget() const + { + return mRenderTarget; + } + + /** + * Get the graphics render pass created for the scene + * + * @return the graphics render pass + */ + [[nodiscard]] Graphics::RenderPass* GetGraphicsRenderPass(Graphics::AttachmentLoadOp loadOp, Graphics::AttachmentStoreOp storeOp) const + { + if(loadOp == Graphics::AttachmentLoadOp::CLEAR) + { + return mRenderPass.get(); + } + else + { + return mRenderPassNoClear.get(); + } + } + + /** + * Get an initialized array of clear values which then can be modified and accessed to BeginRenderPass() command. + * + * @return the array of clear values + */ + [[nodiscard]] auto& GetGraphicsRenderPassClearValues() + { + return mClearValues; + } - Context* mContext; ///< The context holding the GL state of rendering for the scene + /** + * @brief Get ItemsDirtyRects + * + * @return the ItemsDirtyRects + */ + std::vector& GetItemsDirtyRects(); +private: // Render instructions describe what should be rendered during RenderManager::RenderScene() // Update manager updates instructions for the next frame while we render the current one - RenderInstructionContainer mInstructions; ///< Render instructions for the scene + RenderInstructionContainer mInstructions; ///< Render instructions for the scene + + Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks; ///< Frame rendered callbacks + Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks + + bool mSkipRendering; ///< A flag to skip rendering + + Rect mSurfaceRect; ///< The rectangle of surface which is related ot this scene. + int32_t mSurfaceOrientation; ///< The orientation of surface which is related of this scene + bool mSurfaceRectChanged; ///< The flag of surface's rectangle is changed when is resized, moved or rotated. + bool mRotationCompletedAcknowledgement; ///< The flag of sending the acknowledgement to complete window rotation. + + // Render pass and render target + + /** + * Render pass is created on fly depending on Load and Store operations + * The default render pass (most likely to be used) is the load = CLEAR + * and store = STORE for color attachment. + */ + Graphics::UniquePtr mRenderPass{nullptr}; ///< The render pass created to render the surface + Graphics::UniquePtr mRenderPassNoClear{nullptr}; ///< The render pass created to render the surface without clearing color + Graphics::RenderTarget* mRenderTarget{nullptr}; ///< This is created in the event thread when surface is created/resized/replaced + + std::vector mClearValues{}; ///< Clear colors + std::vector mItemsDirtyRects{}; ///< Dirty rect list }; +/// Messages +inline void AddFrameRenderedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId) +{ + using LocalType = MessageValue2; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&scene, &Scene::AddFrameRenderedCallback, const_cast(callback), frameId); +} + +inline void AddFramePresentedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId) +{ + using LocalType = MessageValue2; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&scene, &Scene::AddFramePresentedCallback, const_cast(callback), frameId); +} + +inline void SetSurfaceRectMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Rect& rect) +{ + using LocalType = MessageValue1 >; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&scene, &Scene::SetSurfaceRect, rect); +} + +inline void SetSurfaceOrientationMessage(EventThreadServices& eventThreadServices, const Scene& scene, int32_t orientation) +{ + using LocalType = MessageValue1; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&scene, &Scene::SetSurfaceOrientation, orientation); +} + +inline void SetRotationCompletedAcknowledgementMessage(EventThreadServices& eventThreadServices, const Scene& scene) +{ + using LocalType = Message; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&scene, &Scene::SetRotationCompletedAcknowledgement); +} + +inline void SetSurfaceRenderTargetMessage(EventThreadServices& eventThreadServices, const Scene& scene, Graphics::RenderTarget* renderTarget) +{ + using LocalType = MessageValue1; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&scene, &Scene::SetSurfaceRenderTarget, renderTarget); +} } // namespace SceneGraph @@ -90,5 +369,4 @@ private: } // namespace Dali - #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H