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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "SkColorFilterImageFilter.h" | 9 #include "SkColorFilterImageFilter.h" |
10 #include "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 86 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
87 0, SK_Scalar1, 0, 0, 0, | 87 0, SK_Scalar1, 0, 0, 0, |
88 0, 0, SK_Scalar1, 0, 0, | 88 0, 0, SK_Scalar1, 0, 0, |
89 0, 0, 0, SK_Scalar1, 0 }; | 89 0, 0, 0, SK_Scalar1, 0 }; |
90 | 90 |
91 SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()), | 91 SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()), |
92 SkIntToScalar(fBitmap->height())); | 92 SkIntToScalar(fBitmap->height())); |
93 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2), | 93 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2), |
94 SkIntToScalar(fBitmap->height() * 2)); | 94 SkIntToScalar(fBitmap->height() * 2)); |
95 SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstR
ect, nullptr)); | 95 SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstR
ect, nullptr)); |
96 SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(matrix)); | 96 auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); |
97 | 97 |
98 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf, ti
le.get())); | 98 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get
(), tile.get())); |
99 SkPaint paint; | 99 SkPaint paint; |
100 paint.setImageFilter(cfif); | 100 paint.setImageFilter(cfif); |
101 canvas->save(); | 101 canvas->save(); |
102 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 102 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
103 canvas->clipRect(dstRect); | 103 canvas->clipRect(dstRect); |
104 canvas->saveLayer(&dstRect, &paint); | 104 canvas->saveLayer(&dstRect, &paint); |
105 canvas->drawImage(fBitmap.get(), 0, 0); | 105 canvas->drawImage(fBitmap.get(), 0, 0); |
106 canvas->restore(); | 106 canvas->restore(); |
107 canvas->drawRect(srcRect, red); | 107 canvas->drawRect(srcRect, red); |
108 canvas->drawRect(dstRect, blue); | 108 canvas->drawRect(dstRect, blue); |
109 canvas->restore(); | 109 canvas->restore(); |
110 } | 110 } |
111 private: | 111 private: |
112 sk_sp<SkImage> fBitmap, fCheckerboard; | 112 sk_sp<SkImage> fBitmap, fCheckerboard; |
113 | 113 |
114 typedef GM INHERITED; | 114 typedef GM INHERITED; |
115 }; | 115 }; |
116 | 116 |
117 ////////////////////////////////////////////////////////////////////////////// | 117 ////////////////////////////////////////////////////////////////////////////// |
118 | 118 |
119 DEF_GM(return new TileImageFilterGM;) | 119 DEF_GM(return new TileImageFilterGM;) |
120 } | 120 } |
OLD | NEW |