xref: /aosp_15_r20/frameworks/native/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2019 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 <input/DisplayViewport.h>
20 #include <stdint.h>
21 #include <ui/Rotation.h>
22 
23 #include "EventHub.h"
24 #include "InputListener.h"
25 #include "InputReaderContext.h"
26 
27 namespace android {
28 
29 ui::Rotation getInverseRotation(ui::Rotation orientation);
30 
31 void rotateDelta(ui::Rotation orientation, float* deltaX, float* deltaY);
32 
33 // Returns true if the pointer should be reported as being down given the specified
34 // button states.  This determines whether the event is reported as a touch event.
35 bool isPointerDown(int32_t buttonState);
36 
37 [[nodiscard]] std::list<NotifyArgs> synthesizeButtonKeys(
38         InputReaderContext* context, int32_t action, nsecs_t when, nsecs_t readTime,
39         int32_t deviceId, uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
40         int32_t lastButtonState, int32_t currentButtonState);
41 
42 // For devices connected over Bluetooth, although they may produce events at a consistent rate,
43 // the events might end up reaching Android in a "batched" manner through the Bluetooth
44 // stack, where a few events may be clumped together and processed around the same time.
45 // In this case, if the input device or its driver does not send or process the actual event
46 // generation timestamps, the event time will set to whenever the kernel received the event.
47 // When the timestamp deltas are minuscule for these batched events, any changes in x or y
48 // coordinates result in extremely large instantaneous velocities, which can negatively impact
49 // user experience. To avoid this, we augment the timestamps so that subsequent event timestamps
50 // differ by at least a minimum delta value.
51 std::tuple<nsecs_t /*eventTime*/, nsecs_t /*readTime*/> applyBluetoothTimestampSmoothening(
52         const InputDeviceIdentifier& identifier, nsecs_t currentEventTime, nsecs_t readTime,
53         nsecs_t lastEventTime);
54 
55 } // namespace android
56