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 { |