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

Commit 9f51644a authored by John Reck's avatar John Reck Committed by Makoto Onuki
Browse files

Extreme battery saver: Allow lowering framerate for experiments.

Bug: 68769804
Test: manual
Change-Id: Ic0c95f32c7ba6d86a997997e480e6d8a5f228f25
parent a044c1d2
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ public final class Choreographer {
    private long mLastFrameTimeNanos;
    private long mFrameIntervalNanos;
    private boolean mDebugPrintNextFrameTimeDelta;
    private int mFPSDivisor = 1;

    /**
     * Contains information about the current frame for jank-tracking,
@@ -601,6 +602,11 @@ public final class Choreographer {
        }
    }

    void setFPSDivisor(int divisor) {
        if (divisor <= 0) divisor = 1;
        mFPSDivisor = divisor;
    }

    void doFrame(long frameTimeNanos, int frame) {
        final long startNanos;
        synchronized (mLock) {
@@ -643,6 +649,14 @@ public final class Choreographer {
                return;
            }

            if (mFPSDivisor > 1) {
                long timeSinceVsync = frameTimeNanos - mLastFrameTimeNanos;
                if (timeSinceVsync < (mFrameIntervalNanos * mFPSDivisor) && timeSinceVsync > 0) {
                    scheduleVsyncLocked();
                    return;
                }
            }

            mFrameInfo.setVsync(intendedFrameTimeNanos, frameTimeNanos);
            mFrameScheduled = false;
            mLastFrameTimeNanos = frameTimeNanos;
+23 −0
Original line number Diff line number Diff line
@@ -190,6 +190,17 @@ public final class ThreadedRenderer {
    public static final String DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY =
            "debug.hwui.show_non_rect_clip";

    /**
     * Sets the FPS devisor to lower the FPS.
     *
     * Sets a positive integer as a divisor. 1 (the default value) menas the full FPS, and 2
     * means half the full FPS.
     *
     *
     * @hide
     */
    public static final String DEBUG_FPS_DIVISOR = "debug.hwui.fps_divisor";

    static {
        // Try to check OpenGL support early if possible.
        isAvailable();
@@ -955,6 +966,9 @@ public final class ThreadedRenderer {
            if (mInitialized) return;
            mInitialized = true;
            mAppContext = context.getApplicationContext();

            // b/68769804: For low FPS experiments.
            setFPSDivisor(SystemProperties.getInt(DEBUG_FPS_DIVISOR, 1));
            initSched(renderProxy);
            initGraphicsStats();
        }
@@ -1007,6 +1021,13 @@ public final class ThreadedRenderer {
        observer.mNative = null;
    }

    /** b/68769804: For low FPS experiments. */
    public static void setFPSDivisor(int divisor) {
        if (divisor <= 0) divisor = 1;
        Choreographer.getInstance().setFPSDivisor(divisor);
        nHackySetRTAnimationsEnabled(divisor == 1);
    }

    /** Not actually public - internal use only. This doc to make lint happy */
    public static native void disableVsync();

@@ -1075,4 +1096,6 @@ public final class ThreadedRenderer {

    private static native Bitmap nCreateHardwareBitmap(long renderNode, int width, int height);
    private static native void nSetHighContrastText(boolean enabled);
    // For temporary experimentation b/66945974
    private static native void nHackySetRTAnimationsEnabled(boolean enabled);
}
+7 −0
Original line number Diff line number Diff line
@@ -937,6 +937,11 @@ static void android_view_ThreadedRenderer_setHighContrastText(JNIEnv*, jclass, j
    Properties::enableHighContrastText = enable;
}

static void android_view_ThreadedRenderer_hackySetRTAnimationsEnabled(JNIEnv*, jclass,
        jboolean enable) {
    Properties::enableRTAnimations = enable;
}

// ----------------------------------------------------------------------------
// FrameMetricsObserver
// ----------------------------------------------------------------------------
@@ -1041,6 +1046,8 @@ static const JNINativeMethod gMethods[] = {
            (void*)android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode },
    { "disableVsync", "()V", (void*)android_view_ThreadedRenderer_disableVsync },
    { "nSetHighContrastText", "(Z)V", (void*)android_view_ThreadedRenderer_setHighContrastText },
    { "nHackySetRTAnimationsEnabled", "(Z)V",
            (void*)android_view_ThreadedRenderer_hackySetRTAnimationsEnabled },
};

static JavaVM* mJvm = nullptr;
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ bool Properties::forceDrawFrame = false;
bool Properties::filterOutTestOverhead = false;
bool Properties::disableVsync = false;
bool Properties::skpCaptureEnabled = false;
bool Properties::enableRTAnimations = true;

static int property_get_int(const char* key, int defaultValue) {
    char buf[PROPERTY_VALUE_MAX] = {
+3 −0
Original line number Diff line number Diff line
@@ -255,6 +255,9 @@ public:

    static bool skpCaptureEnabled;

    // For experimentation b/68769804
    ANDROID_API static bool enableRTAnimations;

    // Used for testing only to change the render pipeline.
    static void overrideRenderPipelineType(RenderPipelineType);

Loading