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

Side by Side Diff: tests/PaintTest.cpp

Issue 203203003: SkPaint: eliminate some dead bytes in 64-bit build. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tighter Created 6 years, 9 months 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
« no previous file with comments | « src/core/SkPaint.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkBlurMask.h" 8 #include "SkBlurMask.h"
9 #include "SkBlurMaskFilter.h" 9 #include "SkBlurMaskFilter.h"
10 #include "SkLayerDrawLooper.h" 10 #include "SkLayerDrawLooper.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 static int find_first_zero(const uint16_t glyphs[], int count) { 53 static int find_first_zero(const uint16_t glyphs[], int count) {
54 for (int i = 0; i < count; ++i) { 54 for (int i = 0; i < count; ++i) {
55 if (0 == glyphs[i]) { 55 if (0 == glyphs[i]) {
56 return i; 56 return i;
57 } 57 }
58 } 58 }
59 return count; 59 return count;
60 } 60 }
61 61
62 static void test_cmap(skiatest::Reporter* reporter) { 62 DEF_TEST(Paint_cmap, reporter) {
63 // need to implement charsToGlyphs on other backends (e.g. linux, win)
64 // before we can run this tests everywhere
65 return;
66
63 static const int NGLYPHS = 64; 67 static const int NGLYPHS = 64;
64 68
65 SkUnichar src[NGLYPHS]; 69 SkUnichar src[NGLYPHS];
66 SkUnichar dst[NGLYPHS]; // used for utf8, utf16, utf32 storage 70 SkUnichar dst[NGLYPHS]; // used for utf8, utf16, utf32 storage
67 71
68 static const struct { 72 static const struct {
69 size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count); 73 size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count);
70 SkPaint::TextEncoding fEncoding; 74 SkPaint::TextEncoding fEncoding;
71 } gRec[] = { 75 } gRec[] = {
72 { uni_to_utf8, SkPaint::kUTF8_TextEncoding }, 76 { uni_to_utf8, SkPaint::kUTF8_TextEncoding },
(...skipping 21 matching lines...) Expand all
94 98
95 uint16_t glyphs0[NGLYPHS], glyphs1[NGLYPHS]; 99 uint16_t glyphs0[NGLYPHS], glyphs1[NGLYPHS];
96 100
97 bool contains = paint.containsText(dst, len); 101 bool contains = paint.containsText(dst, len);
98 int nglyphs = paint.textToGlyphs(dst, len, glyphs0); 102 int nglyphs = paint.textToGlyphs(dst, len, glyphs0);
99 int first = face->charsToGlyphs(dst, paint2encoding(paint), glyphs1, NGLYPHS); 103 int first = face->charsToGlyphs(dst, paint2encoding(paint), glyphs1, NGLYPHS);
100 int index = find_first_zero(glyphs1, NGLYPHS); 104 int index = find_first_zero(glyphs1, NGLYPHS);
101 105
102 REPORTER_ASSERT(reporter, NGLYPHS == nglyphs); 106 REPORTER_ASSERT(reporter, NGLYPHS == nglyphs);
103 REPORTER_ASSERT(reporter, index == first); 107 REPORTER_ASSERT(reporter, index == first);
104 REPORTER_ASSERT(reporter, 108 REPORTER_ASSERT(reporter, 0 == memcmp(glyphs0, glyphs1, NGLYPHS * si zeof(uint16_t)));
105 !memcmp(glyphs0, glyphs1, NGLYPHS * sizeof(uint16_t)));
106 if (contains) { 109 if (contains) {
107 REPORTER_ASSERT(reporter, NGLYPHS == first); 110 REPORTER_ASSERT(reporter, NGLYPHS == first);
108 } else { 111 } else {
109 REPORTER_ASSERT(reporter, NGLYPHS > first); 112 REPORTER_ASSERT(reporter, NGLYPHS > first);
110 } 113 }
111 } 114 }
112 } 115 }
113 } 116 }
114 117
115 // temparary api for bicubic, just be sure we can set/clear it 118 // temparary api for bicubic, just be sure we can set/clear it
116 static void test_filterlevel(skiatest::Reporter* reporter) { 119 DEF_TEST(Paint_filterlevel, reporter) {
117 SkPaint p0, p1; 120 SkPaint p0, p1;
118 121
119 REPORTER_ASSERT(reporter, 122 REPORTER_ASSERT(reporter,
120 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); 123 SkPaint::kNone_FilterLevel == p0.getFilterLevel());
121 124
122 static const SkPaint::FilterLevel gLevels[] = { 125 static const SkPaint::FilterLevel gLevels[] = {
123 SkPaint::kNone_FilterLevel, 126 SkPaint::kNone_FilterLevel,
124 SkPaint::kLow_FilterLevel, 127 SkPaint::kLow_FilterLevel,
125 SkPaint::kMedium_FilterLevel, 128 SkPaint::kMedium_FilterLevel,
126 SkPaint::kHigh_FilterLevel 129 SkPaint::kHigh_FilterLevel
127 }; 130 };
128 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) { 131 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
129 p0.setFilterLevel(gLevels[i]); 132 p0.setFilterLevel(gLevels[i]);
130 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel()); 133 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel());
131 p1 = p0; 134 p1 = p0;
132 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel()); 135 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel());
133 136
134 p0.reset(); 137 p0.reset();
135 REPORTER_ASSERT(reporter, 138 REPORTER_ASSERT(reporter,
136 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); 139 SkPaint::kNone_FilterLevel == p0.getFilterLevel());
137 } 140 }
138 } 141 }
139 142
140 static void test_copy(skiatest::Reporter* reporter) { 143 DEF_TEST(Paint_copy, reporter) {
141 SkPaint paint; 144 SkPaint paint;
142 // set a few member variables 145 // set a few member variables
143 paint.setStyle(SkPaint::kStrokeAndFill_Style); 146 paint.setStyle(SkPaint::kStrokeAndFill_Style);
144 paint.setTextAlign(SkPaint::kLeft_Align); 147 paint.setTextAlign(SkPaint::kLeft_Align);
145 paint.setStrokeWidth(SkIntToScalar(2)); 148 paint.setStrokeWidth(SkIntToScalar(2));
146 // set a few pointers 149 // set a few pointers
147 SkLayerDrawLooper* looper = new SkLayerDrawLooper(); 150 SkLayerDrawLooper* looper = new SkLayerDrawLooper();
148 paint.setLooper(looper)->unref(); 151 paint.setLooper(looper)->unref();
149 SkMaskFilter* mask = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Blur Style, 152 SkMaskFilter* mask = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_Blur Style,
150 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(1))); 153 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(1)));
151 paint.setMaskFilter(mask)->unref(); 154 paint.setMaskFilter(mask)->unref();
152 155
153 // copy the paint using the copy constructor and check they are the same 156 // copy the paint using the copy constructor and check they are the same
154 SkPaint copiedPaint = paint; 157 SkPaint copiedPaint = paint;
155 REPORTER_ASSERT(reporter, paint == copiedPaint); 158 REPORTER_ASSERT(reporter, paint == copiedPaint);
156 159
157 #ifdef SK_BUILD_FOR_ANDROID 160 #ifdef SK_BUILD_FOR_ANDROID
158 // the copy constructor should preserve the Generation ID 161 // the copy constructor should preserve the Generation ID
159 uint32_t paintGenID = paint.getGenerationID(); 162 uint32_t paintGenID = paint.getGenerationID();
160 uint32_t copiedPaintGenID = copiedPaint.getGenerationID(); 163 uint32_t copiedPaintGenID = copiedPaint.getGenerationID();
161 REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID); 164 REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID);
162 REPORTER_ASSERT(reporter, !memcmp(&paint, &copiedPaint, sizeof(paint))); 165 REPORTER_ASSERT(reporter, paint == copiedPaint);
163 #endif 166 #endif
164 167
165 // copy the paint using the equal operator and check they are the same 168 // copy the paint using the equal operator and check they are the same
166 copiedPaint = paint; 169 copiedPaint = paint;
167 REPORTER_ASSERT(reporter, paint == copiedPaint); 170 REPORTER_ASSERT(reporter, paint == copiedPaint);
168 171
169 #ifdef SK_BUILD_FOR_ANDROID 172 #ifdef SK_BUILD_FOR_ANDROID
170 // the equals operator should increment the Generation ID 173 // the equals operator should increment the Generation ID
171 REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID); 174 REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID);
172 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; 175 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ;
173 copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value 176 copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value
174 REPORTER_ASSERT(reporter, memcmp(&paint, &copiedPaint, sizeof(paint))); 177 REPORTER_ASSERT(reporter, paint == copiedPaint); // operator== ignores fGen erationID
175 #endif 178 #endif
176 179
177 // clean the paint and check they are back to their initial states 180 // clean the paint and check they are back to their initial states
178 SkPaint cleanPaint; 181 SkPaint cleanPaint;
179 paint.reset(); 182 paint.reset();
180 copiedPaint.reset(); 183 copiedPaint.reset();
181 REPORTER_ASSERT(reporter, cleanPaint == paint); 184 REPORTER_ASSERT(reporter, cleanPaint == paint);
182 REPORTER_ASSERT(reporter, cleanPaint == copiedPaint); 185 REPORTER_ASSERT(reporter, cleanPaint == copiedPaint);
183 186
184 #ifdef SK_BUILD_FOR_ANDROID 187 #ifdef SK_BUILD_FOR_ANDROID
185 // the reset function should increment the Generation ID 188 // the reset function should increment the Generation ID
186 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID); 189 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID);
187 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; 190 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ;
188 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &paint, sizeof(cleanPaint))); 191 // operator== ignores fGenerationID
189 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &copiedPaint, sizeof(cleanPain t))); 192 REPORTER_ASSERT(reporter, cleanPaint == paint);
193 REPORTER_ASSERT(reporter, cleanPaint == copiedPaint);
190 #endif 194 #endif
191 } 195 }
192 196
193 // found and fixed for webkit: mishandling when we hit recursion limit on 197 // found and fixed for webkit: mishandling when we hit recursion limit on
194 // mostly degenerate cubic flatness test 198 // mostly degenerate cubic flatness test
195 static void regression_cubic(skiatest::Reporter* reporter) { 199 DEF_TEST(Paint_regression_cubic, reporter) {
196 SkPath path, stroke; 200 SkPath path, stroke;
197 SkPaint paint; 201 SkPaint paint;
198 202
199 path.moveTo(460.2881309415525f, 203 path.moveTo(460.2881309415525f,
200 303.250847066498f); 204 303.250847066498f);
201 path.cubicTo(463.36378422175284f, 205 path.cubicTo(463.36378422175284f,
202 302.1169735073363f, 206 302.1169735073363f,
203 456.32239330810046f, 207 456.32239330810046f,
204 304.720354932878f, 208 304.720354932878f,
205 453.15255460013304f, 209 453.15255460013304f,
(...skipping 12 matching lines...) Expand all
218 SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ? 222 SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ?
219 SkScalarMul(paint.getStrokeWidth(), miter) : 223 SkScalarMul(paint.getStrokeWidth(), miter) :
220 paint.getStrokeWidth(); 224 paint.getStrokeWidth();
221 maxR.inset(-inset, -inset); 225 maxR.inset(-inset, -inset);
222 226
223 // test that our stroke didn't explode 227 // test that our stroke didn't explode
224 REPORTER_ASSERT(reporter, maxR.contains(strokeR)); 228 REPORTER_ASSERT(reporter, maxR.contains(strokeR));
225 } 229 }
226 230
227 // found and fixed for android: not initializing rect for string's of length 0 231 // found and fixed for android: not initializing rect for string's of length 0
228 static void regression_measureText(skiatest::Reporter* reporter) { 232 DEF_TEST(Paint_regression_measureText, reporter) {
229 233
230 SkPaint paint; 234 SkPaint paint;
231 paint.setTextSize(12.0f); 235 paint.setTextSize(12.0f);
232 236
233 SkRect r; 237 SkRect r;
234 r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN); 238 r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN);
235 239
236 // test that the rect was reset 240 // test that the rect was reset
237 paint.measureText("", 0, &r, 1.0f); 241 paint.measureText("", 0, &r, 1.0f);
238 REPORTER_ASSERT(reporter, r.isEmpty()); 242 REPORTER_ASSERT(reporter, r.isEmpty());
239 } 243 }
240 244
241 DEF_TEST(Paint, reporter) {
242 // TODO add general paint tests
243 test_copy(reporter);
244
245 // regression tests
246 regression_cubic(reporter);
247 regression_measureText(reporter);
248
249 test_filterlevel(reporter);
250
251 // need to implement charsToGlyphs on other backends (e.g. linux, win)
252 // before we can run this tests everywhere
253 if (false) {
254 test_cmap(reporter);
255 }
256 }
257
258 #define ASSERT(expr) REPORTER_ASSERT(r, expr) 245 #define ASSERT(expr) REPORTER_ASSERT(r, expr)
259 246
260 DEF_TEST(Paint_FlatteningTraits, r) { 247 DEF_TEST(Paint_FlatteningTraits, r) {
261 SkPaint paint; 248 SkPaint paint;
262 paint.setColor(0x00AABBCC); 249 paint.setColor(0x00AABBCC);
263 paint.setTextScaleX(1.0f); // Encoded despite being the default value. 250 paint.setTextScaleX(1.0f); // Encoded despite being the default value.
264 paint.setTextSize(19); 251 paint.setTextSize(19);
265 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref(); 252 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref();
266 paint.setLooper(NULL); // Ignored. 253 paint.setLooper(NULL); // Ignored.
267 254
(...skipping 16 matching lines...) Expand all
284 ASSERT(other.getTextScaleX() == paint.getTextScaleX()); 271 ASSERT(other.getTextScaleX() == paint.getTextScaleX());
285 ASSERT(other.getTextSize() == paint.getTextSize()); 272 ASSERT(other.getTextSize() == paint.getTextSize());
286 ASSERT(other.getLooper() == paint.getLooper()); 273 ASSERT(other.getLooper() == paint.getLooper());
287 274
288 // We have to be a little looser and compare just the modes. Pointers might not be the same. 275 // We have to be a little looser and compare just the modes. Pointers might not be the same.
289 SkXfermode::Mode otherMode, paintMode; 276 SkXfermode::Mode otherMode, paintMode;
290 ASSERT(other.getXfermode()->asMode(&otherMode)); 277 ASSERT(other.getXfermode()->asMode(&otherMode));
291 ASSERT(paint.getXfermode()->asMode(&paintMode)); 278 ASSERT(paint.getXfermode()->asMode(&paintMode));
292 ASSERT(otherMode == paintMode); 279 ASSERT(otherMode == paintMode);
293 } 280 }
OLDNEW
« no previous file with comments | « src/core/SkPaint.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698