1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SCENE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SCENE_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.
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/public-api/common/vector-wrapper.h>
40 class RenderInstructionContainer;
45 DirtyRect(Node* node, Render::Renderer* renderer, int32_t frame, Rect<int>& rect)
54 DirtyRect() = default;
56 bool operator<(const DirtyRect& rhs) const
60 if(renderer == rhs.renderer)
62 return frame > rhs.frame; // Most recent rects come first
66 return renderer < rhs.renderer;
71 return node < rhs.node;
76 Render::Renderer* renderer{nullptr};
87 * @param[in] surface The render surface
97 * Creates a scene object in the GPU.
98 * @param[in] graphicsController The graphics controller
99 * @param[in] depthBufferAvailable True if there is a depth buffer
100 * @param[in] stencilBufferAvailable True if there is a stencil buffer
102 void Initialize(Graphics::Controller& graphicsController, Integration::DepthBufferAvailable depthBufferAvailable, Integration::StencilBufferAvailable stencilBufferAvailable);
105 * Gets the render instructions for the scene
106 * @return the render instructions
108 RenderInstructionContainer& GetRenderInstructions();
111 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
113 * @param[in] callback The function to call
114 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
116 * @note A callback of the following type may be used:
118 * void MyFunction( int frameId );
120 * This callback will be deleted once it is called.
122 * @note Ownership of the callback is passed onto this class.
124 void AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId);
127 * @brief Adds a callback that is called when the frame is displayed on the display.
129 * @param[in] callback The function to call
130 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
132 * @note A callback of the following type may be used:
134 * void MyFunction( int frameId );
136 * This callback will be deleted once it is called.
138 * @note Ownership of the callback is passed onto this class.
140 void AddFramePresentedCallback(CallbackBase* callback, int32_t frameId);
143 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
145 * @param[out] callbacks The callback list
147 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
150 * @brief Gets the callback list that is called when the frame is displayed on the display.
152 * @param[out] callbacks The callback list
154 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
157 * @brief Sets whether rendering should be skipped or not.
158 * @param[in] skip true if rendering should be skipped.
160 void SetSkipRendering(bool skip);
163 * @brief Query whether rendering should be skipped or not.
164 * @return true if rendering should be skipped, false otherwise.
166 bool IsRenderingSkipped() const;
169 * Set the surface rectangle when surface is resized.
171 * @param[in] scene The resized scene.
172 * @param[in] rect The retangle representing the surface.
174 void SetSurfaceRect(const Rect<int32_t>& rect);
177 * Get the surface rectangle.
179 * @return the current surface rectangle
181 const Rect<int32_t>& GetSurfaceRect() const;
184 * Set the surface orientation when surface is rotated.
186 * @param[in] orientation The orientation value representing the surface.
188 void SetSurfaceOrientation(int32_t orientation);
191 * Get the surface orientation.
193 * @return the current surface orientation
195 int32_t GetSurfaceOrientation() const;
198 * Query wheter the surface rect is changed or not.
199 * @return true if the surface rect is changed.
201 bool IsSurfaceRectChanged();
204 * @brief Set the internal flag to acknowledge surface rotation.
206 void SetRotationCompletedAcknowledgement();
209 * @brief Query wheter is set to acknowledge for completing surface rotation.
210 * @return true it should be acknowledged.
212 bool IsRotationCompletedAcknowledgementSet();
215 * Set the render target of the surface
217 * @param[in] renderTarget The render target.
219 void SetSurfaceRenderTargetCreateInfo(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo);
222 * Get the render target created for the scene
224 * @return the render target
226 [[nodiscard]] Graphics::RenderTarget* GetSurfaceRenderTarget() const
228 return mRenderTarget.get();
232 * Get the graphics render pass created for the scene
234 * @return the graphics render pass
236 [[nodiscard]] Graphics::RenderPass* GetGraphicsRenderPass(Graphics::AttachmentLoadOp loadOp, Graphics::AttachmentStoreOp storeOp) const
238 if(loadOp == Graphics::AttachmentLoadOp::CLEAR)
240 return mRenderPass.get();
244 return mRenderPassNoClear.get();
249 * Get an initialized array of clear values which then can be modified and accessed to BeginRenderPass() command.
251 * @return the array of clear values
253 [[nodiscard]] auto& GetGraphicsRenderPassClearValues()
259 * @brief Get ItemsDirtyRects
261 * @return the ItemsDirtyRects
263 std::vector<DirtyRect>& GetItemsDirtyRects();
266 // Render instructions describe what should be rendered during RenderManager::RenderScene()
267 // Update manager updates instructions for the next frame while we render the current one
269 RenderInstructionContainer mInstructions; ///< Render instructions for the scene
271 Graphics::Controller* mGraphicsController; ///< Graphics controller
273 Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks; ///< Frame rendered callbacks
274 Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks
276 bool mSkipRendering; ///< A flag to skip rendering
278 Rect<int32_t> mSurfaceRect; ///< The rectangle of surface which is related ot this scene.
279 int32_t mSurfaceOrientation; ///< The orientation of surface which is related of this scene
280 bool mSurfaceRectChanged; ///< The flag of surface's rectangle is changed when is resized, moved or rotated.
281 bool mRotationCompletedAcknowledgement; ///< The flag of sending the acknowledgement to complete window rotation.
283 // Render pass and render target
285 Graphics::RenderTargetCreateInfo mRenderTargetCreateInfo; // Passed in by message before 2nd stage Initialization happens.
288 * Render pass is created on fly depending on Load and Store operations
289 * The default render pass (most likely to be used) is the load = CLEAR
290 * and store = STORE for color attachment.
292 Graphics::UniquePtr<Graphics::RenderPass> mRenderPass{nullptr}; ///< The render pass created to render the surface
293 Graphics::UniquePtr<Graphics::RenderPass> mRenderPassNoClear{nullptr}; ///< The render pass created to render the surface without clearing color
294 Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget{nullptr}; ///< This is created in Update/Render thread when surface is created/resized/replaced
296 std::vector<Graphics::ClearValue> mClearValues{}; ///< Clear colors
297 std::vector<Dali::Internal::SceneGraph::DirtyRect> mItemsDirtyRects{}; ///< Dirty rect list
301 inline void AddFrameRenderedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
303 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
305 // Reserve some memory inside the message queue
306 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
308 // Construct message in the message queue memory; note that delete should not be called on the return value
309 new(slot) LocalType(&scene, &Scene::AddFrameRenderedCallback, const_cast<CallbackBase*>(callback), frameId);
312 inline void AddFramePresentedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
314 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
316 // Reserve some memory inside the message queue
317 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
319 // Construct message in the message queue memory; note that delete should not be called on the return value
320 new(slot) LocalType(&scene, &Scene::AddFramePresentedCallback, const_cast<CallbackBase*>(callback), frameId);
323 inline void SetSurfaceRectMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Rect<int32_t>& rect)
325 using LocalType = MessageValue1<Scene, Rect<int32_t> >;
327 // Reserve some memory inside the message queue
328 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
330 // Construct message in the message queue memory; note that delete should not be called on the return value
331 new(slot) LocalType(&scene, &Scene::SetSurfaceRect, rect);
334 inline void SetSurfaceOrientationMessage(EventThreadServices& eventThreadServices, const Scene& scene, int32_t orientation)
336 using LocalType = MessageValue1<Scene, int32_t>;
338 // Reserve some memory inside the message queue
339 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
341 // Construct message in the message queue memory; note that delete should not be called on the return value
342 new(slot) LocalType(&scene, &Scene::SetSurfaceOrientation, orientation);
345 inline void SetRotationCompletedAcknowledgementMessage(EventThreadServices& eventThreadServices, const Scene& scene)
347 using LocalType = Message<Scene>;
349 // Reserve some memory inside the message queue
350 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
352 // Construct message in the message queue memory; note that delete should not be called on the return value
353 new(slot) LocalType(&scene, &Scene::SetRotationCompletedAcknowledgement);
356 inline void SetSurfaceRenderTargetCreateInfoMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo)
358 using LocalType = MessageValue1<Scene, Graphics::RenderTargetCreateInfo>;
360 // Reserve some memory inside the message queue
361 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
363 // Construct message in the message queue memory; note that delete should not be called on the return value
364 new(slot) LocalType(&scene, &Scene::SetSurfaceRenderTargetCreateInfo, renderTargetCreateInfo);
367 } // namespace SceneGraph
369 } // namespace Internal
373 #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H