Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d7639af

Browse files
HalCanarySkia Commit-Bot
authored andcommitted
Samples: clean up cruft
- replace virtual with override. - remove default constructor. - use default field initializers - move work from constructor into onOnceBeforeDraw - mark everything private - enum { N = 100 }; constants to constexpr - remove unused variables Change-Id: I8c7a19bc24fec416a6b88d634ee948d3e842b986 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228056 Commit-Queue: Ben Wagner <bungeman@google.com> Auto-Submit: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
1 parent 1281ec3 commit d7639af

19 files changed

+113
-328
lines changed

samplecode/SampleAAClip.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,11 @@ static void drawClip(SkCanvas* canvas, const SkAAClip& clip) {
5555
}
5656

5757
class AAClipView : public Sample {
58-
public:
59-
AAClipView() {
60-
testop();
61-
}
58+
SkString name() override { return SkString("AAClip"); }
6259

63-
protected:
64-
virtual SkString name() { return SkString("AAClip"); }
60+
void onOnceBeforeDraw() override { testop(); }
6561

66-
virtual void onDrawContent(SkCanvas* canvas) {
62+
void onDrawContent(SkCanvas* canvas) override {
6763
#if 1
6864
SkAAClip aaclip;
6965
SkPath path;
@@ -106,11 +102,5 @@ class AAClipView : public Sample {
106102
canvas->drawPath(path, paint);
107103
#endif
108104
}
109-
110-
private:
111-
typedef Sample INHERITED;
112105
};
113-
114-
//////////////////////////////////////////////////////////////////////////////
115-
116106
DEF_SAMPLE( return new AAClipView(); )

samplecode/SampleAARectModes.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ static sk_sp<SkShader> make_bg_shader() {
7070

7171
class AARectsModesView : public Sample {
7272
SkPaint fBGPaint;
73-
public:
74-
AARectsModesView () {
73+
74+
void onOnceBeforeDraw() override {
7575
fBGPaint.setShader(make_bg_shader());
7676
}
7777

78-
protected:
79-
virtual SkString name() { return SkString("AARectsModes"); }
78+
SkString name() override { return SkString("AARectsModes"); }
8079

81-
virtual void onDrawContent(SkCanvas* canvas) {
80+
void onDrawContent(SkCanvas* canvas) override {
8281
const SkRect bounds = SkRect::MakeWH(W, H);
8382
static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
8483

@@ -107,11 +106,5 @@ class AARectsModesView : public Sample {
107106
canvas->translate(W * 5 / 4, 0);
108107
}
109108
}
110-
111-
private:
112-
typedef Sample INHERITED;
113109
};
114-
115-
///////////////////////////////////////////////////////////////////////////////
116-
117110
DEF_SAMPLE( return new AARectsModesView(); )

samplecode/SampleAARects.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@ static SkBitmap createBitmap(int n) {
3232
return bitmap;
3333
}
3434

35+
static constexpr int N = 64;
36+
3537
class AARectView : public Sample {
3638
SkBitmap fBitmap;
37-
enum {
38-
N = 64
39-
};
4039

41-
protected:
4240
void onOnceBeforeDraw() override {
4341
fBitmap = createBitmap(N);
44-
45-
fWidth = N;
4642
}
4743

4844
SkString name() override { return SkString("AA Rects"); }
@@ -173,7 +169,6 @@ class AARectView : public Sample {
173169
}
174170

175171
private:
176-
int fWidth;
177172

178173
typedef Sample INHERITED;
179174
};

samplecode/SampleAndroidShadows.cpp

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,18 @@ class ShadowsView : public Sample {
3535
SkPath fTabPath;
3636

3737
SkPoint3 fLightPos;
38-
SkScalar fZDelta;
39-
SkScalar fAnimTranslate;
40-
SkScalar fAnimAngle;
41-
SkScalar fAnimAlpha;
42-
43-
bool fShowAmbient;
44-
bool fShowSpot;
45-
bool fUseAlt;
46-
bool fShowObject;
47-
bool fIgnoreShadowAlpha;
48-
bool fDoAlphaAnimation;
49-
50-
public:
51-
ShadowsView()
52-
: fZDelta(0)
53-
, fAnimTranslate(0)
54-
, fAnimAngle(0)
55-
, fAnimAlpha(1)
56-
, fShowAmbient(true)
57-
, fShowSpot(true)
58-
, fUseAlt(false)
59-
, fShowObject(true)
60-
, fIgnoreShadowAlpha(false)
61-
, fDoAlphaAnimation(false) {}
62-
63-
protected:
38+
SkScalar fZDelta = 0;
39+
SkScalar fAnimTranslate = 0;
40+
SkScalar fAnimAngle = 0;
41+
SkScalar fAnimAlpha = 1;
42+
43+
bool fShowAmbient = true;
44+
bool fShowSpot = true;
45+
bool fUseAlt = false;
46+
bool fShowObject = true;
47+
bool fIgnoreShadowAlpha = false;
48+
bool fDoAlphaAnimation = false;
49+
6450
void onOnceBeforeDraw() override {
6551
fCirclePath.addCircle(0, 0, 50);
6652
fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100));
@@ -155,10 +141,6 @@ class ShadowsView : public Sample {
155141
return false;
156142
}
157143

158-
void drawBG(SkCanvas* canvas) {
159-
canvas->drawColor(0xFFDDDDDD);
160-
}
161-
162144
void drawShadowedPath(SkCanvas* canvas, const SkPath& path,
163145
const SkPoint3& zPlaneParams,
164146
const SkPaint& paint, SkScalar ambientAlpha,
@@ -196,7 +178,8 @@ class ShadowsView : public Sample {
196178
}
197179

198180
void onDrawContent(SkCanvas* canvas) override {
199-
this->drawBG(canvas);
181+
canvas->drawColor(0xFFDDDDDD);
182+
200183
const SkScalar kLightWidth = 800;
201184
const SkScalar kAmbientAlpha = 0.039f;
202185
const SkScalar kSpotAlpha = 0.19f;

samplecode/SampleAnimBlur.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkS
2222
}
2323

2424
class AnimBlurView : public Sample {
25-
public:
26-
AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {}
25+
SkScalar fBlurSigma = 0;
26+
SkScalar fCircleRadius = 100;
2727

28-
protected:
2928
SkString name() override { return SkString("AnimBlur"); }
3029

3130
void onDrawContent(SkCanvas* canvas) override {
@@ -53,13 +52,5 @@ class AnimBlurView : public Sample {
5352
fCircleRadius = 3 + get_anim_sin(1e-9 * nanos, 150, 25, 3);
5453
return true;
5554
}
56-
57-
private:
58-
SkScalar fBlurSigma, fCircleRadius;
59-
60-
typedef Sample INHERITED;
6155
};
62-
63-
//////////////////////////////////////////////////////////////////////////////
64-
6556
DEF_SAMPLE( return new AnimBlurView(); )

samplecode/SampleAnimatedImage.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ static constexpr char kPauseKey = 'p';
2323
static constexpr char kResetKey = 'r';
2424

2525
class SampleAnimatedImage : public Sample {
26-
public:
27-
SampleAnimatedImage()
28-
: INHERITED()
29-
, fYOffset(0)
30-
{}
26+
sk_sp<SkAnimatedImage> fImage;
27+
sk_sp<SkDrawable> fDrawable;
28+
SkScalar fYOffset = 0;
29+
bool fRunning = false;
30+
double fCurrentTime = 0.0;
31+
double fLastWallTime = 0.0;
32+
double fTimeToShowNextFrame = 0.0;
3133

32-
protected:
3334
void onDrawBackground(SkCanvas* canvas) override {
3435
SkFont font;
3536
font.setSize(20);
@@ -119,18 +120,6 @@ class SampleAnimatedImage : public Sample {
119120
}
120121
return false;
121122
}
122-
123-
private:
124-
sk_sp<SkAnimatedImage> fImage;
125-
sk_sp<SkDrawable> fDrawable;
126-
SkScalar fYOffset;
127-
bool fRunning = false;
128-
double fCurrentTime = 0.0;
129-
double fLastWallTime = 0.0;
130-
double fTimeToShowNextFrame = 0.0;
131-
typedef Sample INHERITED;
132123
};
133124

134-
///////////////////////////////////////////////////////////////////////////////
135-
136125
DEF_SAMPLE( return new SampleAnimatedImage(); )

samplecode/SampleAnimatedText.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
3838
// SDF-text special case (which falls back to bitmap fonts for small points)
3939

4040
class AnimatedTextView : public Sample {
41-
public:
42-
AnimatedTextView() : fScale(1.0f), fScaleInc(0.1f), fRotation(0.0f), fSizeScale(1) {}
41+
float fScale = 1;
42+
float fScaleInc = 0.1f;
43+
float fRotation = 0;
44+
int fSizeScale = 1;
4345

44-
protected:
4546
SkString name() override { return SkString("AnimatedText"); }
4647

4748
bool onChar(SkUnichar uni) override {
@@ -106,17 +107,6 @@ class AnimatedTextView : public Sample {
106107
}
107108
return true;
108109
}
109-
110-
private:
111-
float fScale;
112-
float fScaleInc;
113-
float fRotation;
114-
int fSizeScale;
115-
116-
117-
typedef Sample INHERITED;
118110
};
119111

120-
//////////////////////////////////////////////////////////////////////////////
121-
122112
DEF_SAMPLE( return new AnimatedTextView(); )

samplecode/SampleArc.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,10 @@ class ArcsView : public Sample {
7878
}
7979
};
8080

81-
public:
82-
SkRect fRect;
81+
SkRect fRect = {20, 20, 220, 220};
8382
sk_sp<MyDrawable> fAnimatingDrawable;
8483
sk_sp<SkDrawable> fRootDrawable;
8584

86-
ArcsView() { }
87-
88-
protected:
8985
SkString name() override { return SkString("Arcs"); }
9086

9187
static void DrawRectWithLines(SkCanvas* canvas, const SkRect& r, const SkPaint& p) {
@@ -164,11 +160,8 @@ class ArcsView : public Sample {
164160

165161
void onOnceBeforeDraw() override {
166162
testparse();
167-
fSweep = SkIntToScalar(100);
168163
this->setBGColor(0xFFDDDDDD);
169164

170-
fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
171-
fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
172165
fAnimatingDrawable = sk_make_sp<MyDrawable>(fRect);
173166

174167
SkPictureRecorder recorder;
@@ -187,13 +180,6 @@ class ArcsView : public Sample {
187180
}
188181
return true;
189182
}
190-
191-
private:
192-
SkScalar fSweep;
193-
194-
typedef Sample INHERITED;
195183
};
196184

197-
//////////////////////////////////////////////////////////////////////////////
198-
199185
DEF_SAMPLE( return new ArcsView(); )

samplecode/SampleBitmapRect.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ class BitmapRectView : public Sample {
9595
bounce_pt(&fSrcPt, &fSrcVec, fSrcLimit);
9696
return true;
9797
}
98-
99-
private:
100-
typedef Sample INHERITED;
10198
};
10299

103-
//////////////////////////////////////////////////////////////////////////////
104-
105100
static constexpr int BIG_H = 120;
106101

107102
static void make_big_bitmap(SkBitmap* bm) {
@@ -161,7 +156,5 @@ class BitmapRectView2 : public Sample {
161156
}
162157
};
163158

164-
//////////////////////////////////////////////////////////////////////////////
165-
166159
DEF_SAMPLE( return new BitmapRectView(); )
167160
DEF_SAMPLE( return new BitmapRectView2(); )

samplecode/SampleCCPRGeometry.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@ static constexpr float kDebugBloat = 40;
4444
* geometry processors.
4545
*/
4646
class CCPRGeometryView : public Sample {
47-
public:
48-
CCPRGeometryView() { this->updateGpuData(); }
47+
void onOnceBeforeDraw() override { this->updateGpuData(); }
4948
void onDrawContent(SkCanvas*) override;
5049

5150
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override;
5251
bool onClick(Sample::Click*) override;
5352
bool onChar(SkUnichar) override;
5453
SkString name() override { return SkString("CCPRGeometry"); }
5554

56-
private:
5755
class Click;
5856
class DrawCoverageCountOp;
5957
class VisualizeCoverageCountFP;
@@ -76,8 +74,6 @@ class CCPRGeometryView : public Sample {
7674
SkTArray<TriPointInstance> fTriPointInstances;
7775
SkTArray<QuadPointInstance> fQuadPointInstances;
7876
SkPath fPath;
79-
80-
typedef Sample INHERITED;
8177
};
8278

8379
class CCPRGeometryView::DrawCoverageCountOp : public GrDrawOp {

0 commit comments

Comments
 (0)