[dali_1.0.19] Merge branch 'release19'
[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) 2014 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/internal/common/message.h>
24 #include <dali/internal/render/common/post-process-resource-dispatcher.h>
25 #include <dali/internal/render/gl-resources/bitmap-texture.h>
26 #include <dali/internal/update/common/double-buffered.h>
27 #include <dali/internal/update/resources/resource-manager-declarations.h>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 class GlAbstraction;
35 class RenderStatus;
36 }
37
38 struct Vector4;
39
40 namespace Internal
41 {
42 class Context;
43 class ProgramCache;
44
45 namespace SceneGraph
46 {
47 class Renderer;
48 class RenderQueue;
49 class RenderMaterial;
50 class TextureCache;
51 class RenderInstruction;
52 class RenderInstructionContainer;
53 class RenderTracker;
54 class Shader;
55
56 /**
57  * RenderManager is responsible for rendering the result of the previous "update", which
58  * is provided in a RenderCommand during UpdateManager::Update().
59  */
60 class RenderManager : public PostProcessResourceDispatcher
61 {
62 public:
63
64   /**
65    * Construct a new RenderManager.
66    * @param[in]  glAbstraction The GL abstraction used for rendering.
67    * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
68    */
69   static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
70
71   /**
72    * Non-virtual destructor; not intended as a base class
73    */
74   ~RenderManager();
75
76   /**
77    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
78    * @return The render queue.
79    */
80   RenderQueue& GetRenderQueue();
81
82   /**
83    * Retrieve the texture cache. Messages should only be sent to this from the update thread,
84    * accessor methods should only be used from the render thread.
85    * @return The texture cache
86    */
87   TextureCache& GetTextureCache();
88
89   /**
90    * @copydoc Dali::Integration::Core::ContextCreated()
91    */
92   void ContextCreated();
93
94   /**
95    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
96    */
97   void ContextDestroyed();
98
99   /**
100    * Dispatch requests onto the postProcessResourcesQueue
101    * @param[in] request The request to dispatch
102    */
103   virtual void DispatchPostProcessRequest(ResourcePostProcessRequest& request);
104
105   /**
106    * Retrieve the render instructions; these should be set during each "update" traversal.
107    * @return The render instruction container.
108    */
109   RenderInstructionContainer& GetRenderInstructionContainer();
110
111   // The following methods should be called via RenderQueue messages
112
113   /**
114    * Set the background color i.e. the glClear color used at the beginning of each frame.
115    * @param[in] color The new background color.
116    */
117   void SetBackgroundColor( const Vector4& color );
118
119   /*
120    * Set the frame time delta (time elapsed since the last frame.
121    * @param[in] deltaTime the delta time
122    */
123   void SetFrameDeltaTime( float deltaTime );
124
125   /**
126    * Returns the rectangle for the default surface (probably the application window).
127    * @return Rectangle for the surface.
128    */
129   void SetDefaultSurfaceRect( const Rect<int>& rect );
130
131   /**
132    * Add a Renderer to the render manager.
133    * @param[in] renderer The renderer to add.
134    * @post renderer is owned by RenderManager
135    */
136   void AddRenderer( Renderer* renderer );
137
138   /**
139    * Remove a Renderer from the render manager.
140    * @param[in] renderer The renderer to remove.
141    * @post renderer is destroyed.
142    */
143   void RemoveRenderer( Renderer* renderer );
144
145   /**
146    * Adds a RenderMaterial to the render manager for MeshRenderers to use.
147    * The RenderManager takes ownership of the material
148    * @param[in] renderMaterial
149    * @post renderMaterial is owned by RenderManager
150    */
151   void AddRenderMaterial( RenderMaterial* renderMaterial );
152
153   /**
154    * Removes a RenderMaterial from the RenderManager
155    * RenderManager will destroy the material
156    * @pre renderManager owns the materail
157    * @param[in] renderMaterial
158    * @post renderMaterial is destroyed
159    */
160   void RemoveRenderMaterial( RenderMaterial* renderMaterial );
161
162   /**
163    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
164    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
165    * object, usually an offscreen render task.
166    * @param[in] renderTracker The render tracker
167    */
168   void AddRenderTracker( RenderTracker* renderTracker );
169
170   /**
171    * Removes a render tracker from the RenderManager.
172    * @param[in] renderTracker The render tracker to remove.
173    */
174   void RemoveRenderTracker( RenderTracker* renderTracker );
175
176   /**
177    * Set the default shader that is to be used in absence of custom shader
178    * @param[in] shader that is the default one
179    */
180   void SetDefaultShader( Shader* shader );
181
182   /**
183    * returns the Program controller for sending program messages
184    * @return the ProgramController
185    */
186   ProgramCache* GetProgramCache();
187
188   // This method should be called from Core::Render()
189
190   /**
191    * Renders the results of the previous "update" traversal.
192    * @param[out] status contains the flag that indicates if render instructions exist
193    * @return true if a further update is required
194    */
195   bool Render( Integration::RenderStatus& status );
196
197 private:
198
199   /**
200    * Helper to process a single RenderInstruction.
201    * @param[in] instruction A description of the rendering operation.
202    * @param[in] defaultShader default shader to use.
203    * @param[in] elapsedTime from previous render.
204    */
205   void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
206
207 private:
208
209   /**
210    * Construct a new RenderManager.
211    */
212   RenderManager();
213
214   // Undefined
215   RenderManager( const RenderManager& );
216
217   // Undefined
218   RenderManager& operator=( const RenderManager& rhs );
219
220 private:
221
222   struct Impl;
223   Impl* mImpl;
224
225 };
226
227 } // namespace SceneGraph
228
229 } // namespace Internal
230
231 } // namespace Dali
232
233 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__