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

Side by Side Diff: tests/PictureTest.cpp

Issue 1699183004: Make SkPicture/SkImageGenerator default to SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix rebase bug 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 | « tests/KtxTest.cpp ('k') | tools/LazyDecodeBitmap.h » ('j') | 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 2012 Google Inc. 2 * Copyright 2012 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 "SkBBoxHierarchy.h" 8 #include "SkBBoxHierarchy.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkColorMatrixFilter.h" 11 #include "SkColorMatrixFilter.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #include "SkDashPathEffect.h" 13 #include "SkDashPathEffect.h"
14 #include "SkData.h" 14 #include "SkData.h"
15 #include "SkImageGenerator.h" 15 #include "SkImageGenerator.h"
16 #include "SkError.h" 16 #include "SkError.h"
17 #include "SkImageEncoder.h" 17 #include "SkImageEncoder.h"
18 #include "SkImageGenerator.h" 18 #include "SkImageGenerator.h"
19 #include "SkLayerInfo.h" 19 #include "SkLayerInfo.h"
20 #include "SkMD5.h"
20 #include "SkPaint.h" 21 #include "SkPaint.h"
21 #include "SkPicture.h" 22 #include "SkPicture.h"
22 #include "SkPictureRecorder.h" 23 #include "SkPictureRecorder.h"
23 #include "SkPictureUtils.h" 24 #include "SkPictureUtils.h"
24 #include "SkPixelRef.h" 25 #include "SkPixelRef.h"
25 #include "SkPixelSerializer.h" 26 #include "SkPixelSerializer.h"
26 #include "SkMiniRecorder.h" 27 #include "SkMiniRecorder.h"
27 #include "SkRRect.h" 28 #include "SkRRect.h"
28 #include "SkRandom.h" 29 #include "SkRandom.h"
29 #include "SkRecord.h" 30 #include "SkRecord.h"
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 ErrorContext* errorContext = static_cast<ErrorContext*>(context); 865 ErrorContext* errorContext = static_cast<ErrorContext*>(context);
865 errorContext->fErrors++; 866 errorContext->fErrors++;
866 // This test only expects one error, and that is a kParseError. If there are others, 867 // This test only expects one error, and that is a kParseError. If there are others,
867 // there is some unknown problem. 868 // there is some unknown problem.
868 REPORTER_ASSERT_MESSAGE(errorContext->fReporter, 1 == errorContext->fErrors, 869 REPORTER_ASSERT_MESSAGE(errorContext->fReporter, 1 == errorContext->fErrors,
869 "This threw more errors than expected."); 870 "This threw more errors than expected.");
870 REPORTER_ASSERT_MESSAGE(errorContext->fReporter, kParseError_SkError == erro r, 871 REPORTER_ASSERT_MESSAGE(errorContext->fReporter, kParseError_SkError == erro r,
871 SkGetLastErrorString()); 872 SkGetLastErrorString());
872 } 873 }
873 874
874 static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) { 875 static void md5(const SkBitmap& bm, SkMD5::Digest* digest) {
876 SkAutoLockPixels autoLockPixels(bm);
877 SkASSERT(bm.getPixels());
878 SkMD5 md5;
879 size_t rowLen = bm.info().bytesPerPixel() * bm.width();
880 for (int y = 0; y < bm.height(); ++y) {
881 md5.update(static_cast<uint8_t*>(bm.getAddr(0, y)), rowLen);
882 }
883 md5.finish(*digest);
884 }
885
886 DEF_TEST(Picture_EncodedData, reporter) {
875 // Create a bitmap that will be encoded. 887 // Create a bitmap that will be encoded.
876 SkBitmap original; 888 SkBitmap original;
877 make_bm(&original, 100, 100, SK_ColorBLUE, true); 889 make_bm(&original, 100, 100, SK_ColorBLUE, true);
878 SkDynamicMemoryWStream wStream; 890 SkDynamicMemoryWStream wStream;
879 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T ype, 100)) { 891 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T ype, 100)) {
880 return; 892 return;
881 } 893 }
882 SkAutoDataUnref data(wStream.copyToData()); 894 SkAutoDataUnref data(wStream.copyToData());
883 895
884 SkBitmap bm; 896 SkBitmap bm;
885 bool installSuccess = SkDEPRECATED_InstallDiscardablePixelRef(data, &bm); 897 bool installSuccess = SkDEPRECATED_InstallDiscardablePixelRef(data, &bm);
886 REPORTER_ASSERT(reporter, installSuccess); 898 REPORTER_ASSERT(reporter, installSuccess);
887 899
888 // Write both bitmaps to pictures, and ensure that the resulting data stream s are the same. 900 // Write both bitmaps to pictures, and ensure that the resulting data stream s are the same.
889 // Flattening original will follow the old path of performing an encode, whi le flattening bm 901 // Flattening original will follow the old path of performing an encode, whi le flattening bm
890 // will use the already encoded data. 902 // will use the already encoded data.
891 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); 903 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original));
892 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); 904 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm));
893 REPORTER_ASSERT(reporter, picture1->equals(picture2)); 905 REPORTER_ASSERT(reporter, picture1->equals(picture2));
906
894 // Now test that a parse error was generated when trying to create a new SkP icture without 907 // Now test that a parse error was generated when trying to create a new SkP icture without
895 // providing a function to decode the bitmap. 908 // providing a function to decode the bitmap.
896 ErrorContext context; 909 ErrorContext context;
897 context.fErrors = 0; 910 context.fErrors = 0;
898 context.fReporter = reporter; 911 context.fReporter = reporter;
899 SkSetErrorCallback(assert_one_parse_error_cb, &context); 912 SkSetErrorCallback(assert_one_parse_error_cb, &context);
900 SkMemoryStream pictureStream(picture1); 913 SkMemoryStream pictureStream(picture1);
901 SkClearLastError(); 914 SkClearLastError();
902 SkAutoTUnref<SkPicture> pictureFromStream(SkPicture::CreateFromStream(&pictu reStream, nullptr)); 915 SkAutoTUnref<SkPicture> pictureFromStream(SkPicture::CreateFromStream(&pictu reStream, nullptr));
903 REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr); 916 REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr);
904 SkClearLastError(); 917 SkClearLastError();
905 SkSetErrorCallback(nullptr, nullptr); 918 SkSetErrorCallback(nullptr, nullptr);
919
920 // Test that using the version of CreateFromStream that just takes a stream also decodes the
921 // bitmap. Drawing this picture should look exactly like the original bitmap .
922 SkMD5::Digest referenceDigest;
923 md5(original, &referenceDigest);
924
925 SkBitmap dst;
926 dst.allocPixels(original.info());
927 dst.eraseColor(SK_ColorRED);
928 SkCanvas canvas(dst);
929
930 pictureStream.rewind();
931 pictureFromStream.reset(SkPicture::CreateFromStream(&pictureStream));
932 canvas.drawPicture(pictureFromStream.get());
933
934 SkMD5::Digest digest2;
935 md5(dst, &digest2);
936 REPORTER_ASSERT(reporter, referenceDigest == digest2);
906 } 937 }
907 938
908 static void test_clip_bound_opt(skiatest::Reporter* reporter) { 939 static void test_clip_bound_opt(skiatest::Reporter* reporter) {
909 // Test for crbug.com/229011 940 // Test for crbug.com/229011
910 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), 941 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4),
911 SkIntToScalar(2), SkIntToScalar(2)); 942 SkIntToScalar(2), SkIntToScalar(2));
912 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), 943 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7),
913 SkIntToScalar(1), SkIntToScalar(1)); 944 SkIntToScalar(1), SkIntToScalar(1));
914 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), 945 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6),
915 SkIntToScalar(1), SkIntToScalar(1)); 946 SkIntToScalar(1), SkIntToScalar(1));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 test_bad_bitmap(); 1198 test_bad_bitmap();
1168 #endif 1199 #endif
1169 test_unbalanced_save_restores(reporter); 1200 test_unbalanced_save_restores(reporter);
1170 test_peephole(); 1201 test_peephole();
1171 #if SK_SUPPORT_GPU 1202 #if SK_SUPPORT_GPU
1172 test_gpu_veto(reporter); 1203 test_gpu_veto(reporter);
1173 #endif 1204 #endif
1174 test_has_text(reporter); 1205 test_has_text(reporter);
1175 test_images_are_found_by_willPlayBackBitmaps(reporter); 1206 test_images_are_found_by_willPlayBackBitmaps(reporter);
1176 test_analysis(reporter); 1207 test_analysis(reporter);
1177 test_bitmap_with_encoded_data(reporter);
1178 test_clip_bound_opt(reporter); 1208 test_clip_bound_opt(reporter);
1179 test_clip_expansion(reporter); 1209 test_clip_expansion(reporter);
1180 test_hierarchical(reporter); 1210 test_hierarchical(reporter);
1181 test_gen_id(reporter); 1211 test_gen_id(reporter);
1182 test_savelayer_extraction(reporter); 1212 test_savelayer_extraction(reporter);
1183 test_cull_rect_reset(reporter); 1213 test_cull_rect_reset(reporter);
1184 } 1214 }
1185 1215
1186 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { 1216 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {
1187 const SkPaint paint; 1217 const SkPaint paint;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 1408
1379 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); 1409 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream());
1380 SkAutoTUnref<SkPicture> deserializedPicture(SkPicture::CreateFromStream(rstr eam)); 1410 SkAutoTUnref<SkPicture> deserializedPicture(SkPicture::CreateFromStream(rstr eam));
1381 1411
1382 REPORTER_ASSERT(r, SkToBool(deserializedPicture)); 1412 REPORTER_ASSERT(r, SkToBool(deserializedPicture));
1383 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); 1413 REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1);
1384 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2); 1414 REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2);
1385 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3); 1415 REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3);
1386 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4); 1416 REPORTER_ASSERT(r, deserializedPicture->cullRect().bottom() == 4);
1387 } 1417 }
OLDNEW
« no previous file with comments | « tests/KtxTest.cpp ('k') | tools/LazyDecodeBitmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698