Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
complexclip4.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
12#include "include/core/SkPath.h"
14#include "include/core/SkRect.h"
16#include "include/core/SkSize.h"
19
20namespace skiagm {
21
22// This test exercise SkCanvas::androidFramework_replaceClip behavior
23class ComplexClip4GM : public GM {
24public:
25 ComplexClip4GM(bool aaclip)
26 : fDoAAClip(aaclip) {
27 this->setBGColor(0xFFDEDFDE);
28 }
29
30protected:
31 SkString getName() const override {
32 SkString str;
33 str.printf("complexclip4_%s",
34 fDoAAClip ? "aa" : "bw");
35 return str;
36 }
37
38 SkISize getISize() override { return SkISize::Make(970, 780); }
39
40 // Android Framework will still support the legacy kReplace SkClipOp on older devices, so
41 // this represents how to do so while also respecting the device restriction using the newer
42 // androidFramework_resetClip() API.
43 void emulateDeviceRestriction(SkCanvas* canvas, const SkIRect& deviceRestriction) {
44 // TODO(michaelludwig): It may make more sense for device clip restriction to move on to
45 // the SkSurface (which would let this GM draw correctly in viewer).
46 canvas->androidFramework_setDeviceClipRestriction(deviceRestriction);
47 }
48
50 const SkRect& clipRect,
51 bool aa) {
54 }
55
57 const SkRRect& clipRRect,
58 bool aa) {
61 }
62
64 const SkPath& path,
65 bool aa) {
68 }
69
70 void onDraw(SkCanvas* canvas) override {
71 SkPaint p;
72 p.setAntiAlias(fDoAAClip);
73 p.setColor(SK_ColorYELLOW);
74
75 canvas->save();
76 // draw a yellow rect through a rect clip
77 canvas->save();
78 emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(100, 100, 300, 300));
79 canvas->drawColor(SK_ColorGREEN);
80 emulateClipRectReplace(canvas, SkRect::MakeLTRB(100, 200, 400, 500), fDoAAClip);
81 canvas->drawRect(SkRect::MakeLTRB(100, 200, 400, 500), p);
82 canvas->restore();
83
84 // draw a yellow rect through a diamond clip
85 canvas->save();
86 emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(500, 100, 800, 300));
87 canvas->drawColor(SK_ColorGREEN);
88
89 SkPath pathClip = SkPath::Polygon({
90 {650, 200},
91 {900, 300},
92 {650, 400},
93 {650, 300},
94 }, true);
95 emulateClipPathReplace(canvas, pathClip, fDoAAClip);
96 canvas->drawRect(SkRect::MakeLTRB(500, 200, 900, 500), p);
97 canvas->restore();
98
99 // draw a yellow rect through a round rect clip
100 canvas->save();
101 emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(500, 500, 800, 700));
102 canvas->drawColor(SK_ColorGREEN);
103
105 canvas, SkRRect::MakeOval(SkRect::MakeLTRB(500, 600, 900, 750)), fDoAAClip);
106 canvas->drawRect(SkRect::MakeLTRB(500, 600, 900, 750), p);
107 canvas->restore();
108
109 // fill the clip with yellow color showing that androidFramework_replaceClip is
110 // in device space
111 canvas->save();
112 canvas->clipRect(SkRect::MakeLTRB(100, 400, 300, 750),
113 SkClipOp::kIntersect, fDoAAClip);
114 canvas->drawColor(SK_ColorGREEN);
115 // should not affect the device-space clip
116 canvas->rotate(20.f);
117 canvas->translate(50.f, 50.f);
118 emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(150, 450, 250, 700));
119 canvas->drawColor(SK_ColorYELLOW);
120 canvas->restore();
121
122 canvas->restore();
123 }
124private:
125 bool fDoAAClip;
126
127 using INHERITED = GM;
128};
129
130//////////////////////////////////////////////////////////////////////////////
131
132DEF_GM(return new ComplexClip4GM(false);)
133DEF_GM(return new ComplexClip4GM(true);)
134} // namespace skiagm
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
static void ResetClip(SkCanvas *canvas)
Definition: SkCanvasPriv.h:61
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
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 androidFramework_setDeviceClipRestriction(const SkIRect &rect)
Definition: SkCanvas.cpp:1378
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
int save()
Definition: SkCanvas.cpp:447
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1439
Definition: SkPath.h:59
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition: SkPath.cpp:3614
static SkRRect MakeOval(const SkRect &oval)
Definition: SkRRect.h:162
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
void emulateClipPathReplace(SkCanvas *canvas, const SkPath &path, bool aa)
void emulateDeviceRestriction(SkCanvas *canvas, const SkIRect &deviceRestriction)
void onDraw(SkCanvas *canvas) override
void emulateClipRRectReplace(SkCanvas *canvas, const SkRRect &clipRRect, bool aa)
void emulateClipRectReplace(SkCanvas *canvas, const SkRect &clipRect, bool aa)
SkISize getISize() override
SkString getName() const override
ComplexClip4GM(bool aaclip)
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void setBGColor(SkColor)
Definition: gm.cpp:159
clipRRect(r.rrect, r.opAA.op(), r.opAA.aa())) DRAW(ClipRect
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkRect.h:32
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646