Merge "Allow AssetStreamAdaptor to be seekable" into pi-dev

This commit is contained in:
Leon Scroggins
2018-05-09 16:40:01 +00:00
committed by Android (Google) Code Review
2 changed files with 36 additions and 0 deletions

View File

@@ -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;

View File

@@ -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: