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/scene.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/event/common/event-thread-services.h>
25 #include <dali/internal/render/common/render-instruction-container.h>
26 #include <dali/public-api/common/vector-wrapper.h>
36 class RenderInstructionContainer;
43 * @param[in] surface The render surface
53 * Creates a scene object in the GPU.
54 * @param[in] context The GL context
55 * @param[in] graphicsController The graphics controller
57 void Initialize(Context& context, Graphics::Controller& graphicsController);
60 * Gets the context holding the GL state of rendering for the scene
63 Context* GetContext();
66 * Gets the render instructions for the scene
67 * @return the render instructions
69 RenderInstructionContainer& GetRenderInstructions();
72 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
74 * @param[in] callback The function to call
75 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
77 * @note A callback of the following type may be used:
79 * void MyFunction( int frameId );
81 * This callback will be deleted once it is called.
83 * @note Ownership of the callback is passed onto this class.
85 void AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId);
88 * @brief Adds a callback that is called when the frame is displayed on the display.
90 * @param[in] callback The function to call
91 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
93 * @note A callback of the following type may be used:
95 * void MyFunction( int frameId );
97 * This callback will be deleted once it is called.
99 * @note Ownership of the callback is passed onto this class.
101 void AddFramePresentedCallback(CallbackBase* callback, int32_t frameId);
104 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
106 * @param[out] callbacks The callback list
108 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
111 * @brief Gets the callback list that is called when the frame is displayed on the display.
113 * @param[out] callbacks The callback list
115 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
118 * @brief Sets whether rendering should be skipped or not.
119 * @param[in] skip true if rendering should be skipped.
121 void SetSkipRendering(bool skip);
124 * @brief Query whether rendering should be skipped or not.
125 * @return true if rendering should be skipped, false otherwise.
127 bool IsRenderingSkipped() const;
130 * Set the surface rectangle when surface is resized.
132 * @param[in] scene The resized scene.
133 * @param[in] rect The retangle representing the surface.
135 void SetSurfaceRect(const Rect<int32_t>& rect);
138 * Get the surface rectangle.
140 * @return the current surface rectangle
142 const Rect<int32_t>& GetSurfaceRect() const;
145 * Set the surface orientation when surface is rotated.
147 * @param[in] scene The rotated scene.
148 * @param[in] orientation The orientation value representing the surface.
150 void SetSurfaceOrientation(int32_t orientation);
153 * Get the surface orientation.
155 * @return the current surface orientation
157 int32_t GetSurfaceOrientation() const;
160 * Query wheter the surface rect is changed or not.
161 * @return true if the surface rect is changed.
163 bool IsSurfaceRectChanged();
166 * Set the render target of the surface
168 * @param[in] renderTarget The render target.
170 void SetSurfaceRenderTarget(Graphics::RenderTarget* renderTarget)
172 mRenderTarget = renderTarget;
176 * Get the render target created for the scene
178 * @return the render target
180 [[nodiscard]] Graphics::RenderTarget* GetSurfaceRenderTarget() const
182 return mRenderTarget;
186 * Get the graphics render pass created for the scene
188 * @return the graphics render pass
190 [[nodiscard]] Graphics::RenderPass* GetGraphicsRenderPass() const
192 return mRenderPass.get();
196 * Get an initialized array of clear values which then can be modified and accessed to BeginRenderPass() command.
198 * @return the array of clear values
200 [[nodiscard]] auto& GetGraphicsRenderPassClearValues()
206 Context* mContext; ///< The context holding the GL state of rendering for the scene, not owned
208 // Render instructions describe what should be rendered during RenderManager::RenderScene()
209 // Update manager updates instructions for the next frame while we render the current one
211 RenderInstructionContainer mInstructions; ///< Render instructions for the scene
213 Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks; ///< Frame rendered callbacks
214 Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks
216 bool mSkipRendering; ///< A flag to skip rendering
218 Rect<int32_t> mSurfaceRect; ///< The rectangle of surface which is related ot this scene.
219 int32_t mSurfaceOrientation; ///< The orientation of surface which is related of this scene
220 bool mSurfaceRectChanged; ///< The flag of surface's rectangle is changed when is resized, moved or rotated.
222 // Render pass and render target
225 * Render pass is created on fly depending on Load and Store operations
226 * The default render pass (most likely to be used) is the load = CLEAR
227 * and store = STORE for color attachment.
229 Graphics::UniquePtr<Graphics::RenderPass> mRenderPass{nullptr}; ///< The render pass created to render the surface
230 Graphics::RenderTarget* mRenderTarget{nullptr}; ///< This is created in the event thread when surface is created/resized/replaced
233 std::vector<Graphics::ClearValue> mClearValues{};
237 inline void AddFrameRenderedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
239 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
241 // Reserve some memory inside the message queue
242 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
244 // Construct message in the message queue memory; note that delete should not be called on the return value
245 new(slot) LocalType(&scene, &Scene::AddFrameRenderedCallback, const_cast<CallbackBase*>(callback), frameId);
248 inline void AddFramePresentedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
250 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
252 // Reserve some memory inside the message queue
253 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
255 // Construct message in the message queue memory; note that delete should not be called on the return value
256 new(slot) LocalType(&scene, &Scene::AddFramePresentedCallback, const_cast<CallbackBase*>(callback), frameId);
259 inline void SetSurfaceRectMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Rect<int32_t>& rect)
261 using LocalType = MessageValue1<Scene, Rect<int32_t> >;
263 // Reserve some memory inside the message queue
264 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
266 // Construct message in the message queue memory; note that delete should not be called on the return value
267 new(slot) LocalType(&scene, &Scene::SetSurfaceRect, rect);
270 inline void SetSurfaceOrientationMessage(EventThreadServices& eventThreadServices, const Scene& scene, int32_t orientation)
272 using LocalType = MessageValue1<Scene, int32_t>;
274 // Reserve some memory inside the message queue
275 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
277 // Construct message in the message queue memory; note that delete should not be called on the return value
278 new(slot) LocalType(&scene, &Scene::SetSurfaceOrientation, orientation);
281 inline void SetSurfaceRenderTargetMessage(EventThreadServices& eventThreadServices, const Scene& scene, Graphics::RenderTarget* renderTarget)
283 using LocalType = MessageValue1<Scene, Graphics::RenderTarget*>;
285 // Reserve some memory inside the message queue
286 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
288 // Construct message in the message queue memory; note that delete should not be called on the return value
289 new(slot) LocalType(&scene, &Scene::SetSurfaceRenderTarget, renderTarget);
292 } // namespace SceneGraph
294 } // namespace Internal
298 #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H