Merge "Refactor android.graphics.Picture JNI bindings."
This commit is contained in:
committed by
Android (Google) Code Review
commit
bc8bd76bc7
@@ -31,18 +31,13 @@ public class Picture {
|
||||
private Canvas mRecordingCanvas;
|
||||
private final long mNativePicture;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final boolean createdFromStream;
|
||||
|
||||
private static final int WORKING_STREAM_STORAGE = 16 * 1024;
|
||||
|
||||
/**
|
||||
* Creates an empty picture that is ready to record.
|
||||
*/
|
||||
public Picture() {
|
||||
this(nativeConstructor(0), false);
|
||||
this(nativeConstructor(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +46,23 @@ public class Picture {
|
||||
* changes will not be reflected in this picture.
|
||||
*/
|
||||
public Picture(Picture src) {
|
||||
this(nativeConstructor(src != null ? src.mNativePicture : 0), false);
|
||||
this(nativeConstructor(src != null ? src.mNativePicture : 0));
|
||||
}
|
||||
|
||||
private Picture(long nativePicture) {
|
||||
if (nativePicture == 0) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
mNativePicture = nativePicture;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
nativeDestructor(mNativePicture);
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,13 +96,17 @@ public class Picture {
|
||||
* Get the width of the picture as passed to beginRecording. This
|
||||
* does not reflect (per se) the content of the picture.
|
||||
*/
|
||||
public native int getWidth();
|
||||
public int getWidth() {
|
||||
return nativeGetWidth(mNativePicture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the picture as passed to beginRecording. This
|
||||
* does not reflect (per se) the content of the picture.
|
||||
*/
|
||||
public native int getHeight();
|
||||
public int getHeight() {
|
||||
return nativeGetHeight(mNativePicture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw this picture on the canvas.
|
||||
@@ -130,7 +145,7 @@ public class Picture {
|
||||
*/
|
||||
@Deprecated
|
||||
public static Picture createFromStream(InputStream stream) {
|
||||
return new Picture(nativeCreateFromStream(stream, new byte[WORKING_STREAM_STORAGE]), true);
|
||||
return new Picture(nativeCreateFromStream(stream, new byte[WORKING_STREAM_STORAGE]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,32 +174,12 @@ public class Picture {
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
nativeDestructor(mNativePicture);
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
final long ni() {
|
||||
return mNativePicture;
|
||||
}
|
||||
|
||||
private Picture(long nativePicture, boolean fromStream) {
|
||||
if (nativePicture == 0) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
mNativePicture = nativePicture;
|
||||
createdFromStream = fromStream;
|
||||
}
|
||||
|
||||
// return empty picture if src is 0, or a copy of the native src
|
||||
private static native long nativeConstructor(long nativeSrcOr0);
|
||||
private static native long nativeCreateFromStream(InputStream stream,
|
||||
byte[] storage);
|
||||
private static native long nativeBeginRecording(long nativeCanvas,
|
||||
int w, int h);
|
||||
private static native long nativeCreateFromStream(InputStream stream, byte[] storage);
|
||||
private static native int nativeGetWidth(long nativePicture);
|
||||
private static native int nativeGetHeight(long nativePicture);
|
||||
private static native long nativeBeginRecording(long nativeCanvas, int w, int h);
|
||||
private static native void nativeEndRecording(long nativeCanvas);
|
||||
private static native void nativeDraw(long nativeCanvas, long nativePicture);
|
||||
private static native boolean nativeWriteToStream(long nativePicture,
|
||||
@@ -201,18 +196,15 @@ public class Picture {
|
||||
|
||||
@Override
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
throw new RuntimeException(
|
||||
"Cannot call setBitmap on a picture canvas");
|
||||
throw new RuntimeException("Cannot call setBitmap on a picture canvas");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPicture(Picture picture) {
|
||||
if (mPicture == picture) {
|
||||
throw new RuntimeException(
|
||||
"Cannot draw a picture into its recording canvas");
|
||||
throw new RuntimeException("Cannot draw a picture into its recording canvas");
|
||||
}
|
||||
super.drawPicture(picture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user