diff options
author | caryclark <caryclark@google.com> | 2015-02-25 09:04:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-25 09:04:04 -0800 |
commit | 63c684a8a609d39da11b4a656223cebf52ca85dc (patch) | |
tree | d29415e15295a6384ece7cfdf601062871def428 /gm | |
parent | 4e4e8160459f68c1795f2297bcec6f7866e01fa8 (diff) |
fuzzer fixes
Fix path bugs exposed by the path fuzzer.
Changes to existing gm and samplecode files defer their calls to construct
SkPath objects until the first draw instead of at test initialization.
Add an experimental call to SkPath to validate the internal SkPathRef.
Fix SkPath::addPoly to set the last moveto after adding a close verb.
Fix stroke to handle failures when computing the unit normal.
Add a unit test for the unit normal failure.
R=reed@google.com
Review URL: https://codereview.chromium.org/953383002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/bitmapshader.cpp | 5 | ||||
-rw-r--r-- | gm/circularclips.cpp | 5 | ||||
-rw-r--r-- | gm/complexclip2.cpp | 23 | ||||
-rw-r--r-- | gm/picture.cpp | 8 | ||||
-rw-r--r-- | gm/pictureshader.cpp | 10 | ||||
-rw-r--r-- | gm/shadows.cpp | 4 | ||||
-rw-r--r-- | gm/simpleaaclip.cpp | 4 | ||||
-rw-r--r-- | gm/strokes.cpp | 5 |
8 files changed, 39 insertions, 25 deletions
diff --git a/gm/bitmapshader.cpp b/gm/bitmapshader.cpp index 8085f5c42c..ac8bf663c9 100644 --- a/gm/bitmapshader.cpp +++ b/gm/bitmapshader.cpp @@ -41,15 +41,14 @@ static void adopt_shader(SkPaint* paint, SkShader* shader) { } class BitmapShaderGM : public GM { -public: - BitmapShaderGM() { +protected: + void onOnceBeforeDraw() SK_OVERRIDE { this->setBGColor(SK_ColorGRAY); draw_bm(&fBitmap); draw_mask(&fMask); } -protected: virtual SkString onShortName() { return SkString("bitmapshaders"); } diff --git a/gm/circularclips.cpp b/gm/circularclips.cpp index ec766fbca4..614ebb6097 100644 --- a/gm/circularclips.cpp +++ b/gm/circularclips.cpp @@ -13,8 +13,8 @@ class CircularClipsGM : public skiagm::GM { SkScalar fX1, fX2, fY, fR; SkPath fCircle1, fCircle2; -public: - CircularClipsGM() { +protected: + void onOnceBeforeDraw() SK_OVERRIDE { fX1 = 80; fX2 = 120; fY = 50; @@ -24,7 +24,6 @@ public: fCircle2.addCircle(fX2, fY, fR, SkPath::kCW_Direction); } -protected: bool runAsBench() const SK_OVERRIDE { return true; } diff --git a/gm/complexclip2.cpp b/gm/complexclip2.cpp index a55d0733e0..361b1c0b97 100644 --- a/gm/complexclip2.cpp +++ b/gm/complexclip2.cpp @@ -24,6 +24,21 @@ public: ComplexClip2GM(Clip clip, bool antiAlias) : fClip(clip) , fAntiAlias(antiAlias) { + SkScalar xA = 0.65f; + SkScalar xF = 50.65f; + + SkScalar yA = 0.65f; + SkScalar yF = 50.65f; + + fWidth = xF - xA; + fHeight = yF - yA; + + fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX; + fTotalHeight = kRows * fHeight + SK_Scalar1 * (kRows + 1) * kPadY; + } + +protected: + void onOnceBeforeDraw() SK_OVERRIDE { this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD)); // offset the rects a bit so we get antialiasing even in the rect case @@ -41,9 +56,6 @@ public: SkScalar yE = 40.65f; SkScalar yF = 50.65f; - fWidth = xF - xA; - fHeight = yF - yA; - fRects[0].set(xB, yB, xE, yE); fRRects[0].setRectXY(fRects[0], 7, 7); fPaths[0].addRoundRect(fRects[0], 5, 5); @@ -69,9 +81,6 @@ public: fPaths[4].addRoundRect(fRects[4], 5, 5); fRectColors[4] = SK_ColorCYAN; - fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX; - fTotalHeight = kRows * fHeight + SK_Scalar1 * (kRows + 1) * kPadY; - SkRegion::Op ops[] = { SkRegion::kDifference_Op, SkRegion::kIntersect_Op, @@ -91,8 +100,6 @@ public: } } -protected: - static const int kRows = 5; static const int kCols = 5; static const int kPadX = 20; diff --git a/gm/picture.cpp b/gm/picture.cpp index b07a5969a9..5432fc93ef 100644 --- a/gm/picture.cpp +++ b/gm/picture.cpp @@ -39,9 +39,15 @@ static SkPicture* make_picture() { // class PictureGM : public skiagm::GM { public: - PictureGM() : fPicture(make_picture()) {} + PictureGM() + : fPicture(NULL) + {} protected: + void onOnceBeforeDraw() SK_OVERRIDE { + fPicture.reset(make_picture()); + } + SkString onShortName() SK_OVERRIDE { return SkString("pictures"); } diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp index 630ecd8f0c..3f184ec2d6 100644 --- a/gm/pictureshader.cpp +++ b/gm/pictureshader.cpp @@ -27,21 +27,23 @@ public: PictureShaderGM(SkScalar tileSize, SkScalar sceneSize) : fTileSize(tileSize) , fSceneSize(sceneSize) { + } - // Build the picture. + protected: + void onOnceBeforeDraw() SK_OVERRIDE { + // Build the picture. SkPictureRecorder recorder; - SkCanvas* pictureCanvas = recorder.beginRecording(tileSize, tileSize, NULL, 0); + SkCanvas* pictureCanvas = recorder.beginRecording(fTileSize, fTileSize, NULL, 0); this->drawTile(pictureCanvas); fPicture.reset(recorder.endRecording()); // Build a reference bitmap. - fBitmap.allocN32Pixels(SkScalarCeilToInt(tileSize), SkScalarCeilToInt(tileSize)); + fBitmap.allocN32Pixels(SkScalarCeilToInt(fTileSize), SkScalarCeilToInt(fTileSize)); fBitmap.eraseColor(SK_ColorTRANSPARENT); SkCanvas bitmapCanvas(fBitmap); this->drawTile(&bitmapCanvas); } -protected: SkString onShortName() SK_OVERRIDE { return SkString("pictureshader"); diff --git a/gm/shadows.cpp b/gm/shadows.cpp index 3ecbdd833f..66ad32e089 100644 --- a/gm/shadows.cpp +++ b/gm/shadows.cpp @@ -28,14 +28,14 @@ public: SkPath fCirclePath; SkRect fRect; - ShadowsGM() { +protected: + void onOnceBeforeDraw() SK_OVERRIDE { this->setBGColor(0xFFDDDDDD); fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) ); fRect.set(SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(30), SkIntToScalar(30)); } -protected: virtual SkString onShortName() { return SkString("shadows"); } diff --git a/gm/simpleaaclip.cpp b/gm/simpleaaclip.cpp index 950a1c025e..8a18f48e62 100644 --- a/gm/simpleaaclip.cpp +++ b/gm/simpleaaclip.cpp @@ -49,7 +49,10 @@ public: SimpleClipGM(SkGeomTypes geomType) : fGeomType(geomType) { + } +protected: + void onOnceBeforeDraw() SK_OVERRIDE { // offset the rects a bit so we get anti-aliasing in the rect case fBase.set(100.65f, 100.65f, @@ -64,7 +67,6 @@ public: INHERITED::setBGColor(0xFFDDDDDD); } -protected: void buildRgn(SkAAClip* clip, SkRegion::Op op) { clip->setPath(fBasePath, NULL, true); diff --git a/gm/strokes.cpp b/gm/strokes.cpp index af01b9169e..cadd0d6d9e 100644 --- a/gm/strokes.cpp +++ b/gm/strokes.cpp @@ -80,8 +80,8 @@ private: class Strokes2GM : public skiagm::GM { SkPath fPath; -public: - Strokes2GM() { +protected: + void onOnceBeforeDraw() SK_OVERRIDE { SkRandom rand; fPath.moveTo(0, 0); for (int i = 0; i < 13; i++) { @@ -91,7 +91,6 @@ public: } } -protected: SkString onShortName() SK_OVERRIDE { return SkString("strokes_poly"); |