blob: 3aa1b5759ce3a53b0d9a6fc9602f17455bd31be2 [file] [log] [blame]
reed@google.com5dd85a42012-11-15 13:46:47 +00001/*
2 * Copyright 2012 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 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10
11#define W SkIntToScalar(100)
12#define H SkIntToScalar(60)
13
14typedef void (*Proc)(SkCanvas*, const SkPaint&);
15
16static void draw_hair(SkCanvas* canvas, const SkPaint& paint) {
17 SkPaint p(paint);
18 p.setStrokeWidth(0);
19 canvas->drawLine(0, 0, W, H, p);
20}
21
22static void draw_thick(SkCanvas* canvas, const SkPaint& paint) {
23 SkPaint p(paint);
24 p.setStrokeWidth(H/5);
25 canvas->drawLine(0, 0, W, H, p);
26}
27
28static void draw_rect(SkCanvas* canvas, const SkPaint& paint) {
29 canvas->drawRect(SkRect::MakeWH(W, H), paint);
30}
31
32static void draw_oval(SkCanvas* canvas, const SkPaint& paint) {
33 canvas->drawOval(SkRect::MakeWH(W, H), paint);
34}
35
36static void draw_text(SkCanvas* canvas, const SkPaint& paint) {
37 SkPaint p(paint);
38 p.setTextSize(H/4);
39 canvas->drawText("Hamburgefons", 12, 0, H*2/3, p);
40}
41
42class SrcModeGM : public skiagm::GM {
43 SkPath fPath;
44public:
45 SrcModeGM() {
46 this->setBGColor(0xFFDDDDDD);
47 }
48
49protected:
50 virtual SkString onShortName() {
51 return SkString("srcmode");
52 }
53
54 virtual SkISize onISize() {
55 return SkISize::Make(640, 480);
56 }
57
58 virtual void onDraw(SkCanvas* canvas) {
59 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
60
61 SkPaint paint;
62 paint.setAntiAlias(true);
63 paint.setColor(0x80FF0000);
64
65 const Proc procs[] = {
66 draw_hair, draw_thick, draw_rect, draw_oval, draw_text
67 };
68
69 const SkXfermode::Mode modes[] = {
70 SkXfermode::kSrcOver_Mode, SkXfermode::kSrc_Mode, SkXfermode::kClear_Mode
71 };
72
73 for (size_t x = 0; x < SK_ARRAY_COUNT(modes); ++x) {
74 paint.setXfermodeMode(modes[x]);
75 canvas->save();
76 for (size_t y = 0; y < SK_ARRAY_COUNT(procs); ++y) {
77 procs[y](canvas, paint);
78 canvas->translate(0, H * 5 / 4);
79 }
80 canvas->restore();
81 canvas->translate(W * 5 / 4, 0);
82 }
83 }
84
85private:
86 typedef skiagm::GM INHERITED;
87};
88
89///////////////////////////////////////////////////////////////////////////////
90
91DEF_GM(return new SrcModeGM;)
92