2 * Copyright (c) 2021 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/hover-event-integ.h>
25 #include <dali/integration-api/events/key-event-integ.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/wheel-event-integ.h>
28 #include <dali/internal/common/core-impl.h>
29 #include <dali/internal/event/common/notification-manager.h>
30 #include <dali/internal/event/events/gesture-event-processor.h>
32 using Dali::Integration::Event;
38 namespace // unnamed namespace
40 static const std::size_t MAX_MESSAGE_SIZE = std::max(sizeof(Integration::TouchEvent),
41 std::max(sizeof(Integration::KeyEvent), sizeof(Integration::WheelEvent)));
43 static const std::size_t INITIAL_MIN_CAPACITY = 4;
45 static const std::size_t INITIAL_BUFFER_SIZE = MAX_MESSAGE_SIZE * INITIAL_MIN_CAPACITY;
47 } // unnamed namespace
49 EventProcessor::EventProcessor(Scene& scene, GestureEventProcessor& gestureEventProcessor)
51 mTouchEventProcessor(scene),
52 mHoverEventProcessor(scene),
53 mGestureEventProcessor(gestureEventProcessor),
54 mKeyEventProcessor(scene),
55 mWheelEventProcessor(scene),
56 mEventQueue0(INITIAL_BUFFER_SIZE),
57 mEventQueue1(INITIAL_BUFFER_SIZE),
58 mCurrentEventQueue(&mEventQueue0)
62 EventProcessor::~EventProcessor()
64 for(MessageBuffer::Iterator iter = mEventQueue0.Begin(); iter.IsValid(); iter.Next())
66 // Call virtual destructor explictly; since delete will not be called after placement new
67 Event* event = reinterpret_cast<Event*>(iter.Get());
71 for(MessageBuffer::Iterator iter = mEventQueue1.Begin(); iter.IsValid(); iter.Next())
73 // Call virtual destructor explictly; since delete will not be called after placement new
74 Event* event = reinterpret_cast<Event*>(iter.Get());
79 void EventProcessor::QueueEvent(const Event& event)
85 typedef Integration::TouchEvent DerivedType;
87 // Reserve some memory inside the message queue
88 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot(sizeof(DerivedType));
90 // Construct message in the message queue memory; note that delete should not be called on the return value
91 new(slot) DerivedType(static_cast<const DerivedType&>(event));
98 using DerivedType = Integration::HoverEvent;
100 // Reserve some memory inside the message queue
101 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot(sizeof(DerivedType));
103 // Construct message in the message queue memory; note that delete should not be called on the return value
104 new(slot) DerivedType(static_cast<const DerivedType&>(event));
111 using DerivedType = Integration::KeyEvent;
113 // Reserve some memory inside the message queue
114 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot(sizeof(DerivedType));
116 // Construct message in the message queue memory; note that delete should not be called on the return value
117 new(slot) DerivedType(static_cast<const DerivedType&>(event));
124 using DerivedType = Integration::WheelEvent;
126 // Reserve some memory inside the message queue
127 uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot(sizeof(DerivedType));
129 // Construct message in the message queue memory; note that delete should not be called on the return value
130 new(slot) DerivedType(static_cast<const DerivedType&>(event));
137 void EventProcessor::ProcessEvents()
139 MessageBuffer* queueToProcess = mCurrentEventQueue;
141 // Switch current queue; events can be added safely while iterating through the other queue.
142 mCurrentEventQueue = (&mEventQueue0 == mCurrentEventQueue) ? &mEventQueue1 : &mEventQueue0;
144 for(MessageBuffer::Iterator iter = queueToProcess->Begin(); iter.IsValid(); iter.Next())
146 Event* event = reinterpret_cast<Event*>(iter.Get());
152 Integration::TouchEvent& touchEvent = static_cast<Integration::TouchEvent&>(*event);
153 mTouchEventProcessor.ProcessTouchEvent(touchEvent);
155 mGestureEventProcessor.ProcessTouchEvent(mScene, touchEvent);
161 mHoverEventProcessor.ProcessHoverEvent(static_cast<const Integration::HoverEvent&>(*event));
167 mKeyEventProcessor.ProcessKeyEvent(static_cast<const Integration::KeyEvent&>(*event));
173 mWheelEventProcessor.ProcessWheelEvent(static_cast<const Integration::WheelEvent&>(*event));
177 // Call virtual destructor explictly; since delete will not be called after placement new
181 queueToProcess->Reset();
184 } // namespace Internal