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

Commit 50121d58 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Use RenderSurfaceCreationArgsBuilder

Fix -Wmissing-field-initializers errors silenced via pragmas.

Bug: 129481165
Test: m libcompositionengine_test
Change-Id: I6b254be239b173af599c4423f190472af218dbb9
parent f1833853
Loading
Loading
Loading
Loading
+14 −25
Original line number Diff line number Diff line
@@ -24,21 +24,17 @@

struct ANativeWindow;

namespace android {

namespace compositionengine {

class Display;
namespace android::compositionengine {

/**
 * A parameter object for creating RenderSurface instances
 */
struct RenderSurfaceCreationArgs {
    // The initial width of the surface
    int32_t displayWidth;
    int32_t displayWidth = -1;

    // The initial height of the surface
    int32_t displayHeight;
    int32_t displayHeight = -1;

    // The ANativeWindow for the buffer queue for this surface
    sp<ANativeWindow> nativeWindow;
@@ -46,22 +42,16 @@ struct RenderSurfaceCreationArgs {
    // The DisplaySurface for this surface
    sp<DisplaySurface> displaySurface;

    size_t maxTextureCacheSize;
    // The maximum size of the renderengine::ExternalTexture cache
    size_t maxTextureCacheSize = 0;

private:
    friend class RenderSurfaceCreationArgsBuilder;

    // Not defaulted to disable aggregate initialization.
    RenderSurfaceCreationArgs() {}
};

/**
 * A helper for setting up a RenderSurfaceCreationArgs value in-line.
 * Prefer this builder over raw structure initialization.
 *
 * Instead of:
 *
 *   RenderSurfaceCreationArgs{1000, 1000, nativeWindow, displaySurface}
 *
 * Prefer:
 *
 *  RenderSurfaceCreationArgsBuilder().setDisplayWidth(1000).setDisplayHeight(1000)
 *      .setNativeWindow(nativeWindow).setDisplaySurface(displaySurface).Build();
 */
class RenderSurfaceCreationArgsBuilder {
public:
    RenderSurfaceCreationArgs build() { return std::move(mArgs); }
@@ -75,11 +65,11 @@ public:
        return *this;
    }
    RenderSurfaceCreationArgsBuilder& setNativeWindow(sp<ANativeWindow> nativeWindow) {
        mArgs.nativeWindow = nativeWindow;
        mArgs.nativeWindow = std::move(nativeWindow);
        return *this;
    }
    RenderSurfaceCreationArgsBuilder& setDisplaySurface(sp<DisplaySurface> displaySurface) {
        mArgs.displaySurface = displaySurface;
        mArgs.displaySurface = std::move(displaySurface);
        return *this;
    }

@@ -92,5 +82,4 @@ private:
    RenderSurfaceCreationArgs mArgs;
};

} // namespace compositionengine
} // namespace android
} // namespace android::compositionengine
+11 −4
Original line number Diff line number Diff line
@@ -522,7 +522,11 @@ using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
    EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
    EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
    mDisplay->createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr});
    mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
                                          .setDisplayWidth(640)
                                          .setDisplayHeight(480)
                                          .setNativeWindow(mNativeWindow)
                                          .build());
    EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
}

@@ -1030,9 +1034,12 @@ struct DisplayFunctionalTest : public testing::Test {
    );
    impl::RenderSurface* mRenderSurface =
            new impl::RenderSurface{mCompositionEngine, *mDisplay,
                                    RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH,
                                                              DEFAULT_DISPLAY_HEIGHT, mNativeWindow,
                                                              mDisplaySurface}};
                                    RenderSurfaceCreationArgsBuilder()
                                            .setDisplayWidth(DEFAULT_DISPLAY_WIDTH)
                                            .setDisplayHeight(DEFAULT_DISPLAY_HEIGHT)
                                            .setNativeWindow(mNativeWindow)
                                            .setDisplaySurface(mDisplaySurface)
                                            .build()};
};

TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
+9 −13
Original line number Diff line number Diff line
@@ -14,12 +14,6 @@
 * limitations under the License.
 */

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#include "renderengine/ExternalTexture.h"
#include "ui/GraphicBuffer.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextra"

#include <cstdarg>
#include <cstdint>

@@ -32,7 +26,9 @@
#include <compositionengine/mock/NativeWindow.h>
#include <compositionengine/mock/OutputLayer.h>
#include <gtest/gtest.h>
#include <renderengine/ExternalTexture.h>
#include <renderengine/mock/RenderEngine.h>
#include <ui/GraphicBuffer.h>

namespace android::compositionengine {
namespace {
@@ -67,9 +63,12 @@ public:
    sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
    sp<mock::DisplaySurface> mDisplaySurface = new StrictMock<mock::DisplaySurface>();
    impl::RenderSurface mSurface{mCompositionEngine, mDisplay,
                                 RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH,
                                                           DEFAULT_DISPLAY_HEIGHT, mNativeWindow,
                                                           mDisplaySurface}};
                                 RenderSurfaceCreationArgsBuilder()
                                         .setDisplayWidth(DEFAULT_DISPLAY_WIDTH)
                                         .setDisplayHeight(DEFAULT_DISPLAY_HEIGHT)
                                         .setNativeWindow(mNativeWindow)
                                         .setDisplaySurface(mDisplaySurface)
                                         .build()};
};

/*
@@ -367,11 +366,8 @@ TEST_F(RenderSurfaceTest, flipForwardsSignal) {

    mSurface.flip();

    EXPECT_EQ(501, mSurface.getPageFlipCount());
    EXPECT_EQ(501u, mSurface.getPageFlipCount());
}

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

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic pop // ignored "-Wextra"
+8 −7
Original line number Diff line number Diff line
@@ -70,13 +70,14 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
        mIsPrimary(args.isPrimary) {
    mCompositionDisplay->editState().isSecure = args.isSecure;
    mCompositionDisplay->createRenderSurface(
            compositionengine::
                    RenderSurfaceCreationArgs{ANativeWindow_getWidth(args.nativeWindow.get()),
                                              ANativeWindow_getHeight(args.nativeWindow.get()),
                                              args.nativeWindow, args.displaySurface,
                                              static_cast<size_t>(
                                                      SurfaceFlinger::
                                                              maxFrameBufferAcquiredBuffers)});
            compositionengine::RenderSurfaceCreationArgsBuilder()
                    .setDisplayWidth(ANativeWindow_getWidth(args.nativeWindow.get()))
                    .setDisplayHeight(ANativeWindow_getHeight(args.nativeWindow.get()))
                    .setNativeWindow(std::move(args.nativeWindow))
                    .setDisplaySurface(std::move(args.displaySurface))
                    .setMaxTextureCacheSize(
                            static_cast<size_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers))
                    .build());

    if (!mFlinger->mDisableClientCompositionCache &&
        SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) {