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

Commit ffc67daf authored by Marissa Wall's avatar Marissa Wall
Browse files

test-hwc2: set layer blend mode

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: Id5a7a568fb81ac9aff388d04077a12765cc135a3
parent 6bd8bfde
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
@@ -357,6 +357,23 @@ public:
        }
    }

    void setLayerBlendMode(hwc2_display_t display, hwc2_layer_t layer,
            hwc2_blend_mode_t mode, hwc2_error_t* outErr = nullptr)
    {
        auto pfn = reinterpret_cast<HWC2_PFN_SET_LAYER_BLEND_MODE>(
                getFunction(HWC2_FUNCTION_SET_LAYER_BLEND_MODE));
        ASSERT_TRUE(pfn) << "failed to get function";

        auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, layer,
                mode));
        if (outErr) {
            *outErr = err;
        } else {
            ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set layer blend mode "
                    << getBlendModeName(mode);
        }
    }

protected:
    hwc2_function_pointer_t getFunction(hwc2_function_descriptor_t descriptor)
    {
@@ -683,6 +700,13 @@ void hwc2TestVsyncCallback(hwc2_callback_data_t callbackData,
                timestamp);
}

void setBlendMode(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
        const Hwc2TestLayer& testLayer, hwc2_error_t* outErr)
{
    EXPECT_NO_FATAL_FAILURE(test->setLayerBlendMode(display, layer,
            testLayer.getBlendMode(), outErr));
}

void setComposition(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
        const Hwc2TestLayer& testLayer, hwc2_error_t* outErr)
{
@@ -704,6 +728,11 @@ void setComposition(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
    }
}

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

bool advanceComposition(Hwc2TestLayer* testLayer)
{
    return testLayer->advanceComposition();
@@ -1556,3 +1585,37 @@ TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_bad_parameter)
            }
    ));
}

/* TESTCASE: Tests that the HWC2 can set a blend mode value of a layer. */
TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE)
{
    ASSERT_NO_FATAL_FAILURE(setLayerProperty(Hwc2TestCoverage::Complete,
            setBlendMode, advanceBlendMode));
}

/* TESTCASE: Tests that the HWC2 can update a blend mode value of a layer. */
TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE_update)
{
    ASSERT_NO_FATAL_FAILURE(setLayerPropertyUpdate(Hwc2TestCoverage::Complete,
            setBlendMode, advanceBlendMode));
}

/* TESTCASE: Tests that the HWC2 cannot set a blend mode for a bad layer. */
TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE_bad_layer)
{
    ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadLayer(Hwc2TestCoverage::Default,
            setBlendMode));
}

/* TESTCASE: Tests that the HWC2 cannot set an invalid blend mode. */
TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE_bad_parameter)
{
    ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadParameter(
            [] (Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer,
                    hwc2_error_t* outErr) {

                ASSERT_NO_FATAL_FAILURE(test->setLayerBlendMode(display,
                        layer, HWC2_BLEND_MODE_INVALID, outErr));
            }
    ));
}
+19 −3
Original line number Diff line number Diff line
@@ -19,21 +19,32 @@
#include "Hwc2TestLayer.h"

Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage)
    : mComposition(coverage) { }
    : mBlendMode(coverage),
      mComposition(coverage) { }

std::string Hwc2TestLayer::dump() const
{
    std::stringstream dmp;

    dmp << "layer: \n";
    dmp << mComposition.dump();

    for (auto property : mProperties) {
        dmp << property->dump();
    }

    return dmp.str();
}

void Hwc2TestLayer::reset()
{
    mComposition.reset();
    for (auto property : mProperties) {
        property->reset();
    }
}

hwc2_blend_mode_t Hwc2TestLayer::getBlendMode() const
{
    return mBlendMode.get();
}

hwc2_composition_t Hwc2TestLayer::getComposition() const
@@ -41,6 +52,11 @@ hwc2_composition_t Hwc2TestLayer::getComposition() const
    return mComposition.get();
}

bool Hwc2TestLayer::advanceBlendMode()
{
    return mBlendMode.advance();
}

bool Hwc2TestLayer::advanceComposition()
{
    return mComposition.advance();
+7 −0
Original line number Diff line number Diff line
@@ -33,11 +33,18 @@ public:

    void reset();

    hwc2_blend_mode_t  getBlendMode() const;
    hwc2_composition_t getComposition() const;

    bool advanceBlendMode();
    bool advanceComposition();

private:
    std::array<Hwc2TestContainer*, 2> mProperties = {{
        &mBlendMode, &mComposition
    }};

    Hwc2TestBlendMode mBlendMode;
    Hwc2TestComposition mComposition;
};

+28 −3
Original line number Diff line number Diff line
@@ -18,10 +18,35 @@

#include "Hwc2TestProperties.h"

Hwc2TestBlendMode::Hwc2TestBlendMode(Hwc2TestCoverage coverage)
    : Hwc2TestProperty(coverage, mCompleteBlendModes, mBasicBlendModes,
            mDefaultBlendModes) { }

std::string Hwc2TestBlendMode::dump() const
{
    std::stringstream dmp;
    dmp << "\tblend mode: " << getBlendModeName(get()) << "\n";
    return dmp.str();
}

const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mDefaultBlendModes = {
    HWC2_BLEND_MODE_NONE,
};

const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mBasicBlendModes = {
    HWC2_BLEND_MODE_NONE,
    HWC2_BLEND_MODE_PREMULTIPLIED,
};

const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mCompleteBlendModes = {
    HWC2_BLEND_MODE_NONE,
    HWC2_BLEND_MODE_PREMULTIPLIED,
    HWC2_BLEND_MODE_COVERAGE,
};


Hwc2TestComposition::Hwc2TestComposition(Hwc2TestCoverage coverage)
    : Hwc2TestProperty(
            (coverage == Hwc2TestCoverage::Complete)? mCompleteCompositions:
            (coverage == Hwc2TestCoverage::Basic)? mBasicCompositions:
    : Hwc2TestProperty(coverage, mCompleteCompositions, mBasicCompositions,
            mDefaultCompositions) { }

std::string Hwc2TestComposition::dump() const
+39 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef _HWC2_TEST_PROPERTIES_H
#define _HWC2_TEST_PROPERTIES_H

#include <array>
#include <vector>

#define HWC2_INCLUDE_STRINGIFICATION
@@ -32,20 +33,39 @@ enum class Hwc2TestCoverage {
};


class Hwc2TestContainer {
public:
    virtual ~Hwc2TestContainer() = default;

    /* Resets the container */
    virtual void reset() = 0;

    /* Attempts to advance to the next valid value. Returns true if one can be
     * found */
    virtual bool advance() = 0;

    virtual std::string dump() const = 0;
};


template <class T>
class Hwc2TestProperty {
class Hwc2TestProperty : public Hwc2TestContainer {
public:
    Hwc2TestProperty(Hwc2TestCoverage coverage,
            const std::vector<T>& completeList, const std::vector<T>& basicList,
            const std::vector<T>& defaultList)
        : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
                (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList) { }

    Hwc2TestProperty(const std::vector<T>& list)
        : mList(list) { }

    virtual ~Hwc2TestProperty() { };

    virtual void reset()
    void reset() override
    {
        mListIdx = 0;
    }

    virtual bool advance()
    bool advance() override
    {
        if (mListIdx + 1 < mList.size()) {
            mListIdx++;
@@ -55,19 +75,30 @@ public:
        return false;
    }

    virtual T get() const
    T get() const
    {
        return mList.at(mListIdx);
    }

    virtual std::string dump() const = 0;

protected:
    const std::vector<T>& mList;
    size_t mListIdx = 0;
};


class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
public:
    Hwc2TestBlendMode(Hwc2TestCoverage coverage);

    std::string dump() const override;

protected:
    static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
    static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
    static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
};


class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
public:
    Hwc2TestComposition(Hwc2TestCoverage coverage);