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

Commit 67016af1 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

fix an issue where SF would spin if /sys/power/wait_for_fb_xxx don't exist

we now exit the Display thread on any error happening on these files.
also refactor the code and remove a lot of unused stuff.

Change-Id: I8d080c35b211890ca20ae09fa36fbdccdf5669a8
parent 93bfeedd
Loading
Loading
Loading
Loading
+54 −69
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2007 The Android Open Source Project
 * Copyright (C) 2012 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#include <assert.h>
#include <errno.h>
#include <errno.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
@@ -22,15 +21,6 @@


#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <signal.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>

#include <linux/unistd.h>


#include <utils/Log.h>
#include <utils/Log.h>


@@ -45,39 +35,30 @@ static char const * const kWakeFileName = "/sys/power/wait_for_fb_wake";


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


DisplayHardwareBase::DisplayEventThreadBase::DisplayEventThreadBase(
DisplayHardwareBase::DisplayEventThread::DisplayEventThread(
        const sp<SurfaceFlinger>& flinger)
        const sp<SurfaceFlinger>& flinger)
    : Thread(false), mFlinger(flinger) {
    : Thread(false), mFlinger(flinger) {
}
}


DisplayHardwareBase::DisplayEventThreadBase::~DisplayEventThreadBase() {
DisplayHardwareBase::DisplayEventThread::~DisplayEventThread() {
}
}


// ----------------------------------------------------------------------------
void DisplayHardwareBase::DisplayEventThread::onFirstRef() {

    if (initCheck() == NO_ERROR) {
DisplayHardwareBase::DisplayEventThread::DisplayEventThread(
        run("DisplayEventThread", PRIORITY_URGENT_DISPLAY);
        const sp<SurfaceFlinger>& flinger)
    } else {
    : DisplayEventThreadBase(flinger)
        ALOGW("/sys/power/wait_for_fb_{wake|sleep} don't exist");
{
    }
}
}


DisplayHardwareBase::DisplayEventThread::~DisplayEventThread()
status_t DisplayHardwareBase::DisplayEventThread::initCheck() const {
{
    return ((access(kSleepFileName, R_OK) == 0 &&
            access(kWakeFileName, R_OK) == 0)) ? NO_ERROR : NO_INIT;
}
}


bool DisplayHardwareBase::DisplayEventThread::threadLoop()
bool DisplayHardwareBase::DisplayEventThread::threadLoop() {
{
    int err = 0;
    char buf;
    int fd;


    fd = open(kSleepFileName, O_RDONLY, 0);
    if (waitForFbSleep() == NO_ERROR) {
    do {
      err = read(fd, &buf, 1);
    } while (err < 0 && errno == EINTR);
    close(fd);
    ALOGW_IF(err<0, "ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno));
    if (err >= 0) {
        sp<SurfaceFlinger> flinger = mFlinger.promote();
        sp<SurfaceFlinger> flinger = mFlinger.promote();
        ALOGD("About to give-up screen, flinger = %p", flinger.get());
        ALOGD("About to give-up screen, flinger = %p", flinger.get());
        if (flinger != 0) {
        if (flinger != 0) {
@@ -85,37 +66,49 @@ bool DisplayHardwareBase::DisplayEventThread::threadLoop()
            flinger->screenReleased(0);
            flinger->screenReleased(0);
            mBarrier.wait();
            mBarrier.wait();
        }
        }
    }
        if (waitForFbWake() == NO_ERROR) {
    fd = open(kWakeFileName, O_RDONLY, 0);
    do {
      err = read(fd, &buf, 1);
    } while (err < 0 && errno == EINTR);
    close(fd);
    ALOGW_IF(err<0, "ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno));
    if (err >= 0) {
            sp<SurfaceFlinger> flinger = mFlinger.promote();
            sp<SurfaceFlinger> flinger = mFlinger.promote();
            ALOGD("Screen about to return, flinger = %p", flinger.get());
            ALOGD("Screen about to return, flinger = %p", flinger.get());
        if (flinger != 0)
            if (flinger != 0) {
                flinger->screenAcquired(0);
                flinger->screenAcquired(0);
            }
            }
            return true;
            return true;
        }
        }
    }


status_t DisplayHardwareBase::DisplayEventThread::releaseScreen() const
    // error, exit the thread
{
    return false;
    mBarrier.open();
    return NO_ERROR;
}
}


status_t DisplayHardwareBase::DisplayEventThread::readyToRun()
status_t DisplayHardwareBase::DisplayEventThread::waitForFbSleep() {
{
    int err = 0;
    return NO_ERROR;
    char buf;
    int fd = open(kSleepFileName, O_RDONLY, 0);
    // if the file doesn't exist, the error will be caught in read() below
    do {
        err = read(fd, &buf, 1);
    } while (err < 0 && errno == EINTR);
    close(fd);
    ALOGE_IF(err<0, "*** ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno));
    return err < 0 ? -errno : int(NO_ERROR);
}
}


status_t DisplayHardwareBase::DisplayEventThread::initCheck() const
status_t DisplayHardwareBase::DisplayEventThread::waitForFbWake() {
{
    int err = 0;
    return ((access(kSleepFileName, R_OK) == 0 &&
    char buf;
            access(kWakeFileName, R_OK) == 0)) ? NO_ERROR : NO_INIT;
    int fd = open(kWakeFileName, O_RDONLY, 0);
    // if the file doesn't exist, the error will be caught in read() below
    do {
        err = read(fd, &buf, 1);
    } while (err < 0 && errno == EINTR);
    close(fd);
    ALOGE_IF(err<0, "*** ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno));
    return err < 0 ? -errno : int(NO_ERROR);
}

status_t DisplayHardwareBase::DisplayEventThread::releaseScreen() const {
    mBarrier.open();
    return NO_ERROR;
}
}


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -127,35 +120,27 @@ DisplayHardwareBase::DisplayHardwareBase(const sp<SurfaceFlinger>& flinger,
    mDisplayEventThread = new DisplayEventThread(flinger);
    mDisplayEventThread = new DisplayEventThread(flinger);
}
}


DisplayHardwareBase::~DisplayHardwareBase()
DisplayHardwareBase::~DisplayHardwareBase() {
{
    // request exit
    // request exit
    mDisplayEventThread->requestExitAndWait();
    mDisplayEventThread->requestExitAndWait();
}
}


bool DisplayHardwareBase::canDraw() const
bool DisplayHardwareBase::canDraw() const {
{
    return mScreenAcquired;
    return mScreenAcquired;
}
}


void DisplayHardwareBase::releaseScreen() const
void DisplayHardwareBase::releaseScreen() const {
{
    status_t err = mDisplayEventThread->releaseScreen();
    status_t err = mDisplayEventThread->releaseScreen();
    if (err >= 0) {
    if (err >= 0) {
        mScreenAcquired = false;
        mScreenAcquired = false;
    }
    }
}
}


void DisplayHardwareBase::acquireScreen() const
void DisplayHardwareBase::acquireScreen() const {
{
    status_t err = mDisplayEventThread->acquireScreen();
    if (err >= 0) {
    mScreenAcquired = true;
    mScreenAcquired = true;
}
}
}


bool DisplayHardwareBase::isScreenAcquired() const
bool DisplayHardwareBase::isScreenAcquired() const {
{
    return mScreenAcquired;
    return mScreenAcquired;
}
}


+14 −28
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2007 The Android Open Source Project
 * Copyright (C) 2012 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
#include <stdint.h>
#include <stdint.h>
#include <utils/RefBase.h>
#include <utils/RefBase.h>
#include <utils/threads.h>
#include <utils/threads.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include "Barrier.h"
#include "Barrier.h"


namespace android {
namespace android {
@@ -46,33 +44,21 @@ public:




private:
private:
    class DisplayEventThreadBase : public Thread {
    class DisplayEventThread : public Thread {
    protected:
        wp<SurfaceFlinger> mFlinger;
        wp<SurfaceFlinger> mFlinger;
    public:
        DisplayEventThreadBase(const sp<SurfaceFlinger>& flinger);
        virtual ~DisplayEventThreadBase();
        virtual void onFirstRef() {
            run("DisplayEventThread", PRIORITY_URGENT_DISPLAY);
        }
        virtual status_t acquireScreen() const { return NO_ERROR; };
        virtual status_t releaseScreen() const { return NO_ERROR; };
        virtual status_t initCheck() const = 0;
    };

    class DisplayEventThread : public DisplayEventThreadBase 
    {
        mutable Barrier mBarrier;
        mutable Barrier mBarrier;
        status_t waitForFbSleep();
        status_t waitForFbWake();
    public:
    public:
        DisplayEventThread(const sp<SurfaceFlinger>& flinger);
        DisplayEventThread(const sp<SurfaceFlinger>& flinger);
        virtual ~DisplayEventThread();
        virtual ~DisplayEventThread();
        virtual void onFirstRef();
        virtual bool threadLoop();
        virtual bool threadLoop();
        virtual status_t readyToRun();
        status_t releaseScreen() const;
        virtual status_t releaseScreen() const;
        status_t initCheck() const;
        virtual status_t initCheck() const;
    };
    };


    sp<DisplayEventThreadBase>  mDisplayEventThread;
    sp<DisplayEventThread>  mDisplayEventThread;
    mutable int             mScreenAcquired;
    mutable int             mScreenAcquired;
};
};