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"
|
2017-05-16 14:39:06 +00:00
|
|
|
#include "SkPath.h"
|
2012-09-14 13:53:36 +00:00
|
|
|
#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");
|
|
|
|
}
|
|
|
|
|
2014-06-10 06:59:03 +00:00
|
|
|
SkISize onISize() { return SkISize::Make(100, 100); }
|
2012-09-14 13:53:36 +00:00
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar kOffset = 35000.0f;
|
|
|
|
constexpr SkScalar kExtents = 1000.0f;
|
2012-09-14 13:53:36 +00:00
|
|
|
|
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.
|
2015-08-27 14:41:13 +00:00
|
|
|
SkCanvas* rec = recorder.beginRecording(kExtents, kOffset + kExtents, nullptr, 0);
|
2014-08-29 15:03:56 +00:00
|
|
|
rec->drawColor(SK_ColorRED);
|
2012-09-14 13:53:36 +00:00
|
|
|
rec->save();
|
2014-08-29 15:03:56 +00:00
|
|
|
SkRect r = SkRect::MakeXYWH(-kExtents, kOffset - kExtents, 2 * kExtents, 2 * kExtents);
|
2012-09-14 13:53:36 +00:00
|
|
|
SkPath p;
|
|
|
|
p.addRoundRect(r, 5, 5);
|
2016-09-21 18:15:07 +00:00
|
|
|
rec->clipPath(p, true);
|
2014-08-29 15:03:56 +00:00
|
|
|
rec->drawColor(SK_ColorGREEN);
|
2012-09-14 13:53:36 +00:00
|
|
|
rec->restore();
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
|
2012-09-14 13:53:36 +00:00
|
|
|
|
|
|
|
// Next we play that picture into another picture of the same size.
|
2016-03-29 16:03:52 +00:00
|
|
|
pict->playback(recorder.beginRecording(pict->cullRect().width(),
|
|
|
|
pict->cullRect().height(),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, 0));
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> pict2(recorder.finishRecordingAsPicture());
|
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();
|
2014-08-29 15:03:56 +00:00
|
|
|
canvas->translate(kExtents / 2, -(kOffset - kExtents / 2));
|
2014-09-04 15:42:50 +00:00
|
|
|
pict2->playback(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;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new DistantClipGM; )
|
2012-09-14 13:53:36 +00:00
|
|
|
|
|
|
|
}
|