2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
36 const unsigned int ARRAY_SIZE( 4u );
37 } // unnamed namespace
39 PanGesture* PanGesture::New()
41 return new PanGesture();
44 PanGesture::~PanGesture()
48 void PanGesture::AddGesture( const Dali::PanGesture& gesture )
50 mGestures[ mWritePosition ] = gesture;
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 );
56 // Update our write position.
58 mWritePosition %= ARRAY_SIZE;
61 void PanGesture::UpdateProperties( unsigned int nextRenderTime )
63 unsigned int time( 0u );
67 // Not going through array from the beginning, using it as a circular buffer and only using unread
69 for ( unsigned int i = 0; ( i < ARRAY_SIZE ); ++i )
71 // Copy the gesture first
72 PanInfo currentGesture;
73 currentGesture = mGestures[mReadPosition];
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 ) )
81 if ( currentGesture.time < time )
86 latest = currentGesture;
87 time = currentGesture.time;
90 // Update our read position.
92 mReadPosition %= ARRAY_SIZE;
97 mScreenPosition.Set( latest.screen.position );
98 mScreenDisplacement.Set( latest.screen.displacement );
99 mLocalPosition.Set( latest.local.position );
100 mLocalDisplacement.Set( latest.local.displacement );
104 const GesturePropertyVector2& PanGesture::GetScreenPositionProperty() const
106 return mScreenPosition;
109 const GesturePropertyVector2& PanGesture::GetScreenDisplacementProperty() const
111 return mScreenDisplacement;
114 const GesturePropertyVector2& PanGesture::GetLocalPositionProperty() const
116 return mLocalPosition;
119 const GesturePropertyVector2& PanGesture::GetLocalDisplacementProperty() const
121 return mLocalDisplacement;
124 void PanGesture::ResetDefaultProperties( BufferIndex updateBufferIndex )
126 mScreenPosition.Reset();
127 mScreenDisplacement.Reset();
128 mLocalPosition.Reset();
129 mLocalDisplacement.Reset();
132 PanGesture::PanGesture()
137 mGestures.resize( ARRAY_SIZE );
140 } // namespace SceneGraph
142 } // namespace Internal