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