Modify bounds and transform for BSL input.
We don't want to send the BufferStateLayer's transform to input, but rather
the parent's transform. This is because the current layer's transform is
information about how the buffer is placed on screen. The parent's
transform makes more sense to send since this is information about how the
layer is placed on screen. This transform is used by input to determine
how to go from screen space back to window space.
Also update the bounds for BufferStateLayer that's used for input. We
need to include the transform here since input assumes the frame already
includes the buffer transform.
Test: EndToEndNativeInputTest
Test: Rotate and scroll content
Fixes: 184807094
Change-Id: I59c1f32a57dff4f007202b5998fff55f4e125438
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index 09e3cd9..ed826a0 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -903,6 +903,36 @@
}
}
+/*
+ * We don't want to send the layer's transform to input, but rather the
+ * parent's transform. This is because BufferStateLayer's transform is
+ * information about how the buffer is placed on screen. The parent's
+ * transform makes more sense to send since it's information about how the
+ * layer is placed on screen. This transform is used by input to determine
+ * how to go from screen space back to window space.
+ */
+ui::Transform BufferStateLayer::getInputTransform() const {
+ sp<Layer> parent = mDrawingParent.promote();
+ if (parent == nullptr) {
+ return ui::Transform();
+ }
+
+ return parent->getTransform();
+}
+
+/**
+ * Similar to getInputTransform, we need to update the bounds to include the transform.
+ * This is because bounds for BSL doesn't include buffer transform, where the input assumes
+ * that's already included.
+ */
+Rect BufferStateLayer::getInputBounds() const {
+ Rect bufferBounds = getCroppedBufferSize(getDrawingState());
+ if (mDrawingState.transform.getType() == ui::Transform::IDENTITY || !bufferBounds.isValid()) {
+ return bufferBounds;
+ }
+ return mDrawingState.transform.transform(bufferBounds);
+}
+
} // namespace android
// TODO(b/129481165): remove the #pragma below and fix conversion issues
diff --git a/services/surfaceflinger/BufferStateLayer.h b/services/surfaceflinger/BufferStateLayer.h
index af2819e..8ce3e1f 100644
--- a/services/surfaceflinger/BufferStateLayer.h
+++ b/services/surfaceflinger/BufferStateLayer.h
@@ -118,6 +118,8 @@
void gatherBufferInfo() override;
uint64_t getHeadFrameNumber(nsecs_t expectedPresentTime) const;
void onSurfaceFrameCreated(const std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame);
+ ui::Transform getInputTransform() const override;
+ Rect getInputBounds() const override;
private:
friend class SlotGenerationTest;
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 2fcd821..80d2ea8 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -2535,14 +2535,22 @@
return mRemovedFromCurrentState;
}
+ui::Transform Layer::getInputTransform() const {
+ return getTransform();
+}
+
+Rect Layer::getInputBounds() const {
+ return getCroppedBufferSize(getDrawingState());
+}
+
void Layer::fillInputFrameInfo(InputWindowInfo& info, const ui::Transform& toPhysicalDisplay) {
// Transform layer size to screen space and inset it by surface insets.
// If this is a portal window, set the touchableRegion to the layerBounds.
Rect layerBounds = info.portalToDisplayId == ADISPLAY_ID_NONE
- ? getBufferSize(getDrawingState())
+ ? getInputBounds()
: info.touchableRegion.getBounds();
if (!layerBounds.isValid()) {
- layerBounds = getCroppedBufferSize(getDrawingState());
+ layerBounds = getInputBounds();
}
if (!layerBounds.isValid()) {
@@ -2555,7 +2563,7 @@
return;
}
- ui::Transform layerToDisplay = getTransform();
+ ui::Transform layerToDisplay = getInputTransform();
// Transform that takes window coordinates to unrotated display coordinates
ui::Transform t = toPhysicalDisplay * layerToDisplay;
int32_t xSurfaceInset = info.surfaceInset;
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 4a105eb..f900968 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -1025,6 +1025,9 @@
compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const;
bool usingRelativeZ(LayerVector::StateSet) const;
+ virtual ui::Transform getInputTransform() const;
+ virtual Rect getInputBounds() const;
+
// SyncPoints which will be signaled when the correct frame is at the head
// of the queue and dropped after the frame has been latched. Protected by
// mLocalSyncPointMutex.