Commit 64f45fc4 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Do not use alpha channel for colorDepth/pixelDepth on Android.

Android is the only Chrome platform that takes into account the alpha
channel. This value is used for CSS Media Queries and Screen object on
the Web Platform.

Bug: 788329
Change-Id: I9f3f20db1b00fcf8fbf2588f23785b695deb6546
Reviewed-on: https://chromium-review.googlesource.com/789333
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519710}
parent c2aaefcc
...@@ -52,8 +52,42 @@ import org.chromium.base.Log; ...@@ -52,8 +52,42 @@ import org.chromium.base.Log;
return sForcedDIPScale.floatValue() > 0; return sForcedDIPScale.floatValue() > 0;
} }
/**
* This method returns the bitsPerPixel without the alpha channel, as this is the value expected
* by Chrome and the CSS media queries.
*/
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private int bitsPerComponent(int pixelFormatId) { private static int bitsPerPixel(int pixelFormatId) {
// For JB-MR1 and above, this is the only value, so we can hard-code the result.
if (pixelFormatId == PixelFormat.RGBA_8888) return 24;
PixelFormat pixelFormat = new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelFormatId, pixelFormat);
if (!PixelFormat.formatHasAlpha(pixelFormatId)) return pixelFormat.bitsPerPixel;
switch (pixelFormatId) {
case PixelFormat.RGBA_1010102:
return 30;
case PixelFormat.RGBA_4444:
return 12;
case PixelFormat.RGBA_5551:
return 15;
case PixelFormat.RGBA_8888:
assert false;
// fall through
// RGBX_8888 does not have an alpha channel even if it has 8 reserved bits at the end.
case PixelFormat.RGBX_8888:
case PixelFormat.RGB_888:
default:
return 24;
}
}
@SuppressWarnings("deprecation")
private static int bitsPerComponent(int pixelFormatId) {
switch (pixelFormatId) { switch (pixelFormatId) {
case PixelFormat.RGBA_4444: case PixelFormat.RGBA_4444:
return 4; return 4;
...@@ -93,7 +127,6 @@ import org.chromium.base.Log; ...@@ -93,7 +127,6 @@ import org.chromium.base.Log;
/* package */ void updateFromDisplay(Display display) { /* package */ void updateFromDisplay(Display display) {
Point size = new Point(); Point size = new Point();
DisplayMetrics displayMetrics = new DisplayMetrics(); DisplayMetrics displayMetrics = new DisplayMetrics();
PixelFormat pixelFormat = new PixelFormat();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
display.getRealSize(size); display.getRealSize(size);
display.getRealMetrics(displayMetrics); display.getRealMetrics(displayMetrics);
...@@ -111,8 +144,7 @@ import org.chromium.base.Log; ...@@ -111,8 +144,7 @@ import org.chromium.base.Log;
int pixelFormatId = (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) int pixelFormatId = (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
? display.getPixelFormat() ? display.getPixelFormat()
: PixelFormat.RGBA_8888; : PixelFormat.RGBA_8888;
PixelFormat.getPixelFormatInfo(pixelFormatId, pixelFormat); super.update(size, displayMetrics.density, bitsPerPixel(pixelFormatId),
super.update(size, displayMetrics.density, pixelFormat.bitsPerPixel,
bitsPerComponent(pixelFormatId), display.getRotation(), isWideColorGamut, null); bitsPerComponent(pixelFormatId), display.getRotation(), isWideColorGamut, null);
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment