From 261c3ad7fde95748da92550735decc949dc73bf2 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Mon, 27 Apr 2015 09:16:57 -0700 Subject: Change to add zoom animations to nanobench BUG=skia: Review URL: https://codereview.chromium.org/1061323003 --- bench/SKPAnimationBench.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bench/SKPAnimationBench.cpp (limited to 'bench/SKPAnimationBench.cpp') 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); + } +} -- cgit v1.2.3