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>
This commit is contained in:
parent
1281ec3eec
commit
d7639aff10
@ -55,15 +55,11 @@ static void drawClip(SkCanvas* canvas, const SkAAClip& clip) {
|
||||
}
|
||||
|
||||
class AAClipView : public Sample {
|
||||
public:
|
||||
AAClipView() {
|
||||
testop();
|
||||
}
|
||||
SkString name() override { return SkString("AAClip"); }
|
||||
|
||||
protected:
|
||||
virtual SkString name() { return SkString("AAClip"); }
|
||||
void onOnceBeforeDraw() override { testop(); }
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
#if 1
|
||||
SkAAClip aaclip;
|
||||
SkPath path;
|
||||
@ -106,11 +102,5 @@ protected:
|
||||
canvas->drawPath(path, paint);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new AAClipView(); )
|
||||
|
@ -70,15 +70,14 @@ static sk_sp<SkShader> make_bg_shader() {
|
||||
|
||||
class AARectsModesView : public Sample {
|
||||
SkPaint fBGPaint;
|
||||
public:
|
||||
AARectsModesView () {
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
fBGPaint.setShader(make_bg_shader());
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString name() { return SkString("AARectsModes"); }
|
||||
SkString name() override { return SkString("AARectsModes"); }
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
const SkRect bounds = SkRect::MakeWH(W, H);
|
||||
static const SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
|
||||
|
||||
@ -107,11 +106,5 @@ protected:
|
||||
canvas->translate(W * 5 / 4, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new AARectsModesView(); )
|
||||
|
@ -32,17 +32,13 @@ static SkBitmap createBitmap(int n) {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
static constexpr int N = 64;
|
||||
|
||||
class AARectView : public Sample {
|
||||
SkBitmap fBitmap;
|
||||
enum {
|
||||
N = 64
|
||||
};
|
||||
|
||||
protected:
|
||||
void onOnceBeforeDraw() override {
|
||||
fBitmap = createBitmap(N);
|
||||
|
||||
fWidth = N;
|
||||
}
|
||||
|
||||
SkString name() override { return SkString("AA Rects"); }
|
||||
@ -173,7 +169,6 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
int fWidth;
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
@ -35,32 +35,18 @@ class ShadowsView : public Sample {
|
||||
SkPath fTabPath;
|
||||
|
||||
SkPoint3 fLightPos;
|
||||
SkScalar fZDelta;
|
||||
SkScalar fAnimTranslate;
|
||||
SkScalar fAnimAngle;
|
||||
SkScalar fAnimAlpha;
|
||||
SkScalar fZDelta = 0;
|
||||
SkScalar fAnimTranslate = 0;
|
||||
SkScalar fAnimAngle = 0;
|
||||
SkScalar fAnimAlpha = 1;
|
||||
|
||||
bool fShowAmbient;
|
||||
bool fShowSpot;
|
||||
bool fUseAlt;
|
||||
bool fShowObject;
|
||||
bool fIgnoreShadowAlpha;
|
||||
bool fDoAlphaAnimation;
|
||||
bool fShowAmbient = true;
|
||||
bool fShowSpot = true;
|
||||
bool fUseAlt = false;
|
||||
bool fShowObject = true;
|
||||
bool fIgnoreShadowAlpha = false;
|
||||
bool fDoAlphaAnimation = false;
|
||||
|
||||
public:
|
||||
ShadowsView()
|
||||
: fZDelta(0)
|
||||
, fAnimTranslate(0)
|
||||
, fAnimAngle(0)
|
||||
, fAnimAlpha(1)
|
||||
, fShowAmbient(true)
|
||||
, fShowSpot(true)
|
||||
, fUseAlt(false)
|
||||
, fShowObject(true)
|
||||
, fIgnoreShadowAlpha(false)
|
||||
, fDoAlphaAnimation(false) {}
|
||||
|
||||
protected:
|
||||
void onOnceBeforeDraw() override {
|
||||
fCirclePath.addCircle(0, 0, 50);
|
||||
fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100));
|
||||
@ -155,10 +141,6 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
void drawBG(SkCanvas* canvas) {
|
||||
canvas->drawColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
void drawShadowedPath(SkCanvas* canvas, const SkPath& path,
|
||||
const SkPoint3& zPlaneParams,
|
||||
const SkPaint& paint, SkScalar ambientAlpha,
|
||||
@ -196,7 +178,8 @@ protected:
|
||||
}
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
this->drawBG(canvas);
|
||||
canvas->drawColor(0xFFDDDDDD);
|
||||
|
||||
const SkScalar kLightWidth = 800;
|
||||
const SkScalar kAmbientAlpha = 0.039f;
|
||||
const SkScalar kSpotAlpha = 0.19f;
|
||||
|
@ -22,10 +22,9 @@ SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkS
|
||||
}
|
||||
|
||||
class AnimBlurView : public Sample {
|
||||
public:
|
||||
AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {}
|
||||
SkScalar fBlurSigma = 0;
|
||||
SkScalar fCircleRadius = 100;
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("AnimBlur"); }
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
@ -53,13 +52,5 @@ protected:
|
||||
fCircleRadius = 3 + get_anim_sin(1e-9 * nanos, 150, 25, 3);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
SkScalar fBlurSigma, fCircleRadius;
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new AnimBlurView(); )
|
||||
|
@ -23,13 +23,14 @@ static constexpr char kPauseKey = 'p';
|
||||
static constexpr char kResetKey = 'r';
|
||||
|
||||
class SampleAnimatedImage : public Sample {
|
||||
public:
|
||||
SampleAnimatedImage()
|
||||
: INHERITED()
|
||||
, fYOffset(0)
|
||||
{}
|
||||
sk_sp<SkAnimatedImage> fImage;
|
||||
sk_sp<SkDrawable> fDrawable;
|
||||
SkScalar fYOffset = 0;
|
||||
bool fRunning = false;
|
||||
double fCurrentTime = 0.0;
|
||||
double fLastWallTime = 0.0;
|
||||
double fTimeToShowNextFrame = 0.0;
|
||||
|
||||
protected:
|
||||
void onDrawBackground(SkCanvas* canvas) override {
|
||||
SkFont font;
|
||||
font.setSize(20);
|
||||
@ -119,18 +120,6 @@ protected:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
sk_sp<SkAnimatedImage> fImage;
|
||||
sk_sp<SkDrawable> fDrawable;
|
||||
SkScalar fYOffset;
|
||||
bool fRunning = false;
|
||||
double fCurrentTime = 0.0;
|
||||
double fLastWallTime = 0.0;
|
||||
double fTimeToShowNextFrame = 0.0;
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new SampleAnimatedImage(); )
|
||||
|
@ -38,10 +38,11 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
|
||||
// SDF-text special case (which falls back to bitmap fonts for small points)
|
||||
|
||||
class AnimatedTextView : public Sample {
|
||||
public:
|
||||
AnimatedTextView() : fScale(1.0f), fScaleInc(0.1f), fRotation(0.0f), fSizeScale(1) {}
|
||||
float fScale = 1;
|
||||
float fScaleInc = 0.1f;
|
||||
float fRotation = 0;
|
||||
int fSizeScale = 1;
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("AnimatedText"); }
|
||||
|
||||
bool onChar(SkUnichar uni) override {
|
||||
@ -106,17 +107,6 @@ protected:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
float fScale;
|
||||
float fScaleInc;
|
||||
float fRotation;
|
||||
int fSizeScale;
|
||||
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new AnimatedTextView(); )
|
||||
|
@ -78,14 +78,10 @@ class ArcsView : public Sample {
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
SkRect fRect;
|
||||
SkRect fRect = {20, 20, 220, 220};
|
||||
sk_sp<MyDrawable> fAnimatingDrawable;
|
||||
sk_sp<SkDrawable> fRootDrawable;
|
||||
|
||||
ArcsView() { }
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("Arcs"); }
|
||||
|
||||
static void DrawRectWithLines(SkCanvas* canvas, const SkRect& r, const SkPaint& p) {
|
||||
@ -164,11 +160,8 @@ protected:
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
testparse();
|
||||
fSweep = SkIntToScalar(100);
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
|
||||
fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
|
||||
fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
|
||||
fAnimatingDrawable = sk_make_sp<MyDrawable>(fRect);
|
||||
|
||||
SkPictureRecorder recorder;
|
||||
@ -187,13 +180,6 @@ protected:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
SkScalar fSweep;
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ArcsView(); )
|
||||
|
@ -95,13 +95,8 @@ class BitmapRectView : public Sample {
|
||||
bounce_pt(&fSrcPt, &fSrcVec, fSrcLimit);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static constexpr int BIG_H = 120;
|
||||
|
||||
static void make_big_bitmap(SkBitmap* bm) {
|
||||
@ -161,7 +156,5 @@ class BitmapRectView2 : public Sample {
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new BitmapRectView(); )
|
||||
DEF_SAMPLE( return new BitmapRectView2(); )
|
||||
|
@ -44,8 +44,7 @@ static constexpr float kDebugBloat = 40;
|
||||
* geometry processors.
|
||||
*/
|
||||
class CCPRGeometryView : public Sample {
|
||||
public:
|
||||
CCPRGeometryView() { this->updateGpuData(); }
|
||||
void onOnceBeforeDraw() override { this->updateGpuData(); }
|
||||
void onDrawContent(SkCanvas*) override;
|
||||
|
||||
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override;
|
||||
@ -53,7 +52,6 @@ public:
|
||||
bool onChar(SkUnichar) override;
|
||||
SkString name() override { return SkString("CCPRGeometry"); }
|
||||
|
||||
private:
|
||||
class Click;
|
||||
class DrawCoverageCountOp;
|
||||
class VisualizeCoverageCountFP;
|
||||
@ -76,8 +74,6 @@ private:
|
||||
SkTArray<TriPointInstance> fTriPointInstances;
|
||||
SkTArray<QuadPointInstance> fQuadPointInstances;
|
||||
SkPath fPath;
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
class CCPRGeometryView::DrawCoverageCountOp : public GrDrawOp {
|
||||
|
@ -81,13 +81,13 @@ static void gen_paths(const SkTDArray<SkScalar>& topData,
|
||||
// A set of scrolling line plots with the area between each plot filled. Stresses out GPU path
|
||||
// filling
|
||||
class ChartView : public Sample {
|
||||
public:
|
||||
ChartView() {
|
||||
fShift = 0;
|
||||
fSize.set(-1, -1);
|
||||
}
|
||||
static constexpr int kNumGraphs = 5;
|
||||
static constexpr int kPixelsPerTick = 3;
|
||||
static constexpr int kShiftPerFrame = 1;
|
||||
int fShift = 0;
|
||||
SkISize fSize = {-1, -1};
|
||||
SkTDArray<SkScalar> fData[kNumGraphs];
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("Chart"); }
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
@ -158,19 +158,6 @@ protected:
|
||||
|
||||
fShift += kShiftPerFrame;
|
||||
}
|
||||
|
||||
private:
|
||||
enum {
|
||||
kNumGraphs = 5,
|
||||
kPixelsPerTick = 3,
|
||||
kShiftPerFrame = 1,
|
||||
};
|
||||
int fShift;
|
||||
SkISize fSize;
|
||||
SkTDArray<SkScalar> fData[kNumGraphs];
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ChartView(); )
|
||||
|
@ -38,18 +38,18 @@ static sk_sp<SkTypeface> chinese_typeface() {
|
||||
}
|
||||
|
||||
class ChineseFlingView : public Sample {
|
||||
public:
|
||||
ChineseFlingView() : fBlobs(kNumBlobs) {}
|
||||
static constexpr int kNumBlobs = 200;
|
||||
static constexpr int kWordLength = 16;
|
||||
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
SkFontMetrics fMetrics;
|
||||
sk_sp<SkTextBlob> fBlobs[kNumBlobs];
|
||||
SkRandom fRand;
|
||||
int fIndex = 0;
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("chinese-fling"); }
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
if (!fInitialized) {
|
||||
this->init();
|
||||
fInitialized = true;
|
||||
}
|
||||
|
||||
canvas->clear(0xFFDDDDDD);
|
||||
|
||||
SkPaint paint;
|
||||
@ -64,18 +64,14 @@ protected:
|
||||
|
||||
y += fMetrics.fDescent + fMetrics.fLeading;
|
||||
++index;
|
||||
index %= fBlobs.count();
|
||||
index %= kNumBlobs;
|
||||
}
|
||||
// now "fling" a random amount
|
||||
fIndex += fRand.nextRangeU(5, 20);
|
||||
fIndex %= fBlobs.count();
|
||||
fIndex %= kNumBlobs;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr auto kNumBlobs = 200;
|
||||
static constexpr auto kWordLength = 16;
|
||||
|
||||
void init() {
|
||||
void onOnceBeforeDraw() override {
|
||||
fTypeface = chinese_typeface();
|
||||
|
||||
SkFont font(fTypeface, 56);
|
||||
@ -94,10 +90,8 @@ private:
|
||||
0,
|
||||
0);
|
||||
|
||||
fBlobs.emplace_back(builder.make());
|
||||
fBlobs[i] = builder.make();
|
||||
}
|
||||
|
||||
fIndex = 0;
|
||||
}
|
||||
|
||||
// Construct a random kWordLength character 'word' drawing from the full Chinese set
|
||||
@ -106,22 +100,20 @@ private:
|
||||
glyphs[i] = fRand.nextRangeU(0x4F00, 0x9FA0);
|
||||
}
|
||||
}
|
||||
|
||||
bool fInitialized = false;
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
SkFontMetrics fMetrics;
|
||||
SkTArray<sk_sp<SkTextBlob>> fBlobs;
|
||||
SkRandom fRand;
|
||||
int fIndex;
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
class ChineseZoomView : public Sample {
|
||||
public:
|
||||
ChineseZoomView() : fBlobs(kNumBlobs), fScale(15.0f), fTranslate(0.0f) {}
|
||||
static constexpr int kNumBlobs = 8;
|
||||
static constexpr int kParagraphLength = 175;
|
||||
|
||||
bool fAfterFirstFrame = false;
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
SkFontMetrics fMetrics;
|
||||
sk_sp<SkTextBlob> fBlobs[kNumBlobs];
|
||||
SkRandom fRand;
|
||||
SkScalar fScale = 15;
|
||||
SkScalar fTranslate = 0;
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("chinese-zoom"); }
|
||||
|
||||
bool onChar(SkUnichar uni) override {
|
||||
@ -137,37 +129,30 @@ protected:
|
||||
}
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
bool afterFirstFrame = fInitialized;
|
||||
if (!fInitialized) {
|
||||
this->init();
|
||||
fInitialized = true;
|
||||
}
|
||||
|
||||
canvas->clear(0xFFDDDDDD);
|
||||
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColor(0xDE000000);
|
||||
|
||||
if (afterFirstFrame) {
|
||||
if (fAfterFirstFrame) {
|
||||
#if SK_SUPPORT_GPU
|
||||
GrContext* grContext = canvas->getGrContext();
|
||||
if (grContext) {
|
||||
sk_sp<SkImage> image =
|
||||
grContext->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 0);
|
||||
sk_sp<SkImage> image = grContext->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 0);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(10.0f, 10.0f, 512.0f, 512.0), &paint);
|
||||
image = grContext->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 1);
|
||||
GrMaskFormat::kA8_GrMaskFormat, 1);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(522.0f, 10.0f, 512.f, 512.0f), &paint);
|
||||
image = grContext->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 2);
|
||||
GrMaskFormat::kA8_GrMaskFormat, 2);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(10.0f, 522.0f, 512.0f, 512.0f), &paint);
|
||||
image = grContext->priv().testingOnly_getFontAtlasImage(
|
||||
GrMaskFormat::kA8_GrMaskFormat, 3);
|
||||
GrMaskFormat::kA8_GrMaskFormat, 3);
|
||||
canvas->drawImageRect(image,
|
||||
SkRect::MakeXYWH(522.0f, 522.0f, 512.0f, 512.0f), &paint);
|
||||
}
|
||||
@ -186,13 +171,12 @@ protected:
|
||||
|
||||
y += 3*(fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading);
|
||||
}
|
||||
if (!fAfterFirstFrame) {
|
||||
fAfterFirstFrame = true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr auto kNumBlobs = 8;
|
||||
static constexpr auto kParagraphLength = 175;
|
||||
|
||||
void init() {
|
||||
void onOnceBeforeDraw() override {
|
||||
fTypeface = chinese_typeface();
|
||||
|
||||
SkFont font(fTypeface, 11);
|
||||
@ -220,10 +204,8 @@ private:
|
||||
y += fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading;
|
||||
paragraphLength -= 45;
|
||||
}
|
||||
fBlobs.emplace_back(builder.make());
|
||||
fBlobs[i] = builder.make();
|
||||
}
|
||||
|
||||
fIndex = 0;
|
||||
}
|
||||
|
||||
// Construct a random kWordLength character 'word' drawing from the full Chinese set
|
||||
@ -232,17 +214,6 @@ private:
|
||||
glyphs[i] = fRand.nextRangeU(0x4F00, 0x9FA0);
|
||||
}
|
||||
}
|
||||
|
||||
bool fInitialized = false;
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
SkFontMetrics fMetrics;
|
||||
SkTArray<sk_sp<SkTextBlob>> fBlobs;
|
||||
SkRandom fRand;
|
||||
SkScalar fScale;
|
||||
SkScalar fTranslate;
|
||||
int fIndex;
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -22,19 +22,7 @@ static void test_circlebounds(SkCanvas*) {
|
||||
}
|
||||
|
||||
class CircleView : public Sample {
|
||||
public:
|
||||
static const SkScalar ANIM_DX;
|
||||
static const SkScalar ANIM_DY;
|
||||
static const SkScalar ANIM_RAD;
|
||||
SkScalar fDX, fDY, fRAD;
|
||||
|
||||
CircleView() {
|
||||
fDX = fDY = fRAD = 0;
|
||||
fN = 3;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString name() { return SkString("Circles"); }
|
||||
SkString name() override { return SkString("Circles"); }
|
||||
|
||||
void circle(SkCanvas* canvas, int width, bool aa) {
|
||||
SkPaint paint;
|
||||
@ -46,7 +34,7 @@ protected:
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
paint.setStrokeWidth(SkIntToScalar(width));
|
||||
}
|
||||
canvas->drawCircle(0, 0, SkIntToScalar(9) + fRAD, paint);
|
||||
canvas->drawCircle(0, 0, 9.0f, paint);
|
||||
if (false) { // avoid bit rot, suppress warning
|
||||
test_circlebounds(canvas);
|
||||
}
|
||||
@ -78,7 +66,7 @@ protected:
|
||||
path->close();
|
||||
}
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
@ -95,16 +83,6 @@ protected:
|
||||
canvas->drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int fN;
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
const SkScalar CircleView::ANIM_DX(SK_Scalar1 / 67);
|
||||
const SkScalar CircleView::ANIM_DY(SK_Scalar1 / 29);
|
||||
const SkScalar CircleView::ANIM_RAD(SK_Scalar1 / 19);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new CircleView(); )
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "include/core/SkPath.h"
|
||||
#include "include/utils/SkRandom.h"
|
||||
#include "samplecode/Sample.h"
|
||||
#include "src/core/SkAAClip.h"
|
||||
#include "src/core/SkClipOpPriv.h"
|
||||
|
||||
constexpr int W = 150;
|
||||
@ -102,20 +101,9 @@ static void show_thick(SkCanvas* canvas, bool doAA) {
|
||||
typedef void (*CanvasProc)(SkCanvas*, bool);
|
||||
|
||||
class ClipView : public Sample {
|
||||
public:
|
||||
ClipView() {
|
||||
SkAAClip clip;
|
||||
SkIRect r = { -2, -3, 842, 18 };
|
||||
clip.setRect(r);
|
||||
}
|
||||
SkString name() override { return SkString("Clip"); }
|
||||
|
||||
virtual ~ClipView() {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString name() { return SkString("Clip"); }
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
canvas->drawColor(SK_ColorWHITE);
|
||||
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
||||
|
||||
@ -144,11 +132,6 @@ protected:
|
||||
canvas->translate(0, H * SK_Scalar1 * 8 / 7);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ClipView(); )
|
||||
|
@ -115,8 +115,17 @@ static void draw_normal_geom(SkCanvas* canvas, const SkPoint& offset, int geom,
|
||||
}
|
||||
|
||||
class ClipDrawMatchView : public Sample {
|
||||
SkInterpolator fTrans;
|
||||
Geometry fGeom;
|
||||
bool fClipFirst = true;
|
||||
int fSign = 1;
|
||||
const double fStart = SkTime::GetMSecs();
|
||||
|
||||
public:
|
||||
ClipDrawMatchView() : fTrans(2, 5), fGeom(kRect_Geometry), fClipFirst(true), fSign(1) {
|
||||
ClipDrawMatchView() : fTrans(2, 5), fGeom(kRect_Geometry) {}
|
||||
|
||||
private:
|
||||
void onOnceBeforeDraw() override {
|
||||
SkScalar values[2];
|
||||
|
||||
fTrans.setRepeatCount(999);
|
||||
@ -132,7 +141,6 @@ public:
|
||||
fTrans.setKeyFrame(4, GetMSecs() + 5000, values);
|
||||
}
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("ClipDrawMatch"); }
|
||||
|
||||
bool onChar(SkUnichar uni) override {
|
||||
@ -239,17 +247,6 @@ protected:
|
||||
SkMSec GetMSecs() const {
|
||||
return static_cast<SkMSec>(SkTime::GetMSecs() - fStart);
|
||||
}
|
||||
|
||||
private:
|
||||
SkInterpolator fTrans;
|
||||
Geometry fGeom;
|
||||
bool fClipFirst;
|
||||
int fSign;
|
||||
const double fStart = SkTime::GetMSecs();
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ClipDrawMatchView(); )
|
||||
|
@ -18,10 +18,6 @@
|
||||
#define USE_PATH 1
|
||||
|
||||
class ClockView : public Sample {
|
||||
public:
|
||||
ClockView() {}
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("Clock"); }
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
@ -211,12 +207,6 @@ protected:
|
||||
}
|
||||
|
||||
bool onAnimate(double /*nanos*/) override { return true; }
|
||||
|
||||
private:
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ClockView(); )
|
||||
|
@ -113,7 +113,6 @@ class ColorFilterView : public Sample {
|
||||
N = 64
|
||||
};
|
||||
|
||||
protected:
|
||||
void onOnceBeforeDraw() override {
|
||||
fBitmap = createBitmap(N);
|
||||
fShader = ToolUtils::create_checkerboard_shader(0xFFCCCCCC, 0xFFFFFFFF, 12);
|
||||
@ -179,11 +178,6 @@ protected:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ColorFilterView(); )
|
||||
|
@ -12,15 +12,13 @@
|
||||
#include "src/core/SkClipOpPriv.h"
|
||||
|
||||
class ComplexClipView : public Sample {
|
||||
public:
|
||||
ComplexClipView() {
|
||||
void onOnceBeforeDraw() override {
|
||||
this->setBGColor(0xFFA0DDA0);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString name() { return SkString("ComplexClip"); }
|
||||
SkString name() override { return SkString("ComplexClip"); }
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
SkPath path;
|
||||
path.moveTo(SkIntToScalar(0), SkIntToScalar(50));
|
||||
path.quadTo(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(50), SkIntToScalar(0));
|
||||
@ -137,11 +135,6 @@ protected:
|
||||
}
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ComplexClipView(); )
|
||||
|
@ -20,37 +20,36 @@
|
||||
#include "tools/Resources.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class CowboyView : public Sample {
|
||||
public:
|
||||
CowboyView()
|
||||
: fLabel("SampleCowboy")
|
||||
, fState(kZoomIn)
|
||||
, fAnimationLoop(kAnimationIterations)
|
||||
, fDelta(1) {}
|
||||
~CowboyView() override = default;
|
||||
|
||||
protected:
|
||||
class AnimatedSVGSample : public Sample {
|
||||
static constexpr auto kAnimationIterations = 5;
|
||||
|
||||
enum State {
|
||||
kZoomIn,
|
||||
kScroll,
|
||||
kZoomOut
|
||||
};
|
||||
sk_sp<SkSVGDOM> fDom;
|
||||
const char* fResource = nullptr;
|
||||
const char* fName = nullptr;
|
||||
State fState = kZoomIn;
|
||||
int fAnimationLoop = kAnimationIterations;
|
||||
SkScalar fDelta = 1;
|
||||
|
||||
public:
|
||||
AnimatedSVGSample(const char* r, const char* n) : fResource(r), fName(n) {}
|
||||
|
||||
private:
|
||||
void onOnceBeforeDraw() override {
|
||||
constexpr char path[] = "Cowboy.svg";
|
||||
auto data = GetResourceAsData(path);
|
||||
SkASSERT(fResource);
|
||||
auto data = GetResourceAsData(fResource);
|
||||
if (!data) {
|
||||
SkDebugf("file not found: \"%s\"\n", path);
|
||||
SkDebugf("Resource not found: \"%s\"\n", fResource);
|
||||
return;
|
||||
}
|
||||
SkMemoryStream svgStream(std::move(data));
|
||||
|
||||
SkDOM xmlDom;
|
||||
if (!xmlDom.build(svgStream)) {
|
||||
SkDebugf("XML parsing failed: \"path\"\n", fPath.c_str());
|
||||
SkDebugf("XML parsing failed: \"%s\"\n", fResource);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -92,11 +91,9 @@ protected:
|
||||
if (fDom) {
|
||||
fDom->setContainerSize(SkSize::Make(this->width(), this->height()));
|
||||
}
|
||||
|
||||
this->INHERITED::onSizeChange();
|
||||
}
|
||||
|
||||
SkString name() override { return fLabel; }
|
||||
SkString name() override { return SkASSERT(fName), SkString(fName); }
|
||||
|
||||
bool onAnimate(double nanos) override {
|
||||
if (!fDom) {
|
||||
@ -123,20 +120,9 @@ protected:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
sk_sp<SkSVGDOM> fDom;
|
||||
SkString fPath;
|
||||
SkString fLabel;
|
||||
State fState;
|
||||
int fAnimationLoop;
|
||||
SkScalar fDelta;
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
DEF_SAMPLE( return new CowboyView(); )
|
||||
DEF_SAMPLE( return new AnimatedSVGSample("Cowboy.svg", "SampleCowboy"); )
|
||||
|
||||
#endif // SK_XML
|
||||
|
Loading…
Reference in New Issue
Block a user