Index: gm/transparency.cpp |
diff --git a/gm/transparency.cpp b/gm/transparency.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2e77d5b42f906d2168d97e4db2d7be2c8a5c8a56 |
--- /dev/null |
+++ b/gm/transparency.cpp |
@@ -0,0 +1,57 @@ |
+/* |
+ * 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 "SkGradientShader.h" |
+#include "SkSurface.h" |
+#include "checkerboard.h" |
+#include "gm.h" |
+ |
+static void make_transparency(SkCanvas* canvas, |
+ SkScalar width, |
+ SkScalar height) { |
+ SkPoint pts[2]; |
+ pts[0] = SkPoint::Make(0, 0); |
+ pts[1] = SkPoint::Make(width, 0); |
+ const SkColor kColors[] = { |
+ SK_ColorBLACK, |
+ SK_ColorGRAY, |
+ SK_ColorWHITE, |
+ SK_ColorRED, |
+ SK_ColorYELLOW, |
+ SK_ColorGREEN, |
+ SK_ColorCYAN, |
+ SK_ColorBLUE, |
+ SK_ColorMAGENTA, |
+ }; |
+ const SkScalar kRowHeight = height / SK_ARRAY_COUNT(kColors); |
+ for (size_t i = 0; i < SK_ARRAY_COUNT(kColors); ++i) { |
+ SkColor shaderColors[2]; |
+ shaderColors[0] = SK_AlphaTRANSPARENT; |
+ shaderColors[1] = kColors[i]; |
+ SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear( |
+ pts, shaderColors, NULL, 2, SkShader::kClamp_TileMode)); |
+ SkRect r = SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight); |
+ SkPaint p; |
+ p.setShader(shader); |
+ canvas->drawRect(r, p); |
+ } |
+} |
+ |
+/** |
+ * This GM verifies that a transparent bitmap drawn over a |
+ * checkerboard pattern looks correct. |
+ */ |
+DEF_SIMPLE_GM(transparency_check, canvas, 1912, 1080) { |
+ skiagm::Checkerboard(canvas); |
+ { |
+ SkAutoCanvasRestore autoCanvasRestore(canvas, true); |
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(256, 9)); |
+ make_transparency(surface->getCanvas(), 256.0f, 9.0f); |
+ canvas->scale(7.5f, 120.0f); |
+ surface->draw(canvas, 0, 0, NULL); |
+ } |
+} |