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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.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
|
|
|
|
|
|
|
}
|