test-hwc2: set cursor position
Test: Add "#define HAVE_NO_SURFACE_FLINGER" to
frameworks/native/libs/gui/BufferQueueCore.cpp.
Recompile and flash.
Run "mm" in frameworks/native/services/surfaceflinger/tests/hwc2.
Push test-hwc2 to device.
Run "adb root && adb shell stop".
Run test case. Ex: "./test-hwc2"
Change-Id: I4b265826befcf33c3f71b52bfabc076c48efed5f
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp b/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp
index bba97b8..2a97a8c 100644
--- a/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp
+++ b/services/surfaceflinger/tests/hwc2/Hwc2Test.cpp
@@ -358,6 +358,22 @@
}
}
+ void setCursorPosition(hwc2_display_t display, hwc2_layer_t layer,
+ int32_t x, int32_t y, hwc2_error_t* outErr = nullptr)
+ {
+ auto pfn = reinterpret_cast<HWC2_PFN_SET_CURSOR_POSITION>(
+ getFunction(HWC2_FUNCTION_SET_CURSOR_POSITION));
+ ASSERT_TRUE(pfn) << "failed to get function";
+
+ auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, layer, x,
+ y));
+ if (outErr) {
+ *outErr = err;
+ } else {
+ ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set cursor position";
+ }
+ }
+
void setLayerBlendMode(hwc2_display_t display, hwc2_layer_t layer,
hwc2_blend_mode_t mode, hwc2_error_t* outErr = nullptr)
{
@@ -925,6 +941,17 @@
}
}
+void setCursorPosition(Hwc2Test* test, hwc2_display_t display,
+ hwc2_layer_t layer, const Hwc2TestLayer& testLayer, hwc2_error_t* outErr)
+{
+ ASSERT_NO_FATAL_FAILURE(test->setLayerCompositionType(display,
+ layer, HWC2_COMPOSITION_CURSOR));
+
+ const hwc_rect_t cursorPosition = testLayer.getCursorPosition();
+ EXPECT_NO_FATAL_FAILURE(test->setCursorPosition(display, layer,
+ cursorPosition.left, cursorPosition.top, outErr));
+}
+
void setDataspace(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
const Hwc2TestLayer& testLayer, hwc2_error_t* outErr)
{
@@ -990,6 +1017,11 @@
return testLayer->advanceComposition();
}
+bool advanceCursorPosition(Hwc2TestLayer* testLayer)
+{
+ return testLayer->advanceCursorPosition();
+}
+
bool advanceDataspace(Hwc2TestLayer* testLayer)
{
return testLayer->advanceDataspace();
@@ -1865,6 +1897,66 @@
));
}
+/* TESTCASE: Tests that the HWC2 can set the cursor position of a layer. */
+TEST_F(Hwc2Test, SET_CURSOR_POSITION)
+{
+ ASSERT_NO_FATAL_FAILURE(setLayerProperty(Hwc2TestCoverage::Complete,
+ ::setCursorPosition, advanceCursorPosition));
+}
+
+/* TESTCASE: Tests that the HWC2 can update the cursor position of a layer. */
+TEST_F(Hwc2Test, SET_CURSOR_POSITION_update)
+{
+ ASSERT_NO_FATAL_FAILURE(setLayerPropertyUpdate(Hwc2TestCoverage::Complete,
+ ::setCursorPosition, advanceCursorPosition));
+}
+
+/* TESTCASE: Tests that the HWC2 can set the cursor position of a layer when the
+ * composition type has not been set to HWC2_COMPOSITION_CURSOR. */
+TEST_F(Hwc2Test, SET_CURSOR_POSITION_composition_type_unset)
+{
+ ASSERT_NO_FATAL_FAILURE(setLayerProperty(Hwc2TestCoverage::Complete,
+ [] (Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
+ const Hwc2TestLayer& testLayer, hwc2_error_t* outErr) {
+
+ const hwc_rect_t cursorPosition = testLayer.getCursorPosition();
+ EXPECT_NO_FATAL_FAILURE(test->setCursorPosition(display, layer,
+ cursorPosition.left, cursorPosition.top, outErr));
+ },
+
+ advanceCursorPosition));
+}
+
+/* TESTCASE: Tests that the HWC2 cannot set the cursor position of a bad
+ * display. */
+TEST_F(Hwc2Test, SET_CURSOR_POSITION_bad_display)
+{
+ hwc2_display_t display;
+ hwc2_layer_t layer = 0;
+ int32_t x = 0, y = 0;
+ hwc2_error_t err = HWC2_ERROR_NONE;
+
+ ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display));
+
+ ASSERT_NO_FATAL_FAILURE(setCursorPosition(display, layer, x, y, &err));
+ EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code";
+}
+
+/* TESTCASE: Tests that the HWC2 cannot set the cursor position of a bad layer. */
+TEST_F(Hwc2Test, SET_CURSOR_POSITION_bad_layer)
+{
+ ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadLayer(Hwc2TestCoverage::Default,
+ [] (Hwc2Test* test, hwc2_display_t display, hwc2_layer_t badLayer,
+ const Hwc2TestLayer& testLayer, hwc2_error_t* outErr) {
+
+ const hwc_rect_t cursorPosition = testLayer.getCursorPosition();
+ EXPECT_NO_FATAL_FAILURE(test->setCursorPosition(display,
+ badLayer, cursorPosition.left, cursorPosition.top,
+ outErr));
+ }
+ ));
+}
+
/* TESTCASE: Tests that the HWC2 can set a blend mode value of a layer. */
TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE)
{
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp
index caf3987..2a5a1af 100644
--- a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp
+++ b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.cpp
@@ -72,6 +72,12 @@
return mComposition.get();
}
+/* The cursor position corresponds to {displayFrame.left, displayFrame.top} */
+hwc_rect_t Hwc2TestLayer::getCursorPosition() const
+{
+ return mDisplayFrame.get();
+}
+
android_dataspace_t Hwc2TestLayer::getDataspace() const
{
return mDataspace.get();
@@ -122,6 +128,11 @@
return mComposition.advance();
}
+bool Hwc2TestLayer::advanceCursorPosition()
+{
+ return mDisplayFrame.advance();
+}
+
bool Hwc2TestLayer::advanceDataspace()
{
return mDataspace.advance();
diff --git a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h
index f548ea6..2cf2029 100644
--- a/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h
+++ b/services/surfaceflinger/tests/hwc2/Hwc2TestLayer.h
@@ -37,6 +37,7 @@
hwc2_blend_mode_t getBlendMode() const;
hwc_color_t getColor() const;
hwc2_composition_t getComposition() const;
+ hwc_rect_t getCursorPosition() const;
android_dataspace_t getDataspace() const;
hwc_rect_t getDisplayFrame() const;
float getPlaneAlpha() const;
@@ -48,6 +49,7 @@
bool advanceBufferArea();
bool advanceColor();
bool advanceComposition();
+ bool advanceCursorPosition();
bool advanceDataspace();
bool advanceDisplayFrame();
bool advancePlaneAlpha();