diff options
| author | Rashed Abdel-Tawab <rashed@linux.com> | 2017-12-06 19:43:21 -0500 |
|---|---|---|
| committer | Sam Mortimer <sam@mortimer.me.uk> | 2018-01-04 13:21:18 -0800 |
| commit | 7eaff52f2d7493a2bfae0ce44c1d7a93cb13dfd3 (patch) | |
| tree | a3ffd81913548523f5b88c5cdf33d8a7fc67bd76 | |
| parent | 52c1a2de02cbe544d20f3a2cb802e82acc2e894f (diff) | |
| download | android_hardware_lineage_lineagehw-7eaff52f2d7493a2bfae0ce44c1d7a93cb13dfd3.tar.gz android_hardware_lineage_lineagehw-7eaff52f2d7493a2bfae0ce44c1d7a93cb13dfd3.tar.bz2 android_hardware_lineage_lineagehw-7eaff52f2d7493a2bfae0ce44c1d7a93cb13dfd3.zip | |
lineagehw: Add support for HWC2 color transform
Change-Id: I6e7cec71f170f906f3c9fdb85738ec8ef1ed59bd
| -rw-r--r-- | Android.mk | 2 | ||||
| -rw-r--r-- | src/org/lineageos/hardware/DisplayColorCalibration.java | 30 |
2 files changed, 29 insertions, 3 deletions
@@ -44,7 +44,7 @@ LOCAL_SRC_FILES += $(default_classes) $(unique_specific_classes) LOCAL_MODULE_TAGS := optional LOCAL_MODULE := org.lineageos.hardware -LOCAL_JAVA_LIBRARIES := org.lineageos.platform.internal +LOCAL_JAVA_LIBRARIES := org.lineageos.platform.internal services include $(BUILD_JAVA_LIBRARY) diff --git a/src/org/lineageos/hardware/DisplayColorCalibration.java b/src/org/lineageos/hardware/DisplayColorCalibration.java index f988ead..aa12df8 100644 --- a/src/org/lineageos/hardware/DisplayColorCalibration.java +++ b/src/org/lineageos/hardware/DisplayColorCalibration.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2014 The CyanogenMod Project + * Copyright (C) 2018 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +17,7 @@ package org.lineageos.hardware; +import android.app.ActivityThread; import android.os.IBinder; import android.os.Parcel; import android.os.RemoteException; @@ -23,6 +25,10 @@ import android.os.ServiceManager; import android.os.SystemProperties; import android.util.Slog; +import com.android.server.LocalServices; +import com.android.server.display.DisplayTransformManager; +import static com.android.server.display.DisplayTransformManager.LEVEL_COLOR_MATRIX_NIGHT_DISPLAY; + import org.lineageos.internal.util.FileUtils; public class DisplayColorCalibration { @@ -31,6 +37,9 @@ public class DisplayColorCalibration { private static final String COLOR_FILE = "/sys/class/graphics/fb0/rgb"; + 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 MIN = 255; @@ -38,7 +47,13 @@ public class DisplayColorCalibration { private static final int[] sCurColors = new int[] { MAX, MAX, MAX }; + 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) || @@ -63,7 +78,7 @@ public class DisplayColorCalibration { } public static String getCurColors() { - if (!sUseGPUMode) { + if (!sUseGPUMode && !sUseHWC2ColorTransform) { return FileUtils.readOneLine(COLOR_FILE); } @@ -72,12 +87,23 @@ public class DisplayColorCalibration { } public static boolean setColors(String colors) { - if (!sUseGPUMode) { + if (!sUseGPUMode && !sUseHWC2ColorTransform) { return FileUtils.writeLine(COLOR_FILE, colors); } float[] mat = toColorMatrix(colors); + if (sUseHWC2ColorTransform) { + if (sDTMService == null) { + sDTMService = LocalServices.getService(DisplayTransformManager.class); + if (sDTMService == null) { + return false; + } + } + sDTMService.setColorMatrix(LEVEL_COLOR_MATRIX_LIVEDISPLAY, mat); + return true; + } + // set to null if identity if (mat == null || (mat[0] == 1.0f && mat[5] == 1.0f && |
