[dali_1.0.17] Merge branch 'tizen'
[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/internal/common/message.h>
23 #include <dali/internal/render/common/post-process-resource-dispatcher.h>
24 #include <dali/internal/render/gl-resources/bitmap-texture.h>
25 #include <dali/internal/update/common/double-buffered.h>
26 #include <dali/internal/update/resources/resource-manager-declarations.h>
27 #include <dali/public-api/math/rect.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
44 namespace SceneGraph
45 {
46 class Renderer;
47 class RenderQueue;
48 class RenderMaterial;
49 class TextureCache;
50 class RenderInstruction;
51 class RenderInstructionContainer;
52 class RenderTracker;
53 class Shader;
54
55 /**
56  * RenderManager is responsible for rendering the result of the previous "update", which
57  * is provided in a RenderCommand during UpdateManager::Update().
58  */
59 class RenderManager : public PostProcessResourceDispatcher
60 {
61 public:
62
63   /**
64    * Construct a new RenderManager.
65    * @param[in]  glAbstraction The GL abstraction used for rendering.
66    * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
67    */
68   static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
69
70   /**
71    * Non-virtual destructor; not intended as a base class
72    */
73   ~RenderManager();
74
75   /**
76    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
77    * @return The render queue.
78    */
79   RenderQueue& GetRenderQueue();
80
81   /**
82    * Retrieve the texture cache. Messages should only be sent to this from the update thread,
83    * accessor methods should only be used from the render thread.
84    * @return The texture cache
85    */
86   TextureCache& GetTextureCache();
87
88   /**
89    * Retrieves the context. Can only be called inside render thread
90    * TODO remove this when programs are initialized in render thread
91    * @return reference to the context
92    */
93   Context& GetContext();
94
95   /**
96    * @copydoc Dali::Integration::Core::ContextCreated()
97    */
98   void ContextCreated();
99
100   /**
101    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
102    */
103   void ContextDestroyed();
104
105   /**
106    * Dispatch requests onto the postProcessResourcesQueue
107    * @param[in] request The request to dispatch
108    */
109   virtual void DispatchPostProcessRequest(ResourcePostProcessRequest& request);
110
111   /**
112    * Retrieve the render instructions; these should be set during each "update" traversal.
113    * @return The render instruction container.
114    */
115   RenderInstructionContainer& GetRenderInstructionContainer();
116
117   // The following methods should be called via RenderQueue messages
118
119   /**
120    * Set the background color i.e. the glClear color used at the beginning of each frame.
121    * @param[in] color The new background color.
122    */
123   void SetBackgroundColor( const Vector4& color );
124
125   /*
126    * Set the frame time delta (time elapsed since the last frame.
127    * @param[in] deltaTime the delta time
128    */
129   void SetFrameDeltaTime( float deltaTime );
130
131   /**
132    * Returns the rectangle for the default surface (probably the application window).
133    * @return Rectangle for the surface.
134    */
135   void SetDefaultSurfaceRect( const Rect<int>& rect );
136
137   /**
138    * Add a Renderer to the render manager.
139    * @param[in] renderer The renderer to add.
140    * @post renderer is owned by RenderManager
141    */
142   void AddRenderer( Renderer* renderer );
143
144   /**
145    * Remove a Renderer from the render manager.
146    * @param[in] renderer The renderer to remove.
147    * @post renderer is destroyed.
148    */
149   void RemoveRenderer( Renderer* renderer );
150
151   /**
152    * Adds a RenderMaterial to the render manager for MeshRenderers to use.
153    * The RenderManager takes ownership of the material
154    * @param[in] renderMaterial
155    * @post renderMaterial is owned by RenderManager
156    */
157   void AddRenderMaterial( RenderMaterial* renderMaterial );
158
159   /**
160    * Removes a RenderMaterial from the RenderManager
161    * RenderManager will destroy the material
162    * @pre renderManager owns the materail
163    * @param[in] renderMaterial
164    * @post renderMaterial is destroyed
165    */
166   void RemoveRenderMaterial( RenderMaterial* renderMaterial );
167
168   /**
169    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
170    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
171    * object, usually an offscreen render task.
172    * @param[in] renderTracker The render tracker
173    */
174   void AddRenderTracker( RenderTracker* renderTracker );
175
176   /**
177    * Removes a render tracker from the RenderManager.
178    * @param[in] renderTracker The render tracker to remove.
179    */
180   void RemoveRenderTracker( RenderTracker* renderTracker );
181
182   /**
183    * Set the default shader that is to be used in absence of custom shader
184    * @param[in] shader that is the default one
185    */
186   void SetDefaultShader( Shader* shader );
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__