| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "gm.h" | 8 #include "gm.h" |
| 9 | 9 |
| 10 #include "SkArithmeticMode.h" | 10 #include "SkArithmeticMode.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 130 } |
| 131 | 131 |
| 132 void onDraw(SkCanvas* canvas) override { | 132 void onDraw(SkCanvas* canvas) override { |
| 133 canvas->clear(SK_ColorBLACK); | 133 canvas->clear(SK_ColorBLACK); |
| 134 { | 134 { |
| 135 sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage)); | 135 sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage)); |
| 136 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, | 136 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, |
| 137 SkXfermode::kS
rcIn_Mode)); | 137 SkXfermode::kS
rcIn_Mode)); |
| 138 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::m
ove(bitmapSource))); | 138 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::m
ove(bitmapSource))); |
| 139 sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur)); | 139 sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur)); |
| 140 sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Create(cf.get()
, erode.get())); | 140 sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(
cf), |
| 141 std::move(
erode))); |
| 141 sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color)); | 142 sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color)); |
| 142 | 143 |
| 143 SkPaint paint; | 144 SkPaint paint; |
| 144 paint.setImageFilter(std::move(merge)); | 145 paint.setImageFilter(std::move(merge)); |
| 145 canvas->drawPaint(paint); | 146 canvas->drawPaint(paint); |
| 146 canvas->translate(SkIntToScalar(100), 0); | 147 canvas->translate(SkIntToScalar(100), 0); |
| 147 } | 148 } |
| 148 { | 149 { |
| 149 sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr))
; | 150 sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr))
; |
| 150 | 151 |
| 151 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 152 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
| 152 0, SK_Scalar1, 0, 0, 0, | 153 0, SK_Scalar1, 0, 0, 0, |
| 153 0, 0, SK_Scalar1, 0, 0, | 154 0, 0, SK_Scalar1, 0, 0, |
| 154 0, 0, 0, 0.5f, 0 }; | 155 0, 0, 0, 0.5f, 0 }; |
| 155 | 156 |
| 156 sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRow
Major255(matrix)); | 157 sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRow
Major255(matrix)); |
| 157 sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(mat
rixFilter.get(), | 158 sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::
move(matrixFilter), |
| 158 mor
ph.get())); | 159 std::
move(morph))); |
| 159 SkPaint paint; | 160 SkPaint paint; |
| 160 paint.setImageFilter(SkXfermodeImageFilter::Make( | 161 paint.setImageFilter(SkXfermodeImageFilter::Make( |
| 161 SkXfermode::Make(SkXfermode::kSrcOver_Mo
de), | 162 SkXfermode::Make(SkXfermode::kSrcOver_Mo
de), |
| 162 colorMorph.get())); | 163 colorMorph.get())); |
| 163 | 164 |
| 164 DrawClippedImage(canvas, fImage.get(), paint); | 165 DrawClippedImage(canvas, fImage.get(), paint); |
| 165 canvas->translate(SkIntToScalar(100), 0); | 166 canvas->translate(SkIntToScalar(100), 0); |
| 166 } | 167 } |
| 167 { | 168 { |
| 168 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 169 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
| 169 0, SK_Scalar1, 0, 0, 0, | 170 0, SK_Scalar1, 0, 0, 0, |
| 170 0, 0, SK_Scalar1, 0, 0, | 171 0, 0, SK_Scalar1, 0, 0, |
| 171 0, 0, 0, 0.5f, 0 }; | 172 0, 0, 0, 0.5f, 0 }; |
| 172 sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajo
r255(matrix)); | 173 sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajo
r255(matrix)); |
| 173 sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(m
atrixCF.get())); | 174 sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std
::move(matrixCF), |
| 175 nul
lptr)); |
| 174 sk_sp<SkImageFilter> offsetFilter(SimpleOffsetFilter::Make(10.0f, 10
.f, matrixFilter)); | 176 sk_sp<SkImageFilter> offsetFilter(SimpleOffsetFilter::Make(10.0f, 10
.f, matrixFilter)); |
| 175 | 177 |
| 176 SkPaint paint; | 178 SkPaint paint; |
| 177 paint.setImageFilter( | 179 paint.setImageFilter( |
| 178 SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1
, SK_Scalar1, 0), | 180 SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1
, SK_Scalar1, 0), |
| 179 matrixFilter.get(), offsetFilter.get
(), nullptr)); | 181 matrixFilter.get(), offsetFilter.get
(), nullptr)); |
| 180 | 182 |
| 181 DrawClippedImage(canvas, fImage.get(), paint); | 183 DrawClippedImage(canvas, fImage.get(), paint); |
| 182 canvas->translate(SkIntToScalar(100), 0); | 184 canvas->translate(SkIntToScalar(100), 0); |
| 183 } | 185 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 convolveAlpha, | 223 convolveAlpha, |
| 222 dilate.get())); | 224 dilate.get())); |
| 223 | 225 |
| 224 SkPaint paint; | 226 SkPaint paint; |
| 225 paint.setImageFilter(std::move(convolve)); | 227 paint.setImageFilter(std::move(convolve)); |
| 226 DrawClippedImage(canvas, fImage.get(), paint); | 228 DrawClippedImage(canvas, fImage.get(), paint); |
| 227 canvas->translate(SkIntToScalar(100), 0); | 229 canvas->translate(SkIntToScalar(100), 0); |
| 228 } | 230 } |
| 229 { | 231 { |
| 230 // Test that crop offsets are absolute, not relative to the parent's
crop rect. | 232 // Test that crop offsets are absolute, not relative to the parent's
crop rect. |
| 231 auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSr
cIn_Mode)); | 233 sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, |
| 232 auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kS
rcIn_Mode)); | 234 SkXfermode::k
SrcIn_Mode)); |
| 235 sk_sp<SkColorFilter> cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN
, |
| 236 SkXfermode::k
SrcIn_Mode)); |
| 233 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10)
, SkIntToScalar(10), | 237 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10)
, SkIntToScalar(10), |
| 234 SkIntToScalar(80)
, SkIntToScalar(80))); | 238 SkIntToScalar(80)
, SkIntToScalar(80))); |
| 235 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20)
, SkIntToScalar(20), | 239 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20)
, SkIntToScalar(20), |
| 236 SkIntToScalar(60)
, SkIntToScalar(60))); | 240 SkIntToScalar(60)
, SkIntToScalar(60))); |
| 237 sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get
(), | 241 sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move
(cf1), |
| 238 nullptr
, | 242 nullptr, |
| 239 &outerR
ect)); | 243 &outerRec
t)); |
| 240 sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get
(), | 244 sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move
(cf2), |
| 241 color1.
get(), | 245 std::move
(color1), |
| 242 &innerR
ect)); | 246 &innerRec
t)); |
| 243 | 247 |
| 244 SkPaint paint; | 248 SkPaint paint; |
| 245 paint.setImageFilter(std::move(color2)); | 249 paint.setImageFilter(std::move(color2)); |
| 246 paint.setColor(SK_ColorRED); | 250 paint.setColor(SK_ColorRED); |
| 247 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); | 251 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); |
| 248 canvas->translate(SkIntToScalar(100), 0); | 252 canvas->translate(SkIntToScalar(100), 0); |
| 249 } | 253 } |
| 250 } | 254 } |
| 251 | 255 |
| 252 private: | 256 private: |
| 253 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S
kPaint& paint) { | 257 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S
kPaint& paint) { |
| 254 canvas->save(); | 258 canvas->save(); |
| 255 canvas->clipRect(SkRect::MakeIWH(image->width(), image->height())); | 259 canvas->clipRect(SkRect::MakeIWH(image->width(), image->height())); |
| 256 canvas->drawImage(image, 0, 0, &paint); | 260 canvas->drawImage(image, 0, 0, &paint); |
| 257 canvas->restore(); | 261 canvas->restore(); |
| 258 } | 262 } |
| 259 | 263 |
| 260 sk_sp<SkImage> fImage; | 264 sk_sp<SkImage> fImage; |
| 261 | 265 |
| 262 typedef GM INHERITED; | 266 typedef GM INHERITED; |
| 263 }; | 267 }; |
| 264 | 268 |
| 265 /////////////////////////////////////////////////////////////////////////////// | 269 /////////////////////////////////////////////////////////////////////////////// |
| 266 | 270 |
| 267 DEF_GM(return new ImageFiltersGraphGM;) | 271 DEF_GM(return new ImageFiltersGraphGM;) |
| OLD | NEW |