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"
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)
, fAnimation(SkRef(animation)) {
, fAnimation(std::move(animation)) {
fUniqueName.printf("%s_%s", name, fAnimation->getTag());
}
@ -25,16 +25,13 @@ void SKPAnimationBench::onPerCanvasPreDraw(SkCanvas* canvas) {
INHERITED::onPerCanvasPreDraw(canvas);
fDevBounds = canvas->getDeviceClipBounds();
SkAssertResult(!fDevBounds.isEmpty());
fAnimationTimer.start();
}
void SKPAnimationBench::drawPicture() {
fAnimationTimer.end();
for (int j = 0; j < this->tileRects().count(); ++j) {
SkMatrix trans = SkMatrix::MakeTrans(-1.f * this->tileRects()[j].fLeft,
-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);
}
@ -70,7 +67,7 @@ private:
double fZoomPeriodMs;
};
SKPAnimationBench::Animation* SKPAnimationBench::CreateZoomAnimation(SkScalar zoomMax,
double zoomPeriodMs) {
return new ZoomAnimation(zoomMax, zoomPeriodMs);
sk_sp<SKPAnimationBench::Animation> SKPAnimationBench::MakeZoomAnimation(SkScalar zoomMax,
double zoomPeriodMs) {
return sk_make_sp<ZoomAnimation>(zoomMax, zoomPeriodMs);
}

View File

@ -10,6 +10,7 @@
#include "bench/SKPBench.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
@ -25,10 +26,10 @@ public:
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);
static Animation* CreateZoomAnimation(SkScalar zoomMax, double zoomPeriodMs);
static sk_sp<Animation> MakeZoomAnimation(SkScalar zoomMax, double zoomPeriodMs);
protected:
const char* onGetUniqueName() override;
@ -41,7 +42,7 @@ protected:
private:
sk_sp<Animation> fAnimation;
WallTimer fAnimationTimer;
SkRandom fAnimationTime;
SkString fUniqueName;
SkIRect fDevBounds;

View File

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

View File

@ -14,7 +14,6 @@
#include "include/utils/SkRandom.h"
#include "samplecode/Sample.h"
#include "src/utils/SkUTF.h"
#include "tools/timer/Timer.h"
#if SK_SUPPORT_GPU
#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 {
public:
AnimatedTextView() : fScale(1.0f), fScaleInc(0.1f), fRotation(0.0f), fSizeScale(1) {
fCurrentTime = 0;
fTimer.start();
memset(fTimes, 0, sizeof(fTimes));
}
AnimatedTextView() : fScale(1.0f), fScaleInc(0.1f), fRotation(0.0f), fSizeScale(1) {}
protected:
SkString name() override { return SkString("AnimatedText"); }
@ -68,29 +63,6 @@ protected:
paint.setAntiAlias(true);
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();
#if SK_SUPPORT_GPU
@ -119,11 +91,10 @@ protected:
canvas->restore();
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 {
// TODO: use nanos
// We add noise to the scale and rotation animations to
// keep the font atlas from falling into a steady state
fRotation += (1.0f + gRand.nextRangeF(-0.1f, 0.1f));
@ -142,10 +113,6 @@ private:
float fRotation;
int fSizeScale;
WallTimer fTimer;
float fTimes[32];
int fCurrentTime;
typedef Sample INHERITED;
};

View File

@ -80,8 +80,6 @@ public:
fXform[currIndex] = SkRSXform::MakeFromRadians(0.5f, SK_ScalarPI*0.5f,
kWidth*0.5f, kHeight*0.5f, anchorX, anchorY);
fCurrentTime = 0;
fTimer.start();
}
~DrawShipView() override {}
@ -101,27 +99,6 @@ protected:
paint.setFilterQuality(kLow_SkFilterQuality);
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 anchorY = fAtlas->height()*0.5f;
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);
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 {
SkScalar angle = SkDoubleToScalar(fmod(1e-9 * nanos * 360 / 24, 360));
fAnimatingDrawable->setSweep(angle);
//TODO: use nanos
//SkScalar angle = SkDoubleToScalar(fmod(1e-9 * nanos * 360 / 24, 360));
//fAnimatingDrawable->setSweep(angle);
return true;
}
#endif
private:
const char* fName;
@ -163,10 +134,6 @@ private:
sk_sp<SkImage> fAtlas;
SkRSXform fXform[kGrid*kGrid+1];
SkRect fTex[kGrid*kGrid+1];
WallTimer fTimer;
float fTimes[32];
int fCurrentTime;
typedef Sample INHERITED;
};

View File

@ -8,18 +8,6 @@
#define Timer_DEFINED
#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);