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

Side by Side Diff: samplecode/SampleXfermodesBlur.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 2011 Google Inc. 2 * Copyright 2011 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkBlurMask.h" 10 #include "SkBlurMask.h"
(...skipping 21 matching lines...) Expand all
32 paint->setTypeface(face); 32 paint->setTypeface(face);
33 SkSafeUnref(face); 33 SkSafeUnref(face);
34 } 34 }
35 35
36 static uint16_t gBG[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; 36 static uint16_t gBG[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
37 37
38 class XfermodesBlurView : public SampleView { 38 class XfermodesBlurView : public SampleView {
39 SkBitmap fBG; 39 SkBitmap fBG;
40 SkBitmap fSrcB, fDstB; 40 SkBitmap fSrcB, fDstB;
41 41
42 void draw_mode(SkCanvas* canvas, SkXfermode* mode, int alpha, 42 void draw_mode(SkCanvas* canvas, sk_sp<SkXfermode> mode, int alpha,
43 SkScalar x, SkScalar y) { 43 SkScalar x, SkScalar y) {
44 SkPaint p; 44 SkPaint p;
45 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 45 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
46 SkBlurMask::ConvertRadiusToSigma(SkIntToS calar(5)), 46 SkBlurMask::ConvertRadiusToSigma(SkIntToS calar(5)),
47 SkBlurMaskFilter::kNone_BlurFlag); 47 SkBlurMaskFilter::kNone_BlurFlag);
48 p.setMaskFilter(mf)->unref(); 48 p.setMaskFilter(mf)->unref();
49 49
50 SkScalar ww = SkIntToScalar(W); 50 SkScalar ww = SkIntToScalar(W);
51 SkScalar hh = SkIntToScalar(H); 51 SkScalar hh = SkIntToScalar(H);
52 52
53 // draw a circle covering the upper 53 // draw a circle covering the upper
54 // left three quarters of the canvas 54 // left three quarters of the canvas
55 p.setColor(0xFFCC44FF); 55 p.setColor(0xFFCC44FF);
56 SkRect r; 56 SkRect r;
57 r.set(0, 0, ww*3/4, hh*3/4); 57 r.set(0, 0, ww*3/4, hh*3/4);
58 r.offset(x, y); 58 r.offset(x, y);
59 canvas->drawOval(r, p); 59 canvas->drawOval(r, p);
60 60
61 p.setXfermode(mode); 61 p.setXfermode(std::move(mode));
62 62
63 // draw a square overlapping the circle 63 // draw a square overlapping the circle
64 // in the lower right of the canvas 64 // in the lower right of the canvas
65 p.setColor(0x00AA6633 | alpha << 24); 65 p.setColor(0x00AA6633 | alpha << 24);
66 r.set(ww/3, hh/3, ww*19/20, hh*19/20); 66 r.set(ww/3, hh/3, ww*19/20, hh*19/20);
67 r.offset(x, y); 67 r.offset(x, y);
68 canvas->drawRect(r, p); 68 canvas->drawRect(r, p);
69 } 69 }
70 70
71 public: 71 public:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 labelP.setLCDRenderText(true); 156 labelP.setLCDRenderText(true);
157 labelP.setTextAlign(SkPaint::kCenter_Align); 157 labelP.setTextAlign(SkPaint::kCenter_Align);
158 setNamedTypeface(&labelP, "Menlo Regular"); 158 setNamedTypeface(&labelP, "Menlo Regular");
159 159
160 const int W = 5; 160 const int W = 5;
161 161
162 SkScalar x0 = 0; 162 SkScalar x0 = 0;
163 for (int twice = 0; twice < 2; twice++) { 163 for (int twice = 0; twice < 2; twice++) {
164 SkScalar x = x0, y = 0; 164 SkScalar x = x0, y = 0;
165 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { 165 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
166 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
167 SkAutoUnref aur(mode);
168 SkRect r; 166 SkRect r;
169 r.set(x, y, x+w, y+h); 167 r.set(x, y, x+w, y+h);
170 168
171 SkPaint p; 169 SkPaint p;
172 p.setStyle(SkPaint::kFill_Style); 170 p.setStyle(SkPaint::kFill_Style);
173 p.setShader(s); 171 p.setShader(s);
174 canvas->drawRect(r, p); 172 canvas->drawRect(r, p);
175 173
176 canvas->saveLayer(&r, nullptr); 174 canvas->saveLayer(&r, nullptr);
177 draw_mode(canvas, mode, twice ? 0x88 : 0xFF, r.fLeft, r.fTop); 175 draw_mode(canvas, SkXfermode::Make(gModes[i].fMode),
176 twice ? 0x88 : 0xFF, r.fLeft, r.fTop);
178 canvas->restore(); 177 canvas->restore();
179 178
180 r.inset(-SK_ScalarHalf, -SK_ScalarHalf); 179 r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
181 p.setStyle(SkPaint::kStroke_Style); 180 p.setStyle(SkPaint::kStroke_Style);
182 p.setShader(nullptr); 181 p.setShader(nullptr);
183 canvas->drawRect(r, p); 182 canvas->drawRect(r, p);
184 183
185 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel), 184 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
186 x + w/2, y - labelP.getTextSize()/2, labelP); 185 x + w/2, y - labelP.getTextSize()/2, labelP);
187 x += w + SkIntToScalar(10); 186 x += w + SkIntToScalar(10);
188 if ((i % W) == W - 1) { 187 if ((i % W) == W - 1) {
189 x = x0; 188 x = x0;
190 y += h + SkIntToScalar(30); 189 y += h + SkIntToScalar(30);
191 } 190 }
192 } 191 }
193 x0 += SkIntToScalar(400); 192 x0 += SkIntToScalar(400);
194 } 193 }
195 } 194 }
196 195
197 private: 196 private:
198 typedef SampleView INHERITED; 197 typedef SampleView INHERITED;
199 }; 198 };
200 199
201 ////////////////////////////////////////////////////////////////////////////// 200 //////////////////////////////////////////////////////////////////////////////
202 201
203 static SkView* MyFactory() { return new XfermodesBlurView; } 202 static SkView* MyFactory() { return new XfermodesBlurView; }
204 static SkViewRegister reg(MyFactory); 203 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698