This source file includes following definitions.
- JNINamespace
- getDisplayHeight
- getDisplayWidth
- getPhysicalDisplayHeight
- getPhysicalDisplayWidth
- SuppressWarnings
- getPixelFormat
- getBitsPerPixel
- SuppressWarnings
- getBitsPerComponent
- getDIPScale
- getSmallestDIPWidth
- updateNativeSharedDisplayInfo
- getDisplay
- create
- nativeUpdateSharedDeviceDisplayInfo
package org.chromium.ui.gfx;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
@JNINamespace("gfx")
public class DeviceDisplayInfo {
private final Context mAppContext;
private final WindowManager mWinManager;
private Point mTempPoint = new Point();
private DisplayMetrics mTempMetrics = new DisplayMetrics();
private DeviceDisplayInfo(Context context) {
mAppContext = context.getApplicationContext();
mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDOW_SERVICE);
}
@CalledByNative
public int getDisplayHeight() {
getDisplay().getSize(mTempPoint);
return mTempPoint.y;
}
@CalledByNative
public int getDisplayWidth() {
getDisplay().getSize(mTempPoint);
return mTempPoint.x;
}
@CalledByNative
public int getPhysicalDisplayHeight() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return 0;
}
getDisplay().getRealSize(mTempPoint);
return mTempPoint.y;
}
@CalledByNative
public int getPhysicalDisplayWidth() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return 0;
}
getDisplay().getRealSize(mTempPoint);
return mTempPoint.x;
}
@SuppressWarnings("deprecation")
private int getPixelFormat() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return getDisplay().getPixelFormat();
}
return PixelFormat.RGBA_8888;
}
@CalledByNative
public int getBitsPerPixel() {
int format = getPixelFormat();
PixelFormat info = new PixelFormat();
PixelFormat.getPixelFormatInfo(format, info);
return info.bitsPerPixel;
}
@SuppressWarnings("deprecation")
@CalledByNative
public int getBitsPerComponent() {
int format = getPixelFormat();
switch (format) {
case PixelFormat.RGBA_4444:
return 4;
case PixelFormat.RGBA_5551:
return 5;
case PixelFormat.RGBA_8888:
case PixelFormat.RGBX_8888:
case PixelFormat.RGB_888:
return 8;
case PixelFormat.RGB_332:
return 2;
case PixelFormat.RGB_565:
return 5;
case PixelFormat.A_8:
case PixelFormat.LA_88:
case PixelFormat.L_8:
return 0;
default:
return 8;
}
}
@CalledByNative
public double getDIPScale() {
getDisplay().getMetrics(mTempMetrics);
return mTempMetrics.density;
}
@CalledByNative
private int getSmallestDIPWidth() {
return mAppContext.getResources().getConfiguration().smallestScreenWidthDp;
}
public void updateNativeSharedDisplayInfo() {
nativeUpdateSharedDeviceDisplayInfo(
getDisplayHeight(), getDisplayWidth(),
getPhysicalDisplayHeight(), getPhysicalDisplayWidth(),
getBitsPerPixel(), getBitsPerComponent(),
getDIPScale(), getSmallestDIPWidth());
}
private Display getDisplay() {
return mWinManager.getDefaultDisplay();
}
@CalledByNative
public static DeviceDisplayInfo create(Context context) {
return new DeviceDisplayInfo(context);
}
private native void nativeUpdateSharedDeviceDisplayInfo(
int displayHeight, int displayWidth,
int physicalDisplayHeight, int physicalDisplayWidth,
int bitsPerPixel, int bitsPerComponent, double dipScale,
int smallestDIPWidth);
}