blob: c5cf0833a8f8a30c582c8f4e356a899fcabf48dd [file] [log] [blame]
Siarhei Vishniakoud0784762019-11-01 15:33:48 -07001/*
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#include <benchmark/benchmark.h>
18
Siarhei Vishniakouf2652122021-03-05 21:39:46 +000019#include <android/os/IInputConstants.h>
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070020#include <binder/Binder.h>
chaviw3277faf2021-05-19 16:45:23 -050021#include <gui/constants.h>
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070022#include "../dispatcher/InputDispatcher.h"
23
Siarhei Vishniakou18050092021-09-01 13:32:49 -070024using android::base::Result;
chaviw3277faf2021-05-19 16:45:23 -050025using android::gui::WindowInfo;
26using android::gui::WindowInfoHandle;
Siarhei Vishniakouf2652122021-03-05 21:39:46 +000027using android::os::IInputConstants;
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080028using android::os::InputEventInjectionResult;
29using android::os::InputEventInjectionSync;
30
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070031namespace android::inputdispatcher {
32
Siarhei Vishniakouadeb6fa2023-05-26 09:11:06 -070033namespace {
34
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070035// An arbitrary device id.
Prabir Pradhan5735a322022-04-11 17:23:34 +000036constexpr int32_t DEVICE_ID = 1;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070037
Prabir Pradhan5735a322022-04-11 17:23:34 +000038// The default pid and uid for windows created by the test.
39constexpr int32_t WINDOW_PID = 999;
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000040constexpr gui::Uid WINDOW_UID{1001};
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070041
Siarhei Vishniakou097c3db2020-05-06 14:18:38 -070042static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 5s;
43static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 100ms;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070044
45static nsecs_t now() {
46 return systemTime(SYSTEM_TIME_MONOTONIC);
47}
48
49// --- FakeInputDispatcherPolicy ---
50
51class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface {
52public:
Prabir Pradhana41d2442023-04-20 21:30:40 +000053 FakeInputDispatcherPolicy() = default;
54 virtual ~FakeInputDispatcherPolicy() = default;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070055
56private:
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050057 void notifyConfigurationChanged(nsecs_t) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070058
Siarhei Vishniakou234129c2020-10-22 22:28:12 -050059 void notifyNoFocusedWindowAnr(
60 const std::shared_ptr<InputApplicationHandle>& applicationHandle) override {
61 ALOGE("There is no focused window for %s", applicationHandle->getName().c_str());
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070062 }
63
Prabir Pradhanedd96402022-02-15 01:46:16 -080064 void notifyWindowUnresponsive(const sp<IBinder>& connectionToken, std::optional<int32_t> pid,
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +000065 const std::string& reason) override {
66 ALOGE("Window is not responding: %s", reason.c_str());
Siarhei Vishniakou234129c2020-10-22 22:28:12 -050067 }
68
Prabir Pradhanedd96402022-02-15 01:46:16 -080069 void notifyWindowResponsive(const sp<IBinder>& connectionToken,
70 std::optional<int32_t> pid) override {}
Siarhei Vishniakou234129c2020-10-22 22:28:12 -050071
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050072 void notifyInputChannelBroken(const sp<IBinder>&) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070073
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050074 void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070075
Chris Yef59a2f42020-10-16 12:55:26 -070076 void notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType,
77 InputDeviceSensorAccuracy accuracy, nsecs_t timestamp,
78 const std::vector<float>& values) override {}
79
80 void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType,
81 InputDeviceSensorAccuracy accuracy) override {}
82
Chris Yefb552902021-02-03 17:18:37 -080083 void notifyVibratorState(int32_t deviceId, bool isOn) override {}
84
Prabir Pradhana41d2442023-04-20 21:30:40 +000085 InputDispatcherConfiguration getDispatcherConfiguration() override { return mConfig; }
86
87 bool filterInputEvent(const InputEvent& inputEvent, uint32_t policyFlags) override {
88 return true; // dispatch event normally
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070089 }
90
Prabir Pradhana41d2442023-04-20 21:30:40 +000091 void interceptKeyBeforeQueueing(const KeyEvent&, uint32_t&) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070092
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050093 void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070094
Prabir Pradhana41d2442023-04-20 21:30:40 +000095 nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override {
Siarhei Vishniakoud0784762019-11-01 15:33:48 -070096 return 0;
97 }
98
Prabir Pradhana41d2442023-04-20 21:30:40 +000099 std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent&,
100 uint32_t) override {
101 return {};
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700102 }
103
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500104 void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700105
Sean Stoutb4e0a592021-02-23 07:34:53 -0800106 void pokeUserActivity(nsecs_t, int32_t, int32_t) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700107
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500108 void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {}
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700109
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000110 void setPointerCapture(const PointerCaptureRequest&) override {}
Prabir Pradhan99987712020-11-10 18:43:05 -0800111
arthurhungf452d0b2021-01-06 00:19:52 +0800112 void notifyDropWindow(const sp<IBinder>&, float x, float y) override {}
113
Prabir Pradhan8ede1d12023-05-08 19:37:44 +0000114 void notifyDeviceInteraction(int32_t deviceId, nsecs_t timestamp,
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +0000115 const std::set<gui::Uid>& uids) override {}
Prabir Pradhan8ede1d12023-05-08 19:37:44 +0000116
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700117 InputDispatcherConfiguration mConfig;
118};
119
120class FakeApplicationHandle : public InputApplicationHandle {
121public:
122 FakeApplicationHandle() {}
123 virtual ~FakeApplicationHandle() {}
124
125 virtual bool updateInfo() {
Siarhei Vishniakou70622952020-07-30 11:17:23 -0500126 mInfo.dispatchingTimeoutMillis =
127 std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700128 return true;
129 }
130};
131
132class FakeInputReceiver {
133public:
134 void consumeEvent() {
Siarhei Vishniakoud549b252020-08-11 11:25:26 -0500135 uint32_t consumeSeq = 0;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700136 InputEvent* event;
137
Siarhei Vishniakouadfd4fa2019-12-20 11:02:58 -0800138 std::chrono::time_point start = std::chrono::steady_clock::now();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700139 status_t result = WOULD_BLOCK;
140 while (result == WOULD_BLOCK) {
Siarhei Vishniakouadfd4fa2019-12-20 11:02:58 -0800141 std::chrono::duration elapsed = std::chrono::steady_clock::now() - start;
142 if (elapsed > 10ms) {
143 ALOGE("Waited too long for consumer to produce an event, giving up");
144 break;
145 }
Harry Cutts33476232023-01-30 19:57:29 +0000146 result = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq,
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700147 &event);
148 }
149 if (result != OK) {
150 ALOGE("Received result = %d from consume()", result);
151 }
152 result = mConsumer->sendFinishedSignal(consumeSeq, true);
153 if (result != OK) {
154 ALOGE("Received result = %d from sendFinishedSignal", result);
155 }
156 }
157
158protected:
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700159 explicit FakeInputReceiver(InputDispatcher& dispatcher, const std::string name) {
160 Result<std::unique_ptr<InputChannel>> channelResult = dispatcher.createInputChannel(name);
161 LOG_ALWAYS_FATAL_IF(!channelResult.ok());
162 mClientChannel = std::move(*channelResult);
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700163 mConsumer = std::make_unique<InputConsumer>(mClientChannel);
164 }
165
166 virtual ~FakeInputReceiver() {}
167
Garfield Tan15601662020-09-22 15:32:38 -0700168 std::shared_ptr<InputChannel> mClientChannel;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700169 std::unique_ptr<InputConsumer> mConsumer;
170 PreallocatedInputEventFactory mEventFactory;
171};
172
chaviw3277faf2021-05-19 16:45:23 -0500173class FakeWindowHandle : public WindowInfoHandle, public FakeInputReceiver {
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700174public:
175 static const int32_t WIDTH = 200;
176 static const int32_t HEIGHT = 200;
177
Chris Yea209fde2020-07-22 13:54:51 -0700178 FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle,
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700179 InputDispatcher& dispatcher, const std::string name)
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700180 : FakeInputReceiver(dispatcher, name), mFrame(Rect(0, 0, WIDTH, HEIGHT)) {
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700181 inputApplicationHandle->updateInfo();
chaviw15fab6f2021-06-07 14:15:52 -0500182 updateInfo();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700183 mInfo.applicationInfo = *inputApplicationHandle->getInfo();
184 }
185
chaviw15fab6f2021-06-07 14:15:52 -0500186 void updateInfo() {
Garfield Tan15601662020-09-22 15:32:38 -0700187 mInfo.token = mClientChannel->getConnectionToken();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700188 mInfo.name = "FakeWindowHandle";
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500189 mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700190 mInfo.frameLeft = mFrame.left;
191 mInfo.frameTop = mFrame.top;
192 mInfo.frameRight = mFrame.right;
193 mInfo.frameBottom = mFrame.bottom;
194 mInfo.globalScaleFactor = 1.0;
195 mInfo.touchableRegion.clear();
196 mInfo.addTouchableRegion(mFrame);
Prabir Pradhan5735a322022-04-11 17:23:34 +0000197 mInfo.ownerPid = WINDOW_PID;
198 mInfo.ownerUid = WINDOW_UID;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700199 mInfo.displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700200 }
201
202protected:
203 Rect mFrame;
204};
205
206static MotionEvent generateMotionEvent() {
207 PointerProperties pointerProperties[1];
208 PointerCoords pointerCoords[1];
209
210 pointerProperties[0].clear();
211 pointerProperties[0].id = 0;
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700212 pointerProperties[0].toolType = ToolType::FINGER;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700213
214 pointerCoords[0].clear();
215 pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100);
216 pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 100);
217
218 const nsecs_t currentTime = now();
219
chaviw9eaa22c2020-07-01 16:21:27 -0700220 ui::Transform identityTransform;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700221 MotionEvent event;
Siarhei Vishniakouf2652122021-03-05 21:39:46 +0000222 event.initialize(IInputConstants::INVALID_INPUT_EVENT_ID, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
Garfield Tanfbe732e2020-01-24 11:26:14 -0800223 ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN,
224 /* actionButton */ 0, /* flags */ 0,
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700225 /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE,
chaviw9eaa22c2020-07-01 16:21:27 -0700226 identityTransform, /* xPrecision */ 0,
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700227 /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700228 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, currentTime,
229 currentTime,
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700230 /*pointerCount*/ 1, pointerProperties, pointerCoords);
231 return event;
232}
233
234static NotifyMotionArgs generateMotionArgs() {
235 PointerProperties pointerProperties[1];
236 PointerCoords pointerCoords[1];
237
238 pointerProperties[0].clear();
239 pointerProperties[0].id = 0;
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700240 pointerProperties[0].toolType = ToolType::FINGER;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700241
242 pointerCoords[0].clear();
243 pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100);
244 pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 100);
245
246 const nsecs_t currentTime = now();
247 // Define a valid motion event.
Siarhei Vishniakouf2652122021-03-05 21:39:46 +0000248 NotifyMotionArgs args(IInputConstants::INVALID_INPUT_EVENT_ID, currentTime, currentTime,
249 DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
250 POLICY_FLAG_PASS_TO_USER, AMOTION_EVENT_ACTION_DOWN,
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700251 /* actionButton */ 0, /* flags */ 0, AMETA_NONE, /* buttonState */ 0,
252 MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
253 pointerProperties, pointerCoords,
254 /* xPrecision */ 0, /* yPrecision */ 0,
255 AMOTION_EVENT_INVALID_CURSOR_POSITION,
256 AMOTION_EVENT_INVALID_CURSOR_POSITION, currentTime, /* videoFrames */ {});
257
258 return args;
259}
260
261static void benchmarkNotifyMotion(benchmark::State& state) {
262 // Create dispatcher
Prabir Pradhana41d2442023-04-20 21:30:40 +0000263 FakeInputDispatcherPolicy fakePolicy;
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700264 InputDispatcher dispatcher(fakePolicy);
265 dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false);
266 dispatcher.start();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700267
268 // Create a window that will receive motion events
Chris Yea209fde2020-07-22 13:54:51 -0700269 std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
Siarhei Vishniakouaed7ad02022-08-03 15:04:33 -0700270 sp<FakeWindowHandle> window =
271 sp<FakeWindowHandle>::make(application, dispatcher, "Fake Window");
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700272
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700273 dispatcher.setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700274
275 NotifyMotionArgs motionArgs = generateMotionArgs();
276
277 for (auto _ : state) {
278 // Send ACTION_DOWN
279 motionArgs.action = AMOTION_EVENT_ACTION_DOWN;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700280 motionArgs.downTime = now();
281 motionArgs.eventTime = motionArgs.downTime;
Prabir Pradhan678438e2023-04-13 19:32:51 +0000282 dispatcher.notifyMotion(motionArgs);
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700283
284 // Send ACTION_UP
285 motionArgs.action = AMOTION_EVENT_ACTION_UP;
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700286 motionArgs.eventTime = now();
Prabir Pradhan678438e2023-04-13 19:32:51 +0000287 dispatcher.notifyMotion(motionArgs);
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700288
289 window->consumeEvent();
290 window->consumeEvent();
291 }
292
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700293 dispatcher.stop();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700294}
295
296static void benchmarkInjectMotion(benchmark::State& state) {
297 // Create dispatcher
Prabir Pradhana41d2442023-04-20 21:30:40 +0000298 FakeInputDispatcherPolicy fakePolicy;
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700299 InputDispatcher dispatcher(fakePolicy);
300 dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false);
301 dispatcher.start();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700302
303 // Create a window that will receive motion events
Chris Yea209fde2020-07-22 13:54:51 -0700304 std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
Siarhei Vishniakouaed7ad02022-08-03 15:04:33 -0700305 sp<FakeWindowHandle> window =
306 sp<FakeWindowHandle>::make(application, dispatcher, "Fake Window");
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700307
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700308 dispatcher.setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700309
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700310 for (auto _ : state) {
Siarhei Vishniakouadfd4fa2019-12-20 11:02:58 -0800311 MotionEvent event = generateMotionEvent();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700312 // Send ACTION_DOWN
Harry Cutts33476232023-01-30 19:57:29 +0000313 dispatcher.injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE,
Prabir Pradhan5735a322022-04-11 17:23:34 +0000314 INJECT_EVENT_TIMEOUT,
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700315 POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700316
317 // Send ACTION_UP
318 event.setAction(AMOTION_EVENT_ACTION_UP);
Harry Cutts33476232023-01-30 19:57:29 +0000319 dispatcher.injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE,
Prabir Pradhan5735a322022-04-11 17:23:34 +0000320 INJECT_EVENT_TIMEOUT,
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700321 POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700322
323 window->consumeEvent();
324 window->consumeEvent();
325 }
326
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700327 dispatcher.stop();
328}
329
330static void benchmarkOnWindowInfosChanged(benchmark::State& state) {
331 // Create dispatcher
Prabir Pradhana41d2442023-04-20 21:30:40 +0000332 FakeInputDispatcherPolicy fakePolicy;
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700333 InputDispatcher dispatcher(fakePolicy);
334 dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false);
335 dispatcher.start();
336
337 // Create a window
338 std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
Siarhei Vishniakouaed7ad02022-08-03 15:04:33 -0700339 sp<FakeWindowHandle> window =
340 sp<FakeWindowHandle>::make(application, dispatcher, "Fake Window");
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700341
342 std::vector<gui::WindowInfo> windowInfos{*window->getInfo()};
343 gui::DisplayInfo info;
344 info.displayId = window->getInfo()->displayId;
345 std::vector<gui::DisplayInfo> displayInfos{info};
346
347 for (auto _ : state) {
Patrick Williamsd828f302023-04-28 17:52:08 -0500348 dispatcher.onWindowInfosChanged(
349 {windowInfos, displayInfos, /*vsyncId=*/0, /*timestamp=*/0});
350 dispatcher.onWindowInfosChanged(
351 {/*windowInfos=*/{}, /*displayInfos=*/{}, /*vsyncId=*/{}, /*timestamp=*/0});
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700352 }
353 dispatcher.stop();
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700354}
355
Siarhei Vishniakouadeb6fa2023-05-26 09:11:06 -0700356} // namespace
357
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700358BENCHMARK(benchmarkNotifyMotion);
359BENCHMARK(benchmarkInjectMotion);
Siarhei Vishniakou8c84b802022-03-23 15:48:41 -0700360BENCHMARK(benchmarkOnWindowInfosChanged);
Siarhei Vishniakoud0784762019-11-01 15:33:48 -0700361
362} // namespace android::inputdispatcher
363
364BENCHMARK_MAIN();