Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a0aaf9f authored by Marissa Wall's avatar Marissa Wall
Browse files

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
parent ee24278d
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
@@ -358,6 +358,22 @@ public:
        }
    }

    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 setComposition(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
    }
}

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 @@ bool advanceComposition(Hwc2TestLayer* testLayer)
    return testLayer->advanceComposition();
}

bool advanceCursorPosition(Hwc2TestLayer* testLayer)
{
    return testLayer->advanceCursorPosition();
}

bool advanceDataspace(Hwc2TestLayer* testLayer)
{
    return testLayer->advanceDataspace();
@@ -1865,6 +1897,66 @@ TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_bad_parameter)
    ));
}

/* 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)
{
+11 −0
Original line number Diff line number Diff line
@@ -72,6 +72,12 @@ hwc2_composition_t Hwc2TestLayer::getComposition() const
    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 @@ bool Hwc2TestLayer::advanceComposition()
    return mComposition.advance();
}

bool Hwc2TestLayer::advanceCursorPosition()
{
    return mDisplayFrame.advance();
}

bool Hwc2TestLayer::advanceDataspace()
{
    return mDataspace.advance();
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public:
    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 @@ public:
    bool advanceBufferArea();
    bool advanceColor();
    bool advanceComposition();
    bool advanceCursorPosition();
    bool advanceDataspace();
    bool advanceDisplayFrame();
    bool advancePlaneAlpha();