Merge "Report more specific error if codec creation fails"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2ae7857ee5
@@ -237,10 +237,22 @@ static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream,
|
||||
|
||||
// Create the codec.
|
||||
NinePatchPeeker peeker;
|
||||
std::unique_ptr<SkAndroidCodec> codec = SkAndroidCodec::MakeFromStream(
|
||||
std::move(stream), &peeker);
|
||||
if (!codec.get()) {
|
||||
return nullObjectReturn("SkAndroidCodec::MakeFromStream returned null");
|
||||
std::unique_ptr<SkAndroidCodec> codec;
|
||||
{
|
||||
SkCodec::Result result;
|
||||
std::unique_ptr<SkCodec> c = SkCodec::MakeFromStream(std::move(stream), &result,
|
||||
&peeker);
|
||||
if (!c) {
|
||||
SkString msg;
|
||||
msg.printf("Failed to create image decoder with message '%s'",
|
||||
SkCodec::ResultToString(result));
|
||||
return nullObjectReturn(msg.c_str());
|
||||
}
|
||||
|
||||
codec = SkAndroidCodec::MakeFromCodec(std::move(c));
|
||||
if (!codec) {
|
||||
return nullObjectReturn("SkAndroidCodec::MakeFromCodec returned null");
|
||||
}
|
||||
}
|
||||
|
||||
// Do not allow ninepatch decodes to 565. In the past, decodes to 565
|
||||
|
||||
@@ -77,11 +77,27 @@ static jobject native_create(JNIEnv* env, std::unique_ptr<SkStream> stream) {
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<ImageDecoder> decoder(new ImageDecoder);
|
||||
decoder->mCodec = SkAndroidCodec::MakeFromStream(std::move(stream), &decoder->mPeeker);
|
||||
SkCodec::Result result;
|
||||
auto codec = SkCodec::MakeFromStream(std::move(stream), &result, &decoder->mPeeker);
|
||||
if (!codec) {
|
||||
switch (result) {
|
||||
case SkCodec::kIncompleteInput:
|
||||
env->ThrowNew(gIncomplete_class, "Incomplete input");
|
||||
break;
|
||||
default:
|
||||
SkString msg;
|
||||
msg.printf("Failed to create image decoder with message '%s'",
|
||||
SkCodec::ResultToString(result));
|
||||
doThrowIOE(env, msg.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
decoder->mCodec = SkAndroidCodec::MakeFromCodec(std::move(codec));
|
||||
if (!decoder->mCodec.get()) {
|
||||
// FIXME: (b/71578461) Use the error message from
|
||||
// SkCodec::MakeFromStream to report a more informative error message.
|
||||
doThrowIOE(env, "Failed to create an SkCodec");
|
||||
doThrowIOE(env, "Could not create AndroidCodec");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,11 +239,12 @@ public final class ImageDecoder implements AutoCloseable {
|
||||
};
|
||||
|
||||
/**
|
||||
* Supplied to onPartialImage if the provided data is incomplete.
|
||||
* Used if the provided data is incomplete.
|
||||
*
|
||||
* Will never be thrown by ImageDecoder.
|
||||
* May be thrown if there is nothing to display.
|
||||
*
|
||||
* There may be a partial image to display.
|
||||
* If supplied to onPartialImage, there may be a correct partial image to
|
||||
* display.
|
||||
*/
|
||||
public static class IncompleteException extends IOException {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user