Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions core/java/android/hardware/display/ColorDisplayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,30 @@ public boolean setAppSaturationLevel(@NonNull String packageName,
return mManager.setAppSaturationLevel(packageName, saturationLevel);
}

/**
* Set the global color balance for a specific RGB channel.
*
* @param channel RGB (0,1,2) channel to change
* @param value 0-255 (inclusive), where 255 is default balance
* @return whether the change was successful
* @hide
*/
@RequiresPermission(android.Manifest.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS)
public boolean setColorBalanceChannel(int channel, int value) {
return mManager.setColorBalanceChannel(channel, value);
}

/**
* Get the current global color balance for a specific RGB channel.
*
* @param channel RGB (0,1,2) channel to get the balance of
* @return weight of the channel, 0-255 (inclusive) where 255 is the default
* @hide
*/
public int getColorBalanceChannel(int channel) {
return mManager.getColorBalanceChannel(channel);
}

/**
* Enables or disables display white balance.
*
Expand Down Expand Up @@ -682,6 +706,22 @@ boolean setAppSaturationLevel(String packageName, int saturationLevel) {
}
}

boolean setColorBalanceChannel(int channel, int value) {
try {
return mCdm.setColorBalanceChannel(channel, value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}

int getColorBalanceChannel(int channel) {
try {
return mCdm.getColorBalanceChannel(channel);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}

boolean isDisplayWhiteBalanceEnabled() {
try {
return mCdm.isDisplayWhiteBalanceEnabled();
Expand Down
3 changes: 3 additions & 0 deletions core/java/android/hardware/display/IColorDisplayManager.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ interface IColorDisplayManager {
int getColorMode();
void setColorMode(int colorMode);

int getColorBalanceChannel(int channel);
boolean setColorBalanceChannel(int channel, int value);

boolean isDisplayWhiteBalanceEnabled();
boolean setDisplayWhiteBalanceEnabled(boolean enabled);
Time getNightDisplayAutoStartTime();
Expand Down
18 changes: 18 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10386,6 +10386,24 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val
public static final String NIGHT_DISPLAY_LAST_ACTIVATED_TIME =
"night_display_last_activated_time";

/**
* Display color balance for the red channel, from 0 to 255.
* @hide
*/
public static final String DISPLAY_COLOR_BALANCE_RED = "display_color_balance_red";

/**
* Display color balance for the green channel, from 0 to 255.
* @hide
*/
public static final String DISPLAY_COLOR_BALANCE_GREEN = "display_color_balance_green";

/**
* Display color balance for the blue channel, from 0 to 255.
* @hide
*/
public static final String DISPLAY_COLOR_BALANCE_BLUE = "display_color_balance_blue";

/**
* Control whether display white balance is currently enabled.
* @hide
Expand Down
26 changes: 20 additions & 6 deletions core/res/res/raw/color_fade_frag.frag
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
precision mediump float;
uniform samplerExternalOES texUnit;
uniform float opacity;
uniform float gamma;
varying vec2 UV;

void main()
{
vec4 color = texture2D(texUnit, UV);
vec3 rgb = pow(color.rgb * opacity, vec3(gamma));
gl_FragColor = vec4(rgb, 1.0);
vec3 srgbTransfer(vec3 c) {
vec3 gamma = 1.055 * pow(c, vec3(1.0/2.4)) - 0.055;
vec3 linear = 12.92 * c;
bvec3 selectParts = lessThan(c, vec3(0.0031308));
return mix(gamma, linear, selectParts);
}

vec3 srgbTransferInv(vec3 c) {
vec3 gamma = pow((c + 0.055)/1.055, vec3(2.4));
vec3 linear = c / 12.92;
bvec3 selectParts = lessThan(c, vec3(0.04045));
return mix(gamma, linear, selectParts);
}

void main() {
vec3 inRgb = srgbTransferInv(texture2D(texUnit, UV).rgb);
vec3 fade = inRgb * opacity * opacity;
vec3 outRgb = srgbTransfer(fade);

gl_FragColor = vec4(outRgb, 1.0);
}
12 changes: 12 additions & 0 deletions graphics/java/android/graphics/ColorSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,18 @@ public enum Adaptation {
0.7328f, -0.7036f, 0.0030f,
0.4296f, 1.6975f, 0.0136f,
-0.1624f, 0.0061f, 0.9834f
}),
/**
* CAT16 chromatic adaptation transform, as defined in the
* CAM16 color appearance model.
*
* @see <a href="https://onlinelibrary.wiley.com/doi/abs/10.1002/col.22131">Comprehensive color solutions: CAM16, CAT16, and CAM16-UCS</a>
* @hide
*/
CAT16(new float[] {
0.401288f, -0.250268f, -0.002079f,
0.650173f, 1.204414f, 0.048952f,
-0.051461f, 0.045854f, 0.953127f,
});

final float[] mTransform;
Expand Down
15 changes: 4 additions & 11 deletions services/core/java/com/android/server/display/ColorFade.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class ColorFade implements ScreenStateAnimator {
private final float mProjMatrix[] = new float[16];
private final int[] mGLBuffers = new int[2];
private int mTexCoordLoc, mVertexLoc, mTexUnitLoc, mProjMatrixLoc, mTexMatrixLoc;
private int mOpacityLoc, mGammaLoc;
private int mOpacityLoc;
private int mProgram;

// Vertex and corresponding texture coordinates.
Expand Down Expand Up @@ -253,7 +253,6 @@ private boolean initGLShaders(Context context) {
mTexMatrixLoc = GLES20.glGetUniformLocation(mProgram, "tex_matrix");

mOpacityLoc = GLES20.glGetUniformLocation(mProgram, "opacity");
mGammaLoc = GLES20.glGetUniformLocation(mProgram, "gamma");
mTexUnitLoc = GLES20.glGetUniformLocation(mProgram, "texUnit");

GLES20.glUseProgram(mProgram);
Expand Down Expand Up @@ -397,12 +396,7 @@ public boolean draw(float level) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

// Draw the frame.
double one_minus_level = 1 - level;
double cos = Math.cos(Math.PI * one_minus_level);
double sign = cos < 0 ? -1 : 1;
float opacity = (float) -Math.pow(one_minus_level, 2) + 1;
float gamma = (float) ((0.5d * sign * Math.pow(cos, 2) + 0.5d) * 0.9d + 0.1d);
drawFaded(opacity, 1.f / gamma);
drawFaded(level);
if (checkGlErrors("drawFrame")) {
return false;
}
Expand All @@ -414,9 +408,9 @@ public boolean draw(float level) {
return showSurface(1.0f);
}

private void drawFaded(float opacity, float gamma) {
private void drawFaded(float opacity) {
if (DEBUG) {
Slog.d(TAG, "drawFaded: opacity=" + opacity + ", gamma=" + gamma);
Slog.d(TAG, "drawFaded: opacity=" + opacity);
}
// Use shaders
GLES20.glUseProgram(mProgram);
Expand All @@ -425,7 +419,6 @@ private void drawFaded(float opacity, float gamma) {
GLES20.glUniformMatrix4fv(mProjMatrixLoc, 1, false, mProjMatrix, 0);
GLES20.glUniformMatrix4fv(mTexMatrixLoc, 1, false, mTexMatrix, 0);
GLES20.glUniform1f(mOpacityLoc, opacity);
GLES20.glUniform1f(mGammaLoc, gamma);

// Use textures
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
Expand Down
Loading