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

Side by Side Diff: samplecode/SampleHairModes.cpp

Issue 2396953002: Revert[8] "replace SkXfermode obj with SkBlendMode enum in paints" (Closed)
Patch Set: add tmp virtual to unroll legacy arithmodes Created 4 years, 2 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 | « samplecode/SampleFuzz.cpp ('k') | samplecode/SampleLayerMask.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 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 "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkShader.h" 12 #include "SkShader.h"
13 13
14 static const struct { 14 static const struct {
15 SkXfermode::Mode fMode; 15 SkBlendMode fMode;
16 const char* fLabel; 16 const char* fLabel;
17 } gModes[] = { 17 } gModes[] = {
18 { SkXfermode::kClear_Mode, "Clear" }, 18 { SkBlendMode::kClear, "Clear" },
19 { SkXfermode::kSrc_Mode, "Src" }, 19 { SkBlendMode::kSrc, "Src" },
20 { SkXfermode::kDst_Mode, "Dst" }, 20 { SkBlendMode::kDst, "Dst" },
21 { SkXfermode::kSrcOver_Mode, "SrcOver" }, 21 { SkBlendMode::kSrcOver, "SrcOver" },
22 { SkXfermode::kDstOver_Mode, "DstOver" }, 22 { SkBlendMode::kDstOver, "DstOver" },
23 { SkXfermode::kSrcIn_Mode, "SrcIn" }, 23 { SkBlendMode::kSrcIn, "SrcIn" },
24 { SkXfermode::kDstIn_Mode, "DstIn" }, 24 { SkBlendMode::kDstIn, "DstIn" },
25 { SkXfermode::kSrcOut_Mode, "SrcOut" }, 25 { SkBlendMode::kSrcOut, "SrcOut" },
26 { SkXfermode::kDstOut_Mode, "DstOut" }, 26 { SkBlendMode::kDstOut, "DstOut" },
27 { SkXfermode::kSrcATop_Mode, "SrcATop" }, 27 { SkBlendMode::kSrcATop, "SrcATop" },
28 { SkXfermode::kDstATop_Mode, "DstATop" }, 28 { SkBlendMode::kDstATop, "DstATop" },
29 { SkXfermode::kXor_Mode, "Xor" }, 29 { SkBlendMode::kXor, "Xor" },
30 }; 30 };
31 31
32 const int gWidth = 64; 32 const int gWidth = 64;
33 const int gHeight = 64; 33 const int gHeight = 64;
34 const SkScalar W = SkIntToScalar(gWidth); 34 const SkScalar W = SkIntToScalar(gWidth);
35 const SkScalar H = SkIntToScalar(gHeight); 35 const SkScalar H = SkIntToScalar(gHeight);
36 36
37 static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, S kAlpha a1) { 37 static SkScalar drawCell(SkCanvas* canvas, SkBlendMode mode, SkAlpha a0, SkAlpha a1) {
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.setBlendMode(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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 canvas->save(); 98 canvas->save();
99 canvas->save(); 99 canvas->save();
100 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) { 100 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) {
101 if (6 == i) { 101 if (6 == i) {
102 canvas->restore(); 102 canvas->restore();
103 canvas->translate(W * 5, 0); 103 canvas->translate(W * 5, 0);
104 canvas->save(); 104 canvas->save();
105 } 105 }
106 canvas->drawRect(bounds, fBGPaint); 106 canvas->drawRect(bounds, fBGPaint);
107 canvas->saveLayer(&bounds, nullptr); 107 canvas->saveLayer(&bounds, nullptr);
108 SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fMode) , 108 SkScalar dy = drawCell(canvas, gModes[i].fMode,
109 gAlphaValue[alpha & 1], 109 gAlphaValue[alpha & 1],
110 gAlphaValue[alpha & 2]); 110 gAlphaValue[alpha & 2]);
111 canvas->restore(); 111 canvas->restore();
112 112
113 canvas->translate(0, dy * 5 / 4); 113 canvas->translate(0, dy * 5 / 4);
114 } 114 }
115 canvas->restore(); 115 canvas->restore();
116 canvas->restore(); 116 canvas->restore();
117 canvas->translate(W * 5 / 4, 0); 117 canvas->translate(W * 5 / 4, 0);
118 } 118 }
119 } 119 }
120 120
121 private: 121 private:
122 typedef SampleView INHERITED; 122 typedef SampleView INHERITED;
123 }; 123 };
124 124
125 /////////////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////////////
126 126
127 static SkView* MyFactory() { return new HairModesView; } 127 static SkView* MyFactory() { return new HairModesView; }
128 static SkViewRegister reg(MyFactory); 128 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleFuzz.cpp ('k') | samplecode/SampleLayerMask.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698