1 /* 2 * Copyright 2022 The Android Open Source Project 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 #pragma once 18 19 #include <optional> 20 #include <set> 21 22 #include <utils/Timers.h> 23 24 #include "EventHub.h" 25 #include "InputDevice.h" 26 #include "accumulator/CursorButtonAccumulator.h" 27 #include "accumulator/MultiTouchMotionAccumulator.h" 28 #include "accumulator/TouchButtonAccumulator.h" 29 30 #include "include/gestures.h" 31 32 namespace android { 33 34 // A HardwareState struct, but bundled with a vector to contain its FingerStates, so you don't have 35 // to worry about where that memory is allocated. 36 struct SelfContainedHardwareState { 37 HardwareState state; 38 std::vector<FingerState> fingers; 39 }; 40 41 // Converts RawEvents into the HardwareState structs used by the gestures library. 42 class HardwareStateConverter { 43 public: 44 HardwareStateConverter(const InputDeviceContext& deviceContext, 45 MultiTouchMotionAccumulator& motionAccumulator); 46 47 std::optional<SelfContainedHardwareState> processRawEvent(const RawEvent& event); 48 void reset(); 49 50 private: 51 SelfContainedHardwareState produceHardwareState(nsecs_t when); 52 53 const InputDeviceContext& mDeviceContext; 54 CursorButtonAccumulator mCursorButtonAccumulator; 55 MultiTouchMotionAccumulator& mMotionAccumulator; 56 TouchButtonAccumulator mTouchButtonAccumulator; 57 int32_t mMscTimestamp = 0; 58 }; 59 60 } // namespace android 61