Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: bench/PictureNestingBench.cpp

Issue 725523002: Do not calculate many sierpinski fractals for each nanobench run unless needed (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address review commetns Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/PictureNestingBench.cpp
diff --git a/bench/PictureNestingBench.cpp b/bench/PictureNestingBench.cpp
index c2848833b747a8d8afaaf09117addeb75129fe04..7868f46c9fd60190cb64bb20971dabd91502366f 100644
--- a/bench/PictureNestingBench.cpp
+++ b/bench/PictureNestingBench.cpp
@@ -14,17 +14,17 @@
#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());
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:
@@ -37,7 +37,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 +87,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 static_cast<int>((pow(3.0, fMaxPictureLevel) - 1.0) / 2.0);
+ }
+
SkString fName;
SkPaint fPaint;
@@ -123,6 +133,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 +147,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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698