(PanGestures)PropertyOwner.ResetDefaultProperties is now called on PanGestures
[platform/core/uifw/dali-core.git] / dali / internal / update / gestures / scene-graph-pan-gesture.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
19
20 // EXTERNAL INCLUDES
21 #include <cstring>
22
23 // INTERNAL INCLUDES
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace SceneGraph
32 {
33
34 namespace
35 {
36 const unsigned int ARRAY_SIZE( 4u );
37 } // unnamed namespace
38
39 PanGesture* PanGesture::New()
40 {
41   return new PanGesture();
42 }
43
44 PanGesture::~PanGesture()
45 {
46 }
47
48 void PanGesture::AddGesture( const Dali::PanGesture& gesture )
49 {
50   mGestures[ mWritePosition ] = gesture;
51
52   // Set the read flag to false for the gesture we have just written.
53   // Ignore return value, we want to overwrite oldest gesture information even if it hasn't been read.
54   (void) __sync_val_compare_and_swap( &mGestures[ mWritePosition ].read, true, false );
55
56   // Update our write position.
57   ++mWritePosition;
58   mWritePosition %= ARRAY_SIZE;
59 }
60
61 void PanGesture::UpdateProperties( unsigned int nextRenderTime )
62 {
63   unsigned int time( 0u );
64   PanInfo latest;
65   bool set( false );
66
67   // Not going through array from the beginning, using it as a circular buffer and only using unread
68   // values.
69   for ( unsigned int i = 0; ( i < ARRAY_SIZE ); ++i )
70   {
71     // Copy the gesture first
72     PanInfo currentGesture;
73     currentGesture = mGestures[mReadPosition];
74
75     // If we have already read this member, then exit out of loop
76     if ( ! __sync_bool_compare_and_swap( &mGestures[mReadPosition].read, false, true ) )
77     {
78       break;
79     }
80
81     if ( currentGesture.time < time )
82     {
83       break;
84     }
85
86     latest = currentGesture;
87     time = currentGesture.time;
88     set = true;
89
90     // Update our read position.
91     ++mReadPosition;
92     mReadPosition %= ARRAY_SIZE;
93   }
94
95   if ( set )
96   {
97     mScreenPosition.Set( latest.screen.position );
98     mScreenDisplacement.Set( latest.screen.displacement );
99     mLocalPosition.Set( latest.local.position );
100     mLocalDisplacement.Set( latest.local.displacement );
101   }
102 }
103
104 const GesturePropertyVector2& PanGesture::GetScreenPositionProperty() const
105 {
106   return mScreenPosition;
107 }
108
109 const GesturePropertyVector2& PanGesture::GetScreenDisplacementProperty() const
110 {
111   return mScreenDisplacement;
112 }
113
114 const GesturePropertyVector2& PanGesture::GetLocalPositionProperty() const
115 {
116   return mLocalPosition;
117 }
118
119 const GesturePropertyVector2& PanGesture::GetLocalDisplacementProperty() const
120 {
121   return mLocalDisplacement;
122 }
123
124 void PanGesture::ResetDefaultProperties( BufferIndex updateBufferIndex )
125 {
126   mScreenPosition.Reset();
127   mScreenDisplacement.Reset();
128   mLocalPosition.Reset();
129   mLocalDisplacement.Reset();
130 }
131
132 PanGesture::PanGesture()
133 : mGestures(),
134   mWritePosition( 0 ),
135   mReadPosition( 0 )
136 {
137   mGestures.resize( ARRAY_SIZE );
138 }
139
140 } // namespace SceneGraph
141
142 } // namespace Internal
143
144 } // namespace Dali