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

Side by Side Diff: gm/imagefiltersgraph.cpp

Issue 1820303002: Revert of switch colorfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « gm/imagefilterscropped.cpp ('k') | gm/lumafilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 void onOnceBeforeDraw() override { 113 void onOnceBeforeDraw() override {
114 fImage = SkImage::MakeFromBitmap( 114 fImage = SkImage::MakeFromBitmap(
115 sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70, 96, "e")); 115 sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70, 96, "e"));
116 } 116 }
117 117
118 void onDraw(SkCanvas* canvas) override { 118 void onDraw(SkCanvas* canvas) override {
119 canvas->clear(SK_ColorBLACK); 119 canvas->clear(SK_ColorBLACK);
120 { 120 {
121 SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImag e.get())); 121 SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImag e.get()));
122 auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcI n_Mode)); 122 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co lorRED,
123 SkXfermode::kSrcIn_Mode ));
123 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0 f, bitmapSource)); 124 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0 f, bitmapSource));
124 SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, b lur)); 125 SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, b lur));
125 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c f.get(), erode)); 126 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c f, erode));
126 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, c olor)); 127 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, c olor));
127 128
128 SkPaint paint; 129 SkPaint paint;
129 paint.setImageFilter(merge); 130 paint.setImageFilter(merge);
130 canvas->drawPaint(paint); 131 canvas->drawPaint(paint);
131 canvas->translate(SkIntToScalar(100), 0); 132 canvas->translate(SkIntToScalar(100), 0);
132 } 133 }
133 { 134 {
134 SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5)) ; 135 SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5)) ;
135 136
136 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 137 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
137 0, SK_Scalar1, 0, 0, 0, 138 0, SK_Scalar1, 0, 0, 0,
138 0, 0, SK_Scalar1, 0, 0, 139 0, 0, SK_Scalar1, 0, 0,
139 0, 0, 0, 0.5f, 0 }; 140 0, 0, 0, 0.5f, 0 };
140 141
141 auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix) ); 142 SkAutoTUnref<SkColorFilter> matrixFilter(SkColorMatrixFilter::Create (matrix));
142 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre ate(matrixFilter.get(), morph)); 143 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre ate(matrixFilter, morph));
143 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve r_Mode)); 144 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve r_Mode));
144 SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create (mode, colorMorph)); 145 SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create (mode, colorMorph));
145 146
146 SkPaint paint; 147 SkPaint paint;
147 paint.setImageFilter(blendColor); 148 paint.setImageFilter(blendColor);
148 DrawClippedImage(canvas, fImage.get(), paint); 149 DrawClippedImage(canvas, fImage.get(), paint);
149 canvas->translate(SkIntToScalar(100), 0); 150 canvas->translate(SkIntToScalar(100), 0);
150 } 151 }
151 { 152 {
152 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 153 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
153 0, SK_Scalar1, 0, 0, 0, 154 0, SK_Scalar1, 0, 0, 0,
154 0, 0, SK_Scalar1, 0, 0, 155 0, 0, SK_Scalar1, 0, 0,
155 0, 0, 0, 0.5f, 0 }; 156 0, 0, 0, 0.5f, 0 };
156 auto matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); 157 SkAutoTUnref<SkColorFilter> matrixCF(SkColorMatrixFilter::Create(mat rix));
157 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C reate(matrixCF.get())); 158 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C reate(matrixCF));
158 SkAutoTUnref<SkImageFilter> offsetFilter( 159 SkAutoTUnref<SkImageFilter> offsetFilter(
159 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter)); 160 SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter));
160 161
161 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar 1, SK_Scalar1, 0)); 162 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar 1, SK_Scalar1, 0));
162 SkAutoTUnref<SkImageFilter> arithFilter( 163 SkAutoTUnref<SkImageFilter> arithFilter(
163 SkXfermodeImageFilter::Create(arith, matrixFilter, offsetFilter) ); 164 SkXfermodeImageFilter::Create(arith, matrixFilter, offsetFilter) );
164 165
165 SkPaint paint; 166 SkPaint paint;
166 paint.setImageFilter(arithFilter); 167 paint.setImageFilter(arithFilter);
167 DrawClippedImage(canvas, fImage.get(), paint); 168 DrawClippedImage(canvas, fImage.get(), paint);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 convolveAlpha, 211 convolveAlpha,
211 dilate)); 212 dilate));
212 213
213 SkPaint paint; 214 SkPaint paint;
214 paint.setImageFilter(convolve); 215 paint.setImageFilter(convolve);
215 DrawClippedImage(canvas, fImage.get(), paint); 216 DrawClippedImage(canvas, fImage.get(), paint);
216 canvas->translate(SkIntToScalar(100), 0); 217 canvas->translate(SkIntToScalar(100), 0);
217 } 218 }
218 { 219 {
219 // Test that crop offsets are absolute, not relative to the parent's crop rect. 220 // Test that crop offsets are absolute, not relative to the parent's crop rect.
220 auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSr cIn_Mode)); 221 SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_C olorBLUE,
221 auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kS rcIn_Mode)); 222 SkXf ermode::kSrcIn_Mode));
223 SkAutoTUnref<SkColorFilter> cf2(SkColorFilter::CreateModeFilter(SK_C olorGREEN,
224 SkXf ermode::kSrcIn_Mode));
222 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10) , SkIntToScalar(10), 225 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10) , SkIntToScalar(10),
223 SkIntToScalar(80) , SkIntToScalar(80))); 226 SkIntToScalar(80) , SkIntToScalar(80)));
224 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20) , SkIntToScalar(20), 227 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20) , SkIntToScalar(20),
225 SkIntToScalar(60) , SkIntToScalar(60))); 228 SkIntToScalar(60) , SkIntToScalar(60)));
226 SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create( cf1.get(), nullptr, &outerRect)); 229 SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create( cf1, nullptr, &outerRect));
227 SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create( cf2.get(), color1, &innerRect)); 230 SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create( cf2, color1, &innerRect));
228 231
229 SkPaint paint; 232 SkPaint paint;
230 paint.setImageFilter(color2); 233 paint.setImageFilter(color2);
231 paint.setColor(SK_ColorRED); 234 paint.setColor(SK_ColorRED);
232 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); 235 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
233 canvas->translate(SkIntToScalar(100), 0); 236 canvas->translate(SkIntToScalar(100), 0);
234 } 237 }
235 } 238 }
236 239
237 private: 240 private:
238 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S kPaint& paint) { 241 static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const S kPaint& paint) {
239 canvas->save(); 242 canvas->save();
240 canvas->clipRect(SkRect::MakeIWH(image->width(), image->height())); 243 canvas->clipRect(SkRect::MakeIWH(image->width(), image->height()));
241 canvas->drawImage(image, 0, 0, &paint); 244 canvas->drawImage(image, 0, 0, &paint);
242 canvas->restore(); 245 canvas->restore();
243 } 246 }
244 247
245 sk_sp<SkImage> fImage; 248 sk_sp<SkImage> fImage;
246 249
247 typedef GM INHERITED; 250 typedef GM INHERITED;
248 }; 251 };
249 252
250 /////////////////////////////////////////////////////////////////////////////// 253 ///////////////////////////////////////////////////////////////////////////////
251 254
252 DEF_GM(return new ImageFiltersGraphGM;) 255 DEF_GM(return new ImageFiltersGraphGM;)
OLDNEW
« no previous file with comments | « gm/imagefilterscropped.cpp ('k') | gm/lumafilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698