1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SCENE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SCENE_H
5 * Copyright (c) 2023 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.
21 #include <dali/graphics-api/graphics-controller.h>
22 #include <dali/integration-api/core.h>
23 #include <dali/integration-api/scene.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/event/common/event-thread-services.h>
26 #include <dali/internal/render/common/render-instruction-container.h>
27 #include <dali/internal/render/renderers/render-renderer.h> // RendererKey
28 #include <dali/internal/update/nodes/scene-graph-layer.h>
29 #include <dali/public-api/common/vector-wrapper.h>
37 class RenderInstructionContainer;
42 DirtyRect(Node* node, Render::RendererKey renderer, Rect<int>& rect)
50 DirtyRect() = default;
52 bool operator<(const DirtyRect& rhs) const
56 return renderer.Value() < rhs.renderer.Value();
60 return node < rhs.node;
65 Render::RendererKey renderer{};
75 * @param[in] surface The render surface
85 * Creates a scene object in the GPU.
86 * @param[in] graphicsController The graphics controller
87 * @param[in] depthBufferAvailable True if there is a depth buffer
88 * @param[in] stencilBufferAvailable True if there is a stencil buffer
90 void Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable);
93 * Gets the render instructions for the scene
94 * @return the render instructions
96 RenderInstructionContainer& GetRenderInstructions();
99 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
101 * @param[in] callback The function to call
102 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
104 * @note A callback of the following type may be used:
106 * void MyFunction( int frameId );
108 * This callback will be deleted once it is called.
110 * @note Ownership of the callback is passed onto this class.
112 void AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId);
115 * @brief Adds a callback that is called when the frame is displayed on the display.
117 * @param[in] callback The function to call
118 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
120 * @note A callback of the following type may be used:
122 * void MyFunction( int frameId );
124 * This callback will be deleted once it is called.
126 * @note Ownership of the callback is passed onto this class.
128 void AddFramePresentedCallback(CallbackBase* callback, int32_t frameId);
131 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
133 * @param[out] callbacks The callback list
135 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
138 * @brief Gets the callback list that is called when the frame is displayed on the display.
140 * @param[out] callbacks The callback list
142 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
145 * @brief Sets whether rendering should be skipped or not.
146 * @param[in] skip true if rendering should be skipped.
148 void SetSkipRendering(bool skip);
151 * @brief Query whether rendering should be skipped or not.
152 * @return true if rendering should be skipped, false otherwise.
154 bool IsRenderingSkipped() const;
157 * Set the surface rectangle when surface is resized.
159 * @param[in] scene The resized scene.
160 * @param[in] rect The retangle representing the surface.
162 void SetSurfaceRect(const Rect<int32_t>& rect);
165 * Get the surface rectangle.
167 * @return the current surface rectangle
169 const Rect<int32_t>& GetSurfaceRect() const;
172 * Set the surface orientations when surface or screen is rotated.
174 * @param[in] windowOrientation The orientations value representing surface.
175 * @param[in] screenOrienation The orientations value representing screen.
177 void SetSurfaceOrientations(int32_t windowOrientation, int32_t screenOrienation);
180 * Get the surface orientation.
182 * @return the current surface orientation
184 int32_t GetSurfaceOrientation() const;
187 * Get the screen orientation.
189 * @return the current screen orientation
191 int32_t GetScreenOrientation() const;
194 * Query wheter the surface rect is changed or not.
195 * @return true if the surface rect is changed.
197 bool IsSurfaceRectChanged();
200 * @brief Set the internal flag to acknowledge surface rotation.
202 void SetRotationCompletedAcknowledgement();
205 * @brief Query wheter is set to acknowledge for completing surface rotation.
206 * @return true it should be acknowledged.
208 bool IsRotationCompletedAcknowledgementSet();
211 * Set the render target of the surface
213 * @param[in] renderTarget The render target.
215 void SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo);
218 * Get the render target created for the scene
220 * @return the render target
222 [[nodiscard]] Graphics::RenderTarget* GetSurfaceRenderTarget() const
224 return mRenderTarget.get();
228 * Get the graphics render pass created for the scene
230 * @return the graphics render pass
232 [[nodiscard]] Graphics::RenderPass* GetGraphicsRenderPass(Graphics::AttachmentLoadOp loadOp, Graphics::AttachmentStoreOp storeOp) const
234 if(loadOp == Graphics::AttachmentLoadOp::CLEAR)
236 return mRenderPass.get();
240 return mRenderPassNoClear.get();
245 * Get an initialized array of clear values which then can be modified and accessed to BeginRenderPass() command.
247 * @return the array of clear values
249 [[nodiscard]] auto& GetGraphicsRenderPassClearValues()
255 * @brief Set a root of the Scene
257 * @param layer The root layer
259 void SetRoot(SceneGraph::Layer* layer)
265 * @brief Get a root of the Scene
267 * @return The root layer
269 SceneGraph::Layer* GetRoot() const
275 * @brief Get ItemsDirtyRects
277 * @return the ItemsDirtyRects
279 std::vector<DirtyRect>& GetItemsDirtyRects();
282 // Render instructions describe what should be rendered during RenderManager::RenderScene()
283 // Update manager updates instructions for the next frame while we render the current one
285 RenderInstructionContainer mInstructions; ///< Render instructions for the scene
287 Graphics::Controller* mGraphicsController{nullptr}; ///< Graphics controller
289 Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks; ///< Frame rendered callbacks
290 Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks
292 bool mSkipRendering; ///< A flag to skip rendering
294 Rect<int32_t> mSurfaceRect; ///< The rectangle of surface which is related ot this scene.
295 int32_t mSurfaceOrientation; ///< The orientation of surface which is related of this scene
296 int32_t mScreenOrientation; ///< The orientation of screen
297 bool mSurfaceRectChanged; ///< The flag of surface's rectangle is changed when is resized or moved.
298 bool mRotationCompletedAcknowledgement; ///< The flag of sending the acknowledgement to complete window rotation.
300 // Render pass and render target
302 Graphics::RenderTargetCreateInfo mRenderTargetCreateInfo; // Passed in by message before 2nd stage Initialization happens.
305 * Render pass is created on fly depending on Load and Store operations
306 * The default render pass (most likely to be used) is the load = CLEAR
307 * and store = STORE for color attachment.
309 Graphics::UniquePtr<Graphics::RenderPass> mRenderPass{nullptr}; ///< The render pass created to render the surface
310 Graphics::UniquePtr<Graphics::RenderPass> mRenderPassNoClear{nullptr}; ///< The render pass created to render the surface without clearing color
311 Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget{nullptr}; ///< This is created in Update/Render thread when surface is created/resized/replaced
313 SceneGraph::Layer* mRoot{nullptr}; ///< Root node
315 std::vector<Graphics::ClearValue> mClearValues{}; ///< Clear colors
316 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects{}; ///< Dirty rect list
320 inline void AddFrameRenderedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
322 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
324 // Reserve some memory inside the message queue
325 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
327 // Construct message in the message queue memory; note that delete should not be called on the return value
328 new(slot) LocalType(&scene, &Scene::AddFrameRenderedCallback, const_cast<CallbackBase*>(callback), frameId);
331 inline void AddFramePresentedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
333 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
335 // Reserve some memory inside the message queue
336 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
338 // Construct message in the message queue memory; note that delete should not be called on the return value
339 new(slot) LocalType(&scene, &Scene::AddFramePresentedCallback, const_cast<CallbackBase*>(callback), frameId);
342 inline void SetSurfaceRectMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Rect<int32_t>& rect)
344 using LocalType = MessageValue1<Scene, Rect<int32_t> >;
346 // Reserve some memory inside the message queue
347 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
349 // Construct message in the message queue memory; note that delete should not be called on the return value
350 new(slot) LocalType(&scene, &Scene::SetSurfaceRect, rect);
353 inline void SetSurfaceOrientationsMessage(EventThreadServices& eventThreadServices, const Scene& scene, const int32_t windowOrientation, const int32_t screenOrientation)
355 using LocalType = MessageValue2<Scene, int32_t, int32_t>;
357 // Reserve some memory inside the message queue
358 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
360 // Construct message in the message queue memory; note that delete should not be called on the return value
361 new(slot) LocalType(&scene, &Scene::SetSurfaceOrientations, windowOrientation, screenOrientation);
364 inline void SetRotationCompletedAcknowledgementMessage(EventThreadServices& eventThreadServices, const Scene& scene)
366 using LocalType = Message<Scene>;
368 // Reserve some memory inside the message queue
369 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
371 // Construct message in the message queue memory; note that delete should not be called on the return value
372 new(slot) LocalType(&scene, &Scene::SetRotationCompletedAcknowledgement);
375 inline void SetSurfaceRenderTargetCreateInfoMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
377 using LocalType = MessageValue1<Scene, Graphics::RenderTargetCreateInfo>;
379 // Reserve some memory inside the message queue
380 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
382 // Construct message in the message queue memory; note that delete should not be called on the return value
383 new(slot) LocalType(&scene, &Scene::SetSurfaceRenderTargetCreateInfo, renderTargetCreateInfo);
386 } // namespace SceneGraph
388 } // namespace Internal
392 #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H