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

Unified Diff: gm/mixedxfermodes.cpp

Issue 15012026: Finish mixed_xfermodes GM. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix case order Created 7 years, 7 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 | « no previous file | no next file » | 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 c0045f84ae8f44eb2df010d96cb9b1658359d75b..f4e9768b3ae2930dc2b15b1184388411ce6e3831 100644
--- a/gm/mixedxfermodes.cpp
+++ b/gm/mixedxfermodes.cpp
@@ -14,7 +14,7 @@
namespace skiagm {
/**
- * Renders overlapping circles with random SkXfermode::Modes against a checkerboard.
+ * Renders overlapping shapes with random SkXfermode::Modes against a checkerboard.
*/
class MixedXfermodesGM : public GM {
public:
@@ -44,51 +44,87 @@ protected:
return make_isize(790, 640);
}
+ virtual void drawShape(SkCanvas* canvas,
+ const SkPaint& paint,
+ SkMWCRandom* random) {
+ static const SkRect kRect = SkRect::MakeXYWH(SkIntToScalar(-50), SkIntToScalar(-50),
+ SkIntToScalar(75), SkIntToScalar(105));
robertphillips 2013/05/14 21:49:37 x -> drawOption? geometry?
bsalomon 2013/05/15 13:10:20 shape
+ int x = random->nextULessThan(5);
+ switch (x) {
+ case 0:
+ canvas->drawCircle(0, 0, 50, paint);
+ break;
+ case 1:
+ canvas->drawRoundRect(kRect, SkIntToScalar(10), SkIntToScalar(20), paint);
+ break;
+ case 2:
+ canvas->drawRect(kRect, paint);
+ break;
+ case 3:
+ if (fConvexPath.isEmpty()) {
+ SkPoint points[4];
+ kRect.toQuad(points);
+ fConvexPath.moveTo(points[0]);
+ fConvexPath.quadTo(points[1], points[2]);
+ fConvexPath.quadTo(points[3], points[0]);
robertphillips 2013/05/14 21:49:37 assert that 'fConvexPath' is indeed convex?
bsalomon 2013/05/15 13:10:20 Done.
+ }
+ canvas->drawPath(fConvexPath, paint);
+ break;
+ case 4:
+ if (fConcavePath.isEmpty()) {
+ SkPoint points[5] = {{0, SkIntToScalar(-50)} };
+ SkMatrix rot;
+ rot.setRotate(SkIntToScalar(360) / 5);
+ for (int i = 1; i < 5; ++i) {
+ rot.mapPoints(points + i, points + i - 1, 1);
+ }
+ fConcavePath.moveTo(points[0]);
+ for (int i = 0; i < 5; ++i) {
+ fConcavePath.lineTo(points[(2 * i) % 5]);
+ }
+ fConcavePath.setFillType(SkPath::kEvenOdd_FillType);
robertphillips 2013/05/14 21:49:37 assert that 'fConcavePath' is non-convex?
bsalomon 2013/05/15 13:10:20 Done.
+ }
+ canvas->drawPath(fConcavePath, paint);
+ break;
+ }
+ }
+
virtual void onDraw(SkCanvas* canvas) {
SkPaint bgPaint;
bgPaint.setShader(fBG.get());
canvas->drawPaint(bgPaint);
SkISize size = canvas->getDeviceSize();
- SkScalar areaSqrt = SkScalarSqrt((SkIntToScalar(size.fWidth * size.fHeight)));
- SkScalar minR = areaSqrt / 10;
- SkScalar maxR = areaSqrt / 4;
+ SkScalar maxScale = SkScalarSqrt((SkIntToScalar(size.fWidth * size.fHeight))) / 300;
SkMWCRandom random;
- for (int i = 0; i < kNumCircles; ++i) {
- SkScalar cx = random.nextRangeScalar(0, SkIntToScalar(size.fWidth));
- SkScalar cy = random.nextRangeScalar(0, SkIntToScalar(size.fHeight));
- SkScalar r = random.nextRangeScalar(minR, maxR);
+ for (int i = 0; i < kNumShapes; ++i) {
+ SkScalar s = random.nextRangeScalar(SK_Scalar1 / 8, SK_Scalar1) * maxScale;
+ SkScalar r = random.nextRangeScalar(0, SkIntToScalar(360));
+ SkScalar dx = random.nextRangeScalar(0, SkIntToScalar(size.fWidth));
+ SkScalar dy = random.nextRangeScalar(0, SkIntToScalar(size.fHeight));
SkColor color = random.nextU();
-
SkXfermode::Mode mode =
static_cast<SkXfermode::Mode>(random.nextULessThan(SkXfermode::kLastMode + 1));
- // FIXME: Currently testing kDarken on GPU.
- mode = SkXfermode::kDarken_Mode;
SkPaint p;
p.setAntiAlias(true);
p.setColor(color);
p.setXfermodeMode(mode);
- canvas->drawCircle(cx, cy, r, p);
+ canvas->save();
+ canvas->translate(dx, dy);
+ canvas->scale(s, s);
+ canvas->rotate(r);
+ this->drawShape(canvas, p, &random);
+ canvas->restore();
}
-
- // FIXME: Remove text draw once this GM is finished.
- SkPaint txtPaint;
- txtPaint.setTextSize(areaSqrt / 20);
- txtPaint.setAntiAlias(true);
- static const char kTxt[] = "Work in progres... Do not baseline.";
- canvas->drawText(kTxt, strlen(kTxt),
- areaSqrt/50,
- SkIntToScalar(size.fHeight / 2),
- txtPaint);
}
private:
enum {
- kMinR = 10,
- kMaxR = 50,
- kNumCircles = 50,
+ kNumShapes = 100,
};
SkAutoTUnref<SkShader> fBG;
+ SkPath fConcavePath;
+ SkPath fConvexPath;
typedef GM INHERITED;
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698