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