diff options
author | 2016-02-05 08:21:19 -0800 | |
---|---|---|
committer | 2016-02-05 08:21:19 -0800 | |
commit | 9c7a8a464894436fc71a15b5419e818905226cdf (patch) | |
tree | eeaf5afed6b1cc4745769f54274b0140067282ec /tests | |
parent | e63ffef6248bd103b5f7827f1e4bc75e47ca9e20 (diff) |
Optimize the SkRawStream when the input is an asset stream
BUG=b/26841494
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1645963002
Review URL: https://codereview.chromium.org/1645963002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CodexTest.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp index 747d064481..1261d2b556 100644 --- a/tests/CodexTest.cpp +++ b/tests/CodexTest.cpp @@ -389,6 +389,7 @@ DEF_TEST(Codec, r) { // RAW #if defined(SK_CODEC_DECODES_RAW) check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false); + check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false); #endif } @@ -586,6 +587,7 @@ DEF_TEST(Codec_Dimensions, r) { // RAW #if defined(SK_CODEC_DECODES_RAW) test_dimensions(r, "sample_1mp.dng"); + test_dimensions(r, "dng_with_preview.dng"); #endif } @@ -829,6 +831,54 @@ private: const size_t fLimit; }; +// Stream that is not an asset stream (!hasPosition() or !hasLength()) +class NotAssetMemStream : public SkStream { +public: + NotAssetMemStream(SkData* data) : fStream(data) {} + + bool hasPosition() const override { + return false; + } + + bool hasLength() const override { + return false; + } + + size_t peek(void* buf, size_t bytes) const override { + return fStream.peek(buf, bytes); + } + size_t read(void* buf, size_t bytes) override { + return fStream.read(buf, bytes); + } + bool rewind() override { + return fStream.rewind(); + } + bool isAtEnd() const override { + return fStream.isAtEnd(); + } +private: + SkMemoryStream fStream; +}; + +// Test that the RawCodec works also for not asset stream. This will test the code path using +// SkRawBufferedStream instead of SkRawAssetStream. +#if defined(SK_CODEC_DECODES_RAW) +DEF_TEST(Codec_raw_notseekable, r) { + const char* path = "dng_with_preview.dng"; + SkString fullPath(GetResourcePath(path)); + SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str())); + if (!data) { + SkDebugf("Missing resource '%s'\n", path); + return; + } + + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(data))); + REPORTER_ASSERT(r, codec); + + test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); +} +#endif + // Test that even if webp_parse_header fails to peek enough, it will fall back to read() // + rewind() and succeed. DEF_TEST(Codec_webp_peek, r) { |