Tizen 2.4.0 rev3 SDK Public Release
[framework/graphics/dali.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/devel-api/common/mutex.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/internal/common/shader-saver.h>
25 #include <dali/internal/render/common/post-process-resource-dispatcher.h>
26 #include <dali/internal/update/resources/resource-manager-declarations.h>
27 #include <dali/internal/render/gl-resources/gpu-buffer.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 class ShaderSaver;
45
46 namespace SceneGraph
47 {
48 class Renderer;
49 class ImageRenderer;
50 class NodeDataProvider;
51 class RenderQueue;
52 class TextureCache;
53 class RenderInstruction;
54 class RenderInstructionContainer;
55 class RenderTracker;
56 class Shader;
57 class RenderGeometry;
58 class PropertyBufferDataProvider;
59
60 /**
61  * RenderManager is responsible for rendering the result of the previous "update", which
62  * is provided in a RenderCommand during UpdateManager::Update().
63  */
64 class RenderManager : public PostProcessResourceDispatcher
65 {
66 public:
67
68   /**
69    * Construct a new RenderManager.
70    * @param[in]  glAbstraction The GL abstraction used for rendering.
71    * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
72    */
73   static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
74
75   /**
76    * Non-virtual destructor; not intended as a base class
77    */
78   ~RenderManager();
79
80   /**
81    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
82    * @return The render queue.
83    */
84   RenderQueue& GetRenderQueue();
85
86   /**
87    * Retrieve the texture cache. Messages should only be sent to this from the update thread,
88    * accessor methods should only be used from the render thread.
89    * @return The texture cache
90    */
91   TextureCache& GetTextureCache();
92
93   /**
94    * @copydoc Dali::Integration::Core::ContextCreated()
95    */
96   void ContextCreated();
97
98   /**
99    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
100    */
101   void ContextDestroyed();
102
103   /**
104    * Dispatch requests onto the postProcessResourcesQueue
105    * @param[in] request The request to dispatch
106    */
107   virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
108
109   /**
110    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
111    * caching and saving.
112    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
113    * @note This should be called during core initialisation if shader binaries are to be used.
114    */
115   void SetShaderSaver( ShaderSaver& upstream );
116
117   /**
118    * Retrieve the render instructions; these should be set during each "update" traversal.
119    * @return The render instruction container.
120    */
121   RenderInstructionContainer& GetRenderInstructionContainer();
122
123   // The following methods should be called via RenderQueue messages
124
125   /**
126    * Set the background color i.e. the glClear color used at the beginning of each frame.
127    * @param[in] color The new background color.
128    */
129   void SetBackgroundColor( const Vector4& color );
130
131   /*
132    * Set the frame time delta (time elapsed since the last frame.
133    * @param[in] deltaTime the delta time
134    */
135   void SetFrameDeltaTime( float deltaTime );
136
137   /**
138    * Returns the rectangle for the default surface (probably the application window).
139    * @return Rectangle for the surface.
140    */
141   void SetDefaultSurfaceRect( const Rect<int>& rect );
142
143   /**
144    * Add a Renderer to the render manager.
145    * @param[in] renderer The renderer to add.
146    * @post renderer is owned by RenderManager
147    */
148   void AddRenderer( Renderer* renderer );
149
150   /**
151    * Remove a Renderer from the render manager.
152    * @param[in] renderer The renderer to remove.
153    * @post renderer is destroyed.
154    */
155   void RemoveRenderer( Renderer* renderer );
156
157   /**
158    * Add an image renderer in the render-thread.
159    * ImageRenderers are not owned by render-manager; this is just for initialization.
160    * @param[in] renderer The renderer to add.
161    * @param[in] dataProvider The Node using this image renderer.
162    */
163   void AddImageRenderer( ImageRenderer* renderer, NodeDataProvider* dataProvider );
164
165   /**
166    * Remove an image renderer in the render-thread.
167    * ImageRenderers are not owned by render-manager; this is just for GL cleanup.
168    * @param[in] renderer The renderer to remove.
169    */
170   void RemoveImageRenderer( ImageRenderer* renderer );
171
172   /**
173    * Add a geometry to the render manager.
174    * @param[in] geometry The geometry to add.
175    * @post geometry is owned by RenderManager
176    */
177   void AddGeometry( RenderGeometry* geometry );
178
179   /**
180    * Remove a geometry from the render manager.
181    * @param[in] geometry The geometry to remove.
182    * @post geometry is destroyed.
183    */
184   void RemoveGeometry( RenderGeometry* geometry );
185
186   /**
187    * Adds a property buffer to a RenderGeometry from the render manager.
188    * @param[in] geometry The geometry
189    * @param[in] propertyBuffer The property buffer to remove.
190    * @param[in] target Specifies the type of the buffer
191    * @param[in] usage Specifies how will the buffer be used
192    */
193   void AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage );
194
195   /**
196    * Remove a property buffer from a RenderGeometry from the render manager.
197    * @param[in] geometry The geometry
198    * @param[in] propertyBuffer The property buffer to remove.
199    * @post property buffer is destroyed.
200    */
201   void RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer );
202
203   /**
204    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
205    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
206    * object, usually an offscreen render task.
207    * @param[in] renderTracker The render tracker
208    */
209   void AddRenderTracker( RenderTracker* renderTracker );
210
211   /**
212    * Removes a render tracker from the RenderManager.
213    * @param[in] renderTracker The render tracker to remove.
214    */
215   void RemoveRenderTracker( RenderTracker* renderTracker );
216
217   /**
218    * Set the default shader that is to be used in absence of custom shader
219    * @param[in] shader that is the default one
220    */
221   void SetDefaultShader( Shader* shader );
222
223   /**
224    * returns the Program controller for sending program messages
225    * @return the ProgramController
226    */
227   ProgramCache* GetProgramCache();
228
229   // This method should be called from Core::Render()
230
231   /**
232    * Renders the results of the previous "update" traversal.
233    * @param[out] status contains the flag that indicates if render instructions exist
234    * @return true if a further update is required
235    */
236   bool Render( Integration::RenderStatus& status );
237
238   // Pixmap
239
240   /**
241    * @copydoc Dali::Integration::Core::SetPixmapYInverted()
242    */
243   void SetPixmapYInverted( bool yInverted );
244
245 private:
246
247   /**
248    * Helper to process a single RenderInstruction.
249    * @param[in] instruction A description of the rendering operation.
250    * @param[in] defaultShader default shader to use.
251    * @param[in] elapsedTime from previous render.
252    */
253   void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
254
255 private:
256
257   /**
258    * Construct a new RenderManager.
259    */
260   RenderManager();
261
262   // Undefined
263   RenderManager( const RenderManager& );
264
265   // Undefined
266   RenderManager& operator=( const RenderManager& rhs );
267
268   // Set the last frame time while locking access
269   void SetLastFrameTime();
270
271 private:
272
273   struct Impl;
274   Impl* mImpl;
275   Dali::Mutex mMutex;
276
277 };
278
279 } // namespace SceneGraph
280
281 } // namespace Internal
282
283 } // namespace Dali
284
285 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__