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

Unified Diff: gm/mixedxfermodes.cpp

Issue 666043003: Preventing division by 0 in non-separable blend mode shaders. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: addressing comments Created 6 years, 1 month 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 | « no previous file | src/core/SkXfermode.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/mixedxfermodes.cpp
diff --git a/gm/mixedxfermodes.cpp b/gm/mixedxfermodes.cpp
index a5023e1b0b07218ad6b2acc171568ecae7d35de4..37b8da3c15a240f94d3c1808e01f31b5e7642b05 100644
--- a/gm/mixedxfermodes.cpp
+++ b/gm/mixedxfermodes.cpp
@@ -22,6 +22,15 @@ public:
}
protected:
+ enum ShapeType {
+ kShapeTypeCircle,
+ kShapeTypeRoundRect,
+ kShapeTypeRect,
+ kShapeTypeConvexPath,
+ kShapeTypeConcavePath,
+ kNumShapeTypes
+ };
+
virtual SkString onShortName() SK_OVERRIDE {
return SkString("mixed_xfermodes");
}
@@ -32,21 +41,20 @@ protected:
void drawShape(SkCanvas* canvas,
const SkPaint& paint,
- SkRandom* random) {
+ ShapeType type) {
static const SkRect kRect = SkRect::MakeXYWH(SkIntToScalar(-50), SkIntToScalar(-50),
SkIntToScalar(75), SkIntToScalar(105));
- int shape = random->nextULessThan(5);
- switch (shape) {
- case 0:
+ switch (type) {
+ case kShapeTypeCircle:
egdaniel 2014/11/20 14:34:15 we tend to indent the "case" inside the switch sta
rosca 2014/11/20 14:52:10 Done.
canvas->drawCircle(0, 0, 50, paint);
break;
- case 1:
+ case kShapeTypeRoundRect:
canvas->drawRoundRect(kRect, SkIntToScalar(10), SkIntToScalar(20), paint);
break;
- case 2:
+ case kShapeTypeRect:
canvas->drawRect(kRect, paint);
break;
- case 3:
+ case kShapeTypeConvexPath:
if (fConvexPath.isEmpty()) {
SkPoint points[4];
kRect.toQuad(points);
@@ -57,7 +65,7 @@ protected:
}
canvas->drawPath(fConvexPath, paint);
break;
- case 4:
+ case kShapeTypeConcavePath:
if (fConcavePath.isEmpty()) {
SkPoint points[5] = {{0, SkIntToScalar(-50)} };
SkMatrix rot;
@@ -74,6 +82,8 @@ protected:
}
canvas->drawPath(fConcavePath, paint);
break;
+ default:
+ break;
}
}
@@ -108,6 +118,7 @@ protected:
SkColor color = random.nextU();
SkXfermode::Mode mode =
static_cast<SkXfermode::Mode>(random.nextULessThan(SkXfermode::kLastMode + 1));
+ ShapeType shapeType = static_cast<ShapeType>(random.nextULessThan(kNumShapeTypes));
SkPaint p;
p.setAntiAlias(true);
@@ -117,9 +128,42 @@ protected:
canvas->translate(dx, dy);
canvas->scale(s, s);
canvas->rotate(r);
- this->drawShape(canvas, p, &random);
+ this->drawShape(canvas, p, shapeType);
canvas->restore();
}
+
+ // This draw should not affect the test's result.
+ drawWithHueOnWhite(canvas);
+ }
+
+ /**
+ * Draws white color into a white square using the hue blend mode.
+ * This will test a divide by 0 bug in the setLum function in shaders,
+ * being fixed with https://codereview.chromium.org/666043003/.
egdaniel 2014/11/18 14:57:16 No need to put link to cl in the comment. The comm
rosca 2014/11/20 14:52:10 Done.
+ * Without the fix, the result would be black (caused by the faulty code).
+ * With this fix the result color is white, so drawing on white should not
+ * change the expected result.
+ */
+ void drawWithHueOnWhite(SkCanvas* canvas) {
+ SkColor color = SkColorSetARGBMacro(225, 255, 255, 255);
+ SkXfermode::Mode mode = SkXfermode::kHue_Mode;
+ ShapeType shapeType = kShapeTypeConvexPath;
+
+ // Make it fit into a square.
+ SkScalar s = 0.15f;
+ // Look for a clean white square.
+ SkScalar dx = 30.f;
+ SkScalar dy = 350.f;
+
+ SkPaint p;
+ p.setAntiAlias(true);
+ p.setColor(color);
+ p.setXfermodeMode(mode);
+ canvas->save();
+ canvas->translate(dx, dy);
+ canvas->scale(s, s);
+ this->drawShape(canvas, p, shapeType);
+ canvas->restore();
}
virtual uint32_t onGetFlags() const {
« no previous file with comments | « no previous file | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698