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

Side by Side Diff: tests/PaintTest.cpp

Issue 158913005: Merge tomhudson and mtklein SkPaint shrinking approaches. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't unref typeface. Created 6 years, 10 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/SkPicturePlayback.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"
11 #include "SkPaint.h" 11 #include "SkPaint.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkRandom.h" 13 #include "SkRandom.h"
14 #include "SkReadBuffer.h"
14 #include "SkTypeface.h" 15 #include "SkTypeface.h"
15 #include "SkUtils.h" 16 #include "SkUtils.h"
17 #include "SkWriteBuffer.h"
18 #include "SkXfermode.h"
16 #include "Test.h" 19 #include "Test.h"
17 20
18 static size_t uni_to_utf8(const SkUnichar src[], void* dst, int count) { 21 static size_t uni_to_utf8(const SkUnichar src[], void* dst, int count) {
19 char* u8 = (char*)dst; 22 char* u8 = (char*)dst;
20 for (int i = 0; i < count; ++i) { 23 for (int i = 0; i < count; ++i) {
21 int n = SkUTF8_FromUnichar(src[i], u8); 24 int n = SkUTF8_FromUnichar(src[i], u8);
22 u8 += n; 25 u8 += n;
23 } 26 }
24 return u8 - (char*)dst; 27 return u8 - (char*)dst;
25 } 28 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 regression_measureText(reporter); 247 regression_measureText(reporter);
245 248
246 test_filterlevel(reporter); 249 test_filterlevel(reporter);
247 250
248 // need to implement charsToGlyphs on other backends (e.g. linux, win) 251 // need to implement charsToGlyphs on other backends (e.g. linux, win)
249 // before we can run this tests everywhere 252 // before we can run this tests everywhere
250 if (false) { 253 if (false) {
251 test_cmap(reporter); 254 test_cmap(reporter);
252 } 255 }
253 } 256 }
257
258 #define ASSERT(expr) REPORTER_ASSERT(r, expr)
259
260 DEF_TEST(Paint_FlatteningTraits, r) {
261 SkPaint paint;
262 paint.setColor(0x00AABBCC);
263 paint.setTextScaleX(1.0f); // Encoded despite being the default value.
264 paint.setTextSize(19);
265 paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref();
266 paint.setLooper(NULL); // Ignored.
267
268 SkWriteBuffer writer;
269 SkPaint::FlatteningTraits::Flatten(writer, paint);
270 const size_t expectedBytesWritten = sizeof(void*) == 8 ? 48 : 40;
271 ASSERT(expectedBytesWritten == writer.bytesWritten());
272
273 const uint32_t* written = writer.getWriter32()->contiguousArray();
274 SkASSERT(written != NULL);
275 ASSERT(*written == ((1<<0) | (1<<2) | (1<<3) | (1<<9))); // Dirty bits for our 4.
276
277 SkReadBuffer reader(written, writer.bytesWritten());
278 SkPaint other;
279 SkPaint::FlatteningTraits::Unflatten(reader, &other);
280 ASSERT(reader.offset() == writer.bytesWritten());
281
282 // No matter the encoding, these must always hold.
283 ASSERT(other.getColor() == paint.getColor());
284 ASSERT(other.getTextScaleX() == paint.getTextScaleX());
285 ASSERT(other.getTextSize() == paint.getTextSize());
286 ASSERT(other.getLooper() == paint.getLooper());
287
288 // We have to be a little looser and compare just the modes. Pointers might not be the same.
289 SkXfermode::Mode otherMode, paintMode;
290 ASSERT(other.getXfermode()->asMode(&otherMode));
291 ASSERT(paint.getXfermode()->asMode(&paintMode));
292 ASSERT(otherMode == paintMode);
293 }
OLDNEW
« no previous file with comments | « src/core/SkPicturePlayback.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698