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

Commit 2f5bd001 authored by Chia-I Wu's avatar Chia-I Wu Committed by android-build-merger
Browse files

surfaceflinger: make vsync injection more robust am: 6200eacd am: ffbf2d94

am: 3c192d05

Change-Id: I229ea69baff9295ace1495111640eca1222486c8
parents 1dbadb9c 3c192d05
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -91,6 +91,14 @@ void MessageQueue::init(const sp<SurfaceFlinger>& flinger)

void MessageQueue::setEventThread(const sp<EventThread>& eventThread)
{
    if (mEventThread == eventThread) {
        return;
    }

    if (mEventTube.getFd() >= 0) {
        mLooper->removeFd(mEventTube.getFd());
    }

    mEventThread = eventThread;
    mEvents = eventThread->createEventConnection();
    mEvents->stealReceiveChannel(&mEventTube);
+30 −7
Original line number Diff line number Diff line
@@ -568,8 +568,10 @@ public:

    virtual void onInjectSyncEvent(nsecs_t when) {
        std::lock_guard<std::mutex> lock(mCallbackMutex);
        if (mCallback != nullptr) {
            mCallback->onVSyncEvent(when);
        }
    }

    virtual void setVSyncEnabled(bool) {}
    virtual void setPhaseOffset(nsecs_t) {}
@@ -1063,13 +1065,14 @@ status_t SurfaceFlinger::getHdrCapabilities(const sp<IBinder>& display,
    return NO_ERROR;
}

status_t SurfaceFlinger::enableVSyncInjections(bool enable) {
    if (enable == mInjectVSyncs) {
        return NO_ERROR;
void SurfaceFlinger::enableVSyncInjectionsInternal(bool enable) {
    Mutex::Autolock _l(mStateLock);

    if (mInjectVSyncs == enable) {
        return;
    }

    if (enable) {
        mInjectVSyncs = enable;
        ALOGV("VSync Injections enabled");
        if (mVSyncInjector.get() == nullptr) {
            mVSyncInjector = new InjectVSyncSource();
@@ -1077,15 +1080,33 @@ status_t SurfaceFlinger::enableVSyncInjections(bool enable) {
        }
        mEventQueue.setEventThread(mInjectorEventThread);
    } else {
        mInjectVSyncs = enable;
        ALOGV("VSync Injections disabled");
        mEventQueue.setEventThread(mSFEventThread);
        mVSyncInjector.clear();
    }

    mInjectVSyncs = enable;
}

status_t SurfaceFlinger::enableVSyncInjections(bool enable) {
    class MessageEnableVSyncInjections : public MessageBase {
        SurfaceFlinger* mFlinger;
        bool mEnable;
    public:
        MessageEnableVSyncInjections(SurfaceFlinger* flinger, bool enable)
            : mFlinger(flinger), mEnable(enable) { }
        virtual bool handler() {
            mFlinger->enableVSyncInjectionsInternal(mEnable);
            return true;
        }
    };
    sp<MessageBase> msg = new MessageEnableVSyncInjections(this, enable);
    postMessageSync(msg);
    return NO_ERROR;
}

status_t SurfaceFlinger::injectVSync(nsecs_t when) {
    Mutex::Autolock _l(mStateLock);

    if (!mInjectVSyncs) {
        ALOGE("VSync Injections not enabled");
        return BAD_VALUE;
@@ -3948,6 +3969,8 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) {
        case GET_ANIMATION_FRAME_STATS:
        case SET_POWER_MODE:
        case GET_HDR_CAPABILITIES:
        case ENABLE_VSYNC_INJECTIONS:
        case INJECT_VSYNC:
        {
            // codes that require permission check
            IPCThreadState* ipc = IPCThreadState::self();
+3 −0
Original line number Diff line number Diff line
@@ -367,6 +367,9 @@ private:
    // Called on the main thread in response to setActiveColorMode()
    void setActiveColorModeInternal(const sp<DisplayDevice>& hw, android_color_mode_t colorMode);

    // Called on the main thread in response to enableVSyncInjections()
    void enableVSyncInjectionsInternal(bool enable);

    // Returns whether the transaction actually modified any state
    bool handleMessageTransaction();