| 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 for (int i = 0; i < 256; ++i) { | 286 for (int i = 0; i < 256; ++i) { |
| 287 table[i] = (i * 41) % 256; | 287 table[i] = (i * 41) % 256; |
| 288 } | 288 } |
| 289 auto colorFilter(SkTableColorFilter::Make(table)); | 289 auto colorFilter(SkTableColorFilter::Make(table)); |
| 290 SkAutoTUnref<SkColorFilter> copy( | 290 SkAutoTUnref<SkColorFilter> copy( |
| 291 TestFlattenableSerialization<SkColorFilter>(colorFilter.get(), true, rep
orter)); | 291 TestFlattenableSerialization<SkColorFilter>(colorFilter.get(), true, rep
orter)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 static SkBitmap draw_picture(SkPicture& picture) { | 294 static SkBitmap draw_picture(SkPicture& picture) { |
| 295 SkBitmap bitmap; | 295 SkBitmap bitmap; |
| 296 bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()), | 296 bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()), |
| 297 SkScalarCeilToInt(picture.cullRect().height())); | 297 SkScalarCeilToInt(picture.cullRect().height())); |
| 298 SkCanvas canvas(bitmap); | 298 SkCanvas canvas(bitmap); |
| 299 picture.playback(&canvas); | 299 picture.playback(&canvas); |
| 300 return bitmap; | 300 return bitmap; |
| 301 } | 301 } |
| 302 | 302 |
| 303 static void compare_bitmaps(skiatest::Reporter* reporter, | 303 static void compare_bitmaps(skiatest::Reporter* reporter, |
| 304 const SkBitmap& b1, const SkBitmap& b2) { | 304 const SkBitmap& b1, const SkBitmap& b2) { |
| 305 REPORTER_ASSERT(reporter, b1.width() == b2.width()); | 305 REPORTER_ASSERT(reporter, b1.width() == b2.width()); |
| 306 REPORTER_ASSERT(reporter, b1.height() == b2.height()); | 306 REPORTER_ASSERT(reporter, b1.height() == b2.height()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 326 { | 326 { |
| 327 // Create a paint with the typeface. | 327 // Create a paint with the typeface. |
| 328 SkPaint paint; | 328 SkPaint paint; |
| 329 paint.setColor(SK_ColorGRAY); | 329 paint.setColor(SK_ColorGRAY); |
| 330 paint.setTextSize(SkIntToScalar(30)); | 330 paint.setTextSize(SkIntToScalar(30)); |
| 331 paint.setTypeface(typeface); | 331 paint.setTypeface(typeface); |
| 332 | 332 |
| 333 // Paint some text. | 333 // Paint some text. |
| 334 SkPictureRecorder recorder; | 334 SkPictureRecorder recorder; |
| 335 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); | 335 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); |
| 336 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, | 336 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width())
, |
| 337 SkIntToScalar(canvasRect.height()
), | 337 SkIntToScalar(canvasRect.height()
), |
| 338 nullptr, 0); | 338 nullptr, 0); |
| 339 canvas->drawColor(SK_ColorWHITE); | 339 canvas->drawColor(SK_ColorWHITE); |
| 340 canvas->drawText(text, 2, 24, 32, paint); | 340 canvas->drawText(text, 2, 24, 32, paint); |
| 341 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); | 341 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
| 342 | 342 |
| 343 // Serlialize picture and create its clone from stream. | 343 // Serlialize picture and create its clone from stream. |
| 344 SkDynamicMemoryWStream stream; | 344 SkDynamicMemoryWStream stream; |
| 345 picture->serialize(&stream); | 345 picture->serialize(&stream); |
| 346 SkAutoTDelete<SkStream> inputStream(stream.detachAsStream()); | 346 SkAutoTDelete<SkStream> inputStream(stream.detachAsStream()); |
| 347 sk_sp<SkPicture> loadedPicture(SkPicture::MakeFromStream(inputStream.get()))
; | 347 sk_sp<SkPicture> loadedPicture(SkPicture::MakeFromStream(inputStream.get()))
; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 } | 592 } |
| 593 }; | 593 }; |
| 594 | 594 |
| 595 /* | 595 /* |
| 596 * Test the 3 annotation types by recording them into a picture, serializing, a
nd then playing | 596 * Test the 3 annotation types by recording them into a picture, serializing, a
nd then playing |
| 597 * them back into another canvas. | 597 * them back into another canvas. |
| 598 */ | 598 */ |
| 599 DEF_TEST(Annotations, reporter) { | 599 DEF_TEST(Annotations, reporter) { |
| 600 SkPictureRecorder recorder; | 600 SkPictureRecorder recorder; |
| 601 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100)
); | 601 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100)
); |
| 602 | 602 |
| 603 const char* str0 = "rect-with-url"; | 603 const char* str0 = "rect-with-url"; |
| 604 const SkRect r0 = SkRect::MakeWH(10, 10); | 604 const SkRect r0 = SkRect::MakeWH(10, 10); |
| 605 SkAutoTUnref<SkData> d0(SkData::NewWithCString(str0)); | 605 SkAutoTUnref<SkData> d0(SkData::NewWithCString(str0)); |
| 606 SkAnnotateRectWithURL(recordingCanvas, r0, d0); | 606 SkAnnotateRectWithURL(recordingCanvas, r0, d0); |
| 607 | 607 |
| 608 const char* str1 = "named-destination"; | 608 const char* str1 = "named-destination"; |
| 609 const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point | 609 const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point |
| 610 SkAutoTUnref<SkData> d1(SkData::NewWithCString(str1)); | 610 SkAutoTUnref<SkData> d1(SkData::NewWithCString(str1)); |
| 611 SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1); | 611 SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1); |
| 612 | 612 |
| 613 const char* str2 = "link-to-destination"; | 613 const char* str2 = "link-to-destination"; |
| 614 const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6); | 614 const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6); |
| 615 SkAutoTUnref<SkData> d2(SkData::NewWithCString(str2)); | 615 SkAutoTUnref<SkData> d2(SkData::NewWithCString(str2)); |
| 616 SkAnnotateLinkToDestination(recordingCanvas, r2, d2); | 616 SkAnnotateLinkToDestination(recordingCanvas, r2, d2); |
| 617 | 617 |
| 618 const AnnotationRec recs[] = { | 618 const AnnotationRec recs[] = { |
| 619 { r0, SkAnnotationKeys::URL_Key(), d0 }, | 619 { r0, SkAnnotationKeys::URL_Key(), d0 }, |
| 620 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, | 620 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, |
| 621 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, | 621 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, |
| 622 }; | 622 }; |
| 623 | 623 |
| 624 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); | 624 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); |
| 625 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); | 625 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); |
| 626 | 626 |
| 627 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); | 627 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); |
| 628 canvas.drawPicture(pict1); | 628 canvas.drawPicture(pict1); |
| 629 } | 629 } |
| 630 | |
| OLD | NEW |