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

Side by Side Diff: gm/xfermodes.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 | « gm/xfermodeimagefilter.cpp ('k') | gm/xfermodes2.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 "gm.h" 8 #include "gm.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkShader.h" 10 #include "SkShader.h"
(...skipping 16 matching lines...) Expand all
27 //! A W/2xH/2 transparent image. 27 //! A W/2xH/2 transparent image.
28 kSmallTransparentImage_SrcType = 0x40, 28 kSmallTransparentImage_SrcType = 0x40,
29 //! kRectangleImage_SrcType drawn directly with a mask. 29 //! kRectangleImage_SrcType drawn directly with a mask.
30 kRectangleWithMask_SrcType = 0x80, 30 kRectangleWithMask_SrcType = 0x80,
31 31
32 kAll_SrcType = 0xFF, //!< All the source types. 32 kAll_SrcType = 0xFF, //!< All the source types.
33 kBasic_SrcType = 0x03, //!< Just basic source types. 33 kBasic_SrcType = 0x03, //!< Just basic source types.
34 }; 34 };
35 35
36 const struct { 36 const struct {
37 SkXfermode::Mode fMode; 37 SkBlendMode fMode;
38 const char* fLabel; 38 const char* fLabel;
39 int fSourceTypeMask; // The source types to use this 39 int fSourceTypeMask; // The source types to use this
40 // mode with. See draw_mode for 40 // mode with. See draw_mode for
41 // an explanation of each type. 41 // an explanation of each type.
42 // PDF has to play some tricks 42 // PDF has to play some tricks
43 // to support the base modes, 43 // to support the base modes,
44 // test those more extensively. 44 // test those more extensively.
45 } gModes[] = { 45 } gModes[] = {
46 { SkXfermode::kClear_Mode, "Clear", kAll_SrcType }, 46 { SkBlendMode::kClear, "Clear", kAll_SrcType },
47 { SkXfermode::kSrc_Mode, "Src", kAll_SrcType }, 47 { SkBlendMode::kSrc, "Src", kAll_SrcType },
48 { SkXfermode::kDst_Mode, "Dst", kAll_SrcType }, 48 { SkBlendMode::kDst, "Dst", kAll_SrcType },
49 { SkXfermode::kSrcOver_Mode, "SrcOver", kAll_SrcType }, 49 { SkBlendMode::kSrcOver, "SrcOver", kAll_SrcType },
50 { SkXfermode::kDstOver_Mode, "DstOver", kAll_SrcType }, 50 { SkBlendMode::kDstOver, "DstOver", kAll_SrcType },
51 { SkXfermode::kSrcIn_Mode, "SrcIn", kAll_SrcType }, 51 { SkBlendMode::kSrcIn, "SrcIn", kAll_SrcType },
52 { SkXfermode::kDstIn_Mode, "DstIn", kAll_SrcType }, 52 { SkBlendMode::kDstIn, "DstIn", kAll_SrcType },
53 { SkXfermode::kSrcOut_Mode, "SrcOut", kAll_SrcType }, 53 { SkBlendMode::kSrcOut, "SrcOut", kAll_SrcType },
54 { SkXfermode::kDstOut_Mode, "DstOut", kAll_SrcType }, 54 { SkBlendMode::kDstOut, "DstOut", kAll_SrcType },
55 { SkXfermode::kSrcATop_Mode, "SrcATop", kAll_SrcType }, 55 { SkBlendMode::kSrcATop, "SrcATop", kAll_SrcType },
56 { SkXfermode::kDstATop_Mode, "DstATop", kAll_SrcType }, 56 { SkBlendMode::kDstATop, "DstATop", kAll_SrcType },
57 57
58 { SkXfermode::kXor_Mode, "Xor", kBasic_SrcType }, 58 { SkBlendMode::kXor, "Xor", kBasic_SrcType },
59 { SkXfermode::kPlus_Mode, "Plus", kBasic_SrcType }, 59 { SkBlendMode::kPlus, "Plus", kBasic_SrcType },
60 { SkXfermode::kModulate_Mode, "Modulate", kAll_SrcType }, 60 { SkBlendMode::kModulate, "Modulate", kAll_SrcType },
61 { SkXfermode::kScreen_Mode, "Screen", kBasic_SrcType }, 61 { SkBlendMode::kScreen, "Screen", kBasic_SrcType },
62 { SkXfermode::kOverlay_Mode, "Overlay", kBasic_SrcType }, 62 { SkBlendMode::kOverlay, "Overlay", kBasic_SrcType },
63 { SkXfermode::kDarken_Mode, "Darken", kBasic_SrcType }, 63 { SkBlendMode::kDarken, "Darken", kBasic_SrcType },
64 { SkXfermode::kLighten_Mode, "Lighten", kBasic_SrcType }, 64 { SkBlendMode::kLighten, "Lighten", kBasic_SrcType },
65 { SkXfermode::kColorDodge_Mode, "ColorDodge", kBasic_SrcType }, 65 { SkBlendMode::kColorDodge, "ColorDodge", kBasic_SrcType },
66 { SkXfermode::kColorBurn_Mode, "ColorBurn", kBasic_SrcType }, 66 { SkBlendMode::kColorBurn, "ColorBurn", kBasic_SrcType },
67 { SkXfermode::kHardLight_Mode, "HardLight", kBasic_SrcType }, 67 { SkBlendMode::kHardLight, "HardLight", kBasic_SrcType },
68 { SkXfermode::kSoftLight_Mode, "SoftLight", kBasic_SrcType }, 68 { SkBlendMode::kSoftLight, "SoftLight", kBasic_SrcType },
69 { SkXfermode::kDifference_Mode, "Difference", kBasic_SrcType }, 69 { SkBlendMode::kDifference, "Difference", kBasic_SrcType },
70 { SkXfermode::kExclusion_Mode, "Exclusion", kBasic_SrcType }, 70 { SkBlendMode::kExclusion, "Exclusion", kBasic_SrcType },
71 { SkXfermode::kMultiply_Mode, "Multiply", kAll_SrcType }, 71 { SkBlendMode::kMultiply, "Multiply", kAll_SrcType },
72 { SkXfermode::kHue_Mode, "Hue", kBasic_SrcType }, 72 { SkBlendMode::kHue, "Hue", kBasic_SrcType },
73 { SkXfermode::kSaturation_Mode, "Saturation", kBasic_SrcType }, 73 { SkBlendMode::kSaturation, "Saturation", kBasic_SrcType },
74 { SkXfermode::kColor_Mode, "Color", kBasic_SrcType }, 74 { SkBlendMode::kColor, "Color", kBasic_SrcType },
75 { SkXfermode::kLuminosity_Mode, "Luminosity", kBasic_SrcType }, 75 { SkBlendMode::kLuminosity, "Luminosity", kBasic_SrcType },
76 }; 76 };
77 77
78 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst, 78 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst,
79 SkBitmap* transparent) { 79 SkBitmap* transparent) {
80 src->allocN32Pixels(w, h); 80 src->allocN32Pixels(w, h);
81 src->eraseColor(SK_ColorTRANSPARENT); 81 src->eraseColor(SK_ColorTRANSPARENT);
82 82
83 SkPaint p; 83 SkPaint p;
84 p.setAntiAlias(true); 84 p.setAntiAlias(true);
85 85
(...skipping 25 matching lines...) Expand all
111 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; 111 static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
112 112
113 class XfermodesGM : public skiagm::GM { 113 class XfermodesGM : public skiagm::GM {
114 SkBitmap fBG; 114 SkBitmap fBG;
115 SkBitmap fSrcB, fDstB, fTransparent; 115 SkBitmap fSrcB, fDstB, fTransparent;
116 116
117 /* The srcType argument indicates what to draw for the source part. Skia 117 /* The srcType argument indicates what to draw for the source part. Skia
118 * uses the implied shape of the drawing command and these modes 118 * uses the implied shape of the drawing command and these modes
119 * demonstrate that. 119 * demonstrate that.
120 */ 120 */
121 void draw_mode(SkCanvas* canvas, SkXfermode::Mode mode, SrcType srcType, 121 void draw_mode(SkCanvas* canvas, SkBlendMode mode, SrcType srcType, SkScalar x, SkScalar y) {
122 SkScalar x, SkScalar y) {
123 SkPaint p; 122 SkPaint p;
124 SkMatrix m; 123 SkMatrix m;
125 bool restoreNeeded = false; 124 bool restoreNeeded = false;
126 m.setTranslate(x, y); 125 m.setTranslate(x, y);
127 126
128 canvas->drawBitmap(fSrcB, x, y, &p); 127 canvas->drawBitmap(fSrcB, x, y, &p);
129 p.setXfermodeMode(mode); 128 p.setBlendMode(mode);
130 switch (srcType) { 129 switch (srcType) {
131 case kSmallTransparentImage_SrcType: { 130 case kSmallTransparentImage_SrcType: {
132 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y); 131 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
133 132
134 SkAutoCanvasRestore acr(canvas, true); 133 SkAutoCanvasRestore acr(canvas, true);
135 canvas->concat(m); 134 canvas->concat(m);
136 canvas->drawBitmap(fTransparent, 0, 0, &p); 135 canvas->drawBitmap(fTransparent, 0, 0, &p);
137 break; 136 break;
138 } 137 }
139 case kQuarterClearInLayer_SrcType: { 138 case kQuarterClearInLayer_SrcType: {
140 SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W), 139 SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W),
141 SkIntToScalar(H)); 140 SkIntToScalar(H));
142 canvas->saveLayer(&bounds, &p); 141 canvas->saveLayer(&bounds, &p);
143 restoreNeeded = true; 142 restoreNeeded = true;
144 p.setXfermodeMode(SkXfermode::kSrcOver_Mode); 143 p.setBlendMode(SkBlendMode::kSrcOver);
145 // Fall through. 144 // Fall through.
146 } 145 }
147 case kQuarterClear_SrcType: { 146 case kQuarterClear_SrcType: {
148 SkScalar halfW = SkIntToScalar(W) / 2; 147 SkScalar halfW = SkIntToScalar(W) / 2;
149 SkScalar halfH = SkIntToScalar(H) / 2; 148 SkScalar halfH = SkIntToScalar(H) / 2;
150 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF)); 149 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF));
151 SkRect r = SkRect::MakeXYWH(x + halfW, y, halfW, 150 SkRect r = SkRect::MakeXYWH(x + halfW, y, halfW,
152 SkIntToScalar(H)); 151 SkIntToScalar(H));
153 canvas->drawRect(r, p); 152 canvas->drawRect(r, p);
154 p.setColor(sk_tool_utils::color_to_565(0xFFAA66FF)); 153 p.setColor(sk_tool_utils::color_to_565(0xFFAA66FF));
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 x0 += SkIntToScalar(400); 277 x0 += SkIntToScalar(400);
279 y0 = 0; 278 y0 = 0;
280 } 279 }
281 } 280 }
282 } 281 }
283 282
284 private: 283 private:
285 typedef GM INHERITED; 284 typedef GM INHERITED;
286 }; 285 };
287 DEF_GM( return new XfermodesGM; ) 286 DEF_GM( return new XfermodesGM; )
OLDNEW
« no previous file with comments | « gm/xfermodeimagefilter.cpp ('k') | gm/xfermodes2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698