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

Side by Side Diff: gm/xfermodes.cpp

Issue 1736523002: extend xfermodes gm to include 3 custom modes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | no next file » | 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"
11 #include "SkXfermode.h" 11 #include "SkXfermode.h"
12 #include "SkPM4f.h" 12 #include "SkPM4f.h"
13 13
14 #include "SkArithmeticMode.h"
15 #include "SkPixelXorXfermode.h"
16 #include "SkAvoidXfermode.h"
17
18 #define kCustomShift 16
19 #define kCustomMask (~0xFFFF)
20
21 enum CustomModes {
22 kArithmetic_CustomMode = 1 << kCustomShift,
23 kPixelXor_CustomMode = 2 << kCustomShift,
24 kAvoid_CustomMode = 3 << kCustomShift,
25 };
26
27 static SkXfermode* make_custom(int customMode) {
28 switch (customMode) {
29 case kArithmetic_CustomMode: {
30 const SkScalar k1 = 0.25;
31 const SkScalar k2 = 0.75;
32 const SkScalar k3 = 0.75;
33 const SkScalar k4 = -0.25;
34 return SkArithmeticMode::Create(k1, k2, k3, k4);
35 }
36 case kPixelXor_CustomMode:
37 return SkPixelXorXfermode::Create(0xFF88CC44);
38 case kAvoid_CustomMode:
39 return SkAvoidXfermode::Create(0xFFFF0000, 0x44, SkAvoidXfermode::kA voidColor_Mode);
40 default:
41 break;
42 }
43 SkASSERT(false);
44 return nullptr;
45 }
46
14 enum SrcType { 47 enum SrcType {
15 //! A WxH image with a rectangle in the lower right. 48 //! A WxH image with a rectangle in the lower right.
16 kRectangleImage_SrcType = 0x01, 49 kRectangleImage_SrcType = 0x01,
17 //! kRectangleImage_SrcType with an alpha of 34.5%. 50 //! kRectangleImage_SrcType with an alpha of 34.5%.
18 kRectangleImageWithAlpha_SrcType = 0x02, 51 kRectangleImageWithAlpha_SrcType = 0x02,
19 //! kRectnagleImageWithAlpha_SrcType scaled down by half. 52 //! kRectnagleImageWithAlpha_SrcType scaled down by half.
20 kSmallRectangleImageWithAlpha_SrcType = 0x04, 53 kSmallRectangleImageWithAlpha_SrcType = 0x04,
21 //! kRectangleImage_SrcType drawn directly instead in an image. 54 //! kRectangleImage_SrcType drawn directly instead in an image.
22 kRectangle_SrcType = 0x08, 55 kRectangle_SrcType = 0x08,
23 //! Two rectangles, first on the right half, second on the bottom half. 56 //! Two rectangles, first on the right half, second on the bottom half.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 { SkXfermode::kColorBurn_Mode, "ColorBurn", kBasic_SrcType }, 99 { SkXfermode::kColorBurn_Mode, "ColorBurn", kBasic_SrcType },
67 { SkXfermode::kHardLight_Mode, "HardLight", kBasic_SrcType }, 100 { SkXfermode::kHardLight_Mode, "HardLight", kBasic_SrcType },
68 { SkXfermode::kSoftLight_Mode, "SoftLight", kBasic_SrcType }, 101 { SkXfermode::kSoftLight_Mode, "SoftLight", kBasic_SrcType },
69 { SkXfermode::kDifference_Mode, "Difference", kBasic_SrcType }, 102 { SkXfermode::kDifference_Mode, "Difference", kBasic_SrcType },
70 { SkXfermode::kExclusion_Mode, "Exclusion", kBasic_SrcType }, 103 { SkXfermode::kExclusion_Mode, "Exclusion", kBasic_SrcType },
71 { SkXfermode::kMultiply_Mode, "Multiply", kAll_SrcType }, 104 { SkXfermode::kMultiply_Mode, "Multiply", kAll_SrcType },
72 { SkXfermode::kHue_Mode, "Hue", kBasic_SrcType }, 105 { SkXfermode::kHue_Mode, "Hue", kBasic_SrcType },
73 { SkXfermode::kSaturation_Mode, "Saturation", kBasic_SrcType }, 106 { SkXfermode::kSaturation_Mode, "Saturation", kBasic_SrcType },
74 { SkXfermode::kColor_Mode, "Color", kBasic_SrcType }, 107 { SkXfermode::kColor_Mode, "Color", kBasic_SrcType },
75 { SkXfermode::kLuminosity_Mode, "Luminosity", kBasic_SrcType }, 108 { SkXfermode::kLuminosity_Mode, "Luminosity", kBasic_SrcType },
109
110 { SkXfermode::Mode(0xFFFF), "Arithmetic", kBasic_SrcType + kArithmet ic_CustomMode },
111 { SkXfermode::Mode(0xFFFF), "PixelXor", kBasic_SrcType + kPixelXor _CustomMode },
112 { SkXfermode::Mode(0xFFFF), "Avoid", kBasic_SrcType + kAvoid_Cu stomMode },
76 }; 113 };
77 114
78 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst, 115 static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst,
79 SkBitmap* transparent) { 116 SkBitmap* transparent) {
80 src->allocN32Pixels(w, h); 117 src->allocN32Pixels(w, h);
81 src->eraseColor(SK_ColorTRANSPARENT); 118 src->eraseColor(SK_ColorTRANSPARENT);
82 119
83 SkPaint p; 120 SkPaint p;
84 p.setAntiAlias(true); 121 p.setAntiAlias(true);
85 122
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 const static int W = 64; 244 const static int W = 64;
208 const static int H = 64; 245 const static int H = 64;
209 XfermodesGM() {} 246 XfermodesGM() {}
210 247
211 protected: 248 protected:
212 SkString onShortName() override { 249 SkString onShortName() override {
213 return SkString("xfermodes"); 250 return SkString("xfermodes");
214 } 251 }
215 252
216 SkISize onISize() override { 253 SkISize onISize() override {
217 return SkISize::Make(1990, 640); 254 return SkISize::Make(1990, 660);
218 } 255 }
219 256
220 void onDraw(SkCanvas* canvas) override { 257 void onDraw(SkCanvas* canvas) override {
221 canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); 258 canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
222 259
223 const SkScalar w = SkIntToScalar(W); 260 const SkScalar w = SkIntToScalar(W);
224 const SkScalar h = SkIntToScalar(H); 261 const SkScalar h = SkIntToScalar(H);
225 SkMatrix m; 262 SkMatrix m;
226 m.setScale(SkIntToScalar(6), SkIntToScalar(6)); 263 m.setScale(SkIntToScalar(6), SkIntToScalar(6));
227 SkShader* s = SkShader::CreateBitmapShader(fBG, 264 SkShader* s = SkShader::CreateBitmapShader(fBG,
228 SkShader::kRepeat_TileMode, 265 SkShader::kRepeat_TileMode,
229 SkShader::kRepeat_TileMode, 266 SkShader::kRepeat_TileMode,
230 &m); 267 &m);
231 268
232 SkPaint labelP; 269 SkPaint labelP;
233 labelP.setAntiAlias(true); 270 labelP.setAntiAlias(true);
234 sk_tool_utils::set_portable_typeface(&labelP); 271 sk_tool_utils::set_portable_typeface(&labelP);
235 labelP.setTextAlign(SkPaint::kCenter_Align); 272 labelP.setTextAlign(SkPaint::kCenter_Align);
236 273
237 const int W = 5; 274 const int W = 5;
238 275
239 SkScalar x0 = 0; 276 SkScalar x0 = 0;
240 SkScalar y0 = 0; 277 SkScalar y0 = 0;
241 for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) { 278 for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) {
242 SkScalar x = x0, y = y0; 279 SkScalar x = x0, y = y0;
243 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { 280 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
244 if ((gModes[i].fSourceTypeMask & sourceType) == 0) { 281 if ((gModes[i].fSourceTypeMask & sourceType) == 0) {
282 SkDebugf("skip %d %s for type %x\n", i, gModes[i].fLabel, so urceType);
245 continue; 283 continue;
246 } 284 }
247 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode); 285 SkAutoTUnref<SkXfermode> mode;
248 SkAutoUnref aur(mode); 286 if (gModes[i].fSourceTypeMask & kCustomMask) {
287 mode.reset(make_custom(gModes[i].fSourceTypeMask & kCustomMa sk));
288 } else {
289 mode.reset(SkXfermode::Create(gModes[i].fMode));
290 }
249 SkRect r; 291 SkRect r;
250 r.set(x, y, x+w, y+h); 292 r.set(x, y, x+w, y+h);
251 293
252 SkPaint p; 294 SkPaint p;
253 p.setStyle(SkPaint::kFill_Style); 295 p.setStyle(SkPaint::kFill_Style);
254 p.setShader(s); 296 p.setShader(s);
255 canvas->drawRect(r, p); 297 canvas->drawRect(r, p);
256 298
257 canvas->saveLayer(&r, nullptr); 299 canvas->saveLayer(&r, nullptr);
258 draw_mode(canvas, mode, static_cast<SrcType>(sourceType), 300 draw_mode(canvas, mode, static_cast<SrcType>(sourceType),
(...skipping 25 matching lines...) Expand all
284 y0 = 0; 326 y0 = 0;
285 } 327 }
286 } 328 }
287 s->unref(); 329 s->unref();
288 } 330 }
289 331
290 private: 332 private:
291 typedef GM INHERITED; 333 typedef GM INHERITED;
292 }; 334 };
293 DEF_GM( return new XfermodesGM; ) 335 DEF_GM( return new XfermodesGM; )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698