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

Commit 0a6c3aea authored by Makoto Onuki's avatar Makoto Onuki Committed by android-build-team Robot
Browse files

DO NOT MERGE: 15 FPS on battery saver.

Test: DO NOT MERGE
Change-Id: I59a0819a643904b6fac41c85c36f080882b6214e
(cherry picked from commit d269bc5333d60c3f3df4450433221e36def274ae)
parent 7ee84e6d
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.Context;
import android.content.IContentProvider;
import android.content.IIntentReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
@@ -75,6 +76,7 @@ import android.os.MessageQueue;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -5772,6 +5774,18 @@ public final class ActivityThread {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        IntentFilter filter = new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);

        if (app != null) {
            app.registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            ThreadedRenderer.setFPSDivisor(context, 1);

                        }
                    }, filter);
        }
    }

    /*package*/ final void finishInstrumentation(int resultCode, Bundle results) {
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.IIntentReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
+14 −0
Original line number Diff line number Diff line
@@ -163,6 +163,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,
@@ -597,6 +598,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) {
@@ -639,6 +645,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;
+26 −0
Original line number Diff line number Diff line
@@ -27,10 +27,12 @@ import android.graphics.Rect;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.Trace;
import android.provider.Settings;
import android.util.Log;
import android.view.Surface.OutOfResourcesException;
import android.view.View.AttachInfo;
@@ -944,6 +946,8 @@ public final class ThreadedRenderer {
            if (mInitialized) return;
            mInitialized = true;
            mAppContext = context.getApplicationContext();
            // TODO: Init FPS limit here
            setFPSDivisor(context, SystemProperties.getInt("debug.fps_devisor", 1));
            initSched(renderProxy);
            initGraphicsStats();
        }
@@ -996,6 +1000,25 @@ public final class ThreadedRenderer {
        observer.mNative = null;
    }

    private static int getFPSDivisor(Context context, int inValue) {
        PowerManager pm = context.getSystemService(PowerManager.class);
        if (pm != null && pm.isPowerSaveMode()) {
            inValue = Math.max(1, Settings.Global.getInt(context.getContentResolver(), "battery_saver_fps_divisor", 1));
        }
        return inValue;
    }

    /** For temporary experimentation b/66945974 */
    public static void setFPSDivisor(Context context, int divisor) {
        if (divisor == 0) divisor = 1;
        divisor = getFPSDivisor(context, divisor);

        Log.w("XXX", "Updating fpsDivisor: " + divisor);

        Choreographer.getInstance().setFPSDivisor(divisor);
        nHackySetRTAnimationsEnabled(divisor == 1);
    }

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

@@ -1063,4 +1086,7 @@ public final class ThreadedRenderer {
            int srcLeft, int srcTop, int srcRight, int srcBottom, Bitmap bitmap);

    private static native Bitmap nCreateHardwareBitmap(long renderNode, int width, int height);

    // For temporary experimentation b/66945974
    private static native void nHackySetRTAnimationsEnabled(boolean enabled);
}
+9 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
#include <FrameInfo.h>
#include <FrameMetricsObserver.h>
#include <IContextFactory.h>
#include <Properties.h>
#include <PropertyValuesAnimatorSet.h>
#include <RenderNode.h>
#include <renderthread/CanvasContext.h>
@@ -930,6 +931,12 @@ static void android_view_ThreadedRenderer_disableVsync(JNIEnv*, jclass) {
    RenderProxy::disableVsync();
}


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

// ----------------------------------------------------------------------------
// FrameMetricsObserver
// ----------------------------------------------------------------------------
@@ -1029,6 +1036,8 @@ static const JNINativeMethod gMethods[] = {
    { "nCreateHardwareBitmap", "(JII)Landroid/graphics/Bitmap;",
            (void*)android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode },
    { "disableVsync", "()V", (void*)android_view_ThreadedRenderer_disableVsync },
    { "nHackySetRTAnimationsEnabled", "(Z)V",
            (void*)android_view_ThreadedRenderer_hackySetRTAnimationsEnabled },
};

int register_android_view_ThreadedRenderer(JNIEnv* env) {
Loading