Flutter Engine
The Flutter Engine
distantclip.cpp
Go to the documentation of this file.
1
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "gm/gm.h"
12#include "include/core/SkPath.h"
15#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
20
21namespace skiagm {
22
23class DistantClipGM : public GM {
24 SkString getName() const override { return SkString("distantclip"); }
25
26 SkISize getISize() override { return {100, 100}; }
27
28 void onDraw(SkCanvas* canvas) override {
29 constexpr SkScalar kOffset = 35000.0f;
30 constexpr SkScalar kExtents = 1000.0f;
31
32 SkPictureRecorder recorder;
33 // We record a picture of huge vertical extents in which we clear the canvas to red, create
34 // a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw
35 // green into that.
36 SkCanvas* rec = recorder.beginRecording(kExtents, kOffset + kExtents);
38 rec->save();
39 SkRect r = SkRect::MakeXYWH(-kExtents, kOffset - kExtents, 2 * kExtents, 2 * kExtents);
40 rec->clipPath(SkPath::RRect(r, 5, 5), true);
42 rec->restore();
44
45 // Next we play that picture into another picture of the same size.
46 pict->playback(recorder.beginRecording(pict->cullRect().width(),
47 pict->cullRect().height()));
49
50 // Finally we play the part of that second picture that should be green into the canvas.
51 canvas->save();
52 canvas->translate(kExtents / 2, -(kOffset - kExtents / 2));
53 pict2->playback(canvas);
54 canvas->restore();
55
56 // If the image is red, we erroneously decided the clipPath was empty and didn't record
57 // the green drawColor, if it's green we're all good.
58 }
59};
60
61///////////////////////////////////////////////////////////////////////////////
62
63DEF_GM( return new DistantClipGM; )
64
65} // namespace skiagm
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
int save()
Definition: SkCanvas.cpp:447
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:3602
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
virtual SkRect cullRect() const =0
virtual void playback(SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
Definition: gm.h:110
float SkScalar
Definition: extension.cpp:12
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762