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

Commit 05b3cd9a authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by android-build-merger
Browse files

Merge "Revert "Avoid a potential race condition on mDisplays"" into oc-dev am: c90e4693

am: 5599839f

Change-Id: Iabf61759bda0fc023a925e40ebf1a4b20f996465
parents 581246e8 5599839f
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -206,7 +206,7 @@ void HWComposer::hotplug(const std::shared_ptr<HWC2::Display>& display,
        }
        }
        disp = DisplayDevice::DISPLAY_EXTERNAL;
        disp = DisplayDevice::DISPLAY_EXTERNAL;
    }
    }
    mEventHandler->onHotplugReceived(this, disp,
    mEventHandler->onHotplugReceived(disp,
            connected == HWC2::Connection::Connected);
            connected == HWC2::Connection::Connected);
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ public:
        friend class HWComposer;
        friend class HWComposer;
        virtual void onVSyncReceived(
        virtual void onVSyncReceived(
            HWComposer* composer, int32_t disp, nsecs_t timestamp) = 0;
            HWComposer* composer, int32_t disp, nsecs_t timestamp) = 0;
        virtual void onHotplugReceived(HWComposer* composer, int32_t disp, bool connected) = 0;
        virtual void onHotplugReceived(int32_t disp, bool connected) = 0;
        virtual void onInvalidateReceived(HWComposer* composer) = 0;
        virtual void onInvalidateReceived(HWComposer* composer) = 0;
    protected:
    protected:
        virtual ~EventHandler() {}
        virtual ~EventHandler() {}
+1 −1
Original line number Original line Diff line number Diff line
@@ -315,7 +315,7 @@ void HWComposer::hotplug(int disp, int connected) {
    queryDisplayProperties(disp);
    queryDisplayProperties(disp);
    // Do not teardown or recreate the primary display
    // Do not teardown or recreate the primary display
    if (disp != HWC_DISPLAY_PRIMARY) {
    if (disp != HWC_DISPLAY_PRIMARY) {
        mEventHandler.onHotplugReceived(this, disp, bool(connected));
        mEventHandler.onHotplugReceived(disp, bool(connected));
    }
    }
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ public:
        friend class HWComposer;
        friend class HWComposer;
        virtual void onVSyncReceived(
        virtual void onVSyncReceived(
            HWComposer* composer, int32_t disp, nsecs_t timestamp) = 0;
            HWComposer* composer, int32_t disp, nsecs_t timestamp) = 0;
        virtual void onHotplugReceived(HWComposer* composer, int disp, bool connected) = 0;
        virtual void onHotplugReceived(int disp, bool connected) = 0;
        virtual void onInvalidateReceived(HWComposer* composer) = 0;
        virtual void onInvalidateReceived(HWComposer* composer) = 0;
    protected:
    protected:
        virtual ~EventHandler() {}
        virtual ~EventHandler() {}
+72 −99
Original line number Original line Diff line number Diff line
@@ -606,7 +606,7 @@ void SurfaceFlinger::init() {


    // make the GLContext current so that we can create textures when creating
    // make the GLContext current so that we can create textures when creating
    // Layers (which may happens before we render something)
    // Layers (which may happens before we render something)
    getDefaultDisplayDeviceLocked()->makeCurrent(mEGLDisplay, mEGLContext);
    getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext);


    mEventControlThread = new EventControlThread(this);
    mEventControlThread = new EventControlThread(this);
    mEventControlThread->run("EventControl", PRIORITY_URGENT_DISPLAY);
    mEventControlThread->run("EventControl", PRIORITY_URGENT_DISPLAY);
@@ -741,11 +741,8 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& display,
            info.density = density;
            info.density = density;


            // TODO: this needs to go away (currently needed only by webkit)
            // TODO: this needs to go away (currently needed only by webkit)
            {
            sp<const DisplayDevice> hw(getDefaultDisplayDevice());
                Mutex::Autolock _l(mStateLock);
                sp<const DisplayDevice> hw(getDefaultDisplayDeviceLocked());
            info.orientation = hw->getOrientation();
            info.orientation = hw->getOrientation();
            }
        } else {
        } else {
            // TODO: where should this value come from?
            // TODO: where should this value come from?
            static const int TV_DENSITY = 213;
            static const int TV_DENSITY = 213;
@@ -802,13 +799,10 @@ int SurfaceFlinger::getActiveConfig(const sp<IBinder>& display) {
        ALOGE("%s : display is NULL", __func__);
        ALOGE("%s : display is NULL", __func__);
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }

    Mutex::Autolock _l(mStateLock);
    sp<DisplayDevice> device(getDisplayDevice(display));
    sp<DisplayDevice> device(getDisplayDevice(display));
    if (device != NULL) {
    if (device != NULL) {
        return device->getActiveConfig();
        return device->getActiveConfig();
    }
    }

    return BAD_VALUE;
    return BAD_VALUE;
}
}


@@ -896,7 +890,6 @@ status_t SurfaceFlinger::getDisplayColorModes(const sp<IBinder>& display,
}
}


android_color_mode_t SurfaceFlinger::getActiveColorMode(const sp<IBinder>& display) {
android_color_mode_t SurfaceFlinger::getActiveColorMode(const sp<IBinder>& display) {
    Mutex::Autolock _l(mStateLock);
    sp<DisplayDevice> device(getDisplayDevice(display));
    sp<DisplayDevice> device(getDisplayDevice(display));
    if (device != nullptr) {
    if (device != nullptr) {
        return device->getActiveColorMode();
        return device->getActiveColorMode();
@@ -1158,22 +1151,34 @@ void SurfaceFlinger::getCompositorTiming(CompositorTiming* compositorTiming) {
    *compositorTiming = mCompositorTiming;
    *compositorTiming = mCompositorTiming;
}
}


void SurfaceFlinger::createDefaultDisplayDevice() {
void SurfaceFlinger::onHotplugReceived(int32_t disp, bool connected) {
    const int32_t type = DisplayDevice::DISPLAY_PRIMARY;
    ALOGV("onHotplugReceived(%d, %s)", disp, connected ? "true" : "false");
    wp<IBinder> token = mBuiltinDisplays[type];
    if (disp == DisplayDevice::DISPLAY_PRIMARY) {
        Mutex::Autolock lock(mStateLock);


        // All non-virtual displays are currently considered secure.
        // All non-virtual displays are currently considered secure.
    const bool isSecure = true;
        bool isSecure = true;

        int32_t type = DisplayDevice::DISPLAY_PRIMARY;

        // When we're using the vr composer, the assumption is that we've
        // already created the IBinder object for the primary display.
        if (!mHwc->isUsingVrComposer()) {
            createBuiltinDisplayLocked(DisplayDevice::DISPLAY_PRIMARY);
        }

        wp<IBinder> token = mBuiltinDisplays[type];


        sp<IGraphicBufferProducer> producer;
        sp<IGraphicBufferProducer> producer;
        sp<IGraphicBufferConsumer> consumer;
        sp<IGraphicBufferConsumer> consumer;
    BufferQueue::createBufferQueue(&producer, &consumer, new GraphicBufferAlloc());
        BufferQueue::createBufferQueue(&producer, &consumer,
                new GraphicBufferAlloc());


    sp<FramebufferSurface> fbs = new FramebufferSurface(*mHwc, type, consumer);
        sp<FramebufferSurface> fbs = new FramebufferSurface(*mHwc,
                DisplayDevice::DISPLAY_PRIMARY, consumer);


        bool hasWideColorModes = false;
        bool hasWideColorModes = false;
    std::vector<android_color_mode_t> modes = getHwComposer().getColorModes(
        std::vector<android_color_mode_t> modes = getHwComposer().getColorModes(type);
        type);
        for (android_color_mode_t colorMode : modes) {
        for (android_color_mode_t colorMode : modes) {
            switch (colorMode) {
            switch (colorMode) {
                case HAL_COLOR_MODE_DISPLAY_P3:
                case HAL_COLOR_MODE_DISPLAY_P3:
@@ -1185,8 +1190,9 @@ void SurfaceFlinger::createDefaultDisplayDevice() {
                    break;
                    break;
            }
            }
        }
        }
    sp<DisplayDevice> hw = new DisplayDevice(this, DisplayDevice::DISPLAY_PRIMARY, type, isSecure,
        sp<DisplayDevice> hw =
                                             token, fbs, producer, mRenderEngine->getEGLConfig(),
                new DisplayDevice(this, DisplayDevice::DISPLAY_PRIMARY, disp, isSecure, token, fbs,
                                  producer, mRenderEngine->getEGLConfig(),
                                  hasWideColorModes && hasWideColorDisplay);
                                  hasWideColorModes && hasWideColorDisplay);
        mDisplays.add(token, hw);
        mDisplays.add(token, hw);
        android_color_mode defaultColorMode = HAL_COLOR_MODE_NATIVE;
        android_color_mode defaultColorMode = HAL_COLOR_MODE_NATIVE;
@@ -1194,24 +1200,6 @@ void SurfaceFlinger::createDefaultDisplayDevice() {
            defaultColorMode = HAL_COLOR_MODE_SRGB;
            defaultColorMode = HAL_COLOR_MODE_SRGB;
        }
        }
        setActiveColorModeInternal(hw, defaultColorMode);
        setActiveColorModeInternal(hw, defaultColorMode);
}

void SurfaceFlinger::onHotplugReceived(HWComposer* composer, int32_t disp, bool connected) {
    ALOGV("onHotplugReceived(%d, %s)", disp, connected ? "true" : "false");

    if (composer->isUsingVrComposer()) {
        // We handle initializing the primary display device for the VR
        // window manager hwc explicitly at the time of transition.
        if (disp != DisplayDevice::DISPLAY_PRIMARY) {
            ALOGE("External displays are not supported by the vr hardware composer.");
        }
        return;
    }

    if (disp == DisplayDevice::DISPLAY_PRIMARY) {
        Mutex::Autolock lock(mStateLock);
        createBuiltinDisplayLocked(DisplayDevice::DISPLAY_PRIMARY);
        createDefaultDisplayDevice();
    } else {
    } else {
        auto type = DisplayDevice::DISPLAY_EXTERNAL;
        auto type = DisplayDevice::DISPLAY_EXTERNAL;
        Mutex::Autolock _l(mStateLock);
        Mutex::Autolock _l(mStateLock);
@@ -1253,7 +1241,6 @@ void SurfaceFlinger::clearHwcLayers(const LayerVector& layers) {
    }
    }
}
}


// Note: it is assumed the caller holds |mStateLock| when this is called
void SurfaceFlinger::resetHwc() {
void SurfaceFlinger::resetHwc() {
    disableHardwareVsync(true);
    disableHardwareVsync(true);
    clearHwcLayers(mDrawingState.layersSortedByZ);
    clearHwcLayers(mDrawingState.layersSortedByZ);
@@ -1274,16 +1261,12 @@ void SurfaceFlinger::updateVrFlinger() {
    if (vrFlingerRequestsDisplay == mHwc->isUsingVrComposer()) {
    if (vrFlingerRequestsDisplay == mHwc->isUsingVrComposer()) {
        return;
        return;
    }
    }

    bool vrHwcNewlyInitialized = false;

    if (vrFlingerRequestsDisplay && !mVrHwc) {
    if (vrFlingerRequestsDisplay && !mVrHwc) {
        // Construct new HWComposer without holding any locks.
        // Construct new HWComposer without holding any locks.
        mVrHwc = new HWComposer(true);
        mVrHwc = new HWComposer(true);
        vrHwcNewlyInitialized = true;
        ALOGV("Vr HWC created");
        ALOGV("Vr HWC created");
    }
    }

    {
        Mutex::Autolock _l(mStateLock);
        Mutex::Autolock _l(mStateLock);


        if (vrFlingerRequestsDisplay) {
        if (vrFlingerRequestsDisplay) {
@@ -1291,11 +1274,6 @@ void SurfaceFlinger::updateVrFlinger() {


            mHwc = mVrHwc;
            mHwc = mVrHwc;
            mVrFlinger->GrantDisplayOwnership();
            mVrFlinger->GrantDisplayOwnership();

        if (vrHwcNewlyInitialized) {
            mVrHwc->setEventHandler(
                static_cast<HWComposer::EventHandler*>(this));
        }
        } else {
        } else {
            mVrFlinger->SeizeDisplayOwnership();
            mVrFlinger->SeizeDisplayOwnership();


@@ -1307,14 +1285,13 @@ void SurfaceFlinger::updateVrFlinger() {


        mVisibleRegionsDirty = true;
        mVisibleRegionsDirty = true;
        invalidateHwcGeometry();
        invalidateHwcGeometry();

    // Explicitly re-initialize the primary display. This is because some other
    // parts of this class rely on the primary display always being available.
    createDefaultDisplayDevice();

        android_atomic_or(1, &mRepaintEverything);
        android_atomic_or(1, &mRepaintEverything);
        setTransactionFlags(eDisplayTransactionNeeded);
        setTransactionFlags(eDisplayTransactionNeeded);
    }
    }
    if (mVrHwc) {
        mVrHwc->setEventHandler(static_cast<HWComposer::EventHandler*>(this));
    }
}


void SurfaceFlinger::onMessageReceived(int32_t what) {
void SurfaceFlinger::onMessageReceived(int32_t what) {
    ATRACE_CALL();
    ATRACE_CALL();
@@ -1523,8 +1500,7 @@ void SurfaceFlinger::postComposition(nsecs_t refreshStartTime)
        layer->releasePendingBuffer(dequeueReadyTime);
        layer->releasePendingBuffer(dequeueReadyTime);
    }
    }


    // |mStateLock| not needed as we are on the main thread
    const sp<const DisplayDevice> hw(getDefaultDisplayDevice());
    const sp<const DisplayDevice> hw(getDefaultDisplayDeviceLocked());


    std::shared_ptr<FenceTime> glCompositionDoneFenceTime;
    std::shared_ptr<FenceTime> glCompositionDoneFenceTime;
    if (mHwc->hasClientComposition(HWC_DISPLAY_PRIMARY)) {
    if (mHwc->hasClientComposition(HWC_DISPLAY_PRIMARY)) {
@@ -1872,8 +1848,7 @@ void SurfaceFlinger::postFramebuffer()
    mLastSwapBufferTime = systemTime() - now;
    mLastSwapBufferTime = systemTime() - now;
    mDebugInSwapBuffers = 0;
    mDebugInSwapBuffers = 0;


    // |mStateLock| not needed as we are on the main thread
    uint32_t flipCount = getDefaultDisplayDevice()->getPageFlipCount();
    uint32_t flipCount = getDefaultDisplayDeviceLocked()->getPageFlipCount();
    if (flipCount % LOG_FRAME_STATS_PERIOD == 0) {
    if (flipCount % LOG_FRAME_STATS_PERIOD == 0) {
        logFrameStats();
        logFrameStats();
    }
    }
@@ -1958,7 +1933,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
                        // Call makeCurrent() on the primary display so we can
                        // Call makeCurrent() on the primary display so we can
                        // be sure that nothing associated with this display
                        // be sure that nothing associated with this display
                        // is current.
                        // is current.
                        const sp<const DisplayDevice> defaultDisplay(getDefaultDisplayDeviceLocked());
                        const sp<const DisplayDevice> defaultDisplay(getDefaultDisplayDevice());
                        defaultDisplay->makeCurrent(mEGLDisplay, mEGLContext);
                        defaultDisplay->makeCurrent(mEGLDisplay, mEGLContext);
                        sp<DisplayDevice> hw(getDisplayDevice(draw.keyAt(i)));
                        sp<DisplayDevice> hw(getDisplayDevice(draw.keyAt(i)));
                        if (hw != NULL)
                        if (hw != NULL)
@@ -2148,7 +2123,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
                // could be null when this layer is using a layerStack
                // could be null when this layer is using a layerStack
                // that is not visible on any display. Also can occur at
                // that is not visible on any display. Also can occur at
                // screen off/on times.
                // screen off/on times.
                disp = getDefaultDisplayDeviceLocked();
                disp = getDefaultDisplayDevice();
            }
            }
            layer->updateTransformHint(disp);
            layer->updateTransformHint(disp);


@@ -2504,9 +2479,7 @@ bool SurfaceFlinger::doComposeSurfaces(
            ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s",
            ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s",
                  displayDevice->getDisplayName().string());
                  displayDevice->getDisplayName().string());
            eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
            eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

            if(!getDefaultDisplayDevice()->makeCurrent(mEGLDisplay, mEGLContext)) {
            // |mStateLock| not needed as we are on the main thread
            if(!getDefaultDisplayDeviceLocked()->makeCurrent(mEGLDisplay, mEGLContext)) {
              ALOGE("DisplayDevice::makeCurrent on default display failed. Aborting.");
              ALOGE("DisplayDevice::makeCurrent on default display failed. Aborting.");
            }
            }
            return false;
            return false;
@@ -3598,7 +3571,7 @@ void SurfaceFlinger::dumpAllLocked(const Vector<String16>& args, size_t& index,
    colorizer.reset(result);
    colorizer.reset(result);


    HWComposer& hwc(getHwComposer());
    HWComposer& hwc(getHwComposer());
    sp<const DisplayDevice> hw(getDefaultDisplayDeviceLocked());
    sp<const DisplayDevice> hw(getDefaultDisplayDevice());


    colorizer.bold(result);
    colorizer.bold(result);
    result.appendFormat("EGL implementation : %s\n",
    result.appendFormat("EGL implementation : %s\n",
@@ -3828,7 +3801,7 @@ status_t SurfaceFlinger::onTransact(
                return NO_ERROR;
                return NO_ERROR;
            case 1013: {
            case 1013: {
                Mutex::Autolock _l(mStateLock);
                Mutex::Autolock _l(mStateLock);
                sp<const DisplayDevice> hw(getDefaultDisplayDeviceLocked());
                sp<const DisplayDevice> hw(getDefaultDisplayDevice());
                reply->writeInt32(hw->getPageFlipCount());
                reply->writeInt32(hw->getPageFlipCount());
                return NO_ERROR;
                return NO_ERROR;
            }
            }
Loading