Fix gpu dashing for case where all intervals are 0.

BUG=skia:4409

Review URL: https://codereview.chromium.org/1381803005
This commit is contained in:
egdaniel 2015-10-05 08:11:49 -07:00 committed by Commit bot
parent 6f6264fbbc
commit c00389e45a
2 changed files with 21 additions and 1 deletions

View File

@ -54,7 +54,7 @@ protected:
return SkString("dashing");
}
SkISize onISize() { return SkISize::Make(640, 300); }
SkISize onISize() { return SkISize::Make(640, 340); }
virtual void onDraw(SkCanvas* canvas) {
static const struct {
@ -90,6 +90,10 @@ protected:
show_giant_dash(canvas);
canvas->translate(0, SkIntToScalar(20));
show_zero_len_dash(canvas);
canvas->translate(0, SkIntToScalar(20));
// Draw 0 on, 0 off dashed line
paint.setStrokeWidth(SkIntToScalar(8));
drawline(canvas, 0, 0, paint);
}
};

View File

@ -9,6 +9,15 @@
#include "GrResourceKey.h"
#include "SkDashPathPriv.h"
bool all_dash_intervals_zero(const SkScalar* intervals, int count) {
for (int i = 0 ; i < count; ++i) {
if (intervals[i] != 0) {
return false;
}
}
return true;
}
bool GrStrokeInfo::applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo,
const SkPath& src) const {
if (this->isDashed()) {
@ -17,6 +26,13 @@ bool GrStrokeInfo::applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo,
info.fCount = fIntervals.count();
info.fPhase = fDashPhase;
GrStrokeInfo filteredStroke(*this, false);
// Handle the case where all intervals are 0 and we simply drop the dash effect
if (all_dash_intervals_zero(fIntervals.get(), fIntervals.count())) {
*dstStrokeInfo = filteredStroke;
*dst = src;
return true;
}
// See if we can filter the dash into a path on cpu
if (SkDashPath::FilterDashPath(dst, src, &filteredStroke, nullptr, info)) {
*dstStrokeInfo = filteredStroke;
return true;