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

Commit 2afd5172 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Icf7cf2fd,I325521b7,Ia80c865d,I73599f62,I8526e671, ... into pi-dev

* changes:
  SF: Use display device factory in unit test
  SF: Introduce mock::NativeWindowSurface
  SF: Refactor display device creation
  SF: Introduce mock::NativeWindow
  SF: Introduce mock::DisplaySurface
  SF: Introduce mock::EventControlThread
  SF: Separate EventControlThread into interface and impl
  SF: Define mock::SurfaceInterceptor
  SF: Separate SurfaceInterceptor into interface and impl
  SF: Define mock::MessageQueue
  SF: Separate MessageQueue into interface and impl
  SF: libsurfaceflinger_unittest should skip SF ctor
  SF: Switch to internal display setup
parents 0c2de368 1fa4d46f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -690,7 +690,7 @@ void BufferLayer::onFrameAvailable(const BufferItem& item) {
    // Add this buffer from our internal queue tracker
    { // Autolock scope
        Mutex::Autolock lock(mQueueItemLock);
        mFlinger->mInterceptor.saveBufferUpdate(this, item.mGraphicBuffer->getWidth(),
        mFlinger->mInterceptor->saveBufferUpdate(this, item.mGraphicBuffer->getWidth(),
                                                 item.mGraphicBuffer->getHeight(),
                                                 item.mFrameNumber);
        // Reset the frame number tracker when we receive the first buffer after
+19 −51
Original line number Diff line number Diff line
@@ -57,9 +57,6 @@ using namespace android;
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;

static bool useTripleFramebuffer = getInt64< ISurfaceFlingerConfigs,
        &ISurfaceFlingerConfigs::maxFrameBufferAcquiredBuffers>(2) >= 3;

/*
 * Initialize the display to the specified values.
 *
@@ -74,72 +71,43 @@ DisplayDevice::DisplayDevice(
        int32_t hwcId,
        bool isSecure,
        const wp<IBinder>& displayToken,
        const sp<ANativeWindow>& nativeWindow,
        const sp<DisplaySurface>& displaySurface,
        const sp<IGraphicBufferProducer>& producer,
        std::unique_ptr<RE::Surface> renderSurface,
        int displayWidth,
        int displayHeight,
        bool supportWideColor,
        bool supportHdr)
        bool supportHdr,
        int initialPowerMode)
    : lastCompositionHadVisibleLayers(false),
      mFlinger(flinger),
      mType(type),
      mHwcDisplayId(hwcId),
      mDisplayToken(displayToken),
      mNativeWindow(nativeWindow),
      mDisplaySurface(displaySurface),
      mSurface{flinger->getRenderEngine().createSurface()},
      mDisplayWidth(),
      mDisplayHeight(),
      mPageFlipCount(),
      mSurface{std::move(renderSurface)},
      mDisplayWidth(displayWidth),
      mDisplayHeight(displayHeight),
      mPageFlipCount(0),
      mIsSecure(isSecure),
      mLayerStack(NO_LAYER_STACK),
      mOrientation(),
      mPowerMode(HWC_POWER_MODE_OFF),
      mActiveConfig(0)
      mViewport(Rect::INVALID_RECT),
      mFrame(Rect::INVALID_RECT),
      mPowerMode(initialPowerMode),
      mActiveConfig(0),
      mActiveColorMode(ColorMode::NATIVE),
      mDisplayHasWideColor(supportWideColor),
      mDisplayHasHdr(supportHdr)
{
    // clang-format on
    Surface* surface;
    mNativeWindow = surface = new Surface(producer, false);
    ANativeWindow* const window = mNativeWindow.get();

    mActiveColorMode = ColorMode::NATIVE;
    mDisplayHasWideColor = supportWideColor;
    mDisplayHasHdr = supportHdr;

    /*
     * Create our display's surface
     */
    mSurface->setCritical(mType == DisplayDevice::DISPLAY_PRIMARY);
    mSurface->setAsync(mType >= DisplayDevice::DISPLAY_VIRTUAL);
    mSurface->setNativeWindow(window);
    mDisplayWidth = mSurface->queryWidth();
    mDisplayHeight = mSurface->queryHeight();

    // Make sure that composition can never be stalled by a virtual display
    // consumer that isn't processing buffers fast enough. We have to do this
    // in two places:
    // * Here, in case the display is composed entirely by HWC.
    // * In makeCurrent(), using eglSwapInterval. Some EGL drivers set the
    //   window's swap interval in eglMakeCurrent, so they'll override the
    //   interval we set here.
    if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
        window->setSwapInterval(window, 0);

    mPageFlipCount = 0;
    mViewport.makeInvalid();
    mFrame.makeInvalid();

    // virtual displays are always considered enabled
    mPowerMode = (mType >= DisplayDevice::DISPLAY_VIRTUAL) ?
                  HWC_POWER_MODE_NORMAL : HWC_POWER_MODE_OFF;

    // initialize the display orientation transform.
    setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);

    if (useTripleFramebuffer) {
        surface->allocateBuffers();
    }
}

DisplayDevice::~DisplayDevice() {
}
DisplayDevice::~DisplayDevice() = default;

void DisplayDevice::disconnect(HWComposer& hwc) {
    if (mHwcDisplayId >= 0) {
+7 −2
Original line number Diff line number Diff line
@@ -77,9 +77,14 @@ public:
            int32_t hwcId,
            bool isSecure,
            const wp<IBinder>& displayToken,
            const sp<ANativeWindow>& nativeWindow,
            const sp<DisplaySurface>& displaySurface,
            const sp<IGraphicBufferProducer>& producer,
            bool supportWideColor, bool supportHdr);
            std::unique_ptr<RE::Surface> renderSurface,
            int displayWidth,
            int displayHeight,
            bool supportWideColor,
            bool supportHdr,
            int initialPowerMode);
    // clang-format on

    ~DisplayDevice();
+9 −9
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ Error Device::createVirtualDisplay(uint32_t width, uint32_t height,

    auto display = std::make_unique<Display>(
            *mComposer.get(), mCapabilities, displayId, DisplayType::Virtual);
    display->setConnected(true);
    *outDisplay = display.get();
    *format = static_cast<android_pixel_format_t>(intFormat);
    mDisplays.emplace(displayId, std::move(display));
@@ -168,6 +169,7 @@ void Device::onHotplug(hwc2_display_t displayId, Connection connection) {

        auto newDisplay = std::make_unique<Display>(
                *mComposer.get(), mCapabilities, displayId, displayType);
        newDisplay->setConnected(true);
        mDisplays.emplace(displayId, std::move(newDisplay));
    } else if (connection == Connection::Disconnected) {
        // The display will later be destroyed by a call to
@@ -209,16 +211,14 @@ Error Device::flushCommands()
// Display methods

Display::Display(android::Hwc2::Composer& composer,
                 const std::unordered_set<Capability>& capabilities,
                 hwc2_display_t id, DisplayType type)
                 const std::unordered_set<Capability>& capabilities, hwc2_display_t id,
                 DisplayType type)
      : mComposer(composer),
        mCapabilities(capabilities),
        mId(id),
        mIsConnected(false),
    mType(type)
{
        mType(type) {
    ALOGV("Created display %" PRIu64, id);
    setConnected(true);
}

Display::~Display() {
+5 −2
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ namespace android {
    namespace Hwc2 {
        class Composer;
    }

    class TestableSurfaceFlinger;
}

namespace HWC2 {
@@ -126,8 +128,7 @@ private:
class Display
{
public:
    Display(android::Hwc2::Composer& composer,
            const std::unordered_set<Capability>& capabilities,
    Display(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities,
            hwc2_display_t id, DisplayType type);
    ~Display();

@@ -263,6 +264,8 @@ private:
    // on this display
    Layer* getLayerById(hwc2_layer_t id) const;

    friend android::TestableSurfaceFlinger;

    // Member variables

    // These are references to data owned by HWC2::Device, which will outlive
Loading