aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/badpaint.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2015-04-15 14:18:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-15 14:18:34 -0700
commitbed83a66f5fa5821a3a08da32157a6155960b15e (patch)
tree91c3878d7233b716049d0396d97fd4d60eb38ba8 /gm/badpaint.cpp
parentbc0273524b039c45dcea2c1ab5ab379c75486c07 (diff)
Don't draw if SkShader::asNewFragmentProcessor fails.
BUG=chromium:473156 Review URL: https://codereview.chromium.org/1089063002
Diffstat (limited to 'gm/badpaint.cpp')
-rw-r--r--gm/badpaint.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/gm/badpaint.cpp b/gm/badpaint.cpp
new file mode 100644
index 0000000000..45b17f85fe
--- /dev/null
+++ b/gm/badpaint.cpp
@@ -0,0 +1,62 @@
+/*
+ * 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 "gm.h"
+#include "SkCanvas.h"
+#include "SkShader.h"
+
+
+/** This GM draws with invalid paints. It should draw nothing other than the background. */
+class BadPaintGM : public skiagm::GM {
+ public:
+ BadPaintGM() {}
+
+protected:
+ SkString onShortName() override { return SkString("badpaint"); }
+
+ SkISize onISize() override { return SkISize::Make(100, 100); }
+
+ void onOnceBeforeDraw() override {
+ SkBitmap emptyBmp;
+
+ SkBitmap blueBmp;
+ blueBmp.allocN32Pixels(10, 10);
+ blueBmp.eraseColor(SK_ColorBLUE);
+
+ SkMatrix badMatrix;
+ badMatrix.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
+
+#if 0 // This crashes pipe!
+ // Empty bitmap.
+ fPaints.push_back().setColor(SK_ColorGREEN);
+ fPaints.back().setShader(SkShader::CreateBitmapShader(emptyBmp, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode))->unref();
+#endif
+
+ // Non-invertible local matrix.
+ fPaints.push_back().setColor(SK_ColorGREEN);
+ fPaints.back().setShader(SkShader::CreateBitmapShader(blueBmp, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode,
+ &badMatrix))->unref();
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ SkRect rect = SkRect::MakeXYWH(10, 10, 80, 80);
+ for (int i = 0; i < fPaints.count(); ++i) {
+ canvas->drawRect(rect, fPaints[i]);
+ }
+ }
+
+private:
+ SkTArray<SkPaint> fPaints;
+
+ typedef skiagm::GM INHERITED;
+};
+
+/////////////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return SkNEW(BadPaintGM); )