blob: 25c552c5e06565933ae74f68f785a84b9dbd2aa0 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
bsalomon@google.com971d0c82011-08-19 17:22:05 +00007
mtklein@google.comc2897432013-09-10 19:23:38 +00008#include "BenchTimer.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +00009#include "ResultsWriter.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000010#include "SkBenchLogger.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000011#include "SkBenchmark.h"
robertphillips@google.com73672252013-08-29 12:40:26 +000012#include "SkBitmapDevice.h"
reed@android.combd700c32009-01-05 03:34:50 +000013#include "SkCanvas.h"
mtklein@google.com78d03792013-09-10 19:42:07 +000014#include "SkColorPriv.h"
sglez@google.com586db932013-07-24 17:24:23 +000015#include "SkCommandLineFlags.h"
reed@google.com1bc6c6a2014-02-04 14:02:44 +000016#include "SkData.h"
bsalomon@google.com82a7bfc2012-04-16 19:11:17 +000017#include "SkDeferredCanvas.h"
commit-bot@chromium.org6adce672014-02-03 14:48:17 +000018#include "SkGMBench.h"
reed@android.com3a859a02009-01-28 00:56:29 +000019#include "SkGraphics.h"
reed@android.comb398fe82009-01-07 11:47:57 +000020#include "SkImageEncoder.h"
mtklein@google.comc2897432013-09-10 19:23:38 +000021#include "SkOSFile.h"
reed@android.com6c924ad2009-03-31 03:48:49 +000022#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000023#include "SkPictureRecorder.h"
reed@android.combd700c32009-01-05 03:34:50 +000024#include "SkString.h"
reed@google.com1bc6c6a2014-02-04 14:02:44 +000025#include "SkSurface.h"
reed@android.com29348cb2009-08-04 18:17:15 +000026
djsollen@google.comdb490e92013-11-20 13:15:40 +000027#if SK_SUPPORT_GPU
28#include "GrContext.h"
29#include "GrContextFactory.h"
30#include "GrRenderTarget.h"
31#include "SkGpuDevice.h"
32#include "gl/GrGLDefines.h"
33#else
34class GrContext;
35#endif // SK_SUPPORT_GPU
36
mtklein@google.com9ef1d212013-09-13 20:39:50 +000037#include <limits>
38
mtklein@google.comc2897432013-09-10 19:23:38 +000039enum BenchMode {
40 kNormal_BenchMode,
41 kDeferred_BenchMode,
42 kDeferredSilent_BenchMode,
43 kRecord_BenchMode,
44 kPictureRecord_BenchMode
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +000045};
mtklein@google.comdbd41c82013-09-13 20:11:09 +000046const char* BenchMode_Name[] = {
47 "normal", "deferred", "deferredSilent", "record", "picturerecord"
48};
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000049
borenet@google.com4e061d32013-09-16 19:12:19 +000050static const char kDefaultsConfigStr[] = "defaults";
51
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +000052///////////////////////////////////////////////////////////////////////////////
53
reed@android.combd700c32009-01-05 03:34:50 +000054class Iter {
55public:
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000056 Iter() : fBenches(BenchRegistry::Head()), fGMs(skiagm::GMRegistry::Head()) {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000057
reed@android.combd700c32009-01-05 03:34:50 +000058 SkBenchmark* next() {
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000059 if (fBenches) {
60 BenchRegistry::Factory f = fBenches->factory();
61 fBenches = fBenches->next();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000062 return (*f)(NULL);
reed@android.combd700c32009-01-05 03:34:50 +000063 }
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000064
65 while (fGMs) {
66 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
67 fGMs = fGMs->next();
68 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
69 return SkNEW_ARGS(SkGMBench, (gm.detach()));
70 }
71 }
72
reed@android.combd700c32009-01-05 03:34:50 +000073 return NULL;
74 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +000075
reed@android.combd700c32009-01-05 03:34:50 +000076private:
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000077 const BenchRegistry* fBenches;
78 const skiagm::GMRegistry* fGMs;
reed@android.combd700c32009-01-05 03:34:50 +000079};
80
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000081class AutoPrePostDraw {
82public:
83 AutoPrePostDraw(SkBenchmark* bench) : fBench(bench) {
84 fBench->preDraw();
85 }
86 ~AutoPrePostDraw() {
87 fBench->postDraw();
88 }
89private:
90 SkBenchmark* fBench;
91};
92
reed@android.combd700c32009-01-05 03:34:50 +000093static void make_filename(const char name[], SkString* path) {
94 path->set(name);
95 for (int i = 0; name[i]; i++) {
96 switch (name[i]) {
97 case '/':
98 case '\\':
99 case ' ':
100 case ':':
101 path->writable_str()[i] = '-';
102 break;
103 default:
104 break;
105 }
106 }
107}
108
reed@android.com4c7d3d62009-01-21 03:15:13 +0000109static void saveFile(const char name[], const char config[], const char dir[],
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000110 const SkImage* image) {
111 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100));
112 if (NULL == data.get()) {
reed@android.com4c7d3d62009-01-21 03:15:13 +0000113 return;
114 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000115
mtklein@google.comc2897432013-09-10 19:23:38 +0000116 SkString filename;
117 make_filename(name, &filename);
118 filename.appendf("_%s.png", config);
119 SkString path = SkOSPath::SkPathJoin(dir, filename.c_str());
120 ::remove(path.c_str());
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000121
reed@google.comace13542014-02-06 22:00:58 +0000122 SkFILEWStream stream(path.c_str());
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000123 stream.write(data->data(), data->size());
reed@android.com4c7d3d62009-01-21 03:15:13 +0000124}
125
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000126static void perform_clip(SkCanvas* canvas, int w, int h) {
reed@android.com4c7d3d62009-01-21 03:15:13 +0000127 SkRect r;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000128
reed@android.com4c7d3d62009-01-21 03:15:13 +0000129 r.set(SkIntToScalar(10), SkIntToScalar(10),
130 SkIntToScalar(w*2/3), SkIntToScalar(h*2/3));
131 canvas->clipRect(r, SkRegion::kIntersect_Op);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000132
reed@android.com4c7d3d62009-01-21 03:15:13 +0000133 r.set(SkIntToScalar(w/3), SkIntToScalar(h/3),
134 SkIntToScalar(w-10), SkIntToScalar(h-10));
135 canvas->clipRect(r, SkRegion::kXOR_Op);
136}
137
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000138static void perform_rotate(SkCanvas* canvas, int w, int h) {
reed@android.com4c7d3d62009-01-21 03:15:13 +0000139 const SkScalar x = SkIntToScalar(w) / 2;
140 const SkScalar y = SkIntToScalar(h) / 2;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000141
reed@android.com4c7d3d62009-01-21 03:15:13 +0000142 canvas->translate(x, y);
143 canvas->rotate(SkIntToScalar(35));
144 canvas->translate(-x, -y);
145}
146
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000147static void perform_scale(SkCanvas* canvas, int w, int h) {
reed@android.com387359e2009-08-04 01:51:09 +0000148 const SkScalar x = SkIntToScalar(w) / 2;
149 const SkScalar y = SkIntToScalar(h) / 2;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000150
reed@android.com387359e2009-08-04 01:51:09 +0000151 canvas->translate(x, y);
152 // just enough so we can't take the sprite case
153 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100);
154 canvas->translate(-x, -y);
155}
156
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000157static SkSurface* make_surface(SkColorType colorType, const SkIPoint& size,
158 SkBenchmark::Backend backend, int sampleCount,
159 GrContext* context) {
160 SkSurface* surface = NULL;
161 SkImageInfo info = SkImageInfo::Make(size.fX, size.fY, colorType,
162 kPremul_SkAlphaType);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000163
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000164 switch (backend) {
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000165 case SkBenchmark::kRaster_Backend:
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000166 surface = SkSurface::NewRaster(info);
167 surface->getCanvas()->clear(SK_ColorWHITE);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000168 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000169#if SK_SUPPORT_GPU
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000170 case SkBenchmark::kGPU_Backend: {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000171 surface = SkSurface::NewRenderTarget(context, info, sampleCount);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000172 break;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000173 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000174#endif
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000175 case SkBenchmark::kPDF_Backend:
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000176 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000177 SkDEBUGFAIL("unsupported");
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000178 }
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000179 return surface;
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000180}
181
bsalomon@google.comcb265352013-02-22 16:13:16 +0000182#if SK_SUPPORT_GPU
183GrContextFactory gContextFactory;
184typedef GrContextFactory::GLContextType GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000185static const GLContextType kNative = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orge8989572014-01-26 20:51:00 +0000186static const GLContextType kNVPR = GrContextFactory::kNVPR_GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000187#if SK_ANGLE
188static const GLContextType kANGLE = GrContextFactory::kANGLE_GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000189#endif
190static const GLContextType kDebug = GrContextFactory::kDebug_GLContextType;
191static const GLContextType kNull = GrContextFactory::kNull_GLContextType;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000192#else
193typedef int GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000194static const GLContextType kNative = 0, kANGLE = 0, kDebug = 0, kNull = 0;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000195#endif
196
mtklein@google.comc2897432013-09-10 19:23:38 +0000197#ifdef SK_DEBUG
198static const bool kIsDebug = true;
199#else
200static const bool kIsDebug = false;
201#endif
202
203static const struct Config {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000204 SkColorType fColorType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000205 const char* name;
206 int sampleCount;
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000207 SkBenchmark::Backend backend;
mtklein@google.comc2897432013-09-10 19:23:38 +0000208 GLContextType contextType;
209 bool runByDefault;
reed@android.com4bc19832009-01-19 20:08:35 +0000210} gConfigs[] = {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000211 { kN32_SkColorType, "NONRENDERING", 0, SkBenchmark::kNonRendering_Backend, kNative, true},
212 { kN32_SkColorType, "8888", 0, SkBenchmark::kRaster_Backend, kNative, true},
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000213 { kRGB_565_SkColorType, "565", 0, SkBenchmark::kRaster_Backend, kNative, true},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000214#if SK_SUPPORT_GPU
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000215 { kN32_SkColorType, "GPU", 0, SkBenchmark::kGPU_Backend, kNative, true},
216 { kN32_SkColorType, "MSAA4", 4, SkBenchmark::kGPU_Backend, kNative, false},
217 { kN32_SkColorType, "MSAA16", 16, SkBenchmark::kGPU_Backend, kNative, false},
218 { kN32_SkColorType, "NVPRMSAA4", 4, SkBenchmark::kGPU_Backend, kNVPR, true},
219 { kN32_SkColorType, "NVPRMSAA16", 16, SkBenchmark::kGPU_Backend, kNVPR, false},
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +0000220#if SK_ANGLE
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000221 { kN32_SkColorType, "ANGLE", 0, SkBenchmark::kGPU_Backend, kANGLE, true},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000222#endif // SK_ANGLE
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000223 { kN32_SkColorType, "Debug", 0, SkBenchmark::kGPU_Backend, kDebug, kIsDebug},
224 { kN32_SkColorType, "NULLGPU", 0, SkBenchmark::kGPU_Backend, kNull, true},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000225#endif // SK_SUPPORT_GPU
reed@android.com4bc19832009-01-19 20:08:35 +0000226};
227
mtklein@google.comc2897432013-09-10 19:23:38 +0000228DEFINE_string(outDir, "", "If given, image of each bench will be put in outDir.");
229DEFINE_string(timers, "cg", "Timers to display. "
230 "Options: w(all) W(all, truncated) c(pu) C(pu, truncated) g(pu)");
reed@android.com4c7d3d62009-01-21 03:15:13 +0000231
mtklein@google.comc2897432013-09-10 19:23:38 +0000232DEFINE_bool(rotate, false, "Rotate canvas before bench run?");
233DEFINE_bool(scale, false, "Scale canvas before bench run?");
234DEFINE_bool(clip, false, "Clip canvas before bench run?");
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000235
mtklein@google.comc2897432013-09-10 19:23:38 +0000236DEFINE_bool(forceAA, true, "Force anti-aliasing?");
237DEFINE_bool(forceFilter, false, "Force bitmap filtering?");
238DEFINE_string(forceDither, "default", "Force dithering: true, false, or default?");
239DEFINE_bool(forceBlend, false, "Force alpha blending?");
240
241DEFINE_int32(gpuCacheBytes, -1, "GPU cache size limit in bytes. 0 to disable cache.");
242DEFINE_int32(gpuCacheCount, -1, "GPU cache size limit in object count. 0 to disable cache.");
243
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +0000244DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
mtklein@google.comc2897432013-09-10 19:23:38 +0000245DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
246 "Multiple matches may be separated by spaces.\n"
247 "~ causes a matching test to always be skipped\n"
248 "^ requires the start of the test to match\n"
249 "$ requires the end of the test to match\n"
250 "^ and $ requires an exact match\n"
251 "If a test does not match any list entry,\n"
252 "it is skipped unless some list entry starts with ~\n");
253DEFINE_string(mode, "normal",
254 "normal: draw to a normal canvas;\n"
255 "deferred: draw to a deferred canvas;\n"
256 "deferredSilent: deferred with silent playback;\n"
257 "record: draw to an SkPicture;\n"
258 "picturerecord: draw from an SkPicture to an SkPicture.\n");
borenet@google.com4e061d32013-09-16 19:12:19 +0000259DEFINE_string(config, kDefaultsConfigStr,
260 "Run configs given. By default, runs the configs marked \"runByDefault\" in gConfigs.");
mtklein@google.comc2897432013-09-10 19:23:38 +0000261DEFINE_string(logFile, "", "Also write stdout here.");
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000262DEFINE_int32(minMs, 20, "Shortest time we'll allow a benchmark to run.");
263DEFINE_int32(maxMs, 4000, "Longest time we'll allow a benchmark to run.");
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000264DEFINE_bool(runOnce, kIsDebug, "Run each bench exactly once and don't report timings.");
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000265DEFINE_double(error, 0.01,
266 "Ratio of subsequent bench measurements must drop within 1±error to converge.");
mtklein@google.comc2897432013-09-10 19:23:38 +0000267DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops.");
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000268DEFINE_bool2(verbose, v, false, "Print more.");
tfarina@chromium.org725a64c2013-12-31 14:29:52 +0000269DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
commit-bot@chromium.org61744ec2014-05-16 13:15:41 +0000270#ifdef SK_BUILD_JSON_WRITER
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000271DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format.");
commit-bot@chromium.org61744ec2014-05-16 13:15:41 +0000272#endif
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000273DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done.");
274
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000275// Has this bench converged? First arguments are milliseconds / loop iteration,
276// last is overall runtime in milliseconds.
277static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) {
278 if (currRaw < FLAGS_minMs) {
279 return false;
280 }
281 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error;
282 const double ratio = currPerLoop / prevPerLoop;
283 return low < ratio && ratio < high;
284}
tomhudson@google.com86bb9b72012-04-03 13:28:57 +0000285
caryclark@google.com5987f582012-10-02 18:33:14 +0000286int tool_main(int argc, char** argv);
287int tool_main(int argc, char** argv) {
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +0000288 SkCommandLineFlags::Parse(argc, argv);
bsalomon@google.com4e230682013-01-15 20:37:04 +0000289#if SK_ENABLE_INST_COUNT
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +0000290 if (FLAGS_leaks) {
291 gPrintInstCount = true;
292 }
bsalomon@google.com65a87cc2012-08-14 13:15:44 +0000293#endif
reed@android.com3a859a02009-01-28 00:56:29 +0000294 SkAutoGraphics ag;
bsalomon@google.com65a87cc2012-08-14 13:15:44 +0000295
mtklein@google.comc2897432013-09-10 19:23:38 +0000296 // First, parse some flags.
scroggo@google.com9a412522012-09-07 15:21:18 +0000297 SkBenchLogger logger;
mtklein@google.comc2897432013-09-10 19:23:38 +0000298 if (FLAGS_logFile.count()) {
299 logger.SetLogFile(FLAGS_logFile[0]);
300 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000301
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000302 LoggerResultsWriter logWriter(logger, FLAGS_timeFormat[0]);
303 MultiResultsWriter writer;
304 writer.add(&logWriter);
commit-bot@chromium.org61744ec2014-05-16 13:15:41 +0000305
306#ifdef SK_BUILD_JSON_WRITER
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000307 SkAutoTDelete<JSONResultsWriter> jsonWriter;
308 if (FLAGS_outResultsFile.count()) {
309 jsonWriter.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0])));
310 writer.add(jsonWriter.get());
311 }
commit-bot@chromium.org61744ec2014-05-16 13:15:41 +0000312#endif
313
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000314 // Instantiate after all the writers have been added to writer so that we
315 // call close() before their destructors are called on the way out.
316 CallEnd<MultiResultsWriter> ender(writer);
317
mtklein@google.comc2897432013-09-10 19:23:38 +0000318 const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF;
319 SkTriState::State dither = SkTriState::kDefault;
320 for (size_t i = 0; i < 3; i++) {
321 if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) {
322 dither = static_cast<SkTriState::State>(i);
reed@android.comb398fe82009-01-07 11:47:57 +0000323 }
324 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000325
326 BenchMode benchMode = kNormal_BenchMode;
327 for (size_t i = 0; i < SK_ARRAY_COUNT(BenchMode_Name); i++) {
328 if (strcmp(FLAGS_mode[0], BenchMode_Name[i]) == 0) {
329 benchMode = static_cast<BenchMode>(i);
330 }
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +0000331 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000332
333 SkTDArray<int> configs;
borenet@google.com4e061d32013-09-16 19:12:19 +0000334 bool runDefaultConfigs = false;
mtklein@google.comc2897432013-09-10 19:23:38 +0000335 // Try user-given configs first.
336 for (int i = 0; i < FLAGS_config.count(); i++) {
robertphillips@google.come9cd27d2013-10-16 17:48:11 +0000337 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++j) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000338 if (0 == strcmp(FLAGS_config[i], gConfigs[j].name)) {
339 *configs.append() = j;
borenet@google.com4e061d32013-09-16 19:12:19 +0000340 } else if (0 == strcmp(FLAGS_config[i], kDefaultsConfigStr)) {
341 runDefaultConfigs = true;
mtklein@google.comc2897432013-09-10 19:23:38 +0000342 }
343 }
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +0000344 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000345 // If there weren't any, fill in with defaults.
borenet@google.com4e061d32013-09-16 19:12:19 +0000346 if (runDefaultConfigs) {
robertphillips@google.come9cd27d2013-10-16 17:48:11 +0000347 for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000348 if (gConfigs[i].runByDefault) {
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000349 *configs.append() = i;
350 }
tomhudson@google.com13eaaaa2012-04-16 18:00:40 +0000351 }
352 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000353 // Filter out things we can't run.
354 if (kNormal_BenchMode != benchMode) {
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000355 // Non-rendering configs only run in normal mode
356 for (int i = 0; i < configs.count(); ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000357 const Config& config = gConfigs[configs[i]];
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000358 if (SkBenchmark::kNonRendering_Backend == config.backend) {
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000359 configs.remove(i, 1);
360 --i;
361 }
362 }
363 }
scroggo@google.com111fd112013-09-25 21:42:12 +0000364 // Set the resource path.
365 if (!FLAGS_resourcePath.isEmpty()) {
366 SkBenchmark::SetResourcePath(FLAGS_resourcePath[0]);
367 }
368
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000369#if SK_SUPPORT_GPU
370 for (int i = 0; i < configs.count(); ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000371 const Config& config = gConfigs[configs[i]];
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000372
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000373 if (SkBenchmark::kGPU_Backend == config.backend) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000374 GrContext* context = gContextFactory.get(config.contextType);
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000375 if (NULL == context) {
commit-bot@chromium.org0f298cc2014-04-30 15:54:29 +0000376 SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n",
377 config.name);
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000378 configs.remove(i);
379 --i;
380 continue;
381 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000382 if (config.sampleCount > context->getMaxSampleCount()){
commit-bot@chromium.org0f298cc2014-04-30 15:54:29 +0000383 SkDebugf(
384 "Sample count (%d) for config %s is not supported. Config will be skipped.\n",
385 config.sampleCount, config.name);
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000386 configs.remove(i);
387 --i;
388 continue;
389 }
390 }
391 }
392#endif
393
mtklein@google.comc2897432013-09-10 19:23:38 +0000394 // All flags should be parsed now. Report our settings.
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000395 if (FLAGS_runOnce) {
396 logger.logError("bench was run with --runOnce, so we're going to hide the times."
397 " It's for your own good!\n");
mtklein@google.comc2897432013-09-10 19:23:38 +0000398 }
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000399 writer.option("mode", FLAGS_mode[0]);
400 writer.option("alpha", SkStringPrintf("0x%02X", alpha).c_str());
401 writer.option("antialias", SkStringPrintf("%d", FLAGS_forceAA).c_str());
402 writer.option("filter", SkStringPrintf("%d", FLAGS_forceFilter).c_str());
403 writer.option("dither", SkTriState::Name[dither]);
404
405 writer.option("rotate", SkStringPrintf("%d", FLAGS_rotate).c_str());
406 writer.option("scale", SkStringPrintf("%d", FLAGS_scale).c_str());
407 writer.option("clip", SkStringPrintf("%d", FLAGS_clip).c_str());
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000408
bungeman@google.coma5d48412011-06-15 17:25:46 +0000409#if defined(SK_BUILD_FOR_WIN32)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000410 writer.option("system", "WIN32");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000411#elif defined(SK_BUILD_FOR_MAC)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000412 writer.option("system", "MAC");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000413#elif defined(SK_BUILD_FOR_ANDROID)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000414 writer.option("system", "ANDROID");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000415#elif defined(SK_BUILD_FOR_UNIX)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000416 writer.option("system", "UNIX");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000417#else
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000418 writer.option("system", "other");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000419#endif
420
421#if defined(SK_DEBUG)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000422 writer.option("build", "DEBUG");
423#else
424 writer.option("build", "RELEASE");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000425#endif
mtklein@google.comc2897432013-09-10 19:23:38 +0000426
427 // Set texture cache limits if non-default.
bsalomon@google.com5c90e292013-02-22 19:17:13 +0000428 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
bsalomon@google.comcb265352013-02-22 16:13:16 +0000429#if SK_SUPPORT_GPU
mtklein@google.comc2897432013-09-10 19:23:38 +0000430 const Config& config = gConfigs[i];
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000431 if (SkBenchmark::kGPU_Backend != config.backend) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000432 continue;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000433 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000434 GrContext* context = gContextFactory.get(config.contextType);
435 if (NULL == context) {
436 continue;
437 }
438
439 size_t bytes;
440 int count;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000441 context->getResourceCacheLimits(&count, &bytes);
mtklein@google.comc2897432013-09-10 19:23:38 +0000442 if (-1 != FLAGS_gpuCacheBytes) {
443 bytes = static_cast<size_t>(FLAGS_gpuCacheBytes);
444 }
445 if (-1 != FLAGS_gpuCacheCount) {
446 count = FLAGS_gpuCacheCount;
447 }
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000448 context->setResourceCacheLimits(count, bytes);
bsalomon@google.comcb265352013-02-22 16:13:16 +0000449#endif
450 }
bsalomon@google.com74913722011-10-27 20:44:19 +0000451
mtklein@google.comc2897432013-09-10 19:23:38 +0000452 // Run each bench in each configuration it supports and we asked for.
453 Iter iter;
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000454 SkBenchmark* bench;
reed@android.combd700c32009-01-05 03:34:50 +0000455 while ((bench = iter.next()) != NULL) {
bsalomon@google.com7fbc6042012-08-13 22:10:05 +0000456 SkAutoTUnref<SkBenchmark> benchUnref(bench);
mtklein@google.comc2897432013-09-10 19:23:38 +0000457 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
reed@android.comb398fe82009-01-07 11:47:57 +0000458 continue;
459 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000460
mtklein@google.comc2897432013-09-10 19:23:38 +0000461 bench->setForceAlpha(alpha);
462 bench->setForceAA(FLAGS_forceAA);
463 bench->setForceFilter(FLAGS_forceFilter);
464 bench->setDither(dither);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000465 AutoPrePostDraw appd(bench);
466
mtklein@google.comc2897432013-09-10 19:23:38 +0000467 bool loggedBenchName = false;
468 for (int i = 0; i < configs.count(); ++i) {
469 const int configIndex = configs[i];
470 const Config& config = gConfigs[configIndex];
tomhudson@google.com13eaaaa2012-04-16 18:00:40 +0000471
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000472 if (!bench->isSuitableFor(config.backend)) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000473 continue;
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000474 }
475
bsalomon@google.comcb265352013-02-22 16:13:16 +0000476 GrContext* context = NULL;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000477#if SK_SUPPORT_GPU
sugoi@google.com9c55f802013-03-07 20:52:59 +0000478 SkGLContextHelper* glContext = NULL;
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000479 if (SkBenchmark::kGPU_Backend == config.backend) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000480 context = gContextFactory.get(config.contextType);
bsalomon@google.comcb265352013-02-22 16:13:16 +0000481 if (NULL == context) {
482 continue;
483 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000484 glContext = gContextFactory.getGLContext(config.contextType);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000485 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000486#endif
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000487
mtklein@google.comc2897432013-09-10 19:23:38 +0000488 SkAutoTUnref<SkCanvas> canvas;
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000489 SkAutoTUnref<SkPicture> recordFrom;
490 SkPictureRecorder recorderTo;
mtklein@google.comc2897432013-09-10 19:23:38 +0000491 const SkIPoint dim = bench->getSize();
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000492
mtklein@google.comc2897432013-09-10 19:23:38 +0000493 const SkPicture::RecordingFlags kRecordFlags =
494 SkPicture::kUsePathBoundsForClip_RecordingFlag;
495
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000496 SkAutoTUnref<SkSurface> surface;
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000497 if (SkBenchmark::kNonRendering_Backend != config.backend) {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000498 surface.reset(make_surface(config.fColorType,
499 dim,
500 config.backend,
501 config.sampleCount,
502 context));
503 if (!surface.get()) {
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000504 logger.logError(SkStringPrintf(
505 "Device creation failure for config %s. Will skip.\n", config.name));
mtklein@google.comc2897432013-09-10 19:23:38 +0000506 continue;
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +0000507 }
junov@chromium.orgfb103892012-09-20 19:35:43 +0000508
mtklein@google.comc2897432013-09-10 19:23:38 +0000509 switch(benchMode) {
510 case kDeferredSilent_BenchMode:
511 case kDeferred_BenchMode:
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000512 canvas.reset(SkDeferredCanvas::Create(surface.get()));
mtklein@google.comc2897432013-09-10 19:23:38 +0000513 break;
514 case kRecord_BenchMode:
skia.committer@gmail.com60bd7512014-04-18 03:03:54 +0000515 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY,
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +0000516 NULL, kRecordFlags)));
mtklein@google.comc2897432013-09-10 19:23:38 +0000517 break;
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000518 case kPictureRecord_BenchMode: {
519 SkPictureRecorder recorderFrom;
skia.committer@gmail.com60bd7512014-04-18 03:03:54 +0000520 bench->draw(1, recorderFrom.beginRecording(dim.fX, dim.fY,
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +0000521 NULL, kRecordFlags));
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000522 recordFrom.reset(recorderFrom.endRecording());
skia.committer@gmail.com60bd7512014-04-18 03:03:54 +0000523 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY,
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +0000524 NULL, kRecordFlags)));
mtklein@google.comc2897432013-09-10 19:23:38 +0000525 break;
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000526 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000527 case kNormal_BenchMode:
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000528 canvas.reset(SkRef(surface->getCanvas()));
mtklein@google.comc2897432013-09-10 19:23:38 +0000529 break;
530 default:
531 SkASSERT(false);
532 }
533 }
534
535 if (NULL != canvas) {
536 canvas->clear(SK_ColorWHITE);
skia.committer@gmail.com51997012014-04-14 03:04:57 +0000537 if (FLAGS_clip) {
538 perform_clip(canvas, dim.fX, dim.fY);
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000539 }
skia.committer@gmail.com51997012014-04-14 03:04:57 +0000540 if (FLAGS_scale) {
541 perform_scale(canvas, dim.fX, dim.fY);
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000542 }
skia.committer@gmail.com51997012014-04-14 03:04:57 +0000543 if (FLAGS_rotate) {
544 perform_rotate(canvas, dim.fX, dim.fY);
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000545 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000546 }
547
548 if (!loggedBenchName) {
549 loggedBenchName = true;
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000550 writer.bench(bench->getName(), dim.fX, dim.fY);
mtklein@google.comc2897432013-09-10 19:23:38 +0000551 }
552
553#if SK_SUPPORT_GPU
554 SkGLContextHelper* contextHelper = NULL;
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000555 if (SkBenchmark::kGPU_Backend == config.backend) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000556 contextHelper = gContextFactory.getGLContext(config.contextType);
557 }
558 BenchTimer timer(contextHelper);
559#else
560 BenchTimer timer;
561#endif
562
mtklein@google.com9ef1d212013-09-13 20:39:50 +0000563 double previous = std::numeric_limits<double>::infinity();
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000564 bool converged = false;
djsollen@google.com70de4da2013-10-10 17:33:39 +0000565
566 // variables used to compute loopsPerFrame
567 double frameIntervalTime = 0.0f;
568 int frameIntervalTotalLoops = 0;
569
570 bool frameIntervalComputed = false;
571 int loopsPerFrame = 0;
572 int loopsPerIter = 0;
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000573 if (FLAGS_verbose) { SkDebugf("%s %s: ", bench->getName(), config.name); }
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000574 if (!FLAGS_dryRun) {
575 do {
576 // Ramp up 1 -> 2 -> 4 -> 8 -> 16 -> ... -> ~1 billion.
577 loopsPerIter = (loopsPerIter == 0) ? 1 : loopsPerIter * 2;
578 if (loopsPerIter >= (1<<30) || timer.fWall > FLAGS_maxMs) {
579 // If you find it takes more than a billion loops to get up to 20ms of runtime,
580 // you've got a computer clocked at several THz or have a broken benchmark. ;)
581 // "1B ought to be enough for anybody."
582 logger.logError(SkStringPrintf(
583 "\nCan't get %s %s to converge in %dms (%d loops)",
584 bench->getName(), config.name, FLAGS_maxMs, loopsPerIter));
585 break;
djsollen@google.com70de4da2013-10-10 17:33:39 +0000586 }
587
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000588 if ((benchMode == kRecord_BenchMode || benchMode == kPictureRecord_BenchMode)) {
589 // Clear the recorded commands so that they do not accumulate.
skia.committer@gmail.com60bd7512014-04-18 03:03:54 +0000590 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY,
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +0000591 NULL, kRecordFlags)));
djsollen@google.com70de4da2013-10-10 17:33:39 +0000592 }
593
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000594 timer.start();
595 // Inner loop that allows us to break the run into smaller
596 // chunks (e.g. frames). This is especially useful for the GPU
597 // as we can flush and/or swap buffers to keep the GPU from
598 // queuing up too much work.
599 for (int loopCount = loopsPerIter; loopCount > 0; ) {
600 // Save and restore around each call to draw() to guarantee a pristine canvas.
601 SkAutoCanvasRestore saveRestore(canvas, true/*also save*/);
djsollen@google.com70de4da2013-10-10 17:33:39 +0000602
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000603 int loops;
604 if (frameIntervalComputed && loopCount > loopsPerFrame) {
605 loops = loopsPerFrame;
606 loopCount -= loopsPerFrame;
607 } else {
608 loops = loopCount;
609 loopCount = 0;
djsollen@google.com70de4da2013-10-10 17:33:39 +0000610 }
djsollen@google.comdcfed6c2013-10-10 18:48:27 +0000611
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000612 if (benchMode == kPictureRecord_BenchMode) {
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000613 recordFrom->draw(canvas);
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000614 } else {
615 bench->draw(loops, canvas);
616 }
617
618 if (kDeferredSilent_BenchMode == benchMode) {
619 static_cast<SkDeferredCanvas*>(canvas.get())->silentFlush();
620 } else if (NULL != canvas) {
621 canvas->flush();
622 }
623
624 #if SK_SUPPORT_GPU
625 // swap drawing buffers on each frame to prevent the GPU
626 // from queuing up too much work
627 if (NULL != glContext) {
628 glContext->swapBuffers();
629 }
630 #endif
631 }
632
633
634
635 // Stop truncated timers before GL calls complete, and stop the full timers after.
636 timer.truncatedEnd();
637 #if SK_SUPPORT_GPU
638 if (NULL != glContext) {
639 context->flush();
640 SK_GL(*glContext, Finish());
641 }
642 #endif
643 timer.end();
644
645 // setup the frame interval for subsequent iterations
646 if (!frameIntervalComputed) {
647 frameIntervalTime += timer.fWall;
648 frameIntervalTotalLoops += loopsPerIter;
649 if (frameIntervalTime >= FLAGS_minMs) {
650 frameIntervalComputed = true;
651 loopsPerFrame =
652 (int)(((double)frameIntervalTotalLoops / frameIntervalTime) * FLAGS_minMs);
653 if (loopsPerFrame < 1) {
654 loopsPerFrame = 1;
655 }
656 // SkDebugf(" %s has %d loops in %f ms (normalized to %d)\n",
657 // bench->getName(), frameIntervalTotalLoops,
658 // timer.fWall, loopsPerFrame);
659 }
660 }
661
662 const double current = timer.fWall / loopsPerIter;
663 if (FLAGS_verbose && current > previous) { SkDebugf("↑"); }
664 if (FLAGS_verbose) { SkDebugf("%.3g ", current); }
665 converged = HasConverged(previous, current, timer.fWall);
666 previous = current;
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000667 } while (!FLAGS_runOnce && !converged);
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000668 }
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000669 if (FLAGS_verbose) { SkDebugf("\n"); }
mtklein@google.comc2897432013-09-10 19:23:38 +0000670
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000671 if (!FLAGS_dryRun && FLAGS_outDir.count() && SkBenchmark::kNonRendering_Backend != config.backend) {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000672 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
673 if (image.get()) {
674 saveFile(bench->getName(), config.name, FLAGS_outDir[0],
675 image);
676 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000677 }
678
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000679 if (FLAGS_runOnce) {
680 // Let's not mislead ourselves by looking at Debug build or single iteration bench times!
mtklein@google.comc2897432013-09-10 19:23:38 +0000681 continue;
682 }
683
684 // Normalize to ms per 1000 iterations.
djsollen@google.com70de4da2013-10-10 17:33:39 +0000685 const double normalize = 1000.0 / loopsPerIter;
mtklein@google.comc2897432013-09-10 19:23:38 +0000686 const struct { char shortName; const char* longName; double ms; } times[] = {
687 {'w', "msecs", normalize * timer.fWall},
688 {'W', "Wmsecs", normalize * timer.fTruncatedWall},
689 {'c', "cmsecs", normalize * timer.fCpu},
690 {'C', "Cmsecs", normalize * timer.fTruncatedCpu},
691 {'g', "gmsecs", normalize * timer.fGpu},
692 };
693
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000694 writer.config(config.name);
mtklein@google.comc2897432013-09-10 19:23:38 +0000695 for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) {
696 if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) {
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000697 writer.timer(times[i].longName, times[i].ms);
commit-bot@chromium.org7495f592013-06-03 19:31:07 +0000698 }
reed@google.com25df8882011-07-14 19:03:58 +0000699 }
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000700 }
reed@android.combd700c32009-01-05 03:34:50 +0000701 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000702#if SK_SUPPORT_GPU
bsalomon@google.comcb265352013-02-22 16:13:16 +0000703 gContextFactory.destroyContexts();
robertphillips@google.com9d594202012-09-13 14:05:00 +0000704#endif
reed@android.combd700c32009-01-05 03:34:50 +0000705 return 0;
706}
caryclark@google.com5987f582012-10-02 18:33:14 +0000707
borenet@google.com7158e6a2012-11-01 17:43:44 +0000708#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +0000709int main(int argc, char * const argv[]) {
710 return tool_main(argc, (char**) argv);
711}
712#endif