aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar aleksandar.stojiljkovic <aleksandar.stojiljkovic@intel.com>2015-11-02 13:28:51 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-02 13:28:51 -0800
commit7600183ba7d8c8df6fbba1b32a73e6394216754e (patch)
tree61bb64b51077a78a0c679105af3a5396f671c1ec
parent29a440d2d6f306498a7b54e978e3b034bd625c19 (diff)
SkScan_Antihair: assert in debug and potentialy lost last pixels
alpha: (uint8_t) 256 is clamped to 255 before static cast to uint8_t in SkToU8. BUG=4406 Review URL: https://codereview.chromium.org/1424253002
-rw-r--r--src/core/SkScan_Antihair.cpp6
-rw-r--r--tests/RectTest.cpp39
2 files changed, 44 insertions, 1 deletions
diff --git a/src/core/SkScan_Antihair.cpp b/src/core/SkScan_Antihair.cpp
index beddf63202..b14e12bab8 100644
--- a/src/core/SkScan_Antihair.cpp
+++ b/src/core/SkScan_Antihair.cpp
@@ -847,7 +847,11 @@ static void inner_scanline(FDot8 L, int top, FDot8 R, U8CPU alpha,
SkASSERT(L < R);
if ((L >> 8) == ((R - 1) >> 8)) { // 1x1 pixel
- blitter->blitV(L >> 8, top, 1, InvAlphaMul(alpha, R - L));
+ FDot8 widClamp = R - L;
+ // border case clamp 256 to 255 instead of going through call_hline_blitter
+ // see skbug/4406
+ widClamp = widClamp - (widClamp >> 8);
+ blitter->blitV(L >> 8, top, 1, InvAlphaMul(alpha, widClamp));
return;
}
diff --git a/tests/RectTest.cpp b/tests/RectTest.cpp
index be77a87406..820586c3c6 100644
--- a/tests/RectTest.cpp
+++ b/tests/RectTest.cpp
@@ -46,6 +46,45 @@ static void test_stroke_width_clipping(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, has_green_pixels(bm));
}
+static void test_skbug4406(skiatest::Reporter* reporter) {
+ SkBitmap bm;
+ bm.allocN32Pixels(10, 10);
+ bm.eraseColor(SK_ColorTRANSPARENT);
+
+ SkCanvas canvas(bm);
+ const SkRect r = { 1.5f, 1, 3.5f, 3 };
+ // draw filled green rect first
+ SkPaint paint;
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(0xff00ff00);
+ paint.setStrokeWidth(1);
+ paint.setAntiAlias(true);
+ canvas.drawRect(r, paint);
+
+ // paint black with stroke rect (that asserts in bug 4406)
+ // over the filled rect, it should cover it
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setColor(0xff000000);
+ paint.setStrokeWidth(1);
+ canvas.drawRect(r, paint);
+ REPORTER_ASSERT(reporter, !has_green_pixels(bm));
+
+ // do it again with thinner stroke
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(0xff00ff00);
+ paint.setStrokeWidth(1);
+ paint.setAntiAlias(true);
+ canvas.drawRect(r, paint);
+ // paint black with stroke rect (that asserts in bug 4406)
+ // over the filled rect, it doesnt cover it completelly with thinner stroke
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setColor(0xff000000);
+ paint.setStrokeWidth(0.99f);
+ canvas.drawRect(r, paint);
+ REPORTER_ASSERT(reporter, has_green_pixels(bm));
+}
+
DEF_TEST(Rect, reporter) {
test_stroke_width_clipping(reporter);
+ test_skbug4406(reporter);
}