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 "Test.h" | 8 #include "Test.h" |
9 #include "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel()); | 126 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel()); |
127 p1 = p0; | 127 p1 = p0; |
128 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel()); | 128 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel()); |
129 | 129 |
130 p0.reset(); | 130 p0.reset(); |
131 REPORTER_ASSERT(reporter, | 131 REPORTER_ASSERT(reporter, |
132 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); | 132 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 // Helper to test equality between paints when we know nothing has mutated. | |
137 class PaintEqualityHelper { | |
138 public: | |
139 static bool PaintEquals(const SkPaint& a, const SkPaint &b) { | |
mtklein
2013/08/05 18:18:14
I think we can ditch the class and just have a fre
| |
140 #ifdef SK_BUILD_FOR_ANDROID | |
141 return !memcmp(&a, &b, SK_OFFSETOF(SkPaint, fGenerationID)); | |
142 #else | |
143 return !memcmp(&a, &b, sizeof(a)); | |
144 #endif | |
145 } | |
146 | |
147 }; | |
148 | |
136 static void test_copy(skiatest::Reporter* reporter) { | 149 static void test_copy(skiatest::Reporter* reporter) { |
137 SkPaint paint; | 150 SkPaint paint; |
138 // set a few member variables | 151 // set a few member variables |
139 paint.setStyle(SkPaint::kStrokeAndFill_Style); | 152 paint.setStyle(SkPaint::kStrokeAndFill_Style); |
140 paint.setTextAlign(SkPaint::kLeft_Align); | 153 paint.setTextAlign(SkPaint::kLeft_Align); |
141 paint.setStrokeWidth(SkIntToScalar(2)); | 154 paint.setStrokeWidth(SkIntToScalar(2)); |
142 // set a few pointers | 155 // set a few pointers |
143 SkLayerDrawLooper* looper = new SkLayerDrawLooper(); | 156 SkLayerDrawLooper* looper = new SkLayerDrawLooper(); |
144 paint.setLooper(looper)->unref(); | 157 paint.setLooper(looper)->unref(); |
145 SkMaskFilter* mask = SkBlurMaskFilter::Create(1, SkBlurMaskFilter::kNormal_B lurStyle); | 158 SkMaskFilter* mask = SkBlurMaskFilter::Create(1, SkBlurMaskFilter::kNormal_B lurStyle); |
146 paint.setMaskFilter(mask)->unref(); | 159 paint.setMaskFilter(mask)->unref(); |
147 | 160 |
148 // copy the paint using the copy constructor and check they are the same | 161 // copy the paint using the copy constructor and check they are the same |
149 SkPaint copiedPaint = paint; | 162 SkPaint copiedPaint = paint; |
150 REPORTER_ASSERT(reporter, paint == copiedPaint); | 163 REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(paint, copiedPain t)); |
151 | 164 |
152 #ifdef SK_BUILD_FOR_ANDROID | 165 #ifdef SK_BUILD_FOR_ANDROID |
153 // the copy constructor should preserve the Generation ID | 166 // the copy constructor should preserve the Generation ID |
154 uint32_t paintGenID = paint.getGenerationID(); | 167 uint32_t paintGenID = paint.getGenerationID(); |
155 uint32_t copiedPaintGenID = copiedPaint.getGenerationID(); | 168 uint32_t copiedPaintGenID = copiedPaint.getGenerationID(); |
156 REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID); | 169 REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID); |
157 REPORTER_ASSERT(reporter, !memcmp(&paint, &copiedPaint, sizeof(paint))); | 170 REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(paint, copiedPain t)); |
158 #endif | 171 #endif |
159 | 172 |
160 // copy the paint using the equal operator and check they are the same | 173 // copy the paint using the equal operator and check they are the same |
161 copiedPaint = paint; | 174 copiedPaint = paint; |
162 REPORTER_ASSERT(reporter, paint == copiedPaint); | 175 REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(paint, copiedPain t)); |
163 | 176 |
164 #ifdef SK_BUILD_FOR_ANDROID | 177 #ifdef SK_BUILD_FOR_ANDROID |
165 // the equals operator should increment the Generation ID | 178 // the equals operator should increment the Generation ID |
166 REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID); | 179 REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID); |
167 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; | 180 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; |
168 copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value | 181 copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value |
169 REPORTER_ASSERT(reporter, memcmp(&paint, &copiedPaint, sizeof(paint))); | 182 REPORTER_ASSERT(reporter, memcmp(&paint, &copiedPaint, sizeof(paint))); |
170 #endif | 183 #endif |
171 | 184 |
172 // clean the paint and check they are back to their initial states | 185 // clean the paint and check they are back to their initial states |
173 SkPaint cleanPaint; | 186 SkPaint cleanPaint; |
174 paint.reset(); | 187 paint.reset(); |
175 copiedPaint.reset(); | 188 copiedPaint.reset(); |
176 REPORTER_ASSERT(reporter, cleanPaint == paint); | 189 REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(cleanPaint, paint )); |
177 REPORTER_ASSERT(reporter, cleanPaint == copiedPaint); | 190 REPORTER_ASSERT(reporter, PaintEqualityHelper::PaintEquals(cleanPaint, copie dPaint)); |
178 | 191 |
179 #ifdef SK_BUILD_FOR_ANDROID | 192 #ifdef SK_BUILD_FOR_ANDROID |
180 // the reset function should increment the Generation ID | 193 // the reset function should increment the Generation ID |
181 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID); | 194 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID); |
182 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; | 195 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; |
183 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &paint, sizeof(cleanPaint))); | 196 REPORTER_ASSERT(reporter, !PaintEqualityHelper::PaintEquals(cleanPaint, pain t)); |
184 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &copiedPaint, sizeof(cleanPain t))); | 197 REPORTER_ASSERT(reporter, !PaintEqualityHelper::PaintEquals(cleanPaint, copi edPaint)); |
185 #endif | 198 #endif |
186 } | 199 } |
187 | 200 |
188 // found and fixed for webkit: mishandling when we hit recursion limit on | 201 // found and fixed for webkit: mishandling when we hit recursion limit on |
189 // mostly degenerate cubic flatness test | 202 // mostly degenerate cubic flatness test |
190 static void regression_cubic(skiatest::Reporter* reporter) { | 203 static void regression_cubic(skiatest::Reporter* reporter) { |
191 SkPath path, stroke; | 204 SkPath path, stroke; |
192 SkPaint paint; | 205 SkPaint paint; |
193 | 206 |
194 path.moveTo(SkFloatToScalar(460.2881309415525f), | 207 path.moveTo(SkFloatToScalar(460.2881309415525f), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 | 258 |
246 // need to implement charsToGlyphs on other backends (e.g. linux, win) | 259 // need to implement charsToGlyphs on other backends (e.g. linux, win) |
247 // before we can run this tests everywhere | 260 // before we can run this tests everywhere |
248 if (false) { | 261 if (false) { |
249 test_cmap(reporter); | 262 test_cmap(reporter); |
250 } | 263 } |
251 } | 264 } |
252 | 265 |
253 #include "TestClassDef.h" | 266 #include "TestClassDef.h" |
254 DEFINE_TESTCLASS("Paint", TestPaintClass, TestPaint) | 267 DEFINE_TESTCLASS("Paint", TestPaintClass, TestPaint) |
OLD | NEW |