Index: tools/Checkerboard.cpp |
diff --git a/tools/Checkerboard.cpp b/tools/Checkerboard.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80de125f1569f87c114df4e54e082f4f408a84be |
--- /dev/null |
+++ b/tools/Checkerboard.cpp |
@@ -0,0 +1,28 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "Checkerboard.h" |
+#include "SkCanvas.h" |
+#include "SkShader.h" |
+ |
+SkShader* sk_tools::CreateCheckerboardShader( |
+ SkColor c1, SkColor c2, int size) { |
+ SkBitmap bm; |
+ bm.allocN32Pixels(2 * size, 2 * size); |
+ bm.eraseColor(c1); |
+ bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2); |
+ bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2); |
+ return SkShader::CreateBitmapShader( |
+ bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
+} |
+ |
+void sk_tools::DrawCheckerboard(SkCanvas* canvas, |
+ SkColor c1, SkColor c2, int size) { |
+ SkPaint paint; |
+ paint.setShader(CreateCheckerboardShader(c1, c2, size))->unref(); |
+ canvas->drawPaint(paint); |
+} |