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

Side by Side Diff: gm/hairmodes.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 15 matching lines...) Expand all
26 { SkXfermode::kSrcATop_Mode, "SrcATop" }, 26 { SkXfermode::kSrcATop_Mode, "SrcATop" },
27 { SkXfermode::kDstATop_Mode, "DstATop" }, 27 { SkXfermode::kDstATop_Mode, "DstATop" },
28 { SkXfermode::kXor_Mode, "Xor" }, 28 { SkXfermode::kXor_Mode, "Xor" },
29 }; 29 };
30 30
31 const int gWidth = 64; 31 const int gWidth = 64;
32 const int gHeight = 64; 32 const int gHeight = 64;
33 const SkScalar W = SkIntToScalar(gWidth); 33 const SkScalar W = SkIntToScalar(gWidth);
34 const SkScalar H = SkIntToScalar(gHeight); 34 const SkScalar H = SkIntToScalar(gHeight);
35 35
36 static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha a1) { 36 static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, S kAlpha a1) {
37 37
38 SkPaint paint; 38 SkPaint paint;
39 paint.setAntiAlias(true); 39 paint.setAntiAlias(true);
40 40
41 SkRect r = SkRect::MakeWH(W, H); 41 SkRect r = SkRect::MakeWH(W, H);
42 r.inset(W/10, H/10); 42 r.inset(W/10, H/10);
43 43
44 paint.setColor(SK_ColorBLUE); 44 paint.setColor(SK_ColorBLUE);
45 paint.setAlpha(a0); 45 paint.setAlpha(a0);
46 canvas->drawOval(r, paint); 46 canvas->drawOval(r, paint);
47 47
48 paint.setColor(SK_ColorRED); 48 paint.setColor(SK_ColorRED);
49 paint.setAlpha(a1); 49 paint.setAlpha(a1);
50 paint.setXfermode(mode); 50 paint.setXfermode(std::move(mode));
51 for (int angle = 0; angle < 24; ++angle) { 51 for (int angle = 0; angle < 24; ++angle) {
52 SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth; 52 SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth;
53 SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight; 53 SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight;
54 paint.setStrokeWidth(SK_Scalar1 * angle * 2 / 24); 54 paint.setStrokeWidth(SK_Scalar1 * angle * 2 / 24);
55 canvas->drawLine(W/2, H/2, W/2 + x, H/2 + y, paint); 55 canvas->drawLine(W/2, H/2, W/2 + x, H/2 + y, paint);
56 } 56 }
57 57
58 return H; 58 return H;
59 } 59 }
60 60
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 for (int alpha = 0; alpha < 4; ++alpha) { 95 for (int alpha = 0; alpha < 4; ++alpha) {
96 canvas->save(); 96 canvas->save();
97 canvas->save(); 97 canvas->save();
98 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) { 98 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) {
99 if (6 == i) { 99 if (6 == i) {
100 canvas->restore(); 100 canvas->restore();
101 canvas->translate(W * 5, 0); 101 canvas->translate(W * 5, 0);
102 canvas->save(); 102 canvas->save();
103 } 103 }
104 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
105 104
106 canvas->drawRect(bounds, fBGPaint); 105 canvas->drawRect(bounds, fBGPaint);
107 canvas->saveLayer(&bounds, nullptr); 106 canvas->saveLayer(&bounds, nullptr);
108 SkScalar dy = drawCell(canvas, mode, 107 SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fM ode),
109 gAlphaValue[alpha & 1], 108 gAlphaValue[alpha & 1],
110 gAlphaValue[alpha & 2]); 109 gAlphaValue[alpha & 2]);
111 canvas->restore(); 110 canvas->restore();
112 111
113 canvas->translate(0, dy * 5 / 4); 112 canvas->translate(0, dy * 5 / 4);
114 SkSafeUnref(mode);
115 } 113 }
116 canvas->restore(); 114 canvas->restore();
117 canvas->restore(); 115 canvas->restore();
118 canvas->translate(W * 5 / 4, 0); 116 canvas->translate(W * 5 / 4, 0);
119 } 117 }
120 } 118 }
121 119
122 private: 120 private:
123 typedef GM INHERITED; 121 typedef GM INHERITED;
124 }; 122 };
125 123
126 //////////////////////////////////////////////////////////////////////////// // 124 //////////////////////////////////////////////////////////////////////////// //
127 125
128 static GM* MyFactory(void*) { return new HairModesGM; } 126 static GM* MyFactory(void*) { return new HairModesGM; }
129 static GMRegistry reg(MyFactory); 127 static GMRegistry reg(MyFactory);
130 128
131 } 129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698