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 "SkDevice.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:
|
2014-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2013-04-25 13:34:40 +00:00
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
|
|
|
return SkString("pathopsskpclip");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
|
|
|
return make_isize(1200, 900);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-04-17 23:35:06 +00:00
|
|
|
SkCanvas* rec = recorder.beginRecording(1200, 900, NULL, 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));
|
|
|
|
rec->clipPath(p, SkRegion::kIntersect_Op, true);
|
|
|
|
rec->translate(SkIntToScalar(250), SkIntToScalar(250));
|
|
|
|
rec->clipPath(p, SkRegion::kIntersect_Op, true);
|
|
|
|
rec->drawColor(0xffff0000);
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
|
2013-04-25 13:34:40 +00:00
|
|
|
|
|
|
|
canvas->setAllowSimplifyClip(true);
|
|
|
|
canvas->save();
|
|
|
|
canvas->drawPicture(*pict);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->setAllowSimplifyClip(false);
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(1200 / 2), 0);
|
|
|
|
canvas->drawPicture(*pict);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|