Fix touch event would be offset by crop
SurfaceFlinger overwrite the input frame info by the layer
bounds, and the input coordinate should match the active buffer bounds.
The touch region should intersect the active buffer and screen bounds.
Bug: 120641923
Bug: 120781892
Test: atest com.android.server.wm
Test: atest libgui_test
Test: use landscape mode, split screen, touch on secondary window.
Test: create legacy application (<N), no title bar,
window flags=FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR
Change-Id: Idc3b5bb707ce733c77ee700821bde5786594e430
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index ee49610..aa9bc15 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -2135,7 +2135,7 @@
return mRemovedFromCurrentState;
}
-InputWindowInfo Layer::fillInputInfo(const Rect& screenBounds) {
+InputWindowInfo Layer::fillInputInfo() {
InputWindowInfo info = mDrawingState.inputInfo;
ui::Transform t = getTransform();
@@ -2148,20 +2148,18 @@
}
// Transform layer size to screen space and inset it by surface insets.
- Rect layerBounds = getCroppedBufferSize(getDrawingState());
+ Rect layerBounds = getBufferSize(getDrawingState());
+ if (!layerBounds.isValid()) {
+ layerBounds = getCroppedBufferSize(getDrawingState());
+ }
layerBounds = t.transform(layerBounds);
layerBounds.inset(info.surfaceInset, info.surfaceInset, info.surfaceInset, info.surfaceInset);
- // Intersect with screen bounds to shrink the frame by the surface insets. The surface insets
- // are not set on the screen bounds directly since the surface inset region may already be
- // cropped by a parent layer.
- Rect frame;
- screenBounds.intersect(layerBounds, &frame);
-
- info.frameLeft = frame.left;
- info.frameTop = frame.top;
- info.frameRight = frame.right;
- info.frameBottom = frame.bottom;
+ // Input coordinate should match the layer bounds.
+ info.frameLeft = layerBounds.left;
+ info.frameTop = layerBounds.top;
+ info.frameRight = layerBounds.right;
+ info.frameBottom = layerBounds.bottom;
// Position the touchable region relative to frame screen location and restrict it to frame
// bounds.