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

Side by Side Diff: tests/PictureTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698