[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-manager.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
3
4 /*
5  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/graphics-api/graphics-controller.h>
23 #include <dali/integration-api/core-enumerations.h>
24 #include <dali/internal/common/shader-saver.h>
25 #include <dali/internal/event/rendering/texture-impl.h>
26 #include <dali/internal/render/renderers/render-renderer.h>
27 #include <dali/internal/render/renderers/render-vertex-buffer.h>
28 #include <dali/public-api/math/rect.h>
29
30 #include <dali/graphics-api/graphics-texture-upload-helper.h> // for Graphics::UploadParams
31
32 namespace Dali
33 {
34 namespace Integration
35 {
36 class RenderStatus;
37 class Scene;
38 } // namespace Integration
39
40 struct Vector4;
41
42 namespace Internal
43 {
44 class ShaderSaver;
45
46 namespace Render
47 {
48 class FrameBuffer;
49 class Renderer;
50 struct Sampler;
51 class RenderTracker;
52 class Geometry;
53 class Texture;
54 } // namespace Render
55
56 namespace SceneGraph
57 {
58 class RenderQueue;
59 class RenderInstruction;
60 class RenderInstructionContainer;
61 class Shader;
62 class Scene;
63
64 /**
65  * RenderManager is responsible for rendering the result of the previous "update", which
66  * is provided in a RenderCommand during UpdateManager::Update().
67  */
68 class RenderManager
69 {
70 public:
71   /**
72    * Construct a new RenderManager.
73    * @param[in]  graphicsController         The graphics controller for a given rendering backend
74    * @param[in]  depthBufferAvailable       Whether the depth buffer is available
75    * @param[in]  stencilBufferAvailable     Whether the stencil buffer is available
76    */
77   static RenderManager* New(Graphics::Controller&               graphicsController,
78                             Integration::DepthBufferAvailable   depthBufferAvailable,
79                             Integration::StencilBufferAvailable stencilBufferAvailable,
80                             Integration::PartialUpdateAvailable partialUpdateAvailable);
81
82   /**
83    * Non-virtual destructor; not intended as a base class
84    */
85   ~RenderManager();
86
87   /**
88    * The graphics context is being shutdown. Clean down any outstanding graphics resources.
89    */
90   void ContextDestroyed();
91
92   /**
93    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
94    * @return The render queue.
95    */
96   RenderQueue& GetRenderQueue();
97
98   /**
99    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
100    * caching and saving.
101    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
102    * @note This should be called during core initialisation if shader binaries are to be used.
103    */
104   void SetShaderSaver(ShaderSaver& upstream);
105
106   // The foltlowing methods should be called via RenderQueue messages
107
108   /*
109    * Set the frame time delta (time elapsed since the last frame.
110    * @param[in] deltaTime the delta time
111    */
112   void SetFrameDeltaTime(float deltaTime);
113
114   /**
115    * Add a Renderer to the render manager.
116    * @param[in] renderer The renderer to add.
117    * @post renderer is notionally owned by RenderManager
118    */
119   void AddRenderer(const Render::RendererKey& renderer);
120
121   /**
122    * Remove a Renderer from the render manager.
123    * @param[in] renderer The renderer to remove.
124    * @post renderer is destroyed.
125    */
126   void RemoveRenderer(const Render::RendererKey& renderer);
127
128   /**
129    * Add a sampler to the render manager.
130    * @param[in] sampler The sampler to add.
131    * @post sampler is owned by RenderManager
132    */
133   void AddSampler(OwnerPointer<Render::Sampler>& sampler);
134
135   /**
136    * Remove a sampler from the render manager.
137    * @param[in] sampler The sampler to remove.
138    * @post sampler is destroyed.
139    */
140   void RemoveSampler(Render::Sampler* sampler);
141
142   /**
143    * Set minification and magnification filter modes for a sampler
144    * @param[in] minFilterMode Filter mode to use when the texture is minificated
145    * @param[in] magFilterMode Filter mode to use when the texture is magnified
146    */
147   void SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode);
148
149   /**
150    * Set wrapping mode for a sampler
151    * @param[in] rWrapMode Wrap mode in the z direction
152    * @param[in] uWrapMode Wrap mode in the x direction
153    * @param[in] vWrapMode Wrap mode in the y direction
154    */
155   void SetWrapMode(Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode);
156
157   /**
158    * Add a property buffer to the render manager.
159    * @param[in] vertexBuffer The property buffer to add.
160    * @post propertBuffer is owned by RenderManager
161    */
162   void AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& vertexBuffer);
163
164   /**
165    * Remove a property buffer from the render manager.
166    * @param[in] vertexBuffer The property buffer to remove.
167    * @post vertexBuffer is destroyed.
168    */
169   void RemoveVertexBuffer(Render::VertexBuffer* vertexBuffer);
170
171   /**
172    * Add a geometry to the render manager.
173    * @param[in] geometry The geometry to add.
174    * @post geometry is owned by RenderManager
175    */
176   void AddGeometry(OwnerPointer<Render::Geometry>& geometry);
177
178   /**
179    * Remove a geometry from the render manager.
180    * @param[in] geometry The geometry to remove.
181    * @post geometry is destroyed.
182    */
183   void RemoveGeometry(Render::Geometry* geometry);
184
185   /**
186    * Adds a property buffer to a geometry from the render manager.
187    * @param[in] geometry The geometry
188    * @param[in] vertexBuffer The property buffer to remove.
189    */
190   void AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
191
192   /**
193    * Remove a property buffer from a Render::Geometry from the render manager.
194    * @param[in] geometry The geometry
195    * @param[in] vertexBuffer The property buffer to remove.
196    * @post property buffer is destroyed.
197    */
198   void RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
199
200   /**
201    * Sets the format of an existing property buffer
202    * @param[in] vertexBuffer The property buffer.
203    * @param[in] format The new format of the buffer
204    */
205   void SetVertexBufferFormat(Render::VertexBuffer* vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format);
206
207   /**
208    * Sets the data of an existing property buffer
209    * @param[in] vertexBuffer The property buffer.
210    * @param[in] data The new data of the buffer
211    * @param[in] size The new size of the buffer
212    */
213   void SetVertexBufferData(Render::VertexBuffer* vertexBuffer, OwnerPointer<Vector<uint8_t>>& data, uint32_t size);
214
215   /**
216    * Sets vertex buffer update callback
217    * @param vertexBuffer
218    * @param callback
219    */
220   void SetVertexBufferUpdateCallback(Render::VertexBuffer* vertexBuffer, Dali::VertexBufferUpdateCallback* callback);
221
222   /**
223    * Sets the data for the index buffer of an existing geometry
224    * @param[in] geometry The geometry
225    * @param[in] data A vector containing the indices
226    */
227   void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint16ContainerType& data);
228
229   /**
230    * Sets the data for the index buffer of an existing geometry
231    * @param[in] geometry The geometry
232    * @param[in] data A vector containing the indices
233    */
234   void SetIndexBuffer(Render::Geometry* geometry, Render::Geometry::Uint32ContainerType& data);
235
236   /**
237    * Set the geometry type of an existing render geometry
238    * @param[in] geometry The render geometry
239    * @param[in] geometryType The new geometry type
240    */
241   void SetGeometryType(Render::Geometry* geometry, uint32_t geometryType);
242
243   /**
244    * Adds a texture to the render manager
245    * @param[in] texture The texture to add
246    */
247   void AddTexture(const Render::TextureKey& texture);
248
249   /**
250    * Removes a texture from the render manager
251    * @param[in] texture The texture to remove
252    */
253   void RemoveTexture(const Render::TextureKey& texture);
254
255   /**
256    * Uploads data to an existing texture
257    * @param[in] texture The texture
258    * @param[in] pixelData The pixel data object
259    * @param[in] params The parameters for the upload
260    */
261   void UploadTexture(const Render::TextureKey& texture, PixelDataPtr pixelData, const Graphics::UploadParams& params);
262
263   /**
264    * Generates mipmaps for a given texture
265    * @param[in] texture The texture
266    */
267   void GenerateMipmaps(const Render::TextureKey& texture);
268
269   /**
270    * Set the texture size for a given texture
271    * @param[in] texture The texture
272    * @param[in] size The texture size
273    */
274   void SetTextureSize(const Render::TextureKey& texture, const Dali::ImageDimensions& size);
275
276   /**
277    * Set the texture pixel format for a given texture
278    * @param[in] texture The texture
279    * @param[in] pixelFormat The texture pixel format
280    */
281   void SetTextureFormat(const Render::TextureKey& texture, Dali::Pixel::Format pixelFormat);
282
283   /**
284    * Sets the updated flag of a texture
285    * @param[in] texture The updated texture
286    */
287   void SetTextureUpdated(const Render::TextureKey& textureKey);
288
289   /**
290    * Adds a framebuffer to the render manager
291    * @param[in] frameBuffer The framebuffer to add
292    */
293   void AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer);
294
295   /**
296    * Removes a framebuffer from the render manager
297    * @param[in] frameBuffer The framebuffer to remove
298    */
299   void RemoveFrameBuffer(Render::FrameBuffer* frameBuffer);
300
301   /**
302    * Attaches a texture as color output to the existing frame buffer
303    * @param[in] frameBuffer The FrameBuffer
304    * @param[in] texture The texture that will be used as output when rendering
305    * @param[in] mipmapLevel The mipmap of the texture to be attached
306    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
307    */
308   void AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
309
310   /**
311    * Attaches a texture as depth output to the existing frame buffer
312    * @param[in] frameBuffer The FrameBuffer
313    * @param[in] texture The texture that will be used as output when rendering
314    * @param[in] mipmapLevel The mipmap of the texture to be attached
315    */
316   void AttachDepthTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
317
318   /**
319    * Attaches a texture as depth/stencil output to the existing frame buffer
320    * @param[in] frameBuffer The FrameBuffer
321    * @param[in] texture The texture that will be used as output when rendering
322    * @param[in] mipmapLevel The mipmap of the texture to be attached
323    */
324   void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
325
326   /**
327    * Set a multisampling level value as texture output to the existing frame buffer
328    * @param[in] frameBuffer The FrameBuffer
329    * @param[in] multiSamplingLevel The level of multisampling
330    */
331   void SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel);
332
333   /**
334    * Initializes a Scene to the render manager
335    * @param[in] scene The Scene to initialize
336    */
337   void InitializeScene(SceneGraph::Scene* scene);
338
339   /**
340    * Uninitializes a Scene to the render manager
341    * @param[in] scene The Scene to uninitialize
342    */
343   void UninitializeScene(SceneGraph::Scene* scene);
344
345   /**
346    * This is called when the surface of the scene has been replaced.
347    * @param[in] scene The scene.
348    */
349   void SurfaceReplaced(SceneGraph::Scene* scene);
350
351   /**
352    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
353    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
354    * object, usually an offscreen render task.
355    * @param[in] renderTracker The render tracker
356    */
357   void AddRenderTracker(Render::RenderTracker* renderTracker);
358
359   /**
360    * Removes a render tracker from the RenderManager.
361    * @param[in] renderTracker The render tracker to remove.
362    */
363   void RemoveRenderTracker(Render::RenderTracker* renderTracker);
364
365   // This method should be called from Core::PreRender()
366
367   /**
368    * This is called before rendering any scene in the next frame. This method should be preceded
369    * by a call up Update.
370    * Multi-threading note: this method should be called from a dedicated rendering thread.
371    * @pre The graphics implementation must be initialized
372    * @param[out] status showing whether update is required to run.
373    * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
374    */
375   void PreRender(Integration::RenderStatus& status, bool forceClear);
376
377   // This method should be called from Core::PreRender()
378
379   /**
380    * This is called before rendering any scene in the next frame. This method should be preceded
381    * by a call up Update.
382    * Multi-threading note: this method should be called from a dedicated rendering thread.
383    * @pre The graphics implementation must be initialized
384    * @param[in] scene The scene to be rendered.
385    * @param[out] damagedRects The list of damaged rects for the current render pass.
386    */
387   void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
388
389   // This method should be called from Core::RenderScene()
390
391   /**
392    * Render a scene in the next frame. This method should be preceded by a call up PreRender.
393    * This method should be called twice. The first pass to render off-screen frame buffers if any,
394    * and the second pass to render the surface.
395    * Multi-threading note: this method should be called from a dedicated rendering thread.
396    * @pre The graphics implementation must be initialized
397    * @param[out] status contains the rendering flags.
398    * @param[in] scene The scene to be rendered.
399    * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
400    */
401   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
402
403   /**
404    * Render a scene in the next frame. This method should be preceded by a call up PreRender.
405    * This method should be called twice. The first pass to render off-screen frame buffers if any,
406    * and the second pass to render the surface.
407    * Multi-threading note: this method should be called from a dedicated rendering thread.
408    * @pre The graphics implementation must be initialized
409    * @param[out] status contains the rendering flags.
410    * @param[in] scene The scene to be rendered.
411    * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
412    * @param[in] clippingRect The clipping rect for the rendered scene.
413    */
414   void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
415
416   // This method should be called from Core::PostRender()
417
418   /**
419    * This is called after rendering all the scenes in the next frame. This method should be
420    * followed by a call up RenderScene.
421    * Multi-threading note: this method should be called from a dedicated rendering thread.
422    * @pre The graphics implementation must be initialized
423    */
424   void PostRender();
425
426 private:
427   /**
428    * Construct a new RenderManager.
429    */
430   RenderManager();
431
432   // Undefined
433   RenderManager(const RenderManager&);
434
435   // Undefined
436   RenderManager& operator=(const RenderManager& rhs);
437
438 private:
439   struct Impl;
440   Impl* mImpl;
441 };
442
443 } // namespace SceneGraph
444
445 } // namespace Internal
446
447 } // namespace Dali
448
449 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H