summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authornebkat <nebkat@teamhacksung.org>2012-02-22 21:56:46 +0000
committerSteve Kondik <shade@chemlab.org>2012-06-02 17:32:08 -0700
commit5de96e98090164b5ab3845edf3efa1366be20ee4 (patch)
treef26d90cbc4fbf119feb81eb0c14488750983fd02 /services
parent47a22e40a95e599d2790a74c9c3d1edc5fae301e (diff)
downloadframeworks_base-5de96e98090164b5ab3845edf3efa1366be20ee4.zip
frameworks_base-5de96e98090164b5ab3845edf3efa1366be20ee4.tar.gz
frameworks_base-5de96e98090164b5ab3845edf3efa1366be20ee4.tar.bz2
Electron Beam Animation (1/2 Frameworks)
Change-Id: Ia6e67983008eca505cead7cd4cb196627f5e2f77
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/PowerManagerService.java102
-rw-r--r--services/jni/com_android_server_PowerManagerService.cpp14
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp24
3 files changed, 115 insertions, 25 deletions
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index aafe474..335af64 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -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,11 +2325,56 @@ 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(
- mScreenOffReason == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR
- ? 0 : mAnimationSetting);
- mScreenBrightness.jumpToTargetLocked();
+ 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();
}
}
}
diff --git a/services/jni/com_android_server_PowerManagerService.cpp b/services/jni/com_android_server_PowerManagerService.cpp
index a389c11..15d5e53 100644
--- a/services/jni/com_android_server_PowerManagerService.cpp
+++ b/services/jni/com_android_server_PowerManagerService.cpp
@@ -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) \
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 14e2fa0..ccf3c8a 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -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);
}