switch to a new canvas every once in a while in picture_record_unique

BUG=
R=robertphillips@google.com

Review URL: https://codereview.chromium.org/23995020

git-svn-id: http://skia.googlecode.com/svn/trunk@11321 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
mtklein@google.com 2013-09-17 17:14:25 +00:00
parent d8807976e7
commit 5e5239ed35

View File

@ -18,8 +18,6 @@ class PictureRecordBench : public SkBenchmark {
public:
PictureRecordBench(const char name[]) {
fName.printf("picture_record_%s", name);
fPictureWidth = SkIntToScalar(PICTURE_WIDTH);
fPictureHeight = SkIntToScalar(PICTURE_HEIGHT);
fIsRendering = false;
}
@ -47,9 +45,6 @@ protected:
virtual void recordCanvas(SkCanvas* canvas) = 0;
SkString fName;
SkScalar fPictureWidth;
SkScalar fPictureHeight;
SkScalar fTextSize;
private:
typedef SkBenchmark INHERITED;
};
@ -127,10 +122,21 @@ public:
: INHERITED("unique_paint_dictionary") { }
protected:
virtual void recordCanvas(SkCanvas* canvas) {
virtual void recordCanvas(SkCanvas* /*ignored*/) {
// We ignore the parent's canvas (which is just there for our
// convenience) because we've got to have more careful control over it.
// We start a new one every so often to prevent unbounded memory growth.
SkRandom rand;
SkPaint paint;
SkAutoTDelete<SkPicture> picture;
SkCanvas* canvas = NULL;
const int kMaxPaintsPerCanvas = 10000;
for (int i = 0; i < this->getLoops(); i++) {
SkPaint paint;
if (0 == i % kMaxPaintsPerCanvas) {
picture.reset(SkNEW(SkPicture));
canvas = picture->beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
}
paint.setColor(rand.nextU());
canvas->drawPaint(paint);
}