1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SCENE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SCENE_H
5 * Copyright (c) 2022 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/update/nodes/scene-graph-layer.h>
28 #include <dali/public-api/common/vector-wrapper.h>
41 class RenderInstructionContainer;
46 DirtyRect(Node* node, Render::Renderer* renderer, Rect<int>& rect)
54 DirtyRect() = default;
56 bool operator<(const DirtyRect& rhs) const
60 return renderer < rhs.renderer;
64 return node < rhs.node;
69 Render::Renderer* renderer{nullptr};
79 * @param[in] surface The render surface
89 * Creates a scene object in the GPU.
90 * @param[in] graphicsController The graphics controller
91 * @param[in] depthBufferAvailable True if there is a depth buffer
92 * @param[in] stencilBufferAvailable True if there is a stencil buffer
94 void Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable);
97 * Gets the render instructions for the scene
98 * @return the render instructions
100 RenderInstructionContainer& GetRenderInstructions();
103 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
105 * @param[in] callback The function to call
106 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
108 * @note A callback of the following type may be used:
110 * void MyFunction( int frameId );
112 * This callback will be deleted once it is called.
114 * @note Ownership of the callback is passed onto this class.
116 void AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId);
119 * @brief Adds a callback that is called when the frame is displayed on the display.
121 * @param[in] callback The function to call
122 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
124 * @note A callback of the following type may be used:
126 * void MyFunction( int frameId );
128 * This callback will be deleted once it is called.
130 * @note Ownership of the callback is passed onto this class.
132 void AddFramePresentedCallback(CallbackBase* callback, int32_t frameId);
135 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
137 * @param[out] callbacks The callback list
139 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
142 * @brief Gets the callback list that is called when the frame is displayed on the display.
144 * @param[out] callbacks The callback list
146 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
149 * @brief Sets whether rendering should be skipped or not.
150 * @param[in] skip true if rendering should be skipped.
152 void SetSkipRendering(bool skip);
155 * @brief Query whether rendering should be skipped or not.
156 * @return true if rendering should be skipped, false otherwise.
158 bool IsRenderingSkipped() const;
161 * Set the surface rectangle when surface is resized.
163 * @param[in] scene The resized scene.
164 * @param[in] rect The retangle representing the surface.
166 void SetSurfaceRect(const Rect<int32_t>& rect);
169 * Get the surface rectangle.
171 * @return the current surface rectangle
173 const Rect<int32_t>& GetSurfaceRect() const;
176 * Set the surface orientation when surface is rotated.
178 * @param[in] orientation The orientation value representing the surface.
180 void SetSurfaceOrientation(int32_t orientation);
183 * Get the surface orientation.
185 * @return the current surface orientation
187 int32_t GetSurfaceOrientation() const;
190 * Query wheter the surface rect is changed or not.
191 * @return true if the surface rect is changed.
193 bool IsSurfaceRectChanged();
196 * @brief Set the internal flag to acknowledge surface rotation.
198 void SetRotationCompletedAcknowledgement();
201 * @brief Query wheter is set to acknowledge for completing surface rotation.
202 * @return true it should be acknowledged.
204 bool IsRotationCompletedAcknowledgementSet();
207 * Set the render target of the surface
209 * @param[in] renderTarget The render target.
211 void SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo);
214 * Get the render target created for the scene
216 * @return the render target
218 [[nodiscard]] Graphics::RenderTarget* GetSurfaceRenderTarget() const
220 return mRenderTarget.get();
224 * Get the graphics render pass created for the scene
226 * @return the graphics render pass
228 [[nodiscard]] Graphics::RenderPass* GetGraphicsRenderPass(Graphics::AttachmentLoadOp loadOp, Graphics::AttachmentStoreOp storeOp) const
230 if(loadOp == Graphics::AttachmentLoadOp::CLEAR)
232 return mRenderPass.get();
236 return mRenderPassNoClear.get();
241 * Get an initialized array of clear values which then can be modified and accessed to BeginRenderPass() command.
243 * @return the array of clear values
245 [[nodiscard]] auto& GetGraphicsRenderPassClearValues()
251 * @brief Set a root of the Scene
253 * @param layer The root layer
255 void SetRoot(SceneGraph::Layer* layer)
261 * @brief Get a root of the Scene
263 * @return The root layer
265 SceneGraph::Layer* GetRoot() const
271 * @brief Get ItemsDirtyRects
273 * @return the ItemsDirtyRects
275 std::vector<DirtyRect>& GetItemsDirtyRects();
278 // Render instructions describe what should be rendered during RenderManager::RenderScene()
279 // Update manager updates instructions for the next frame while we render the current one
281 RenderInstructionContainer mInstructions; ///< Render instructions for the scene
283 Graphics::Controller* mGraphicsController{nullptr}; ///< Graphics controller
285 Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks; ///< Frame rendered callbacks
286 Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks
288 bool mSkipRendering; ///< A flag to skip rendering
290 Rect<int32_t> mSurfaceRect; ///< The rectangle of surface which is related ot this scene.
291 int32_t mSurfaceOrientation; ///< The orientation of surface which is related of this scene
292 bool mSurfaceRectChanged; ///< The flag of surface's rectangle is changed when is resized, moved or rotated.
293 bool mRotationCompletedAcknowledgement; ///< The flag of sending the acknowledgement to complete window rotation.
295 // Render pass and render target
297 Graphics::RenderTargetCreateInfo mRenderTargetCreateInfo; // Passed in by message before 2nd stage Initialization happens.
300 * Render pass is created on fly depending on Load and Store operations
301 * The default render pass (most likely to be used) is the load = CLEAR
302 * and store = STORE for color attachment.
304 Graphics::UniquePtr<Graphics::RenderPass> mRenderPass{nullptr}; ///< The render pass created to render the surface
305 Graphics::UniquePtr<Graphics::RenderPass> mRenderPassNoClear{nullptr}; ///< The render pass created to render the surface without clearing color
306 Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget{nullptr}; ///< This is created in Update/Render thread when surface is created/resized/replaced
308 SceneGraph::Layer* mRoot{nullptr}; ///< Root node
310 std::vector<Graphics::ClearValue> mClearValues{}; ///< Clear colors
311 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects{}; ///< Dirty rect list
315 inline void AddFrameRenderedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
317 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
319 // Reserve some memory inside the message queue
320 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
322 // Construct message in the message queue memory; note that delete should not be called on the return value
323 new(slot) LocalType(&scene, &Scene::AddFrameRenderedCallback, const_cast<CallbackBase*>(callback), frameId);
326 inline void AddFramePresentedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
328 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
330 // Reserve some memory inside the message queue
331 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
333 // Construct message in the message queue memory; note that delete should not be called on the return value
334 new(slot) LocalType(&scene, &Scene::AddFramePresentedCallback, const_cast<CallbackBase*>(callback), frameId);
337 inline void SetSurfaceRectMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Rect<int32_t>& rect)
339 using LocalType = MessageValue1<Scene, Rect<int32_t> >;
341 // Reserve some memory inside the message queue
342 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
344 // Construct message in the message queue memory; note that delete should not be called on the return value
345 new(slot) LocalType(&scene, &Scene::SetSurfaceRect, rect);
348 inline void SetSurfaceOrientationMessage(EventThreadServices& eventThreadServices, const Scene& scene, int32_t orientation)
350 using LocalType = MessageValue1<Scene, int32_t>;
352 // Reserve some memory inside the message queue
353 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
355 // Construct message in the message queue memory; note that delete should not be called on the return value
356 new(slot) LocalType(&scene, &Scene::SetSurfaceOrientation, orientation);
359 inline void SetRotationCompletedAcknowledgementMessage(EventThreadServices& eventThreadServices, const Scene& scene)
361 using LocalType = Message<Scene>;
363 // Reserve some memory inside the message queue
364 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
366 // Construct message in the message queue memory; note that delete should not be called on the return value
367 new(slot) LocalType(&scene, &Scene::SetRotationCompletedAcknowledgement);
370 inline void SetSurfaceRenderTargetCreateInfoMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
372 using LocalType = MessageValue1<Scene, Graphics::RenderTargetCreateInfo>;
374 // Reserve some memory inside the message queue
375 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
377 // Construct message in the message queue memory; note that delete should not be called on the return value
378 new(slot) LocalType(&scene, &Scene::SetSurfaceRenderTargetCreateInfo, renderTargetCreateInfo);
381 } // namespace SceneGraph
383 } // namespace Internal
387 #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H