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 "SkAnnotationKeys.h" | 9 #include "SkAnnotationKeys.h" |
| 10 #include "SkBitmapProcShader.h" |
10 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
11 #include "SkFixed.h" | 12 #include "SkFixed.h" |
12 #include "SkFontDescriptor.h" | 13 #include "SkFontDescriptor.h" |
13 #include "SkImage.h" | 14 #include "SkImage.h" |
14 #include "SkImageSource.h" | 15 #include "SkImageSource.h" |
15 #include "SkLightingShader.h" | 16 #include "SkLightingShader.h" |
16 #include "SkMallocPixelRef.h" | 17 #include "SkMallocPixelRef.h" |
| 18 #include "SkNormalSource.h" |
17 #include "SkOSFile.h" | 19 #include "SkOSFile.h" |
18 #include "SkPictureRecorder.h" | 20 #include "SkPictureRecorder.h" |
19 #include "SkTableColorFilter.h" | 21 #include "SkTableColorFilter.h" |
20 #include "SkTemplates.h" | 22 #include "SkTemplates.h" |
21 #include "SkTypeface.h" | 23 #include "SkTypeface.h" |
22 #include "SkWriteBuffer.h" | 24 #include "SkWriteBuffer.h" |
23 #include "SkValidatingReadBuffer.h" | 25 #include "SkValidatingReadBuffer.h" |
24 #include "SkXfermodeImageFilter.h" | 26 #include "SkXfermodeImageFilter.h" |
25 #include "sk_tool_utils.h" | 27 #include "sk_tool_utils.h" |
26 #include "Test.h" | 28 #include "Test.h" |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 sk_tool_utils::color_to_565(0x0), | 568 sk_tool_utils::color_to_565(0x0), |
567 sk_tool_utils::color_to_565(0xFF804020), | 569 sk_tool_utils::color_to_565(0xFF804020), |
568 8); | 570 8); |
569 | 571 |
570 SkRect bitmapBounds = SkRect::MakeIWH(diffuse.width(), diffuse.height())
; | 572 SkRect bitmapBounds = SkRect::MakeIWH(diffuse.width(), diffuse.height())
; |
571 | 573 |
572 SkMatrix matrix; | 574 SkMatrix matrix; |
573 SkRect r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSiz
e)); | 575 SkRect r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSiz
e)); |
574 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); | 576 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); |
575 | 577 |
576 SkVector invNormRotation = { SkScalarSqrt(0.3f), SkScalarSqrt(0.7f) }; | 578 SkMatrix ctm; |
| 579 ctm.setRotate(45); |
577 SkBitmap normals; | 580 SkBitmap normals; |
578 normals.allocN32Pixels(kTexSize, kTexSize); | 581 normals.allocN32Pixels(kTexSize, kTexSize); |
579 | 582 |
580 sk_tool_utils::create_frustum_normal_map(&normals, SkIRect::MakeWH(kTexS
ize, kTexSize)); | 583 sk_tool_utils::create_frustum_normal_map(&normals, SkIRect::MakeWH(kTexS
ize, kTexSize)); |
581 sk_sp<SkShader> lightingShader = SkLightingShader::Make(diffuse, normals
, fLights, | 584 sk_sp<SkShader> normalMap = SkMakeBitmapShader(normals, SkShader::kClamp
_TileMode, |
582 invNormRotation, &matrix, &matrix); | 585 SkShader::kClamp_TileMode
, &matrix, nullptr); |
| 586 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(s
td::move(normalMap), |
| 587 c
tm); |
| 588 sk_sp<SkShader> lightingShader = SkLightingShader::Make(diffuse, fLights
, &matrix, |
| 589 std::move(normal
Source)); |
583 | 590 |
584 SkAutoTUnref<SkShader>(TestFlattenableSerialization(lightingShader.get()
, true, reporter)); | 591 SkAutoTUnref<SkShader>(TestFlattenableSerialization(lightingShader.get()
, true, reporter)); |
585 // TODO test equality? | 592 // TODO test equality? |
586 | 593 |
587 } | 594 } |
588 } | 595 } |
589 | 596 |
590 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 597 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
591 #include "SkAnnotation.h" | 598 #include "SkAnnotation.h" |
592 | 599 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, | 667 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, |
661 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, | 668 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, |
662 }; | 669 }; |
663 | 670 |
664 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); | 671 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); |
665 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); | 672 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); |
666 | 673 |
667 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); | 674 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); |
668 canvas.drawPicture(pict1); | 675 canvas.drawPicture(pict1); |
669 } | 676 } |
OLD | NEW |