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

Side by Side Diff: tests/CodecTest.cpp

Issue 2206633004: Move off SK_SUPPORT_LEGACY_DATA_FACTORIES. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Gotta catch 'em all. Created 4 years, 4 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
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 SkAutoTDelete<SkStream> stream(resource(path)); 201 SkAutoTDelete<SkStream> stream(resource(path));
202 if (!stream) { 202 if (!stream) {
203 SkDebugf("Missing resource '%s'\n", path); 203 SkDebugf("Missing resource '%s'\n", path);
204 return; 204 return;
205 } 205 }
206 206
207 SkAutoTDelete<SkCodec> codec(nullptr); 207 SkAutoTDelete<SkCodec> codec(nullptr);
208 bool isIncomplete = supportsIncomplete; 208 bool isIncomplete = supportsIncomplete;
209 if (isIncomplete) { 209 if (isIncomplete) {
210 size_t size = stream->getLength(); 210 size_t size = stream->getLength();
211 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3))) ; 211 sk_sp<SkData> data((SkData::MakeFromStream(stream, 2 * size / 3)));
212 codec.reset(SkCodec::NewFromData(data)); 212 codec.reset(SkCodec::NewFromData(data.get()));
213 } else { 213 } else {
214 codec.reset(SkCodec::NewFromStream(stream.release())); 214 codec.reset(SkCodec::NewFromStream(stream.release()));
215 } 215 }
216 if (!codec) { 216 if (!codec) {
217 ERRORF(r, "Unable to decode '%s'", path); 217 ERRORF(r, "Unable to decode '%s'", path);
218 return; 218 return;
219 } 219 }
220 220
221 // Test full image decodes with SkCodec 221 // Test full image decodes with SkCodec
222 SkMD5::Digest codecDigest; 222 SkMD5::Digest codecDigest;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 330
331 SkAutoTDelete<SkStream> stream(resource(path)); 331 SkAutoTDelete<SkStream> stream(resource(path));
332 if (!stream) { 332 if (!stream) {
333 SkDebugf("Missing resource '%s'\n", path); 333 SkDebugf("Missing resource '%s'\n", path);
334 return; 334 return;
335 } 335 }
336 336
337 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr); 337 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr);
338 if (isIncomplete) { 338 if (isIncomplete) {
339 size_t size = stream->getLength(); 339 size_t size = stream->getLength();
340 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3))); 340 sk_sp<SkData> data((SkData::MakeFromStream(stream, 2 * size / 3)));
341 androidCodec.reset(SkAndroidCodec::NewFromData(data)); 341 androidCodec.reset(SkAndroidCodec::NewFromData(data.get()));
342 } else { 342 } else {
343 androidCodec.reset(SkAndroidCodec::NewFromStream(stream.release())); 343 androidCodec.reset(SkAndroidCodec::NewFromStream(stream.release()));
344 } 344 }
345 if (!androidCodec) { 345 if (!androidCodec) {
346 ERRORF(r, "Unable to decode '%s'", path); 346 ERRORF(r, "Unable to decode '%s'", path);
347 return; 347 return;
348 } 348 }
349 349
350 SkBitmap bm; 350 SkBitmap bm;
351 SkMD5::Digest androidCodecDigest; 351 SkMD5::Digest androidCodecDigest;
352 test_codec(r, androidCodec.get(), bm, info, size, expectedResult, &andro idCodecDigest, 352 test_codec(r, androidCodec.get(), bm, info, size, expectedResult, &andro idCodecDigest,
353 &codecDigest); 353 &codecDigest);
354 } 354 }
355 355
356 if (!isIncomplete) { 356 if (!isIncomplete) {
357 // Test SkCodecImageGenerator 357 // Test SkCodecImageGenerator
358 SkAutoTDelete<SkStream> stream(resource(path)); 358 SkAutoTDelete<SkStream> stream(resource(path));
359 SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getL ength())); 359 sk_sp<SkData> fullData(SkData::MakeFromStream(stream, stream->getLength( )));
360 SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncode dCodec(fullData)); 360 SkAutoTDelete<SkImageGenerator> gen(
361 SkCodecImageGenerator::NewFromEncodedCodec(fullData.get()));
361 SkBitmap bm; 362 SkBitmap bm;
362 bm.allocPixels(info); 363 bm.allocPixels(info);
363 SkAutoLockPixels autoLockPixels(bm); 364 SkAutoLockPixels autoLockPixels(bm);
364 REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes())); 365 REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes()));
365 compare_to_good_digest(r, codecDigest, bm); 366 compare_to_good_digest(r, codecDigest, bm);
366 367
367 // Test using SkFrontBufferedStream, as Android does 368 // Test using SkFrontBufferedStream, as Android does
368 SkStream* bufferedStream = SkFrontBufferedStream::Create(new SkMemoryStr eam(fullData), 369 SkStream* bufferedStream = SkFrontBufferedStream::Create(
369 SkCodec::MinBufferedBytesNeeded()); 370 new SkMemoryStream(std::move(fullData)), SkCodec::MinBufferedByt esNeeded());
370 REPORTER_ASSERT(r, bufferedStream); 371 REPORTER_ASSERT(r, bufferedStream);
371 codec.reset(SkCodec::NewFromStream(bufferedStream)); 372 codec.reset(SkCodec::NewFromStream(bufferedStream));
372 REPORTER_ASSERT(r, codec); 373 REPORTER_ASSERT(r, codec);
373 if (codec) { 374 if (codec) {
374 test_info(r, codec.get(), info, SkCodec::kSuccess, &codecDigest); 375 test_info(r, codec.get(), info, SkCodec::kSuccess, &codecDigest);
375 } 376 }
376 } 377 }
377 378
378 // If we've just tested incomplete decodes, let's run the same test again on full decodes. 379 // If we've just tested incomplete decodes, let's run the same test again on full decodes.
379 if (isIncomplete) { 380 if (isIncomplete) {
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 return false; 881 return false;
881 } 882 }
882 private: 883 private:
883 SkMemoryStream fStream; 884 SkMemoryStream fStream;
884 const size_t fLimit; 885 const size_t fLimit;
885 }; 886 };
886 887
887 // Stream that is not an asset stream (!hasPosition() or !hasLength()) 888 // Stream that is not an asset stream (!hasPosition() or !hasLength())
888 class NotAssetMemStream : public SkStream { 889 class NotAssetMemStream : public SkStream {
889 public: 890 public:
890 NotAssetMemStream(SkData* data) : fStream(data) {} 891 NotAssetMemStream(sk_sp<SkData> data) : fStream(std::move(data)) {}
891 892
892 bool hasPosition() const override { 893 bool hasPosition() const override {
893 return false; 894 return false;
894 } 895 }
895 896
896 bool hasLength() const override { 897 bool hasLength() const override {
897 return false; 898 return false;
898 } 899 }
899 900
900 size_t peek(void* buf, size_t bytes) const override { 901 size_t peek(void* buf, size_t bytes) const override {
(...skipping 12 matching lines...) Expand all
913 SkMemoryStream fStream; 914 SkMemoryStream fStream;
914 }; 915 };
915 916
916 // Disable RAW tests for Win32. 917 // Disable RAW tests for Win32.
917 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) 918 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
918 // Test that the RawCodec works also for not asset stream. This will test the co de path using 919 // Test that the RawCodec works also for not asset stream. This will test the co de path using
919 // SkRawBufferedStream instead of SkRawAssetStream. 920 // SkRawBufferedStream instead of SkRawAssetStream.
920 DEF_TEST(Codec_raw_notseekable, r) { 921 DEF_TEST(Codec_raw_notseekable, r) {
921 const char* path = "dng_with_preview.dng"; 922 const char* path = "dng_with_preview.dng";
922 SkString fullPath(GetResourcePath(path)); 923 SkString fullPath(GetResourcePath(path));
923 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str())); 924 sk_sp<SkData> data(SkData::MakeFromFileName(fullPath.c_str()));
924 if (!data) { 925 if (!data) {
925 SkDebugf("Missing resource '%s'\n", path); 926 SkDebugf("Missing resource '%s'\n", path);
926 return; 927 return;
927 } 928 }
928 929
929 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(da ta))); 930 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(st d::move(data))));
930 REPORTER_ASSERT(r, codec); 931 REPORTER_ASSERT(r, codec);
931 932
932 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 933 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
933 } 934 }
934 #endif 935 #endif
935 936
936 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read() 937 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read()
937 // + rewind() and succeed. 938 // + rewind() and succeed.
938 DEF_TEST(Codec_webp_peek, r) { 939 DEF_TEST(Codec_webp_peek, r) {
939 const char* path = "baby_tux.webp"; 940 const char* path = "baby_tux.webp";
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 // Perform a sampled decode. 1035 // Perform a sampled decode.
1035 SkAndroidCodec::AndroidOptions opts; 1036 SkAndroidCodec::AndroidOptions opts;
1036 opts.fSampleSize = 12; 1037 opts.fSampleSize = 12;
1037 codec->getAndroidPixels(codec->getInfo().makeWH(width / 12, height / 12), pi xelStorage.get(), 1038 codec->getAndroidPixels(codec->getInfo().makeWH(width / 12, height / 12), pi xelStorage.get(),
1038 rowBytes, &opts); 1039 rowBytes, &opts);
1039 1040
1040 // Rewind the codec and perform a full image decode. 1041 // Rewind the codec and perform a full image decode.
1041 SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get (), rowBytes); 1042 SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get (), rowBytes);
1042 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 1043 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
1043 } 1044 }
OLDNEW
« include/core/SkData.h ('K') | « tests/CodecPriv.h ('k') | tests/DataRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698