skia2/gm/picture.cpp
caryclark 63c684a8a6 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
2015-02-25 09:04:04 -08:00

85 lines
2.0 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkPaint.h"
#include "SkPictureRecorder.h"
static SkPicture* make_picture() {
SkPictureRecorder rec;
SkCanvas* canvas = rec.beginRecording(100, 100);
SkPaint paint;
paint.setAntiAlias(true);
SkPath path;
paint.setColor(0x800000FF);
canvas->drawRect(SkRect::MakeWH(100, 100), paint);
paint.setColor(0x80FF0000);
path.moveTo(0, 0); path.lineTo(100, 0); path.lineTo(100, 100);
canvas->drawPath(path, paint);
paint.setColor(0x8000FF00);
path.reset(); path.moveTo(0, 0); path.lineTo(100, 0); path.lineTo(0, 100);
canvas->drawPath(path, paint);
paint.setColor(0x80FFFFFF);
paint.setXfermodeMode(SkXfermode::kPlus_Mode);
canvas->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), paint);
return rec.endRecording();
}
// Exercise the optional arguments to drawPicture
//
class PictureGM : public skiagm::GM {
public:
PictureGM()
: fPicture(NULL)
{}
protected:
void onOnceBeforeDraw() SK_OVERRIDE {
fPicture.reset(make_picture());
}
SkString onShortName() SK_OVERRIDE {
return SkString("pictures");
}
SkISize onISize() SK_OVERRIDE {
return SkISize::Make(450, 120);
}
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
canvas->translate(10, 10);
SkMatrix matrix;
SkPaint paint;
canvas->drawPicture(fPicture);
matrix.setTranslate(110, 0);
canvas->drawPicture(fPicture, &matrix, NULL);
matrix.postTranslate(110, 0);
canvas->drawPicture(fPicture, &matrix, &paint);
paint.setAlpha(0x80);
matrix.postTranslate(110, 0);
canvas->drawPicture(fPicture, &matrix, &paint);
}
private:
SkAutoTUnref<SkPicture> fPicture;
typedef skiagm::GM INHERITED;
};
DEF_GM( return SkNEW(PictureGM); )