1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SCENE_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SCENE_H
5 * Copyright (c) 2020 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>
37 class RenderInstructionContainer;
45 * @param[in] surface The render surface
55 * Creates a scene object in the GPU.
56 * @param[in] context The GL context
58 void Initialize( Context& context );
61 * Gets the context holding the GL state of rendering for the scene
64 Context* GetContext();
67 * Gets the render instructions for the scene
68 * @return the render instructions
70 RenderInstructionContainer& GetRenderInstructions();
73 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
75 * @param[in] callback The function to call
76 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
78 * @note A callback of the following type may be used:
80 * void MyFunction( int frameId );
82 * This callback will be deleted once it is called.
84 * @note Ownership of the callback is passed onto this class.
86 void AddFrameRenderedCallback( CallbackBase* callback, int32_t frameId );
89 * @brief Adds a callback that is called when the frame is displayed on the display.
91 * @param[in] callback The function to call
92 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
94 * @note A callback of the following type may be used:
96 * void MyFunction( int frameId );
98 * This callback will be deleted once it is called.
100 * @note Ownership of the callback is passed onto this class.
102 void AddFramePresentedCallback( CallbackBase* callback, int32_t frameId );
105 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
107 * @param[out] callbacks The callback list
109 void GetFrameRenderedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
112 * @brief Gets the callback list that is called when the frame is displayed on the display.
114 * @param[out] callbacks The callback list
116 void GetFramePresentedCallback( Dali::Integration::Scene::FrameCallbackContainer& callbacks );
119 * Set the surface orientation when surface is rotated.
121 * @param[in] scene The rotated scene.
122 * @param[in] orientation The orientation value representing the surface.
124 void SetSurfaceOrientation( int orientation );
127 * Get the surface orientation.
129 * @param[in] scene The rotated scene.
130 * @return the current surface orientation
132 int GetSurfaceOrientation() const;
136 Context* mContext; ///< The context holding the GL state of rendering for the scene, not owned
138 // Render instructions describe what should be rendered during RenderManager::RenderScene()
139 // Update manager updates instructions for the next frame while we render the current one
141 RenderInstructionContainer mInstructions; ///< Render instructions for the scene
143 Dali::Integration::Scene::FrameCallbackContainer mFrameRenderedCallbacks; ///< Frame rendered callbacks
144 Dali::Integration::Scene::FrameCallbackContainer mFramePresentedCallbacks; ///< Frame presented callbacks
146 int mSurfaceOrientation;
150 inline void AddFrameRenderedCallbackMessage( EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId )
152 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
154 // Reserve some memory inside the message queue
155 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
157 // Construct message in the message queue memory; note that delete should not be called on the return value
158 new (slot) LocalType( &scene, &Scene::AddFrameRenderedCallback, const_cast< CallbackBase* >( callback ), frameId );
161 inline void AddFramePresentedCallbackMessage( EventThreadServices& eventThreadServices, const Scene& scene, const CallbackBase* callback, int32_t frameId )
163 using LocalType = MessageValue2<Scene, CallbackBase*, int32_t>;
165 // Reserve some memory inside the message queue
166 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
168 // Construct message in the message queue memory; note that delete should not be called on the return value
169 new (slot) LocalType( &scene, &Scene::AddFramePresentedCallback, const_cast< CallbackBase* >( callback ), frameId );
172 inline void SetSurfaceOrientationMessage( EventThreadServices& eventThreadServices, const Scene& scene, int orientation )
174 using LocalType = MessageValue1<Scene, int>;
176 // Reserve some memory inside the message queue
177 uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
179 // Construct message in the message queue memory; note that delete should not be called on the return value
180 new (slot) LocalType( &scene, &Scene::SetSurfaceOrientation, orientation );
183 } // namespace SceneGraph
185 } // namespace Internal
190 #endif // DALI_INTERNAL_SCENE_GRAPH_SCENE_H