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/SerializationTest.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 2013 Google Inc. 2 * Copyright 2013 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 "SkAnnotationKeys.h" 9 #include "SkAnnotationKeys.h"
10 #include "SkBitmapProcShader.h" 10 #include "SkBitmapProcShader.h"
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 static sk_sp<SkPicture> copy_picture_via_serialization(SkPicture* src) { 627 static sk_sp<SkPicture> copy_picture_via_serialization(SkPicture* src) {
628 SkDynamicMemoryWStream wstream; 628 SkDynamicMemoryWStream wstream;
629 src->serialize(&wstream); 629 src->serialize(&wstream);
630 SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream()); 630 SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream());
631 return SkPicture::MakeFromStream(rstream); 631 return SkPicture::MakeFromStream(rstream);
632 } 632 }
633 633
634 struct AnnotationRec { 634 struct AnnotationRec {
635 const SkRect fRect; 635 const SkRect fRect;
636 const char* fKey; 636 const char* fKey;
637 SkData* fValue; 637 sk_sp<SkData> fValue;
638 }; 638 };
639 639
640 class TestAnnotationCanvas : public SkCanvas { 640 class TestAnnotationCanvas : public SkCanvas {
641 skiatest::Reporter* fReporter; 641 skiatest::Reporter* fReporter;
642 const AnnotationRec* fRec; 642 const AnnotationRec* fRec;
643 int fCount; 643 int fCount;
644 int fCurrIndex; 644 int fCurrIndex;
645 645
646 public: 646 public:
647 TestAnnotationCanvas(skiatest::Reporter* reporter, const AnnotationRec rec[] , int count) 647 TestAnnotationCanvas(skiatest::Reporter* reporter, const AnnotationRec rec[] , int count)
648 : SkCanvas(100, 100) 648 : SkCanvas(100, 100)
649 , fReporter(reporter) 649 , fReporter(reporter)
650 , fRec(rec) 650 , fRec(rec)
651 , fCount(count) 651 , fCount(count)
652 , fCurrIndex(0) 652 , fCurrIndex(0)
653 {} 653 {}
654 654
655 ~TestAnnotationCanvas() { 655 ~TestAnnotationCanvas() {
656 REPORTER_ASSERT(fReporter, fCount == fCurrIndex); 656 REPORTER_ASSERT(fReporter, fCount == fCurrIndex);
657 } 657 }
658 658
659 protected: 659 protected:
660 void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { 660 void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
661 REPORTER_ASSERT(fReporter, fCurrIndex < fCount); 661 REPORTER_ASSERT(fReporter, fCurrIndex < fCount);
662 REPORTER_ASSERT(fReporter, rect == fRec[fCurrIndex].fRect); 662 REPORTER_ASSERT(fReporter, rect == fRec[fCurrIndex].fRect);
663 REPORTER_ASSERT(fReporter, !strcmp(key, fRec[fCurrIndex].fKey)); 663 REPORTER_ASSERT(fReporter, !strcmp(key, fRec[fCurrIndex].fKey));
664 REPORTER_ASSERT(fReporter, value->equals(fRec[fCurrIndex].fValue)); 664 REPORTER_ASSERT(fReporter, value->equals(fRec[fCurrIndex].fValue.get())) ;
665 fCurrIndex += 1; 665 fCurrIndex += 1;
666 } 666 }
667 }; 667 };
668 668
669 /* 669 /*
670 * Test the 3 annotation types by recording them into a picture, serializing, a nd then playing 670 * Test the 3 annotation types by recording them into a picture, serializing, a nd then playing
671 * them back into another canvas. 671 * them back into another canvas.
672 */ 672 */
673 DEF_TEST(Annotations, reporter) { 673 DEF_TEST(Annotations, reporter) {
674 SkPictureRecorder recorder; 674 SkPictureRecorder recorder;
675 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100) ); 675 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100) );
676 676
677 const char* str0 = "rect-with-url"; 677 const char* str0 = "rect-with-url";
678 const SkRect r0 = SkRect::MakeWH(10, 10); 678 const SkRect r0 = SkRect::MakeWH(10, 10);
679 SkAutoTUnref<SkData> d0(SkData::NewWithCString(str0)); 679 sk_sp<SkData> d0(SkData::MakeWithCString(str0));
680 SkAnnotateRectWithURL(recordingCanvas, r0, d0); 680 SkAnnotateRectWithURL(recordingCanvas, r0, d0.get());
681 681
682 const char* str1 = "named-destination"; 682 const char* str1 = "named-destination";
683 const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point 683 const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point
684 SkAutoTUnref<SkData> d1(SkData::NewWithCString(str1)); 684 sk_sp<SkData> d1(SkData::MakeWithCString(str1));
685 SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1); 685 SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1.get());
686 686
687 const char* str2 = "link-to-destination"; 687 const char* str2 = "link-to-destination";
688 const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6); 688 const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6);
689 SkAutoTUnref<SkData> d2(SkData::NewWithCString(str2)); 689 sk_sp<SkData> d2(SkData::MakeWithCString(str2));
690 SkAnnotateLinkToDestination(recordingCanvas, r2, d2); 690 SkAnnotateLinkToDestination(recordingCanvas, r2, d2.get());
691 691
692 const AnnotationRec recs[] = { 692 const AnnotationRec recs[] = {
693 { r0, SkAnnotationKeys::URL_Key(), d0 }, 693 { r0, SkAnnotationKeys::URL_Key(), std::move(d0) },
694 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, 694 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), std::move(d1) },
695 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, 695 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), std::move(d2) },
696 }; 696 };
697 697
698 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); 698 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture());
699 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); 699 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get()));
700 700
701 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); 701 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs));
702 canvas.drawPicture(pict1); 702 canvas.drawPicture(pict1);
703 } 703 }
OLDNEW
« include/core/SkData.h ('K') | « tests/ResourceCacheTest.cpp ('k') | tests/StreamTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698