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

Side by Side Diff: gm/megalooper.cpp

Issue 1852113003: switch maskfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « gm/largeglyphblur.cpp ('k') | gm/rects.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 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 "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 kHalfOuterClipSize+kHalfSquareSize, kHalfOuterClipSize+kHalfSquare Size 89 kHalfOuterClipSize+kHalfSquareSize, kHalfOuterClipSize+kHalfSquare Size
90 }; 90 };
91 outerClip.offset(x, y); 91 outerClip.offset(x, y);
92 92
93 canvas->save(); 93 canvas->save();
94 canvas->clipRect(outerClip, SkRegion::kIntersect_Op); 94 canvas->clipRect(outerClip, SkRegion::kIntersect_Op);
95 canvas->clipRect(innerClip, SkRegion::kDifference_Op); 95 canvas->clipRect(innerClip, SkRegion::kDifference_Op);
96 96
97 SkPaint paint; 97 SkPaint paint;
98 paint.setAntiAlias(true); 98 paint.setAntiAlias(true);
99 paint.setMaskFilter(createBlur())->unref(); 99 paint.setMaskFilter(MakeBlur());
100 100
101 for (int i = 0; i < 4; ++i) { 101 for (int i = 0; i < 4; ++i) {
102 paint.setColor(gColors[i]); 102 paint.setColor(gColors[i]);
103 103
104 SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHalfSquareSize }; 104 SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHalfSquareSize };
105 rect.offset(gBlurOffsets[i]); 105 rect.offset(gBlurOffsets[i]);
106 rect.offset(x, y); 106 rect.offset(x, y);
107 canvas->drawRect(rect, paint); 107 canvas->drawRect(rect, paint);
108 } 108 }
109 109
110 canvas->restore(); 110 canvas->restore();
111 } 111 }
112 112
113 SkMaskFilter* createBlur() { 113 static sk_sp<SkMaskFilter> MakeBlur() {
114 static const SkScalar kBlurSigma = SkBlurMask::ConvertRadiusToSigma(SkIn tToScalar(25)); 114 static const SkScalar kBlurSigma = SkBlurMask::ConvertRadiusToSigma(SkIn tToScalar(25));
115 115
116 return SkBlurMaskFilter::Create(kNormal_SkBlurStyle, kBlurSigma, 116 return SkBlurMaskFilter::Make(kNormal_SkBlurStyle, kBlurSigma,
117 SkBlurMaskFilter::kHighQuality_BlurFlag) ; 117 SkBlurMaskFilter::kHighQuality_BlurFlag);
118 } 118 }
119 119
120 // This draws 4 blurred shadows around a single square (centered at x, y). 120 // This draws 4 blurred shadows around a single square (centered at x, y).
121 // Each blur is offset +/- half the square's side in x & y from the original 121 // Each blur is offset +/- half the square's side in x & y from the original
122 // (so each blurred rect is centered at one of the corners of the original). 122 // (so each blurred rect is centered at one of the corners of the original).
123 // For each blur a large outer clip is centered around the blurred rect 123 // For each blur a large outer clip is centered around the blurred rect
124 // while a difference clip stays at the location of the original rect. 124 // while a difference clip stays at the location of the original rect.
125 // Each blurred rect is drawn with a draw looper where the original (non- 125 // Each blurred rect is drawn with a draw looper where the original (non-
126 // blurred rect) is offset to reside outside of the large outer clip (so 126 // blurred rect) is offset to reside outside of the large outer clip (so
127 // it never appears) but the offset in the draw looper is used to translate 127 // it never appears) but the offset in the draw looper is used to translate
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 SkLayerDrawLooper::LayerInfo info; 166 SkLayerDrawLooper::LayerInfo info;
167 167
168 info.fPaintBits = SkLayerDrawLooper::kColorFilter_Bit | 168 info.fPaintBits = SkLayerDrawLooper::kColorFilter_Bit |
169 SkLayerDrawLooper::kMaskFilter_Bit; 169 SkLayerDrawLooper::kMaskFilter_Bit;
170 info.fColorMode = SkXfermode::kSrc_Mode; 170 info.fColorMode = SkXfermode::kSrc_Mode;
171 info.fOffset.set(xOff, yOff); 171 info.fOffset.set(xOff, yOff);
172 info.fPostTranslate = false; 172 info.fPostTranslate = false;
173 173
174 SkPaint* paint = looperBuilder.addLayer(info); 174 SkPaint* paint = looperBuilder.addLayer(info);
175 175
176 paint->setMaskFilter(this->createBlur())->unref(); 176 paint->setMaskFilter(MakeBlur());
177 177
178 paint->setColorFilter(SkColorFilter::MakeModeFilter(color, SkXfermode::k SrcIn_Mode)); 178 paint->setColorFilter(SkColorFilter::MakeModeFilter(color, SkXfermode::k SrcIn_Mode));
179 179
180 return looperBuilder.detach(); 180 return looperBuilder.detach();
181 } 181 }
182 182
183 void draw1x4(SkCanvas* canvas, SkScalar x, SkScalar y) { 183 void draw1x4(SkCanvas* canvas, SkScalar x, SkScalar y) {
184 SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHa lfSquareSize }; 184 SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHa lfSquareSize };
185 rect.offset(x, y); 185 rect.offset(x, y);
186 186
(...skipping 25 matching lines...) Expand all
212 SkLayerDrawLooper::kMaskFilter_Bit; 212 SkLayerDrawLooper::kMaskFilter_Bit;
213 info.fColorMode = SkXfermode::kSrc_Mode; 213 info.fColorMode = SkXfermode::kSrc_Mode;
214 info.fPostTranslate = false; 214 info.fPostTranslate = false;
215 215
216 SkPaint* paint; 216 SkPaint* paint;
217 217
218 for (int i = 3; i >= 0; --i) { 218 for (int i = 3; i >= 0; --i) {
219 info.fOffset.set(xOff+gBlurOffsets[i].fX, yOff+gBlurOffsets[i].fY); 219 info.fOffset.set(xOff+gBlurOffsets[i].fX, yOff+gBlurOffsets[i].fY);
220 paint = looperBuilder.addLayer(info); 220 paint = looperBuilder.addLayer(info);
221 221
222 paint->setMaskFilter(this->createBlur())->unref(); 222 paint->setMaskFilter(MakeBlur());
223 223
224 paint->setColorFilter(SkColorFilter::MakeModeFilter(gColors[i], 224 paint->setColorFilter(SkColorFilter::MakeModeFilter(gColors[i],
225 SkXfermode::kSrc In_Mode)); 225 SkXfermode::kSrc In_Mode));
226 } 226 }
227 227
228 return looperBuilder.detach(); 228 return looperBuilder.detach();
229 } 229 }
230 230
231 typedef GM INHERITED; 231 typedef GM INHERITED;
232 }; 232 };
233 233
234 const SkPoint MegaLooperGM::gBlurOffsets[4] = { 234 const SkPoint MegaLooperGM::gBlurOffsets[4] = {
235 { kHalfSquareSize, kHalfSquareSize }, 235 { kHalfSquareSize, kHalfSquareSize },
236 { -kHalfSquareSize, kHalfSquareSize }, 236 { -kHalfSquareSize, kHalfSquareSize },
237 { kHalfSquareSize, -kHalfSquareSize }, 237 { kHalfSquareSize, -kHalfSquareSize },
238 { -kHalfSquareSize, -kHalfSquareSize } 238 { -kHalfSquareSize, -kHalfSquareSize }
239 }; 239 };
240 240
241 const SkColor MegaLooperGM::gColors[4] = { 241 const SkColor MegaLooperGM::gColors[4] = {
242 SK_ColorGREEN, SK_ColorYELLOW, SK_ColorBLUE, SK_ColorRED 242 SK_ColorGREEN, SK_ColorYELLOW, SK_ColorBLUE, SK_ColorRED
243 }; 243 };
244 244
245 DEF_GM( return new MegaLooperGM(MegaLooperGM::k0x0_Type); ) 245 DEF_GM( return new MegaLooperGM(MegaLooperGM::k0x0_Type); )
246 DEF_GM( return new MegaLooperGM(MegaLooperGM::k4x1_Type); ) 246 DEF_GM( return new MegaLooperGM(MegaLooperGM::k4x1_Type); )
247 DEF_GM( return new MegaLooperGM(MegaLooperGM::k1x4_Type); ) 247 DEF_GM( return new MegaLooperGM(MegaLooperGM::k1x4_Type); )
OLDNEW
« no previous file with comments | « gm/largeglyphblur.cpp ('k') | gm/rects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698