| 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "sk_tool_utils.h" | 9 #include "sk_tool_utils.h" |
| 10 #include "SkArithmeticMode.h" | 10 #include "SkArithmeticMode.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 { SkXfermode::kMultiply_Mode, "Multiply" }, | 80 { SkXfermode::kMultiply_Mode, "Multiply" }, |
| 81 { SkXfermode::kHue_Mode, "Hue" }, | 81 { SkXfermode::kHue_Mode, "Hue" }, |
| 82 { SkXfermode::kSaturation_Mode, "Saturation" }, | 82 { SkXfermode::kSaturation_Mode, "Saturation" }, |
| 83 { SkXfermode::kColor_Mode, "Color" }, | 83 { SkXfermode::kColor_Mode, "Color" }, |
| 84 { SkXfermode::kLuminosity_Mode, "Luminosity" }, | 84 { SkXfermode::kLuminosity_Mode, "Luminosity" }, |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 int x = 0, y = 0; | 87 int x = 0, y = 0; |
| 88 SkAutoTUnref<SkImageFilter> background(SkImageSource::Create(fCheckerboa
rd.get())); | 88 SkAutoTUnref<SkImageFilter> background(SkImageSource::Create(fCheckerboa
rd.get())); |
| 89 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { | 89 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
| 90 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); | 90 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gM
odes[i].fMode), |
| 91 SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mod
e, background)); | 91 background)); |
| 92 paint.setImageFilter(filter); | |
| 93 DrawClippedBitmap(canvas, fBitmap, paint, x, y); | 92 DrawClippedBitmap(canvas, fBitmap, paint, x, y); |
| 94 x += fBitmap.width() + MARGIN; | 93 x += fBitmap.width() + MARGIN; |
| 95 if (x + fBitmap.width() > WIDTH) { | 94 if (x + fBitmap.width() > WIDTH) { |
| 96 x = 0; | 95 x = 0; |
| 97 y += fBitmap.height() + MARGIN; | 96 y += fBitmap.height() + MARGIN; |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 // Test arithmetic mode as image filter | 99 // Test arithmetic mode as image filter |
| 101 SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK
_Scalar1, 0)); | 100 paint.setImageFilter(SkXfermodeImageFilter::Make( |
| 102 SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mode, b
ackground)); | 101 SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), b
ackground)); |
| 103 paint.setImageFilter(filter); | |
| 104 DrawClippedBitmap(canvas, fBitmap, paint, x, y); | 102 DrawClippedBitmap(canvas, fBitmap, paint, x, y); |
| 105 x += fBitmap.width() + MARGIN; | 103 x += fBitmap.width() + MARGIN; |
| 106 if (x + fBitmap.width() > WIDTH) { | 104 if (x + fBitmap.width() > WIDTH) { |
| 107 x = 0; | 105 x = 0; |
| 108 y += fBitmap.height() + MARGIN; | 106 y += fBitmap.height() + MARGIN; |
| 109 } | 107 } |
| 110 // Test nullptr mode | 108 // Test nullptr mode |
| 111 filter.reset(SkXfermodeImageFilter::Create(nullptr, background)); | 109 paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background)); |
| 112 paint.setImageFilter(filter); | |
| 113 DrawClippedBitmap(canvas, fBitmap, paint, x, y); | 110 DrawClippedBitmap(canvas, fBitmap, paint, x, y); |
| 114 x += fBitmap.width() + MARGIN; | 111 x += fBitmap.width() + MARGIN; |
| 115 if (x + fBitmap.width() > WIDTH) { | 112 if (x + fBitmap.width() > WIDTH) { |
| 116 x = 0; | 113 x = 0; |
| 117 y += fBitmap.height() + MARGIN; | 114 y += fBitmap.height() + MARGIN; |
| 118 } | 115 } |
| 119 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), | 116 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), |
| 120 SkIntToScalar(fBitmap.height() + 4)); | 117 SkIntToScalar(fBitmap.height() + 4)); |
| 121 // Test offsets on SrcMode (uses fixed-function blend) | 118 // Test offsets on SrcMode (uses fixed-function blend) |
| 122 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap)); | 119 sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap)); |
| 123 SkAutoTUnref<SkImageFilter> foreground(SkImageSource::Create(bitmapImage
.get())); | 120 SkAutoTUnref<SkImageFilter> foreground(SkImageSource::Create(bitmapImage
.get())); |
| 124 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create
( | 121 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create
( |
| 125 SkIntToScalar(4), SkIntToScalar(-4), foreground)); | 122 SkIntToScalar(4), SkIntToScalar(-4), foreground)); |
| 126 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create
( | 123 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create
( |
| 127 SkIntToScalar(4), SkIntToScalar(4), background)); | 124 SkIntToScalar(4), SkIntToScalar(4), background)); |
| 128 mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); | 125 paint.setImageFilter(SkXfermodeImageFilter::Make( |
| 129 filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offse
tForeground)); | 126 SkXfermode::Make(SkXfermode::kSrcOver_Mode), offsetBackground, |
| 130 paint.setImageFilter(filter); | 127 offsetForeground, nullptr)); |
| 131 DrawClippedPaint(canvas, clipRect, paint, x, y); | 128 DrawClippedPaint(canvas, clipRect, paint, x, y); |
| 132 x += fBitmap.width() + MARGIN; | 129 x += fBitmap.width() + MARGIN; |
| 133 if (x + fBitmap.width() > WIDTH) { | 130 if (x + fBitmap.width() > WIDTH) { |
| 134 x = 0; | 131 x = 0; |
| 135 y += fBitmap.height() + MARGIN; | 132 y += fBitmap.height() + MARGIN; |
| 136 } | 133 } |
| 137 // Test offsets on Darken (uses shader blend) | 134 // Test offsets on Darken (uses shader blend) |
| 138 mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); | 135 paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfer
mode::kDarken_Mode), |
| 139 filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offse
tForeground)); | 136 offsetBackground, offsetFor
eground, nullptr)); |
| 140 paint.setImageFilter(filter); | |
| 141 DrawClippedPaint(canvas, clipRect, paint, x, y); | 137 DrawClippedPaint(canvas, clipRect, paint, x, y); |
| 142 x += fBitmap.width() + MARGIN; | 138 x += fBitmap.width() + MARGIN; |
| 143 if (x + fBitmap.width() > WIDTH) { | 139 if (x + fBitmap.width() > WIDTH) { |
| 144 x = 0; | 140 x = 0; |
| 145 y += fBitmap.height() + MARGIN; | 141 y += fBitmap.height() + MARGIN; |
| 146 } | 142 } |
| 147 // Test cropping | 143 // Test cropping |
| 148 static const size_t nbSamples = 3; | 144 static const size_t nbSamples = 3; |
| 149 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, | 145 SkXfermode::Mode sampledModes[nbSamples] = {SkXfermode::kOverlay_Mode, |
| 150 SkXfermode::kSrcOver_Mode, | 146 SkXfermode::kSrcOver_Mode, |
| 151 SkXfermode::kPlus_Mode}; | 147 SkXfermode::kPlus_Mode}; |
| 152 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, | 148 int offsets[nbSamples][4] = {{ 10, 10, -16, -16}, |
| 153 { 10, 10, 10, 10}, | 149 { 10, 10, 10, 10}, |
| 154 {-10, -10, -6, -6}}; | 150 {-10, -10, -6, -6}}; |
| 155 for (size_t i = 0; i < nbSamples; ++i) { | 151 for (size_t i = 0; i < nbSamples; ++i) { |
| 156 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], | 152 SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], |
| 157 offsets[i][1], | 153 offsets[i][1], |
| 158 fBitmap.width() + offsets[i][2
], | 154 fBitmap.width() + offsets[i][2
], |
| 159 fBitmap.height() + offsets[i][3
]); | 155 fBitmap.height() + offsets[i][3
]); |
| 160 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); | 156 SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
| 161 mode.reset(SkXfermode::Create(sampledModes[i])); | 157 paint.setImageFilter(SkXfermodeImageFilter::Make( |
| 162 filter.reset(SkXfermodeImageFilter::Create( | 158 SkXfermode::Make(sampledModes[i]), offsetBackground, offsetF
oreground, &rect)); |
| 163 mode, offsetBackground, offsetForeground, &r
ect)); | |
| 164 paint.setImageFilter(filter); | |
| 165 DrawClippedPaint(canvas, clipRect, paint, x, y); | 159 DrawClippedPaint(canvas, clipRect, paint, x, y); |
| 166 x += fBitmap.width() + MARGIN; | 160 x += fBitmap.width() + MARGIN; |
| 167 if (x + fBitmap.width() > WIDTH) { | 161 if (x + fBitmap.width() > WIDTH) { |
| 168 x = 0; | 162 x = 0; |
| 169 y += fBitmap.height() + MARGIN; | 163 y += fBitmap.height() + MARGIN; |
| 170 } | 164 } |
| 171 } | 165 } |
| 172 // Test small bg, large fg with Screen (uses shader blend) | 166 // Test small bg, large fg with Screen (uses shader blend) |
| 173 mode.reset(SkXfermode::Create(SkXfermode::kScreen_Mode)); | 167 auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode); |
| 174 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); | 168 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); |
| 175 SkAutoTUnref<SkImageFilter> cropped( | 169 SkAutoTUnref<SkImageFilter> cropped( |
| 176 SkOffsetImageFilter::Create(0, 0, foreground, &cropRect)); | 170 SkOffsetImageFilter::Create(0, 0, foreground, &cropRect)); |
| 177 filter.reset(SkXfermodeImageFilter::Create(mode, cropped, background)); | 171 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, backgrou
nd, nullptr)); |
| 178 paint.setImageFilter(filter); | |
| 179 DrawClippedPaint(canvas, clipRect, paint, x, y); | 172 DrawClippedPaint(canvas, clipRect, paint, x, y); |
| 180 x += fBitmap.width() + MARGIN; | 173 x += fBitmap.width() + MARGIN; |
| 181 if (x + fBitmap.width() > WIDTH) { | 174 if (x + fBitmap.width() > WIDTH) { |
| 182 x = 0; | 175 x = 0; |
| 183 y += fBitmap.height() + MARGIN; | 176 y += fBitmap.height() + MARGIN; |
| 184 } | 177 } |
| 185 // Test small fg, large bg with Screen (uses shader blend) | 178 // Test small fg, large bg with Screen (uses shader blend) |
| 186 filter.reset(SkXfermodeImageFilter::Create(mode, background, cropped)); | 179 paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropp
ed, nullptr)); |
| 187 paint.setImageFilter(filter); | |
| 188 DrawClippedPaint(canvas, clipRect, paint, x, y); | 180 DrawClippedPaint(canvas, clipRect, paint, x, y); |
| 189 x += fBitmap.width() + MARGIN; | 181 x += fBitmap.width() + MARGIN; |
| 190 if (x + fBitmap.width() > WIDTH) { | 182 if (x + fBitmap.width() > WIDTH) { |
| 191 x = 0; | 183 x = 0; |
| 192 y += fBitmap.height() + MARGIN; | 184 y += fBitmap.height() + MARGIN; |
| 193 } | 185 } |
| 194 } | 186 } |
| 195 | 187 |
| 196 private: | 188 private: |
| 197 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons
t SkPaint& paint, | 189 static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons
t SkPaint& paint, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 217 sk_sp<SkImage> fCheckerboard; | 209 sk_sp<SkImage> fCheckerboard; |
| 218 | 210 |
| 219 typedef GM INHERITED; | 211 typedef GM INHERITED; |
| 220 }; | 212 }; |
| 221 | 213 |
| 222 ////////////////////////////////////////////////////////////////////////////// | 214 ////////////////////////////////////////////////////////////////////////////// |
| 223 | 215 |
| 224 DEF_GM( return new XfermodeImageFilterGM; ); | 216 DEF_GM( return new XfermodeImageFilterGM; ); |
| 225 | 217 |
| 226 } | 218 } |
| OLD | NEW |