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

Side by Side Diff: tests/PictureTest.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 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 "SkBigPicture.h" 8 #include "SkBigPicture.h"
9 #include "SkBBoxHierarchy.h" 9 #include "SkBBoxHierarchy.h"
10 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 SkPictureRecorder recorder; 614 SkPictureRecorder recorder;
615 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); 615 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100);
616 recordingCanvas->drawBitmap(bm, 0, 0); 616 recordingCanvas->drawBitmap(bm, 0, 0);
617 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); 617 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
618 618
619 SkCanvas canvas; 619 SkCanvas canvas;
620 canvas.drawPicture(picture); 620 canvas.drawPicture(picture);
621 } 621 }
622 #endif 622 #endif
623 623
624 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { 624 static sk_sp<SkData> serialized_picture_from_bitmap(const SkBitmap& bitmap) {
625 SkPictureRecorder recorder; 625 SkPictureRecorder recorder;
626 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), 626 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
627 SkIntToScalar(bitmap.height())); 627 SkIntToScalar(bitmap.height()));
628 canvas->drawBitmap(bitmap, 0, 0); 628 canvas->drawBitmap(bitmap, 0, 0);
629 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); 629 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
630 630
631 SkDynamicMemoryWStream wStream; 631 SkDynamicMemoryWStream wStream;
632 SkAutoTUnref<SkPixelSerializer> serializer( 632 SkAutoTUnref<SkPixelSerializer> serializer(
633 SkImageEncoder::CreatePixelSerializer()); 633 SkImageEncoder::CreatePixelSerializer());
634 picture->serialize(&wStream, serializer); 634 picture->serialize(&wStream, serializer);
635 return wStream.copyToData(); 635 return sk_sp<SkData>(wStream.copyToData());
636 } 636 }
637 637
638 struct ErrorContext { 638 struct ErrorContext {
639 int fErrors; 639 int fErrors;
640 skiatest::Reporter* fReporter; 640 skiatest::Reporter* fReporter;
641 }; 641 };
642 642
643 static void assert_one_parse_error_cb(SkError error, void* context) { 643 static void assert_one_parse_error_cb(SkError error, void* context) {
644 ErrorContext* errorContext = static_cast<ErrorContext*>(context); 644 ErrorContext* errorContext = static_cast<ErrorContext*>(context);
645 errorContext->fErrors++; 645 errorContext->fErrors++;
(...skipping 17 matching lines...) Expand all
663 } 663 }
664 664
665 DEF_TEST(Picture_EncodedData, reporter) { 665 DEF_TEST(Picture_EncodedData, reporter) {
666 // Create a bitmap that will be encoded. 666 // Create a bitmap that will be encoded.
667 SkBitmap original; 667 SkBitmap original;
668 make_bm(&original, 100, 100, SK_ColorBLUE, true); 668 make_bm(&original, 100, 100, SK_ColorBLUE, true);
669 SkDynamicMemoryWStream wStream; 669 SkDynamicMemoryWStream wStream;
670 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T ype, 100)) { 670 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T ype, 100)) {
671 return; 671 return;
672 } 672 }
673 SkAutoDataUnref data(wStream.copyToData()); 673 sk_sp<SkData> data(wStream.copyToData());
674 674
675 SkBitmap bm; 675 SkBitmap bm;
676 bool installSuccess = SkDEPRECATED_InstallDiscardablePixelRef(data, &bm); 676 bool installSuccess = SkDEPRECATED_InstallDiscardablePixelRef(data.get(), &b m);
677 REPORTER_ASSERT(reporter, installSuccess); 677 REPORTER_ASSERT(reporter, installSuccess);
678 678
679 // Write both bitmaps to pictures, and ensure that the resulting data stream s are the same. 679 // Write both bitmaps to pictures, and ensure that the resulting data stream s are the same.
680 // Flattening original will follow the old path of performing an encode, whi le flattening bm 680 // Flattening original will follow the old path of performing an encode, whi le flattening bm
681 // will use the already encoded data. 681 // will use the already encoded data.
682 SkAutoDataUnref picture1(serialized_picture_from_bitmap(original)); 682 sk_sp<SkData> picture1(serialized_picture_from_bitmap(original));
683 SkAutoDataUnref picture2(serialized_picture_from_bitmap(bm)); 683 sk_sp<SkData> picture2(serialized_picture_from_bitmap(bm));
684 REPORTER_ASSERT(reporter, picture1->equals(picture2)); 684 REPORTER_ASSERT(reporter, picture1->equals(picture2.get()));
685 685
686 // Now test that a parse error was generated when trying to create a new SkP icture without 686 // Now test that a parse error was generated when trying to create a new SkP icture without
687 // providing a function to decode the bitmap. 687 // providing a function to decode the bitmap.
688 ErrorContext context; 688 ErrorContext context;
689 context.fErrors = 0; 689 context.fErrors = 0;
690 context.fReporter = reporter; 690 context.fReporter = reporter;
691 SkSetErrorCallback(assert_one_parse_error_cb, &context); 691 SkSetErrorCallback(assert_one_parse_error_cb, &context);
692 SkMemoryStream pictureStream(picture1); 692 SkMemoryStream pictureStream(std::move(picture1));
693 SkClearLastError(); 693 SkClearLastError();
694 sk_sp<SkPicture> pictureFromStream(SkPicture::MakeFromStream(&pictureStream, nullptr)); 694 sk_sp<SkPicture> pictureFromStream(SkPicture::MakeFromStream(&pictureStream, nullptr));
695 REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr); 695 REPORTER_ASSERT(reporter, pictureFromStream.get() != nullptr);
696 SkClearLastError(); 696 SkClearLastError();
697 SkSetErrorCallback(nullptr, nullptr); 697 SkSetErrorCallback(nullptr, nullptr);
698 698
699 // Test that using the version of CreateFromStream that just takes a stream also decodes the 699 // Test that using the version of CreateFromStream that just takes a stream also decodes the
700 // bitmap. Drawing this picture should look exactly like the original bitmap . 700 // bitmap. Drawing this picture should look exactly like the original bitmap .
701 SkMD5::Digest referenceDigest; 701 SkMD5::Digest referenceDigest;
702 md5(original, &referenceDigest); 702 md5(original, &referenceDigest);
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 SkPictureRecorder rec; 1305 SkPictureRecorder rec;
1306 proc(rec.beginRecording(cull)); 1306 proc(rec.beginRecording(cull));
1307 sk_sp<SkDrawable> dr = rec.finishRecordingAsDrawable( 1307 sk_sp<SkDrawable> dr = rec.finishRecordingAsDrawable(
1308 SkPictureRecorder::kReturnNullF orEmpty_FinishFlag); 1308 SkPictureRecorder::kReturnNullF orEmpty_FinishFlag);
1309 REPORTER_ASSERT(r, !dr.get()); 1309 REPORTER_ASSERT(r, !dr.get());
1310 } 1310 }
1311 } 1311 }
1312 } 1312 }
1313 #endif 1313 #endif
1314 1314
OLDNEW
« include/core/SkData.h ('K') | « tests/PathTest.cpp ('k') | tests/ResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698