Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkColor.h" | 9 #include "SkColor.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| 11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
| 12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
| 13 #include "SkRandom.h" | 13 #include "SkRandom.h" |
| 14 #include "SkRect.h" | 14 #include "SkRect.h" |
| 15 #include "SkString.h" | 15 #include "SkString.h" |
| 16 | 16 |
| 17 class PictureRecordBench : public SkBenchmark { | 17 class PictureRecordBench : public SkBenchmark { |
| 18 public: | 18 public: |
| 19 PictureRecordBench(const char name[]) { | 19 PictureRecordBench(const char name[]) { |
| 20 fName.printf("picture_record_%s", name); | 20 fName.printf("picture_record_%s", name); |
| 21 fPictureWidth = SkIntToScalar(PICTURE_WIDTH); | |
| 22 fPictureHeight = SkIntToScalar(PICTURE_HEIGHT); | |
| 23 fIsRendering = false; | 21 fIsRendering = false; |
| 24 } | 22 } |
| 25 | 23 |
| 26 enum { | 24 enum { |
| 27 PICTURE_WIDTH = 1000, | 25 PICTURE_WIDTH = 1000, |
| 28 PICTURE_HEIGHT = 4000, | 26 PICTURE_HEIGHT = 4000, |
| 29 }; | 27 }; |
| 30 protected: | 28 protected: |
| 31 virtual const char* onGetName() { | 29 virtual const char* onGetName() { |
| 32 return fName.c_str(); | 30 return fName.c_str(); |
| 33 } | 31 } |
| 34 | 32 |
| 35 virtual void onDraw(SkCanvas*) { | 33 virtual void onDraw(SkCanvas*) { |
|
robertphillips
2013/09/17 16:19:33
Don't think we need most of this stuff anymore. Ca
mtklein
2013/09/17 16:55:10
Sorry, I'm a little lost. Do you mean, have Uniqu
| |
| 36 SkPicture picture; | 34 SkPicture picture; |
| 37 | 35 |
| 38 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT ); | 36 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT ); |
| 39 recordCanvas(pCanvas); | 37 recordCanvas(pCanvas); |
| 40 | 38 |
| 41 // we don't need to draw the picture as the endRecording step will | 39 // we don't need to draw the picture as the endRecording step will |
| 42 // do the work of transferring the recorded content into a playback | 40 // do the work of transferring the recorded content into a playback |
| 43 // object. | 41 // object. |
| 44 picture.endRecording(); | 42 picture.endRecording(); |
| 45 } | 43 } |
| 46 | 44 |
| 47 virtual void recordCanvas(SkCanvas* canvas) = 0; | 45 virtual void recordCanvas(SkCanvas* canvas) = 0; |
| 48 | 46 |
| 49 SkString fName; | 47 SkString fName; |
| 50 SkScalar fPictureWidth; | |
| 51 SkScalar fPictureHeight; | |
| 52 SkScalar fTextSize; | |
| 53 private: | 48 private: |
| 54 typedef SkBenchmark INHERITED; | 49 typedef SkBenchmark INHERITED; |
| 55 }; | 50 }; |
| 56 | 51 |
| 57 /* | 52 /* |
| 58 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints, | 53 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints, |
| 59 * and regions. This bench populates those dictionaries to test the speed of | 54 * and regions. This bench populates those dictionaries to test the speed of |
| 60 * reading and writing to those particular dictionary data structures. | 55 * reading and writing to those particular dictionary data structures. |
| 61 */ | 56 */ |
| 62 class DictionaryRecordBench : public PictureRecordBench { | 57 class DictionaryRecordBench : public PictureRecordBench { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 /* | 115 /* |
| 121 * Populates the SkPaint dictionary with a large number of unique paint | 116 * Populates the SkPaint dictionary with a large number of unique paint |
| 122 * objects that differ only by color | 117 * objects that differ only by color |
| 123 */ | 118 */ |
| 124 class UniquePaintDictionaryRecordBench : public PictureRecordBench { | 119 class UniquePaintDictionaryRecordBench : public PictureRecordBench { |
| 125 public: | 120 public: |
| 126 UniquePaintDictionaryRecordBench() | 121 UniquePaintDictionaryRecordBench() |
| 127 : INHERITED("unique_paint_dictionary") { } | 122 : INHERITED("unique_paint_dictionary") { } |
| 128 | 123 |
| 129 protected: | 124 protected: |
| 130 virtual void recordCanvas(SkCanvas* canvas) { | 125 virtual void recordCanvas(SkCanvas* /*ignored*/) { |
| 126 // We ignore the parent's canvas (which is just there for our | |
| 127 // convenience) because we've got to have more careful control over it. | |
| 128 // We start a new one every so often to prevent unbounded memory growth. | |
| 129 | |
| 131 SkRandom rand; | 130 SkRandom rand; |
| 131 SkPaint paint; | |
| 132 SkAutoTDelete<SkPicture> picture; | |
| 133 SkCanvas* canvas = NULL; | |
| 134 const int kMaxPaintsPerCanvas = 10000; | |
| 132 for (int i = 0; i < this->getLoops(); i++) { | 135 for (int i = 0; i < this->getLoops(); i++) { |
| 133 SkPaint paint; | 136 if (0 == i % kMaxPaintsPerCanvas) { |
| 137 picture.reset(SkNEW(SkPicture)); | |
| 138 canvas = picture->beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); | |
| 139 } | |
| 134 paint.setColor(rand.nextU()); | 140 paint.setColor(rand.nextU()); |
| 135 canvas->drawPaint(paint); | 141 canvas->drawPaint(paint); |
| 136 } | 142 } |
| 137 } | 143 } |
| 138 | 144 |
| 139 private: | 145 private: |
| 140 typedef PictureRecordBench INHERITED; | 146 typedef PictureRecordBench INHERITED; |
| 141 }; | 147 }; |
| 142 | 148 |
| 143 /* | 149 /* |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 172 private: | 178 private: |
| 173 SkPaint fPaint [ObjCount]; | 179 SkPaint fPaint [ObjCount]; |
| 174 typedef PictureRecordBench INHERITED; | 180 typedef PictureRecordBench INHERITED; |
| 175 }; | 181 }; |
| 176 | 182 |
| 177 /////////////////////////////////////////////////////////////////////////////// | 183 /////////////////////////////////////////////////////////////////////////////// |
| 178 | 184 |
| 179 DEF_BENCH( return new DictionaryRecordBench(); ) | 185 DEF_BENCH( return new DictionaryRecordBench(); ) |
| 180 DEF_BENCH( return new UniquePaintDictionaryRecordBench(); ) | 186 DEF_BENCH( return new UniquePaintDictionaryRecordBench(); ) |
| 181 DEF_BENCH( return new RecurringPaintDictionaryRecordBench(); ) | 187 DEF_BENCH( return new RecurringPaintDictionaryRecordBench(); ) |
| OLD | NEW |