3 * Copyright 2012 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
12 #include "SkPicture.h"
13 #include "SkPictureRecorder.h"
17 class DistantClipGM : public GM {
23 SkString onShortName() {
24 return SkString("distantclip");
27 SkISize onISize() { return SkISize::Make(100, 100); }
29 virtual void onDraw(SkCanvas* canvas) {
30 constexpr SkScalar kOffset = 35000.0f;
31 constexpr SkScalar kExtents = 1000.0f;
33 SkPictureRecorder recorder;
34 // We record a picture of huge vertical extents in which we clear the canvas to red, create
35 // a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw
37 SkCanvas* rec = recorder.beginRecording(kExtents, kOffset + kExtents, nullptr, 0);
38 rec->drawColor(SK_ColorRED);
40 SkRect r = SkRect::MakeXYWH(-kExtents, kOffset - kExtents, 2 * kExtents, 2 * kExtents);
42 p.addRoundRect(r, 5, 5);
43 rec->clipPath(p, true);
44 rec->drawColor(SK_ColorGREEN);
46 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
48 // Next we play that picture into another picture of the same size.
49 pict->playback(recorder.beginRecording(pict->cullRect().width(),
50 pict->cullRect().height(),
52 sk_sp<SkPicture> pict2(recorder.finishRecordingAsPicture());
54 // Finally we play the part of that second picture that should be green into the canvas.
56 canvas->translate(kExtents / 2, -(kOffset - kExtents / 2));
57 pict2->playback(canvas);
60 // If the image is red, we erroneously decided the clipPath was empty and didn't record
61 // the green drawColor, if it's green we're all good.
68 ///////////////////////////////////////////////////////////////////////////////
70 static GM* MyFactory(void*) { return new DistantClipGM; }
71 static GMRegistry reg(MyFactory);