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 "SkData.h" | 11 #include "SkData.h" |
12 #include "SkDecodingImageGenerator.h" | 12 #include "SkDecodingImageGenerator.h" |
13 #include "SkError.h" | 13 #include "SkError.h" |
14 #include "SkImageEncoder.h" | 14 #include "SkImageEncoder.h" |
15 #include "SkImageGenerator.h" | 15 #include "SkImageGenerator.h" |
16 #include "SkPaint.h" | 16 #include "SkPaint.h" |
17 #include "SkPicture.h" | 17 #include "SkPicture.h" |
18 #include "SkPictureUtils.h" | 18 #include "SkPictureUtils.h" |
| 19 #include "SkQuadTreePicture.h" |
19 #include "SkRRect.h" | 20 #include "SkRRect.h" |
20 #include "SkRandom.h" | 21 #include "SkRandom.h" |
21 #include "SkShader.h" | 22 #include "SkShader.h" |
22 #include "SkStream.h" | 23 #include "SkStream.h" |
| 24 #include "SkTileGrid.h" |
23 #include "Test.h" | 25 #include "Test.h" |
24 | 26 |
25 static const int gColorScale = 30; | 27 static const int gColorScale = 30; |
26 static const int gColorOffset = 60; | 28 static const int gColorOffset = 60; |
27 | 29 |
28 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { | 30 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { |
29 bm->allocN32Pixels(w, h); | 31 bm->allocN32Pixels(w, h); |
30 bm->eraseColor(color); | 32 bm->eraseColor(color); |
31 if (immutable) { | 33 if (immutable) { |
32 bm->setImmutable(); | 34 bm->setImmutable(); |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 { | 882 { |
881 // Test without call to endRecording | 883 // Test without call to endRecording |
882 SkPicture picture; | 884 SkPicture picture; |
883 picture.beginRecording(1, 1); | 885 picture.beginRecording(1, 1); |
884 SkPicture* destPicture = picture.clone(); | 886 SkPicture* destPicture = picture.clone(); |
885 REPORTER_ASSERT(reporter, NULL != destPicture); | 887 REPORTER_ASSERT(reporter, NULL != destPicture); |
886 destPicture->unref(); | 888 destPicture->unref(); |
887 } | 889 } |
888 } | 890 } |
889 | 891 |
| 892 static void test_draw_empty(skiatest::Reporter* reporter) { |
| 893 SkBitmap result; |
| 894 make_bm(&result, 2, 2, SK_ColorBLACK, false); |
| 895 |
| 896 SkCanvas canvas(result); |
| 897 |
| 898 { |
| 899 // stock SkPicture |
| 900 SkPicture picture; |
| 901 picture.beginRecording(1, 1); |
| 902 picture.endRecording(); |
| 903 |
| 904 canvas.drawPicture(picture); |
| 905 } |
| 906 |
| 907 { |
| 908 // tile grid |
| 909 SkTileGridPicture::TileGridInfo gridInfo; |
| 910 gridInfo.fMargin.setEmpty(); |
| 911 gridInfo.fOffset.setZero(); |
| 912 gridInfo.fTileInterval.set(1, 1); |
| 913 |
| 914 SkTileGridPicture picture(1, 1, gridInfo); |
| 915 picture.beginRecording(1, 1, SkPicture::kOptimizeForClippedPlayback_Reco
rdingFlag); |
| 916 picture.endRecording(); |
| 917 |
| 918 canvas.drawPicture(picture); |
| 919 } |
| 920 |
| 921 { |
| 922 // RTree |
| 923 SkPicture picture; |
| 924 picture.beginRecording(1, 1, SkPicture::kOptimizeForClippedPlayback_Reco
rdingFlag); |
| 925 picture.endRecording(); |
| 926 |
| 927 canvas.drawPicture(picture); |
| 928 } |
| 929 |
| 930 { |
| 931 // quad tree |
| 932 SkQuadTreePicture picture(SkIRect::MakeWH(1, 1)); |
| 933 picture.beginRecording(1, 1, SkPicture::kOptimizeForClippedPlayback_Reco
rdingFlag); |
| 934 picture.endRecording(); |
| 935 |
| 936 canvas.drawPicture(picture); |
| 937 } |
| 938 } |
| 939 |
890 static void test_clip_bound_opt(skiatest::Reporter* reporter) { | 940 static void test_clip_bound_opt(skiatest::Reporter* reporter) { |
891 // Test for crbug.com/229011 | 941 // Test for crbug.com/229011 |
892 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), | 942 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), |
893 SkIntToScalar(2), SkIntToScalar(2)); | 943 SkIntToScalar(2), SkIntToScalar(2)); |
894 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), | 944 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), |
895 SkIntToScalar(1), SkIntToScalar(1)); | 945 SkIntToScalar(1), SkIntToScalar(1)); |
896 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), | 946 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), |
897 SkIntToScalar(1), SkIntToScalar(1)); | 947 SkIntToScalar(1), SkIntToScalar(1)); |
898 | 948 |
899 SkPath invPath; | 949 SkPath invPath; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 test_serializing_empty_picture(); | 1148 test_serializing_empty_picture(); |
1099 #else | 1149 #else |
1100 test_bad_bitmap(); | 1150 test_bad_bitmap(); |
1101 #endif | 1151 #endif |
1102 test_unbalanced_save_restores(reporter); | 1152 test_unbalanced_save_restores(reporter); |
1103 test_peephole(); | 1153 test_peephole(); |
1104 test_gatherpixelrefs(reporter); | 1154 test_gatherpixelrefs(reporter); |
1105 test_gatherpixelrefsandrects(reporter); | 1155 test_gatherpixelrefsandrects(reporter); |
1106 test_bitmap_with_encoded_data(reporter); | 1156 test_bitmap_with_encoded_data(reporter); |
1107 test_clone_empty(reporter); | 1157 test_clone_empty(reporter); |
| 1158 test_draw_empty(reporter); |
1108 test_clip_bound_opt(reporter); | 1159 test_clip_bound_opt(reporter); |
1109 test_clip_expansion(reporter); | 1160 test_clip_expansion(reporter); |
1110 test_hierarchical(reporter); | 1161 test_hierarchical(reporter); |
1111 } | 1162 } |
1112 | 1163 |
1113 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { | 1164 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { |
1114 const SkPaint paint; | 1165 const SkPaint paint; |
1115 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; | 1166 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; |
1116 const SkIRect irect = { 2, 2, 3, 3 }; | 1167 const SkIRect irect = { 2, 2, 3, 3 }; |
1117 | 1168 |
(...skipping 18 matching lines...) Expand all Loading... |
1136 picture.endRecording(); | 1187 picture.endRecording(); |
1137 } | 1188 } |
1138 | 1189 |
1139 DEF_TEST(Canvas_EmptyBitmap, r) { | 1190 DEF_TEST(Canvas_EmptyBitmap, r) { |
1140 SkBitmap dst; | 1191 SkBitmap dst; |
1141 dst.allocN32Pixels(10, 10); | 1192 dst.allocN32Pixels(10, 10); |
1142 SkCanvas canvas(dst); | 1193 SkCanvas canvas(dst); |
1143 | 1194 |
1144 test_draw_bitmaps(&canvas); | 1195 test_draw_bitmaps(&canvas); |
1145 } | 1196 } |
OLD | NEW |