2012-09-14 13:53:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 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 "SkCanvas.h"
|
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2012-09-14 13:53:36 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class DistantClipGM : public GM {
|
|
|
|
public:
|
|
|
|
DistantClipGM() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() {
|
|
|
|
return SkString("distantclip");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() { return make_isize(100, 100); }
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
int offset = 35000;
|
|
|
|
int extents = 1000;
|
|
|
|
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2012-09-14 13:53:36 +00:00
|
|
|
// We record a picture of huge vertical extents in which we clear the canvas to red, create
|
|
|
|
// a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw
|
|
|
|
// green into that.
|
2014-04-17 23:35:06 +00:00
|
|
|
SkCanvas* rec = recorder.beginRecording(100, offset + extents, NULL, 0);
|
2012-09-14 13:53:36 +00:00
|
|
|
rec->drawColor(0xffff0000);
|
|
|
|
rec->save();
|
2012-09-17 12:05:40 +00:00
|
|
|
SkRect r = {
|
2012-09-18 02:01:09 +00:00
|
|
|
SkIntToScalar(-extents),
|
|
|
|
SkIntToScalar(offset - extents),
|
|
|
|
SkIntToScalar(extents),
|
|
|
|
SkIntToScalar(offset + extents)
|
2012-09-17 12:05:40 +00:00
|
|
|
};
|
2012-09-14 13:53:36 +00:00
|
|
|
SkPath p;
|
|
|
|
p.addRoundRect(r, 5, 5);
|
|
|
|
rec->clipPath(p, SkRegion::kIntersect_Op, true);
|
|
|
|
rec->drawColor(0xff00ff00);
|
|
|
|
rec->restore();
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
|
2012-09-14 13:53:36 +00:00
|
|
|
|
|
|
|
// Next we play that picture into another picture of the same size.
|
2014-04-17 23:35:06 +00:00
|
|
|
pict->draw(recorder.beginRecording(100, offset + extents, NULL, 0));
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> pict2(recorder.endRecording());
|
2012-09-14 13:53:36 +00:00
|
|
|
|
|
|
|
// Finally we play the part of that second picture that should be green into the canvas.
|
|
|
|
canvas->save();
|
2012-09-18 02:01:09 +00:00
|
|
|
canvas->translate(SkIntToScalar(extents / 2),
|
2012-09-17 12:05:40 +00:00
|
|
|
SkIntToScalar(-(offset - extents / 2)));
|
2014-04-13 19:09:42 +00:00
|
|
|
pict2->draw(canvas);
|
2012-09-14 13:53:36 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// If the image is red, we erroneously decided the clipPath was empty and didn't record
|
|
|
|
// the green drawColor, if it's green we're all good.
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new DistantClipGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|