diff options
author | Leon Scroggins III <scroggo@google.com> | 2016-12-16 11:39:51 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-19 15:25:13 +0000 |
commit | 932efed7c89c69616e283fdfef65e86b9d9da381 (patch) | |
tree | a757be369987a936d2163f5c746a8e1ff0e102fc /tests/CodecPartialTest.cpp | |
parent | 8e04286fa62d04767d39d820439fa4caf6223a46 (diff) |
GIF: Avoid copying/storing data when possible
If the input SkStream has a length and position, do not copy and store
LZW blocks or ColorMaps. Instead, mark the position and size, and read
from the stream when necessary.
This will save memory in Chromium's use case, which has already
buffered all of its data.
In the case where we *do* need to copy, store it on the SkStreamBuffer.
This allows SkGifImageReader to have simpler code.
Add tests.
Change-Id: Ic65fa766328ae2e5974b2084bc2099e19aced731
Reviewed-on: https://skia-review.googlesource.com/6157
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'tests/CodecPartialTest.cpp')
-rw-r--r-- | tests/CodecPartialTest.cpp | 41 |
1 files changed, 1 insertions, 40 deletions
diff --git a/tests/CodecPartialTest.cpp b/tests/CodecPartialTest.cpp index 93e5d63f22..62f9d8570e 100644 --- a/tests/CodecPartialTest.cpp +++ b/tests/CodecPartialTest.cpp @@ -12,6 +12,7 @@ #include "SkRWBuffer.h" #include "SkString.h" +#include "FakeStreams.h" #include "Resources.h" #include "Test.h" @@ -50,46 +51,6 @@ static void compare_bitmaps(skiatest::Reporter* r, const SkBitmap& bm1, const Sk } } -/* - * Represents a stream without all of its data. - */ -class HaltingStream : public SkStream { -public: - HaltingStream(sk_sp<SkData> data, size_t initialLimit) - : fTotalSize(data->size()) - , fLimit(initialLimit) - , fStream(std::move(data)) - {} - - void addNewData(size_t extra) { - fLimit = SkTMin(fTotalSize, fLimit + extra); - } - - size_t read(void* buffer, size_t size) override { - if (fStream.getPosition() + size > fLimit) { - size = fLimit - fStream.getPosition(); - } - - return fStream.read(buffer, size); - } - - bool isAtEnd() const override { - return fStream.isAtEnd(); - } - - bool hasPosition() const override { return true; } - size_t getPosition() const override { return fStream.getPosition(); } - bool rewind() override { return fStream.rewind(); } - bool move(long offset) override { return fStream.move(offset); } - - bool isAllDataReceived() const { return fLimit == fTotalSize; } - -private: - const size_t fTotalSize; - size_t fLimit; - SkMemoryStream fStream; -}; - static void test_partial(skiatest::Reporter* r, const char* name, size_t minBytes = 0) { sk_sp<SkData> file = make_from_resource(name); if (!file) { |