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

Commit 5de96e98 authored by nebkat's avatar nebkat Committed by Steve Kondik
Browse files

Electron Beam Animation (1/2 Frameworks)

Change-Id: Ia6e67983008eca505cead7cd4cb196627f5e2f77
parent 47a22e40
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1528,6 +1528,18 @@ public final class Settings {
         */
        public static final String LIGHT_FILTER_INTERVAL = "light_filter_interval";

        /**
         * Whether to enable the electron beam animation when turning screen on
         *
         * @hide */
        public static final String ELECTRON_BEAM_ANIMATION_ON = "electron_beam_animation_on";

        /**
         * Whether to enable the electron beam animation when turning screen off
         *
         * @hide */
        public static final String ELECTRON_BEAM_ANIMATION_OFF = "electron_beam_animation_off";

        /**
         * Control whether the process CPU usage meter should be shown.
         */
+7 −0
Original line number Diff line number Diff line
@@ -802,4 +802,11 @@
    <!-- Whether to set a system prop (sys.orientation.landscape)
         when rotating for devices that have rotating buttons -->
    <bool name="config_setLandscapeProp">false</bool>

    <!-- Values greater or equal to 0 will enable electronbeam screen-on
         animation with the specified delay (in milliseconds), -1 will disable the animation -->
    <integer name="config_screenOnAnimation">-1</integer>

    <!-- True will enable the electron beam screen-off animation. -->
    <bool name="config_screenOffAnimation">true</bool>
</resources>
+88 −14
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ import android.util.Log;
import android.util.Slog;
import android.view.WindowManagerPolicy;
import static android.provider.Settings.System.DIM_SCREEN;
import static android.provider.Settings.System.ELECTRON_BEAM_ANIMATION_ON;
import static android.provider.Settings.System.ELECTRON_BEAM_ANIMATION_OFF;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
@@ -151,6 +153,9 @@ public class PowerManagerService extends IPowerManager.Stub

    boolean mAnimateScreenLights = true;

    boolean mElectronBeamAnimationOn = false;
    boolean mElectronBeamAnimationOff = false;

    static final int ANIM_STEPS = 60/4;
    // Slower animation for autobrightness changes
    static final int AUTOBRIGHTNESS_ANIM_STEPS = 60;
@@ -313,7 +318,8 @@ public class PowerManagerService extends IPowerManager.Stub
    
    private native void nativeInit();
    private native void nativeSetPowerState(boolean screenOn, boolean screenBright);
    private native void nativeStartSurfaceFlingerAnimation(int mode);
    private native void nativeStartSurfaceFlingerOffAnimation(int mode);
    private native void nativeStartSurfaceFlingerOnAnimation(int mode);

    /*
    static PrintStream mLog;
@@ -512,15 +518,20 @@ public class PowerManagerService extends IPowerManager.Stub
                // recalculate everything
                setScreenOffTimeoutsLocked();

                final float windowScale = getFloat(WINDOW_ANIMATION_SCALE, 1.0f);
                final float transitionScale = getFloat(TRANSITION_ANIMATION_SCALE, 1.0f);
                //read user settings and device config to control animations availability
                mElectronBeamAnimationOn = (Settings.System.getInt(mContext.getContentResolver(),
                        ELECTRON_BEAM_ANIMATION_ON, 0) != 0) &&
                        mContext.getResources().getInteger(com.android.internal.R.integer.config_screenOnAnimation) >= 0;
                mElectronBeamAnimationOff = (Settings.System.getInt(mContext.getContentResolver(),
                        ELECTRON_BEAM_ANIMATION_OFF, 1) != 0) &&
                        mContext.getResources().getBoolean(com.android.internal.R.bool.config_screenOffAnimation);

                mAnimationSetting = 0;
                if (windowScale > 0.5f) {
                if (mElectronBeamAnimationOff) {
                    mAnimationSetting |= ANIM_SETTING_OFF;
                }
                if (transitionScale > 0.5f) {
                    // Uncomment this if you want the screen-on animation.
                    // mAnimationSetting |= ANIM_SETTING_ON;
                if (mElectronBeamAnimationOn) {
                    mAnimationSetting |= ANIM_SETTING_ON;
                }
            }
        }
@@ -672,10 +683,13 @@ public class PowerManagerService extends IPowerManager.Stub
                        + Settings.System.NAME + "=?) or ("
                        + Settings.System.NAME + "=?) or ("
                        + Settings.System.NAME + "=?) or ("
                        + Settings.System.NAME + "=?) or ("
                        + Settings.System.NAME + "=?) or ("
                        + Settings.System.NAME + "=?)",
                new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN,
                        SCREEN_BRIGHTNESS_MODE, WINDOW_ANIMATION_SCALE, TRANSITION_ANIMATION_SCALE,
                        Settings.System.LIGHTS_CHANGED},
                        Settings.System.LIGHTS_CHANGED, ELECTRON_BEAM_ANIMATION_ON,
                        ELECTRON_BEAM_ANIMATION_OFF},
                null);
        mSettings = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, mHandler);
        SettingsObserver settingsObserver = new SettingsObserver();
@@ -2187,6 +2201,8 @@ public class PowerManagerService extends IPowerManager.Stub
        float curValue;
        float delta;
        boolean animating;
        Handler mElectronBeamOnHandler;
        HandlerThread mElectronBeamOnHandlerThread;

        BrightnessState(int m) {
            mask = m;
@@ -2283,11 +2299,24 @@ public class PowerManagerService extends IPowerManager.Stub
            }
        }

        void jumpToTarget() {
            if (mSpew) Slog.d(TAG, "jumpToTarget targetValue=" + targetValue + ": " + mask);
                setLightBrightness(mask, targetValue);
                final int tv = targetValue;
                curValue = tv;
                targetValue = -1;
        }

        public void run() {
            synchronized (mLocks) {
                // we're turning off
                final boolean turningOn = animating && (int)curValue == Power.BRIGHTNESS_OFF;
                final boolean turningOff = animating && targetValue == Power.BRIGHTNESS_OFF;
                if (mAnimateScreenLights || !turningOff) {
                // Check for the electron beam for fully on/off transitions.
                // Otherwise, allow it to fade the brightness as normal.
                final boolean electrifying =
                        ((mElectronBeamAnimationOff && turningOff) ||
                         (mElectronBeamAnimationOn && turningOn));
                if (!electrifying && (mAnimateScreenLights || !turningOff)) {
                    long now = SystemClock.uptimeMillis();
                    boolean more = mScreenBrightness.stepLocked();
                    if (more) {
@@ -2296,14 +2325,59 @@ public class PowerManagerService extends IPowerManager.Stub
                } else {
                    // It's pretty scary to hold mLocks for this long, and we should
                    // redesign this, but it works for now.
                    nativeStartSurfaceFlingerAnimation(
                    if (turningOff) {
                        if (electrifying) {
                            nativeStartSurfaceFlingerOffAnimation(
                                    mScreenOffReason == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR
                                    ? 0 : mAnimationSetting);
                        }
                        mScreenBrightness.jumpToTargetLocked();
                    } else if (turningOn) {
                        if (electrifying) {
                            int delay=mContext.getResources().getInteger(com.android.internal.R.integer.config_screenOnAnimation);
                            if(delay>0) {
                                startElectronBeamDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        startElectronBeamOnAnimation();
                                        synchronized(mElectronBeamOnHandler) {
                                            mElectronBeamOnHandler.notifyAll();
                                        }
                                    }
                                },delay);
                            } else {
                                startElectronBeamOnAnimation();
                            }
                        } else {
                            mScreenBrightness.jumpToTargetLocked();
                        }
                    }
                }
            }
        }

        private void startElectronBeamOnAnimation() {
            jumpToTarget();
            nativeStartSurfaceFlingerOnAnimation(mAnimationSetting);
            mScreenBrightness.animating = false;
        }

        private void startElectronBeamDelayed(Runnable animation, int delay) {
            mElectronBeamOnHandlerThread = new HandlerThread("PowerManagerService.mScreenBrightness.mElectronBeamOnHandlerThread");
            mElectronBeamOnHandlerThread.start();
            mElectronBeamOnHandler = new Handler(mElectronBeamOnHandlerThread.getLooper());
            mElectronBeamOnHandler.postDelayed(animation,delay);
            try {
                synchronized(mElectronBeamOnHandler) {
                    mElectronBeamOnHandler.wait();
                }
            } catch (InterruptedException e) {
                Slog.d(TAG,"mElectronBeamOnHandler.wait() interrupted");
                Slog.d(TAG,Log.getStackTraceString(e));
                e.printStackTrace();
            }
        }
    }

    private int getPreferredBrightness() {
        try {
+11 −3
Original line number Diff line number Diff line
@@ -122,12 +122,18 @@ static void android_server_PowerManagerService_nativeSetPowerState(JNIEnv* env,
    gScreenBright = screenBright;
}

static void android_server_PowerManagerService_nativeStartSurfaceFlingerAnimation(JNIEnv* env,
static void android_server_PowerManagerService_nativeStartSurfaceFlingerOffAnimation(JNIEnv* env,
        jobject obj, jint mode) {
    sp<ISurfaceComposer> s(ComposerService::getComposerService());
    s->turnElectronBeamOff(mode);
}

static void android_server_PowerManagerService_nativeStartSurfaceFlingerOnAnimation(JNIEnv* env,
        jobject obj, jint mode) {
    sp<ISurfaceComposer> s(ComposerService::getComposerService());
    s->turnElectronBeamOn(mode);
}

// ----------------------------------------------------------------------------

static JNINativeMethod gPowerManagerServiceMethods[] = {
@@ -136,8 +142,10 @@ static JNINativeMethod gPowerManagerServiceMethods[] = {
            (void*) android_server_PowerManagerService_nativeInit },
    { "nativeSetPowerState", "(ZZ)V",
            (void*) android_server_PowerManagerService_nativeSetPowerState },
    { "nativeStartSurfaceFlingerAnimation", "(I)V",
            (void*) android_server_PowerManagerService_nativeStartSurfaceFlingerAnimation },
    { "nativeStartSurfaceFlingerOffAnimation", "(I)V",
            (void*) android_server_PowerManagerService_nativeStartSurfaceFlingerOffAnimation },
    { "nativeStartSurfaceFlingerOnAnimation", "(I)V",
            (void*) android_server_PowerManagerService_nativeStartSurfaceFlingerOnAnimation },
};

#define FIND_CLASS(var, className) \
+16 −8
Original line number Diff line number Diff line
@@ -527,9 +527,6 @@ void SurfaceFlinger::handleConsoleEvents()
#ifdef QCOM_HDMI_OUT
        updateHwcExternalDisplay(mExtDispOutput);
#endif
        // this is a temporary work-around, eventually this should be called
        // by the power-manager
        SurfaceFlinger::turnElectronBeamOn(mElectronBeamAnimationMode);
    }

    if (what & eConsoleReleased) {
@@ -2167,7 +2164,7 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
    const DisplayHardware& hw(graphicPlane(0).displayHardware());
    const uint32_t hw_w = hw.getWidth();
    const uint32_t hw_h = hw.getHeight();
    const Region screenBounds(hw.bounds());
    const Region screenBounds(hw.getBounds());

    GLfloat u, v;
    GLuint tname;
@@ -2177,9 +2174,9 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
    }

    GLfloat vtx[8];
    const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
    const GLfloat texCoords[4][2] = { {0,0}, {0,v}, {u,v}, {u,0} };
    glBindTexture(GL_TEXTURE_2D, tname);
    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
@@ -2236,7 +2233,7 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
    };

    // the full animation is 12 frames
    int nbFrames = 8;
    int nbFrames = 12;
    s_curve_interpolator itr(nbFrames, 7.5f);
    s_curve_interpolator itg(nbFrames, 8.0f);
    s_curve_interpolator itb(nbFrames, 8.5f);
@@ -2254,8 +2251,13 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
        hw.flip(screenBounds);
    }

    nbFrames = 4;
    v_stretch vverts(hw_w, hw_h);

    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
    for (int i=nbFrames-1 ; i>=0 ; i--) {
@@ -2284,6 +2286,12 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
        glColorMask(0,0,1,1);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

        // draw the white highlight (we use the last vertices)
        glDisable(GL_TEXTURE_2D);
        glColorMask(1,1,1,1);
        glColor4f(vg, vg, vg, 1);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

        hw.flip(screenBounds);
    }