Home | History | Annotate | Download | only in bench
      1 /*
      2  * Copyright 2015 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "SKPAnimationBench.h"
      9 #include "SkCommandLineFlags.h"
     10 #include "SkMultiPictureDraw.h"
     11 #include "SkSurface.h"
     12 
     13 SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic,
     14                                      const SkIRect& clip, SkMatrix animationMatrix, int steps)
     15     : INHERITED(name, pic, clip, 1.0, false)
     16     , fSteps(steps)
     17     , fAnimationMatrix(animationMatrix)
     18     , fName(name) {
     19     fUniqueName.printf("%s_animation", name);
     20 }
     21 
     22 const char* SKPAnimationBench::onGetName() {
     23     return fName.c_str();
     24 }
     25 
     26 const char* SKPAnimationBench::onGetUniqueName() {
     27     return fUniqueName.c_str();
     28 }
     29 
     30 void SKPAnimationBench::onPerCanvasPreDraw(SkCanvas* canvas) {
     31     INHERITED::onPerCanvasPreDraw(canvas);
     32     SkIRect bounds;
     33     SkAssertResult(canvas->getClipDeviceBounds(&bounds));
     34 
     35     fCenter.set((bounds.fRight - bounds.fLeft) / 2.0f,
     36                 (bounds.fBottom - bounds.fTop) / 2.0f);
     37 }
     38 
     39 void SKPAnimationBench::drawPicture() {
     40     SkMatrix frameMatrix = SkMatrix::MakeTrans(-fCenter.fX, -fCenter.fY);
     41     frameMatrix.postConcat(fAnimationMatrix);
     42     SkMatrix reverseTranslate = SkMatrix::MakeTrans(fCenter.fX, fCenter.fY);
     43     frameMatrix.postConcat(reverseTranslate);
     44 
     45     SkMatrix currentMatrix = frameMatrix;
     46     for (int i = 0; i < fSteps; i++) {
     47         for (int j = 0; j < this->tileRects().count(); ++j) {
     48             SkMatrix trans = SkMatrix::MakeTrans(-1.f * this->tileRects()[j].fLeft,
     49                                                  -1.f * this->tileRects()[j].fTop);
     50             SkMatrix tileMatrix = currentMatrix;
     51             tileMatrix.postConcat(trans);
     52             this->surfaces()[j]->getCanvas()->drawPicture(this->picture(), &tileMatrix, NULL);
     53         }
     54 
     55         for (int j = 0; j < this->tileRects().count(); ++j) {
     56            this->surfaces()[j]->getCanvas()->flush();
     57         }
     58         currentMatrix.postConcat(frameMatrix);
     59     }
     60 }
     61