diff options
| author | Sam Mortimer <sam@mortimer.me.uk> | 2018-01-04 11:04:32 -0800 |
|---|---|---|
| committer | Sam Mortimer <sam@mortimer.me.uk> | 2018-01-04 15:21:19 -0800 |
| commit | 28c466a303aa172535195e67f82457ea3375e265 (patch) | |
| tree | 7599debab8303891608a9896d3122d7afa1a59d6 | |
| parent | 7eaff52f2d7493a2bfae0ce44c1d7a93cb13dfd3 (diff) | |
| download | android_hardware_lineage_lineagehw-28c466a303aa172535195e67f82457ea3375e265.tar.gz android_hardware_lineage_lineagehw-28c466a303aa172535195e67f82457ea3375e265.tar.bz2 android_hardware_lineage_lineagehw-28c466a303aa172535195e67f82457ea3375e265.zip | |
lineagehw: Deprecate use of gpu mode as a fallback for color control
*) It's not power friendly and can break playback of DRM protected
content. Further, there's no obvious connection between these
issues and the use of livedisplay for the end user. (It doesn't
work in Oreo at the moment anyway because related fw/native
surfaceflinger commits are missing so let's capitalize..)
*) Some cleanup whilst we're here.
Change-Id: I85307958ec4cdec87ffdeec02288ddca8a900211
| -rw-r--r-- | src/org/lineageos/hardware/DisplayColorCalibration.java | 84 |
1 files changed, 23 insertions, 61 deletions
diff --git a/src/org/lineageos/hardware/DisplayColorCalibration.java b/src/org/lineageos/hardware/DisplayColorCalibration.java index aa12df8..796c0d4 100644 --- a/src/org/lineageos/hardware/DisplayColorCalibration.java +++ b/src/org/lineageos/hardware/DisplayColorCalibration.java @@ -22,7 +22,6 @@ import android.os.IBinder; import android.os.Parcel; import android.os.RemoteException; import android.os.ServiceManager; -import android.os.SystemProperties; import android.util.Slog; import com.android.server.LocalServices; @@ -39,8 +38,11 @@ public class DisplayColorCalibration { private static final int LEVEL_COLOR_MATRIX_LIVEDISPLAY = LEVEL_COLOR_MATRIX_NIGHT_DISPLAY + 1; - private static final boolean sUseHWC2ColorTransform; - private static final boolean sUseGPUMode; + private static final int MODE_UNSUPPORTED = 0; + private static final int MODE_HWC2_COLOR_TRANSFORM = 1; + private static final int MODE_SYSFS_RGB = 2; + + private static final int sMode; private static final int MIN = 255; private static final int MAX = 32768; @@ -50,19 +52,22 @@ public class DisplayColorCalibration { private static DisplayTransformManager sDTMService; static { - // We use HWC2 color transform if possible. - sUseHWC2ColorTransform = ActivityThread.currentApplication(). - getApplicationContext().getResources().getBoolean( - com.android.internal.R.bool.config_setColorTransformAccelerated); - // We can also support GPU transform using RenderEngine. This is not - // preferred though, as it has a high power cost. - sUseGPUMode = !FileUtils.isFileWritable(COLOR_FILE) || - SystemProperties.getBoolean("debug.livedisplay.force_gpu", false); + // Determine mode of operation. + // Order of priority is: + // 1) HWC2 color transform + // 2) sysfs rgb file + if (ActivityThread.currentApplication().getApplicationContext().getResources().getBoolean( + com.android.internal.R.bool.config_setColorTransformAccelerated)) { + sMode = MODE_HWC2_COLOR_TRANSFORM; + } else if (FileUtils.isFileWritable(COLOR_FILE)) { + sMode = MODE_SYSFS_RGB; + } else { + sMode = MODE_UNSUPPORTED; + } } public static boolean isSupported() { - // Always true, use GPU mode if no HW support - return true; + return sMode != MODE_UNSUPPORTED; } public static int getMaxValue() { @@ -78,7 +83,7 @@ public class DisplayColorCalibration { } public static String getCurColors() { - if (!sUseGPUMode && !sUseHWC2ColorTransform) { + if (sMode == MODE_SYSFS_RGB) { return FileUtils.readOneLine(COLOR_FILE); } @@ -87,30 +92,19 @@ public class DisplayColorCalibration { } public static boolean setColors(String colors) { - if (!sUseGPUMode && !sUseHWC2ColorTransform) { + if (sMode == MODE_SYSFS_RGB) { return FileUtils.writeLine(COLOR_FILE, colors); - } - - float[] mat = toColorMatrix(colors); - - if (sUseHWC2ColorTransform) { + } else if (sMode == MODE_HWC2_COLOR_TRANSFORM) { if (sDTMService == null) { sDTMService = LocalServices.getService(DisplayTransformManager.class); if (sDTMService == null) { return false; } } - sDTMService.setColorMatrix(LEVEL_COLOR_MATRIX_LIVEDISPLAY, mat); + sDTMService.setColorMatrix(LEVEL_COLOR_MATRIX_LIVEDISPLAY, toColorMatrix(colors)); return true; } - - // set to null if identity - if (mat == null || - (mat[0] == 1.0f && mat[5] == 1.0f && - mat[10] == 1.0f && mat[15] == 1.0f)) { - return setColorTransform(null); - } - return setColorTransform(mat); + return false; } private static float[] toColorMatrix(String rgbString) { @@ -139,36 +133,4 @@ public class DisplayColorCalibration { mat[15] = 1.0f; return mat; } - - /** - * Sets the surface flinger's color transformation as a 4x4 matrix. If the - * matrix is null, color transformations are disabled. - * - * @param m the float array that holds the transformation matrix, or null to - * disable transformation - */ - private static boolean setColorTransform(float[] m) { - try { - final IBinder flinger = ServiceManager.getService("SurfaceFlinger"); - if (flinger != null) { - final Parcel data = Parcel.obtain(); - data.writeInterfaceToken("android.ui.ISurfaceComposer"); - if (m != null) { - data.writeInt(1); - for (int i = 0; i < 16; i++) { - data.writeFloat(m[i]); - } - } else { - data.writeInt(0); - } - flinger.transact(1030, data, null, 0); - data.recycle(); - } - } catch (RemoteException ex) { - Slog.e(TAG, "Failed to set color transform", ex); - return false; - } - return true; - } - } |
