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

Commit 461afeb9 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Add support for sending VSYNC events to the framework

use gui/DisplayEvent to receive the events. Events are
dispatched through a unix pipe, so the API is compatible
with utils/Looper. see gui/DisplayEvent.h for more info.

Bug: 1475048
Change-Id: If4126023fc9c067e56087ec7d16a8fd542ce1794
parent 3ad3807a
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -33,8 +33,9 @@
namespace android {
// ----------------------------------------------------------------------------

class IMemoryHeap;
class ComposerState;
class IDisplayEventConnection;
class IMemoryHeap;

class ISurfaceComposer : public IInterface
{
@@ -124,13 +125,19 @@ public:
            uint32_t reqWidth, uint32_t reqHeight,
            uint32_t minLayerZ, uint32_t maxLayerZ) = 0;

    /* triggers screen off animation */
    virtual status_t turnElectronBeamOff(int32_t mode) = 0;

    /* triggers screen on animation */
    virtual status_t turnElectronBeamOn(int32_t mode) = 0;

    /* verify that an ISurfaceTexture was created by SurfaceFlinger.
     */
    virtual bool authenticateSurfaceTexture(
            const sp<ISurfaceTexture>& surface) const = 0;

    /* return an IDisplayEventConnection */
    virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;
};

// ----------------------------------------------------------------------------
@@ -151,6 +158,7 @@ public:
        TURN_ELECTRON_BEAM_OFF,
        TURN_ELECTRON_BEAM_ON,
        AUTHENTICATE_SURFACE,
        CREATE_DISPLAY_EVENT_CONNECTION,
    };

    virtual status_t    onTransact( uint32_t code,
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
	BitTube.cpp \
	DisplayEventReceiver.cpp \
	IDisplayEventConnection.cpp \
	ISensorEventConnection.cpp \
	ISensorServer.cpp \
	ISurfaceTexture.cpp \
+32 −0
Original line number Diff line number Diff line
@@ -29,6 +29,9 @@

#include <surfaceflinger/ISurfaceComposer.h>

#include <gui/BitTube.h>
#include <gui/IDisplayEventConnection.h>

#include <ui/DisplayInfo.h>

#include <gui/ISurfaceTexture.h>
@@ -44,6 +47,8 @@

namespace android {

class IDisplayEventConnection;

class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
{
public:
@@ -174,6 +179,27 @@ public:
        }
        return result != 0;
    }

    virtual sp<IDisplayEventConnection> createDisplayEventConnection()
    {
        Parcel data, reply;
        sp<IDisplayEventConnection> result;
        int err = data.writeInterfaceToken(
                ISurfaceComposer::getInterfaceDescriptor());
        if (err != NO_ERROR) {
            return result;
        }
        err = remote()->transact(
                BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
                data, &reply);
        if (err != NO_ERROR) {
            LOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
                    "transaction: %s (%d)", strerror(-err), -err);
            return result;
        }
        result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
        return result;
    }
};

IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
@@ -254,6 +280,12 @@ status_t BnSurfaceComposer::onTransact(
            int32_t result = authenticateSurfaceTexture(surfaceTexture) ? 1 : 0;
            reply->writeInt32(result);
        } break;
        case CREATE_DISPLAY_EVENT_CONNECTION: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            sp<IDisplayEventConnection> connection(createDisplayEventConnection());
            reply->writeStrongBinder(connection->asBinder());
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+15 −12
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
    EventThread.cpp                         \
    Layer.cpp                               \
    LayerBase.cpp                           \
    LayerDim.cpp                            \
@@ -10,6 +11,8 @@ LOCAL_SRC_FILES:= \
    DisplayHardware/DisplayHardware.cpp     \
    DisplayHardware/DisplayHardwareBase.cpp \
    DisplayHardware/HWComposer.cpp          \
    DisplayHardware/VSyncBarrier.cpp        \
    DisplayEventConnection.cpp              \
    GLExtensions.cpp                        \
    MessageQueue.cpp                        \
    SurfaceFlinger.cpp                      \
+34 −0
Original line number Diff line number Diff line
@@ -140,6 +140,7 @@ void DisplayHardware::init(uint32_t dpy)
    mDpiX = mNativeWindow->xdpi;
    mDpiY = mNativeWindow->ydpi;
    mRefreshRate = fbDev->fps;
    mNextFakeVSync = 0;


/* FIXME: this is a temporary HACK until we are able to report the refresh rate
@@ -152,6 +153,8 @@ void DisplayHardware::init(uint32_t dpy)
#warning "refresh rate set via makefile to REFRESH_RATE"
#endif

    mRefreshPeriod = nsecs_t(1e9 / mRefreshRate);

    EGLint w, h, dummy;
    EGLint numConfigs=0;
    EGLSurface surface;
@@ -346,6 +349,37 @@ uint32_t DisplayHardware::getPageFlipCount() const {
    return mPageFlipCount;
}

// this needs to be thread safe
nsecs_t DisplayHardware::waitForVSync() const {
    nsecs_t timestamp;
    if (mVSync.wait(&timestamp) < 0) {
        // vsync not supported!
        usleep( getDelayToNextVSyncUs(&timestamp) );
    }
    return timestamp;
}

int32_t DisplayHardware::getDelayToNextVSyncUs(nsecs_t* timestamp) const {
    Mutex::Autolock _l(mFakeVSyncMutex);
    const nsecs_t period = mRefreshPeriod;
    const nsecs_t now = systemTime(CLOCK_MONOTONIC);
    nsecs_t next_vsync = mNextFakeVSync;
    nsecs_t sleep = next_vsync - now;
    if (sleep < 0) {
        // we missed, find where the next vsync should be
        sleep = (period - ((now - next_vsync) % period));
        next_vsync = now + sleep;
    }
    mNextFakeVSync = next_vsync + period;
    timestamp[0] = next_vsync;

    // round to next microsecond
    int32_t sleep_us = (sleep + 999LL) / 1000LL;

    // guaranteed to be > 0
    return sleep_us;
}

status_t DisplayHardware::compositionComplete() const {
    return mNativeWindow->compositionComplete();
}
Loading