Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
DashCircleGM Class Reference
Inheritance diagram for DashCircleGM:
skiagm::GM

Public Member Functions

 DashCircleGM ()
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 
bool onAnimate (double nanos) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 40 of file dashcircle.cpp.

Constructor & Destructor Documentation

◆ DashCircleGM()

DashCircleGM::DashCircleGM ( )
inline

Definition at line 42 of file dashcircle.cpp.

42: fRotation(0) { }

Member Function Documentation

◆ getISize()

SkISize DashCircleGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 47 of file dashcircle.cpp.

47{ return SkISize::Make(900, 1200); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ getName()

SkString DashCircleGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 45 of file dashcircle.cpp.

45{ return SkString("dashcircle"); }

◆ onAnimate()

bool DashCircleGM::onAnimate ( double  nanos)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 107 of file dashcircle.cpp.

107 {
108 constexpr SkScalar kDesiredDurationSecs = 100.0f;
109
110 fRotation = TimeUtils::Scaled(1e-9 * nanos, 360.0f/kDesiredDurationSecs, 360.0f);
111 return true;
112 }
float SkScalar
Definition extension.cpp:12
static float Scaled(float time, float speed, float period=0)
Definition TimeUtils.h:27

◆ onDraw()

void DashCircleGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 49 of file dashcircle.cpp.

49 {
50 SkPaint refPaint;
51 refPaint.setAntiAlias(true);
52 refPaint.setColor(0xFFbf3f7f);
53 refPaint.setStroke(true);
54 refPaint.setStrokeWidth(1);
55 const SkScalar radius = 125;
56 SkRect oval = SkRect::MakeLTRB(-radius - 20, -radius - 20, radius + 20, radius + 20);
57 SkPath circle = SkPath::Circle(0, 0, radius);
58 SkScalar circumference = radius * SK_ScalarPI * 2;
59 int wedges[] = { 6, 12, 36 };
60 canvas->translate(radius+20, radius+20);
61 for (int wedge : wedges) {
62 SkScalar arcLength = 360.f / wedge;
63 canvas->save();
64 for (const DashExample& dashExample : dashExamples) {
65 SkPathBuilder refPath;
66 int dashUnits = 0;
67 for (int index = 0; index < dashExample.length; ++index) {
68 dashUnits += dashExample.pattern[index];
69 }
70 SkScalar unitLength = arcLength / dashUnits;
71 SkScalar angle = 0;
72 for (int index = 0; index < wedge; ++index) {
73 for (int i2 = 0; i2 < dashExample.length; i2 += 2) {
74 SkScalar span = dashExample.pattern[i2] * unitLength;
75 refPath.moveTo(0, 0);
76 refPath.arcTo(oval, angle, span, false);
77 refPath.close();
78 angle += span + (dashExample.pattern[i2 + 1]) * unitLength;
79 }
80 }
81 canvas->save();
82 canvas->rotate(fRotation);
83 canvas->drawPath(refPath.detach(), refPaint);
84 canvas->restore();
85 SkPaint p;
86 p.setAntiAlias(true);
87 p.setStroke(true);
88 p.setStrokeWidth(10);
89 SkScalar intervals[4];
90 int intervalCount = dashExample.length;
91 SkScalar dashLength = circumference / wedge / dashUnits;
92 for (int index = 0; index < dashExample.length; ++index) {
93 intervals[index] = dashExample.pattern[index] * dashLength;
94 }
95 p.setPathEffect(SkDashPathEffect::Make(intervals, intervalCount, 0));
96 canvas->save();
97 canvas->rotate(fRotation);
98 canvas->drawPath(circle, p);
99 canvas->restore();
100 canvas->translate(0, radius * 2 + 50);
101 }
102 canvas->restore();
103 canvas->translate(radius * 2 + 50, 0);
104 }
105 }
#define SK_ScalarPI
Definition SkScalar.h:21
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void rotate(SkScalar degrees)
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition SkPaint.h:170
void setStroke(bool)
Definition SkPaint.cpp:115
void setStrokeWidth(SkScalar width)
Definition SkPaint.cpp:159
SkPathBuilder & close()
SkPathBuilder & arcTo(const SkRect &oval, SkScalar startAngleDeg, SkScalar sweepAngleDeg, bool forceMoveTo)
SkPathBuilder & moveTo(SkPoint pt)
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:3530
struct DashExample dashExamples[]
SkRect oval
Definition SkRecords.h:249
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

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