Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1148)

Unified Diff: tools/Checkerboard.cpp

Issue 834303005: Factor out checkerboard function in gm and sampleapp into tools. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rename to sk_tools::DrawCheckerboard Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/Checkerboard.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« no previous file with comments | « tools/Checkerboard.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698