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

Side by Side Diff: gm/aarectmodes.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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 { SkXfermode::kSrcATop_Mode, "SrcATop" }, 74 { SkXfermode::kSrcATop_Mode, "SrcATop" },
75 { SkXfermode::kDstATop_Mode, "DstATop" }, 75 { SkXfermode::kDstATop_Mode, "DstATop" },
76 { SkXfermode::kXor_Mode, "Xor" }, 76 { SkXfermode::kXor_Mode, "Xor" },
77 }; 77 };
78 78
79 const int gWidth = 64; 79 const int gWidth = 64;
80 const int gHeight = 64; 80 const int gHeight = 64;
81 const SkScalar W = SkIntToScalar(gWidth); 81 const SkScalar W = SkIntToScalar(gWidth);
82 const SkScalar H = SkIntToScalar(gHeight); 82 const SkScalar H = SkIntToScalar(gHeight);
83 83
84 static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, 84 static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, S kAlpha a1) {
85 SkAlpha a0, SkAlpha a1) {
86 85
87 SkPaint paint; 86 SkPaint paint;
88 paint.setAntiAlias(true); 87 paint.setAntiAlias(true);
89 88
90 SkRect r = SkRect::MakeWH(W, H); 89 SkRect r = SkRect::MakeWH(W, H);
91 r.inset(W/10, H/10); 90 r.inset(W/10, H/10);
92 91
93 paint.setColor(SK_ColorBLUE); 92 paint.setColor(SK_ColorBLUE);
94 paint.setAlpha(a0); 93 paint.setAlpha(a0);
95 canvas->drawOval(r, paint); 94 canvas->drawOval(r, paint);
96 95
97 paint.setColor(SK_ColorRED); 96 paint.setColor(SK_ColorRED);
98 paint.setAlpha(a1); 97 paint.setAlpha(a1);
99 paint.setXfermode(mode); 98 paint.setXfermode(std::move(mode));
100 99
101 SkScalar offset = SK_Scalar1 / 3; 100 SkScalar offset = SK_Scalar1 / 3;
102 SkRect rect = SkRect::MakeXYWH(W / 4 + offset, 101 SkRect rect = SkRect::MakeXYWH(W / 4 + offset,
103 H / 4 + offset, 102 H / 4 + offset,
104 W / 2, H / 2); 103 W / 2, H / 2);
105 canvas->drawRect(rect, paint); 104 canvas->drawRect(rect, paint);
106 105
107 return H; 106 return H;
108 } 107 }
109 108
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 146
148 for (int alpha = 0; alpha < 4; ++alpha) { 147 for (int alpha = 0; alpha < 4; ++alpha) {
149 canvas->save(); 148 canvas->save();
150 canvas->save(); 149 canvas->save();
151 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) { 150 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) {
152 if (6 == i) { 151 if (6 == i) {
153 canvas->restore(); 152 canvas->restore();
154 canvas->translate(W * 5, 0); 153 canvas->translate(W * 5, 0);
155 canvas->save(); 154 canvas->save();
156 } 155 }
157 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
158
159 canvas->drawRect(bounds, fBGPaint); 156 canvas->drawRect(bounds, fBGPaint);
160 canvas->saveLayer(&bounds, nullptr); 157 canvas->saveLayer(&bounds, nullptr);
161 SkScalar dy = drawCell(canvas, mode, 158 SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fM ode),
162 gAlphaValue[alpha & 1], 159 gAlphaValue[alpha & 1],
163 gAlphaValue[alpha & 2]); 160 gAlphaValue[alpha & 2]);
164 canvas->restore(); 161 canvas->restore();
165 162
166 canvas->translate(0, dy * 5 / 4); 163 canvas->translate(0, dy * 5 / 4);
167 SkSafeUnref(mode);
168 } 164 }
169 canvas->restore(); 165 canvas->restore();
170 canvas->restore(); 166 canvas->restore();
171 canvas->translate(W * 5 / 4, 0); 167 canvas->translate(W * 5 / 4, 0);
172 } 168 }
173 } 169 }
174 170
175 private: 171 private:
176 typedef GM INHERITED; 172 typedef GM INHERITED;
177 }; 173 };
178 174
179 ////////////////////////////////////////////////////////////////////////////// 175 //////////////////////////////////////////////////////////////////////////////
180 176
181 static GM* MyFactory(void*) { return new AARectModesGM; } 177 static GM* MyFactory(void*) { return new AARectModesGM; }
182 static GMRegistry reg(MyFactory); 178 static GMRegistry reg(MyFactory);
183 179
184 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698