Synchronize automated tests with other repos
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / camera-attachment-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/actor-attachments/camera-attachment-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 CameraAttachmentPtr CameraAttachment::New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode )
34 {
35   CameraAttachmentPtr attachment( new CameraAttachment( eventThreadServices ) );
36
37   // Transfer object ownership of scene-object to message
38   SceneGraph::CameraAttachment* sceneObject = CreateSceneObject();
39   AttachToNodeMessage( eventThreadServices.GetUpdateManager(), parentNode, sceneObject );
40
41   // Keep raw pointer for message passing
42   attachment->mSceneObject = sceneObject;
43
44   return attachment;
45 }
46
47 CameraAttachment::CameraAttachment( EventThreadServices& eventThreadServices )
48 : ActorAttachment( eventThreadServices ),
49   mSceneObject( NULL ),
50   mType( SceneGraph::CameraAttachment::DEFAULT_TYPE ),
51   mProjectionMode( SceneGraph::CameraAttachment::DEFAULT_MODE ),
52   mInvertYAxis( SceneGraph::CameraAttachment::DEFAULT_INVERT_Y_AXIS ),
53   mFieldOfView( SceneGraph::CameraAttachment::DEFAULT_FIELD_OF_VIEW ),
54   mAspectRatio( SceneGraph::CameraAttachment::DEFAULT_ASPECT_RATIO ),
55   mLeftClippingPlane( SceneGraph::CameraAttachment::DEFAULT_LEFT_CLIPPING_PLANE ),
56   mRightClippingPlane( SceneGraph::CameraAttachment::DEFAULT_RIGHT_CLIPPING_PLANE ),
57   mTopClippingPlane( SceneGraph::CameraAttachment::DEFAULT_TOP_CLIPPING_PLANE ),
58   mBottomClippingPlane( SceneGraph::CameraAttachment::DEFAULT_BOTTOM_CLIPPING_PLANE ),
59   mNearClippingPlane( SceneGraph::CameraAttachment::DEFAULT_NEAR_CLIPPING_PLANE ),
60   mFarClippingPlane( SceneGraph::CameraAttachment::DEFAULT_FAR_CLIPPING_PLANE ),
61   mStereoBias( SceneGraph::CameraAttachment::DEFAULT_STEREO_BIAS ),
62   mTargetPosition( SceneGraph::CameraAttachment::DEFAULT_TARGET_POSITION )
63 {
64 }
65
66 CameraAttachment::~CameraAttachment()
67 {
68 }
69
70 SceneGraph::CameraAttachment* CameraAttachment::CreateSceneObject()
71 {
72   return SceneGraph::CameraAttachment::New();
73 }
74
75 void CameraAttachment::SetType(Dali::Camera::Type type)
76 {
77   if( type != mType )
78   {
79     mType = type;
80
81     // sceneObject is being used in a separate thread; queue a message to set
82     SetTypeMessage( GetEventThreadServices(), *mSceneObject, type );
83   }
84 }
85
86 Dali::Camera::Type CameraAttachment::GetType() const
87 {
88   return mType;
89 }
90
91 void CameraAttachment::SetProjectionMode(Dali::Camera::ProjectionMode projectionMode)
92 {
93   if( ! Equals(projectionMode, mProjectionMode) )
94   {
95     mProjectionMode = projectionMode;
96
97     // sceneObject is being used in a separate thread; queue a message to set
98     SetProjectionModeMessage( GetEventThreadServices(), *mSceneObject, projectionMode );
99   }
100 }
101
102 Dali::Camera::ProjectionMode CameraAttachment::GetProjectionMode() const
103 {
104   return mProjectionMode;
105 }
106
107 void CameraAttachment::SetFieldOfView( float fieldOfView )
108 {
109   if( ! Equals(fieldOfView, mFieldOfView) )
110   {
111     mFieldOfView = fieldOfView;
112
113     // sceneObject is being used in a separate thread; queue a message to set
114     SetFieldOfViewMessage( GetEventThreadServices(), *mSceneObject, fieldOfView );
115   }
116 }
117
118 float CameraAttachment::GetFieldOfView() const
119 {
120   return mFieldOfView;
121 }
122
123 void CameraAttachment::SetAspectRatio( float aspectRatio )
124 {
125   if( ! Equals(aspectRatio, mAspectRatio) )
126   {
127     mAspectRatio = aspectRatio;
128
129     // sceneObject is being used in a separate thread; queue a message to set
130     SetAspectRatioMessage( GetEventThreadServices(), *mSceneObject, aspectRatio );
131   }
132 }
133
134 float CameraAttachment::GetAspectRatio() const
135 {
136   return mAspectRatio;
137 }
138
139 void CameraAttachment::SetStereoBias(const Vector2& stereoBias)
140 {
141   if( ! Equals(stereoBias.x, mStereoBias.x ) || ! Equals(stereoBias.y, mStereoBias.y )  )
142   {
143     mStereoBias = stereoBias;
144
145     // sceneObject is being used in a separate thread; queue a message to set
146     SetStereoBiasMessage( GetEventThreadServices(), *mSceneObject, stereoBias );
147   }
148 }
149
150 Vector2 CameraAttachment::GetStereoBias() const
151 {
152   return mStereoBias;
153 }
154
155 void CameraAttachment::SetLeftClippingPlane( float leftClippingPlane )
156 {
157   if( ! Equals(leftClippingPlane, mLeftClippingPlane ) )
158   {
159     mLeftClippingPlane = leftClippingPlane;
160
161     // sceneObject is being used in a separate thread; queue a message to set
162     SetLeftClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, leftClippingPlane );
163   }
164 }
165
166 float CameraAttachment::GetLeftClippingPlane() const
167 {
168   return mLeftClippingPlane;
169 }
170
171 void CameraAttachment::SetRightClippingPlane( float rightClippingPlane )
172 {
173   if( ! Equals(rightClippingPlane, mRightClippingPlane ) )
174   {
175     mRightClippingPlane = rightClippingPlane;
176
177     // sceneObject is being used in a separate thread; queue a message to set
178     SetRightClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, rightClippingPlane );
179   }
180 }
181
182 float CameraAttachment::GetRightClippingPlane() const
183 {
184   return mRightClippingPlane;
185 }
186
187 void CameraAttachment::SetTopClippingPlane( float topClippingPlane )
188 {
189   if( ! Equals(topClippingPlane, mTopClippingPlane ) )
190   {
191     mTopClippingPlane = topClippingPlane;
192
193     // sceneObject is being used in a separate thread; queue a message to set
194     SetTopClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, topClippingPlane );
195   }
196 }
197
198 float CameraAttachment::GetTopClippingPlane() const
199 {
200   return mTopClippingPlane;
201 }
202
203 void CameraAttachment::SetBottomClippingPlane( float bottomClippingPlane )
204 {
205   if( ! Equals(bottomClippingPlane, mBottomClippingPlane ) )
206   {
207     mBottomClippingPlane = bottomClippingPlane;
208
209     // sceneObject is being used in a separate thread; queue a message to set
210     SetBottomClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, bottomClippingPlane );
211   }
212 }
213
214 float CameraAttachment::GetBottomClippingPlane() const
215 {
216   return mBottomClippingPlane;
217 }
218
219 void CameraAttachment::SetNearClippingPlane( float nearClippingPlane )
220 {
221   if( ! Equals(nearClippingPlane, mNearClippingPlane ) )
222   {
223     mNearClippingPlane = nearClippingPlane;
224
225     // sceneObject is being used in a separate thread; queue a message to set
226     SetNearClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, nearClippingPlane );
227   }
228 }
229
230 float CameraAttachment::GetNearClippingPlane() const
231 {
232   return mNearClippingPlane;
233 }
234
235 void CameraAttachment::SetFarClippingPlane( float farClippingPlane )
236 {
237   if( ! Equals( farClippingPlane, mFarClippingPlane ) )
238   {
239     mFarClippingPlane = farClippingPlane;
240
241     // sceneObject is being used in a separate thread; queue a message to set
242     SetFarClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, farClippingPlane );
243   }
244 }
245
246 float CameraAttachment::GetFarClippingPlane() const
247 {
248   return mFarClippingPlane;
249 }
250
251 void CameraAttachment::SetTargetPosition( Vector3 targetPosition )
252 {
253   if( targetPosition != mTargetPosition )
254   {
255     mTargetPosition = targetPosition;
256
257     SetTargetPositionMessage( GetEventThreadServices(),  *mSceneObject, targetPosition );
258   }
259 }
260
261 Vector3 CameraAttachment::GetTargetPosition()
262 {
263   return mTargetPosition;
264 }
265
266 void CameraAttachment::SetInvertYAxis( bool invertYAxis )
267 {
268   if( invertYAxis != mInvertYAxis )
269   {
270     mInvertYAxis = invertYAxis;
271
272     // sceneObject is being used in a separate thread; queue a message to set
273     SetInvertYAxisMessage( GetEventThreadServices(), *mSceneObject, invertYAxis );
274   }
275 }
276
277 bool CameraAttachment::GetInvertYAxis() const
278 {
279   return mInvertYAxis;
280 }
281
282 const Matrix& CameraAttachment::GetViewMatrix() const
283 {
284   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
285
286   return sceneObject.GetViewMatrix( GetEventThreadServices().GetEventBufferIndex() );
287 }
288
289 const Matrix& CameraAttachment::GetProjectionMatrix() const
290 {
291   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
292
293   return sceneObject.GetProjectionMatrix( GetEventThreadServices().GetEventBufferIndex() );
294 }
295
296 const Matrix& CameraAttachment::GetInverseViewProjectionMatrix() const
297 {
298   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
299
300   return sceneObject.GetInverseViewProjectionMatrix( GetEventThreadServices().GetEventBufferIndex() );
301 }
302
303 const PropertyInputImpl* CameraAttachment::GetViewMatrixProperty() const
304 {
305   DALI_ASSERT_DEBUG( OnStage() );
306
307   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
308
309   return sceneObject.GetViewMatrix();
310 }
311
312 const PropertyInputImpl* CameraAttachment::GetProjectionMatrixProperty() const
313 {
314   DALI_ASSERT_DEBUG( OnStage() );
315
316   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
317
318   return sceneObject.GetProjectionMatrix();
319 }
320
321 void CameraAttachment::OnStageConnection()
322 {
323   // do nothing
324 }
325
326 void CameraAttachment::OnStageDisconnection()
327 {
328   // do nothing
329 }
330
331 } // namespace Internal
332
333 } // namespace Dali