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

Commit 98908aa0 authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Add call to set power mode for display"

parents e830c37a c55929a2
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -78,8 +78,8 @@ public class SurfaceControl {
            IBinder displayToken);
    private static native int nativeGetActiveConfig(IBinder displayToken);
    private static native boolean nativeSetActiveConfig(IBinder displayToken, int id);
    private static native void nativeBlankDisplay(IBinder displayToken);
    private static native void nativeUnblankDisplay(IBinder displayToken);
    private static native void nativeSetDisplayPowerMode(
            IBinder displayToken, int mode);


    private final CloseGuard mCloseGuard = CloseGuard.get();
@@ -209,6 +209,25 @@ public class SurfaceControl {
     */
    public static final int BUILT_IN_DISPLAY_ID_HDMI = 1;

    /* Display power modes * /

    /**
     * Display power mode off: used while blanking the screen.
     * Use only with {@link SurfaceControl#setDisplayPowerMode()}.
     */
    public static final int POWER_MODE_OFF = 0;

    /**
     * Display power mode doze: used while putting the screen into low power mode.
     * Use only with {@link SurfaceControl#setDisplayPowerMode()}.
     */
    public static final int POWER_MODE_DOZE = 1;

    /**
     * Display power mode normal: used while unblanking the screen.
     * Use only with {@link SurfaceControl#setDisplayPowerMode()}.
     */
    public static final int POWER_MODE_NORMAL = 2;


    /**
@@ -487,18 +506,11 @@ public class SurfaceControl {
        }
    }

    public static void unblankDisplay(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        nativeUnblankDisplay(displayToken);
    }

    public static void blankDisplay(IBinder displayToken) {
    public static void setDisplayPowerMode(IBinder displayToken, int mode) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        nativeBlankDisplay(displayToken);
        nativeSetDisplayPowerMode(displayToken, mode);
    }

    public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken) {
+5 −15
Original line number Diff line number Diff line
@@ -412,20 +412,12 @@ static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenOb
    return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
}

static void nativeBlankDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == NULL) return;

    ALOGD_IF_SLOW(100, "Excessive delay in blankDisplay() while turning screen off");
    SurfaceComposerClient::blankDisplay(token);
}

static void nativeUnblankDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == NULL) return;

    ALOGD_IF_SLOW(100, "Excessive delay in unblankDisplay() while turning screen on");
    SurfaceComposerClient::unblankDisplay(token);
    ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
    SurfaceComposerClient::setDisplayPowerMode(token, mode);
}

static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
@@ -628,10 +620,6 @@ static JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeGetActiveConfig },
    {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
            (void*)nativeSetActiveConfig },
    {"nativeBlankDisplay", "(Landroid/os/IBinder;)V",
            (void*)nativeBlankDisplay },
    {"nativeUnblankDisplay", "(Landroid/os/IBinder;)V",
            (void*)nativeUnblankDisplay },
    {"nativeClearContentFrameStats", "(J)Z",
            (void*)nativeClearContentFrameStats },
    {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
@@ -640,6 +628,8 @@ static JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeClearAnimationFrameStats },
    {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
            (void*)nativeGetAnimationFrameStats },
    {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
            (void*)nativeSetDisplayPowerMode },
};

int register_android_view_SurfaceControl(JNIEnv* env)
+11 −11
Original line number Diff line number Diff line
@@ -111,12 +111,15 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        }
    }

    static boolean shouldBlank(int state) {
        return state == Display.STATE_OFF;
    static int getPowerModeForState(int state) {
        switch (state) {
            case Display.STATE_OFF:
                return SurfaceControl.POWER_MODE_OFF;
            case Display.STATE_DOZING:
                return SurfaceControl.POWER_MODE_DOZE;
            default:
                return SurfaceControl.POWER_MODE_NORMAL;
        }

    static boolean shouldUnblank(int state) {
        return state == Display.STATE_ON || state == Display.STATE_DOZING;
    }

    private final class LocalDisplayDevice extends DisplayDevice {
@@ -204,11 +207,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        @Override
        public void requestDisplayStateLocked(int state) {
            if (mState != state) {
                if (shouldBlank(state) && !shouldBlank(mState)) {
                    SurfaceControl.blankDisplay(getDisplayTokenLocked());
                } else if (shouldUnblank(state) && !shouldUnblank(mState)) {
                    SurfaceControl.unblankDisplay(getDisplayTokenLocked());
                }
                SurfaceControl.setDisplayPowerMode(getDisplayTokenLocked(),
                        getPowerModeForState(state));
                mState = state;
                updateDeviceInfoLocked();
            }