Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2024 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 | #include <input/Resampler.h> |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | #include <chrono> |
| 22 | #include <memory> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include <input/Input.h> |
| 26 | #include <input/InputEventBuilders.h> |
| 27 | #include <input/InputTransport.h> |
| 28 | #include <utils/Timers.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | namespace { |
| 33 | |
| 34 | using namespace std::literals::chrono_literals; |
| 35 | |
| 36 | constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION; |
| 37 | |
| 38 | struct Pointer { |
| 39 | int32_t id{0}; |
| 40 | ToolType toolType{ToolType::FINGER}; |
| 41 | float x{0.0f}; |
| 42 | float y{0.0f}; |
| 43 | bool isResampled{false}; |
| 44 | /** |
| 45 | * Converts from Pointer to PointerCoords. Enables calling LegacyResampler methods and |
| 46 | * assertions only with the relevant data for tests. |
| 47 | */ |
| 48 | operator PointerCoords() const; |
| 49 | }; |
| 50 | |
| 51 | Pointer::operator PointerCoords() const { |
| 52 | PointerCoords pointerCoords; |
| 53 | pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x); |
| 54 | pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y); |
| 55 | pointerCoords.isResampled = isResampled; |
| 56 | return pointerCoords; |
| 57 | } |
| 58 | |
| 59 | struct InputSample { |
| 60 | std::chrono::milliseconds eventTime{0}; |
| 61 | std::vector<Pointer> pointers{}; |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 62 | |
| 63 | explicit InputSample(std::chrono::milliseconds eventTime, const std::vector<Pointer>& pointers) |
| 64 | : eventTime{eventTime}, pointers{pointers} {} |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 65 | /** |
| 66 | * Converts from InputSample to InputMessage. Enables calling LegacyResampler methods only with |
| 67 | * the relevant data for tests. |
| 68 | */ |
| 69 | operator InputMessage() const; |
| 70 | }; |
| 71 | |
| 72 | InputSample::operator InputMessage() const { |
Paul Ramirez | 7dfaa32 | 2024-08-21 17:44:45 +0000 | [diff] [blame] | 73 | InputMessageBuilder messageBuilder = |
| 74 | InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/0} |
| 75 | .eventTime(std::chrono::nanoseconds{eventTime}.count()) |
| 76 | .source(AINPUT_SOURCE_TOUCHSCREEN) |
| 77 | .downTime(0); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 78 | |
Paul Ramirez | 7dfaa32 | 2024-08-21 17:44:45 +0000 | [diff] [blame] | 79 | for (const Pointer& pointer : pointers) { |
| 80 | messageBuilder.pointer( |
| 81 | PointerBuilder{pointer.id, pointer.toolType}.x(pointer.x).y(pointer.y).isResampled( |
| 82 | pointer.isResampled)); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 83 | } |
Paul Ramirez | 7dfaa32 | 2024-08-21 17:44:45 +0000 | [diff] [blame] | 84 | return messageBuilder.build(); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | struct InputStream { |
| 88 | std::vector<InputSample> samples{}; |
| 89 | int32_t action{0}; |
| 90 | DeviceId deviceId{0}; |
| 91 | /** |
| 92 | * Converts from InputStream to MotionEvent. Enables calling LegacyResampler methods only with |
| 93 | * the relevant data for tests. |
| 94 | */ |
| 95 | operator MotionEvent() const; |
| 96 | }; |
| 97 | |
| 98 | InputStream::operator MotionEvent() const { |
| 99 | const InputSample& firstSample{*samples.begin()}; |
| 100 | MotionEventBuilder motionEventBuilder = |
| 101 | MotionEventBuilder(action, AINPUT_SOURCE_CLASS_POINTER) |
| 102 | .downTime(0) |
| 103 | .eventTime(static_cast<std::chrono::nanoseconds>(firstSample.eventTime).count()) |
| 104 | .deviceId(deviceId); |
| 105 | for (const Pointer& pointer : firstSample.pointers) { |
| 106 | const PointerBuilder pointerBuilder = |
| 107 | PointerBuilder(pointer.id, pointer.toolType).x(pointer.x).y(pointer.y); |
| 108 | motionEventBuilder.pointer(pointerBuilder); |
| 109 | } |
| 110 | MotionEvent motionEvent = motionEventBuilder.build(); |
| 111 | const size_t numSamples = samples.size(); |
| 112 | for (size_t i = 1; i < numSamples; ++i) { |
| 113 | std::vector<PointerCoords> pointersCoords{samples[i].pointers.begin(), |
| 114 | samples[i].pointers.end()}; |
| 115 | motionEvent.addSample(static_cast<std::chrono::nanoseconds>(samples[i].eventTime).count(), |
| 116 | pointersCoords.data(), motionEvent.getId()); |
| 117 | } |
| 118 | return motionEvent; |
| 119 | } |
| 120 | |
| 121 | } // namespace |
| 122 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 123 | /** |
| 124 | * The testing setup assumes an input rate of 200 Hz and a display rate of 60 Hz. This implies that |
| 125 | * input events are received every 5 milliseconds, while the display consumes batched events every |
| 126 | * ~16 milliseconds. The resampler's RESAMPLE_LATENCY constant determines the resample time, which |
| 127 | * is calculated as frameTime - RESAMPLE_LATENCY. resampleTime specifies the time used for |
| 128 | * resampling. For example, if the desired frame time consumption is ~16 milliseconds, the resample |
| 129 | * time would be ~11 milliseconds. Consequenly, the last added sample to the motion event has an |
| 130 | * event time of ~11 milliseconds. Note that there are specific scenarios where resampleMotionEvent |
| 131 | * is not called with a multiple of ~16 milliseconds. These cases are primarily for data addition |
| 132 | * or to test other functionalities of the resampler. |
| 133 | * |
| 134 | * Coordinates are calculated using linear interpolation (lerp) based on the last two available |
| 135 | * samples. Linear interpolation is defined as (a + alpha*(b - a)). Let t_b and t_a be the |
| 136 | * timestamps of samples a and b, respectively. The interpolation factor alpha is calculated as |
| 137 | * (resampleTime - t_a) / (t_b - t_a). The value of alpha determines whether the resampled |
| 138 | * coordinates are interpolated or extrapolated. If alpha falls within the semi-closed interval [0, |
| 139 | * 1), the coordinates are interpolated. If alpha is greater than or equal to 1, the coordinates are |
| 140 | * extrapolated. |
| 141 | * |
| 142 | * The timeline below depics an interpolation scenario |
| 143 | * -----------------------------------|---------|---------|---------|---------- |
| 144 | * 10ms 11ms 15ms 16ms |
| 145 | * MOVE | MOVE | |
| 146 | * resampleTime frameTime |
| 147 | * Based on the timeline alpha is (11 - 10)/(15 - 10) = 1/5. Thus, coordinates are interpolated. |
| 148 | * |
| 149 | * The following timeline portrays an extrapolation scenario |
| 150 | * -------------------------|---------|---------|-------------------|---------- |
| 151 | * 5ms 10ms 11ms 16ms |
| 152 | * MOVE MOVE | | |
| 153 | * resampleTime frameTime |
| 154 | * Likewise, alpha = (11 - 5)/(10 - 5) = 6/5. Hence, coordinates are extrapolated. |
| 155 | * |
| 156 | * If a motion event was resampled, the tests will check that the following conditions are satisfied |
| 157 | * to guarantee resampling correctness: |
| 158 | * - The motion event metadata must not change. |
| 159 | * - The number of samples in the motion event must only increment by 1. |
| 160 | * - The resampled values must be at the end of motion event coordinates. |
| 161 | * - The rasamples values must be near the hand calculations. |
| 162 | * - The resampled time must be the most recent one in motion event. |
| 163 | */ |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 164 | class ResamplerTest : public testing::Test { |
| 165 | protected: |
| 166 | ResamplerTest() : mResampler(std::make_unique<LegacyResampler>()) {} |
| 167 | |
| 168 | ~ResamplerTest() override {} |
| 169 | |
| 170 | void SetUp() override {} |
| 171 | |
| 172 | void TearDown() override {} |
| 173 | |
| 174 | std::unique_ptr<Resampler> mResampler; |
| 175 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 176 | /** |
| 177 | * Checks that beforeCall and afterCall are equal except for the mutated attributes by addSample |
| 178 | * member function. |
| 179 | * @param beforeCall MotionEvent before passing it to resampleMotionEvent |
| 180 | * @param afterCall MotionEvent after passing it to resampleMotionEvent |
| 181 | */ |
| 182 | void assertMotionEventMetaDataDidNotMutate(const MotionEvent& beforeCall, |
| 183 | const MotionEvent& afterCall); |
| 184 | |
| 185 | /** |
| 186 | * Asserts the MotionEvent is resampled by checking an increment in history size and that the |
| 187 | * resampled coordinates are near the expected ones. |
| 188 | */ |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 189 | void assertMotionEventIsResampledAndCoordsNear( |
| 190 | const MotionEvent& original, const MotionEvent& resampled, |
| 191 | const std::vector<PointerCoords>& expectedCoords); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 192 | |
| 193 | void assertMotionEventIsNotResampled(const MotionEvent& original, |
| 194 | const MotionEvent& notResampled); |
| 195 | }; |
| 196 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 197 | void ResamplerTest::assertMotionEventMetaDataDidNotMutate(const MotionEvent& beforeCall, |
| 198 | const MotionEvent& afterCall) { |
| 199 | EXPECT_EQ(beforeCall.getDeviceId(), afterCall.getDeviceId()); |
| 200 | EXPECT_EQ(beforeCall.getAction(), afterCall.getAction()); |
| 201 | EXPECT_EQ(beforeCall.getActionButton(), afterCall.getActionButton()); |
| 202 | EXPECT_EQ(beforeCall.getButtonState(), afterCall.getButtonState()); |
| 203 | EXPECT_EQ(beforeCall.getFlags(), afterCall.getFlags()); |
| 204 | EXPECT_EQ(beforeCall.getEdgeFlags(), afterCall.getEdgeFlags()); |
| 205 | EXPECT_EQ(beforeCall.getClassification(), afterCall.getClassification()); |
| 206 | EXPECT_EQ(beforeCall.getPointerCount(), afterCall.getPointerCount()); |
| 207 | EXPECT_EQ(beforeCall.getMetaState(), afterCall.getMetaState()); |
| 208 | EXPECT_EQ(beforeCall.getSource(), afterCall.getSource()); |
| 209 | EXPECT_EQ(beforeCall.getXPrecision(), afterCall.getXPrecision()); |
| 210 | EXPECT_EQ(beforeCall.getYPrecision(), afterCall.getYPrecision()); |
| 211 | EXPECT_EQ(beforeCall.getDownTime(), afterCall.getDownTime()); |
| 212 | EXPECT_EQ(beforeCall.getDisplayId(), afterCall.getDisplayId()); |
| 213 | } |
| 214 | |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 215 | void ResamplerTest::assertMotionEventIsResampledAndCoordsNear( |
| 216 | const MotionEvent& original, const MotionEvent& resampled, |
| 217 | const std::vector<PointerCoords>& expectedCoords) { |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 218 | assertMotionEventMetaDataDidNotMutate(original, resampled); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 219 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 220 | const size_t originalSampleSize = original.getHistorySize() + 1; |
| 221 | const size_t resampledSampleSize = resampled.getHistorySize() + 1; |
| 222 | EXPECT_EQ(originalSampleSize + 1, resampledSampleSize); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 223 | |
| 224 | const size_t numPointers = resampled.getPointerCount(); |
| 225 | const size_t beginLatestSample = resampledSampleSize - 1; |
| 226 | for (size_t i = 0; i < numPointers; ++i) { |
| 227 | SCOPED_TRACE(i); |
| 228 | EXPECT_EQ(original.getPointerId(i), resampled.getPointerId(i)); |
| 229 | EXPECT_EQ(original.getToolType(i), resampled.getToolType(i)); |
| 230 | |
| 231 | const PointerCoords& resampledCoords = |
| 232 | resampled.getSamplePointerCoords()[beginLatestSample * numPointers + i]; |
| 233 | |
| 234 | EXPECT_TRUE(resampledCoords.isResampled); |
| 235 | EXPECT_NEAR(expectedCoords[i].getX(), resampledCoords.getX(), EPSILON); |
| 236 | EXPECT_NEAR(expectedCoords[i].getY(), resampledCoords.getY(), EPSILON); |
| 237 | } |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void ResamplerTest::assertMotionEventIsNotResampled(const MotionEvent& original, |
| 241 | const MotionEvent& notResampled) { |
| 242 | assertMotionEventMetaDataDidNotMutate(original, notResampled); |
| 243 | const size_t originalSampleSize = original.getHistorySize() + 1; |
| 244 | const size_t notResampledSampleSize = notResampled.getHistorySize() + 1; |
| 245 | EXPECT_EQ(originalSampleSize, notResampledSampleSize); |
| 246 | } |
| 247 | |
Paul Ramirez | 68ca3d1 | 2024-08-12 23:00:50 +0000 | [diff] [blame] | 248 | TEST_F(ResamplerTest, NonResampledAxesArePreserved) { |
| 249 | constexpr float TOUCH_MAJOR_VALUE = 1.0f; |
| 250 | |
| 251 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 252 | InputStream{{InputSample{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}}, |
Paul Ramirez | 68ca3d1 | 2024-08-12 23:00:50 +0000 | [diff] [blame] | 253 | AMOTION_EVENT_ACTION_MOVE}; |
| 254 | |
| 255 | constexpr std::chrono::nanoseconds eventTime{10ms}; |
| 256 | PointerCoords pointerCoords{}; |
| 257 | pointerCoords.isResampled = false; |
| 258 | pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, 2.0f); |
| 259 | pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, 2.0f); |
| 260 | pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, TOUCH_MAJOR_VALUE); |
| 261 | |
| 262 | motionEvent.addSample(eventTime.count(), &pointerCoords, motionEvent.getId()); |
| 263 | |
| 264 | const InputMessage futureSample = |
| 265 | InputSample{15ms, {{.id = 0, .x = 3.0f, .y = 4.0f, .isResampled = false}}}; |
| 266 | |
| 267 | const MotionEvent originalMotionEvent = motionEvent; |
| 268 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 269 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | 68ca3d1 | 2024-08-12 23:00:50 +0000 | [diff] [blame] | 270 | |
| 271 | EXPECT_EQ(motionEvent.getTouchMajor(0), TOUCH_MAJOR_VALUE); |
| 272 | |
| 273 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 274 | {Pointer{.id = 0, |
| 275 | .x = 2.2f, |
| 276 | .y = 2.4f, |
| 277 | .isResampled = true}}); |
Paul Ramirez | 68ca3d1 | 2024-08-12 23:00:50 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 280 | TEST_F(ResamplerTest, SinglePointerNotEnoughDataToResample) { |
| 281 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 282 | InputStream{{InputSample{5ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}}, |
| 283 | AMOTION_EVENT_ACTION_MOVE}; |
| 284 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 285 | const MotionEvent originalMotionEvent = motionEvent; |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 286 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 287 | mResampler->resampleMotionEvent(16ms, motionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 288 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 289 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 290 | } |
| 291 | |
| 292 | TEST_F(ResamplerTest, SinglePointerDifferentDeviceIdBetweenMotionEvents) { |
| 293 | MotionEvent motionFromFirstDevice = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 294 | InputStream{{InputSample{4ms, {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}}}, |
| 295 | InputSample{8ms, {{.id = 0, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 296 | AMOTION_EVENT_ACTION_MOVE, |
| 297 | .deviceId = 0}; |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 298 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 299 | mResampler->resampleMotionEvent(10ms, motionFromFirstDevice, nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 300 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 301 | MotionEvent motionFromSecondDevice = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 302 | InputStream{{InputSample{11ms, |
| 303 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 304 | AMOTION_EVENT_ACTION_MOVE, |
| 305 | .deviceId = 1}; |
| 306 | const MotionEvent originalMotionEvent = motionFromSecondDevice; |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 307 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 308 | mResampler->resampleMotionEvent(12ms, motionFromSecondDevice, nullptr); |
| 309 | // The MotionEvent should not be resampled because the second event came from a different device |
| 310 | // than the previous event. |
| 311 | assertMotionEventIsNotResampled(originalMotionEvent, motionFromSecondDevice); |
| 312 | } |
| 313 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 314 | TEST_F(ResamplerTest, SinglePointerSingleSampleInterpolation) { |
| 315 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 316 | InputStream{{InputSample{10ms, |
| 317 | {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 318 | AMOTION_EVENT_ACTION_MOVE}; |
| 319 | const InputMessage futureSample = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 320 | InputSample{15ms, {{.id = 0, .x = 2.0f, .y = 4.0f, .isResampled = false}}}; |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 321 | |
| 322 | const MotionEvent originalMotionEvent = motionEvent; |
| 323 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 324 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 325 | |
| 326 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 327 | {Pointer{.id = 0, |
| 328 | .x = 1.2f, |
| 329 | .y = 2.4f, |
| 330 | .isResampled = true}}); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | TEST_F(ResamplerTest, SinglePointerDeltaTooSmallInterpolation) { |
| 334 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 335 | InputStream{{InputSample{10ms, |
| 336 | {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 337 | AMOTION_EVENT_ACTION_MOVE}; |
| 338 | const InputMessage futureSample = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 339 | InputSample{11ms, {{.id = 0, .x = 2.0f, .y = 4.0f, .isResampled = false}}}; |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 340 | |
| 341 | const MotionEvent originalMotionEvent = motionEvent; |
| 342 | |
| 343 | mResampler->resampleMotionEvent(10'500'000ns, motionEvent, &futureSample); |
| 344 | |
| 345 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Tests extrapolation given two MotionEvents with a single sample. |
| 350 | */ |
| 351 | TEST_F(ResamplerTest, SinglePointerSingleSampleExtrapolation) { |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 352 | MotionEvent firstMotionEvent = |
| 353 | InputStream{{InputSample{5ms, {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 354 | AMOTION_EVENT_ACTION_MOVE}; |
| 355 | |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 356 | mResampler->resampleMotionEvent(9ms, firstMotionEvent, nullptr); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 357 | |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 358 | MotionEvent secondMotionEvent = |
| 359 | InputStream{{InputSample{10ms, |
| 360 | {{.id = 0, .x = 2.0f, .y = 4.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 361 | AMOTION_EVENT_ACTION_MOVE}; |
| 362 | |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 363 | const MotionEvent originalMotionEvent = secondMotionEvent; |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 364 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 365 | mResampler->resampleMotionEvent(16ms, secondMotionEvent, nullptr); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 366 | |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 367 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, secondMotionEvent, |
| 368 | {Pointer{.id = 0, |
| 369 | .x = 2.2f, |
| 370 | .y = 4.4f, |
| 371 | .isResampled = true}}); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | TEST_F(ResamplerTest, SinglePointerMultipleSampleInterpolation) { |
| 375 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 376 | InputStream{{InputSample{5ms, {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}, |
| 377 | InputSample{10ms, |
| 378 | {{.id = 0, .x = 2.0f, .y = 3.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 379 | AMOTION_EVENT_ACTION_MOVE}; |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 380 | |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 381 | const InputMessage futureSample = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 382 | InputSample{15ms, {{.id = 0, .x = 3.0f, .y = 5.0f, .isResampled = false}}}; |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 383 | |
| 384 | const MotionEvent originalMotionEvent = motionEvent; |
| 385 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 386 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 387 | |
| 388 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 389 | {Pointer{.id = 0, |
| 390 | .x = 2.2f, |
| 391 | .y = 3.4f, |
| 392 | .isResampled = true}}); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | TEST_F(ResamplerTest, SinglePointerMultipleSampleExtrapolation) { |
| 396 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 397 | InputStream{{InputSample{5ms, {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}, |
| 398 | InputSample{10ms, |
| 399 | {{.id = 0, .x = 2.0f, .y = 4.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 400 | AMOTION_EVENT_ACTION_MOVE}; |
| 401 | |
| 402 | const MotionEvent originalMotionEvent = motionEvent; |
| 403 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 404 | mResampler->resampleMotionEvent(16ms, motionEvent, nullptr); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 405 | |
| 406 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 407 | {Pointer{.id = 0, |
| 408 | .x = 2.2f, |
| 409 | .y = 4.4f, |
| 410 | .isResampled = true}}); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | TEST_F(ResamplerTest, SinglePointerDeltaTooSmallExtrapolation) { |
| 414 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 415 | InputStream{{InputSample{9ms, {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}, |
| 416 | InputSample{10ms, |
| 417 | {{.id = 0, .x = 2.0f, .y = 4.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 418 | AMOTION_EVENT_ACTION_MOVE}; |
| 419 | |
| 420 | const MotionEvent originalMotionEvent = motionEvent; |
| 421 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 422 | mResampler->resampleMotionEvent(16ms, motionEvent, nullptr); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 423 | |
| 424 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 425 | } |
| 426 | |
| 427 | TEST_F(ResamplerTest, SinglePointerDeltaTooLargeExtrapolation) { |
| 428 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 429 | InputStream{{InputSample{5ms, {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}, |
| 430 | InputSample{26ms, |
| 431 | {{.id = 0, .x = 2.0f, .y = 4.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 432 | AMOTION_EVENT_ACTION_MOVE}; |
| 433 | |
| 434 | const MotionEvent originalMotionEvent = motionEvent; |
| 435 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 436 | mResampler->resampleMotionEvent(32ms, motionEvent, nullptr); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 437 | |
| 438 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 439 | } |
| 440 | |
| 441 | TEST_F(ResamplerTest, SinglePointerResampleTimeTooFarExtrapolation) { |
| 442 | MotionEvent motionEvent = |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 443 | InputStream{{InputSample{5ms, {{.id = 0, .x = 1.0f, .y = 2.0f, .isResampled = false}}}, |
| 444 | InputSample{25ms, |
| 445 | {{.id = 0, .x = 2.0f, .y = 4.0f, .isResampled = false}}}}, |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 446 | AMOTION_EVENT_ACTION_MOVE}; |
| 447 | |
| 448 | const MotionEvent originalMotionEvent = motionEvent; |
| 449 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 450 | mResampler->resampleMotionEvent(48ms, motionEvent, nullptr); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 451 | |
| 452 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 453 | {Pointer{.id = 0, |
| 454 | .x = 2.4f, |
| 455 | .y = 4.8f, |
| 456 | .isResampled = true}}); |
| 457 | } |
| 458 | |
| 459 | TEST_F(ResamplerTest, MultiplePointerSingleSampleInterpolation) { |
| 460 | MotionEvent motionEvent = |
| 461 | InputStream{{InputSample{5ms, |
| 462 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 463 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 464 | AMOTION_EVENT_ACTION_MOVE}; |
| 465 | |
| 466 | const InputMessage futureSample = |
| 467 | InputSample{15ms, |
| 468 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 469 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}}}; |
| 470 | |
| 471 | const MotionEvent originalMotionEvent = motionEvent; |
| 472 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 473 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 474 | |
| 475 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
| 476 | {Pointer{.x = 2.2f, .y = 2.2f, .isResampled = true}, |
| 477 | Pointer{.x = 3.2f, .y = 3.2f, .isResampled = true}}); |
| 478 | } |
| 479 | |
| 480 | TEST_F(ResamplerTest, MultiplePointerSingleSampleExtrapolation) { |
| 481 | MotionEvent firstMotionEvent = |
| 482 | InputStream{{InputSample{5ms, |
| 483 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 484 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 485 | AMOTION_EVENT_ACTION_MOVE}; |
| 486 | |
| 487 | mResampler->resampleMotionEvent(9ms, firstMotionEvent, /*futureSample=*/nullptr); |
| 488 | |
| 489 | MotionEvent secondMotionEvent = |
| 490 | InputStream{{InputSample{10ms, |
| 491 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 492 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}}}}, |
| 493 | AMOTION_EVENT_ACTION_MOVE}; |
| 494 | |
| 495 | const MotionEvent originalMotionEvent = secondMotionEvent; |
| 496 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 497 | mResampler->resampleMotionEvent(16ms, secondMotionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 498 | |
| 499 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, secondMotionEvent, |
| 500 | {Pointer{.x = 3.4f, .y = 3.4f, .isResampled = true}, |
| 501 | Pointer{.x = 4.4f, .y = 4.4f, .isResampled = true}}); |
| 502 | } |
| 503 | |
| 504 | TEST_F(ResamplerTest, MultiplePointerMultipleSampleInterpolation) { |
| 505 | MotionEvent motionEvent = |
| 506 | InputStream{{InputSample{5ms, |
| 507 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 508 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}, |
| 509 | InputSample{10ms, |
| 510 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 511 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}}}}, |
| 512 | AMOTION_EVENT_ACTION_MOVE}; |
| 513 | const InputMessage futureSample = |
| 514 | InputSample{15ms, |
| 515 | {{.id = 0, .x = 5.0f, .y = 5.0f, .isResampled = false}, |
| 516 | {.id = 1, .x = 6.0f, .y = 6.0f, .isResampled = false}}}; |
| 517 | |
| 518 | const MotionEvent originalMotionEvent = motionEvent; |
| 519 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 520 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 521 | |
| 522 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
| 523 | {Pointer{.x = 3.4f, .y = 3.4f, .isResampled = true}, |
| 524 | Pointer{.x = 4.4f, .y = 4.4f, .isResampled = true}}); |
| 525 | } |
| 526 | |
| 527 | TEST_F(ResamplerTest, MultiplePointerMultipleSampleExtrapolation) { |
| 528 | MotionEvent motionEvent = |
| 529 | InputStream{{InputSample{5ms, |
| 530 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 531 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}, |
| 532 | InputSample{10ms, |
| 533 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 534 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}}}}, |
| 535 | AMOTION_EVENT_ACTION_MOVE}; |
| 536 | |
| 537 | const MotionEvent originalMotionEvent = motionEvent; |
| 538 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 539 | mResampler->resampleMotionEvent(16ms, motionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 540 | |
| 541 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
| 542 | {Pointer{.x = 3.4f, .y = 3.4f, .isResampled = true}, |
| 543 | Pointer{.x = 4.4f, .y = 4.4f, .isResampled = true}}); |
| 544 | } |
| 545 | |
| 546 | TEST_F(ResamplerTest, MultiplePointerIncreaseNumPointersInterpolation) { |
| 547 | MotionEvent motionEvent = |
| 548 | InputStream{{InputSample{10ms, |
| 549 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 550 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 551 | AMOTION_EVENT_ACTION_MOVE}; |
| 552 | |
| 553 | const InputMessage futureSample = |
| 554 | InputSample{15ms, |
| 555 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 556 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 557 | {.id = 2, .x = 5.0f, .y = 5.0f, .isResampled = false}}}; |
| 558 | |
| 559 | const MotionEvent originalMotionEvent = motionEvent; |
| 560 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 561 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 562 | |
| 563 | assertMotionEventIsResampledAndCoordsNear(originalMotionEvent, motionEvent, |
| 564 | {Pointer{.x = 1.4f, .y = 1.4f, .isResampled = true}, |
| 565 | Pointer{.x = 2.4f, .y = 2.4f, .isResampled = true}}); |
| 566 | |
| 567 | MotionEvent secondMotionEvent = |
| 568 | InputStream{{InputSample{25ms, |
| 569 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 570 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 571 | {.id = 2, .x = 5.0f, .y = 5.0f, .isResampled = false}}}}, |
| 572 | AMOTION_EVENT_ACTION_MOVE}; |
| 573 | |
| 574 | const InputMessage secondFutureSample = |
| 575 | InputSample{30ms, |
| 576 | {{.id = 0, .x = 5.0f, .y = 5.0f, .isResampled = false}, |
| 577 | {.id = 1, .x = 6.0f, .y = 6.0f, .isResampled = false}, |
| 578 | {.id = 2, .x = 7.0f, .y = 7.0f, .isResampled = false}}}; |
| 579 | |
| 580 | const MotionEvent originalSecondMotionEvent = secondMotionEvent; |
| 581 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 582 | mResampler->resampleMotionEvent(32ms, secondMotionEvent, &secondFutureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 583 | |
| 584 | assertMotionEventIsResampledAndCoordsNear(originalSecondMotionEvent, secondMotionEvent, |
| 585 | {Pointer{.x = 3.8f, .y = 3.8f, .isResampled = true}, |
| 586 | Pointer{.x = 4.8f, .y = 4.8f, .isResampled = true}, |
| 587 | Pointer{.x = 5.8f, .y = 5.8f, .isResampled = true}}); |
| 588 | } |
| 589 | |
| 590 | TEST_F(ResamplerTest, MultiplePointerIncreaseNumPointersExtrapolation) { |
| 591 | MotionEvent firstMotionEvent = |
| 592 | InputStream{{InputSample{5ms, |
| 593 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 594 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 595 | AMOTION_EVENT_ACTION_MOVE}; |
| 596 | |
| 597 | mResampler->resampleMotionEvent(9ms, firstMotionEvent, /*futureSample=*/nullptr); |
| 598 | |
| 599 | MotionEvent secondMotionEvent = |
| 600 | InputStream{{InputSample{10ms, |
| 601 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 602 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 603 | {.id = 2, .x = 5.0f, .y = 5.0f, .isResampled = false}}}}, |
| 604 | AMOTION_EVENT_ACTION_MOVE}; |
| 605 | |
| 606 | const MotionEvent secondOriginalMotionEvent = secondMotionEvent; |
| 607 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 608 | mResampler->resampleMotionEvent(16ms, secondMotionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 609 | |
| 610 | assertMotionEventIsNotResampled(secondOriginalMotionEvent, secondMotionEvent); |
| 611 | } |
| 612 | |
| 613 | TEST_F(ResamplerTest, MultiplePointerDecreaseNumPointersInterpolation) { |
| 614 | MotionEvent motionEvent = |
| 615 | InputStream{{InputSample{10ms, |
| 616 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 617 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 618 | {.id = 2, .x = 5.0f, .y = 5.0f, .isResampled = false}}}}, |
| 619 | AMOTION_EVENT_ACTION_MOVE}; |
| 620 | |
| 621 | const InputMessage futureSample = |
| 622 | InputSample{15ms, |
| 623 | {{.id = 0, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 624 | {.id = 1, .x = 5.0f, .y = 5.0f, .isResampled = false}}}; |
| 625 | |
| 626 | const MotionEvent originalMotionEvent = motionEvent; |
| 627 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 628 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 629 | |
| 630 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 631 | } |
| 632 | |
| 633 | TEST_F(ResamplerTest, MultiplePointerDecreaseNumPointersExtrapolation) { |
| 634 | MotionEvent firstMotionEvent = |
| 635 | InputStream{{InputSample{5ms, |
| 636 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 637 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}, |
| 638 | {.id = 2, .x = 3.0f, .y = 3.0f, .isResampled = false}}}}, |
| 639 | AMOTION_EVENT_ACTION_MOVE}; |
| 640 | |
| 641 | mResampler->resampleMotionEvent(9ms, firstMotionEvent, /*futureSample=*/nullptr); |
| 642 | |
| 643 | MotionEvent secondMotionEvent = |
| 644 | InputStream{{InputSample{10ms, |
| 645 | {{.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}, |
| 646 | {.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}}}}, |
| 647 | AMOTION_EVENT_ACTION_MOVE}; |
| 648 | |
| 649 | const MotionEvent secondOriginalMotionEvent = secondMotionEvent; |
| 650 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 651 | mResampler->resampleMotionEvent(16ms, secondMotionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 652 | |
| 653 | assertMotionEventIsResampledAndCoordsNear(secondOriginalMotionEvent, secondMotionEvent, |
| 654 | {Pointer{.x = 3.4f, .y = 3.4f, .isResampled = true}, |
| 655 | Pointer{.x = 4.4f, .y = 4.4f, .isResampled = true}}); |
| 656 | } |
| 657 | |
| 658 | TEST_F(ResamplerTest, MultiplePointerDifferentIdOrderInterpolation) { |
| 659 | MotionEvent motionEvent = |
| 660 | InputStream{{InputSample{10ms, |
| 661 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 662 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 663 | AMOTION_EVENT_ACTION_MOVE}; |
| 664 | |
| 665 | const InputMessage futureSample = |
| 666 | InputSample{15ms, |
| 667 | {{.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 668 | {.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}}}; |
| 669 | |
| 670 | const MotionEvent originalMotionEvent = motionEvent; |
| 671 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 672 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 673 | |
| 674 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 675 | } |
| 676 | |
| 677 | TEST_F(ResamplerTest, MultiplePointerDifferentIdOrderExtrapolation) { |
| 678 | MotionEvent firstMotionEvent = |
| 679 | InputStream{{InputSample{5ms, |
| 680 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 681 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 682 | AMOTION_EVENT_ACTION_MOVE}; |
| 683 | |
| 684 | mResampler->resampleMotionEvent(9ms, firstMotionEvent, /*futureSample=*/nullptr); |
| 685 | |
| 686 | MotionEvent secondMotionEvent = |
| 687 | InputStream{{InputSample{10ms, |
| 688 | {{.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 689 | {.id = 0, .x = 3.0f, .y = 3.0f, .isResampled = false}}}}, |
| 690 | AMOTION_EVENT_ACTION_MOVE}; |
| 691 | |
| 692 | const MotionEvent secondOriginalMotionEvent = secondMotionEvent; |
| 693 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 694 | mResampler->resampleMotionEvent(16ms, secondMotionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 695 | |
| 696 | assertMotionEventIsNotResampled(secondOriginalMotionEvent, secondMotionEvent); |
| 697 | } |
| 698 | |
| 699 | TEST_F(ResamplerTest, MultiplePointerDifferentIdsInterpolation) { |
| 700 | MotionEvent motionEvent = |
| 701 | InputStream{{InputSample{10ms, |
| 702 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 703 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 704 | AMOTION_EVENT_ACTION_MOVE}; |
| 705 | |
| 706 | const InputMessage futureSample = |
| 707 | InputSample{15ms, |
| 708 | {{.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 709 | {.id = 2, .x = 3.0f, .y = 3.0f, .isResampled = false}}}; |
| 710 | |
| 711 | const MotionEvent originalMotionEvent = motionEvent; |
| 712 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 713 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 714 | |
| 715 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 716 | } |
| 717 | |
| 718 | TEST_F(ResamplerTest, MultiplePointerDifferentIdsExtrapolation) { |
| 719 | MotionEvent firstMotionEvent = |
| 720 | InputStream{{InputSample{5ms, |
| 721 | {{.id = 0, .x = 1.0f, .y = 1.0f, .isResampled = false}, |
| 722 | {.id = 1, .x = 2.0f, .y = 2.0f, .isResampled = false}}}}, |
| 723 | AMOTION_EVENT_ACTION_MOVE}; |
| 724 | |
| 725 | mResampler->resampleMotionEvent(9ms, firstMotionEvent, /*futureSample=*/nullptr); |
| 726 | |
| 727 | MotionEvent secondMotionEvent = |
| 728 | InputStream{{InputSample{10ms, |
| 729 | {{.id = 1, .x = 4.0f, .y = 4.0f, .isResampled = false}, |
| 730 | {.id = 2, .x = 3.0f, .y = 3.0f, .isResampled = false}}}}, |
| 731 | AMOTION_EVENT_ACTION_MOVE}; |
| 732 | |
| 733 | const MotionEvent secondOriginalMotionEvent = secondMotionEvent; |
| 734 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 735 | mResampler->resampleMotionEvent(16ms, secondMotionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 736 | |
| 737 | assertMotionEventIsNotResampled(secondOriginalMotionEvent, secondMotionEvent); |
| 738 | } |
| 739 | |
| 740 | TEST_F(ResamplerTest, MultiplePointerDifferentToolTypeInterpolation) { |
| 741 | MotionEvent motionEvent = InputStream{{InputSample{10ms, |
| 742 | {{.id = 0, |
| 743 | .toolType = ToolType::FINGER, |
| 744 | .x = 1.0f, |
| 745 | .y = 1.0f, |
| 746 | .isResampled = false}, |
| 747 | {.id = 1, |
| 748 | .toolType = ToolType::FINGER, |
| 749 | .x = 2.0f, |
| 750 | .y = 2.0f, |
| 751 | .isResampled = false}}}}, |
| 752 | AMOTION_EVENT_ACTION_MOVE}; |
| 753 | |
| 754 | const InputMessage futureSample = InputSample{15ms, |
| 755 | {{.id = 0, |
| 756 | .toolType = ToolType::FINGER, |
| 757 | .x = 3.0, |
| 758 | .y = 3.0, |
| 759 | .isResampled = false}, |
| 760 | {.id = 1, |
| 761 | .toolType = ToolType::STYLUS, |
| 762 | .x = 4.0, |
| 763 | .y = 4.0, |
| 764 | .isResampled = false}}}; |
| 765 | |
| 766 | const MotionEvent originalMotionEvent = motionEvent; |
| 767 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 768 | mResampler->resampleMotionEvent(16ms, motionEvent, &futureSample); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 769 | |
| 770 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 771 | } |
| 772 | |
| 773 | TEST_F(ResamplerTest, MultiplePointerDifferentToolTypeExtrapolation) { |
| 774 | MotionEvent firstMotionEvent = InputStream{{InputSample{5ms, |
| 775 | {{.id = 0, |
| 776 | .toolType = ToolType::FINGER, |
| 777 | .x = 1.0f, |
| 778 | .y = 1.0f, |
| 779 | .isResampled = false}, |
| 780 | {.id = 1, |
| 781 | .toolType = ToolType::FINGER, |
| 782 | .x = 2.0f, |
| 783 | .y = 2.0f, |
| 784 | .isResampled = false}}}}, |
| 785 | AMOTION_EVENT_ACTION_MOVE}; |
| 786 | |
| 787 | mResampler->resampleMotionEvent(9ms, firstMotionEvent, /*futureSample=*/nullptr); |
| 788 | |
| 789 | MotionEvent secondMotionEvent = InputStream{{InputSample{10ms, |
| 790 | {{.id = 0, |
| 791 | .toolType = ToolType::FINGER, |
| 792 | .x = 1.0f, |
| 793 | .y = 1.0f, |
| 794 | .isResampled = false}, |
| 795 | {.id = 1, |
| 796 | .toolType = ToolType::STYLUS, |
| 797 | .x = 2.0f, |
| 798 | .y = 2.0f, |
| 799 | .isResampled = false}}}}, |
| 800 | AMOTION_EVENT_ACTION_MOVE}; |
| 801 | |
| 802 | const MotionEvent secondOriginalMotionEvent = secondMotionEvent; |
| 803 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 804 | mResampler->resampleMotionEvent(16ms, secondMotionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 805 | |
| 806 | assertMotionEventIsNotResampled(secondOriginalMotionEvent, secondMotionEvent); |
| 807 | } |
| 808 | |
| 809 | TEST_F(ResamplerTest, MultiplePointerShouldNotResampleToolTypeInterpolation) { |
| 810 | MotionEvent motionEvent = InputStream{{InputSample{10ms, |
| 811 | {{.id = 0, |
| 812 | .toolType = ToolType::PALM, |
| 813 | .x = 1.0f, |
| 814 | .y = 1.0f, |
| 815 | .isResampled = false}, |
| 816 | {.id = 1, |
| 817 | .toolType = ToolType::PALM, |
| 818 | .x = 2.0f, |
| 819 | .y = 2.0f, |
| 820 | .isResampled = false}}}}, |
| 821 | AMOTION_EVENT_ACTION_MOVE}; |
| 822 | |
| 823 | const InputMessage futureSample = InputSample{15ms, |
| 824 | {{.id = 0, |
| 825 | .toolType = ToolType::PALM, |
| 826 | .x = 3.0, |
| 827 | .y = 3.0, |
| 828 | .isResampled = false}, |
| 829 | {.id = 1, |
| 830 | .toolType = ToolType::PALM, |
| 831 | .x = 4.0, |
| 832 | .y = 4.0, |
| 833 | .isResampled = false}}}; |
| 834 | |
| 835 | const MotionEvent originalMotionEvent = motionEvent; |
| 836 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 837 | mResampler->resampleMotionEvent(16ms, motionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 838 | |
| 839 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
| 840 | } |
| 841 | |
| 842 | TEST_F(ResamplerTest, MultiplePointerShouldNotResampleToolTypeExtrapolation) { |
| 843 | MotionEvent motionEvent = InputStream{{InputSample{5ms, |
| 844 | {{.id = 0, |
| 845 | .toolType = ToolType::PALM, |
| 846 | .x = 1.0f, |
| 847 | .y = 1.0f, |
| 848 | .isResampled = false}, |
| 849 | {.id = 1, |
| 850 | .toolType = ToolType::PALM, |
| 851 | .x = 2.0f, |
| 852 | .y = 2.0f, |
| 853 | .isResampled = false}}}, |
| 854 | InputSample{10ms, |
| 855 | {{.id = 0, |
| 856 | .toolType = ToolType::PALM, |
| 857 | .x = 3.0f, |
| 858 | .y = 3.0f, |
| 859 | .isResampled = false}, |
| 860 | {.id = 1, |
| 861 | .toolType = ToolType::PALM, |
| 862 | .x = 4.0f, |
| 863 | .y = 4.0f, |
| 864 | .isResampled = false}}}}, |
| 865 | AMOTION_EVENT_ACTION_MOVE}; |
| 866 | |
| 867 | const MotionEvent originalMotionEvent = motionEvent; |
| 868 | |
Paul Ramirez | 6affbdb | 2024-09-11 22:20:26 +0000 | [diff] [blame] | 869 | mResampler->resampleMotionEvent(16ms, motionEvent, /*futureSample=*/nullptr); |
Paul Ramirez | cf1b06e | 2024-08-01 17:11:58 +0000 | [diff] [blame] | 870 | |
| 871 | assertMotionEventIsNotResampled(originalMotionEvent, motionEvent); |
Paul Ramirez | be9c544 | 2024-07-10 00:12:41 +0000 | [diff] [blame] | 872 | } |
| 873 | } // namespace android |