Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: gm/imagefiltersgraph.cpp

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 133 {
134 SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5)) ; 134 SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5)) ;
135 135
136 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 136 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
137 0, SK_Scalar1, 0, 0, 0, 137 0, SK_Scalar1, 0, 0, 0,
138 0, 0, SK_Scalar1, 0, 0, 138 0, 0, SK_Scalar1, 0, 0,
139 0, 0, 0, 0.5f, 0 }; 139 0, 0, 0, 0.5f, 0 };
140 140
141 auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix) ); 141 auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix) );
142 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre ate(matrixFilter.get(), morph)); 142 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre ate(matrixFilter.get(), morph));
143 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve r_Mode)); 143 SkPaint paint;
144 SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create (mode, colorMorph)); 144 paint.setImageFilter(SkXfermodeImageFilter::Make(
145 SkXfermode::Make(SkXfermode::kSrcOver_Mo de), colorMorph));
145 146
146 SkPaint paint;
147 paint.setImageFilter(blendColor);
148 DrawClippedImage(canvas, fImage.get(), paint); 147 DrawClippedImage(canvas, fImage.get(), paint);
149 canvas->translate(SkIntToScalar(100), 0); 148 canvas->translate(SkIntToScalar(100), 0);
150 } 149 }
151 { 150 {
152 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 151 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
153 0, SK_Scalar1, 0, 0, 0, 152 0, SK_Scalar1, 0, 0, 0,
154 0, 0, SK_Scalar1, 0, 0, 153 0, 0, SK_Scalar1, 0, 0,
155 0, 0, 0, 0.5f, 0 }; 154 0, 0, 0, 0.5f, 0 };
156 auto matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); 155 auto matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
157 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C reate(matrixCF.get())); 156 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C reate(matrixCF.get()));
158 SkAutoTUnref<SkImageFilter> offsetFilter( 157 SkAutoTUnref<SkImageFilter> offsetFilter(
159 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter)); 158 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter));
160 159
161 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar 1, SK_Scalar1, 0)); 160 SkPaint paint;
162 SkAutoTUnref<SkImageFilter> arithFilter( 161 paint.setImageFilter(
163 SkXfermodeImageFilter::Create(arith, matrixFilter, offsetFilter) ); 162 SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1 , SK_Scalar1, 0),
163 matrixFilter, offsetFilter, nullptr) );
164 164
165 SkPaint paint;
166 paint.setImageFilter(arithFilter);
167 DrawClippedImage(canvas, fImage.get(), paint); 165 DrawClippedImage(canvas, fImage.get(), paint);
168 canvas->translate(SkIntToScalar(100), 0); 166 canvas->translate(SkIntToScalar(100), 0);
169 } 167 }
170 { 168 {
171 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create( 169 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(
172 SkIntToScalar(10), SkIntToScalar(10))); 170 SkIntToScalar(10), SkIntToScalar(10)));
173 171
174 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_ Mode));
175 SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), S kIntToScalar(100))); 172 SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), S kIntToScalar(100)));
176 SkAutoTUnref<SkImageFilter> blend(
177 SkXfermodeImageFilter::Create(mode, blur, nullptr, &cropRect));
178
179 SkPaint paint; 173 SkPaint paint;
180 paint.setImageFilter(blend); 174 paint.setImageFilter(
175 SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcIn_ Mode), blur,
176 nullptr, &cropRect));
181 DrawClippedImage(canvas, fImage.get(), paint); 177 DrawClippedImage(canvas, fImage.get(), paint);
182 canvas->translate(SkIntToScalar(100), 0); 178 canvas->translate(SkIntToScalar(100), 0);
183 } 179 }
184 { 180 {
185 // Dilate -> matrix convolution. 181 // Dilate -> matrix convolution.
186 // This tests that a filter using asFragmentProcessor (matrix 182 // This tests that a filter using asFragmentProcessor (matrix
187 // convolution) correctly handles a non-zero source offset 183 // convolution) correctly handles a non-zero source offset
188 // (supplied by the dilate). 184 // (supplied by the dilate).
189 SkAutoTUnref<SkImageFilter> dilate(SkDilateImageFilter::Create(5, 5) ); 185 SkAutoTUnref<SkImageFilter> dilate(SkDilateImageFilter::Create(5, 5) );
190 186
191 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_ Mode));
192
193 SkScalar kernel[9] = { 187 SkScalar kernel[9] = {
194 SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), 188 SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
195 SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1), 189 SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1),
196 SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), 190 SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
197 }; 191 };
198 SkISize kernelSize = SkISize::Make(3, 3); 192 SkISize kernelSize = SkISize::Make(3, 3);
199 SkScalar gain = 1.0f, bias = SkIntToScalar(0); 193 SkScalar gain = 1.0f, bias = SkIntToScalar(0);
200 SkIPoint kernelOffset = SkIPoint::Make(1, 1); 194 SkIPoint kernelOffset = SkIPoint::Make(1, 1);
201 auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode; 195 auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode;
202 bool convolveAlpha = false; 196 bool convolveAlpha = false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 237 }
244 238
245 sk_sp<SkImage> fImage; 239 sk_sp<SkImage> fImage;
246 240
247 typedef GM INHERITED; 241 typedef GM INHERITED;
248 }; 242 };
249 243
250 /////////////////////////////////////////////////////////////////////////////// 244 ///////////////////////////////////////////////////////////////////////////////
251 245
252 DEF_GM(return new ImageFiltersGraphGM;) 246 DEF_GM(return new ImageFiltersGraphGM;)
OLDNEW
« no previous file with comments | « gm/hairmodes.cpp ('k') | gm/lcdblendmodes.cpp » ('j') | include/effects/SkXfermodeImageFilter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698