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