diff options
author | 2015-04-27 09:16:57 -0700 | |
---|---|---|
committer | 2015-04-27 09:16:57 -0700 | |
commit | 261c3ad7fde95748da92550735decc949dc73bf2 (patch) | |
tree | b3e824a2c6e59a8001dd5a9641047ff7f56acb2b /bench/SKPAnimationBench.cpp | |
parent | 00c2af8b731085a7fe456e689b70f019a34ef7dd (diff) |
Change to add zoom animations to nanobench
BUG=skia:
Review URL: https://codereview.chromium.org/1061323003
Diffstat (limited to 'bench/SKPAnimationBench.cpp')
-rw-r--r-- | bench/SKPAnimationBench.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bench/SKPAnimationBench.cpp b/bench/SKPAnimationBench.cpp new file mode 100644 index 0000000000..24506d814f --- /dev/null +++ b/bench/SKPAnimationBench.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SKPAnimationBench.h" +#include "SkCommandLineFlags.h" +#include "SkMultiPictureDraw.h" +#include "SkSurface.h" + +SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic, + const SkIRect& clip, SkMatrix animationMatrix, int steps) + : INHERITED(name, pic, clip, 1.0, false) + , fSteps(steps) + , fAnimationMatrix(animationMatrix) + , fName(name) { + fUniqueName.printf("%s_animation", name); +} + +const char* SKPAnimationBench::onGetName() { + return fName.c_str(); +} + +const char* SKPAnimationBench::onGetUniqueName() { + return fUniqueName.c_str(); +} + +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); +} + +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); + } +} |