From 932efed7c89c69616e283fdfef65e86b9d9da381 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 16 Dec 2016 11:39:51 -0500 Subject: 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 Commit-Queue: Leon Scroggins --- tests/CodecPartialTest.cpp | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'tests/CodecPartialTest.cpp') 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 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 file = make_from_resource(name); if (!file) { -- cgit v1.2.3