| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkMallocPixelRef.h" | 11 #include "SkMallocPixelRef.h" |
| 12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 13 #include "SkPictureRecorder.h" | 13 #include "SkPictureRecorder.h" |
| 14 #include "SkTableColorFilter.h" | 14 #include "SkTableColorFilter.h" |
| 15 #include "SkTemplates.h" | 15 #include "SkTemplates.h" |
| 16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
| 17 #include "SkWriteBuffer.h" | 17 #include "SkWriteBuffer.h" |
| 18 #include "SkValidatingReadBuffer.h" | 18 #include "SkValidatingReadBuffer.h" |
| 19 #include "SkXfermodeImageFilter.h" | 19 #include "SkXfermodeImageFilter.h" |
| 20 #ifdef SK_BUILD_FOR_MAC |
| 21 #include "SkTypeface_mac.h" |
| 22 #endif |
| 20 #include "Test.h" | 23 #include "Test.h" |
| 21 | 24 |
| 22 static const uint32_t kArraySize = 64; | 25 static const uint32_t kArraySize = 64; |
| 23 static const int kBitmapSize = 256; | 26 static const int kBitmapSize = 256; |
| 24 | 27 |
| 25 template<typename T> | 28 template<typename T> |
| 26 static void TestAlignment(T* testObj, skiatest::Reporter* reporter) { | 29 static void TestAlignment(T* testObj, skiatest::Reporter* reporter) { |
| 27 // Test memory read/write functions directly | 30 // Test memory read/write functions directly |
| 28 unsigned char dataWritten[1024]; | 31 unsigned char dataWritten[1024]; |
| 29 size_t bytesWrittenToMemory = testObj->writeToMemory(dataWritten); | 32 size_t bytesWrittenToMemory = testObj->writeToMemory(dataWritten); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 int pixelErrors = 0; | 312 int pixelErrors = 0; |
| 310 for (int y = 0; y < b2.height(); ++y) { | 313 for (int y = 0; y < b2.height(); ++y) { |
| 311 for (int x = 0; x < b2.width(); ++x) { | 314 for (int x = 0; x < b2.width(); ++x) { |
| 312 if (b1.getColor(x, y) != b2.getColor(x, y)) | 315 if (b1.getColor(x, y) != b2.getColor(x, y)) |
| 313 ++pixelErrors; | 316 ++pixelErrors; |
| 314 } | 317 } |
| 315 } | 318 } |
| 316 REPORTER_ASSERT(reporter, 0 == pixelErrors); | 319 REPORTER_ASSERT(reporter, 0 == pixelErrors); |
| 317 } | 320 } |
| 318 | 321 |
| 319 static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { | 322 static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter, SkTyp
eface* typeface) { |
| 320 // Load typeface form file. | |
| 321 // This test cannot run if there is no resource path. | |
| 322 SkString resourcePath = GetResourcePath(); | |
| 323 if (resourcePath.isEmpty()) { | |
| 324 SkDebugf("Could not run fontstream test because resourcePath not specifi
ed."); | |
| 325 return; | |
| 326 } | |
| 327 SkString filename = SkOSPath::Join(resourcePath.c_str(), "test.ttc"); | |
| 328 SkTypeface* typeface = SkTypeface::CreateFromFile(filename.c_str(), 1); | |
| 329 if (!typeface) { | |
| 330 SkDebugf("Could not run fontstream test because test.ttc not found."); | |
| 331 return; | |
| 332 } | |
| 333 | |
| 334 // Create a paint with the typeface we loaded. | 323 // Create a paint with the typeface we loaded. |
| 335 SkPaint paint; | 324 SkPaint paint; |
| 336 paint.setColor(SK_ColorGRAY); | 325 paint.setColor(SK_ColorGRAY); |
| 337 paint.setTextSize(SkIntToScalar(30)); | 326 paint.setTextSize(SkIntToScalar(30)); |
| 338 SkSafeUnref(paint.setTypeface(typeface)); | 327 SkSafeUnref(paint.setTypeface(typeface)); |
| 339 | 328 |
| 340 // Paint some text. | 329 // Paint some text. |
| 341 SkPictureRecorder recorder; | 330 SkPictureRecorder recorder; |
| 342 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); | 331 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); |
| 343 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, | 332 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 SkAutoTMalloc<unsigned char> data(size); | 509 SkAutoTMalloc<unsigned char> data(size); |
| 521 writer.writeToMemory(static_cast<void*>(data.get())); | 510 writer.writeToMemory(static_cast<void*>(data.get())); |
| 522 | 511 |
| 523 // Deserialize picture | 512 // Deserialize picture |
| 524 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); | 513 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); |
| 525 SkAutoTUnref<SkPicture> readPict( | 514 SkAutoTUnref<SkPicture> readPict( |
| 526 SkPicture::CreateFromBuffer(reader)); | 515 SkPicture::CreateFromBuffer(reader)); |
| 527 REPORTER_ASSERT(reporter, readPict.get()); | 516 REPORTER_ASSERT(reporter, readPict.get()); |
| 528 } | 517 } |
| 529 | 518 |
| 530 TestPictureTypefaceSerialization(reporter); | 519 { |
| 520 // Load typeface form file. |
| 521 // This test cannot run if there is no resource path. |
| 522 SkString resourcePath = GetResourcePath(); |
| 523 if (resourcePath.isEmpty()) { |
| 524 SkDebugf("Could not run fontstream test because resourcePath not spe
cified."); |
| 525 return; |
| 526 } |
| 527 SkString filename = SkOSPath::Join(resourcePath.c_str(), "test.ttc"); |
| 528 SkTypeface* typeface = SkTypeface::CreateFromFile(filename.c_str(), 1); |
| 529 if (!typeface) { |
| 530 SkDebugf("Could not run fontstream test because test.ttc not found."
); |
| 531 return; |
| 532 } |
| 533 |
| 534 TestPictureTypefaceSerialization(reporter, typeface); |
| 535 |
| 536 #ifdef SK_BUILD_FOR_MAC |
| 537 // Now do almost the same but use SkCreateTypefaceFromCTFont |
| 538 CGDataProviderRef provider = CGDataProviderCreateWithFilename(filename.c
_str()); |
| 539 CGFontRef cgFont = CGFontCreateWithDataProvider(provider); |
| 540 if (NULL == cgFont) { |
| 541 SkDebugf("Could not run fontstream test, CGFontCreateWithDataProvide
r failed."); |
| 542 return; |
| 543 } |
| 544 CTFontRef ctFont = CTFontCreateWithGraphicsFont(cgFont, 0, NULL, NULL); |
| 545 typeface = SkCreateTypefaceFromCTFont(ctFont); |
| 546 TestPictureTypefaceSerialization(reporter, typeface); |
| 547 CFRelease(cgFont); |
| 548 CFRelease(provider); |
| 549 #endif // SK_BUILD_FOR_MAC |
| 550 } |
| 531 } | 551 } |
| OLD | NEW |