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