2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/events/event-processor.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/events/event.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/hover-event-integ.h>
28 #include <dali/internal/event/events/gesture-event-processor.h>
29 #include <dali/internal/common/core-impl.h>
30 #include <dali/internal/event/common/notification-manager.h>
32 using Dali::Integration::Event;
40 namespace // unnamed namespace
43 static const std::size_t MAX_MESSAGE_SIZE = std::max( sizeof(Integration::TouchEvent),
44 std::max( sizeof(Integration::KeyEvent), sizeof(Integration::WheelEvent) ) );
46 static const std::size_t INITIAL_MIN_CAPACITY = 4;
48 static const std::size_t INITIAL_BUFFER_SIZE = MAX_MESSAGE_SIZE * INITIAL_MIN_CAPACITY;
50 } // unnamed namespace
52 EventProcessor::EventProcessor( Scene& scene, GestureEventProcessor& gestureEventProcessor )
54 mTouchEventProcessor( scene ),
55 mHoverEventProcessor( scene ),
56 mGestureEventProcessor( gestureEventProcessor ),
57 mKeyEventProcessor( scene ),
58 mWheelEventProcessor( scene ),
59 mEventQueue0( INITIAL_BUFFER_SIZE ),
60 mEventQueue1( INITIAL_BUFFER_SIZE ),
61 mCurrentEventQueue( &mEventQueue0 )
65 EventProcessor::~EventProcessor()
67 for( MessageBuffer::Iterator iter = mEventQueue0.Begin(); iter.IsValid(); iter.Next() )
69 // Call virtual destructor explictly; since delete will not be called after placement new
70 Event* event = reinterpret_cast< Event* >( iter.Get() );
74 for( MessageBuffer::Iterator iter = mEventQueue1.Begin(); iter.IsValid(); iter.Next() )
76 // Call virtual destructor explictly; since delete will not be called after placement new
77 Event* event = reinterpret_cast< Event* >( iter.Get() );
82 void EventProcessor::QueueEvent( const Event& event )
88 typedef Integration::TouchEvent DerivedType;
90 // Reserve some memory inside the message queue
91 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
93 // Construct message in the message queue memory; note that delete should not be called on the return value
94 new (slot) DerivedType( static_cast<const DerivedType&>(event) );
101 typedef Integration::HoverEvent DerivedType;
103 // Reserve some memory inside the message queue
104 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
106 // Construct message in the message queue memory; note that delete should not be called on the return value
107 new (slot) DerivedType( static_cast<const DerivedType&>(event) );
114 typedef Integration::KeyEvent DerivedType;
116 // Reserve some memory inside the message queue
117 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
119 // Construct message in the message queue memory; note that delete should not be called on the return value
120 new (slot) DerivedType( static_cast<const DerivedType&>(event) );
127 typedef Integration::WheelEvent DerivedType;
129 // Reserve some memory inside the message queue
130 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
132 // Construct message in the message queue memory; note that delete should not be called on the return value
133 new (slot) DerivedType( static_cast<const DerivedType&>(event) );
140 void EventProcessor::ProcessEvents()
142 MessageBuffer* queueToProcess = mCurrentEventQueue;
144 // Switch current queue; events can be added safely while iterating through the other queue.
145 mCurrentEventQueue = ( &mEventQueue0 == mCurrentEventQueue ) ? &mEventQueue1 : &mEventQueue0;
147 for( MessageBuffer::Iterator iter = queueToProcess->Begin(); iter.IsValid(); iter.Next() )
149 Event* event = reinterpret_cast< Event* >( iter.Get() );
151 switch( event->type )
155 mTouchEventProcessor.ProcessTouchEvent( static_cast<const Integration::TouchEvent&>(*event) );
156 mGestureEventProcessor.ProcessTouchEvent(mScene, static_cast<const Integration::TouchEvent&>(*event));
162 mHoverEventProcessor.ProcessHoverEvent( static_cast<const Integration::HoverEvent&>(*event) );
168 mKeyEventProcessor.ProcessKeyEvent( static_cast<const Integration::KeyEvent&>(*event) );
174 mWheelEventProcessor.ProcessWheelEvent( static_cast<const Integration::WheelEvent&>(*event) );
178 // Call virtual destructor explictly; since delete will not be called after placement new
182 queueToProcess->Reset();
185 } // namespace Internal