Skip to content

Commit c32e52b

Browse files
committed
InputTracer: Skip tracing raw coords if they are the same
Save some space in the trace by skipping tracing the raw x/y coords in in window dispatch events if they are the same as the coords already traced in the event. Bug: 388336752 Test: Presubmit Flag: EXEMPT tracing only Change-Id: If504a03a4d66a1119fe9209794b18a767ceea81e
1 parent 0d41d4e commit c32e52b

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

services/inputflinger/dispatcher/trace/AndroidInputEventProtoConverter.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,25 @@ void AndroidInputEventProtoConverter::toProtoWindowDispatchEvent(
115115
for (size_t i = 0; i < motion->pointerProperties.size(); i++) {
116116
auto* pointerProto = outProto.add_dispatched_pointer();
117117
pointerProto->set_pointer_id(motion->pointerProperties[i].id);
118+
const auto& coords = motion->pointerCoords[i];
118119
const auto rawXY =
119120
MotionEvent::calculateTransformedXY(motion->source, args.rawTransform,
120-
motion->pointerCoords[i].getXYValue());
121-
pointerProto->set_x_in_display(rawXY.x);
122-
pointerProto->set_y_in_display(rawXY.y);
121+
coords.getXYValue());
122+
if (coords.getXYValue() != rawXY) {
123+
// These values are only traced if they were modified by the raw transform
124+
// to save space. Trace consumers should be aware of this optimization.
125+
pointerProto->set_x_in_display(rawXY.x);
126+
pointerProto->set_y_in_display(rawXY.y);
127+
}
123128

124-
const auto& coords = motion->pointerCoords[i];
125129
const auto coordsInWindow =
126130
MotionEvent::calculateTransformedCoords(motion->source, motion->flags,
127131
args.transform, coords);
128132
auto bits = BitSet64(coords.bits);
129133
for (int32_t axisIndex = 0; !bits.isEmpty(); axisIndex++) {
130134
const uint32_t axis = bits.clearFirstMarkedBit();
131135
const float axisValueInWindow = coordsInWindow.values[axisIndex];
136+
// Only values that are modified by the window transform are traced.
132137
if (coords.values[axisIndex] != axisValueInWindow) {
133138
auto* axisEntry = pointerProto->add_axis_value_in_window();
134139
axisEntry->set_axis(axis);

0 commit comments

Comments
 (0)