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

Unified Diff: tests/RectTest.cpp

Issue 801353008: Use device-space stroke width for SkDraw::drawRect() quick-reject (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: 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 | « src/core/SkDraw.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RectTest.cpp
diff --git a/tests/RectTest.cpp b/tests/RectTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..be77a87406168a4bae5463c96c38bf8d114c4bfa
--- /dev/null
+++ b/tests/RectTest.cpp
@@ -0,0 +1,51 @@
+/*
+ * 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 "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkRect.h"
+#include "Test.h"
+
+static bool has_green_pixels(const SkBitmap& bm) {
+ for (int j = 0; j < bm.height(); ++j) {
+ for (int i = 0; i < bm.width(); ++i) {
+ if (SkColorGetG(bm.getColor(i, j))) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+static void test_stroke_width_clipping(skiatest::Reporter* reporter) {
+ SkBitmap bm;
+ bm.allocN32Pixels(100, 10);
+ bm.eraseColor(SK_ColorTRANSPARENT);
+
+ SkCanvas canvas(bm);
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(10);
+ paint.setColor(0xff00ff00);
+
+ // clip out the left half of our canvas
+ canvas.clipRect(SkRect::MakeXYWH(51, 0, 49, 100));
+
+ // no stroke bleed should be visible
+ canvas.drawRect(SkRect::MakeWH(44, 100), paint);
+ REPORTER_ASSERT(reporter, !has_green_pixels(bm));
+
+ // right stroke edge should bleed into the visible area
+ canvas.scale(2, 2);
+ canvas.drawRect(SkRect::MakeWH(22, 50), paint);
+ REPORTER_ASSERT(reporter, has_green_pixels(bm));
+}
+
+DEF_TEST(Rect, reporter) {
+ test_stroke_width_clipping(reporter);
+}
« no previous file with comments | « src/core/SkDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698