Merge "Support multiple window rendering" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / common / scene-impl.h
1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
3
4 /*
5  * Copyright (c) 2019 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/integration-api/scene.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <dali/integration-api/render-surface.h>
27 #include <dali/internal/common/owner-pointer.h>
28 #include <dali/internal/event/actors/layer-impl.h>
29 #include <dali/internal/event/render-tasks/render-task-defaults.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 class Layer;
38 class LayerList;
39 class CameraActor;
40 class RenderTaskList;
41 class FrameBuffer;
42
43 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
44 using ScenePtr = IntrusivePtr<Scene>;
45
46 /**
47  * @brief Scene creates a "world" that can be bound to a surface for rendering.
48  */
49 class Scene : public BaseObject, public RenderTaskDefaults
50 {
51
52 public:
53
54   /**
55    * @copydoc Dali::Integration::Scene::New
56    */
57   static ScenePtr New( Size size );
58
59   /**
60    * virtual destructor
61    */
62   virtual ~Scene();
63
64   /**
65    * @copydoc Dali::Integration::Scene::Add
66    */
67   void Add(Actor& actor);
68
69   /**
70    * @copydoc Dali::Integration::Scene::Remove
71    */
72   void Remove(Actor& actor);
73
74   /**
75    * @copydoc Dali::Integration::Scene::GetSize
76    */
77   Size GetSize() const;
78
79   /**
80    * @copydoc Dali::Integration::Scene::SetDpi
81    */
82   void SetDpi( Vector2 dpi );
83
84   /**
85    * @copydoc Dali::Integration::Scene::GetDpi
86    */
87   Vector2 GetDpi() const;
88
89   /**
90    * @copydoc Dali::Integration::Scene::GetRenderTaskList
91    */
92   RenderTaskList& GetRenderTaskList() const;
93
94   /**
95    * @copydoc Dali::Integration::Scene::GetRootLayer
96    */
97   Dali::Layer GetRootLayer() const;
98
99   /**
100    * @copydoc Dali::Integration::Scene::GetLayerCount
101    */
102   uint32_t GetLayerCount() const;
103
104   /**
105    * @copydoc Dali::Integration::Scene::GetLayer
106    */
107   Dali::Layer GetLayer(uint32_t depth) const;
108
109   /**
110    * @copydoc Dali::Integration::Scene::SetSurface
111    */
112   void SetSurface( Integration::RenderSurface& surface );
113
114   /**
115    * Retrieve the render surface the scene is binded to.
116    * @return The render surface.
117    */
118   Integration::RenderSurface* GetSurface() const;
119
120   /**
121    * Retrieve the ordered list of on-stage layers.
122    * @return The layer-list.
123    */
124   LayerList& GetLayerList() const;
125
126   /**
127    * Request that the depth tree is rebuilt
128    */
129   void RequestRebuildDepthTree();
130
131   /**
132    * Rebuilds the depth tree at the end of the event frame if
133    * it was requested this frame.
134    */
135   void RebuildDepthTree();
136
137   /**
138    * @brief Sets the background color of the render surface.
139    * @param[in] color The new background color
140    */
141   void SetBackgroundColor(Vector4 color);
142
143   /**
144    * @brief Gets the background color of the render surface.
145    * @return The background color
146    */
147   Vector4 GetBackgroundColor() const;
148
149 public:
150
151   /**
152    * From RenderTaskDefaults; retrieve the default root actor.
153    * @return The default root actor.
154    */
155   virtual Actor& GetDefaultRootActor();
156
157   /**
158    * From RenderTaskDefaults; retrieve the default camera actor.
159    * @return The default camera actor.
160    */
161   virtual CameraActor& GetDefaultCameraActor();
162
163 private:
164
165   // Constructor
166   Scene( Size size );
167
168   /**
169    * Second-phase constructor.
170    */
171   void Initialize();
172
173   // Undefined
174   Scene(const Scene&) = delete;
175
176   // Undefined
177   Scene& operator=(const Scene& rhs) = delete;
178
179 private:
180
181   Integration::RenderSurface* mSurface;
182
183   // The scene-size may be different with the surface-size
184   Size mSize;
185   Size mSurfaceSize;
186
187   Vector2 mDpi;
188
189   LayerPtr mRootLayer;
190
191   // Ordered list of currently on-stage layers
192   OwnerPointer<LayerList> mLayerList;
193
194   IntrusivePtr<CameraActor> mDefaultCamera;
195
196   // The list of render-tasks
197   IntrusivePtr<RenderTaskList> mRenderTaskList;
198
199   // The frame buffer
200   FrameBufferPtr mFrameBuffer;
201
202   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
203 };
204
205 } // Internal
206
207 // Get impl of handle
208 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
209 {
210   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
211   Dali::RefObject& object = scene.GetBaseObject();
212   return static_cast<Internal::Scene&>(object);
213 }
214
215 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
216 {
217   DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
218   const Dali::RefObject& object = scene.GetBaseObject();
219   return static_cast<const Internal::Scene&>(object);
220 }
221
222 } // Dali
223
224 #endif // DALI_INTERNAL_SCENE_H