aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/srcmode.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-15 13:46:47 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-15 13:46:47 +0000
commit5dd85a45bcb3c529d8d849f428ae51dc70129aef (patch)
tree1bed9ad86c766217502b09dda18029a1525d2794 /gm/srcmode.cpp
parent0f5891caf684b1d913b69d7a654f6ccb2a84ed8c (diff)
add gm for srcmode (and clearmode) in prep for optimization work
git-svn-id: http://skia.googlecode.com/svn/trunk@6429 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/srcmode.cpp')
-rw-r--r--gm/srcmode.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp
new file mode 100644
index 0000000000..3aa1b5759c
--- /dev/null
+++ b/gm/srcmode.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+
+#define W SkIntToScalar(100)
+#define H SkIntToScalar(60)
+
+typedef void (*Proc)(SkCanvas*, const SkPaint&);
+
+static void draw_hair(SkCanvas* canvas, const SkPaint& paint) {
+ SkPaint p(paint);
+ p.setStrokeWidth(0);
+ canvas->drawLine(0, 0, W, H, p);
+}
+
+static void draw_thick(SkCanvas* canvas, const SkPaint& paint) {
+ SkPaint p(paint);
+ p.setStrokeWidth(H/5);
+ canvas->drawLine(0, 0, W, H, p);
+}
+
+static void draw_rect(SkCanvas* canvas, const SkPaint& paint) {
+ canvas->drawRect(SkRect::MakeWH(W, H), paint);
+}
+
+static void draw_oval(SkCanvas* canvas, const SkPaint& paint) {
+ canvas->drawOval(SkRect::MakeWH(W, H), paint);
+}
+
+static void draw_text(SkCanvas* canvas, const SkPaint& paint) {
+ SkPaint p(paint);
+ p.setTextSize(H/4);
+ canvas->drawText("Hamburgefons", 12, 0, H*2/3, p);
+}
+
+class SrcModeGM : public skiagm::GM {
+ SkPath fPath;
+public:
+ SrcModeGM() {
+ this->setBGColor(0xFFDDDDDD);
+ }
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("srcmode");
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(640, 480);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(0x80FF0000);
+
+ const Proc procs[] = {
+ draw_hair, draw_thick, draw_rect, draw_oval, draw_text
+ };
+
+ const SkXfermode::Mode modes[] = {
+ SkXfermode::kSrcOver_Mode, SkXfermode::kSrc_Mode, SkXfermode::kClear_Mode
+ };
+
+ for (size_t x = 0; x < SK_ARRAY_COUNT(modes); ++x) {
+ paint.setXfermodeMode(modes[x]);
+ canvas->save();
+ for (size_t y = 0; y < SK_ARRAY_COUNT(procs); ++y) {
+ procs[y](canvas, paint);
+ canvas->translate(0, H * 5 / 4);
+ }
+ canvas->restore();
+ canvas->translate(W * 5 / 4, 0);
+ }
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_GM(return new SrcModeGM;)
+