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

Commit c782ad88 authored by Leon Scroggins III's avatar Leon Scroggins III Committed by Leon Scroggins
Browse files

Report more specific error if codec creation fails

Bug: 71578461
Test: CtsGraphicsTestCases

Switch to SkCodec::MakeFromStream, and use its error code to determine
the Exception/error message. Then pass that to
SkAndroidCodec::MakeFromCodec. This is essentially what happened
previously (minus error reporting).

Change-Id: Iabaa61a4321d2f2e257db587013afda605b005b0
parent e7403b47
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 {};