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

Commit b335fad4 authored by Jamie Gennis's avatar Jamie Gennis Committed by Mathias Agopian
Browse files

hack up frame latency measurement

Change-Id: I6d9a466a23285304f0e229a5649815636ab5d6af
parent fa1a9162
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -237,6 +237,15 @@ public abstract class HardwareRenderer {

    private static native void nSetupShadersDiskCache(String cacheFile);

    /**
     * Notifies EGL that the frame is about to be rendered.
     */
    private static void beginFrame() {
        nBeginFrame();
    }

    private static native void nBeginFrame();

    /**
     * Interface used to receive callbacks whenever a view is drawn by
     * a hardware renderer instance.
@@ -808,6 +817,7 @@ public abstract class HardwareRenderer {
        }        
        
        void onPreDraw(Rect dirty) {
            
        }

        void onPostDraw() {
@@ -832,6 +842,8 @@ public abstract class HardwareRenderer {
                        dirty = null;
                    }

                    beginFrame();

                    onPreDraw(dirty);

                    HardwareCanvas canvas = mCanvas;
+10 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@

#include <EGL/egl_cache.h>

EGLAPI void EGLAPIENTRY eglBeginFrame(EGLDisplay dpy, EGLSurface surface);

namespace android {

// ----------------------------------------------------------------------------
@@ -36,6 +38,12 @@ static void android_view_HardwareRenderer_setupShadersDiskCache(JNIEnv* env, job
    env->ReleaseStringUTFChars(diskCachePath, cacheArray);
}

static void android_view_HardwareRenderer_beginFrame(JNIEnv* env, jobject clazz) {
    EGLDisplay dpy = eglGetCurrentDisplay();
    EGLSurface surf = eglGetCurrentSurface(EGL_DRAW);
    eglBeginFrame(dpy, surf);
}

// ----------------------------------------------------------------------------
// JNI Glue
// ----------------------------------------------------------------------------
@@ -45,6 +53,8 @@ const char* const kClassPathName = "android/view/HardwareRenderer";
static JNINativeMethod gMethods[] = {
    { "nSetupShadersDiskCache", "(Ljava/lang/String;)V",
            (void*) android_view_HardwareRenderer_setupShadersDiskCache },
    { "nBeginFrame", "()V",
            (void*) android_view_HardwareRenderer_beginFrame },
};

int register_android_view_HardwareRenderer(JNIEnv* env) {
+20 −0
Original line number Diff line number Diff line
@@ -477,6 +477,26 @@ EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
    return result;
}

void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
    clearError();

    egl_display_t const * const dp = validate_display(dpy);
    if (!dp) {
        return;
    }

    SurfaceRef _s(dp, surface);
    if (!_s.get()) {
        setError(EGL_BAD_SURFACE, EGL_FALSE);
        return;
    }

    int64_t timestamp = systemTime(SYSTEM_TIME_MONOTONIC);

    egl_surface_t const * const s = get_surface(surface);
    native_window_set_buffers_timestamp(s->win.get(), timestamp);
}

// ----------------------------------------------------------------------------
// Contexts
// ----------------------------------------------------------------------------
+29 −0
Original line number Diff line number Diff line
@@ -63,6 +63,22 @@ Layer::Layer(SurfaceFlinger* flinger,
{
    mCurrentCrop.makeInvalid();
    glGenTextures(1, &mTextureName);

    mFrameLatencyNeeded = false;
    mFrameLatencyOffset = 0;
    for (int i = 0; i < 128; i++) {
        mFrameLatencies[i] = 0;
    }
}

void Layer::onLayerDisplayed() {
    if (mFrameLatencyNeeded) {
        int64_t now = systemTime(SYSTEM_TIME_MONOTONIC);
        mFrameLatencies[mFrameLatencyOffset] = now -
                mSurfaceTexture->getTimestamp();
        mFrameLatencyOffset = (mFrameLatencyOffset + 1) % 128;
        mFrameLatencyNeeded = false;
    }
}

void Layer::onFirstRef()
@@ -408,6 +424,7 @@ void Layer::lockPageFlip(bool& recomputeVisibleRegions)

        // update the active buffer
        mActiveBuffer = mSurfaceTexture->getCurrentBuffer();
        mFrameLatencyNeeded = true;

        const Rect crop(mSurfaceTexture->getCurrentCrop());
        const uint32_t transform(mSurfaceTexture->getCurrentTransform());
@@ -538,6 +555,18 @@ void Layer::dump(String8& result, char* buffer, size_t SIZE) const

    result.append(buffer);

    const int64_t* l = mFrameLatencies;
    int o = mFrameLatencyOffset;
    for (int i = 0; i < 128; i += 8) {
        snprintf(buffer, SIZE,
                "      "
                "% 12lld % 12lld % 12lld % 12lld "
                "% 12lld % 12lld % 12lld % 12lld\n",
                l[(o+i+0)%128], l[(o+i+1)%128], l[(o+i+2)%128], l[(o+i+3)%128],
                l[(o+i+4)%128], l[(o+i+5)%128], l[(o+i+6)%128], l[(o+i+7)%128]);
        result.append(buffer);
    }

    if (mSurfaceTexture != 0) {
        mSurfaceTexture->dump(result, "            ", buffer, SIZE);
    }
+5 −0
Original line number Diff line number Diff line
@@ -78,6 +78,8 @@ public:
    // LayerBaseClient interface
    virtual wp<IBinder> getSurfaceTextureBinder() const;

    virtual void onLayerDisplayed();

    // only for debugging
    inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; }

@@ -110,6 +112,9 @@ private:
    uint32_t mCurrentTransform;
    uint32_t mCurrentScalingMode;
    bool mCurrentOpacity;
    bool mFrameLatencyNeeded;
    int mFrameLatencyOffset;
    int64_t mFrameLatencies[128];

    // constants
    PixelFormat mFormat;
Loading