[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
90   /**
91    * Non-virtual destructor; not intended as a base class
92    */
93   ~RenderManager();
94
95   /**
96    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
97    * @return The render queue.
98    */
99   RenderQueue& GetRenderQueue();
100
101   /**
102    * @copydoc Dali::Integration::Core::ContextCreated()
103    */
104   void ContextCreated();
105
106   /**
107    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
108    */
109   void ContextDestroyed();
110
111   /**
112    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
113    * caching and saving.
114    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
115    * @note This should be called during core initialisation if shader binaries are to be used.
116    */
117   void SetShaderSaver( ShaderSaver& upstream );
118
119   // The following methods should be called via RenderQueue messages
120
121   /*
122    * Set the frame time delta (time elapsed since the last frame.
123    * @param[in] deltaTime the delta time
124    */
125   void SetFrameDeltaTime( float deltaTime );
126
127   /**
128    * Returns the rectangle for the default surface (probably the application window).
129    * @return Rectangle for the surface.
130    */
131   void SetDefaultSurfaceRect( const Rect<int>& rect );
132
133   /**
134    * Returns the orintation for the default surface (probably the application window).
135    * @return Orientation for the surface.
136    */
137   void SetDefaultSurfaceOrientation( int orientation );
138
139   /**
140    * Add a Renderer to the render manager.
141    * @param[in] renderer The renderer to add.
142    * @post renderer is owned by RenderManager
143    */
144   void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
145
146   /**
147    * Remove a Renderer from the render manager.
148    * @param[in] renderer The renderer to remove.
149    * @post renderer is destroyed.
150    */
151   void RemoveRenderer( Render::Renderer* renderer );
152
153   /**
154    * Add a sampler to the render manager.
155    * @param[in] sampler The sampler to add.
156    * @post sampler is owned by RenderManager
157    */
158   void AddSampler( OwnerPointer< Render::Sampler >& sampler );
159
160   /**
161    * Remove a sampler from the render manager.
162    * @param[in] sampler The sampler to remove.
163    * @post sampler is destroyed.
164    */
165   void RemoveSampler( Render::Sampler* sampler );
166
167   /**
168    * Set minification and magnification filter modes for a sampler
169    * @param[in] minFilterMode Filter mode to use when the texture is minificated
170    * @param[in] magFilterMode Filter mode to use when the texture is magnified
171    */
172   void SetFilterMode( Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode );
173
174   /**
175    * Set wrapping mode for a sampler
176    * @param[in] rWrapMode Wrap mode in the z direction
177    * @param[in] uWrapMode Wrap mode in the x direction
178    * @param[in] vWrapMode Wrap mode in the y direction
179    */
180   void SetWrapMode( Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode );
181
182   /**
183    * Add a property buffer to the render manager.
184    * @param[in] propertyBuffer The property buffer to add.
185    * @post propertBuffer is owned by RenderManager
186    */
187   void AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertyBuffer );
188
189   /**
190    * Remove a property buffer from the render manager.
191    * @param[in] propertyBuffer The property buffer to remove.
192    * @post propertyBuffer is destroyed.
193    */
194   void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
195
196   /**
197    * Add a geometry to the render manager.
198    * @param[in] geometry The geometry to add.
199    * @post geometry is owned by RenderManager
200    */
201   void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
202
203   /**
204    * Remove a geometry from the render manager.
205    * @param[in] geometry The geometry to remove.
206    * @post geometry is destroyed.
207    */
208   void RemoveGeometry( Render::Geometry* geometry );
209
210   /**
211    * Adds a property buffer to a geometry from the render manager.
212    * @param[in] geometry The geometry
213    * @param[in] propertyBuffer The property buffer to remove.
214    */
215   void AttachVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
216
217   /**
218    * Remove a property buffer from a Render::Geometry from the render manager.
219    * @param[in] geometry The geometry
220    * @param[in] propertyBuffer The property buffer to remove.
221    * @post property buffer is destroyed.
222    */
223   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
224
225   /**
226    * Sets the format of an existing property buffer
227    * @param[in] propertyBuffer The property buffer.
228    * @param[in] format The new format of the buffer
229    */
230   void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format );
231
232   /**
233    * Sets the data of an existing property buffer
234    * @param[in] propertyBuffer The property buffer.
235    * @param[in] data The new data of the buffer
236    * @param[in] size The new size of the buffer
237    */
238   void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Vector<uint8_t> >& data, uint32_t size );
239
240   /**
241    * Sets the data for the index buffer of an existing geometry
242    * @param[in] geometry The geometry
243    * @param[in] data A vector containing the indices
244    */
245   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<uint16_t>& data );
246
247   /**
248    * Set the geometry type of an existing render geometry
249    * @param[in] geometry The render geometry
250    * @param[in] geometryType The new geometry type
251    */
252   void SetGeometryType( Render::Geometry* geometry, uint32_t geometryType );
253
254   /**
255    * Adds a texture to the render manager
256    * @param[in] texture The texture to add
257    */
258   void AddTexture( OwnerPointer< Render::Texture >& texture );
259
260   /**
261    * Removes a texture from the render manager
262    * @param[in] texture The texture to remove
263    */
264   void RemoveTexture( Render::Texture* texture );
265
266   /**
267    * Uploads data to an existing texture
268    * @param[in] texture The texture
269    * @param[in] pixelData The pixel data object
270    * @param[in] params The parameters for the upload
271    */
272   void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
273
274   /**
275    * Generates mipmaps for a given texture
276    * @param[in] texture The texture
277    */
278   void GenerateMipmaps( Render::Texture* texture );
279
280   /**
281    * Adds a framebuffer to the render manager
282    * @param[in] frameBuffer The framebuffer to add
283    */
284   void AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer );
285
286   /**
287    * Removes a framebuffer from the render manager
288    * @param[in] frameBuffer The framebuffer to remove
289    */
290   void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
291
292   /**
293    * Attach a texture as color output to an existing FrameBuffer
294    * @param[in] frameBuffer The FrameBuffer
295    * @param[in] texture The texture that will be used as output when rendering
296    * @param[in] mipmapLevel The mipmap of the texture to be attached
297    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
298    */
299   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
300
301   /**
302    * Initializes a Scene to the render manager
303    * @param[in] scene The Scene to initialize
304    */
305   void InitializeScene( SceneGraph::Scene* scene );
306
307   /**
308    * Uninitializes a Scene to the render manager
309    * @param[in] scene The Scene to uninitialize
310    */
311   void UninitializeScene( SceneGraph::Scene* scene );
312
313   /**
314    * This is called when the surface of the scene has been replaced.
315    * @param[in] scene The scene.
316    */
317   void SurfaceReplaced( SceneGraph::Scene* scene );
318
319   /**
320    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
321    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
322    * object, usually an offscreen render task.
323    * @param[in] renderTracker The render tracker
324    */
325   void AddRenderTracker( Render::RenderTracker* renderTracker );
326
327   /**
328    * Removes a render tracker from the RenderManager.
329    * @param[in] renderTracker The render tracker to remove.
330    */
331   void RemoveRenderTracker( Render::RenderTracker* renderTracker );
332
333   /**
334    * returns the Program controller for sending program messages
335    * @return the ProgramController
336    */
337   ProgramCache* GetProgramCache();
338
339   // This method should be called from Core::PreRender()
340
341   /**
342    * This is called before rendering any scene in the next frame. This method should be preceded
343    * by a call up Update.
344    * Multi-threading note: this method should be called from a dedicated rendering thread.
345    * @pre The GL context must have been created, and made current.
346    * @param[out] status showing whether update is required to run.
347    * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
348    * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
349    */
350   void PreRender( Integration::RenderStatus& status, bool forceClear, bool uploadOnly );
351
352   // This method should be called from Core::RenderScene()
353
354   /**
355    * Render a scene in the next frame. This method should be preceded by a call up PreRender.
356    * This method should be called twice. The first pass to render off-screen frame buffers if any,
357    * and the second pass to render the surface.
358    * Multi-threading note: this method should be called from a dedicated rendering thread.
359    * @pre The GL context must have been created, and made current.
360    * @param[in] scene The scene to be rendered.
361    * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
362    */
363   void RenderScene( Integration::Scene& scene, bool renderToFbo );
364
365   // This method should be called from Core::PostRender()
366
367   /**
368    * This is called after rendering all the scenes in the next frame. This method should be
369    * followed by a call up RenderScene.
370    * Multi-threading note: this method should be called from a dedicated rendering thread.
371    * @pre The GL context must have been created, and made current.
372    * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
373    */
374   void PostRender( bool uploadOnly );
375
376
377 private:
378
379 private:
380
381   /**
382    * Construct a new RenderManager.
383    */
384   RenderManager();
385
386   // Undefined
387   RenderManager( const RenderManager& );
388
389   // Undefined
390   RenderManager& operator=( const RenderManager& rhs );
391
392 private:
393
394   struct Impl;
395   Impl* mImpl;
396
397 };
398
399 } // namespace SceneGraph
400
401 } // namespace Internal
402
403 } // namespace Dali
404
405 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H