Flutter Engine
The Flutter Engine
filltypespersp.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
15#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
23
24namespace skiagm {
25
26class FillTypePerspGM : public GM {
27 SkPath fPath;
28public:
30
31 void makePath() {
32 if (fPath.isEmpty()) {
33 const SkScalar radius = SkIntToScalar(45);
35 .addCircle(SkIntToScalar(100), SkIntToScalar(100), radius)
36 .detach();
37 }
38 }
39
40protected:
41 SkString getName() const override { return SkString("filltypespersp"); }
42
43 SkISize getISize() override { return SkISize::Make(835, 840); }
44
45 void showPath(SkCanvas* canvas, int x, int y, SkPathFillType ft,
46 SkScalar scale, const SkPaint& paint) {
47 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
48
49 canvas->save();
51 canvas->clipRect(r);
52 canvas->drawColor(SK_ColorWHITE);
54 canvas->translate(r.centerX(), r.centerY());
55 canvas->scale(scale, scale);
56 canvas->translate(-r.centerX(), -r.centerY());
57 canvas->drawPath(fPath, paint);
58 canvas->restore();
59 }
60
61 void showFour(SkCanvas* canvas, SkScalar scale, bool aa) {
66 paint.setShader(SkGradientShader::MakeRadial(center,
67 SkIntToScalar(100),
68 colors,
69 pos,
72 paint.setAntiAlias(aa);
73
75 scale, paint);
76 showPath(canvas, 200, 0, SkPathFillType::kEvenOdd,
77 scale, paint);
79 scale, paint);
81 scale, paint);
82 }
83
84 void onDraw(SkCanvas* canvas) override {
85 this->makePath();
86
87 // do perspective drawPaint as the background;
88 SkPaint bkgnrd;
90 SkIntToScalar(100));
93 SkScalar pos[] = {0, SK_ScalarHalf / 2,
94 3 * SK_ScalarHalf / 2, SK_Scalar1};
96 SkIntToScalar(1000),
97 colors,
98 pos,
101 canvas->save();
102 canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
103 SkMatrix mat;
104 mat.reset();
105 mat.setPerspY(SK_Scalar1 / 1000);
106 canvas->concat(mat);
107 canvas->drawPaint(bkgnrd);
108 canvas->restore();
109
110 // draw the paths in perspective
111 SkMatrix persp;
112 persp.reset();
113 persp.setPerspX(-SK_Scalar1 / 1800);
114 persp.setPerspY(SK_Scalar1 / 500);
115 canvas->concat(persp);
116
117 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
118 const SkScalar scale = SkIntToScalar(5)/4;
119
120 showFour(canvas, SK_Scalar1, false);
121 canvas->translate(SkIntToScalar(450), 0);
122 showFour(canvas, scale, false);
123
124 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
125 showFour(canvas, SK_Scalar1, true);
126 canvas->translate(SkIntToScalar(450), 0);
127 showFour(canvas, scale, true);
128 }
129
130private:
131 using INHERITED = GM;
132};
133
134//////////////////////////////////////////////////////////////////////////////
135
136DEF_GM( return new FillTypePerspGM; )
137
138} // namespace skiagm
SkPath fPath
SkPoint pos
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
SkPathFillType
Definition: SkPathTypes.h:11
#define SK_Scalar1
Definition: SkScalar.h:18
#define SK_ScalarHalf
Definition: SkScalar.h:19
#define SkIntToScalar(x)
Definition: SkScalar.h:57
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 drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
SkMatrix & setPerspX(SkScalar v)
Definition: SkMatrix.h:537
SkMatrix & setPerspY(SkScalar v)
Definition: SkMatrix.h:544
SkMatrix & reset()
Definition: SkMatrix.cpp:49
void setShader(sk_sp< SkShader > shader)
SkPathBuilder & addCircle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.h:59
bool isEmpty() const
Definition: SkPath.cpp:416
void setFillType(SkPathFillType ft)
Definition: SkPath.h:235
void showFour(SkCanvas *canvas, SkScalar scale, bool aa)
void onDraw(SkCanvas *canvas) override
SkString getName() const override
SkISize getISize() override
void showPath(SkCanvas *canvas, int x, int y, SkPathFillType ft, SkScalar scale, const SkPaint &paint)
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
static SkPath scale(const SkPath &path, SkScalar scale)
Definition: patheffects.cpp:68
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float centerY() const
Definition: SkRect.h:785