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

Commit ba013fa7 authored by Alec Mouri's avatar Alec Mouri
Browse files

Get display dimensions through ANativeWindow api.

We're moving away from rendering to a GL surface so that we can render
to a buffer directly. Future CLs will remove this surface.

Bug: 117680609
Change-Id: I8b469bfcdcf274abce221ec66b844946dafc0904
Test: libsurfaceflinger_unittest, SurfaceFlinger_test
parent cb10f956
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -223,8 +223,6 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
        mNativeWindow(args.nativeWindow),
        mDisplaySurface(args.displaySurface),
        mSurface{std::move(args.renderSurface)},
        mDisplayWidth(args.displayWidth),
        mDisplayHeight(args.displayHeight),
        mDisplayInstallOrientation(args.displayInstallOrientation),
        mPageFlipCount(0),
        mIsVirtual(args.isVirtual),
@@ -247,8 +245,6 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
    ALOGE_IF(!mNativeWindow, "No native window was set for display");
    ALOGE_IF(!mDisplaySurface, "No display surface was set for display");
    ALOGE_IF(!mSurface, "No render surface was set for display");
    ALOGE_IF(mDisplayWidth <= 0 || mDisplayHeight <= 0,
             "Invalid dimensions of %d x %d were set for display", mDisplayWidth, mDisplayHeight);

    std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes();
    for (Hdr hdrType : types) {
@@ -287,6 +283,10 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
    }
    mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance);

    ANativeWindow* const window = mNativeWindow.get();
    mDisplayWidth = ANativeWindow_getWidth(window);
    mDisplayHeight = ANativeWindow_getHeight(window);

    // initialize the display orientation transform.
    setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
}
@@ -538,13 +538,8 @@ void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {

    ANativeWindow* const window = mNativeWindow.get();
    mSurface->setNativeWindow(window);
    mDisplayWidth = mSurface->getWidth();
    mDisplayHeight = mSurface->getHeight();

    LOG_FATAL_IF(mDisplayWidth != newWidth,
                "Unable to set new width to %d", newWidth);
    LOG_FATAL_IF(mDisplayHeight != newHeight,
                "Unable to set new height to %d", newHeight);
    mDisplayWidth = newWidth;
    mDisplayHeight = newHeight;
}

void DisplayDevice::setProjection(int orientation,
+0 −2
Original line number Diff line number Diff line
@@ -327,8 +327,6 @@ struct DisplayDeviceCreationArgs {
    sp<ANativeWindow> nativeWindow;
    sp<DisplaySurface> displaySurface;
    std::unique_ptr<renderengine::Surface> renderSurface;
    int displayWidth{0};
    int displayHeight{0};
    int displayInstallOrientation{DisplayState::eOrientationDefault};
    bool hasWideColorGamut{false};
    HdrCapabilities hdrCapabilities;
+0 −2
Original line number Diff line number Diff line
@@ -2342,8 +2342,6 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
    renderSurface->setCritical(isInternalDisplay);
    renderSurface->setAsync(state.isVirtual());
    renderSurface->setNativeWindow(nativeWindow.get());
    creationArgs.displayWidth = renderSurface->getWidth();
    creationArgs.displayHeight = renderSurface->getHeight();
    creationArgs.renderSurface = std::move(renderSurface);

    // Make sure that composition can never be stalled by a virtual display
+8 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include "mock/MockEventThread.h"
#include "mock/MockMessageQueue.h"
#include "mock/RenderEngine/MockRenderEngine.h"
#include "mock/system/window/MockNativeWindow.h"

namespace android {
namespace {
@@ -139,6 +140,7 @@ public:
    sp<DisplayDevice> mExternalDisplay;
    sp<mock::DisplaySurface> mDisplaySurface = new mock::DisplaySurface();
    renderengine::mock::Surface* mRenderSurface = new renderengine::mock::Surface();
    mock::NativeWindow* mNativeWindow = new mock::NativeWindow();

    mock::EventThread* mEventThread = new mock::EventThread();
    mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
@@ -227,6 +229,11 @@ struct BaseDisplayVariant {
    static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_NORMAL;

    static void setupPreconditions(CompositionTest* test) {
        EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0)));
        EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0)));

        FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, HWC2::DisplayType::Physical,
                               true /* isPrimary */)
                .setCapabilities(&test->mDefaultCapabilities)
@@ -234,10 +241,10 @@ struct BaseDisplayVariant {

        test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID,
                                                   false /* isVirtual */, true /* isPrimary */)
                                 .setDisplaySize(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT)
                                 .setDisplaySurface(test->mDisplaySurface)
                                 .setRenderSurface(std::unique_ptr<renderengine::Surface>(
                                         test->mRenderSurface))
                                 .setNativeWindow(test->mNativeWindow)
                                 .setSecure(Derived::IS_SECURE)
                                 .setPowerMode(Derived::INIT_POWER_MODE)
                                 .inject();
+25 −8
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public:
    TestableSurfaceFlinger mFlinger;
    mock::EventThread* mEventThread = new mock::EventThread();
    mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
    sp<mock::NativeWindow> mNativeWindow = new mock::NativeWindow();

    // These mocks are created by the test, but are destroyed by SurfaceFlinger
    // by virtue of being stored into a std::unique_ptr. However we still need
@@ -133,7 +134,6 @@ public:
    sp<mock::GraphicBufferConsumer> mConsumer;
    sp<mock::GraphicBufferProducer> mProducer;
    surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
    sp<mock::NativeWindow> mNativeWindow;
    renderengine::mock::Surface* mRenderSurface = nullptr;
};

@@ -203,7 +203,6 @@ void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
    ASSERT_TRUE(mNativeWindowSurface == nullptr);

    mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
    mNativeWindow = new mock::NativeWindow();

    mFlinger.setCreateNativeWindowSurface([this](auto) {
        return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
@@ -326,6 +325,14 @@ struct DisplayVariant {
                                          static_cast<bool>(VIRTUAL), static_cast<bool>(PRIMARY));

        injector.setSecure(static_cast<bool>(SECURE));
        injector.setNativeWindow(test->mNativeWindow);

        // Creating a DisplayDevice requires getting default dimensions from the
        // native window.
        EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
        EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));
        return injector;
    }

@@ -342,11 +349,17 @@ struct DisplayVariant {
        EXPECT_CALL(*test->mRenderEngine, createSurface())
                .WillOnce(Return(ByMove(
                        std::unique_ptr<renderengine::Surface>(test->mRenderSurface))));

        // Creating a DisplayDevice requires getting default dimensions from the
        // native window.
        EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0)));
        EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0)));

        EXPECT_CALL(*test->mRenderSurface, setAsync(static_cast<bool>(ASYNC))).Times(1);
        EXPECT_CALL(*test->mRenderSurface, setCritical(static_cast<bool>(CRITICAL))).Times(1);
        EXPECT_CALL(*test->mRenderSurface, setNativeWindow(test->mNativeWindow.get())).Times(1);
        EXPECT_CALL(*test->mRenderSurface, getWidth()).WillOnce(Return(WIDTH));
        EXPECT_CALL(*test->mRenderSurface, getHeight()).WillOnce(Return(HEIGHT));
    }

    static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) {
@@ -1111,6 +1124,14 @@ public:
    void getBestColorMode() {
        mInjector.setHwcColorModes(mHwcColorModes);
        mInjector.setHasWideColorGamut(mHasWideColorGamut);
        mInjector.setNativeWindow(mNativeWindow);

        // Creating a DisplayDevice requires getting default dimensions from the
        // native window.
        EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(1080 /* arbitrary */), Return(0)));
        EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _))
                .WillRepeatedly(DoAll(SetArgPointee<1>(1920 /* arbitrary */), Return(0)));
        auto displayDevice = mInjector.inject();

        displayDevice->getBestColorMode(mInputDataspace, mInputRenderIntent, &mOutDataspace,
@@ -1947,8 +1968,6 @@ TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) {
    EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
    EXPECT_CALL(*displaySurface, resizeBuffers(newWidth, oldHeight)).Times(1);
    EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
    EXPECT_CALL(*renderSurface, getWidth()).WillOnce(Return(newWidth));
    EXPECT_CALL(*renderSurface, getHeight()).WillOnce(Return(oldHeight));

    // --------------------------------------------------------------------
    // Invocation
@@ -1988,8 +2007,6 @@ TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) {
    EXPECT_CALL(*renderSurface, setNativeWindow(nullptr)).Times(1);
    EXPECT_CALL(*displaySurface, resizeBuffers(oldWidth, newHeight)).Times(1);
    EXPECT_CALL(*renderSurface, setNativeWindow(nativeWindow)).Times(1);
    EXPECT_CALL(*renderSurface, getWidth()).WillOnce(Return(oldWidth));
    EXPECT_CALL(*renderSurface, getHeight()).WillOnce(Return(newHeight));

    // --------------------------------------------------------------------
    // Invocation
Loading