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 "SkAnnotationKeys.h" | 8 #include "SkAnnotationKeys.h" |
9 #include "Resources.h" | 9 #include "Resources.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 315 |
316 int pixelErrors = 0; | 316 int pixelErrors = 0; |
317 for (int y = 0; y < b2.height(); ++y) { | 317 for (int y = 0; y < b2.height(); ++y) { |
318 for (int x = 0; x < b2.width(); ++x) { | 318 for (int x = 0; x < b2.width(); ++x) { |
319 if (b1.getColor(x, y) != b2.getColor(x, y)) | 319 if (b1.getColor(x, y) != b2.getColor(x, y)) |
320 ++pixelErrors; | 320 ++pixelErrors; |
321 } | 321 } |
322 } | 322 } |
323 REPORTER_ASSERT(reporter, 0 == pixelErrors); | 323 REPORTER_ASSERT(reporter, 0 == pixelErrors); |
324 } | 324 } |
325 static void serialize_and_compare_typeface(sk_sp<SkTypeface> typeface, const cha
r* text, | 325 static void serialize_and_compare_typeface(SkTypeface* typeface, const char* tex
t, |
326 skiatest::Reporter* reporter) | 326 skiatest::Reporter* reporter) |
327 { | 327 { |
328 // Create a paint with the typeface. | 328 // Create a paint with the typeface. |
329 SkPaint paint; | 329 SkPaint paint; |
330 paint.setColor(SK_ColorGRAY); | 330 paint.setColor(SK_ColorGRAY); |
331 paint.setTextSize(SkIntToScalar(30)); | 331 paint.setTextSize(SkIntToScalar(30)); |
332 paint.setTypeface(std::move(typeface)); | 332 paint.setTypeface(typeface); |
333 | 333 |
334 // Paint some text. | 334 // Paint some text. |
335 SkPictureRecorder recorder; | 335 SkPictureRecorder recorder; |
336 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); | 336 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); |
337 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, | 337 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, |
338 SkIntToScalar(canvasRect.height()
), | 338 SkIntToScalar(canvasRect.height()
), |
339 nullptr, 0); | 339 nullptr, 0); |
340 canvas->drawColor(SK_ColorWHITE); | 340 canvas->drawColor(SK_ColorWHITE); |
341 canvas->drawText(text, 2, 24, 32, paint); | 341 canvas->drawText(text, 2, 24, 32, paint); |
342 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); | 342 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
343 | 343 |
344 // Serlialize picture and create its clone from stream. | 344 // Serlialize picture and create its clone from stream. |
345 SkDynamicMemoryWStream stream; | 345 SkDynamicMemoryWStream stream; |
346 picture->serialize(&stream); | 346 picture->serialize(&stream); |
347 SkAutoTDelete<SkStream> inputStream(stream.detachAsStream()); | 347 SkAutoTDelete<SkStream> inputStream(stream.detachAsStream()); |
348 sk_sp<SkPicture> loadedPicture(SkPicture::MakeFromStream(inputStream.get()))
; | 348 sk_sp<SkPicture> loadedPicture(SkPicture::MakeFromStream(inputStream.get()))
; |
349 | 349 |
350 // Draw both original and clone picture and compare bitmaps -- they should b
e identical. | 350 // Draw both original and clone picture and compare bitmaps -- they should b
e identical. |
351 SkBitmap origBitmap = draw_picture(*picture); | 351 SkBitmap origBitmap = draw_picture(*picture); |
352 SkBitmap destBitmap = draw_picture(*loadedPicture); | 352 SkBitmap destBitmap = draw_picture(*loadedPicture); |
353 compare_bitmaps(reporter, origBitmap, destBitmap); | 353 compare_bitmaps(reporter, origBitmap, destBitmap); |
354 } | 354 } |
355 | 355 |
356 static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { | 356 static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { |
357 { | 357 { |
358 // Load typeface from file to test CreateFromFile with index. | 358 // Load typeface from file to test CreateFromFile with index. |
359 SkString filename = GetResourcePath("/fonts/test.ttc"); | 359 SkString filename = GetResourcePath("/fonts/test.ttc"); |
360 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFile(filename.c_str(), 1)
); | 360 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFile(filename.c_
str(), 1)); |
361 if (!typeface) { | 361 if (!typeface) { |
362 INFOF(reporter, "Could not run fontstream test because test.ttc not
found."); | 362 INFOF(reporter, "Could not run fontstream test because test.ttc not
found."); |
363 } else { | 363 } else { |
364 serialize_and_compare_typeface(std::move(typeface), "A!", reporter); | 364 serialize_and_compare_typeface(typeface, "A!", reporter); |
365 } | 365 } |
366 } | 366 } |
367 | 367 |
368 { | 368 { |
369 // Load typeface as stream to create with axis settings. | 369 // Load typeface as stream to create with axis settings. |
370 SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Dis
tortable.ttf")); | 370 SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Dis
tortable.ttf")); |
371 if (!distortable) { | 371 if (!distortable) { |
372 INFOF(reporter, "Could not run fontstream test because Distortable.t
tf not found."); | 372 INFOF(reporter, "Could not run fontstream test because Distortable.t
tf not found."); |
373 } else { | 373 } else { |
374 SkFixed axis = SK_FixedSqrt2; | 374 SkFixed axis = SK_FixedSqrt2; |
375 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData( | 375 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData( |
376 new SkFontData(distortable.release(), 0, &axis, 1))); | 376 new SkFontData(distortable.release(), 0, &axis, 1))); |
377 if (!typeface) { | 377 if (!typeface) { |
378 INFOF(reporter, "Could not run fontstream test because Distortab
le.ttf not created."); | 378 INFOF(reporter, "Could not run fontstream test because Distortab
le.ttf not created."); |
379 } else { | 379 } else { |
380 serialize_and_compare_typeface(std::move(typeface), "abc", repor
ter); | 380 serialize_and_compare_typeface(typeface, "abc", reporter); |
381 } | 381 } |
382 } | 382 } |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 static void setup_bitmap_for_canvas(SkBitmap* bitmap) { | 386 static void setup_bitmap_for_canvas(SkBitmap* bitmap) { |
387 bitmap->allocN32Pixels(kBitmapSize, kBitmapSize); | 387 bitmap->allocN32Pixels(kBitmapSize, kBitmapSize); |
388 } | 388 } |
389 | 389 |
390 static void make_checkerboard_bitmap(SkBitmap& bitmap) { | 390 static void make_checkerboard_bitmap(SkBitmap& bitmap) { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, | 621 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, |
622 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, | 622 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, |
623 }; | 623 }; |
624 | 624 |
625 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); | 625 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); |
626 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); | 626 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); |
627 | 627 |
628 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); | 628 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); |
629 canvas.drawPicture(pict1); | 629 canvas.drawPicture(pict1); |
630 } | 630 } |
OLD | NEW |