| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 /////////////////////////////////////////////////////////////////////////////// | 138 /////////////////////////////////////////////////////////////////////////////// |
| 139 | 139 |
| 140 DEF_BENCH( return new TextPlaybackBench(); ) | 140 DEF_BENCH( return new TextPlaybackBench(); ) |
| 141 DEF_BENCH( return new PosTextPlaybackBench(true); ) | 141 DEF_BENCH( return new PosTextPlaybackBench(true); ) |
| 142 DEF_BENCH( return new PosTextPlaybackBench(false); ) | 142 DEF_BENCH( return new PosTextPlaybackBench(false); ) |
| 143 | 143 |
| 144 // Chrome draws into small tiles with impl-side painting. | 144 // Chrome draws into small tiles with impl-side painting. |
| 145 // This benchmark measures the relative performance of our bounding-box hierarch
ies, | 145 // This benchmark measures the relative performance of our bounding-box hierarch
ies, |
| 146 // both when querying tiles perfectly and when not. | 146 // both when querying tiles perfectly and when not. |
| 147 enum BBH { kNone, kRTree, kTileGrid }; | 147 enum BBH { kNone, kRTree }; |
| 148 enum Mode { kTiled, kRandom }; | 148 enum Mode { kTiled, kRandom }; |
| 149 class TiledPlaybackBench : public Benchmark { | 149 class TiledPlaybackBench : public Benchmark { |
| 150 public: | 150 public: |
| 151 TiledPlaybackBench(BBH bbh, Mode mode) : fBBH(bbh), fMode(mode), fName("tile
d_playback") { | 151 TiledPlaybackBench(BBH bbh, Mode mode) : fBBH(bbh), fMode(mode), fName("tile
d_playback") { |
| 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 case kTileGrid: fName.append("_tilegrid"); break; | |
| 156 } | 155 } |
| 157 switch (fMode) { | 156 switch (fMode) { |
| 158 case kTiled: fName.append("_tiled" ); break; | 157 case kTiled: fName.append("_tiled" ); break; |
| 159 case kRandom: fName.append("_random"); break; | 158 case kRandom: fName.append("_random"); break; |
| 160 } | 159 } |
| 161 } | 160 } |
| 162 | 161 |
| 163 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } | 162 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } |
| 164 virtual SkIPoint onGetSize() SK_OVERRIDE { return SkIPoint::Make(1024,1024);
} | 163 virtual SkIPoint onGetSize() SK_OVERRIDE { return SkIPoint::Make(1024,1024);
} |
| 165 | 164 |
| 166 virtual void onPreDraw() SK_OVERRIDE { | 165 virtual void onPreDraw() SK_OVERRIDE { |
| 167 SkTileGridFactory::TileGridInfo info = { { 256, 256 }, {0,0}, {0,0} }; | |
| 168 SkAutoTDelete<SkBBHFactory> factory; | 166 SkAutoTDelete<SkBBHFactory> factory; |
| 169 switch (fBBH) { | 167 switch (fBBH) { |
| 170 case kNone: break; | 168 case kNone: break; |
| 171 case kRTree: factory.reset(new SkRTreeFactory); break; | 169 case kRTree: factory.reset(new SkRTreeFactory); break; |
| 172 case kTileGrid: factory.reset(new SkTileGridFactory(info)); break; | |
| 173 } | 170 } |
| 174 | 171 |
| 175 SkPictureRecorder recorder; | 172 SkPictureRecorder recorder; |
| 176 SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory); | 173 SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory); |
| 177 SkRandom rand; | 174 SkRandom rand; |
| 178 for (int i = 0; i < 10000; i++) { | 175 for (int i = 0; i < 10000; i++) { |
| 179 SkScalar x = rand.nextRangeScalar(0, 1024), | 176 SkScalar x = rand.nextRangeScalar(0, 1024), |
| 180 y = rand.nextRangeScalar(0, 1024), | 177 y = rand.nextRangeScalar(0, 1024), |
| 181 w = rand.nextRangeScalar(0, 128), | 178 w = rand.nextRangeScalar(0, 128), |
| 182 h = rand.nextRangeScalar(0, 128); | 179 h = rand.nextRangeScalar(0, 128); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 213 BBH fBBH; | 210 BBH fBBH; |
| 214 Mode fMode; | 211 Mode fMode; |
| 215 SkString fName; | 212 SkString fName; |
| 216 SkAutoTUnref<SkPicture> fPic; | 213 SkAutoTUnref<SkPicture> fPic; |
| 217 }; | 214 }; |
| 218 | 215 |
| 219 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) | 216 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) |
| 220 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); ) | 217 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); ) |
| 221 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); ) | 218 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); ) |
| 222 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); ) | 219 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); ) |
| 223 DEF_BENCH( return new TiledPlaybackBench(kTileGrid, kRandom); ) | |
| 224 DEF_BENCH( return new TiledPlaybackBench(kTileGrid, kTiled ); ) | |
| OLD | NEW |