2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkColorPriv.h"
13 static void test4(SkCanvas* canvas) {
15 paint.setAntiAlias(true);
17 {10, 160}, {610, 160},
18 {610, 160}, {10, 160},
20 {610, 160}, {610, 160},
21 {610, 199}, {610, 199},
23 {10, 198}, {610, 198},
24 {610, 199}, {10, 199},
37 for (size_t i = 0; i < sizeof(verbs); ++i) {
38 switch ((SkPath::Verb) verbs[i]) {
39 case SkPath::kMove_Verb:
40 path.moveTo(ptPtr->fX, ptPtr->fY);
43 case SkPath::kLine_Verb:
44 path.lineTo(ptPtr->fX, ptPtr->fY);
47 case SkPath::kClose_Verb:
55 SkRect clip = {0, 130, 772, 531};
56 canvas->clipRect(clip);
57 canvas->drawPath(path, paint);
61 SkXfermode::Mode fMode;
64 { SkXfermode::kClear_Mode, "Clear" },
65 { SkXfermode::kSrc_Mode, "Src" },
66 { SkXfermode::kDst_Mode, "Dst" },
67 { SkXfermode::kSrcOver_Mode, "SrcOver" },
68 { SkXfermode::kDstOver_Mode, "DstOver" },
69 { SkXfermode::kSrcIn_Mode, "SrcIn" },
70 { SkXfermode::kDstIn_Mode, "DstIn" },
71 { SkXfermode::kSrcOut_Mode, "SrcOut" },
72 { SkXfermode::kDstOut_Mode, "DstOut" },
73 { SkXfermode::kSrcATop_Mode, "SrcATop" },
74 { SkXfermode::kDstATop_Mode, "DstATop" },
75 { SkXfermode::kXor_Mode, "Xor" },
78 const int gWidth = 64;
79 const int gHeight = 64;
80 const SkScalar W = SkIntToScalar(gWidth);
81 const SkScalar H = SkIntToScalar(gHeight);
83 static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode,
84 SkAlpha a0, SkAlpha a1) {
87 paint.setAntiAlias(true);
89 SkRect r = SkRect::MakeWH(W, H);
92 paint.setColor(SK_ColorBLUE);
94 canvas->drawOval(r, paint);
96 paint.setColor(SK_ColorRED);
98 paint.setXfermode(mode);
100 SkScalar offset = SK_Scalar1 / 3;
101 SkRect rect = SkRect::MakeXYWH(W / 4 + offset,
104 canvas->drawRect(rect, paint);
109 static SkShader* make_bg_shader() {
111 bm.allocN32Pixels(2, 2);
112 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
113 *bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCC,
117 m.setScale(SkIntToScalar(6), SkIntToScalar(6));
118 SkShader* s = SkShader::CreateBitmapShader(bm,
119 SkShader::kRepeat_TileMode,
120 SkShader::kRepeat_TileMode,
128 class AARectModesGM : public GM {
132 fBGPaint.setShader(make_bg_shader())->unref();
137 SkString onShortName() SK_OVERRIDE {
138 return SkString("aarectmodes");
141 SkISize onISize() SK_OVERRIDE { return SkISize::Make(640, 480); }
143 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
144 if (false) { // avoid bit rot, suppress warning
147 const SkRect bounds = SkRect::MakeWH(W, H);
148 static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
150 canvas->translate(SkIntToScalar(4), SkIntToScalar(4));
152 for (int alpha = 0; alpha < 4; ++alpha) {
155 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); ++i) {
158 canvas->translate(W * 5, 0);
161 SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
163 canvas->drawRect(bounds, fBGPaint);
164 canvas->saveLayer(&bounds, NULL);
165 SkScalar dy = drawCell(canvas, mode,
166 gAlphaValue[alpha & 1],
167 gAlphaValue[alpha & 2]);
170 canvas->translate(0, dy * 5 / 4);
175 canvas->translate(W * 5 / 4, 0);
180 typedef GM INHERITED;
183 //////////////////////////////////////////////////////////////////////////////
185 static GM* MyFactory(void*) { return new AARectModesGM; }
186 static GMRegistry reg(MyFactory);