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