Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tests/CodexTest.cpp

Issue 1645963002: Optimize the SkRawStream when the input is an asset stream (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add missing override Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkRawCodec.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 check(r, "mandrill_64.png", SkISize::Make(64, 64), true, false, false); 382 check(r, "mandrill_64.png", SkISize::Make(64, 64), true, false, false);
383 check(r, "plane.png", SkISize::Make(250, 126), true, false, false); 383 check(r, "plane.png", SkISize::Make(250, 126), true, false, false);
384 // FIXME: We are not ready to test incomplete interlaced pngs 384 // FIXME: We are not ready to test incomplete interlaced pngs
385 check(r, "plane_interlaced.png", SkISize::Make(250, 126), true, false, false ); 385 check(r, "plane_interlaced.png", SkISize::Make(250, 126), true, false, false );
386 check(r, "randPixels.png", SkISize::Make(8, 8), true, false, false); 386 check(r, "randPixels.png", SkISize::Make(8, 8), true, false, false);
387 check(r, "yellow_rose.png", SkISize::Make(400, 301), true, false, false); 387 check(r, "yellow_rose.png", SkISize::Make(400, 301), true, false, false);
388 388
389 // RAW 389 // RAW
390 #if defined(SK_CODEC_DECODES_RAW) 390 #if defined(SK_CODEC_DECODES_RAW)
391 check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false); 391 check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false);
392 check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false );
392 #endif 393 #endif
393 } 394 }
394 395
395 // Test interlaced PNG in stripes, similar to DM's kStripe_Mode 396 // Test interlaced PNG in stripes, similar to DM's kStripe_Mode
396 DEF_TEST(Codec_stripes, r) { 397 DEF_TEST(Codec_stripes, r) {
397 const char * path = "plane_interlaced.png"; 398 const char * path = "plane_interlaced.png";
398 SkAutoTDelete<SkStream> stream(resource(path)); 399 SkAutoTDelete<SkStream> stream(resource(path));
399 if (!stream) { 400 if (!stream) {
400 SkDebugf("Missing resource '%s'\n", path); 401 SkDebugf("Missing resource '%s'\n", path);
401 } 402 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 test_dimensions(r, "3x3.png"); 580 test_dimensions(r, "3x3.png");
580 test_dimensions(r, "3x1.png"); 581 test_dimensions(r, "3x1.png");
581 test_dimensions(r, "1x1.png"); 582 test_dimensions(r, "1x1.png");
582 test_dimensions(r, "16x1.png"); 583 test_dimensions(r, "16x1.png");
583 test_dimensions(r, "1x16.png"); 584 test_dimensions(r, "1x16.png");
584 test_dimensions(r, "mandrill_16.png"); 585 test_dimensions(r, "mandrill_16.png");
585 586
586 // RAW 587 // RAW
587 #if defined(SK_CODEC_DECODES_RAW) 588 #if defined(SK_CODEC_DECODES_RAW)
588 test_dimensions(r, "sample_1mp.dng"); 589 test_dimensions(r, "sample_1mp.dng");
590 test_dimensions(r, "dng_with_preview.dng");
589 #endif 591 #endif
590 } 592 }
591 593
592 static void test_invalid(skiatest::Reporter* r, const char path[]) { 594 static void test_invalid(skiatest::Reporter* r, const char path[]) {
593 SkAutoTDelete<SkStream> stream(resource(path)); 595 SkAutoTDelete<SkStream> stream(resource(path));
594 if (!stream) { 596 if (!stream) {
595 SkDebugf("Missing resource '%s'\n", path); 597 SkDebugf("Missing resource '%s'\n", path);
596 return; 598 return;
597 } 599 }
598 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); 600 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 return fStream.rewind(); 824 return fStream.rewind();
823 } 825 }
824 bool isAtEnd() const override { 826 bool isAtEnd() const override {
825 return false; 827 return false;
826 } 828 }
827 private: 829 private:
828 SkMemoryStream fStream; 830 SkMemoryStream fStream;
829 const size_t fLimit; 831 const size_t fLimit;
830 }; 832 };
831 833
834 // Stream that is not an asset stream (!hasPosition() or !hasLength())
835 class NotAssetMemStream : public SkStream {
836 public:
837 NotAssetMemStream(SkData* data) : fStream(data) {}
838
839 bool hasPosition() const override {
840 return false;
841 }
842
843 bool hasLength() const override {
844 return false;
845 }
846
847 size_t peek(void* buf, size_t bytes) const override {
848 return fStream.peek(buf, bytes);
849 }
850 size_t read(void* buf, size_t bytes) override {
851 return fStream.read(buf, bytes);
852 }
853 bool rewind() override {
854 return fStream.rewind();
855 }
856 bool isAtEnd() const override {
857 return fStream.isAtEnd();
858 }
859 private:
860 SkMemoryStream fStream;
861 };
862
863 // Test that the RawCodec works also for not asset stream. This will test the co de path using
864 // SkRawBufferedStream instead of SkRawAssetStream.
865 #if defined(SK_CODEC_DECODES_RAW)
866 DEF_TEST(Codec_raw_notseekable, r) {
867 const char* path = "dng_with_preview.dng";
868 SkString fullPath(GetResourcePath(path));
869 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str()));
870 if (!data) {
871 SkDebugf("Missing resource '%s'\n", path);
872 return;
873 }
874
875 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(da ta)));
876 REPORTER_ASSERT(r, codec);
877
878 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
879 }
880 #endif
881
832 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read() 882 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read()
833 // + rewind() and succeed. 883 // + rewind() and succeed.
834 DEF_TEST(Codec_webp_peek, r) { 884 DEF_TEST(Codec_webp_peek, r) {
835 const char* path = "baby_tux.webp"; 885 const char* path = "baby_tux.webp";
836 SkString fullPath(GetResourcePath(path)); 886 SkString fullPath(GetResourcePath(path));
837 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str())); 887 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str()));
838 if (!data) { 888 if (!data) {
839 SkDebugf("Missing resource '%s'\n", path); 889 SkDebugf("Missing resource '%s'\n", path);
840 return; 890 return;
841 } 891 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // Now test an image which is too big. Any image with a larger header (i.e. 954 // Now test an image which is too big. Any image with a larger header (i.e.
905 // has bigger width/height) is also too big. 955 // has bigger width/height) is also too big.
906 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header 956 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header
907 0x84, 0x80, 0x00, // W: 65536 957 0x84, 0x80, 0x00, // W: 65536
908 0x84, 0x80, 0x00 }; // H: 65536 958 0x84, 0x80, 0x00 }; // H: 65536
909 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); 959 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
910 codec.reset(SkCodec::NewFromStream(stream.detach())); 960 codec.reset(SkCodec::NewFromStream(stream.detach()));
911 961
912 REPORTER_ASSERT(r, !codec); 962 REPORTER_ASSERT(r, !codec);
913 } 963 }
OLDNEW
« no previous file with comments | « src/codec/SkRawCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698