Remove WallTimer class.

Only used in three somewhat dubious places.

Change-Id: I7ccd1aef41f826d0eb62606751f4d3f0ceda267d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227065
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2019-07-12 12:51:44 -04:00 committed by Skia Commit-Bot
parent f355a1ead8
commit acf98df7a1
6 changed files with 19 additions and 98 deletions

View File

@ -11,9 +11,9 @@
#include "tools/flags/CommandLineFlags.h" #include "tools/flags/CommandLineFlags.h"
SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic, const SkIRect& clip, SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic, const SkIRect& clip,
Animation* animation, bool doLooping) sk_sp<Animation> animation, bool doLooping)
: INHERITED(name, pic, clip, 1.0, false, doLooping) : INHERITED(name, pic, clip, 1.0, false, doLooping)
, fAnimation(SkRef(animation)) { , fAnimation(std::move(animation)) {
fUniqueName.printf("%s_%s", name, fAnimation->getTag()); fUniqueName.printf("%s_%s", name, fAnimation->getTag());
} }
@ -25,16 +25,13 @@ void SKPAnimationBench::onPerCanvasPreDraw(SkCanvas* canvas) {
INHERITED::onPerCanvasPreDraw(canvas); INHERITED::onPerCanvasPreDraw(canvas);
fDevBounds = canvas->getDeviceClipBounds(); fDevBounds = canvas->getDeviceClipBounds();
SkAssertResult(!fDevBounds.isEmpty()); SkAssertResult(!fDevBounds.isEmpty());
fAnimationTimer.start();
} }
void SKPAnimationBench::drawPicture() { void SKPAnimationBench::drawPicture() {
fAnimationTimer.end();
for (int j = 0; j < this->tileRects().count(); ++j) { for (int j = 0; j < this->tileRects().count(); ++j) {
SkMatrix trans = SkMatrix::MakeTrans(-1.f * this->tileRects()[j].fLeft, SkMatrix trans = SkMatrix::MakeTrans(-1.f * this->tileRects()[j].fLeft,
-1.f * this->tileRects()[j].fTop); -1.f * this->tileRects()[j].fTop);
fAnimation->preConcatFrameMatrix(fAnimationTimer.fWall, fDevBounds, &trans); fAnimation->preConcatFrameMatrix(fAnimationTime.nextRangeF(0, 1000), fDevBounds, &trans);
this->surfaces()[j]->getCanvas()->drawPicture(this->picture(), &trans, nullptr); this->surfaces()[j]->getCanvas()->drawPicture(this->picture(), &trans, nullptr);
} }
@ -70,7 +67,7 @@ private:
double fZoomPeriodMs; double fZoomPeriodMs;
}; };
SKPAnimationBench::Animation* SKPAnimationBench::CreateZoomAnimation(SkScalar zoomMax, sk_sp<SKPAnimationBench::Animation> SKPAnimationBench::MakeZoomAnimation(SkScalar zoomMax,
double zoomPeriodMs) { double zoomPeriodMs) {
return new ZoomAnimation(zoomMax, zoomPeriodMs); return sk_make_sp<ZoomAnimation>(zoomMax, zoomPeriodMs);
} }

View File

@ -10,6 +10,7 @@
#include "bench/SKPBench.h" #include "bench/SKPBench.h"
#include "tools/timer/Timer.h" #include "tools/timer/Timer.h"
#include "include/utils/SkRandom.h"
/** /**
* Runs an SkPicture as a benchmark by repeatedly drawing it, first centering the picture and * Runs an SkPicture as a benchmark by repeatedly drawing it, first centering the picture and
@ -25,10 +26,10 @@ public:
virtual ~Animation() {} virtual ~Animation() {}
}; };
SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip, Animation*, SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip, sk_sp<Animation>,
bool doLooping); bool doLooping);
static Animation* CreateZoomAnimation(SkScalar zoomMax, double zoomPeriodMs); static sk_sp<Animation> MakeZoomAnimation(SkScalar zoomMax, double zoomPeriodMs);
protected: protected:
const char* onGetUniqueName() override; const char* onGetUniqueName() override;
@ -41,7 +42,7 @@ protected:
private: private:
sk_sp<Animation> fAnimation; sk_sp<Animation> fAnimation;
WallTimer fAnimationTimer; SkRandom fAnimationTime;
SkString fUniqueName; SkString fUniqueName;
SkIRect fDevBounds; SkIRect fDevBounds;

View File

@ -28,6 +28,7 @@
#include "include/core/SkPictureRecorder.h" #include "include/core/SkPictureRecorder.h"
#include "include/core/SkString.h" #include "include/core/SkString.h"
#include "include/core/SkSurface.h" #include "include/core/SkSurface.h"
#include "include/core/SkTime.h"
#include "src/core/SkAutoMalloc.h" #include "src/core/SkAutoMalloc.h"
#include "src/core/SkBBoxHierarchy.h" #include "src/core/SkBBoxHierarchy.h"
#include "src/core/SkColorSpacePriv.h" #include "src/core/SkColorSpacePriv.h"
@ -845,9 +846,9 @@ public:
fCurrentAnimSKP++; fCurrentAnimSKP++;
SkString name = SkOSPath::Basename(path.c_str()); SkString name = SkOSPath::Basename(path.c_str());
sk_sp<SKPAnimationBench::Animation> animation( sk_sp<SKPAnimationBench::Animation> animation =
SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs)); SKPAnimationBench::MakeZoomAnimation(fZoomMax, fZoomPeriodMs);
return new SKPAnimationBench(name.c_str(), pic.get(), fClip, animation.get(), return new SKPAnimationBench(name.c_str(), pic.get(), fClip, std::move(animation),
FLAGS_loopSKP); FLAGS_loopSKP);
} }
} }

View File

@ -14,7 +14,6 @@
#include "include/utils/SkRandom.h" #include "include/utils/SkRandom.h"
#include "samplecode/Sample.h" #include "samplecode/Sample.h"
#include "src/utils/SkUTF.h" #include "src/utils/SkUTF.h"
#include "tools/timer/Timer.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
@ -40,11 +39,7 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
class AnimatedTextView : public Sample { class AnimatedTextView : public Sample {
public: public:
AnimatedTextView() : fScale(1.0f), fScaleInc(0.1f), fRotation(0.0f), fSizeScale(1) { AnimatedTextView() : fScale(1.0f), fScaleInc(0.1f), fRotation(0.0f), fSizeScale(1) {}
fCurrentTime = 0;
fTimer.start();
memset(fTimes, 0, sizeof(fTimes));
}
protected: protected:
SkString name() override { return SkString("AnimatedText"); } SkString name() override { return SkString("AnimatedText"); }
@ -68,29 +63,6 @@ protected:
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setFilterQuality(kMedium_SkFilterQuality); paint.setFilterQuality(kMedium_SkFilterQuality);
SkString outString("fps: ");
fTimer.end();
// TODO: generalize this timing code in utils
fTimes[fCurrentTime] = (float)(fTimer.fWall);
fCurrentTime = (fCurrentTime + 1) & 0x1f;
float meanTime = 0.0f;
for (int i = 0; i < 32; ++i) {
meanTime += fTimes[i];
}
meanTime /= 32.f;
SkScalar fps = 1000.f / meanTime;
outString.appendScalar(fps);
outString.append(" ms: ");
outString.appendScalar(meanTime);
SkString modeString("Text scale: ");
modeString.appendU32(fSizeScale);
modeString.append("x");
fTimer.start();
canvas->save(); canvas->save();
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
@ -119,11 +91,10 @@ protected:
canvas->restore(); canvas->restore();
font.setSize(16); font.setSize(16);
// canvas->drawString(outString, 512.f, 540.f, paint);
canvas->drawString(modeString, 768.f, 540.f, font, paint);
} }
bool onAnimate(double nanos) override { bool onAnimate(double nanos) override {
// TODO: use nanos
// We add noise to the scale and rotation animations to // We add noise to the scale and rotation animations to
// keep the font atlas from falling into a steady state // keep the font atlas from falling into a steady state
fRotation += (1.0f + gRand.nextRangeF(-0.1f, 0.1f)); fRotation += (1.0f + gRand.nextRangeF(-0.1f, 0.1f));
@ -142,10 +113,6 @@ private:
float fRotation; float fRotation;
int fSizeScale; int fSizeScale;
WallTimer fTimer;
float fTimes[32];
int fCurrentTime;
typedef Sample INHERITED; typedef Sample INHERITED;
}; };

View File

@ -80,8 +80,6 @@ public:
fXform[currIndex] = SkRSXform::MakeFromRadians(0.5f, SK_ScalarPI*0.5f, fXform[currIndex] = SkRSXform::MakeFromRadians(0.5f, SK_ScalarPI*0.5f,
kWidth*0.5f, kHeight*0.5f, anchorX, anchorY); kWidth*0.5f, kHeight*0.5f, anchorX, anchorY);
fCurrentTime = 0;
fTimer.start();
} }
~DrawShipView() override {} ~DrawShipView() override {}
@ -101,27 +99,6 @@ protected:
paint.setFilterQuality(kLow_SkFilterQuality); paint.setFilterQuality(kLow_SkFilterQuality);
paint.setColor(SK_ColorWHITE); paint.setColor(SK_ColorWHITE);
SkFont font;
font.setSize(15.0f);
fTimer.end();
fTimes[fCurrentTime] = (float)(fTimer.fWall);
fCurrentTime = (fCurrentTime + 1) & 0x1f;
float meanTime = 0.0f;
for (int i = 0; i < 32; ++i) {
meanTime += fTimes[i];
}
meanTime /= 32.f;
SkString outString("fps: ");
SkScalar fps = 1000.f/meanTime;
outString.appendScalar(fps);
outString.append(" ms: ");
outString.appendScalar(meanTime);
fTimer.start();
SkScalar anchorX = fAtlas->width()*0.5f; SkScalar anchorX = fAtlas->width()*0.5f;
SkScalar anchorY = fAtlas->height()*0.5f; SkScalar anchorY = fAtlas->height()*0.5f;
for (int i = 0; i < kGrid*kGrid+1; ++i) { for (int i = 0; i < kGrid*kGrid+1; ++i) {
@ -141,20 +118,14 @@ protected:
} }
fProc(canvas, fAtlas.get(), fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &paint); fProc(canvas, fAtlas.get(), fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &paint);
paint.setColor(SK_ColorBLACK);
canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint);
paint.setColor(SK_ColorWHITE);
canvas->drawString(outString, 5, 15, font, paint);
} }
#if 0
// TODO: switch over to use this for our animation
bool onAnimate(double nanos) override { bool onAnimate(double nanos) override {
SkScalar angle = SkDoubleToScalar(fmod(1e-9 * nanos * 360 / 24, 360)); //TODO: use nanos
fAnimatingDrawable->setSweep(angle); //SkScalar angle = SkDoubleToScalar(fmod(1e-9 * nanos * 360 / 24, 360));
//fAnimatingDrawable->setSweep(angle);
return true; return true;
} }
#endif
private: private:
const char* fName; const char* fName;
@ -163,10 +134,6 @@ private:
sk_sp<SkImage> fAtlas; sk_sp<SkImage> fAtlas;
SkRSXform fXform[kGrid*kGrid+1]; SkRSXform fXform[kGrid*kGrid+1];
SkRect fTex[kGrid*kGrid+1]; SkRect fTex[kGrid*kGrid+1];
WallTimer fTimer;
float fTimes[32];
int fCurrentTime;
typedef Sample INHERITED; typedef Sample INHERITED;
}; };

View File

@ -8,18 +8,6 @@
#define Timer_DEFINED #define Timer_DEFINED
#include "include/core/SkString.h" #include "include/core/SkString.h"
#include "include/core/SkTime.h"
#include "include/core/SkTypes.h"
class WallTimer {
public:
WallTimer() : fWall(-1) {}
void start() { fWall = SkTime::GetNSecs(); }
void end() { fWall = (SkTime::GetNSecs() - fWall) * 1e-6; }
double fWall; // Milliseconds.
};
SkString HumanizeMs(double); SkString HumanizeMs(double);