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

Commit c660755a authored by Lloyd Pique's avatar Lloyd Pique
Browse files

CE: Functional test for Display::postFramebuffer

Verify that DisplaySurface::onFrameCommitted() is called after
HWComposer::presentAndGetReleaseFences() when a framebuffer is posted to
the display.

Bug: 144116961
Test: atest libcompositionengine_test
Change-Id: I29928fac37771b4efa320a0140ab0f948f01ea89
parent 470eee76
Loading
Loading
Loading
Loading
+60 −0
Original line number Original line Diff line number Diff line
@@ -21,8 +21,10 @@
#include <compositionengine/DisplaySurface.h>
#include <compositionengine/DisplaySurface.h>
#include <compositionengine/RenderSurfaceCreationArgs.h>
#include <compositionengine/RenderSurfaceCreationArgs.h>
#include <compositionengine/impl/Display.h>
#include <compositionengine/impl/Display.h>
#include <compositionengine/impl/RenderSurface.h>
#include <compositionengine/mock/CompositionEngine.h>
#include <compositionengine/mock/CompositionEngine.h>
#include <compositionengine/mock/DisplayColorProfile.h>
#include <compositionengine/mock/DisplayColorProfile.h>
#include <compositionengine/mock/DisplaySurface.h>
#include <compositionengine/mock/Layer.h>
#include <compositionengine/mock/Layer.h>
#include <compositionengine/mock/LayerFE.h>
#include <compositionengine/mock/LayerFE.h>
#include <compositionengine/mock/NativeWindow.h>
#include <compositionengine/mock/NativeWindow.h>
@@ -39,6 +41,8 @@ namespace {


using testing::_;
using testing::_;
using testing::DoAll;
using testing::DoAll;
using testing::InSequence;
using testing::NiceMock;
using testing::Return;
using testing::Return;
using testing::ReturnRef;
using testing::ReturnRef;
using testing::Sequence;
using testing::Sequence;
@@ -46,6 +50,8 @@ using testing::SetArgPointee;
using testing::StrictMock;
using testing::StrictMock;


constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920;
constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080;


struct DisplayTest : public testing::Test {
struct DisplayTest : public testing::Test {
    class Display : public impl::Display {
    class Display : public impl::Display {
@@ -768,5 +774,59 @@ TEST_F(DisplayTest, finishFramePerformsCompositionIfRepaintEverything) {
    nonHwcDisplay->finishFrame(refreshArgs);
    nonHwcDisplay->finishFrame(refreshArgs);
}
}


/*
 * Display functional tests
 */

struct DisplayFunctionalTest : public testing::Test {
    class Display : public impl::Display {
    public:
        explicit Display(const compositionengine::DisplayCreationArgs& args)
              : impl::Display(args) {}

        using impl::Display::injectOutputLayerForTest;
        virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
    };

    static std::shared_ptr<Display> createDisplay(
            const compositionengine::CompositionEngine& compositionEngine,
            compositionengine::DisplayCreationArgs&& args) {
        return impl::createDisplayTemplated<Display>(compositionEngine, args);
    }

    DisplayFunctionalTest() {
        EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));

        mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
    }

    NiceMock<android::mock::HWComposer> mHwComposer;
    NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
    NiceMock<mock::CompositionEngine> mCompositionEngine;
    sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
    sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
    std::shared_ptr<Display> mDisplay = createDisplay(mCompositionEngine,
                                                      DisplayCreationArgsBuilder()
                                                              .setDisplayId(DEFAULT_DISPLAY_ID)
                                                              .setPowerAdvisor(&mPowerAdvisor)
                                                              .build());
    impl::RenderSurface* mRenderSurface =
            new impl::RenderSurface{mCompositionEngine, *mDisplay,
                                    RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH,
                                                              DEFAULT_DISPLAY_HEIGHT, mNativeWindow,
                                                              mDisplaySurface}};
};

TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
    InSequence seq;

    mDisplay->editState().isEnabled = true;

    EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_));
    EXPECT_CALL(*mDisplaySurface, onFrameCommitted());

    mDisplay->postFramebuffer();
}

} // namespace
} // namespace
} // namespace android::compositionengine
} // namespace android::compositionengine