diff options
author | cdalton <cdalton@nvidia.com> | 2015-06-29 14:06:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-29 14:06:10 -0700 |
commit | 63a82855b1f0b83952b65fca330954c50ebe7a4b (patch) | |
tree | 63f6d3856bf95ea020d7f5143ee5fe8ab56d41d6 /bench | |
parent | c782b2a046763dc427fa47d4e33afca59c994d60 (diff) |
Make nanobench zoom animation time based
BUG=skia:
Review URL: https://codereview.chromium.org/1211253003
Diffstat (limited to 'bench')
-rw-r--r-- | bench/SKPAnimationBench.cpp | 81 | ||||
-rw-r--r-- | bench/SKPAnimationBench.h | 25 | ||||
-rw-r--r-- | bench/nanobench.cpp | 21 |
3 files changed, 76 insertions, 51 deletions
diff --git a/bench/SKPAnimationBench.cpp b/bench/SKPAnimationBench.cpp index 55a85966a4..02fd48a0f1 100644 --- a/bench/SKPAnimationBench.cpp +++ b/bench/SKPAnimationBench.cpp @@ -11,16 +11,10 @@ #include "SkSurface.h" SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic, const SkIRect& clip, - SkMatrix animationMatrix, int steps, bool doLooping) + Animation* animation, bool doLooping) : INHERITED(name, pic, clip, 1.0, false, doLooping) - , fSteps(steps) - , fAnimationMatrix(animationMatrix) - , fName(name) { - fUniqueName.printf("%s_animation", name); -} - -const char* SKPAnimationBench::onGetName() { - return fName.c_str(); + , fAnimation(SkRef(animation)) { + fUniqueName.printf("%s_%s", name, fAnimation->getTag()); } const char* SKPAnimationBench::onGetUniqueName() { @@ -29,32 +23,53 @@ const char* SKPAnimationBench::onGetUniqueName() { void SKPAnimationBench::onPerCanvasPreDraw(SkCanvas* canvas) { INHERITED::onPerCanvasPreDraw(canvas); - SkIRect bounds; - SkAssertResult(canvas->getClipDeviceBounds(&bounds)); - - fCenter.set((bounds.fRight - bounds.fLeft) / 2.0f, - (bounds.fBottom - bounds.fTop) / 2.0f); + SkAssertResult(canvas->getClipDeviceBounds(&fDevBounds)); + fAnimationTimer.start(); } void SKPAnimationBench::drawPicture() { - SkMatrix frameMatrix = SkMatrix::MakeTrans(-fCenter.fX, -fCenter.fY); - frameMatrix.postConcat(fAnimationMatrix); - SkMatrix reverseTranslate = SkMatrix::MakeTrans(fCenter.fX, fCenter.fY); - frameMatrix.postConcat(reverseTranslate); - - SkMatrix currentMatrix = frameMatrix; - for (int i = 0; i < fSteps; i++) { - 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); - SkMatrix tileMatrix = currentMatrix; - tileMatrix.postConcat(trans); - this->surfaces()[j]->getCanvas()->drawPicture(this->picture(), &tileMatrix, NULL); - } - - for (int j = 0; j < this->tileRects().count(); ++j) { - this->surfaces()[j]->getCanvas()->flush(); - } - currentMatrix.postConcat(frameMatrix); + 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); + this->surfaces()[j]->getCanvas()->drawPicture(this->picture(), &trans, NULL); } + + for (int j = 0; j < this->tileRects().count(); ++j) { + this->surfaces()[j]->getCanvas()->flush(); + } +} + +class ZoomAnimation : public SKPAnimationBench::Animation { +public: + ZoomAnimation(SkScalar zoomMax, double zoomPeriodMs) + : fZoomMax(zoomMax) + , fZoomPeriodMs(zoomPeriodMs) { + } + + virtual const char* getTag() { return "zoom"; } + + virtual void preConcatFrameMatrix(double animationTimeMs, const SkIRect& devBounds, + SkMatrix* drawMatrix) { + double t = fmod(animationTimeMs / fZoomPeriodMs, 1.0); // t is in [0, 1). + t = fabs(2 * t - 1); // Make t ping-pong between 0 and 1 + SkScalar zoom = static_cast<SkScalar>(pow(fZoomMax, t)); + + SkPoint center = SkPoint::Make((devBounds.fLeft + devBounds.fRight) / 2.0f, + (devBounds.fTop + devBounds.fBottom) / 2.0f); + drawMatrix->preTranslate(center.fX, center.fY); + drawMatrix->preScale(zoom, zoom); + drawMatrix->preTranslate(-center.fX, -center.fY); + } + +private: + double fZoomMax; + double fZoomPeriodMs; +}; + +SKPAnimationBench::Animation* SKPAnimationBench::CreateZoomAnimation(SkScalar zoomMax, + double zoomPeriodMs) { + return SkNEW_ARGS(ZoomAnimation, (zoomMax, zoomPeriodMs)); } diff --git a/bench/SKPAnimationBench.h b/bench/SKPAnimationBench.h index 65708f7639..c0bef308ec 100644 --- a/bench/SKPAnimationBench.h +++ b/bench/SKPAnimationBench.h @@ -9,6 +9,7 @@ #define SKPAnimationBench_DEFINED #include "SKPBench.h" +#include "Timer.h" /** * Runs an SkPicture as a benchmark by repeatedly drawing it, first centering the picture and @@ -16,11 +17,20 @@ */ class SKPAnimationBench : public SKPBench { public: - SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip, - SkMatrix viewMatrix, int steps, bool doLooping); + class Animation : public SkRefCnt { + public: + virtual const char* getTag() = 0; + virtual void preConcatFrameMatrix(double animationTimeMs, const SkIRect& devBounds, + SkMatrix* drawMatrix) = 0; + virtual ~Animation() {} + }; + + SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip, Animation*, + bool doLooping); + + static Animation* CreateZoomAnimation(SkScalar zoomMax, double zoomPeriodMs); protected: - const char* onGetName() override; const char* onGetUniqueName() override; void onPerCanvasPreDraw(SkCanvas* canvas) override; @@ -30,11 +40,10 @@ protected: void drawPicture() override; private: - int fSteps; - SkMatrix fAnimationMatrix; - SkString fName; - SkString fUniqueName; - SkPoint fCenter; + SkAutoTUnref<Animation> fAnimation; + WallTimer fAnimationTimer; + SkString fUniqueName; + SkIRect fDevBounds; typedef SKPBench INHERITED; }; diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 7cc5383091..519d320985 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -99,7 +99,8 @@ DEFINE_int32(maxCalibrationAttempts, 3, DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); -DEFINE_string(zoom, "1.0,1", "Comma-separated scale,step zoom factors for SKPs."); +DEFINE_string(zoom, "1.0,0", "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom " + "function that ping-pongs between 1.0 and zoomMax."); DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?"); DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?"); @@ -599,8 +600,8 @@ public: } } - if (2 != sscanf(FLAGS_zoom[0], "%f,%d", &fZoomScale, &fZoomSteps)) { - SkDebugf("Can't parse %s from --zoom as a scale,step.\n", FLAGS_zoom[0]); + if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) { + SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]); exit(1); } @@ -728,7 +729,7 @@ public: } // Now loop over each skp again if we have an animation - if (fZoomScale != 1.0f && fZoomSteps != 1) { + if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { while (fCurrentAnimSKP < fSKPs.count()) { const SkString& path = fSKPs[fCurrentAnimSKP]; SkAutoTUnref<SkPicture> pic; @@ -739,10 +740,10 @@ public: fCurrentAnimSKP++; SkString name = SkOSPath::Basename(path.c_str()); - SkMatrix anim = SkMatrix::I(); - anim.setScale(fZoomScale, fZoomScale); - return SkNEW_ARGS(SKPAnimationBench, (name.c_str(), pic.get(), fClip, anim, - fZoomSteps, FLAGS_loopSKP)); + SkAutoTUnref<SKPAnimationBench::Animation> animation( + SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs)); + return SkNEW_ARGS(SKPAnimationBench, (name.c_str(), pic.get(), fClip, animation, + FLAGS_loopSKP)); } } @@ -910,8 +911,8 @@ private: SkTArray<bool> fUseMPDs; SkTArray<SkString> fImages; SkTArray<SkColorType> fColorTypes; - SkScalar fZoomScale; - int fZoomSteps; + SkScalar fZoomMax; + double fZoomPeriodMs; double fSKPBytes, fSKPOps; |