Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ae7857e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Report more specific error if codec creation fails"

parents 3b956718 c782ad88
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -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
+20 −4
Original line number Diff line number Diff line
@@ -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;
    }

+4 −3
Original line number Diff line number Diff line
@@ -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 {};