2013-04-25 13:34:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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 "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkClipStack.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPathOps.h"
|
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2013-04-25 13:34:40 +00:00
|
|
|
#include "SkRect.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class PathOpsSkpClipGM : public GM {
|
|
|
|
public:
|
|
|
|
PathOpsSkpClipGM() {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-04-25 13:34:40 +00:00
|
|
|
return SkString("pathopsskpclip");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(1200, 900);
|
2013-04-25 13:34:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2015-08-27 14:41:13 +00:00
|
|
|
SkCanvas* rec = recorder.beginRecording(1200, 900, nullptr, 0);
|
2013-04-25 13:34:40 +00:00
|
|
|
SkPath p;
|
|
|
|
SkRect r = {
|
|
|
|
SkIntToScalar(100),
|
|
|
|
SkIntToScalar(200),
|
|
|
|
SkIntToScalar(400),
|
|
|
|
SkIntToScalar(700)
|
|
|
|
};
|
|
|
|
p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
|
2016-09-21 18:15:07 +00:00
|
|
|
rec->clipPath(p, true);
|
2013-04-25 13:34:40 +00:00
|
|
|
rec->translate(SkIntToScalar(250), SkIntToScalar(250));
|
2016-09-21 18:15:07 +00:00
|
|
|
rec->clipPath(p, true);
|
2013-04-25 13:34:40 +00:00
|
|
|
rec->drawColor(0xffff0000);
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
|
2013-04-25 13:34:40 +00:00
|
|
|
|
|
|
|
canvas->setAllowSimplifyClip(true);
|
|
|
|
canvas->save();
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(pict);
|
2013-04-25 13:34:40 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->setAllowSimplifyClip(false);
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(1200 / 2), 0);
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(pict);
|
2013-04-25 13:34:40 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|