2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-08-19 17:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "BenchTimer.h"
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-08-19 17:22:05 +00:00
|
|
|
#include "GrContext.h"
|
2013-02-22 16:13:16 +00:00
|
|
|
#include "GrContextFactory.h"
|
2013-02-07 19:45:46 +00:00
|
|
|
#include "gl/GrGLDefines.h"
|
2011-08-19 17:22:05 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2012-08-02 14:03:32 +00:00
|
|
|
#include "SkGpuDevice.h"
|
2013-02-22 16:25:28 +00:00
|
|
|
#else
|
|
|
|
class GrContext;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
2011-08-19 17:22:05 +00:00
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "SkBenchLogger.h"
|
2011-08-19 17:22:05 +00:00
|
|
|
#include "SkBenchmark.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
#include "SkCanvas.h"
|
2012-04-16 19:11:17 +00:00
|
|
|
#include "SkDeferredCanvas.h"
|
2012-08-07 18:00:31 +00:00
|
|
|
#include "SkDevice.h"
|
2009-01-26 23:15:37 +00:00
|
|
|
#include "SkColorPriv.h"
|
2009-01-28 00:56:29 +00:00
|
|
|
#include "SkGraphics.h"
|
2009-01-07 11:47:57 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2009-03-31 03:48:49 +00:00
|
|
|
#include "SkNWayCanvas.h"
|
|
|
|
#include "SkPicture.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
#include "SkString.h"
|
2013-02-22 16:25:28 +00:00
|
|
|
#include "SkTArray.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "TimerData.h"
|
2009-08-04 18:17:15 +00:00
|
|
|
|
2012-07-20 23:03:42 +00:00
|
|
|
enum benchModes {
|
|
|
|
kNormal_benchModes,
|
|
|
|
kDeferred_benchModes,
|
2012-09-20 19:35:43 +00:00
|
|
|
kDeferredSilent_benchModes,
|
2012-07-20 23:03:42 +00:00
|
|
|
kRecord_benchModes,
|
|
|
|
kPictureRecord_benchModes
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-03-31 03:48:49 +00:00
|
|
|
static void erase(SkBitmap& bm) {
|
|
|
|
if (bm.config() == SkBitmap::kA8_Config) {
|
2012-12-06 21:47:40 +00:00
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
2009-03-31 03:48:49 +00:00
|
|
|
} else {
|
|
|
|
bm.eraseColor(SK_ColorWHITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-17 02:25:05 +00:00
|
|
|
#if 0
|
2009-03-31 03:48:49 +00:00
|
|
|
static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) {
|
|
|
|
if (bm1.width() != bm2.width() ||
|
|
|
|
bm1.height() != bm2.height() ||
|
|
|
|
bm1.config() != bm2.config()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-03-31 03:48:49 +00:00
|
|
|
size_t pixelBytes = bm1.width() * bm1.bytesPerPixel();
|
|
|
|
for (int y = 0; y < bm1.height(); y++) {
|
|
|
|
if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-05-17 02:25:05 +00:00
|
|
|
#endif
|
2009-03-31 03:48:49 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
class Iter {
|
|
|
|
public:
|
2009-09-02 21:12:42 +00:00
|
|
|
Iter(void* param) {
|
2009-01-05 03:34:50 +00:00
|
|
|
fBench = BenchRegistry::Head();
|
2009-09-02 21:12:42 +00:00
|
|
|
fParam = param;
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
SkBenchmark* next() {
|
|
|
|
if (fBench) {
|
|
|
|
BenchRegistry::Factory f = fBench->factory();
|
|
|
|
fBench = fBench->next();
|
2009-09-02 21:12:42 +00:00
|
|
|
return f(fParam);
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-05-18 18:37:07 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
private:
|
|
|
|
const BenchRegistry* fBench;
|
2009-09-02 21:12:42 +00:00
|
|
|
void* fParam;
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
2012-08-13 14:03:31 +00:00
|
|
|
class AutoPrePostDraw {
|
|
|
|
public:
|
|
|
|
AutoPrePostDraw(SkBenchmark* bench) : fBench(bench) {
|
|
|
|
fBench->preDraw();
|
|
|
|
}
|
|
|
|
~AutoPrePostDraw() {
|
|
|
|
fBench->postDraw();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkBenchmark* fBench;
|
|
|
|
};
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
static void make_filename(const char name[], SkString* path) {
|
|
|
|
path->set(name);
|
|
|
|
for (int i = 0; name[i]; i++) {
|
|
|
|
switch (name[i]) {
|
|
|
|
case '/':
|
|
|
|
case '\\':
|
|
|
|
case ' ':
|
|
|
|
case ':':
|
|
|
|
path->writable_str()[i] = '-';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-21 03:15:13 +00:00
|
|
|
static void saveFile(const char name[], const char config[], const char dir[],
|
|
|
|
const SkBitmap& bm) {
|
|
|
|
SkBitmap copy;
|
|
|
|
if (!bm.copyTo(©, SkBitmap::kARGB_8888_Config)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-26 23:15:37 +00:00
|
|
|
if (bm.config() == SkBitmap::kA8_Config) {
|
|
|
|
// turn alpha into gray-scale
|
|
|
|
size_t size = copy.getSize() >> 2;
|
|
|
|
SkPMColor* p = copy.getAddr32(0, 0);
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
int c = (*p >> SK_A32_SHIFT) & 0xFF;
|
|
|
|
c = 255 - c;
|
|
|
|
c |= (c << 24) | (c << 16) | (c << 8);
|
|
|
|
*p++ = c | (SK_A32_MASK << SK_A32_SHIFT);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-21 03:15:13 +00:00
|
|
|
SkString str;
|
|
|
|
make_filename(name, &str);
|
|
|
|
str.appendf("_%s.png", config);
|
|
|
|
str.prepend(dir);
|
|
|
|
::remove(str.c_str());
|
|
|
|
SkImageEncoder::EncodeFile(str.c_str(), copy, SkImageEncoder::kPNG_Type,
|
|
|
|
100);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void performClip(SkCanvas* canvas, int w, int h) {
|
|
|
|
SkRect r;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-21 03:15:13 +00:00
|
|
|
r.set(SkIntToScalar(10), SkIntToScalar(10),
|
|
|
|
SkIntToScalar(w*2/3), SkIntToScalar(h*2/3));
|
|
|
|
canvas->clipRect(r, SkRegion::kIntersect_Op);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-21 03:15:13 +00:00
|
|
|
r.set(SkIntToScalar(w/3), SkIntToScalar(h/3),
|
|
|
|
SkIntToScalar(w-10), SkIntToScalar(h-10));
|
|
|
|
canvas->clipRect(r, SkRegion::kXOR_Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void performRotate(SkCanvas* canvas, int w, int h) {
|
|
|
|
const SkScalar x = SkIntToScalar(w) / 2;
|
|
|
|
const SkScalar y = SkIntToScalar(h) / 2;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-21 03:15:13 +00:00
|
|
|
canvas->translate(x, y);
|
|
|
|
canvas->rotate(SkIntToScalar(35));
|
|
|
|
canvas->translate(-x, -y);
|
|
|
|
}
|
|
|
|
|
2009-08-04 01:51:09 +00:00
|
|
|
static void performScale(SkCanvas* canvas, int w, int h) {
|
|
|
|
const SkScalar x = SkIntToScalar(w) / 2;
|
|
|
|
const SkScalar y = SkIntToScalar(h) / 2;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-08-04 01:51:09 +00:00
|
|
|
canvas->translate(x, y);
|
|
|
|
// just enough so we can't take the sprite case
|
|
|
|
canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100);
|
|
|
|
canvas->translate(-x, -y);
|
|
|
|
}
|
|
|
|
|
2009-08-04 18:17:15 +00:00
|
|
|
static bool parse_bool_arg(char * const* argv, char* const* stop, bool* var) {
|
|
|
|
if (argv < stop) {
|
|
|
|
*var = atoi(*argv) != 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-17 02:25:05 +00:00
|
|
|
enum Backend {
|
2013-03-15 15:42:15 +00:00
|
|
|
kNonRendering_Backend,
|
2011-05-17 02:25:05 +00:00
|
|
|
kRaster_Backend,
|
|
|
|
kGPU_Backend,
|
|
|
|
kPDF_Backend,
|
|
|
|
};
|
|
|
|
|
|
|
|
static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size,
|
2013-03-19 13:58:55 +00:00
|
|
|
Backend backend, int sampleCount, GrContext* context) {
|
2011-05-17 02:25:05 +00:00
|
|
|
SkDevice* device = NULL;
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setConfig(config, size.fX, size.fY);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-05-17 02:25:05 +00:00
|
|
|
switch (backend) {
|
|
|
|
case kRaster_Backend:
|
|
|
|
bitmap.allocPixels();
|
|
|
|
erase(bitmap);
|
2013-02-22 16:13:16 +00:00
|
|
|
device = SkNEW_ARGS(SkDevice, (bitmap));
|
2011-05-17 02:25:05 +00:00
|
|
|
break;
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-02-22 16:13:16 +00:00
|
|
|
case kGPU_Backend: {
|
|
|
|
GrTextureDesc desc;
|
|
|
|
desc.fConfig = kSkia8888_GrPixelConfig;
|
|
|
|
desc.fFlags = kRenderTarget_GrTextureFlagBit;
|
|
|
|
desc.fWidth = size.fX;
|
|
|
|
desc.fHeight = size.fY;
|
2013-03-19 13:58:55 +00:00
|
|
|
desc.fSampleCnt = sampleCount;
|
2013-02-22 16:13:16 +00:00
|
|
|
SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0));
|
|
|
|
if (!texture) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
device = SkNEW_ARGS(SkGpuDevice, (context, texture.get()));
|
2011-05-17 02:25:05 +00:00
|
|
|
break;
|
2013-02-22 16:13:16 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-05-17 02:25:05 +00:00
|
|
|
case kPDF_Backend:
|
|
|
|
default:
|
|
|
|
SkASSERT(!"unsupported");
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2013-02-22 16:13:16 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContextFactory gContextFactory;
|
|
|
|
typedef GrContextFactory::GLContextType GLContextType;
|
|
|
|
static const GLContextType kDontCareGLCtxType = GrContextFactory::kNative_GLContextType;
|
|
|
|
#else
|
|
|
|
typedef int GLContextType;
|
|
|
|
static const GLContextType kDontCareGLCtxType = 0;
|
|
|
|
#endif
|
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
static const struct {
|
|
|
|
SkBitmap::Config fConfig;
|
|
|
|
const char* fName;
|
2013-03-19 13:58:55 +00:00
|
|
|
int fSampleCnt;
|
2011-05-17 02:25:05 +00:00
|
|
|
Backend fBackend;
|
2013-02-22 16:13:16 +00:00
|
|
|
GLContextType fContextType;
|
2013-03-19 13:58:55 +00:00
|
|
|
bool fRunByDefault;
|
2009-01-19 20:08:35 +00:00
|
|
|
} gConfigs[] = {
|
2013-03-19 13:58:55 +00:00
|
|
|
{ SkBitmap::kNo_Config, "NONRENDERING", 0, kNonRendering_Backend, kDontCareGLCtxType, true },
|
|
|
|
{ SkBitmap::kARGB_8888_Config, "8888", 0, kRaster_Backend, kDontCareGLCtxType, true },
|
|
|
|
{ SkBitmap::kRGB_565_Config, "565", 0, kRaster_Backend, kDontCareGLCtxType, true },
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-03-19 13:58:55 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, "GPU", 0, kGPU_Backend, GrContextFactory::kNative_GLContextType, true },
|
|
|
|
{ SkBitmap::kARGB_8888_Config, "MSAA4", 4, kGPU_Backend, GrContextFactory::kNative_GLContextType, false },
|
|
|
|
{ SkBitmap::kARGB_8888_Config, "MSAA16", 16, kGPU_Backend, GrContextFactory::kNative_GLContextType, false },
|
2012-03-28 16:19:11 +00:00
|
|
|
#if SK_ANGLE
|
2013-03-19 13:58:55 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, "ANGLE", 0, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, true },
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
2012-03-30 12:23:56 +00:00
|
|
|
#ifdef SK_DEBUG
|
2013-03-19 13:58:55 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, "Debug", 0, kGPU_Backend, GrContextFactory::kDebug_GLContextType, GR_DEBUG },
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_DEBUG
|
2013-03-19 13:58:55 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, "NULLGPU", 0, kGPU_Backend, GrContextFactory::kNull_GLContextType, true },
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
2009-01-19 20:08:35 +00:00
|
|
|
};
|
|
|
|
|
2009-01-21 03:15:13 +00:00
|
|
|
static int findConfig(const char config[]) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
|
|
|
|
if (!strcmp(config, gConfigs[i].fName)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-23 17:56:20 +00:00
|
|
|
static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
|
|
|
|
// FIXME: this duplicates the logic in skia_test.cpp, gmmain.cpp -- consolidate
|
|
|
|
int count = array.count();
|
|
|
|
size_t testLen = strlen(name);
|
|
|
|
bool anyExclude = count == 0;
|
|
|
|
for (int i = 0; i < array.count(); ++i) {
|
|
|
|
const char* matchName = array[i];
|
|
|
|
size_t matchLen = strlen(matchName);
|
|
|
|
bool matchExclude, matchStart, matchEnd;
|
|
|
|
if ((matchExclude = matchName[0] == '~')) {
|
|
|
|
anyExclude = true;
|
|
|
|
matchName++;
|
|
|
|
matchLen--;
|
|
|
|
}
|
|
|
|
if ((matchStart = matchName[0] == '^')) {
|
|
|
|
matchName++;
|
|
|
|
matchLen--;
|
|
|
|
}
|
|
|
|
if ((matchEnd = matchName[matchLen - 1] == '$')) {
|
|
|
|
matchLen--;
|
|
|
|
}
|
|
|
|
if (matchStart ? (!matchEnd || matchLen == testLen)
|
|
|
|
&& strncmp(name, matchName, matchLen) == 0
|
|
|
|
: matchEnd ? matchLen <= testLen
|
|
|
|
&& strncmp(name + testLen - matchLen, matchName, matchLen) == 0
|
|
|
|
: strstr(name, matchName) != 0) {
|
|
|
|
return matchExclude;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !anyExclude;
|
|
|
|
}
|
|
|
|
|
2012-04-03 13:28:57 +00:00
|
|
|
static void help() {
|
2013-03-19 13:58:55 +00:00
|
|
|
SkString configsStr;
|
|
|
|
static const size_t kConfigCount = SK_ARRAY_COUNT(gConfigs);
|
|
|
|
for (size_t i = 0; i < kConfigCount; ++i) {
|
|
|
|
configsStr.appendf("%s%s", gConfigs[i].fName, ((i == kConfigCount - 1) ? "" : "|"));
|
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
SkDebugf("Usage: bench [-o outDir] [--repeat nr] [--logPerIter] "
|
2012-09-12 19:27:11 +00:00
|
|
|
"[--timers [wcgWC]*] [--rotate]\n"
|
|
|
|
" [--scale] [--clip] [--min] [--forceAA 1|0] [--forceFilter 1|0]\n"
|
2013-03-11 20:22:15 +00:00
|
|
|
" [--forceDither 1|0] [--forceBlend 1|0]"
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
" [--gpuCacheSize <bytes> <count>]"
|
|
|
|
#endif
|
|
|
|
"\n"
|
|
|
|
" [--strokeWidth width] [--match name]\n"
|
|
|
|
" [--mode normal|deferred|deferredSilent|record|picturerecord]\n"
|
2013-03-19 13:58:55 +00:00
|
|
|
" [--config ");
|
|
|
|
SkDebugf("%s]\n", configsStr.c_str());
|
|
|
|
SkDebugf(" [-Dfoo bar] [--logFile filename] [-h|--help]");
|
2012-04-03 13:28:57 +00:00
|
|
|
SkDebugf("\n\n");
|
|
|
|
SkDebugf(" -o outDir : Image of each bench will be put in outDir.\n");
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --repeat nr : Each bench repeats for nr times.\n");
|
2013-03-04 16:41:06 +00:00
|
|
|
SkDebugf(" --logPerIter : "
|
2012-07-02 20:48:51 +00:00
|
|
|
"Log each repeat timer instead of mean, default is disabled.\n");
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --timers [wcgWC]* : "
|
2012-08-28 12:18:40 +00:00
|
|
|
"Display wall, cpu, gpu, truncated wall or truncated cpu time for each bench.\n");
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --rotate : Rotate before each bench runs.\n");
|
|
|
|
SkDebugf(" --scale : Scale before each bench runs.\n");
|
|
|
|
SkDebugf(" --clip : Clip before each bench runs.\n");
|
|
|
|
SkDebugf(" --min : Print the minimum times (instead of average).\n");
|
|
|
|
SkDebugf(" --forceAA 1|0 : "
|
2012-04-03 13:28:57 +00:00
|
|
|
"Enable/disable anti-aliased, default is enabled.\n");
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --forceFilter 1|0 : "
|
2012-04-03 13:28:57 +00:00
|
|
|
"Enable/disable bitmap filtering, default is disabled.\n");
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --forceDither 1|0 : "
|
2012-04-03 13:28:57 +00:00
|
|
|
"Enable/disable dithering, default is disabled.\n");
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --forceBlend 1|0 : "
|
2012-04-03 13:28:57 +00:00
|
|
|
"Enable/disable dithering, default is disabled.\n");
|
2013-03-11 20:22:15 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
SkDebugf(" --gpuCacheSize <bytes> <count>: "
|
|
|
|
"limits gpu cache to bytes size or object count.\n");
|
|
|
|
SkDebugf(" -1 for either value means use the default. 0 for either disables the cache.\n");
|
|
|
|
#endif
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --strokeWidth width : The width for path stroke.\n");
|
2013-05-10 15:16:13 +00:00
|
|
|
SkDebugf(" --match [~][^]substring[$] [...] of test name to run.\n"
|
|
|
|
" Multiple matches may be separated by spaces.\n"
|
|
|
|
" ~ causes a matching test to always be skipped\n"
|
|
|
|
" ^ requires the start of the test to match\n"
|
|
|
|
" $ requires the end of the test to match\n"
|
|
|
|
" ^ and $ requires an exact match\n"
|
|
|
|
" If a test does not match any list entry,\n"
|
|
|
|
" it is skipped unless some list entry starts with ~\n");
|
2012-09-20 19:35:43 +00:00
|
|
|
SkDebugf(" --mode normal|deferred|deferredSilent|record|picturerecord :\n"
|
|
|
|
" Run in the corresponding mode\n"
|
2012-07-20 23:03:42 +00:00
|
|
|
" normal, Use a normal canvas to draw to;\n"
|
|
|
|
" deferred, Use a deferrred canvas when drawing;\n"
|
2012-09-20 19:35:43 +00:00
|
|
|
" deferredSilent, deferred with silent playback;\n"
|
2012-07-20 23:03:42 +00:00
|
|
|
" record, Benchmark the time to record to an SkPicture;\n"
|
|
|
|
" picturerecord, Benchmark the time to do record from a \n"
|
|
|
|
" SkPicture to a SkPicture.\n");
|
2012-09-12 19:27:11 +00:00
|
|
|
SkDebugf(" --logFile filename : destination for writing log output, in addition to stdout.\n");
|
2013-03-19 13:58:55 +00:00
|
|
|
SkDebugf(" --config %s:\n", configsStr.c_str());
|
|
|
|
SkDebugf(" Run bench in corresponding config mode.\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
SkDebugf(" -Dfoo bar : Add extra definition to bench.\n");
|
|
|
|
SkDebugf(" -h|--help : Show this help message.\n");
|
|
|
|
}
|
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
2013-01-15 20:37:04 +00:00
|
|
|
#if SK_ENABLE_INST_COUNT
|
2012-08-14 13:15:44 +00:00
|
|
|
gPrintInstCount = true;
|
|
|
|
#endif
|
2009-01-28 00:56:29 +00:00
|
|
|
SkAutoGraphics ag;
|
2012-08-14 13:15:44 +00:00
|
|
|
|
2009-09-02 21:12:42 +00:00
|
|
|
SkTDict<const char*> defineDict(1024);
|
2009-01-19 20:08:35 +00:00
|
|
|
int repeatDraw = 1;
|
2012-07-02 20:48:51 +00:00
|
|
|
bool logPerIter = false;
|
2009-01-19 20:08:35 +00:00
|
|
|
int forceAlpha = 0xFF;
|
|
|
|
bool forceAA = true;
|
2009-08-04 18:17:15 +00:00
|
|
|
bool forceFilter = false;
|
2009-10-19 17:39:46 +00:00
|
|
|
SkTriState::State forceDither = SkTriState::kDefault;
|
2011-06-07 19:16:02 +00:00
|
|
|
bool timerWall = false;
|
2012-08-28 12:18:40 +00:00
|
|
|
bool truncatedTimerWall = false;
|
2011-06-07 19:16:02 +00:00
|
|
|
bool timerCpu = true;
|
2012-08-28 12:18:40 +00:00
|
|
|
bool truncatedTimerCpu = false;
|
2011-06-07 19:16:02 +00:00
|
|
|
bool timerGpu = true;
|
2009-08-04 01:51:09 +00:00
|
|
|
bool doScale = false;
|
2009-01-21 03:15:13 +00:00
|
|
|
bool doRotate = false;
|
|
|
|
bool doClip = false;
|
2012-08-23 17:50:06 +00:00
|
|
|
bool printMin = false;
|
2010-04-27 15:47:34 +00:00
|
|
|
bool hasStrokeWidth = false;
|
2013-03-11 20:22:15 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
struct {
|
2013-03-11 20:33:45 +00:00
|
|
|
int fBytes;
|
2013-03-11 20:22:15 +00:00
|
|
|
int fCount;
|
|
|
|
} gpuCacheSize = { -1, -1 }; // -1s mean use the default
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 15:47:34 +00:00
|
|
|
float strokeWidth;
|
2011-10-31 16:33:52 +00:00
|
|
|
SkTDArray<const char*> fMatches;
|
2012-07-20 23:03:42 +00:00
|
|
|
benchModes benchMode = kNormal_benchModes;
|
|
|
|
SkString perIterTimeformat("%.2f");
|
|
|
|
SkString normalTimeFormat("%6.2f");
|
|
|
|
|
2009-01-07 11:47:57 +00:00
|
|
|
SkString outDir;
|
2009-08-04 01:51:09 +00:00
|
|
|
SkBitmap::Config outConfig = SkBitmap::kNo_Config;
|
|
|
|
const char* configName = "";
|
2011-05-17 02:25:05 +00:00
|
|
|
Backend backend = kRaster_Backend; // for warning
|
2013-03-19 13:58:55 +00:00
|
|
|
int sampleCount = 0;
|
2012-04-16 18:00:40 +00:00
|
|
|
SkTDArray<int> configs;
|
|
|
|
bool userConfig = false;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
SkBenchLogger logger;
|
|
|
|
|
2009-01-07 11:47:57 +00:00
|
|
|
char* const* stop = argv + argc;
|
|
|
|
for (++argv; argv < stop; ++argv) {
|
|
|
|
if (strcmp(*argv, "-o") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
outDir.set(*argv);
|
|
|
|
if (outDir.c_str()[outDir.size() - 1] != '/') {
|
|
|
|
outDir.append("/");
|
|
|
|
}
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--repeat") == 0) {
|
2009-01-19 20:08:35 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
repeatDraw = atoi(*argv);
|
|
|
|
if (repeatDraw < 1) {
|
|
|
|
repeatDraw = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --repeat\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-01-19 20:08:35 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--logPerIter") == 0) {
|
2013-03-04 16:41:06 +00:00
|
|
|
logPerIter = true;
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--timers") == 0) {
|
2011-06-07 19:16:02 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
timerWall = false;
|
2012-08-28 12:18:40 +00:00
|
|
|
truncatedTimerWall = false;
|
2011-06-07 19:16:02 +00:00
|
|
|
timerCpu = false;
|
2012-08-28 12:18:40 +00:00
|
|
|
truncatedTimerCpu = false;
|
2011-06-07 19:16:02 +00:00
|
|
|
timerGpu = false;
|
|
|
|
for (char* t = *argv; *t; ++t) {
|
|
|
|
switch (*t) {
|
|
|
|
case 'w': timerWall = true; break;
|
|
|
|
case 'c': timerCpu = true; break;
|
2012-08-28 12:18:40 +00:00
|
|
|
case 'W': truncatedTimerWall = true; break;
|
|
|
|
case 'C': truncatedTimerCpu = true; break;
|
2011-06-07 19:16:02 +00:00
|
|
|
case 'g': timerGpu = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --timers\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2011-06-07 19:16:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (!strcmp(*argv, "--rotate")) {
|
2009-01-21 03:15:13 +00:00
|
|
|
doRotate = true;
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (!strcmp(*argv, "--scale")) {
|
2009-08-04 01:51:09 +00:00
|
|
|
doScale = true;
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (!strcmp(*argv, "--clip")) {
|
2009-01-21 03:15:13 +00:00
|
|
|
doClip = true;
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (!strcmp(*argv, "--min")) {
|
2012-08-23 17:50:06 +00:00
|
|
|
printMin = true;
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--forceAA") == 0) {
|
2009-08-04 18:17:15 +00:00
|
|
|
if (!parse_bool_arg(++argv, stop, &forceAA)) {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --forceAA\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-08-04 18:17:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--forceFilter") == 0) {
|
2009-08-04 18:17:15 +00:00
|
|
|
if (!parse_bool_arg(++argv, stop, &forceFilter)) {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --forceFilter\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-08-04 18:17:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--forceDither") == 0) {
|
2009-10-19 17:39:46 +00:00
|
|
|
bool tmp;
|
|
|
|
if (!parse_bool_arg(++argv, stop, &tmp)) {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --forceDither\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-10-19 17:39:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
forceDither = tmp ? SkTriState::kTrue : SkTriState::kFalse;
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--forceBlend") == 0) {
|
2009-08-04 18:17:15 +00:00
|
|
|
bool wantAlpha = false;
|
|
|
|
if (!parse_bool_arg(++argv, stop, &wantAlpha)) {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --forceBlend\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-08-04 18:17:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
forceAlpha = wantAlpha ? 0x80 : 0xFF;
|
2013-03-11 20:22:15 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
} else if (strcmp(*argv, "--gpuCacheSize") == 0) {
|
|
|
|
if (stop - argv > 2) {
|
|
|
|
gpuCacheSize.fBytes = atoi(*++argv);
|
|
|
|
gpuCacheSize.fCount = atoi(*++argv);
|
|
|
|
} else {
|
|
|
|
SkDebugf("missing arg for --gpuCacheSize\n");
|
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--mode") == 0) {
|
2012-07-20 23:03:42 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
if (strcmp(*argv, "normal") == 0) {
|
|
|
|
benchMode = kNormal_benchModes;
|
|
|
|
} else if (strcmp(*argv, "deferred") == 0) {
|
|
|
|
benchMode = kDeferred_benchModes;
|
2012-09-20 19:35:43 +00:00
|
|
|
} else if (strcmp(*argv, "deferredSilent") == 0) {
|
|
|
|
benchMode = kDeferredSilent_benchModes;
|
2012-07-20 23:03:42 +00:00
|
|
|
} else if (strcmp(*argv, "record") == 0) {
|
|
|
|
benchMode = kRecord_benchModes;
|
|
|
|
} else if (strcmp(*argv, "picturerecord") == 0) {
|
|
|
|
benchMode = kPictureRecord_benchModes;
|
|
|
|
} else {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("bad arg for --mode\n");
|
2012-07-20 23:03:42 +00:00
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --mode\n");
|
2012-04-16 19:11:17 +00:00
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--strokeWidth") == 0) {
|
2010-04-27 15:47:34 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
const char *strokeWidthStr = *argv;
|
|
|
|
if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("bad arg for --strokeWidth\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2010-04-27 15:47:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
hasStrokeWidth = true;
|
|
|
|
} else {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --strokeWidth\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2010-04-27 15:47:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--match") == 0) {
|
2009-08-04 01:51:09 +00:00
|
|
|
argv++;
|
2013-05-10 15:16:13 +00:00
|
|
|
while (argv < stop && (*argv)[0] != '-') {
|
|
|
|
*fMatches.append() = *argv++;
|
|
|
|
}
|
|
|
|
argv--;
|
|
|
|
if (!fMatches.count()) {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --match\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-08-04 01:51:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--config") == 0) {
|
2009-08-04 01:51:09 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
int index = findConfig(*argv);
|
|
|
|
if (index >= 0) {
|
2012-04-16 18:00:40 +00:00
|
|
|
*configs.append() = index;
|
|
|
|
userConfig = true;
|
2009-08-04 01:51:09 +00:00
|
|
|
} else {
|
2009-08-04 18:17:15 +00:00
|
|
|
SkString str;
|
|
|
|
str.printf("unrecognized config %s\n", *argv);
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logError(str);
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-08-04 01:51:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --config\n");
|
2012-08-07 12:58:50 +00:00
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-09-12 19:27:11 +00:00
|
|
|
} else if (strcmp(*argv, "--logFile") == 0) {
|
2012-08-07 12:58:50 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
if (!logger.SetLogFile(*argv)) {
|
|
|
|
SkString str;
|
|
|
|
str.printf("Could not open %s for writing.", *argv);
|
2012-09-07 15:21:18 +00:00
|
|
|
logger.logError(str);
|
2012-08-07 12:58:50 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("missing arg for --logFile\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-08-04 01:51:09 +00:00
|
|
|
return -1;
|
2009-01-21 03:15:13 +00:00
|
|
|
}
|
2010-02-22 19:50:13 +00:00
|
|
|
} else if (strlen(*argv) > 2 && strncmp(*argv, "-D", 2) == 0) {
|
2009-09-02 21:12:42 +00:00
|
|
|
argv++;
|
2010-02-22 19:50:13 +00:00
|
|
|
if (argv < stop) {
|
2009-09-02 21:12:42 +00:00
|
|
|
defineDict.set(argv[-1] + 2, *argv);
|
|
|
|
} else {
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logError("incomplete '-Dfoo bar' definition\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-09-02 21:12:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-03 13:28:57 +00:00
|
|
|
} else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) {
|
|
|
|
help();
|
|
|
|
return 0;
|
2009-08-04 01:51:09 +00:00
|
|
|
} else {
|
2009-08-04 18:17:15 +00:00
|
|
|
SkString str;
|
|
|
|
str.printf("unrecognized arg %s\n", *argv);
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logError(str);
|
2012-04-03 13:28:57 +00:00
|
|
|
help();
|
2009-08-04 01:51:09 +00:00
|
|
|
return -1;
|
2009-01-07 11:47:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-20 23:03:42 +00:00
|
|
|
if ((benchMode == kRecord_benchModes || benchMode == kPictureRecord_benchModes)
|
|
|
|
&& !outDir.isEmpty()) {
|
2012-09-12 19:27:11 +00:00
|
|
|
logger.logError("'--mode record' and '--mode picturerecord' are not"
|
2012-07-20 23:03:42 +00:00
|
|
|
" compatible with -o.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((benchMode == kRecord_benchModes || benchMode == kPictureRecord_benchModes)) {
|
|
|
|
perIterTimeformat.set("%.4f");
|
|
|
|
normalTimeFormat.set("%6.4f");
|
|
|
|
}
|
2012-04-16 18:00:40 +00:00
|
|
|
if (!userConfig) {
|
2013-03-19 13:58:55 +00:00
|
|
|
// if no config is specified by user, add the default configs
|
2012-04-16 18:00:40 +00:00
|
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
|
2013-03-19 13:58:55 +00:00
|
|
|
if (gConfigs[i].fRunByDefault) {
|
|
|
|
*configs.append() = i;
|
|
|
|
}
|
2012-04-16 18:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-15 15:42:15 +00:00
|
|
|
if (kNormal_benchModes != benchMode) {
|
|
|
|
// Non-rendering configs only run in normal mode
|
|
|
|
for (int i = 0; i < configs.count(); ++i) {
|
|
|
|
int configIdx = configs[i];
|
|
|
|
if (kNonRendering_Backend == gConfigs[configIdx].fBackend) {
|
|
|
|
configs.remove(i, 1);
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-07 12:58:50 +00:00
|
|
|
|
2013-03-19 13:58:55 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
for (int i = 0; i < configs.count(); ++i) {
|
|
|
|
int configIdx = configs[i];
|
|
|
|
|
|
|
|
if (kGPU_Backend == gConfigs[configIdx].fBackend && gConfigs[configIdx].fSampleCnt > 0) {
|
|
|
|
GrContext* context = gContextFactory.get(gConfigs[configIdx].fContextType);
|
|
|
|
if (NULL == context) {
|
|
|
|
SkString error;
|
|
|
|
error.printf("Error creating GrContext for config %s. Config will be skipped.\n",
|
|
|
|
gConfigs[configIdx].fName);
|
|
|
|
logger.logError(error.c_str());
|
|
|
|
configs.remove(i);
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (gConfigs[configIdx].fSampleCnt > context->getMaxSampleCount()){
|
|
|
|
SkString error;
|
|
|
|
error.printf("Sample count (%d) for config %s is unsupported. "
|
|
|
|
"Config will be skipped.\n",
|
|
|
|
gConfigs[configIdx].fSampleCnt, gConfigs[configIdx].fName);
|
|
|
|
logger.logError(error.c_str());
|
|
|
|
configs.remove(i);
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-04-04 14:31:36 +00:00
|
|
|
// report our current settings
|
|
|
|
{
|
|
|
|
SkString str;
|
2012-09-20 19:35:43 +00:00
|
|
|
const char* deferredMode = benchMode == kDeferred_benchModes ? "yes" :
|
|
|
|
(benchMode == kDeferredSilent_benchModes ? "silent" : "no");
|
2012-07-02 20:48:51 +00:00
|
|
|
str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d "
|
2012-09-20 19:35:43 +00:00
|
|
|
"deferred=%s logperiter=%d",
|
|
|
|
forceAlpha, forceAA, forceFilter, deferredMode,
|
2012-07-20 23:03:42 +00:00
|
|
|
logPerIter);
|
2012-08-23 17:50:06 +00:00
|
|
|
str.appendf(" rotate=%d scale=%d clip=%d min=%d",
|
|
|
|
doRotate, doScale, doClip, printMin);
|
2012-07-20 23:03:42 +00:00
|
|
|
str.appendf(" record=%d picturerecord=%d",
|
|
|
|
benchMode == kRecord_benchModes,
|
|
|
|
benchMode == kPictureRecord_benchModes);
|
2011-06-15 17:25:46 +00:00
|
|
|
const char * ditherName;
|
|
|
|
switch (forceDither) {
|
|
|
|
case SkTriState::kDefault: ditherName = "default"; break;
|
|
|
|
case SkTriState::kTrue: ditherName = "true"; break;
|
|
|
|
case SkTriState::kFalse: ditherName = "false"; break;
|
|
|
|
default: ditherName = "<invalid>"; break;
|
|
|
|
}
|
|
|
|
str.appendf(" dither=%s", ditherName);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-06-15 17:25:46 +00:00
|
|
|
if (hasStrokeWidth) {
|
|
|
|
str.appendf(" strokeWidth=%f", strokeWidth);
|
|
|
|
} else {
|
|
|
|
str.append(" strokeWidth=none");
|
|
|
|
}
|
2012-08-07 12:58:50 +00:00
|
|
|
|
2011-06-15 17:25:46 +00:00
|
|
|
#if defined(SK_SCALAR_IS_FLOAT)
|
|
|
|
str.append(" scalar=float");
|
|
|
|
#elif defined(SK_SCALAR_IS_FIXED)
|
|
|
|
str.append(" scalar=fixed");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(SK_BUILD_FOR_WIN32)
|
|
|
|
str.append(" system=WIN32");
|
|
|
|
#elif defined(SK_BUILD_FOR_MAC)
|
|
|
|
str.append(" system=MAC");
|
|
|
|
#elif defined(SK_BUILD_FOR_ANDROID)
|
|
|
|
str.append(" system=ANDROID");
|
|
|
|
#elif defined(SK_BUILD_FOR_UNIX)
|
|
|
|
str.append(" system=UNIX");
|
|
|
|
#else
|
|
|
|
str.append(" system=other");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(SK_DEBUG)
|
|
|
|
str.append(" DEBUG");
|
|
|
|
#endif
|
|
|
|
str.append("\n");
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logProgress(str);
|
2011-04-04 14:31:36 +00:00
|
|
|
}
|
2011-12-13 16:49:49 +00:00
|
|
|
|
2013-02-22 16:13:16 +00:00
|
|
|
SkTArray<BenchTimer*> timers(SK_ARRAY_COUNT(gConfigs));
|
2013-02-22 19:17:13 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
|
2013-02-22 16:13:16 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-03-11 20:22:15 +00:00
|
|
|
SkGLContextHelper* glCtx = NULL;
|
2013-02-22 16:13:16 +00:00
|
|
|
if (kGPU_Backend == gConfigs[i].fBackend) {
|
2013-03-11 20:22:15 +00:00
|
|
|
GrContext* context = gContextFactory.get(gConfigs[i].fContextType);
|
|
|
|
if (NULL != context) {
|
|
|
|
// Set the user specified cache limits if non-default.
|
|
|
|
size_t bytes;
|
|
|
|
int count;
|
|
|
|
context->getTextureCacheLimits(&count, &bytes);
|
|
|
|
if (-1 != gpuCacheSize.fBytes) {
|
2013-03-11 20:33:45 +00:00
|
|
|
bytes = static_cast<size_t>(gpuCacheSize.fBytes);
|
2013-03-11 20:22:15 +00:00
|
|
|
}
|
|
|
|
if (-1 != gpuCacheSize.fCount) {
|
|
|
|
count = gpuCacheSize.fCount;
|
|
|
|
}
|
|
|
|
context->setTextureCacheLimits(count, bytes);
|
|
|
|
}
|
|
|
|
glCtx = gContextFactory.getGLContext(gConfigs[i].fContextType);
|
2013-02-22 16:13:16 +00:00
|
|
|
}
|
2013-03-11 20:22:15 +00:00
|
|
|
timers.push_back(SkNEW_ARGS(BenchTimer, (glCtx)));
|
2013-02-22 16:13:16 +00:00
|
|
|
#else
|
|
|
|
timers.push_back(SkNEW(BenchTimer));
|
|
|
|
#endif
|
|
|
|
}
|
2011-10-27 20:44:19 +00:00
|
|
|
|
2009-09-02 21:12:42 +00:00
|
|
|
Iter iter(&defineDict);
|
2009-01-05 03:34:50 +00:00
|
|
|
SkBenchmark* bench;
|
|
|
|
while ((bench = iter.next()) != NULL) {
|
2012-08-13 22:10:05 +00:00
|
|
|
SkAutoTUnref<SkBenchmark> benchUnref(bench);
|
|
|
|
|
2009-01-07 11:47:57 +00:00
|
|
|
SkIPoint dim = bench->getSize();
|
|
|
|
if (dim.fX <= 0 || dim.fY <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
bench->setForceAlpha(forceAlpha);
|
|
|
|
bench->setForceAA(forceAA);
|
2009-08-04 18:17:15 +00:00
|
|
|
bench->setForceFilter(forceFilter);
|
2009-10-19 17:39:46 +00:00
|
|
|
bench->setDither(forceDither);
|
2010-04-27 15:47:34 +00:00
|
|
|
if (hasStrokeWidth) {
|
|
|
|
bench->setStrokeWidth(strokeWidth);
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-08-04 01:51:09 +00:00
|
|
|
// only run benchmarks if their name contains matchStr
|
2013-07-23 17:56:20 +00:00
|
|
|
if (skip_name(fMatches, bench->getName())) {
|
2009-08-04 01:51:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2013-03-15 15:42:15 +00:00
|
|
|
bool loggedBenchStart = false;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-08-13 14:03:31 +00:00
|
|
|
AutoPrePostDraw appd(bench);
|
|
|
|
|
2012-04-16 18:00:40 +00:00
|
|
|
for (int x = 0; x < configs.count(); ++x) {
|
|
|
|
int configIndex = configs[x];
|
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
bool setupFailed = false;
|
|
|
|
|
2013-03-15 15:42:15 +00:00
|
|
|
if (kNonRendering_Backend == gConfigs[configIndex].fBackend) {
|
|
|
|
if (bench->isRendering()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!bench->isRendering()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 18:00:40 +00:00
|
|
|
outConfig = gConfigs[configIndex].fConfig;
|
|
|
|
configName = gConfigs[configIndex].fName;
|
|
|
|
backend = gConfigs[configIndex].fBackend;
|
2013-03-19 13:58:55 +00:00
|
|
|
sampleCount = gConfigs[configIndex].fSampleCnt;
|
2013-02-22 16:13:16 +00:00
|
|
|
GrContext* context = NULL;
|
|
|
|
BenchTimer* timer = timers[configIndex];
|
2011-12-13 16:49:49 +00:00
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-03-07 20:52:59 +00:00
|
|
|
SkGLContextHelper* glContext = NULL;
|
2013-02-22 16:13:16 +00:00
|
|
|
if (kGPU_Backend == backend) {
|
|
|
|
context = gContextFactory.get(gConfigs[configIndex].fContextType);
|
|
|
|
if (NULL == context) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
glContext = gContextFactory.getGLContext(gConfigs[configIndex].fContextType);
|
2009-01-19 20:08:35 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2013-03-15 15:42:15 +00:00
|
|
|
SkDevice* device = NULL;
|
2012-07-20 23:03:42 +00:00
|
|
|
SkCanvas* canvas = NULL;
|
|
|
|
SkPicture pictureRecordFrom;
|
|
|
|
SkPicture pictureRecordTo;
|
2013-03-15 15:42:15 +00:00
|
|
|
|
|
|
|
if (kNonRendering_Backend != backend) {
|
2013-03-19 13:58:55 +00:00
|
|
|
device = make_device(outConfig, dim, backend, sampleCount, context);
|
2013-06-03 19:31:07 +00:00
|
|
|
if (NULL == device) {
|
|
|
|
SkString error;
|
|
|
|
error.printf("Device creation failure for config %s. Will skip.\n", configName);
|
|
|
|
logger.logError(error.c_str());
|
|
|
|
setupFailed = true;
|
|
|
|
} else {
|
|
|
|
switch(benchMode) {
|
|
|
|
case kDeferredSilent_benchModes:
|
|
|
|
case kDeferred_benchModes:
|
|
|
|
canvas =
|
2013-05-28 17:39:08 +00:00
|
|
|
#if SK_DEFERRED_CANVAS_USES_FACTORIES
|
2013-06-03 19:31:07 +00:00
|
|
|
SkDeferredCanvas::Create(device);
|
2013-05-28 17:39:08 +00:00
|
|
|
#else
|
2013-06-03 19:31:07 +00:00
|
|
|
SkNEW_ARGS(SkDeferredCanvas, (device));
|
2013-05-28 17:39:08 +00:00
|
|
|
#endif
|
2013-06-03 19:31:07 +00:00
|
|
|
break;
|
|
|
|
case kRecord_benchModes:
|
|
|
|
canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY,
|
|
|
|
SkPicture::kUsePathBoundsForClip_RecordingFlag);
|
|
|
|
canvas->ref();
|
|
|
|
break;
|
|
|
|
case kPictureRecord_benchModes: {
|
|
|
|
// This sets up picture-to-picture recording.
|
|
|
|
// The C++ drawing calls for the benchmark are recorded into
|
|
|
|
// pictureRecordFrom. As the benchmark, we will time how
|
|
|
|
// long it takes to playback pictureRecordFrom into
|
|
|
|
// pictureRecordTo.
|
|
|
|
SkCanvas* tempCanvas = pictureRecordFrom.beginRecording(dim.fX, dim.fY,
|
|
|
|
SkPicture::kUsePathBoundsForClip_RecordingFlag);
|
|
|
|
bench->draw(tempCanvas);
|
|
|
|
pictureRecordFrom.endRecording();
|
|
|
|
canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY,
|
|
|
|
SkPicture::kUsePathBoundsForClip_RecordingFlag);
|
|
|
|
canvas->ref();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kNormal_benchModes:
|
|
|
|
canvas = new SkCanvas(device);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
2013-03-15 15:42:15 +00:00
|
|
|
}
|
2013-06-03 19:31:07 +00:00
|
|
|
device->unref();
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
2012-07-20 23:03:42 +00:00
|
|
|
}
|
2012-04-16 19:11:17 +00:00
|
|
|
}
|
|
|
|
SkAutoUnref canvasUnref(canvas);
|
2013-06-03 19:31:07 +00:00
|
|
|
if (!setupFailed) {
|
|
|
|
if (NULL != canvas) {
|
|
|
|
if (doClip) {
|
|
|
|
performClip(canvas, dim.fX, dim.fY);
|
|
|
|
}
|
|
|
|
if (doScale) {
|
|
|
|
performScale(canvas, dim.fX, dim.fY);
|
|
|
|
}
|
|
|
|
if (doRotate) {
|
|
|
|
performRotate(canvas, dim.fX, dim.fY);
|
|
|
|
}
|
2013-03-15 15:42:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
if (!loggedBenchStart) {
|
|
|
|
loggedBenchStart = true;
|
|
|
|
SkString str;
|
|
|
|
str.printf("running bench [%d %d] %28s", dim.fX, dim.fY, bench->getName());
|
|
|
|
logger.logProgress(str);
|
|
|
|
}
|
2011-12-13 16:49:49 +00:00
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
// warm up caches if needed
|
|
|
|
if (repeatDraw > 1 && NULL != canvas) {
|
2012-08-28 12:18:40 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-06-03 19:31:07 +00:00
|
|
|
// purge the GPU resources to reduce variance
|
|
|
|
if (NULL != context) {
|
|
|
|
context->freeGpuResources();
|
|
|
|
}
|
2012-08-28 12:18:40 +00:00
|
|
|
#endif
|
2013-06-03 19:31:07 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
if (benchMode == kPictureRecord_benchModes) {
|
|
|
|
pictureRecordFrom.draw(canvas);
|
|
|
|
} else {
|
|
|
|
bench->draw(canvas);
|
|
|
|
}
|
2012-09-20 19:35:43 +00:00
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
if (kDeferredSilent_benchModes == benchMode) {
|
|
|
|
static_cast<SkDeferredCanvas*>(canvas)->silentFlush();
|
|
|
|
} else {
|
|
|
|
canvas->flush();
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-06-03 19:31:07 +00:00
|
|
|
if (NULL != context) {
|
|
|
|
context->flush();
|
|
|
|
SK_GL(*glContext, Finish());
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2012-07-20 23:03:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
// record timer values for each repeat, and their sum
|
|
|
|
TimerData timerData(perIterTimeformat, normalTimeFormat);
|
|
|
|
for (int i = 0; i < repeatDraw; i++) {
|
|
|
|
if ((benchMode == kRecord_benchModes || benchMode == kPictureRecord_benchModes)) {
|
|
|
|
// This will clear the recorded commands so that they do not
|
|
|
|
// accumulate.
|
|
|
|
canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY,
|
|
|
|
SkPicture::kUsePathBoundsForClip_RecordingFlag);
|
|
|
|
}
|
2012-09-20 19:35:43 +00:00
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
timer->start(bench->getDurationScale());
|
|
|
|
if (NULL != canvas) {
|
|
|
|
canvas->save();
|
|
|
|
}
|
|
|
|
if (benchMode == kPictureRecord_benchModes) {
|
|
|
|
pictureRecordFrom.draw(canvas);
|
|
|
|
} else {
|
|
|
|
bench->draw(canvas);
|
|
|
|
}
|
2012-08-28 12:18:40 +00:00
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
if (kDeferredSilent_benchModes == benchMode) {
|
|
|
|
static_cast<SkDeferredCanvas*>(canvas)->silentFlush();
|
|
|
|
} else if (NULL != canvas) {
|
|
|
|
canvas->flush();
|
|
|
|
}
|
2013-03-15 15:42:15 +00:00
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
if (NULL != canvas) {
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop the truncated timer after the last canvas call but
|
|
|
|
// don't wait for all the GL calls to complete
|
|
|
|
timer->truncatedEnd();
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-06-03 19:31:07 +00:00
|
|
|
if (NULL != glContext) {
|
|
|
|
context->flush();
|
|
|
|
SK_GL(*glContext, Finish());
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2013-06-03 19:31:07 +00:00
|
|
|
// stop the inclusive and gpu timers once all the GL calls
|
|
|
|
// have completed
|
|
|
|
timer->end();
|
2012-07-02 20:48:51 +00:00
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
timerData.appendTimes(timer, repeatDraw - 1 == i);
|
2012-08-23 17:50:06 +00:00
|
|
|
|
2013-06-03 19:31:07 +00:00
|
|
|
}
|
|
|
|
if (repeatDraw > 1) {
|
|
|
|
SkString result = timerData.getResult(
|
|
|
|
logPerIter, printMin, repeatDraw, configName,
|
|
|
|
timerWall, truncatedTimerWall, timerCpu,
|
|
|
|
truncatedTimerCpu,
|
|
|
|
timerGpu && NULL != context);
|
|
|
|
logger.logProgress(result);
|
|
|
|
}
|
|
|
|
if (outDir.size() > 0 && kNonRendering_Backend != backend) {
|
|
|
|
saveFile(bench->getName(), configName, outDir.c_str(),
|
|
|
|
device->accessBitmap(false));
|
|
|
|
}
|
2011-07-14 19:03:58 +00:00
|
|
|
}
|
2013-06-12 14:45:03 +00:00
|
|
|
}
|
|
|
|
if (loggedBenchStart) {
|
|
|
|
logger.logProgress(SkString("\n"));
|
2009-01-19 20:08:35 +00:00
|
|
|
}
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-09-13 14:05:00 +00:00
|
|
|
#if GR_CACHE_STATS
|
2013-02-22 16:13:16 +00:00
|
|
|
for (int i = 0; i <= GrContextFactory::kLastGLContextType; ++i) {
|
|
|
|
GrContextFactory::GLContextType ctxType = (GrContextFactory::GLContextType)i;
|
|
|
|
GrContext* context = gContextFactory.get(ctxType);
|
|
|
|
if (NULL != context) {
|
|
|
|
SkDebugf("Cache Stats for %s context:\n", GrContextFactory::GLContextTypeName(ctxType));
|
|
|
|
context->printCacheStats();
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
}
|
2012-09-13 14:05:00 +00:00
|
|
|
#endif
|
2013-02-22 16:13:16 +00:00
|
|
|
// Destroy the GrContext before the inst tracking printing at main() exit occurs.
|
|
|
|
gContextFactory.destroyContexts();
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2013-02-22 19:17:13 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
|
2013-02-22 16:13:16 +00:00
|
|
|
SkDELETE(timers[i]);
|
|
|
|
}
|
2012-09-13 14:05:00 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-10-02 18:33:14 +00:00
|
|
|
|
2012-11-01 17:43:44 +00:00
|
|
|
#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
|
2012-10-02 18:33:14 +00:00
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|