[layertracegenerator] fix display proto parsing
- fixes a couple of bugs in how we parsed display data
and added tests to cover the logic
- additionally create fake input tokens when
generating layer state so we don't assume that the token
is null and ignore input data
Fixes: 275418553
Test: presubmit
Change-Id: I60dd2862e0c6ce0e214ad2123a8523b4f74c38e9
diff --git a/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp b/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp
index 7355c35..3e3d8f0 100644
--- a/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp
+++ b/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp
@@ -22,6 +22,7 @@
#include <string>
#include <unordered_map>
+#include <LayerProtoHelper.h>
#include <LayerTraceGenerator.h>
#include <Tracing/TransactionProtoParser.h>
#include <layerproto/LayerProtoHeader.h>
@@ -94,11 +95,14 @@
float y;
uint32_t bufferWidth;
uint32_t bufferHeight;
+ Rect touchableRegionBounds;
};
bool operator==(const LayerInfo& lh, const LayerInfo& rh) {
- return std::make_tuple(lh.id, lh.name, lh.parent, lh.z, lh.curr_frame) ==
- std::make_tuple(rh.id, rh.name, rh.parent, rh.z, rh.curr_frame);
+ return std::make_tuple(lh.id, lh.name, lh.parent, lh.z, lh.curr_frame, lh.bufferWidth,
+ lh.bufferHeight, lh.touchableRegionBounds) ==
+ std::make_tuple(rh.id, rh.name, rh.parent, rh.z, rh.curr_frame, rh.bufferWidth,
+ rh.bufferHeight, rh.touchableRegionBounds);
}
bool compareById(const LayerInfo& a, const LayerInfo& b) {
@@ -109,7 +113,9 @@
*os << "Layer [" << info.id << "] name=" << info.name << " parent=" << info.parent
<< " z=" << info.z << " curr_frame=" << info.curr_frame << " x=" << info.x
<< " y=" << info.y << " bufferWidth=" << info.bufferWidth
- << " bufferHeight=" << info.bufferHeight;
+ << " bufferHeight=" << info.bufferHeight << "touchableRegionBounds={"
+ << info.touchableRegionBounds.left << "," << info.touchableRegionBounds.top << ","
+ << info.touchableRegionBounds.right << "," << info.touchableRegionBounds.bottom << "}";
}
struct find_id : std::unary_function<LayerInfo, bool> {
@@ -119,6 +125,17 @@
};
static LayerInfo getLayerInfoFromProto(::android::surfaceflinger::LayerProto& proto) {
+ Rect touchableRegionBounds = Rect::INVALID_RECT;
+ // ignore touchable region for layers without buffers, the new fe aggressively avoids
+ // calculating state for layers that are not visible which could lead to mismatches
+ if (proto.has_input_window_info() && proto.input_window_info().has_touchable_region() &&
+ proto.has_active_buffer()) {
+ Region touchableRegion;
+ LayerProtoHelper::readFromProto(proto.input_window_info().touchable_region(),
+ touchableRegion);
+ touchableRegionBounds = touchableRegion.bounds();
+ }
+
return {proto.id(),
proto.name(),
proto.parent(),
@@ -127,7 +144,8 @@
proto.has_position() ? proto.position().x() : -1,
proto.has_position() ? proto.position().y() : -1,
proto.has_active_buffer() ? proto.active_buffer().width() : 0,
- proto.has_active_buffer() ? proto.active_buffer().height() : 0};
+ proto.has_active_buffer() ? proto.active_buffer().height() : 0,
+ touchableRegionBounds};
}
TEST_P(TransactionTraceTestSuite, validateEndState) {
diff --git a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp
index 3dea189..dd72174 100644
--- a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp
+++ b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp
@@ -19,6 +19,7 @@
#include <limits> // std::numeric_limits
#include <gui/SurfaceComposerClient.h>
+#include <ui/Rotation.h>
#include "LayerProtoHelper.h"
#include "Tracing/TransactionProtoParser.h"
@@ -103,4 +104,48 @@
ASSERT_EQ(t1.displays[0].token, t2.displays[0].token);
}
+TEST(TransactionProtoParserTest, parseDisplayInfo) {
+ frontend::DisplayInfo d1;
+ d1.info.displayId = 42;
+ d1.info.logicalWidth = 43;
+ d1.info.logicalHeight = 44;
+ d1.info.transform.set(1, 2, 3, 4);
+ d1.transform = d1.info.transform.inverse();
+ d1.receivesInput = true;
+ d1.isSecure = false;
+ d1.isPrimary = true;
+ d1.isVirtual = false;
+ d1.rotationFlags = ui::Transform::ROT_180;
+ d1.transformHint = ui::Transform::ROT_90;
+
+ const uint32_t layerStack = 2;
+ google::protobuf::RepeatedPtrField<proto::DisplayInfo> displayProtos;
+ auto displayInfoProto = displayProtos.Add();
+ *displayInfoProto = TransactionProtoParser::toProto(d1, layerStack);
+ display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> displayInfos;
+ TransactionProtoParser::fromProto(displayProtos, displayInfos);
+
+ ASSERT_TRUE(displayInfos.contains(ui::LayerStack::fromValue(layerStack)));
+ frontend::DisplayInfo d2 = displayInfos.get(ui::LayerStack::fromValue(layerStack))->get();
+ EXPECT_EQ(d1.info.displayId, d2.info.displayId);
+ EXPECT_EQ(d1.info.logicalWidth, d2.info.logicalWidth);
+ EXPECT_EQ(d1.info.logicalHeight, d2.info.logicalHeight);
+
+ EXPECT_EQ(d1.info.transform.dsdx(), d2.info.transform.dsdx());
+ EXPECT_EQ(d1.info.transform.dsdy(), d2.info.transform.dsdy());
+ EXPECT_EQ(d1.info.transform.dtdx(), d2.info.transform.dtdx());
+ EXPECT_EQ(d1.info.transform.dtdy(), d2.info.transform.dtdy());
+
+ EXPECT_EQ(d1.transform.dsdx(), d2.transform.dsdx());
+ EXPECT_EQ(d1.transform.dsdy(), d2.transform.dsdy());
+ EXPECT_EQ(d1.transform.dtdx(), d2.transform.dtdx());
+ EXPECT_EQ(d1.transform.dtdy(), d2.transform.dtdy());
+
+ EXPECT_EQ(d1.receivesInput, d2.receivesInput);
+ EXPECT_EQ(d1.isSecure, d2.isSecure);
+ EXPECT_EQ(d1.isVirtual, d2.isVirtual);
+ EXPECT_EQ(d1.rotationFlags, d2.rotationFlags);
+ EXPECT_EQ(d1.transformHint, d2.transformHint);
+}
+
} // namespace android