Chromium Code Reviews| Index: bench/PictureNestingBench.cpp |
| diff --git a/bench/PictureNestingBench.cpp b/bench/PictureNestingBench.cpp |
| index c2848833b747a8d8afaaf09117addeb75129fe04..224f7355f90541f07efb48353e467ef488d51897 100644 |
| --- a/bench/PictureNestingBench.cpp |
| +++ b/bench/PictureNestingBench.cpp |
| @@ -14,20 +14,23 @@ |
| #include "SkPictureRecorder.h" |
| #include "SkString.h" |
| +#include <math.h> |
| + |
| class PictureNesting : public Benchmark { |
| public: |
| PictureNesting(const char* name, int maxLevel, int maxPictureLevel) |
| : fMaxLevel(maxLevel) |
| , fMaxPictureLevel(maxPictureLevel) { |
| + fName.printf("picture_nesting_%s_%d", name, this->countPics()); |
| + } |
| +protected: |
| + virtual void onPreDraw() SK_OVERRIDE { |
|
mtklein
2014/11/13 16:15:04
Moving this part to onPreDraw() might be overkill.
Kimmo Kinnunen
2014/11/18 12:42:19
Done.
|
| fPaint.setColor(SK_ColorRED); |
| fPaint.setAntiAlias(true); |
| fPaint.setStyle(SkPaint::kStroke_Style); |
| - SkAutoTUnref<SkCanvas> nullCanvas(SkCreateNullCanvas()); |
| - fName.printf("picture_nesting_%s_%d", name, this->sierpinsky(nullCanvas, 0, fPaint)); |
| } |
| -protected: |
| virtual const char* onGetName() SK_OVERRIDE { |
| return fName.c_str(); |
| } |
| @@ -37,7 +40,8 @@ protected: |
| canvas->save(); |
| canvas->scale(SkIntToScalar(canvasSize.x()), SkIntToScalar(canvasSize.y())); |
| - this->sierpinsky(canvas, 0, fPaint); |
| + SkDEBUGCODE(int pics = ) this->sierpinsky(canvas, 0, fPaint); |
| + SkASSERT(pics == this->countPics()); |
| canvas->restore(); |
| } |
| @@ -86,6 +90,15 @@ protected: |
| int fMaxPictureLevel; |
| private: |
| + int countPics() const { |
| + // Solve: pics from sierpinsky |
| + // f(m) = 1 + 3*f(m - 1) |
| + // f(0) = 0 |
| + // via "recursive function to closed form" tricks |
| + // f(m) = 1/2 (3^m - 1) |
| + return (pow(3, fMaxPictureLevel) - 1) / 2; |
|
mtklein
2014/11/13 16:15:04
You may need some explicit casts in here. Our com
Kimmo Kinnunen
2014/11/18 12:42:19
Done.
|
| + } |
| + |
| SkString fName; |
| SkPaint fPaint; |
| @@ -123,6 +136,10 @@ class PictureNestingPlayback : public PictureNesting { |
| public: |
| PictureNestingPlayback(int maxLevel, int maxPictureLevel) |
| : INHERITED("playback", maxLevel, maxPictureLevel) { |
| + } |
| +protected: |
| + virtual void onPreDraw() SK_OVERRIDE { |
| + this->INHERITED::onPreDraw(); |
| SkIPoint canvasSize = onGetSize(); |
| SkPictureRecorder recorder; |
| @@ -133,7 +150,6 @@ public: |
| fPicture.reset(recorder.endRecording()); |
| } |
| -protected: |
| virtual void onDraw(const int loops, SkCanvas* canvas) { |
| for (int i = 0; i < loops; i++) { |
| canvas->drawPicture(fPicture); |