summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2014-08-23 00:41:14 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-08-23 00:41:14 +0000
commit5cd8ae9146e8f36bafa47cf4cc5ea73a0ae5e5dd (patch)
tree6c21af154db6a0ccbfe43de40e86f2947d515105
parenta988347120b139f6bfe5ee900df40505b1d8e15d (diff)
parent46a8750aeead916547828787316b908dd46e8a87 (diff)
downloadframeworks_base-5cd8ae9146e8f36bafa47cf4cc5ea73a0ae5e5dd.zip
frameworks_base-5cd8ae9146e8f36bafa47cf4cc5ea73a0ae5e5dd.tar.gz
frameworks_base-5cd8ae9146e8f36bafa47cf4cc5ea73a0ae5e5dd.tar.bz2
am 25ea66dd: am 4056d9cb: Merge "Fix matrix multiply in accessiblity display adjustments." into lmp-dev
* commit '25ea66dd6d5f18b9feef35edf692f5c41ec06da0': Fix matrix multiply in accessiblity display adjustments.
-rw-r--r--services/accessibility/java/com/android/server/accessibility/DisplayAdjustmentUtils.java69
1 files changed, 29 insertions, 40 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/DisplayAdjustmentUtils.java b/services/accessibility/java/com/android/server/accessibility/DisplayAdjustmentUtils.java
index 394c196..38827d0 100644
--- a/services/accessibility/java/com/android/server/accessibility/DisplayAdjustmentUtils.java
+++ b/services/accessibility/java/com/android/server/accessibility/DisplayAdjustmentUtils.java
@@ -60,15 +60,17 @@ class DisplayAdjustmentUtils {
public static boolean hasAdjustments(Context context, int userId) {
final ContentResolver cr = context.getContentResolver();
- boolean hasColorTransform = Settings.Secure.getIntForUser(
- cr, Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, userId) == 1;
+ if (Settings.Secure.getIntForUser(cr,
+ Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, userId) != 0) {
+ return true;
+ }
- if (!hasColorTransform) {
- hasColorTransform |= Settings.Secure.getIntForUser(
- cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) == 1;
+ if (Settings.Secure.getIntForUser(cr,
+ Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) != 0) {
+ return true;
}
- return hasColorTransform;
+ return false;
}
/**
@@ -76,52 +78,39 @@ class DisplayAdjustmentUtils {
*/
public static void applyAdjustments(Context context, int userId) {
final ContentResolver cr = context.getContentResolver();
- float[] colorMatrix = new float[16];
- float[] outputMatrix = new float[16];
- boolean hasColorTransform = false;
-
- Matrix.setIdentityM(colorMatrix, 0);
-
- final boolean inversionEnabled = Settings.Secure.getIntForUser(
- cr, Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, userId) == 1;
- if (inversionEnabled) {
- final float[] inversionMatrix = INVERSION_MATRIX_VALUE_ONLY;
- Matrix.multiplyMM(outputMatrix, 0, colorMatrix, 0, inversionMatrix, 0);
+ float[] colorMatrix = null;
- colorMatrix = outputMatrix;
- outputMatrix = colorMatrix;
-
- hasColorTransform = true;
+ if (Settings.Secure.getIntForUser(cr,
+ Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, userId) != 0) {
+ colorMatrix = multiply(colorMatrix, INVERSION_MATRIX_VALUE_ONLY);
}
- final boolean daltonizerEnabled = Settings.Secure.getIntForUser(
- cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) != 0;
- if (daltonizerEnabled) {
+ if (Settings.Secure.getIntForUser(cr,
+ Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) != 0) {
final int daltonizerMode = Settings.Secure.getIntForUser(cr,
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, DEFAULT_DISPLAY_DALTONIZER,
userId);
// Monochromacy isn't supported by the native Daltonizer.
if (daltonizerMode == AccessibilityManager.DALTONIZER_SIMULATE_MONOCHROMACY) {
- Matrix.multiplyMM(outputMatrix, 0, colorMatrix, 0, GRAYSCALE_MATRIX, 0);
-
- final float[] temp = colorMatrix;
- colorMatrix = outputMatrix;
- outputMatrix = temp;
-
- hasColorTransform = true;
- nativeSetDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED);
+ colorMatrix = multiply(colorMatrix, GRAYSCALE_MATRIX);
+ setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED);
} else {
- nativeSetDaltonizerMode(daltonizerMode);
+ setDaltonizerMode(daltonizerMode);
}
} else {
- nativeSetDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED);
+ setDaltonizerMode(AccessibilityManager.DALTONIZER_DISABLED);
}
- if (hasColorTransform) {
- nativeSetColorTransform(colorMatrix);
- } else {
- nativeSetColorTransform(null);
+ setColorTransform(colorMatrix);
+ }
+
+ private static float[] multiply(float[] matrix, float[] other) {
+ if (matrix == null) {
+ return other;
}
+ float[] result = new float[16];
+ Matrix.multiplyMM(result, 0, matrix, 0, other, 0);
+ return result;
}
/**
@@ -130,7 +119,7 @@ class DisplayAdjustmentUtils {
*
* @param mode new Daltonization mode
*/
- private static void nativeSetDaltonizerMode(int mode) {
+ private static void setDaltonizerMode(int mode) {
try {
final IBinder flinger = ServiceManager.getService("SurfaceFlinger");
if (flinger != null) {
@@ -152,7 +141,7 @@ class DisplayAdjustmentUtils {
* @param m the float array that holds the transformation matrix, or null to
* disable transformation
*/
- private static void nativeSetColorTransform(float[] m) {
+ private static void setColorTransform(float[] m) {
try {
final IBinder flinger = ServiceManager.getService("SurfaceFlinger");
if (flinger != null) {