Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "gm.h" | |
| 9 #include "SkCanvas.h" | |
| 10 #include "SkPath.h" | |
| 11 | |
| 12 namespace skiagm { | |
| 13 | |
|
robertphillips
2013/11/08 14:18:50
// This GM tests ...
| |
| 14 class NonClosePathsGM: public GM { | |
| 15 public: | |
| 16 NonClosePathsGM() {} | |
| 17 | |
|
robertphillips
2013/11/08 14:18:50
Maybe make this ClosureType rather than NonCloseTy
| |
| 18 enum NonCloseType { | |
| 19 TotalNonClose, // The last point doesn't coincide with the first one in the contour. | |
| 20 // The path looks not closed at all. | |
| 21 | |
|
robertphillips
2013/11/08 14:18:50
coincide -> coincides
| |
| 22 FakeCloseCorner, // The last point coincide with the first one at a cor ner. | |
| 23 // The path looks like closed, but final rendering has 2 ends with cap. | |
| 24 | |
|
robertphillips
2013/11/08 14:18:50
coincide -> coincides
| |
| 25 FakeCloseMiddle, // The last point coincide with the first one in the m iddle of a line. | |
|
robertphillips
2013/11/08 14:18:50
// The path looks closed, and the final rendering
| |
| 26 // The path looks like closed, and the final rendering looks closed too. | |
| 27 | |
| 28 kNonCloseTypeCount | |
| 29 }; | |
| 30 | |
| 31 protected: | |
|
robertphillips
2013/11/08 14:18:50
SK_OVERRIDE
| |
| 32 virtual SkString onShortName() { | |
|
robertphillips
2013/11/08 14:18:50
nonclosedpaths (i.e., add 'd')
| |
| 33 return SkString("nonclosepaths"); | |
| 34 } | |
| 35 | |
|
robertphillips
2013/11/08 14:18:50
SK_OVERRIDE
| |
| 36 virtual SkISize onISize() { | |
|
robertphillips
2013/11/08 14:18:50
Does it need to be this big?
yunchao
2013/11/08 15:56:21
Yeah, there are 12 * 18 + 3 cases, very one is 100
| |
| 37 return SkISize::Make(1220, 1920); | |
| 38 } | |
| 39 | |
|
robertphillips
2013/11/08 14:18:50
non-close path -> non-closed paths
for right angle
| |
| 40 // Use rect-like geometry for non-close path, for right angle is easier to | |
| 41 // show the visual difference of lineCap and lineJoin. | |
|
robertphillips
2013/11/08 14:18:50
We only use const references in Skia. If the objec
yunchao
2013/11/08 15:56:21
Because some cases are stroke-style, and the bigge
| |
| 42 void makePath(SkPath& path, NonCloseType type) { | |
| 43 if (FakeCloseMiddle == type) { | |
| 44 path.moveTo(30, 50); | |
| 45 path.lineTo(30, 30); | |
| 46 } else { | |
| 47 path.moveTo(30, 30); | |
| 48 } | |
| 49 path.lineTo(70, 30); | |
| 50 path.lineTo(70, 70); | |
| 51 path.lineTo(30, 70); | |
| 52 path.lineTo(30, 50); | |
| 53 if (FakeCloseCorner == type) { | |
| 54 path.lineTo(30, 30); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 // set the location for the current test on the canvas | |
|
robertphillips
2013/11/08 14:18:50
SetLocation for static member methods
| |
| 59 static void setLocation(SkCanvas* canvas, int counter, int lineNum) { | |
| 60 SkScalar x = SK_Scalar1 * 100 * (counter % lineNum) + 10 + SK_Scalar1 / 4; | |
| 61 SkScalar y = SK_Scalar1 * 100 * (counter / lineNum) + 10 + 3 * SK_Scalar 1 / 4; | |
| 62 canvas->translate(x, y); | |
| 63 } | |
| 64 | |
|
robertphillips
2013/11/08 14:18:50
SK_OVERRIDE
| |
| 65 virtual void onDraw(SkCanvas* canvas) { | |
|
robertphillips
2013/11/08 14:18:50
Maybe kStrokeWidths or gStrokeWidths?
| |
| 66 static const int strokeWidth[] = {0, 10, 40, 50}; | |
|
robertphillips
2013/11/08 14:18:50
Maybe numWidths?
| |
| 67 size_t size = SK_ARRAY_COUNT(strokeWidth); | |
| 68 | |
|
robertphillips
2013/11/08 14:18:50
Same here w.r.t. naming. Maybe prefix with a 'k' o
| |
| 69 static const SkPaint::Style testStyle[] = { | |
| 70 SkPaint::kStroke_Style, SkPaint::kStrokeAndFill_Style | |
| 71 }; | |
| 72 | |
| 73 static const SkPaint::Cap testCap[] = { | |
| 74 SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap | |
| 75 }; | |
| 76 | |
| 77 static const SkPaint::Join testJoin[] = { | |
| 78 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join | |
| 79 }; | |
| 80 | |
| 81 static const NonCloseType testType[] = { | |
| 82 TotalNonClose, FakeCloseCorner, FakeCloseMiddle | |
| 83 }; | |
| 84 | |
| 85 int counter = 0; | |
| 86 SkPaint paint; | |
| 87 paint.setAntiAlias(true); | |
| 88 | |
| 89 // For stroke style painter and fill-and-stroke style painter | |
|
robertphillips
2013/11/08 14:18:50
pre-increments for these please (e.g., ++type)
| |
| 90 for (size_t type = 0; type < kNonCloseTypeCount; type++) { | |
| 91 for (size_t style = 0; style < SK_ARRAY_COUNT(testStyle); style++) { | |
| 92 for (size_t cap = 0; cap < SK_ARRAY_COUNT(testCap); cap++) { | |
| 93 for (size_t join = 0; join < SK_ARRAY_COUNT(testJoin); join+ +) { | |
| 94 for (size_t width = 0; width < size; width++) { | |
| 95 canvas->save(); | |
| 96 setLocation(canvas, counter, SkPaint::kJoinCount * s ize); | |
| 97 | |
| 98 SkPath path; | |
|
robertphillips
2013/11/08 14:18:50
this->makePath
| |
| 99 makePath(path, testType[type]); | |
| 100 | |
| 101 paint.setStyle(testStyle[style]); | |
| 102 paint.setStrokeCap(testCap[cap]); | |
| 103 paint.setStrokeJoin(testJoin[join]); | |
|
robertphillips
2013/11/08 14:18:50
SkIntToScalar instead of SkScalar
| |
| 104 paint.setStrokeWidth(SkScalar(strokeWidth[width])); | |
| 105 | |
| 106 canvas->drawPath(path, paint); | |
| 107 canvas->restore(); | |
| 108 counter++; | |
| 109 } | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 // For fill style painter | |
| 116 for (size_t type = 0; type < kNonCloseTypeCount; type++) { | |
| 117 canvas->save(); | |
| 118 setLocation(canvas, counter, SkPaint::kJoinCount * size); | |
| 119 | |
| 120 SkPath path; | |
|
robertphillips
2013/11/08 14:18:50
this->makePath
| |
| 121 makePath(path, testType[type]); | |
| 122 | |
| 123 paint.setStyle(SkPaint::kFill_Style); | |
| 124 | |
| 125 canvas->drawPath(path, paint); | |
| 126 canvas->restore(); | |
| 127 counter++; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 typedef GM INHERITED; | |
| 133 }; | |
| 134 | |
| 135 ////////////////////////////////////////////////////////////////////////////// | |
| 136 | |
|
robertphillips
2013/11/08 14:18:50
Please use DEF_GM macro instead here
| |
| 137 static GM* MyFactory(void*) { return new NonClosePathsGM; } | |
| 138 static GMRegistry reg(MyFactory); | |
| 139 | |
| 140 } | |
| OLD | NEW |