Add new GMs to stress rendering of many circles and rrects
authorJim Van Verth <jvanverth@google.com>
Tue, 21 Feb 2017 22:55:13 +0000 (17:55 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 22 Feb 2017 18:01:11 +0000 (18:01 +0000)
Change-Id: I060419bc39484b379329a1691e199d9d3db9c808
Reviewed-on: https://skia-review.googlesource.com/8807
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
gm/manypaths.cpp [new file with mode: 0644]
gn/gm.gni
src/gpu/ops/GrOvalOpFactory.cpp

diff --git a/gm/manypaths.cpp b/gm/manypaths.cpp
new file mode 100644 (file)
index 0000000..c33552f
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2017 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 "SkRandom.h"
+#include "SkRect.h"
+#include "SkRRect.h"
+
+namespace skiagm {
+
+static SkColor gen_color(SkRandom* rand) {
+    SkScalar hsv[3];
+    hsv[0] = rand->nextRangeF(0.0f, 360.0f);
+    hsv[1] = rand->nextRangeF(0.5f, 1.0f);
+    hsv[2] = rand->nextRangeF(0.5f, 1.0f);
+
+    return sk_tool_utils::color_to_565(SkHSVToColor(hsv));
+}
+
+class ManyCirclesGM : public GM {
+    // This GM attempts to flood Ganesh with more circles than will fit in a single index buffer
+    // Stresses crbug.com/688582.
+public:
+    ManyCirclesGM() {
+        this->setBGColor(0xFFFFFFFF);
+    }
+
+protected:
+    static const int kWidth = 800;
+    static const int kHeight = 600;
+
+    SkString onShortName() override {
+        return SkString("manycircles");
+    }
+
+    SkISize onISize() override {
+        return SkISize::Make(kWidth, kHeight);
+    }
+
+    void onDraw(SkCanvas* canvas) override {
+        SkRandom rand(1);
+        SkPaint paint;
+        paint.setAntiAlias(true);
+        int total = 10000;
+        while (total--) {
+            SkScalar x = rand.nextF() * kWidth - 100;
+            SkScalar y = rand.nextF() * kHeight - 100;
+            SkScalar w = rand.nextF() * 200;
+            SkRect circle = SkRect::MakeXYWH(x, y, w, w);
+            paint.setColor(gen_color(&rand));
+            canvas->drawOval(circle, paint);
+        }
+    }
+
+private:
+    typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+class ManyRRectsGM : public GM {
+    // This GM attempts to flood Ganesh with more rrects than will fit in a single index buffer
+    // Stresses crbug.com/684112
+public:
+    ManyRRectsGM() {
+        this->setBGColor(0xFFFFFFFF);
+    }
+
+protected:
+
+    SkString onShortName() override {
+        return SkString("manyrrects");
+    }
+
+    SkISize onISize() override {
+        return SkISize::Make(800, 300);
+    }
+
+    void onDraw(SkCanvas* canvas) override {
+        SkRandom rand(1);
+        SkPaint paint;
+        paint.setAntiAlias(true);
+        paint.setColor(SK_ColorBLUE);
+        int total = 7000;
+
+        // Rectangle positioning variables
+        int x = 0;
+        int y = 0;
+        const int kXLimit = 700;
+        const int kYIncrement = 5;
+        const int kXIncrement = 5;
+
+        SkRect rect = SkRect::MakeLTRB(0, 0, 4, 4);
+        SkRRect rrect = SkRRect::MakeRectXY(rect, 1, 1);
+        while (total--) {
+            canvas->save();
+            canvas->translate(x, y);
+            canvas->drawRRect(rrect, paint);
+            x += kXIncrement;
+            if (x > kXLimit) {
+                x = 0;
+                y += kYIncrement;
+            }
+            canvas->restore();
+        }
+    }
+
+private:
+    typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return new ManyCirclesGM; )
+DEF_GM( return new ManyRRectsGM; )
+
+}
index d9c25652b0db1fa138bad26c4ca69a75bb4e161c..32c22d7f06cc21a38e82260382d4cb7399311de5 100644 (file)
--- a/gn/gm.gni
+++ b/gn/gm.gni
@@ -188,6 +188,7 @@ gm_sources = [
   "$_gm/linepaths.cpp",
   "$_gm/localmatriximagefilter.cpp",
   "$_gm/lumafilter.cpp",
+  "$_gm/manypaths.cpp",
   "$_gm/matrixconvolution.cpp",
   "$_gm/matriximagefilter.cpp",
   "$_gm/megalooper.cpp",
index 5f04dd48f0b73b9b64c062e2e66651b3e619e6ec..f1c8f9aec25ecfac97ea22579d3d70dc8c80bf61 100644 (file)
@@ -1104,7 +1104,7 @@ private:
         CircleOp* that = t->cast<CircleOp>();
 
         // can only represent 65535 unique vertices with 16-bit indices
-        if (fVertCount + that->fVertCount > 65535) {
+        if (fVertCount + that->fVertCount > 65536) {
             return false;
         }
 
@@ -2001,7 +2001,7 @@ private:
         CircularRRectOp* that = t->cast<CircularRRectOp>();
 
         // can only represent 65535 unique vertices with 16-bit indices
-        if (fVertCount + that->fVertCount > 65535) {
+        if (fVertCount + that->fVertCount > 65536) {
             return false;
         }