OLD | NEW |
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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkDashPathEffect.h" |
11 #include "SkData.h" | 12 #include "SkData.h" |
12 #include "SkDecodingImageGenerator.h" | 13 #include "SkDecodingImageGenerator.h" |
13 #include "SkError.h" | 14 #include "SkError.h" |
14 #include "SkImageEncoder.h" | 15 #include "SkImageEncoder.h" |
15 #include "SkImageGenerator.h" | 16 #include "SkImageGenerator.h" |
16 #include "SkPaint.h" | 17 #include "SkPaint.h" |
17 #include "SkPicture.h" | 18 #include "SkPicture.h" |
18 #include "SkPictureRecorder.h" | 19 #include "SkPictureRecorder.h" |
19 #include "SkPictureUtils.h" | 20 #include "SkPictureUtils.h" |
20 #include "SkRRect.h" | 21 #include "SkRRect.h" |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 canvas->restore(); | 688 canvas->restore(); |
688 } else if (unit <= 0.9) { | 689 } else if (unit <= 0.9) { |
689 // SkDebugf("clip\n"); | 690 // SkDebugf("clip\n"); |
690 canvas->clipRect(rect); | 691 canvas->clipRect(rect); |
691 } else { | 692 } else { |
692 // SkDebugf("draw\n"); | 693 // SkDebugf("draw\n"); |
693 canvas->drawPaint(paint); | 694 canvas->drawPaint(paint); |
694 } | 695 } |
695 } | 696 } |
696 | 697 |
| 698 static void test_gpu_veto(skiatest::Reporter* reporter) { |
| 699 |
| 700 SkPictureRecorder recorder; |
| 701 |
| 702 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); |
| 703 { |
| 704 SkPath path; |
| 705 path.moveTo(0, 0); |
| 706 path.lineTo(50, 50); |
| 707 |
| 708 SkScalar intervals[] = { 1.0f, 1.0f }; |
| 709 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals,
2, 0)); |
| 710 |
| 711 SkPaint paint; |
| 712 paint.setStyle(SkPaint::kStroke_Style); |
| 713 paint.setPathEffect(dash); |
| 714 |
| 715 canvas->drawPath(path, paint); |
| 716 } |
| 717 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 718 // path effects currently render an SkPicture undesireable for GPU rendering |
| 719 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); |
| 720 |
| 721 canvas = recorder.beginRecording(100, 100, NULL, 0); |
| 722 { |
| 723 SkPath path; |
| 724 |
| 725 path.moveTo(0, 0); |
| 726 path.lineTo(0, 50); |
| 727 path.lineTo(25, 25); |
| 728 path.lineTo(50, 50); |
| 729 path.lineTo(50, 0); |
| 730 path.close(); |
| 731 REPORTER_ASSERT(reporter, !path.isConvex()); |
| 732 |
| 733 SkPaint paint; |
| 734 paint.setAntiAlias(true); |
| 735 for (int i = 0; i < 50; ++i) { |
| 736 canvas->drawPath(path, paint); |
| 737 } |
| 738 } |
| 739 picture.reset(recorder.endRecording()); |
| 740 // A lot of AA concave paths currently render an SkPicture undesireable for
GPU rendering |
| 741 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); |
| 742 |
| 743 canvas = recorder.beginRecording(100, 100, NULL, 0); |
| 744 { |
| 745 SkPath path; |
| 746 |
| 747 path.moveTo(0, 0); |
| 748 path.lineTo(0, 50); |
| 749 path.lineTo(25, 25); |
| 750 path.lineTo(50, 50); |
| 751 path.lineTo(50, 0); |
| 752 path.close(); |
| 753 REPORTER_ASSERT(reporter, !path.isConvex()); |
| 754 |
| 755 SkPaint paint; |
| 756 paint.setAntiAlias(true); |
| 757 paint.setStyle(SkPaint::kStroke_Style); |
| 758 paint.setStrokeWidth(0); |
| 759 for (int i = 0; i < 50; ++i) { |
| 760 canvas->drawPath(path, paint); |
| 761 } |
| 762 } |
| 763 picture.reset(recorder.endRecording()); |
| 764 // hairline stroked AA concave paths are fine for GPU rendering |
| 765 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); |
| 766 } |
| 767 |
697 static void set_canvas_to_save_count_4(SkCanvas* canvas) { | 768 static void set_canvas_to_save_count_4(SkCanvas* canvas) { |
698 canvas->restoreToCount(1); | 769 canvas->restoreToCount(1); |
699 canvas->save(); | 770 canvas->save(); |
700 canvas->save(); | 771 canvas->save(); |
701 canvas->save(); | 772 canvas->save(); |
702 } | 773 } |
703 | 774 |
704 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { | 775 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { |
705 SkCanvas testCanvas(100, 100); | 776 SkCanvas testCanvas(100, 100); |
706 set_canvas_to_save_count_4(&testCanvas); | 777 set_canvas_to_save_count_4(&testCanvas); |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 | 1261 |
1191 DEF_TEST(Picture, reporter) { | 1262 DEF_TEST(Picture, reporter) { |
1192 #ifdef SK_DEBUG | 1263 #ifdef SK_DEBUG |
1193 test_deleting_empty_playback(); | 1264 test_deleting_empty_playback(); |
1194 test_serializing_empty_picture(); | 1265 test_serializing_empty_picture(); |
1195 #else | 1266 #else |
1196 test_bad_bitmap(); | 1267 test_bad_bitmap(); |
1197 #endif | 1268 #endif |
1198 test_unbalanced_save_restores(reporter); | 1269 test_unbalanced_save_restores(reporter); |
1199 test_peephole(); | 1270 test_peephole(); |
| 1271 test_gpu_veto(reporter); |
1200 test_gatherpixelrefs(reporter); | 1272 test_gatherpixelrefs(reporter); |
1201 test_gatherpixelrefsandrects(reporter); | 1273 test_gatherpixelrefsandrects(reporter); |
1202 test_bitmap_with_encoded_data(reporter); | 1274 test_bitmap_with_encoded_data(reporter); |
1203 test_clone_empty(reporter); | 1275 test_clone_empty(reporter); |
1204 test_draw_empty(reporter); | 1276 test_draw_empty(reporter); |
1205 test_clip_bound_opt(reporter); | 1277 test_clip_bound_opt(reporter); |
1206 test_clip_expansion(reporter); | 1278 test_clip_expansion(reporter); |
1207 test_hierarchical(reporter); | 1279 test_hierarchical(reporter); |
1208 test_gen_id(reporter); | 1280 test_gen_id(reporter); |
1209 } | 1281 } |
(...skipping 24 matching lines...) Expand all Loading... |
1234 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1306 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1235 } | 1307 } |
1236 | 1308 |
1237 DEF_TEST(Canvas_EmptyBitmap, r) { | 1309 DEF_TEST(Canvas_EmptyBitmap, r) { |
1238 SkBitmap dst; | 1310 SkBitmap dst; |
1239 dst.allocN32Pixels(10, 10); | 1311 dst.allocN32Pixels(10, 10); |
1240 SkCanvas canvas(dst); | 1312 SkCanvas canvas(dst); |
1241 | 1313 |
1242 test_draw_bitmaps(&canvas); | 1314 test_draw_bitmaps(&canvas); |
1243 } | 1315 } |
OLD | NEW |