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

Commit 0c699add authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Allow ImageDecoder to read SkFILEStream directly

Bug: 78866720
Test: Manual

If the input stream is seekable, SkGifCodec will read from it directly.
If not, it has to copy (parts of) the input in order re-decode when it
loops. Directly use the seekable SkFILEStream so that SkGifCodec skips
the copy, saving memory proportional to the size of the file.

Depends on a change in upstream Skia which allows SkFILEStream to treat
the initial offset as the beginning of the file:
https://skia-review.googlesource.com/c/skia/+/126511

Change-Id: Iefb58785157ba684ad3603778175b3dba97567b2
parent 0492eefe
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -139,20 +139,11 @@ static jobject ImageDecoder_nCreateFd(JNIEnv* env, jobject /*clazz*/,
        return throw_exception(env, ImageDecoder::kSourceMalformedData, "Could not open file",
                               nullptr, source);
    }
    std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file));

    if (::lseek(descriptor, 0, SEEK_CUR) == 0) {
    std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file));
    return native_create(env, std::move(fileStream), source);
}

    // FIXME: This allows us to pretend the current location is the beginning,
    // but it would be better if SkFILEStream allowed treating its starting
    // point as the beginning.
    std::unique_ptr<SkStream> stream(SkFrontBufferedStream::Make(std::move(fileStream),
                SkCodec::MinBufferedBytesNeeded()));
    return native_create(env, std::move(stream), source);
}

static jobject ImageDecoder_nCreateInputStream(JNIEnv* env, jobject /*clazz*/,
        jobject is, jbyteArray storage, jobject source) {
    std::unique_ptr<SkStream> stream(CreateJavaInputStreamAdaptor(env, is, storage, false));