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

Side by Side Diff: skia/ext/vector_canvas_unittest.cc

Issue 11418217: Add skia::RefPtr class to wrap ref counted classes from Skia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Just skia/ Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if !defined(OS_WIN) 7 #if !defined(OS_WIN)
8 #include <unistd.h> 8 #include <unistd.h>
9 #endif 9 #endif
10 10
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 delete context_; 383 delete context_;
384 context_ = NULL; 384 context_ = NULL;
385 385
386 parent::TearDown(); 386 parent::TearDown();
387 } 387 }
388 388
389 void Init(int size) { 389 void Init(int size) {
390 size_ = size; 390 size_ = size;
391 context_ = new Context(); 391 context_ = new Context();
392 bitmap_ = new Bitmap(*context_, size_, size_); 392 bitmap_ = new Bitmap(*context_, size_, size_);
393 vcanvas_ = new VectorCanvas(VectorPlatformDeviceEmf::CreateDevice( 393 vcanvas_ = new VectorCanvas(skia::RefPtr<SkDevice>(
394 size_, size_, true, context_->context())); 394 VectorPlatformDeviceEmf::CreateDevice(
395 size_, size_, true, context_->context())));
395 pcanvas_ = CreatePlatformCanvas(size_, size_, false); 396 pcanvas_ = CreatePlatformCanvas(size_, size_, false);
396 397
397 // Clear white. 398 // Clear white.
398 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); 399 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
399 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); 400 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
400 } 401 }
401 402
402 // Compares both canvas and returns the pixel difference in percentage between 403 // Compares both canvas and returns the pixel difference in percentage between
403 // both images. 0 on success and ]0, 100] on failure. 404 // both images. 0 on success and ]0, 100] on failure.
404 double ProcessImage(const FilePath::StringType& filename) { 405 double ProcessImage(const FilePath::StringType& filename) {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 723
723 #if defined(OS_WIN) 724 #if defined(OS_WIN)
724 #define MAYBE_PathEffects DISABLED_PathEffects 725 #define MAYBE_PathEffects DISABLED_PathEffects
725 #else 726 #else
726 #define MAYBE_PathEffects PathEffects 727 #define MAYBE_PathEffects PathEffects
727 #endif 728 #endif
728 TEST_F(VectorCanvasTest, MAYBE_PathEffects) { 729 TEST_F(VectorCanvasTest, MAYBE_PathEffects) {
729 { 730 {
730 SkPaint paint; 731 SkPaint paint;
731 SkScalar intervals[] = { 1, 1 }; 732 SkScalar intervals[] = { 1, 1 };
732 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 733 skia::RefPtr<SkPathEffect> effect = new SkDashPathEffect(
Stephen White 2012/11/29 23:00:33 Shouldn't we be doing an AdoptRef here? How is th
Stephen White 2012/11/29 23:11:47 In fact, it doesn't compile (yay!). See win_rel u
danakj 2012/11/29 23:15:52 Yeh, fixing!
733 0); 734 intervals, arraysize(intervals), 0);
734 paint.setPathEffect(effect)->unref(); 735 paint.setPathEffect(effect.get());
735 paint.setColor(SK_ColorMAGENTA); 736 paint.setColor(SK_ColorMAGENTA);
736 paint.setStyle(SkPaint::kStroke_Style); 737 paint.setStyle(SkPaint::kStroke_Style);
737 738
738 vcanvas_->drawLine(10, 10, 90, 10, paint); 739 vcanvas_->drawLine(10, 10, 90, 10, paint);
739 pcanvas_->drawLine(10, 10, 90, 10, paint); 740 pcanvas_->drawLine(10, 10, 90, 10, paint);
740 } 741 }
741 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_line"))); 742 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_line")));
742 743
743 744
744 // Starting here, there is NO WAY to make them agree. At least verify that the 745 // Starting here, there is NO WAY to make them agree. At least verify that the
745 // output doesn't change across versions. This test is disabled. See bug 746 // output doesn't change across versions. This test is disabled. See bug
746 // 1060231. 747 // 1060231.
747 compare_canvas_ = false; 748 compare_canvas_ = false;
748 749
749 { 750 {
750 SkPaint paint; 751 SkPaint paint;
751 SkScalar intervals[] = { 3, 5 }; 752 SkScalar intervals[] = { 3, 5 };
752 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 753 skia::RefPtr<SkPathEffect> effect = new SkDashPathEffect(
Stephen White 2012/11/29 23:00:33 Same here.
753 0); 754 intervals, arraysize(intervals), 0);
754 paint.setPathEffect(effect)->unref(); 755 paint.setPathEffect(effect.get());
755 paint.setColor(SK_ColorMAGENTA); 756 paint.setColor(SK_ColorMAGENTA);
756 paint.setStyle(SkPaint::kStroke_Style); 757 paint.setStyle(SkPaint::kStroke_Style);
757 758
758 SkPath path; 759 SkPath path;
759 path.moveTo(10, 15); 760 path.moveTo(10, 15);
760 path.lineTo(90, 15); 761 path.lineTo(90, 15);
761 path.lineTo(90, 90); 762 path.lineTo(90, 90);
762 vcanvas_->drawPath(path, paint); 763 vcanvas_->drawPath(path, paint);
763 pcanvas_->drawPath(path, paint); 764 pcanvas_->drawPath(path, paint);
764 } 765 }
765 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_path"))); 766 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_path")));
766 767
767 { 768 {
768 SkPaint paint; 769 SkPaint paint;
769 SkScalar intervals[] = { 2, 1 }; 770 SkScalar intervals[] = { 2, 1 };
770 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 771 skia::RefPtr<SkPathEffect> effect = new SkDashPathEffect(
Stephen White 2012/11/29 23:00:33 Same here (and below).
danakj 2012/11/29 23:15:52 Done.
771 0); 772 intervals, arraysize(intervals), 0);
772 paint.setPathEffect(effect)->unref(); 773 paint.setPathEffect(effect.get());
773 paint.setColor(SK_ColorMAGENTA); 774 paint.setColor(SK_ColorMAGENTA);
774 paint.setStyle(SkPaint::kStroke_Style); 775 paint.setStyle(SkPaint::kStroke_Style);
775 776
776 vcanvas_->drawRectCoords(20, 20, 30, 30, paint); 777 vcanvas_->drawRectCoords(20, 20, 30, 30, paint);
777 pcanvas_->drawRectCoords(20, 20, 30, 30, paint); 778 pcanvas_->drawRectCoords(20, 20, 30, 30, paint);
778 } 779 }
779 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_rect"))); 780 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_rect")));
780 781
781 // This thing looks like it has been drawn by a 3 years old kid. I haven't 782 // This thing looks like it has been drawn by a 3 years old kid. I haven't
782 // filed a bug on this since I guess nobody is expecting this to look nice. 783 // filed a bug on this since I guess nobody is expecting this to look nice.
783 { 784 {
784 SkPaint paint; 785 SkPaint paint;
785 SkScalar intervals[] = { 1, 1 }; 786 SkScalar intervals[] = { 1, 1 };
786 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 787 skia::RefPtr<SkPathEffect> effect = new SkDashPathEffect(
787 0); 788 intervals, arraysize(intervals), 0);
788 paint.setPathEffect(effect)->unref(); 789 paint.setPathEffect(effect.get());
789 paint.setColor(SK_ColorMAGENTA); 790 paint.setColor(SK_ColorMAGENTA);
790 paint.setStyle(SkPaint::kStroke_Style); 791 paint.setStyle(SkPaint::kStroke_Style);
791 792
792 SkPath path; 793 SkPath path;
793 path.addCircle(50, 75, 10); 794 path.addCircle(50, 75, 10);
794 vcanvas_->drawPath(path, paint); 795 vcanvas_->drawPath(path, paint);
795 pcanvas_->drawPath(path, paint); 796 pcanvas_->drawPath(path, paint);
796 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("circle"))); 797 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("circle")));
797 } 798 }
798 } 799 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 pcanvas_->rotate(67); 960 pcanvas_->rotate(67);
960 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); 961 vcanvas_->drawBitmap(bitmap, 20, -50, NULL);
961 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); 962 pcanvas_->drawBitmap(bitmap, 20, -50, NULL);
962 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("rotate"))); 963 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("rotate")));
963 } 964 }
964 } 965 }
965 966
966 #endif // !defined(USE_AURA) 967 #endif // !defined(USE_AURA)
967 968
968 } // namespace skia 969 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698