Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
skiagm::ConvexPolyEffect Class Reference
Inheritance diagram for skiagm::ConvexPolyEffect:

Public Member Functions

 ConvexPolyEffect ()
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onOnceBeforeDraw () override
 
DrawResult onDraw (GrRecordingContext *rContext, SkCanvas *canvas, SkString *errorMsg) override
 

Detailed Description

This GM directly exercises a GrProcessor that draws convex polygons.

Definition at line 41 of file convexpolyeffect.cpp.

Constructor & Destructor Documentation

◆ ConvexPolyEffect()

skiagm::ConvexPolyEffect::ConvexPolyEffect ( )
inline

Definition at line 43 of file convexpolyeffect.cpp.

43 {
44 this->setBGColor(0xFFFFFFFF);
45 }

Member Function Documentation

◆ getISize()

SkISize skiagm::ConvexPolyEffect::getISize ( )
inlineoverrideprotected

Definition at line 50 of file convexpolyeffect.cpp.

50{ return SkISize::Make(720, 550); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::ConvexPolyEffect::getName ( ) const
inlineoverrideprotected

Definition at line 48 of file convexpolyeffect.cpp.

48{ return SkString("convex_poly_effect"); }

◆ onDraw()

DrawResult skiagm::ConvexPolyEffect::onDraw ( GrRecordingContext rContext,
SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotected

Definition at line 92 of file convexpolyeffect.cpp.

92 {
94 if (!sdc) {
95 *errorMsg = kErrorMsg_DrawSkippedGpuOnly;
96 return DrawResult::kSkip;
97 }
98
99 SkScalar y = 0;
100 static constexpr SkScalar kDX = 12.f;
101 static constexpr SkScalar kOutset = 5.f;
102
103 for (const SkPath& path : fPaths) {
104 SkScalar x = 0;
105
106 for (int et = 0; et < kGrClipEdgeTypeCnt; ++et) {
107 const SkMatrix m = SkMatrix::Translate(x, y);
108 SkPath p;
109 path.transform(m, &p);
110
111 GrClipEdgeType edgeType = (GrClipEdgeType) et;
112 auto [success, fp] = GrConvexPolyEffect::Make(/*inputFP=*/nullptr, edgeType, p);
113 if (!success) {
114 continue;
115 }
116
117 GrPaint grPaint;
118 grPaint.setColor4f({ 0, 0, 0, 1.f });
120 grPaint.setCoverageFragmentProcessor(std::move(fp));
121 auto rect = p.getBounds().makeOutset(kOutset, kOutset);
122 auto op = sk_gpu_test::test_ops::MakeRect(rContext, std::move(grPaint), rect);
123 sdc->addDrawOp(std::move(op));
124
125 x += SkScalarCeilToScalar(path.getBounds().width() + kDX);
126 }
127
128 // Draw AA and non AA paths using normal API for reference.
129 canvas->save();
130 canvas->translate(x, y);
132 canvas->drawPath(path, paint);
133 canvas->translate(path.getBounds().width() + 10.f, 0);
134 paint.setAntiAlias(true);
135 canvas->drawPath(path, paint);
136 canvas->restore();
137
138 y += SkScalarCeilToScalar(path.getBounds().height() + 20.f);
139 }
140
141 return DrawResult::kOk;
142 }
static const int kGrClipEdgeTypeCnt
Definition: GrTypesPriv.h:369
GrClipEdgeType
Definition: GrTypesPriv.h:361
#define SkScalarCeilToScalar(x)
Definition: SkScalar.h:31
static GrFPResult Make(std::unique_ptr< GrFragmentProcessor > inputFP, GrClipEdgeType edgeType, int n, const float edges[])
void setXPFactory(const GrXPFactory *xpFactory)
Definition: GrPaint.h:53
void setColor4f(const SkPMColor4f &color)
Definition: GrPaint.h:50
void setCoverageFragmentProcessor(std::unique_ptr< GrFragmentProcessor > fp)
Definition: GrPaint.h:75
static const GrXPFactory * Get(SkBlendMode blendMode)
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
Definition: SkPath.h:59
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
const uint32_t fp
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
GrOp::Owner MakeRect(GrRecordingContext *context, GrPaint &&paint, const SkRect &drawRect, const SkRect &localRect, const SkMatrix &localM)
Definition: TestOps.cpp:227
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:20

◆ onOnceBeforeDraw()

void skiagm::ConvexPolyEffect::onOnceBeforeDraw ( )
inlineoverrideprotected

Definition at line 52 of file convexpolyeffect.cpp.

52 {
53 SkPath tri;
54 tri.moveTo(5.f, 5.f);
55 tri.lineTo(100.f, 20.f);
56 tri.lineTo(15.f, 100.f);
57
58 fPaths.push_back(tri);
59 fPaths.emplace_back();
60 fPaths.back().reverseAddPath(tri);
61
62 tri.close();
63 fPaths.push_back(tri);
64
65 SkPath ngon;
66 constexpr SkScalar kRadius = 50.f;
67 const SkPoint center = { kRadius, kRadius };
68 for (int i = 0; i < GrConvexPolyEffect::kMaxEdges; ++i) {
70 SkPoint point = { SkScalarCos(angle), SkScalarSin(angle) };
71 point.scale(kRadius);
72 point = center + point;
73 if (0 == i) {
74 ngon.moveTo(point);
75 } else {
76 ngon.lineTo(point);
77 }
78 }
79
80 fPaths.push_back(ngon);
81 SkMatrix scaleM;
82 scaleM.setScale(1.1f, 0.4f);
83 ngon.transform(scaleM);
84 fPaths.push_back(ngon);
85
86 SkPath linePath;
87 linePath.moveTo(5.f, 5.f);
88 linePath.lineTo(6.f, 6.f);
89 fPaths.push_back(linePath);
90 }
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
static constexpr int kMaxEdges
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:296
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & close()
Definition: SkPath.cpp:823
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.cpp:1711
constexpr int kRadius
void scale(float scale, SkPoint *dst) const
Definition: SkPoint.cpp:17

The documentation for this class was generated from the following file: