Loading core/java/android/app/ActivityThread.java +8 −0 Original line number Diff line number Diff line Loading @@ -3753,6 +3753,14 @@ public final class ActivityThread { data.info = getPackageInfoNoCheck(data.appInfo); /** * Switch this process to density compatibility mode if needed. */ if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) == 0) { Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); } if (data.debugMode != IApplicationThread.DEBUG_OFF) { // XXX should have option to change the port. Debug.changeDebugPort(8100); Loading graphics/java/android/graphics/Bitmap.java +56 −14 Original line number Diff line number Diff line Loading @@ -46,10 +46,29 @@ public final class Bitmap implements Parcelable { private boolean mRecycled; // Package-scoped for fast access. /*package*/ int mDensity = DENSITY_NONE; /*package*/ int mDensity = sDefaultDensity = getDefaultDensity(); private static volatile Matrix sScaleMatrix; private static volatile int sDefaultDensity = -1; /** * For backwards compatibility, allows the app layer to change the default * density when running old apps. * @hide */ public static void setDefaultDensity(int density) { sDefaultDensity = density; } /*package*/ static int getDefaultDensity() { if (sDefaultDensity >= 0) { return sDefaultDensity; } sDefaultDensity = DisplayMetrics.DENSITY_DEVICE; return sDefaultDensity; } /** * @noinspection UnusedDeclaration */ Loading @@ -72,9 +91,16 @@ public final class Bitmap implements Parcelable { /** * <p>Returns the density for this bitmap.</p> * * <p>The default density scale is {@link #DENSITY_NONE}.</p> * <p>The default density is the same density as the current display, * unless the current application does not support different screen * densities in which case it is * {@link android.util.DisplayMetrics#DENSITY_DEFAULT}. Note that * compatibility mode is determined by the application that was initially * loaded into a process -- applications that share the same process should * all have the same compatibility, or ensure they explicitly set the * density of their bitmaps appropriately.</p> * * @return A scaling factor of the default density (160) or {@link #DENSITY_NONE} * @return A scaling factor of the default density or {@link #DENSITY_NONE} * if the scaling factor is unknown. * * @see #setDensity(int) Loading Loading @@ -272,7 +298,8 @@ public final class Bitmap implements Parcelable { * Tries to make a new bitmap based on the dimensions of this bitmap, * setting the new bitmap's config to the one specified, and then copying * this bitmap's pixels into the new bitmap. If the conversion is not * supported, or the allocator fails, then this returns NULL. * supported, or the allocator fails, then this returns NULL. The returned * bitmap initially has the same density as the original. * * @param config The desired config for the resulting bitmap * @param isMutable True if the resulting bitmap should be mutable (i.e. Loading @@ -281,7 +308,11 @@ public final class Bitmap implements Parcelable { */ public Bitmap copy(Config config, boolean isMutable) { checkRecycled("Can't copy a recycled bitmap"); return nativeCopy(mNativeBitmap, config.nativeInt, isMutable); Bitmap b = nativeCopy(mNativeBitmap, config.nativeInt, isMutable); if (b != null) { b.mDensity = mDensity; } return b; } public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, Loading Loading @@ -316,7 +347,8 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from the source bitmap. The new bitmap may * be the same object as source, or a copy may have been made. * be the same object as source, or a copy may have been made. It is * initialized with the same density as the original bitmap. */ public static Bitmap createBitmap(Bitmap src) { return createBitmap(src, 0, 0, src.getWidth(), src.getHeight()); Loading @@ -325,7 +357,8 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from the specified subset of the source * bitmap. The new bitmap may be the same object as source, or a copy may * have been made. * have been made. It is * initialized with the same density as the original bitmap. * * @param source The bitmap we are subsetting * @param x The x coordinate of the first pixel in source Loading @@ -339,7 +372,8 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from subset of the source bitmap, * transformed by the optional matrix. * transformed by the optional matrix. It is * initialized with the same density as the original bitmap. * * @param source The bitmap we are subsetting * @param x The x coordinate of the first pixel in source Loading Loading @@ -406,18 +440,20 @@ public final class Bitmap implements Parcelable { paint.setAntiAlias(true); } } canvas.setBitmap(bitmap); canvas.drawBitmap(source, srcR, dstR, paint); // The new bitmap was created from a known bitmap source so assume that // they use the same density bitmap.mDensity = source.mDensity; canvas.setBitmap(bitmap); canvas.drawBitmap(source, srcR, dstR, paint); return bitmap; } /** * Returns a mutable bitmap with the specified width and height. * Returns a mutable bitmap with the specified width and height. Its * initial density is as per {@link #getDensity}. * * @param width The width of the bitmap * @param height The height of the bitmap Loading @@ -432,7 +468,8 @@ public final class Bitmap implements Parcelable { /** * Returns a immutable bitmap with the specified width and height, with each * pixel value set to the corresponding value in the colors array. * pixel value set to the corresponding value in the colors array. Its * initial density is as per {@link #getDensity}. * * @param colors Array of {@link Color} used to initialize the pixels. * @param offset Number of values to skip before the first color in the Loading Loading @@ -466,7 +503,8 @@ public final class Bitmap implements Parcelable { /** * Returns a immutable bitmap with the specified width and height, with each * pixel value set to the corresponding value in the colors array. * pixel value set to the corresponding value in the colors array. Its * initial density is as per {@link #getDensity}. * * @param colors Array of {@link Color} used to initialize the pixels. * This array must be at least as large as width * height. Loading Loading @@ -882,6 +920,9 @@ public final class Bitmap implements Parcelable { * -2, -2, so that drawing the alpha bitmap offset by (-2, -2) and then * drawing the original would result in the blur visually aligning with * the original. * * <p>The initial density of the returned bitmap is the same as the original's. * * @param paint Optional paint used to modify the alpha values in the * resulting bitmap. Pass null for default behavior. * @param offsetXY Optional array that returns the X (index 0) and Y Loading @@ -899,6 +940,7 @@ public final class Bitmap implements Parcelable { if (bm == null) { throw new RuntimeException("Failed to extractAlpha on Bitmap"); } bm.mDensity = mDensity; return bm; } Loading graphics/java/android/graphics/Canvas.java +30 −17 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ public class Canvas { private DrawFilter mDrawFilter; // Package-scoped for quick access. /*package*/ int mDensity = DisplayMetrics.DENSITY_DEFAULT; /*package*/ int mDensity = Bitmap.DENSITY_NONE; // Used by native code @SuppressWarnings({"UnusedDeclaration"}) Loading @@ -57,7 +57,9 @@ public class Canvas { /** * Construct an empty raster canvas. Use setBitmap() to specify a bitmap to * draw into. * draw into. The initial target density is {@link Bitmap#DENSITY_NONE}; * this will typically be replaced when a target bitmap is set for the * canvas. */ public Canvas() { // 0 means no native bitmap Loading @@ -68,6 +70,9 @@ public class Canvas { * Construct a canvas with the specified bitmap to draw into. The bitmap * must be mutable. * * <p>The initial target density of the canvas is the same as the given * bitmap's density. * * @param bitmap Specifies a mutable bitmap for the canvas to draw into. */ public Canvas(Bitmap bitmap) { Loading @@ -78,9 +83,7 @@ public class Canvas { throwIfRecycled(bitmap); mNativeCanvas = initRaster(bitmap.ni()); mBitmap = bitmap; final int density = bitmap.mDensity; mDensity = density == Bitmap.DENSITY_NONE ? DisplayMetrics.DENSITY_DEFAULT : density; mDensity = bitmap.mDensity; } /*package*/ Canvas(int nativeCanvas) { Loading @@ -88,6 +91,7 @@ public class Canvas { throw new IllegalStateException(); } mNativeCanvas = nativeCanvas; mDensity = Bitmap.getDefaultDensity(); } /** Loading @@ -96,10 +100,14 @@ public class Canvas { * be supported in this mode (e.g. some GL implementations may not support * antialiasing or certain effects like ColorMatrix or certain Xfermodes). * However, no exception will be thrown in those cases. * * <p>The initial target density of the canvas is the same as the initial * density of bitmaps as per {@link Bitmap#getDensity() Bitmap.getDensity()}. */ public Canvas(GL gl) { mNativeCanvas = initGL(); mGL = gl; mDensity = Bitmap.getDefaultDensity(); } /** Loading @@ -120,9 +128,13 @@ public class Canvas { } /** * Specify a bitmap for the canvas to draw into. * Specify a bitmap for the canvas to draw into. As a side-effect, also * updates the canvas's target density to match that of the bitmap. * * @param bitmap Specifies a mutable bitmap for the canvas to draw into. * * @see #setDensity(int) * @see #getDensity() */ public void setBitmap(Bitmap bitmap) { if (!bitmap.isMutable()) { Loading @@ -135,9 +147,7 @@ public class Canvas { native_setBitmap(mNativeCanvas, bitmap.ni()); mBitmap = bitmap; final int density = bitmap.mDensity; mDensity = density == Bitmap.DENSITY_NONE ? DisplayMetrics.DENSITY_DEFAULT : density; mDensity = bitmap.mDensity; } /** Loading Loading @@ -176,12 +186,12 @@ public class Canvas { public native int getHeight(); /** * <p>Returns the density for this Canvas' backing bitmap.</p> * * <p>The default density scale is {@link Bitmap#DENSITY_NONE}.</p> * <p>Returns the target density of the canvas. The default density is * derived from the density of its backing bitmap, or * {@link Bitmap#DENSITY_NONE} if there is not one.</p> * * @return A scaling factor of the default density (160dpi) or * {@link Bitmap#DENSITY_NONE} if the scaling factor is unknown. * @return Returns the current target density of the canvas, which is used * to determine the scaling factor when drawing a bitmap into it. * * @see #setDensity(int) * @see Bitmap#getDensity() Loading @@ -191,10 +201,13 @@ public class Canvas { } /** * <p>Specifies the density for this Canvas' backing bitmap. * <p>Specifies the density for this Canvas' backing bitmap. This modifies * the target density of the canvas itself, as well as the density of its * backing bitmap via {@link Bitmap#setDensity(int) Bitmap.setDensity(int)}. * * @param density The density scaling factor to use with this bitmap or * {@link Bitmap#DENSITY_NONE} if the factor is unknown. * @param density The new target density of the canvas, which is used * to determine the scaling factor when drawing a bitmap into it. Use * {@link Bitmap#DENSITY_NONE} to disable bitmap scaling. * * @see #getDensity() * @see Bitmap#setDensity(int) Loading Loading
core/java/android/app/ActivityThread.java +8 −0 Original line number Diff line number Diff line Loading @@ -3753,6 +3753,14 @@ public final class ActivityThread { data.info = getPackageInfoNoCheck(data.appInfo); /** * Switch this process to density compatibility mode if needed. */ if ((data.appInfo.flags&ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) == 0) { Bitmap.setDefaultDensity(DisplayMetrics.DENSITY_DEFAULT); } if (data.debugMode != IApplicationThread.DEBUG_OFF) { // XXX should have option to change the port. Debug.changeDebugPort(8100); Loading
graphics/java/android/graphics/Bitmap.java +56 −14 Original line number Diff line number Diff line Loading @@ -46,10 +46,29 @@ public final class Bitmap implements Parcelable { private boolean mRecycled; // Package-scoped for fast access. /*package*/ int mDensity = DENSITY_NONE; /*package*/ int mDensity = sDefaultDensity = getDefaultDensity(); private static volatile Matrix sScaleMatrix; private static volatile int sDefaultDensity = -1; /** * For backwards compatibility, allows the app layer to change the default * density when running old apps. * @hide */ public static void setDefaultDensity(int density) { sDefaultDensity = density; } /*package*/ static int getDefaultDensity() { if (sDefaultDensity >= 0) { return sDefaultDensity; } sDefaultDensity = DisplayMetrics.DENSITY_DEVICE; return sDefaultDensity; } /** * @noinspection UnusedDeclaration */ Loading @@ -72,9 +91,16 @@ public final class Bitmap implements Parcelable { /** * <p>Returns the density for this bitmap.</p> * * <p>The default density scale is {@link #DENSITY_NONE}.</p> * <p>The default density is the same density as the current display, * unless the current application does not support different screen * densities in which case it is * {@link android.util.DisplayMetrics#DENSITY_DEFAULT}. Note that * compatibility mode is determined by the application that was initially * loaded into a process -- applications that share the same process should * all have the same compatibility, or ensure they explicitly set the * density of their bitmaps appropriately.</p> * * @return A scaling factor of the default density (160) or {@link #DENSITY_NONE} * @return A scaling factor of the default density or {@link #DENSITY_NONE} * if the scaling factor is unknown. * * @see #setDensity(int) Loading Loading @@ -272,7 +298,8 @@ public final class Bitmap implements Parcelable { * Tries to make a new bitmap based on the dimensions of this bitmap, * setting the new bitmap's config to the one specified, and then copying * this bitmap's pixels into the new bitmap. If the conversion is not * supported, or the allocator fails, then this returns NULL. * supported, or the allocator fails, then this returns NULL. The returned * bitmap initially has the same density as the original. * * @param config The desired config for the resulting bitmap * @param isMutable True if the resulting bitmap should be mutable (i.e. Loading @@ -281,7 +308,11 @@ public final class Bitmap implements Parcelable { */ public Bitmap copy(Config config, boolean isMutable) { checkRecycled("Can't copy a recycled bitmap"); return nativeCopy(mNativeBitmap, config.nativeInt, isMutable); Bitmap b = nativeCopy(mNativeBitmap, config.nativeInt, isMutable); if (b != null) { b.mDensity = mDensity; } return b; } public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, Loading Loading @@ -316,7 +347,8 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from the source bitmap. The new bitmap may * be the same object as source, or a copy may have been made. * be the same object as source, or a copy may have been made. It is * initialized with the same density as the original bitmap. */ public static Bitmap createBitmap(Bitmap src) { return createBitmap(src, 0, 0, src.getWidth(), src.getHeight()); Loading @@ -325,7 +357,8 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from the specified subset of the source * bitmap. The new bitmap may be the same object as source, or a copy may * have been made. * have been made. It is * initialized with the same density as the original bitmap. * * @param source The bitmap we are subsetting * @param x The x coordinate of the first pixel in source Loading @@ -339,7 +372,8 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from subset of the source bitmap, * transformed by the optional matrix. * transformed by the optional matrix. It is * initialized with the same density as the original bitmap. * * @param source The bitmap we are subsetting * @param x The x coordinate of the first pixel in source Loading Loading @@ -406,18 +440,20 @@ public final class Bitmap implements Parcelable { paint.setAntiAlias(true); } } canvas.setBitmap(bitmap); canvas.drawBitmap(source, srcR, dstR, paint); // The new bitmap was created from a known bitmap source so assume that // they use the same density bitmap.mDensity = source.mDensity; canvas.setBitmap(bitmap); canvas.drawBitmap(source, srcR, dstR, paint); return bitmap; } /** * Returns a mutable bitmap with the specified width and height. * Returns a mutable bitmap with the specified width and height. Its * initial density is as per {@link #getDensity}. * * @param width The width of the bitmap * @param height The height of the bitmap Loading @@ -432,7 +468,8 @@ public final class Bitmap implements Parcelable { /** * Returns a immutable bitmap with the specified width and height, with each * pixel value set to the corresponding value in the colors array. * pixel value set to the corresponding value in the colors array. Its * initial density is as per {@link #getDensity}. * * @param colors Array of {@link Color} used to initialize the pixels. * @param offset Number of values to skip before the first color in the Loading Loading @@ -466,7 +503,8 @@ public final class Bitmap implements Parcelable { /** * Returns a immutable bitmap with the specified width and height, with each * pixel value set to the corresponding value in the colors array. * pixel value set to the corresponding value in the colors array. Its * initial density is as per {@link #getDensity}. * * @param colors Array of {@link Color} used to initialize the pixels. * This array must be at least as large as width * height. Loading Loading @@ -882,6 +920,9 @@ public final class Bitmap implements Parcelable { * -2, -2, so that drawing the alpha bitmap offset by (-2, -2) and then * drawing the original would result in the blur visually aligning with * the original. * * <p>The initial density of the returned bitmap is the same as the original's. * * @param paint Optional paint used to modify the alpha values in the * resulting bitmap. Pass null for default behavior. * @param offsetXY Optional array that returns the X (index 0) and Y Loading @@ -899,6 +940,7 @@ public final class Bitmap implements Parcelable { if (bm == null) { throw new RuntimeException("Failed to extractAlpha on Bitmap"); } bm.mDensity = mDensity; return bm; } Loading
graphics/java/android/graphics/Canvas.java +30 −17 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ public class Canvas { private DrawFilter mDrawFilter; // Package-scoped for quick access. /*package*/ int mDensity = DisplayMetrics.DENSITY_DEFAULT; /*package*/ int mDensity = Bitmap.DENSITY_NONE; // Used by native code @SuppressWarnings({"UnusedDeclaration"}) Loading @@ -57,7 +57,9 @@ public class Canvas { /** * Construct an empty raster canvas. Use setBitmap() to specify a bitmap to * draw into. * draw into. The initial target density is {@link Bitmap#DENSITY_NONE}; * this will typically be replaced when a target bitmap is set for the * canvas. */ public Canvas() { // 0 means no native bitmap Loading @@ -68,6 +70,9 @@ public class Canvas { * Construct a canvas with the specified bitmap to draw into. The bitmap * must be mutable. * * <p>The initial target density of the canvas is the same as the given * bitmap's density. * * @param bitmap Specifies a mutable bitmap for the canvas to draw into. */ public Canvas(Bitmap bitmap) { Loading @@ -78,9 +83,7 @@ public class Canvas { throwIfRecycled(bitmap); mNativeCanvas = initRaster(bitmap.ni()); mBitmap = bitmap; final int density = bitmap.mDensity; mDensity = density == Bitmap.DENSITY_NONE ? DisplayMetrics.DENSITY_DEFAULT : density; mDensity = bitmap.mDensity; } /*package*/ Canvas(int nativeCanvas) { Loading @@ -88,6 +91,7 @@ public class Canvas { throw new IllegalStateException(); } mNativeCanvas = nativeCanvas; mDensity = Bitmap.getDefaultDensity(); } /** Loading @@ -96,10 +100,14 @@ public class Canvas { * be supported in this mode (e.g. some GL implementations may not support * antialiasing or certain effects like ColorMatrix or certain Xfermodes). * However, no exception will be thrown in those cases. * * <p>The initial target density of the canvas is the same as the initial * density of bitmaps as per {@link Bitmap#getDensity() Bitmap.getDensity()}. */ public Canvas(GL gl) { mNativeCanvas = initGL(); mGL = gl; mDensity = Bitmap.getDefaultDensity(); } /** Loading @@ -120,9 +128,13 @@ public class Canvas { } /** * Specify a bitmap for the canvas to draw into. * Specify a bitmap for the canvas to draw into. As a side-effect, also * updates the canvas's target density to match that of the bitmap. * * @param bitmap Specifies a mutable bitmap for the canvas to draw into. * * @see #setDensity(int) * @see #getDensity() */ public void setBitmap(Bitmap bitmap) { if (!bitmap.isMutable()) { Loading @@ -135,9 +147,7 @@ public class Canvas { native_setBitmap(mNativeCanvas, bitmap.ni()); mBitmap = bitmap; final int density = bitmap.mDensity; mDensity = density == Bitmap.DENSITY_NONE ? DisplayMetrics.DENSITY_DEFAULT : density; mDensity = bitmap.mDensity; } /** Loading Loading @@ -176,12 +186,12 @@ public class Canvas { public native int getHeight(); /** * <p>Returns the density for this Canvas' backing bitmap.</p> * * <p>The default density scale is {@link Bitmap#DENSITY_NONE}.</p> * <p>Returns the target density of the canvas. The default density is * derived from the density of its backing bitmap, or * {@link Bitmap#DENSITY_NONE} if there is not one.</p> * * @return A scaling factor of the default density (160dpi) or * {@link Bitmap#DENSITY_NONE} if the scaling factor is unknown. * @return Returns the current target density of the canvas, which is used * to determine the scaling factor when drawing a bitmap into it. * * @see #setDensity(int) * @see Bitmap#getDensity() Loading @@ -191,10 +201,13 @@ public class Canvas { } /** * <p>Specifies the density for this Canvas' backing bitmap. * <p>Specifies the density for this Canvas' backing bitmap. This modifies * the target density of the canvas itself, as well as the density of its * backing bitmap via {@link Bitmap#setDensity(int) Bitmap.setDensity(int)}. * * @param density The density scaling factor to use with this bitmap or * {@link Bitmap#DENSITY_NONE} if the factor is unknown. * @param density The new target density of the canvas, which is used * to determine the scaling factor when drawing a bitmap into it. Use * {@link Bitmap#DENSITY_NONE} to disable bitmap scaling. * * @see #getDensity() * @see Bitmap#setDensity(int) Loading