ColorSpaces have native SkColorSpaces
Bug: 120904891 Bug: 122844033 Bug: 122514935 Test: CtsGraphicsTestCases Create an SkColorSpace when creating an android.graphics.ColorSpace.Rgb. This allows simplifying getNativeColorSpace, so that each time we need it, we do not need to call back up into Java or reconstruct the SkColorSpace. Funnel all ColorSpace.Rgb constructors into one, so we can set a final mNativePtr in the base constructor. Update TransferParameters to also be final. Use the same TransferParameters as SRGB in EXTENDED_SRGB and DISPLAY_P3. When passing a BitmapFactory.Options to native, call getNativeInstance() (which may throw an Exception) and pass the result to native. Move native ColorSpace code into its own file. Make Paint methods @CriticalNative again, now that they do not need the JNIEnv. Remove unused decodeBitmap. Change-Id: I60adbb060b87ab6f92559f1217bfefc0b9ea72e1
This commit is contained in:
@@ -460,6 +460,21 @@ public class BitmapFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for passing SkColorSpace pointer to native.
|
||||
*
|
||||
* @throws IllegalArgumentException if the ColorSpace is not Rgb or does
|
||||
* not have TransferParameters.
|
||||
*/
|
||||
static long nativeColorSpace(Options opts) {
|
||||
if (opts == null || opts.inPreferredColorSpace == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return opts.inPreferredColorSpace.getNativeInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -633,7 +648,8 @@ public class BitmapFactory {
|
||||
|
||||
Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
|
||||
try {
|
||||
bm = nativeDecodeByteArray(data, offset, length, opts);
|
||||
bm = nativeDecodeByteArray(data, offset, length, opts,
|
||||
Options.nativeColorSpace(opts));
|
||||
|
||||
if (bm == null && opts != null && opts.inBitmap != null) {
|
||||
throw new IllegalArgumentException("Problem decoding into existing bitmap");
|
||||
@@ -728,7 +744,7 @@ public class BitmapFactory {
|
||||
try {
|
||||
if (is instanceof AssetManager.AssetInputStream) {
|
||||
final long asset = ((AssetManager.AssetInputStream) is).getNativeAsset();
|
||||
bm = nativeDecodeAsset(asset, outPadding, opts);
|
||||
bm = nativeDecodeAsset(asset, outPadding, opts, Options.nativeColorSpace(opts));
|
||||
} else {
|
||||
bm = decodeStreamInternal(is, outPadding, opts);
|
||||
}
|
||||
@@ -755,7 +771,8 @@ public class BitmapFactory {
|
||||
byte [] tempStorage = null;
|
||||
if (opts != null) tempStorage = opts.inTempStorage;
|
||||
if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE];
|
||||
return nativeDecodeStream(is, tempStorage, outPadding, opts);
|
||||
return nativeDecodeStream(is, tempStorage, outPadding, opts,
|
||||
Options.nativeColorSpace(opts));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -798,7 +815,8 @@ public class BitmapFactory {
|
||||
Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeFileDescriptor");
|
||||
try {
|
||||
if (nativeIsSeekable(fd)) {
|
||||
bm = nativeDecodeFileDescriptor(fd, outPadding, opts);
|
||||
bm = nativeDecodeFileDescriptor(fd, outPadding, opts,
|
||||
Options.nativeColorSpace(opts));
|
||||
} else {
|
||||
FileInputStream fis = new FileInputStream(fd);
|
||||
try {
|
||||
@@ -835,14 +853,15 @@ public class BitmapFactory {
|
||||
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage,
|
||||
Rect padding, Options opts);
|
||||
Rect padding, Options opts, long colorSpaceHandle);
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd,
|
||||
Rect padding, Options opts);
|
||||
Rect padding, Options opts, long colorSpaceHandle);
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeAsset(long nativeAsset, Rect padding, Options opts);
|
||||
private static native Bitmap nativeDecodeAsset(long nativeAsset, Rect padding, Options opts,
|
||||
long colorSpaceHandle);
|
||||
@UnsupportedAppUsage
|
||||
private static native Bitmap nativeDecodeByteArray(byte[] data, int offset,
|
||||
int length, Options opts);
|
||||
int length, Options opts, long colorSpaceHandle);
|
||||
private static native boolean nativeIsSeekable(FileDescriptor fd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user