blob: 9e87c04455d5cb4d82101c37fe4e72b25cf70b98 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reeddd9ffea2016-02-18 12:39:14 -08007
reed@android.comdd0ac282009-06-20 02:38:16 +00008#include "gm.h"
9#include "SkBitmap.h"
10#include "SkShader.h"
11#include "SkXfermode.h"
reeddd9ffea2016-02-18 12:39:14 -080012#include "SkPM4f.h"
reed@android.comdd0ac282009-06-20 02:38:16 +000013
reede7125322016-02-09 11:59:24 -080014enum SrcType {
15 //! A WxH image with a rectangle in the lower right.
16 kRectangleImage_SrcType = 0x01,
17 //! kRectangleImage_SrcType with an alpha of 34.5%.
18 kRectangleImageWithAlpha_SrcType = 0x02,
19 //! kRectnagleImageWithAlpha_SrcType scaled down by half.
20 kSmallRectangleImageWithAlpha_SrcType = 0x04,
21 //! kRectangleImage_SrcType drawn directly instead in an image.
22 kRectangle_SrcType = 0x08,
23 //! Two rectangles, first on the right half, second on the bottom half.
24 kQuarterClear_SrcType = 0x10,
25 //! kQuarterClear_SrcType in a layer.
26 kQuarterClearInLayer_SrcType = 0x20,
27 //! A W/2xH/2 transparent image.
28 kSmallTransparentImage_SrcType = 0x40,
29 //! kRectangleImage_SrcType drawn directly with a mask.
30 kRectangleWithMask_SrcType = 0x80,
31
32 kAll_SrcType = 0xFF, //!< All the source types.
33 kBasic_SrcType = 0x03, //!< Just basic source types.
34};
35
36const struct {
37 SkXfermode::Mode fMode;
38 const char* fLabel;
39 int fSourceTypeMask; // The source types to use this
40 // mode with. See draw_mode for
41 // an explanation of each type.
42 // PDF has to play some tricks
43 // to support the base modes,
44 // test those more extensively.
45} gModes[] = {
46 { SkXfermode::kClear_Mode, "Clear", kAll_SrcType },
47 { SkXfermode::kSrc_Mode, "Src", kAll_SrcType },
48 { SkXfermode::kDst_Mode, "Dst", kAll_SrcType },
49 { SkXfermode::kSrcOver_Mode, "SrcOver", kAll_SrcType },
50 { SkXfermode::kDstOver_Mode, "DstOver", kAll_SrcType },
51 { SkXfermode::kSrcIn_Mode, "SrcIn", kAll_SrcType },
52 { SkXfermode::kDstIn_Mode, "DstIn", kAll_SrcType },
53 { SkXfermode::kSrcOut_Mode, "SrcOut", kAll_SrcType },
54 { SkXfermode::kDstOut_Mode, "DstOut", kAll_SrcType },
55 { SkXfermode::kSrcATop_Mode, "SrcATop", kAll_SrcType },
56 { SkXfermode::kDstATop_Mode, "DstATop", kAll_SrcType },
57
58 { SkXfermode::kXor_Mode, "Xor", kBasic_SrcType },
59 { SkXfermode::kPlus_Mode, "Plus", kBasic_SrcType },
60 { SkXfermode::kModulate_Mode, "Modulate", kAll_SrcType },
61 { SkXfermode::kScreen_Mode, "Screen", kBasic_SrcType },
62 { SkXfermode::kOverlay_Mode, "Overlay", kBasic_SrcType },
63 { SkXfermode::kDarken_Mode, "Darken", kBasic_SrcType },
64 { SkXfermode::kLighten_Mode, "Lighten", kBasic_SrcType },
65 { SkXfermode::kColorDodge_Mode, "ColorDodge", kBasic_SrcType },
66 { SkXfermode::kColorBurn_Mode, "ColorBurn", kBasic_SrcType },
67 { SkXfermode::kHardLight_Mode, "HardLight", kBasic_SrcType },
68 { SkXfermode::kSoftLight_Mode, "SoftLight", kBasic_SrcType },
69 { SkXfermode::kDifference_Mode, "Difference", kBasic_SrcType },
70 { SkXfermode::kExclusion_Mode, "Exclusion", kBasic_SrcType },
71 { SkXfermode::kMultiply_Mode, "Multiply", kAll_SrcType },
72 { SkXfermode::kHue_Mode, "Hue", kBasic_SrcType },
73 { SkXfermode::kSaturation_Mode, "Saturation", kBasic_SrcType },
74 { SkXfermode::kColor_Mode, "Color", kBasic_SrcType },
75 { SkXfermode::kLuminosity_Mode, "Luminosity", kBasic_SrcType },
76};
reed@android.comdd0ac282009-06-20 02:38:16 +000077
commit-bot@chromium.org7542dc82013-12-03 21:08:46 +000078static void make_bitmaps(int w, int h, SkBitmap* src, SkBitmap* dst,
79 SkBitmap* transparent) {
reed@google.comeb9a46c2014-01-25 16:46:20 +000080 src->allocN32Pixels(w, h);
junov@google.comdbfac8a2012-12-06 21:47:40 +000081 src->eraseColor(SK_ColorTRANSPARENT);
reed@android.comdd0ac282009-06-20 02:38:16 +000082
reed@android.comdd0ac282009-06-20 02:38:16 +000083 SkPaint p;
mike@reedtribe.org3bd21732012-09-26 02:45:10 +000084 p.setAntiAlias(true);
85
reed@android.comdd0ac282009-06-20 02:38:16 +000086 SkRect r;
87 SkScalar ww = SkIntToScalar(w);
88 SkScalar hh = SkIntToScalar(h);
89
mike@reedtribe.org3bd21732012-09-26 02:45:10 +000090 {
91 SkCanvas c(*src);
caryclark4ec1ac62015-07-21 07:42:45 -070092 p.setColor(sk_tool_utils::color_to_565(0xFFFFCC44));
mike@reedtribe.org3bd21732012-09-26 02:45:10 +000093 r.set(0, 0, ww*3/4, hh*3/4);
94 c.drawOval(r, p);
95 }
tomhudson@google.com86bf5c92011-04-26 18:15:03 +000096
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +000097 dst->allocN32Pixels(w, h);
junov@google.comdbfac8a2012-12-06 21:47:40 +000098 dst->eraseColor(SK_ColorTRANSPARENT);
reed@android.comdd0ac282009-06-20 02:38:16 +000099
mike@reedtribe.org3bd21732012-09-26 02:45:10 +0000100 {
101 SkCanvas c(*dst);
caryclark4ec1ac62015-07-21 07:42:45 -0700102 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF));
mike@reedtribe.org3bd21732012-09-26 02:45:10 +0000103 r.set(ww/3, hh/3, ww*19/20, hh*19/20);
104 c.drawRect(r, p);
105 }
commit-bot@chromium.org7542dc82013-12-03 21:08:46 +0000106
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000107 transparent->allocN32Pixels(w, h);
commit-bot@chromium.org7542dc82013-12-03 21:08:46 +0000108 transparent->eraseColor(SK_ColorTRANSPARENT);
reed@android.comdd0ac282009-06-20 02:38:16 +0000109}
110
scroggo@google.com7312a182013-01-28 21:14:21 +0000111static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
112
reede7125322016-02-09 11:59:24 -0800113class XfermodesGM : public skiagm::GM {
reed@android.comdd0ac282009-06-20 02:38:16 +0000114 SkBitmap fBG;
commit-bot@chromium.org7542dc82013-12-03 21:08:46 +0000115 SkBitmap fSrcB, fDstB, fTransparent;
reed@android.comdd0ac282009-06-20 02:38:16 +0000116
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000117 /* The srcType argument indicates what to draw for the source part. Skia
118 * uses the implied shape of the drawing command and these modes
119 * demonstrate that.
120 */
121 void draw_mode(SkCanvas* canvas, SkXfermode* mode, SrcType srcType,
reed@google.comf3c1cc92010-12-23 16:45:33 +0000122 SkScalar x, SkScalar y) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000123 SkPaint p;
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000124 SkMatrix m;
125 bool restoreNeeded = false;
126 m.setTranslate(x, y);
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000127
Florin Malitac54d8db2014-12-10 12:02:16 -0500128 canvas->drawBitmap(fSrcB, x, y, &p);
reed@android.comdd0ac282009-06-20 02:38:16 +0000129 p.setXfermode(mode);
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000130 switch (srcType) {
Florin Malitac54d8db2014-12-10 12:02:16 -0500131 case kSmallTransparentImage_SrcType: {
commit-bot@chromium.org7542dc82013-12-03 21:08:46 +0000132 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
Florin Malitac54d8db2014-12-10 12:02:16 -0500133
134 SkAutoCanvasRestore acr(canvas, true);
135 canvas->concat(m);
136 canvas->drawBitmap(fTransparent, 0, 0, &p);
commit-bot@chromium.org7542dc82013-12-03 21:08:46 +0000137 break;
Florin Malitac54d8db2014-12-10 12:02:16 -0500138 }
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000139 case kQuarterClearInLayer_SrcType: {
vandebo@chromium.orgf5747da2013-10-30 21:29:47 +0000140 SkRect bounds = SkRect::MakeXYWH(x, y, SkIntToScalar(W),
141 SkIntToScalar(H));
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000142 canvas->saveLayer(&bounds, &p);
143 restoreNeeded = true;
144 p.setXfermodeMode(SkXfermode::kSrcOver_Mode);
145 // Fall through.
146 }
147 case kQuarterClear_SrcType: {
148 SkScalar halfW = SkIntToScalar(W) / 2;
149 SkScalar halfH = SkIntToScalar(H) / 2;
caryclark4ec1ac62015-07-21 07:42:45 -0700150 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF));
vandebo@chromium.orgf5747da2013-10-30 21:29:47 +0000151 SkRect r = SkRect::MakeXYWH(x + halfW, y, halfW,
152 SkIntToScalar(H));
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000153 canvas->drawRect(r, p);
caryclark4ec1ac62015-07-21 07:42:45 -0700154 p.setColor(sk_tool_utils::color_to_565(0xFFAA66FF));
vandebo@chromium.orgf5747da2013-10-30 21:29:47 +0000155 r = SkRect::MakeXYWH(x, y + halfH, SkIntToScalar(W), halfH);
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000156 canvas->drawRect(r, p);
157 break;
158 }
commit-bot@chromium.org4e8f1e52013-12-17 23:38:28 +0000159 case kRectangleWithMask_SrcType: {
commit-bot@chromium.org091a5942014-04-18 14:19:31 +0000160 canvas->save();
commit-bot@chromium.org4e8f1e52013-12-17 23:38:28 +0000161 restoreNeeded = true;
162 SkScalar w = SkIntToScalar(W);
163 SkScalar h = SkIntToScalar(H);
164 SkRect r = SkRect::MakeXYWH(x, y + h / 4, w, h * 23 / 60);
165 canvas->clipRect(r);
166 // Fall through.
167 }
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000168 case kRectangle_SrcType: {
169 SkScalar w = SkIntToScalar(W);
170 SkScalar h = SkIntToScalar(H);
171 SkRect r = SkRect::MakeXYWH(x + w / 3, y + h / 3,
172 w * 37 / 60, h * 37 / 60);
caryclark4ec1ac62015-07-21 07:42:45 -0700173 p.setColor(sk_tool_utils::color_to_565(0xFF66AAFF));
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000174 canvas->drawRect(r, p);
175 break;
176 }
177 case kSmallRectangleImageWithAlpha_SrcType:
178 m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
179 // Fall through.
180 case kRectangleImageWithAlpha_SrcType:
181 p.setAlpha(0x88);
182 // Fall through.
Florin Malitac54d8db2014-12-10 12:02:16 -0500183 case kRectangleImage_SrcType: {
184 SkAutoCanvasRestore acr(canvas, true);
185 canvas->concat(m);
186 canvas->drawBitmap(fDstB, 0, 0, &p);
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000187 break;
Florin Malitac54d8db2014-12-10 12:02:16 -0500188 }
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000189 default:
190 break;
191 }
192
193 if (restoreNeeded) {
194 canvas->restore();
195 }
reed@android.comdd0ac282009-06-20 02:38:16 +0000196 }
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000197
mtklein36352bf2015-03-25 18:17:31 -0700198 void onOnceBeforeDraw() override {
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000199 fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
200 kOpaque_SkAlphaType),
201 gData, 4);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000202
commit-bot@chromium.org7542dc82013-12-03 21:08:46 +0000203 make_bitmaps(W, H, &fSrcB, &fDstB, &fTransparent);
reed@google.com5213c042011-12-20 13:41:09 +0000204 }
205
reed@android.comdd0ac282009-06-20 02:38:16 +0000206public:
reed@google.comf3c1cc92010-12-23 16:45:33 +0000207 const static int W = 64;
208 const static int H = 64;
scroggo@google.com7312a182013-01-28 21:14:21 +0000209 XfermodesGM() {}
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000210
reed@android.comdd0ac282009-06-20 02:38:16 +0000211protected:
mtklein36352bf2015-03-25 18:17:31 -0700212 SkString onShortName() override {
reed@android.com8015dd82009-06-21 00:49:18 +0000213 return SkString("xfermodes");
214 }
215
mtklein36352bf2015-03-25 18:17:31 -0700216 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -0700217 return SkISize::Make(1990, 640);
reed@android.com048522d2009-06-23 12:19:41 +0000218 }
reed@android.comdd0ac282009-06-20 02:38:16 +0000219
mtklein36352bf2015-03-25 18:17:31 -0700220 void onDraw(SkCanvas* canvas) override {
reed@google.comf3c1cc92010-12-23 16:45:33 +0000221 canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000222
reed@google.comf3c1cc92010-12-23 16:45:33 +0000223 const SkScalar w = SkIntToScalar(W);
224 const SkScalar h = SkIntToScalar(H);
reed@android.comdd0ac282009-06-20 02:38:16 +0000225 SkMatrix m;
226 m.setScale(SkIntToScalar(6), SkIntToScalar(6));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000227 SkShader* s = SkShader::CreateBitmapShader(fBG,
228 SkShader::kRepeat_TileMode,
229 SkShader::kRepeat_TileMode,
230 &m);
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000231
reed@android.comdd0ac282009-06-20 02:38:16 +0000232 SkPaint labelP;
233 labelP.setAntiAlias(true);
caryclark1818acb2015-07-24 12:09:25 -0700234 sk_tool_utils::set_portable_typeface(&labelP);
reed@android.comdd0ac282009-06-20 02:38:16 +0000235 labelP.setTextAlign(SkPaint::kCenter_Align);
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000236
reed@android.comc9c64222009-06-23 00:09:12 +0000237 const int W = 5;
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000238
reed@android.comdd0ac282009-06-20 02:38:16 +0000239 SkScalar x0 = 0;
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000240 SkScalar y0 = 0;
241 for (int sourceType = 1; sourceType & kAll_SrcType; sourceType <<= 1) {
242 SkScalar x = x0, y = y0;
reed@android.comdd0ac282009-06-20 02:38:16 +0000243 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000244 if ((gModes[i].fSourceTypeMask & sourceType) == 0) {
245 continue;
246 }
reed@android.comc9c64222009-06-23 00:09:12 +0000247 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
reed@google.comf3c1cc92010-12-23 16:45:33 +0000248 SkAutoUnref aur(mode);
reed@android.comdd0ac282009-06-20 02:38:16 +0000249 SkRect r;
250 r.set(x, y, x+w, y+h);
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000251
reed@google.comf3c1cc92010-12-23 16:45:33 +0000252 SkPaint p;
reed@android.comdd0ac282009-06-20 02:38:16 +0000253 p.setStyle(SkPaint::kFill_Style);
254 p.setShader(s);
reed@android.comdd0ac282009-06-20 02:38:16 +0000255 canvas->drawRect(r, p);
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000256
halcanary96fcdcc2015-08-27 07:41:13 -0700257 canvas->saveLayer(&r, nullptr);
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000258 draw_mode(canvas, mode, static_cast<SrcType>(sourceType),
259 r.fLeft, r.fTop);
reed@google.comf3c1cc92010-12-23 16:45:33 +0000260 canvas->restore();
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000261
reed@google.comf3c1cc92010-12-23 16:45:33 +0000262 r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
263 p.setStyle(SkPaint::kStroke_Style);
halcanary96fcdcc2015-08-27 07:41:13 -0700264 p.setShader(nullptr);
reed@google.comf3c1cc92010-12-23 16:45:33 +0000265 canvas->drawRect(r, p);
tomhudson@google.com86bf5c92011-04-26 18:15:03 +0000266
reed@google.comf3c1cc92010-12-23 16:45:33 +0000267#if 1
reed@android.comdd0ac282009-06-20 02:38:16 +0000268 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
269 x + w/2, y - labelP.getTextSize()/2, labelP);
reed@google.comf3c1cc92010-12-23 16:45:33 +0000270#endif
reed@android.comdd0ac282009-06-20 02:38:16 +0000271 x += w + SkIntToScalar(10);
reed@android.comc9c64222009-06-23 00:09:12 +0000272 if ((i % W) == W - 1) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000273 x = x0;
274 y += h + SkIntToScalar(30);
275 }
276 }
vandebo@chromium.org3b416212013-10-30 20:48:05 +0000277 if (y < 320) {
278 if (x > x0) {
279 y += h + SkIntToScalar(30);
280 }
281 y0 = y;
282 } else {
283 x0 += SkIntToScalar(400);
284 y0 = 0;
285 }
reed@android.comdd0ac282009-06-20 02:38:16 +0000286 }
287 s->unref();
288 }
289
290private:
291 typedef GM INHERITED;
292};
reede7125322016-02-09 11:59:24 -0800293DEF_GM( return new XfermodesGM; )
reed@android.comdd0ac282009-06-20 02:38:16 +0000294
reede7125322016-02-09 11:59:24 -0800295///////////////////////////////////////////////////////////////////////////////////////////////////
296#include "SkNx.h"
reed@android.comdd0ac282009-06-20 02:38:16 +0000297
reede7125322016-02-09 11:59:24 -0800298static SkPMColor apply_proc(SkPMColor src, SkPMColor dst, SkXfermodeProc4f proc, float src_alpha) {
299 SkPM4f src4 = SkPM4f::FromPMColor(src);
300 for (int i = 0; i < 4; ++i) {
301 src4.fVec[i] *= src_alpha;
302 }
303 SkPM4f dst4 = SkPM4f::FromPMColor(dst);
304 SkPM4f res4 = proc(src4, dst4);
305 SkPMColor res;
306 SkNx_cast<uint8_t>(Sk4f::Load(res4.fVec) * Sk4f(255) + Sk4f(0.5f)).store(&res);
307 return res;
308}
reed@android.comdd0ac282009-06-20 02:38:16 +0000309
reede7125322016-02-09 11:59:24 -0800310static bool apply_mode(const SkPixmap& res, const SkPixmap& src, const SkPixmap& dst,
311 SkXfermode* xfer, float src_alpha) {
312 SkXfermode::Mode mode;
313 if (!xfer) {
314 mode = SkXfermode::kSrcOver_Mode;
315 } else if (!xfer->asMode(&mode)) {
316 return false;
317 }
318 SkXfermodeProc4f proc = SkXfermode::GetProc4f(mode);
319 if (!proc) {
320 return false;
321 }
322
323 for (int y = 0; y < res.height(); ++y) {
324 for (int x = 0; x < res.width(); ++x) {
325 *res.writable_addr32(x, y) = apply_proc(*src.addr32(x, y), *dst.addr32(x, y),
326 proc, src_alpha);
327 }
328 }
329 return true;
330}
331
332void draw_mode(const SkBitmap& srcB, const SkBitmap& dstB,
333 SkCanvas* canvas, SkXfermode* mode, SkScalar x, SkScalar y, float src_alpha) {
334 SkBitmap resB;
335 resB.allocN32Pixels(64, 64);
336
337 SkPixmap srcPM, dstPM, resPM;
338 srcB.peekPixels(&srcPM);
339 dstB.peekPixels(&dstPM);
340 resB.peekPixels(&resPM);
341
342 if (apply_mode(resPM, srcPM, dstPM, mode, src_alpha)) {
343 canvas->drawBitmap(resB, x, y, nullptr);
344 }
345}
346
347DEF_SIMPLE_GM(xfermodes_proc4f, canvas, 1000, 1000) {
348 SkBitmap bg, srcB, dstB, transparent;
349
350 bg.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kOpaque_SkAlphaType),
351 gData, 4);
352 make_bitmaps(64, 64, &dstB, &srcB, &transparent);
353
354 canvas->translate(10, 20);
355
356 const SkScalar w = 64;
357 const SkScalar h = 64;
358 SkMatrix m = SkMatrix::MakeScale(6, 6);
359 SkShader* s = SkShader::CreateBitmapShader(bg,
360 SkShader::kRepeat_TileMode,
361 SkShader::kRepeat_TileMode,
362 &m);
363
364 SkPaint labelP;
365 labelP.setAntiAlias(true);
366 sk_tool_utils::set_portable_typeface(&labelP);
367 labelP.setTextAlign(SkPaint::kCenter_Align);
368
369 const int W = 5;
370
371 const float alphas[] = { 1.0f, 0.5f };
372
373 for (auto alpha : alphas) {
374 SkScalar x0 = 0;
375 SkScalar y0 = 0;
376 SkScalar x = x0, y = y0;
377 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
378 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
379 SkAutoUnref aur(mode);
380 SkRect r;
381 r.set(x, y, x+w, y+h);
382
383 SkPaint p;
384 p.setStyle(SkPaint::kFill_Style);
385 p.setShader(s);
386 canvas->drawRect(r, p);
387
388 draw_mode(srcB, dstB, canvas, mode, r.fLeft, r.fTop, alpha);
389
390 r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
391 p.setStyle(SkPaint::kStroke_Style);
392 p.setShader(nullptr);
393 canvas->drawRect(r, p);
394
395 #if 1
396 canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),
397 x + w/2, y - labelP.getTextSize()/2, labelP);
398 #endif
399 x += w + SkIntToScalar(10);
400 if ((i % W) == W - 1) {
401 x = x0;
402 y += h + SkIntToScalar(30);
403 }
404 }
405 if (y < 320) {
406 if (x > x0) {
407 y += h + SkIntToScalar(30);
408 }
409 y0 = y;
410 } else {
411 x0 += SkIntToScalar(400);
412 y0 = 0;
413 }
414
415 canvas->translate(400, 0);
416 }
417 s->unref();
reed@android.comdd0ac282009-06-20 02:38:16 +0000418}