| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "Benchmark.h" | 7 #include "Benchmark.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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 SkScalar fTextSize; | 65 SkScalar fTextSize; |
| 66 private: | 66 private: |
| 67 typedef Benchmark INHERITED; | 67 typedef Benchmark INHERITED; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 | 70 |
| 71 class TextPlaybackBench : public PicturePlaybackBench { | 71 class TextPlaybackBench : public PicturePlaybackBench { |
| 72 public: | 72 public: |
| 73 TextPlaybackBench() : INHERITED("drawText") { } | 73 TextPlaybackBench() : INHERITED("drawText") { } |
| 74 protected: | 74 protected: |
| 75 void recordCanvas(SkCanvas* canvas) SK_OVERRIDE { | 75 void recordCanvas(SkCanvas* canvas) override { |
| 76 SkPaint paint; | 76 SkPaint paint; |
| 77 paint.setTextSize(fTextSize); | 77 paint.setTextSize(fTextSize); |
| 78 paint.setColor(SK_ColorBLACK); | 78 paint.setColor(SK_ColorBLACK); |
| 79 | 79 |
| 80 const char* text = "Hamburgefons"; | 80 const char* text = "Hamburgefons"; |
| 81 size_t len = strlen(text); | 81 size_t len = strlen(text); |
| 82 const SkScalar textWidth = paint.measureText(text, len); | 82 const SkScalar textWidth = paint.measureText(text, len); |
| 83 | 83 |
| 84 for (SkScalar x = 0; x < fPictureWidth; x += textWidth) { | 84 for (SkScalar x = 0; x < fPictureWidth; x += textWidth) { |
| 85 for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) { | 85 for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) { |
| 86 canvas->drawText(text, len, x, y, paint); | 86 canvas->drawText(text, len, x, y, paint); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 private: | 90 private: |
| 91 typedef PicturePlaybackBench INHERITED; | 91 typedef PicturePlaybackBench INHERITED; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class PosTextPlaybackBench : public PicturePlaybackBench { | 94 class PosTextPlaybackBench : public PicturePlaybackBench { |
| 95 public: | 95 public: |
| 96 PosTextPlaybackBench(bool drawPosH) | 96 PosTextPlaybackBench(bool drawPosH) |
| 97 : INHERITED(drawPosH ? "drawPosTextH" : "drawPosText") | 97 : INHERITED(drawPosH ? "drawPosTextH" : "drawPosText") |
| 98 , fDrawPosH(drawPosH) { } | 98 , fDrawPosH(drawPosH) { } |
| 99 protected: | 99 protected: |
| 100 void recordCanvas(SkCanvas* canvas) SK_OVERRIDE { | 100 void recordCanvas(SkCanvas* canvas) override { |
| 101 SkPaint paint; | 101 SkPaint paint; |
| 102 paint.setTextSize(fTextSize); | 102 paint.setTextSize(fTextSize); |
| 103 paint.setColor(SK_ColorBLACK); | 103 paint.setColor(SK_ColorBLACK); |
| 104 | 104 |
| 105 const char* text = "Hamburgefons"; | 105 const char* text = "Hamburgefons"; |
| 106 size_t len = strlen(text); | 106 size_t len = strlen(text); |
| 107 const SkScalar textWidth = paint.measureText(text, len); | 107 const SkScalar textWidth = paint.measureText(text, len); |
| 108 | 108 |
| 109 SkScalar* adv = new SkScalar[len]; | 109 SkScalar* adv = new SkScalar[len]; |
| 110 paint.getTextWidths(text, len, adv); | 110 paint.getTextWidths(text, len, adv); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 switch (fBBH) { | 152 switch (fBBH) { |
| 153 case kNone: fName.append("_none" ); break; | 153 case kNone: fName.append("_none" ); break; |
| 154 case kRTree: fName.append("_rtree" ); break; | 154 case kRTree: fName.append("_rtree" ); break; |
| 155 } | 155 } |
| 156 switch (fMode) { | 156 switch (fMode) { |
| 157 case kTiled: fName.append("_tiled" ); break; | 157 case kTiled: fName.append("_tiled" ); break; |
| 158 case kRandom: fName.append("_random"); break; | 158 case kRandom: fName.append("_random"); break; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 const char* onGetName() SK_OVERRIDE { return fName.c_str(); } | 162 const char* onGetName() override { return fName.c_str(); } |
| 163 SkIPoint onGetSize() SK_OVERRIDE { return SkIPoint::Make(1024,1024); } | 163 SkIPoint onGetSize() override { return SkIPoint::Make(1024,1024); } |
| 164 | 164 |
| 165 void onPreDraw() SK_OVERRIDE { | 165 void onPreDraw() override { |
| 166 SkAutoTDelete<SkBBHFactory> factory; | 166 SkAutoTDelete<SkBBHFactory> factory; |
| 167 switch (fBBH) { | 167 switch (fBBH) { |
| 168 case kNone: break; | 168 case kNone: break; |
| 169 case kRTree: factory.reset(new SkRTreeFactory); break; | 169 case kRTree: factory.reset(new SkRTreeFactory); break; |
| 170 } | 170 } |
| 171 | 171 |
| 172 SkPictureRecorder recorder; | 172 SkPictureRecorder recorder; |
| 173 SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory); | 173 SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory); |
| 174 SkRandom rand; | 174 SkRandom rand; |
| 175 for (int i = 0; i < 10000; i++) { | 175 for (int i = 0; i < 10000; i++) { |
| 176 SkScalar x = rand.nextRangeScalar(0, 1024), | 176 SkScalar x = rand.nextRangeScalar(0, 1024), |
| 177 y = rand.nextRangeScalar(0, 1024), | 177 y = rand.nextRangeScalar(0, 1024), |
| 178 w = rand.nextRangeScalar(0, 128), | 178 w = rand.nextRangeScalar(0, 128), |
| 179 h = rand.nextRangeScalar(0, 128); | 179 h = rand.nextRangeScalar(0, 128); |
| 180 SkPaint paint; | 180 SkPaint paint; |
| 181 paint.setColor(rand.nextU()); | 181 paint.setColor(rand.nextU()); |
| 182 paint.setAlpha(0xFF); | 182 paint.setAlpha(0xFF); |
| 183 canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint); | 183 canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint); |
| 184 } | 184 } |
| 185 fPic.reset(recorder.endRecording()); | 185 fPic.reset(recorder.endRecording()); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 188 void onDraw(const int loops, SkCanvas* canvas) override { |
| 189 for (int i = 0; i < loops; i++) { | 189 for (int i = 0; i < loops; i++) { |
| 190 // This inner loop guarantees we make the same choices for all bench
variants. | 190 // This inner loop guarantees we make the same choices for all bench
variants. |
| 191 SkRandom rand; | 191 SkRandom rand; |
| 192 for (int j = 0; j < 10; j++) { | 192 for (int j = 0; j < 10; j++) { |
| 193 SkScalar x = 0, y = 0; | 193 SkScalar x = 0, y = 0; |
| 194 switch (fMode) { | 194 switch (fMode) { |
| 195 case kTiled: x = SkScalar(256 * rand.nextULessThan(4)); | 195 case kTiled: x = SkScalar(256 * rand.nextULessThan(4)); |
| 196 y = SkScalar(256 * rand.nextULessThan(4)); | 196 y = SkScalar(256 * rand.nextULessThan(4)); |
| 197 break; | 197 break; |
| 198 case kRandom: x = rand.nextRangeScalar(0, 768); | 198 case kRandom: x = rand.nextRangeScalar(0, 768); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 210 BBH fBBH; | 210 BBH fBBH; |
| 211 Mode fMode; | 211 Mode fMode; |
| 212 SkString fName; | 212 SkString fName; |
| 213 SkAutoTUnref<SkPicture> fPic; | 213 SkAutoTUnref<SkPicture> fPic; |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) | 216 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) |
| 217 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); ) | 217 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); ) |
| 218 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); ) | 218 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); ) |
| 219 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); ) | 219 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); ) |
| OLD | NEW |