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