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

Commit 0492eefe authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Allow AssetStreamAdaptor to be seekable

Bug: 78866720
Test: Manual

It already supports rewinding, and the underlying Asset supports
seeking. Allow it to be seeked so that SkGifCodec can read directly from
it rather than copying data it needs for internal use.

Change-Id: I0765dcf4a507724878a5a700a770d35802c4b7be
parent 854c050c
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -49,6 +49,38 @@ SkStreamRewindable* AssetStreamAdaptor::onDuplicate() const {
    return NULL;
}

bool AssetStreamAdaptor::hasPosition() const {
    return fAsset->seek(0, SEEK_CUR) != -1;
}

size_t AssetStreamAdaptor::getPosition() const {
    const off64_t offset = fAsset->seek(0, SEEK_CUR);
    if (offset == -1) {
        SkDebugf("---- fAsset->seek(0, SEEK_CUR) failed\n");
        return 0;
    }

    return offset;
}

bool AssetStreamAdaptor::seek(size_t position) {
    if (fAsset->seek(position, SEEK_SET) == -1) {
        SkDebugf("---- fAsset->seek(0, SEEK_SET) failed\n");
        return false;
    }

    return true;
}

bool AssetStreamAdaptor::move(long offset) {
    if (fAsset->seek(offset, SEEK_CUR) == -1) {
        SkDebugf("---- fAsset->seek(%i, SEEK_CUR) failed\n", offset);
        return false;
    }

    return true;
}

size_t AssetStreamAdaptor::read(void* buffer, size_t size) {
    ssize_t amount;

+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ public:
    virtual size_t read(void* buffer, size_t size);
    virtual bool hasLength() const { return true; }
    virtual size_t getLength() const;
    virtual bool hasPosition() const;
    virtual size_t getPosition() const;
    virtual bool seek(size_t position);
    virtual bool move(long offset);
    virtual bool isAtEnd() const;

protected: