Add bigrect GM.
authorBen Wagner <benjaminwagner@google.com>
Thu, 4 May 2017 22:04:53 +0000 (18:04 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 5 May 2017 19:21:42 +0000 (19:21 +0000)
Previous version in https://codereview.chromium.org/1758113005
was reverted.

Bug: skia:4632
Change-Id: I9a85f11ca3a6fcd5e67016edf67f0538f00b6f01
Reviewed-on: https://skia-review.googlesource.com/14751
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Ben Wagner <benjaminwagner@google.com>

gm/bigrect.cpp [new file with mode: 0644]
gn/gm.gni

diff --git a/gm/bigrect.cpp b/gm/bigrect.cpp
new file mode 100644 (file)
index 0000000..d2ba7fe
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2016 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"
+
+// Draws big rects with clip (0, 0, 35, 35). The size of the rects is given by big.
+static void draw_big_rect(SkCanvas* canvas, SkScalar big, const SkPaint& rectPaint) {
+    // Looks like this:
+    // +--+-+----+-+----+
+    // |  | |    | |    |
+    // |--+-+----+-+----+
+    // |--+-+----+-+----+
+    // |  | |    | |    |
+    // |  | |    +-+    |
+    // +--+-+--+     +--+
+    // +--+-+--+     +--+
+    // |  | |    +-+    |
+    // |  | |    | |    |
+    // +--+-+----+-+----+
+
+    canvas->clipRect({0, 0, 35, 35});
+
+    // Align to pixel boundaries.
+    canvas->translate(0.5, 0.5);
+
+    SkRect horiz = SkRect::MakeLTRB(-big, 5, big, 10);
+    canvas->drawRect(horiz, rectPaint);
+
+    SkRect vert = SkRect::MakeLTRB(5, -big, 10, big);
+    canvas->drawRect(vert, rectPaint);
+
+    SkRect fromLeft = SkRect::MakeLTRB(-big, 20, 17, 25);
+    canvas->drawRect(fromLeft, rectPaint);
+
+    SkRect fromTop = SkRect::MakeLTRB(20, -big, 25, 17);
+    canvas->drawRect(fromTop, rectPaint);
+
+    SkRect fromRight = SkRect::MakeLTRB(28, 20, big, 25);
+    canvas->drawRect(fromRight, rectPaint);
+
+    SkRect fromBottom = SkRect::MakeLTRB(20, 28, 25, big);
+    canvas->drawRect(fromBottom, rectPaint);
+
+    SkRect leftBorder = SkRect::MakeLTRB(-2, -1, 0, 35);
+    canvas->drawRect(leftBorder, rectPaint);
+
+    SkRect topBorder = SkRect::MakeLTRB(-1, -2, 35, 0);
+    canvas->drawRect(topBorder, rectPaint);
+
+    SkRect rightBorder = SkRect::MakeLTRB(34, -1, 36, 35);
+    canvas->drawRect(rightBorder, rectPaint);
+
+    SkRect bottomBorder = SkRect::MakeLTRB(-1, 34, 35, 36);
+    canvas->drawRect(bottomBorder, rectPaint);
+
+    SkPaint outOfBoundsPaint;
+    outOfBoundsPaint.setColor(SK_ColorRED);
+    outOfBoundsPaint.setStyle(SkPaint::kStroke_Style);
+    outOfBoundsPaint.setStrokeWidth(0);
+
+    SkRect outOfBounds = SkRect::MakeLTRB(-1, -1, 35, 35);
+    canvas->drawRect(outOfBounds, outOfBoundsPaint);
+}
+
+DEF_SIMPLE_GM(bigrect, canvas, 325, 125) {
+    // Test with sizes:
+    //   - reasonable size (for comparison),
+    //   - outside the range of int32, and
+    //   - outside the range of SkFixed.
+    static const SkScalar sizes[] = {SkIntToScalar(100), 5e10f, 1e6f};
+
+    for (int i = 0; i < 8; i++) {
+        for (int j = 0; j < 3; j++) {
+            canvas->save();
+            canvas->translate(SkIntToScalar(i*40+5), SkIntToScalar(j*40+5));
+
+            SkPaint paint;
+            paint.setColor(SK_ColorBLUE);
+            // These are the three parameters that affect the behavior of SkDraw::drawRect.
+            if (i & 1) {
+                paint.setStyle(SkPaint::kFill_Style);
+            } else {
+                paint.setStyle(SkPaint::kStroke_Style);
+            }
+            if (i & 2) {
+                paint.setStrokeWidth(1);
+            } else {
+                paint.setStrokeWidth(0);
+            }
+            if (i & 4) {
+                paint.setAntiAlias(true);
+            } else {
+                paint.setAntiAlias(false);
+            }
+
+            const SkScalar big = SkFloatToScalar(sizes[j]);
+            draw_big_rect(canvas, big, paint);
+            canvas->restore();
+        }
+    }
+}
index a14c2eb..ae30ca8 100644 (file)
--- a/gn/gm.gni
+++ b/gn/gm.gni
@@ -26,6 +26,7 @@ gm_sources = [
   "$_gm/beziers.cpp",
   "$_gm/bigblurs.cpp",
   "$_gm/bigmatrix.cpp",
+  "$_gm/bigrect.cpp",
   "$_gm/bigrrectaaeffect.cpp",
   "$_gm/bigtext.cpp",
   "$_gm/bigtileimagefilter.cpp",