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/integration-api/scene.h>
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/render/common/render-instruction-container.h>
25 #include <dali/public-api/common/vector-wrapper.h>
35 class RenderInstructionContainer;
42 * @param[in] surface The render surface
52 * Creates a scene object in the GPU.
53 * @param[in] context The GL context
55 void Initialize(Context& context);
58 * Gets the context holding the GL state of rendering for the scene
61 Context* GetContext();
64 * Gets the render instructions for the scene
65 * @return the render instructions
67 RenderInstructionContainer& GetRenderInstructions();
70 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
72 * @param[in] callback The function to call
73 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
75 * @note A callback of the following type may be used:
77 * void MyFunction( int frameId );
79 * This callback will be deleted once it is called.
81 * @note Ownership of the callback is passed onto this class.
83 void AddFrameRenderedCallback(CallbackBase* callback, int32_t frameId);
86 * @brief Adds a callback that is called when the frame is displayed on the display.
88 * @param[in] callback The function to call
89 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
91 * @note A callback of the following type may be used:
93 * void MyFunction( int frameId );
95 * This callback will be deleted once it is called.
97 * @note Ownership of the callback is passed onto this class.
99 void AddFramePresentedCallback(CallbackBase* callback, int32_t frameId);
102 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
104 * @param[out] callbacks The callback list
106 void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
109 * @brief Gets the callback list that is called when the frame is displayed on the display.
111 * @param[out] callbacks The callback list
113 void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
116 * @brief Sets whether rendering should be skipped or not.
117 * @param[in] skip true if rendering should be skipped.
119 void SetSkipRendering(bool skip);
122 * @brief Query whether rendering should be skipped or not.
123 * @return true if rendering should be skipped, false otherwise.
125 bool IsRenderingSkipped() const;
128 * Set the surface rectangle when surface is resized.
130 * @param[in] scene The resized scene.
131 * @param[in] rect The retangle representing the surface.
133 void SetSurfaceRect(const Rect<int32_t>& rect);
136 * Get the surface rectangle.
138 * @return the current surface rectangle
140 const Rect<int32_t>& GetSurfaceRect() const;
143 * Set the surface orientation when surface is rotated.
145 * @param[in] scene The rotated scene.
146 * @param[in] orientation The orientation value representing the surface.
148 void SetSurfaceOrientation(int32_t orientation);
151 * Get the surface orientation.
153 * @return the current surface orientation
155 int32_t GetSurfaceOrientation() const;
158 * Query wheter the surface rect is changed or not.
159 * @return true if the surface rect is changed.
161 bool IsSurfaceRectChanged();
164 Context* mContext; ///< The context holding the GL state of rendering for the scene, not owned
166 // Render instructions describe what should be rendered during RenderManager::RenderScene()
167 // Update manager updates instructions for the next frame while we render the current one
169 RenderInstructionContainer mInstructions; ///< Render instructions for the scene
171 Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks; ///< Frame rendered callbacks
172 Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks
174 bool mSkipRendering; ///< A flag to skip rendering
176 Rect<int32_t> mSurfaceRect; ///< The rectangle of surface which is related ot this scene.
177 int32_t mSurfaceOrientation; ///< The orientation of surface which is related of this scene
178 bool mSurfaceRectChanged; ///< The flag of surface's rectangle is changed when is resized, moved or rotated.
182 inline void AddFrameRenderedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
184 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
186 // Reserve some memory inside the message queue
187 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
189 // Construct message in the message queue memory; note that delete should not be called on the return value
190 new(slot) LocalType(&scene, &Scene::AddFrameRenderedCallback, const_cast<CallbackBase*>(callback), frameId);
193 inline void AddFramePresentedCallbackMessage(EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId)
195 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
197 // Reserve some memory inside the message queue
198 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
200 // Construct message in the message queue memory; note that delete should not be called on the return value
201 new(slot) LocalType(&scene, &Scene::AddFramePresentedCallback, const_cast<CallbackBase*>(callback), frameId);
204 inline void SetSurfaceRectMessage(EventThreadServices& eventThreadServices, const Scene& scene, const Rect<int32_t>& rect)
206 using LocalType = MessageValue1<Scene, Rect<int32_t> >;
208 // Reserve some memory inside the message queue
209 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
211 // Construct message in the message queue memory; note that delete should not be called on the return value
212 new(slot) LocalType(&scene, &Scene::SetSurfaceRect, rect);
215 inline void SetSurfaceOrientationMessage(EventThreadServices& eventThreadServices, const Scene& scene, int32_t orientation)
217 using LocalType = MessageValue1<Scene, int32_t>;
219 // Reserve some memory inside the message queue
220 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
222 // Construct message in the message queue memory; note that delete should not be called on the return value
223 new(slot) LocalType(&scene, &Scene::SetSurfaceOrientation, orientation);
226 } // namespace SceneGraph
228 } // namespace Internal
232 #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H