Implement outline support for nine patches

b/15856895

Nine patches now have outline round rect metadata stored as optional
png tags. aapt generates these automatically by inspecting the bitmap
pixels to estimate outline bounds and round rect radius, based on
opacity.

Change-Id: I226e328a97873010d9e1adb797ac48f93a31183c
This commit is contained in:
Chris Craik
2014-07-08 17:13:08 -07:00
parent 5028fb0357
commit 47cd8e921d
10 changed files with 280 additions and 90 deletions

View File

@@ -73,8 +73,8 @@ public final class Bitmap implements Parcelable {
*/
private boolean mRequestPremultiplied;
private byte[] mNinePatchChunk; // may be null
private int[] mOpticalInsets; // may be null
private byte[] mNinePatchChunk; // may be null
private NinePatch.InsetStruct mNinePatchInsets; // may be null
private int mWidth;
private int mHeight;
private boolean mRecycled;
@@ -111,7 +111,7 @@ public final class Bitmap implements Parcelable {
@SuppressWarnings({"UnusedDeclaration"}) // called from JNI
Bitmap(long nativeBitmap, byte[] buffer, int width, int height, int density,
boolean isMutable, boolean requestPremultiplied,
byte[] ninePatchChunk, int[] opticalInsets) {
byte[] ninePatchChunk, NinePatch.InsetStruct ninePatchInsets) {
if (nativeBitmap == 0) {
throw new RuntimeException("internal error: native bitmap is 0");
}
@@ -126,7 +126,7 @@ public final class Bitmap implements Parcelable {
mFinalizer = new BitmapFinalizer(nativeBitmap);
mNinePatchChunk = ninePatchChunk;
mOpticalInsets = opticalInsets;
mNinePatchInsets = ninePatchInsets;
if (density >= 0) {
mDensity = density;
}
@@ -946,16 +946,18 @@ public final class Bitmap implements Parcelable {
* @hide
*/
public void getOpticalInsets(@NonNull Rect outInsets) {
if (mOpticalInsets == null) {
if (mNinePatchInsets == null) {
outInsets.setEmpty();
} else {
outInsets.left = mOpticalInsets[0];
outInsets.top = mOpticalInsets[1];
outInsets.right = mOpticalInsets[2];
outInsets.bottom = mOpticalInsets[3];
outInsets.set(mNinePatchInsets.opticalRect);
}
}
/** @hide */
public NinePatch.InsetStruct getNinePatchInsets() {
return mNinePatchInsets;
}
/**
* Specifies the known formats a bitmap can be compressed into
*/