OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (mask & SkMatrix::kPerspective_Mask) { | 75 if (mask & SkMatrix::kPerspective_Mask) { |
76 mat->setPerspX(rand.nextSScalar1()); | 76 mat->setPerspX(rand.nextSScalar1()); |
77 mat->setPerspY(rand.nextSScalar1()); | 77 mat->setPerspY(rand.nextSScalar1()); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 static void rand_size(SkISize* size, SkRandom& rand) { | 81 static void rand_size(SkISize* size, SkRandom& rand) { |
82 size->set(rand.nextU() & 0xFFFF, rand.nextU() & 0xFFFF); | 82 size->set(rand.nextU() & 0xFFFF, rand.nextU() & 0xFFFF); |
83 } | 83 } |
84 | 84 |
| 85 static bool treat_as_sprite(const SkMatrix& mat, const SkISize& size, |
| 86 unsigned bits) { |
| 87 return SkTreatAsSprite(mat, size.width(), size.height(), bits); |
| 88 } |
| 89 |
85 static void test_treatAsSprite(skiatest::Reporter* reporter) { | 90 static void test_treatAsSprite(skiatest::Reporter* reporter) { |
| 91 const unsigned bilerBits = kSkSubPixelBitsForBilerp; |
86 | 92 |
87 SkMatrix mat; | 93 SkMatrix mat; |
88 SkISize size; | 94 SkISize size; |
89 SkRandom rand; | 95 SkRandom rand; |
90 | 96 |
91 SkPaint noaaPaint; | 97 // assert: translate-only no-filter can always be treated as sprite |
92 SkPaint aaPaint; | |
93 aaPaint.setAntiAlias(true); | |
94 | |
95 // assert: translate-only no-aa can always be treated as sprite | |
96 for (int i = 0; i < 1000; ++i) { | 98 for (int i = 0; i < 1000; ++i) { |
97 rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask); | 99 rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask); |
98 for (int j = 0; j < 1000; ++j) { | 100 for (int j = 0; j < 1000; ++j) { |
99 rand_size(&size, rand); | 101 rand_size(&size, rand); |
100 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint)); | 102 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, 0)); |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 // assert: rotate/perspect is never treated as sprite | 106 // assert: rotate/perspect is never treated as sprite |
105 for (int i = 0; i < 1000; ++i) { | 107 for (int i = 0; i < 1000; ++i) { |
106 rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_
Mask); | 108 rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_
Mask); |
107 for (int j = 0; j < 1000; ++j) { | 109 for (int j = 0; j < 1000; ++j) { |
108 rand_size(&size, rand); | 110 rand_size(&size, rand); |
109 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint)); | 111 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, 0)); |
110 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); | 112 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
111 } | 113 } |
112 } | 114 } |
113 | 115 |
114 size.set(500, 600); | 116 size.set(500, 600); |
115 | 117 |
116 const SkScalar tooMuchSubpixel = 100.1f; | 118 const SkScalar tooMuchSubpixel = 100.1f; |
117 mat.setTranslate(tooMuchSubpixel, 0); | 119 mat.setTranslate(tooMuchSubpixel, 0); |
118 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); | 120 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
119 mat.setTranslate(0, tooMuchSubpixel); | 121 mat.setTranslate(0, tooMuchSubpixel); |
120 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); | 122 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
121 | 123 |
122 const SkScalar tinySubPixel = 100.02f; | 124 const SkScalar tinySubPixel = 100.02f; |
123 mat.setTranslate(tinySubPixel, 0); | 125 mat.setTranslate(tinySubPixel, 0); |
124 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint)); | 126 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); |
125 mat.setTranslate(0, tinySubPixel); | 127 mat.setTranslate(0, tinySubPixel); |
126 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint)); | 128 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); |
127 | 129 |
128 const SkScalar twoThirds = SK_Scalar1 * 2 / 3; | 130 const SkScalar twoThirds = SK_Scalar1 * 2 / 3; |
129 const SkScalar bigScale = (size.width() + twoThirds) / size.width(); | 131 const SkScalar bigScale = (size.width() + twoThirds) / size.width(); |
130 mat.setScale(bigScale, bigScale); | 132 mat.setScale(bigScale, bigScale); |
131 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint)); | 133 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false)); |
132 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); | 134 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
133 | 135 |
134 const SkScalar oneThird = SK_Scalar1 / 3; | 136 const SkScalar oneThird = SK_Scalar1 / 3; |
135 const SkScalar smallScale = (size.width() + oneThird) / size.width(); | 137 const SkScalar smallScale = (size.width() + oneThird) / size.width(); |
136 mat.setScale(smallScale, smallScale); | 138 mat.setScale(smallScale, smallScale); |
137 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint)); | 139 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); |
138 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); | 140 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); |
139 | 141 |
140 const SkScalar oneFortyth = SK_Scalar1 / 40; | 142 const SkScalar oneFortyth = SK_Scalar1 / 40; |
141 const SkScalar tinyScale = (size.width() + oneFortyth) / size.width(); | 143 const SkScalar tinyScale = (size.width() + oneFortyth) / size.width(); |
142 mat.setScale(tinyScale, tinyScale); | 144 mat.setScale(tinyScale, tinyScale); |
143 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint)); | 145 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); |
144 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint)); | 146 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); |
145 } | 147 } |
146 | 148 |
147 static void assert_ifDrawnTo(skiatest::Reporter* reporter, | 149 static void assert_ifDrawnTo(skiatest::Reporter* reporter, |
148 const SkBitmap& bm, bool shouldBeDrawn) { | 150 const SkBitmap& bm, bool shouldBeDrawn) { |
149 for (int y = 0; y < bm.height(); ++y) { | 151 for (int y = 0; y < bm.height(); ++y) { |
150 for (int x = 0; x < bm.width(); ++x) { | 152 for (int x = 0; x < bm.width(); ++x) { |
151 if (shouldBeDrawn) { | 153 if (shouldBeDrawn) { |
152 if (SK_ColorTRANSPARENT == *bm.getAddr32(x, y)) { | 154 if (SK_ColorTRANSPARENT == *bm.getAddr32(x, y)) { |
153 REPORTER_ASSERT(reporter, false); | 155 REPORTER_ASSERT(reporter, false); |
154 return; | 156 return; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 307 |
306 // ensure that we draw nothing if srcR does not intersect the bitmap | 308 // ensure that we draw nothing if srcR does not intersect the bitmap |
307 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); | 309 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); |
308 | 310 |
309 test_nan_antihair(); | 311 test_nan_antihair(); |
310 test_giantrepeat_crbug118018(reporter); | 312 test_giantrepeat_crbug118018(reporter); |
311 | 313 |
312 test_treatAsSprite(reporter); | 314 test_treatAsSprite(reporter); |
313 test_faulty_pixelref(reporter); | 315 test_faulty_pixelref(reporter); |
314 } | 316 } |
OLD | NEW |