OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkImageSource.h" | 8 #include "SkImageSource.h" |
9 #include "SkSurface.h" | 9 #include "SkSurface.h" |
10 #include "SkTileImageFilter.h" | 10 #include "SkTileImageFilter.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 fRedImage = create_circle_texture(kBitmapSize, SK_ColorRED); | 47 fRedImage = create_circle_texture(kBitmapSize, SK_ColorRED); |
48 fGreenImage = create_circle_texture(kBitmapSize, SK_ColorGREEN); | 48 fGreenImage = create_circle_texture(kBitmapSize, SK_ColorGREEN); |
49 } | 49 } |
50 | 50 |
51 void onDraw(SkCanvas* canvas) override { | 51 void onDraw(SkCanvas* canvas) override { |
52 canvas->clear(SK_ColorBLACK); | 52 canvas->clear(SK_ColorBLACK); |
53 | 53 |
54 { | 54 { |
55 SkPaint p; | 55 SkPaint p; |
56 | 56 |
57 SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(k
Height)); | 57 const SkRect bound = SkRect::MakeIWH(kWidth, kHeight); |
58 sk_sp<SkImageFilter> imageSource(SkImageSource::Create(fRedImage.get
())); | 58 sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fRedImage)); |
59 SkAutoTUnref<SkImageFilter> tif(SkTileImageFilter::Create( | 59 |
60 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc
alar(kBitmapSize)), | 60 sk_sp<SkImageFilter> tif(SkTileImageFilter::Create( |
61 SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(
kHeight)), | 61 SkRect::MakeIWH(kBitmapSize,
kBitmapSize), |
62 imageSource.get())); | 62 SkRect::MakeIWH(kWidth, kHei
ght), |
63 p.setImageFilter(tif); | 63 imageSource.get())); |
| 64 |
| 65 p.setImageFilter(std::move(tif)); |
64 | 66 |
65 canvas->saveLayer(&bound, &p); | 67 canvas->saveLayer(&bound, &p); |
66 canvas->restore(); | 68 canvas->restore(); |
67 } | 69 } |
68 | 70 |
69 { | 71 { |
70 SkPaint p2; | 72 SkPaint p2; |
71 | 73 |
72 SkRect bound2 = SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc
alar(kBitmapSize)); | 74 const SkRect bound2 = SkRect::MakeIWH(kBitmapSize, kBitmapSize); |
73 | 75 |
74 SkAutoTUnref<SkImageFilter> tif2(SkTileImageFilter::Create( | 76 sk_sp<SkImageFilter> tif(SkTileImageFilter::Create( |
75 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc
alar(kBitmapSize)), | 77 SkRect::MakeIWH(kBitmapS
ize, kBitmapSize), |
76 SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToSc
alar(kBitmapSize)), | 78 SkRect::MakeIWH(kBitmapS
ize, kBitmapSize), |
77 nullptr)); | 79 nullptr)); |
78 p2.setImageFilter(tif2); | 80 |
| 81 p2.setImageFilter(std::move(tif)); |
79 | 82 |
80 canvas->translate(320, 320); | 83 canvas->translate(320, 320); |
81 canvas->saveLayer(&bound2, &p2); | 84 canvas->saveLayer(&bound2, &p2); |
82 canvas->setMatrix(SkMatrix::I()); | 85 canvas->setMatrix(SkMatrix::I()); |
83 | 86 |
84 SkRect bound3 = SkRect::MakeXYWH(320, 320, | 87 SkRect bound3 = SkRect::MakeXYWH(320, 320, |
85 SkIntToScalar(kBitmapSize), | 88 SkIntToScalar(kBitmapSize), |
86 SkIntToScalar(kBitmapSize)); | 89 SkIntToScalar(kBitmapSize)); |
87 canvas->drawImageRect(fGreenImage.get(), bound2, bound3, nullptr, | 90 canvas->drawImageRect(fGreenImage.get(), bound2, bound3, nullptr, |
88 SkCanvas::kStrict_SrcRectConstraint); | 91 SkCanvas::kStrict_SrcRectConstraint); |
89 canvas->restore(); | 92 canvas->restore(); |
90 } | 93 } |
91 } | 94 } |
92 | 95 |
93 private: | 96 private: |
94 static const int kWidth = 512; | 97 static const int kWidth = 512; |
95 static const int kHeight = 512; | 98 static const int kHeight = 512; |
96 static const int kBitmapSize = 64; | 99 static const int kBitmapSize = 64; |
97 | 100 |
98 sk_sp<SkImage> fRedImage; | 101 sk_sp<SkImage> fRedImage; |
99 sk_sp<SkImage> fGreenImage; | 102 sk_sp<SkImage> fGreenImage; |
100 | 103 |
101 typedef GM INHERITED; | 104 typedef GM INHERITED; |
102 }; | 105 }; |
103 | 106 |
104 ////////////////////////////////////////////////////////////////////////////// | 107 ////////////////////////////////////////////////////////////////////////////// |
105 | 108 |
106 DEF_GM(return new BigTileImageFilterGM;) | 109 DEF_GM(return new BigTileImageFilterGM;) |
107 } | 110 } |
OLD | NEW |