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"
|
|
|
|
#include "GrRenderTarget.h"
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
#include "gl/SkANGLEGLContext.h"
|
|
|
|
#endif // SK_ANGLE
|
|
|
|
#include "gl/SkNativeGLContext.h"
|
|
|
|
#include "gl/SkNullGLContext.h"
|
|
|
|
#include "gl/SkDebugGLContext.h"
|
|
|
|
#include "SkGpuDevice.h"
|
|
|
|
#endif // SK_SUPPORT_GPU
|
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"
|
2012-08-07 12:58:50 +00:00
|
|
|
#include "SkStream.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
|
2012-08-07 12:58:50 +00:00
|
|
|
class SkBenchLogger {
|
|
|
|
public:
|
|
|
|
SkBenchLogger() : fFileStream(NULL) {}
|
|
|
|
~SkBenchLogger() {
|
|
|
|
if (fFileStream)
|
|
|
|
SkDELETE(fFileStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SetLogFile(const char file[]) {
|
|
|
|
fFileStream = SkNEW_ARGS(SkFILEWStream, (file));
|
|
|
|
return fFileStream->isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void logError(const char msg[]) { nativeLogError(msg); }
|
|
|
|
void logError(const SkString& str) { nativeLogError(str.c_str()); }
|
|
|
|
|
|
|
|
void logProgress(const char msg[]) {
|
|
|
|
nativeLogProgress(msg);
|
|
|
|
fileWrite(msg, strlen(msg));
|
|
|
|
}
|
|
|
|
void logProgress(const SkString& str) {
|
|
|
|
nativeLogProgress(str.c_str());
|
|
|
|
fileWrite(str.c_str(), str.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-11-08 19:00:26 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
2012-08-07 12:58:50 +00:00
|
|
|
void nativeLogError(const char msg[]) { SkDebugf("%s", msg); }
|
|
|
|
void nativeLogProgress(const char msg[]) { SkDebugf("%s", msg); }
|
2009-08-04 18:17:15 +00:00
|
|
|
#else
|
2012-08-07 12:58:50 +00:00
|
|
|
void nativeLogError(const char msg[]) { fprintf(stderr, "%s", msg); }
|
|
|
|
void nativeLogProgress(const char msg[]) { printf("%s", msg); }
|
2009-08-04 18:17:15 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-07 12:58:50 +00:00
|
|
|
void fileWrite(const char msg[], size_t size) {
|
|
|
|
if (fFileStream && fFileStream->isValid())
|
|
|
|
fFileStream->write(msg, size);
|
|
|
|
}
|
|
|
|
SkFILEWStream* fFileStream;
|
|
|
|
|
|
|
|
} logger;
|
2009-08-04 18:17:15 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-20 23:03:42 +00:00
|
|
|
enum benchModes {
|
|
|
|
kNormal_benchModes,
|
|
|
|
kDeferred_benchModes,
|
|
|
|
kRecord_benchModes,
|
|
|
|
kPictureRecord_benchModes
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-03-31 03:48:49 +00:00
|
|
|
static void erase(SkBitmap& bm) {
|
|
|
|
if (bm.config() == SkBitmap::kA8_Config) {
|
|
|
|
bm.eraseColor(0);
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
2011-05-18 18:37:07 +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;
|
|
|
|
|
|
|
|
r.set(SkIntToScalar(10), SkIntToScalar(10),
|
|
|
|
SkIntToScalar(w*2/3), SkIntToScalar(h*2/3));
|
|
|
|
canvas->clipRect(r, SkRegion::kIntersect_Op);
|
2011-05-18 18:37:07 +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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
kRaster_Backend,
|
|
|
|
kGPU_Backend,
|
|
|
|
kPDF_Backend,
|
|
|
|
};
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-12-13 16:49:49 +00:00
|
|
|
class GLHelper {
|
|
|
|
public:
|
|
|
|
GLHelper() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool init(SkGLContext* glCtx, int width, int height) {
|
|
|
|
GrContext* grCtx;
|
|
|
|
GrRenderTarget* rt;
|
|
|
|
if (glCtx->init(width, height)) {
|
|
|
|
GrPlatform3DContext ctx =
|
|
|
|
reinterpret_cast<GrPlatform3DContext>(glCtx->gl());
|
|
|
|
grCtx = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx);
|
|
|
|
if (NULL != grCtx) {
|
|
|
|
GrPlatformRenderTargetDesc desc;
|
|
|
|
desc.fConfig = kSkia8888_PM_GrPixelConfig;
|
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
|
|
|
desc.fStencilBits = 8;
|
|
|
|
desc.fRenderTargetHandle = glCtx->getFBOID();
|
|
|
|
rt = grCtx->createPlatformRenderTarget(desc);
|
|
|
|
if (NULL == rt) {
|
|
|
|
grCtx->unref();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
glCtx->ref();
|
|
|
|
fGLContext.reset(glCtx);
|
|
|
|
fGrContext.reset(grCtx);
|
|
|
|
fRenderTarget.reset(rt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-19 14:42:13 +00:00
|
|
|
void cleanup() {
|
|
|
|
fGLContext.reset(NULL);
|
|
|
|
fGrContext.reset(NULL);
|
|
|
|
fRenderTarget.reset(NULL);
|
|
|
|
}
|
|
|
|
|
2011-12-13 16:49:49 +00:00
|
|
|
bool isValid() {
|
|
|
|
return NULL != fGLContext.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkGLContext* glContext() {
|
|
|
|
return fGLContext.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
GrRenderTarget* renderTarget() {
|
|
|
|
return fRenderTarget.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
GrContext* grContext() {
|
|
|
|
return fGrContext.get();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkAutoTUnref<SkGLContext> fGLContext;
|
|
|
|
SkAutoTUnref<GrContext> fGrContext;
|
|
|
|
SkAutoTUnref<GrRenderTarget> fRenderTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GLHelper gRealGLHelper;
|
|
|
|
static GLHelper gNullGLHelper;
|
2012-03-19 14:42:13 +00:00
|
|
|
static GLHelper gDebugGLHelper;
|
2012-03-28 16:19:11 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
static GLHelper gANGLEGLHelper;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
|
|
|
#else // !SK_SUPPORT_GPU
|
|
|
|
class GLHelper;
|
|
|
|
class SkGLContext;
|
|
|
|
#endif // !SK_SUPPORT_GPU
|
2011-05-17 02:25:05 +00:00
|
|
|
static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size,
|
2011-12-13 16:49:49 +00:00
|
|
|
Backend backend, GLHelper* glHelper) {
|
2011-05-17 02:25:05 +00:00
|
|
|
SkDevice* device = NULL;
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setConfig(config, size.fX, size.fY);
|
2011-05-18 18:37:07 +00:00
|
|
|
|
2011-05-17 02:25:05 +00:00
|
|
|
switch (backend) {
|
|
|
|
case kRaster_Backend:
|
|
|
|
bitmap.allocPixels();
|
|
|
|
erase(bitmap);
|
2011-06-16 19:10:39 +00:00
|
|
|
device = new SkDevice(bitmap);
|
2011-05-17 02:25:05 +00:00
|
|
|
break;
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-05-17 02:25:05 +00:00
|
|
|
case kGPU_Backend:
|
2011-12-13 16:49:49 +00:00
|
|
|
device = new SkGpuDevice(glHelper->grContext(),
|
|
|
|
glHelper->renderTarget());
|
2011-05-17 02:25:05 +00:00
|
|
|
break;
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
static const struct {
|
|
|
|
SkBitmap::Config fConfig;
|
|
|
|
const char* fName;
|
2011-05-17 02:25:05 +00:00
|
|
|
Backend fBackend;
|
2011-12-13 16:49:49 +00:00
|
|
|
GLHelper* fGLHelper;
|
2009-01-19 20:08:35 +00:00
|
|
|
} gConfigs[] = {
|
2011-12-13 16:49:49 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend, NULL },
|
|
|
|
{ SkBitmap::kRGB_565_Config, "565", kRaster_Backend, NULL },
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-12-13 16:49:49 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend, &gRealGLHelper },
|
2012-03-28 16:19:11 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
{ SkBitmap::kARGB_8888_Config, "ANGLE", kGPU_Backend, &gANGLEGLHelper },
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
2012-03-30 12:23:56 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
{ SkBitmap::kARGB_8888_Config, "Debug", kGPU_Backend, &gDebugGLHelper },
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_DEBUG
|
2011-12-13 16:49:49 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, "NULLGPU", kGPU_Backend, &gNullGLHelper },
|
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;
|
|
|
|
}
|
|
|
|
|
2011-10-28 14:59:07 +00:00
|
|
|
static void determine_gpu_context_size(SkTDict<const char*>& defineDict,
|
|
|
|
int* contextWidth,
|
|
|
|
int* contextHeight) {
|
|
|
|
Iter iter(&defineDict);
|
|
|
|
SkBenchmark* bench;
|
|
|
|
while ((bench = iter.next()) != NULL) {
|
|
|
|
SkIPoint dim = bench->getSize();
|
|
|
|
if (*contextWidth < dim.fX) {
|
|
|
|
*contextWidth = dim.fX;
|
|
|
|
}
|
|
|
|
if (*contextHeight < dim.fY) {
|
|
|
|
*contextHeight = dim.fY;
|
|
|
|
}
|
2012-08-13 22:10:05 +00:00
|
|
|
bench->unref();
|
2011-10-28 14:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-31 16:33:52 +00:00
|
|
|
static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
|
|
|
|
if (0 == array.count()) {
|
|
|
|
// no names, so don't skip anything
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < array.count(); ++i) {
|
|
|
|
if (strstr(name, array[i])) {
|
|
|
|
// found the name, so don't skip
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-03 13:28:57 +00:00
|
|
|
static void help() {
|
2012-07-02 20:48:51 +00:00
|
|
|
SkDebugf("Usage: bench [-o outDir] [-repeat nr] [-logPerIter 1|0] "
|
2012-04-03 13:28:57 +00:00
|
|
|
"[-timers [wcg]*] [-rotate]\n"
|
|
|
|
" [-scale] [-clip] [-forceAA 1|0] [-forceFilter 1|0]\n"
|
|
|
|
" [-forceDither 1|0] [-forceBlend 1|0] [-strokeWidth width]\n"
|
2012-07-20 23:03:42 +00:00
|
|
|
" [-match name] [-mode normal|deferred|record|picturerecord]\n"
|
2012-04-16 19:11:17 +00:00
|
|
|
" [-config 8888|565|GPU|ANGLE|NULLGPU] [-Dfoo bar]\n"
|
|
|
|
" [-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");
|
|
|
|
SkDebugf(" -repeat nr : Each bench repeats for nr times.\n");
|
2012-07-02 20:48:51 +00:00
|
|
|
SkDebugf(" -logPerIter 1|0 : "
|
|
|
|
"Log each repeat timer instead of mean, default is disabled.\n");
|
2012-04-03 13:28:57 +00:00
|
|
|
SkDebugf(" -timers [wcg]* : "
|
|
|
|
"Display wall time, cpu time or gpu time for each bench.\n");
|
|
|
|
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(" -forceAA 1|0 : "
|
|
|
|
"Enable/disable anti-aliased, default is enabled.\n");
|
|
|
|
SkDebugf(" -forceFilter 1|0 : "
|
|
|
|
"Enable/disable bitmap filtering, default is disabled.\n");
|
|
|
|
SkDebugf(" -forceDither 1|0 : "
|
|
|
|
"Enable/disable dithering, default is disabled.\n");
|
|
|
|
SkDebugf(" -forceBlend 1|0 : "
|
|
|
|
"Enable/disable dithering, default is disabled.\n");
|
|
|
|
SkDebugf(" -strokeWidth width : The width for path stroke.\n");
|
|
|
|
SkDebugf(" -match name : Only run bench whose name is matched.\n");
|
2012-07-20 23:03:42 +00:00
|
|
|
SkDebugf(" -mode normal|deferred|record|picturerecord : Run in the corresponding mode\n"
|
|
|
|
" normal, Use a normal canvas to draw to;\n"
|
|
|
|
" deferred, Use a deferrred canvas when drawing;\n"
|
|
|
|
" 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-08-07 12:58:50 +00:00
|
|
|
SkDebugf(" -logFile : destination for writing log output, in addition to stdout.\n");
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-03 13:28:57 +00:00
|
|
|
SkDebugf(" -config 8888|565|GPU|ANGLE|NULLGPU : "
|
|
|
|
"Run bench in corresponding config mode.\n");
|
2012-08-02 14:03:32 +00:00
|
|
|
#else
|
|
|
|
SkDebugf(" -config 8888|565: "
|
|
|
|
"Run bench in corresponding config mode.\n");
|
|
|
|
#endif
|
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");
|
|
|
|
}
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
int main (int argc, char * const argv[]) {
|
2012-08-14 13:15:44 +00:00
|
|
|
#ifdef SK_ENABLE_INST_COUNT
|
|
|
|
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;
|
|
|
|
bool timerCpu = true;
|
|
|
|
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;
|
2010-04-27 15:47:34 +00:00
|
|
|
bool hasStrokeWidth = false;
|
|
|
|
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;
|
2012-01-06 19:22:11 +00:00
|
|
|
GLHelper* glHelper = NULL;
|
2009-08-04 01:51:09 +00:00
|
|
|
const char* configName = "";
|
2011-05-17 02:25:05 +00:00
|
|
|
Backend backend = kRaster_Backend; // for warning
|
2012-04-16 18:00:40 +00:00
|
|
|
SkTDArray<int> configs;
|
|
|
|
bool userConfig = false;
|
2011-05-18 18:37:07 +00:00
|
|
|
|
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("/");
|
|
|
|
}
|
|
|
|
}
|
2009-01-19 20:08:35 +00:00
|
|
|
} else if (strcmp(*argv, "-repeat") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
repeatDraw = atoi(*argv);
|
|
|
|
if (repeatDraw < 1) {
|
|
|
|
repeatDraw = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-07 12:58:50 +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-07-02 20:48:51 +00:00
|
|
|
} else if (strcmp(*argv, "-logPerIter") == 0) {
|
|
|
|
if (!parse_bool_arg(++argv, stop, &logPerIter)) {
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logError("missing arg for -logPerIter\n");
|
2012-07-02 20:48:51 +00:00
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
2011-06-07 19:16:02 +00:00
|
|
|
} else if (strcmp(*argv, "-timers") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
timerWall = false;
|
|
|
|
timerCpu = false;
|
|
|
|
timerGpu = false;
|
|
|
|
for (char* t = *argv; *t; ++t) {
|
|
|
|
switch (*t) {
|
|
|
|
case 'w': timerWall = true; break;
|
|
|
|
case 'c': timerCpu = true; break;
|
|
|
|
case 'g': timerGpu = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-07 12:58:50 +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;
|
|
|
|
}
|
2009-01-21 03:15:13 +00:00
|
|
|
} else if (!strcmp(*argv, "-rotate")) {
|
|
|
|
doRotate = true;
|
2009-08-04 01:51:09 +00:00
|
|
|
} else if (!strcmp(*argv, "-scale")) {
|
|
|
|
doScale = true;
|
2009-01-21 03:15:13 +00:00
|
|
|
} else if (!strcmp(*argv, "-clip")) {
|
|
|
|
doClip = true;
|
2009-01-19 20:08:35 +00:00
|
|
|
} else if (strcmp(*argv, "-forceAA") == 0) {
|
2009-08-04 18:17:15 +00:00
|
|
|
if (!parse_bool_arg(++argv, stop, &forceAA)) {
|
2012-08-07 12:58:50 +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;
|
|
|
|
}
|
|
|
|
} else if (strcmp(*argv, "-forceFilter") == 0) {
|
|
|
|
if (!parse_bool_arg(++argv, stop, &forceFilter)) {
|
2012-08-07 12:58:50 +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;
|
|
|
|
}
|
2009-10-19 17:39:46 +00:00
|
|
|
} else if (strcmp(*argv, "-forceDither") == 0) {
|
|
|
|
bool tmp;
|
|
|
|
if (!parse_bool_arg(++argv, stop, &tmp)) {
|
2012-08-07 12:58:50 +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;
|
2009-01-19 20:08:35 +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-08-07 12:58:50 +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;
|
2012-07-20 23:03:42 +00:00
|
|
|
} else if (strcmp(*argv, "-mode") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
if (strcmp(*argv, "normal") == 0) {
|
|
|
|
benchMode = kNormal_benchModes;
|
|
|
|
} else if (strcmp(*argv, "deferred") == 0) {
|
|
|
|
benchMode = kDeferred_benchModes;
|
|
|
|
} else if (strcmp(*argv, "record") == 0) {
|
|
|
|
benchMode = kRecord_benchModes;
|
|
|
|
} else if (strcmp(*argv, "picturerecord") == 0) {
|
|
|
|
benchMode = kPictureRecord_benchModes;
|
|
|
|
} else {
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logError("bad arg for -mode\n");
|
2012-07-20 23:03:42 +00:00
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logError("missing arg for -mode\n");
|
2012-04-16 19:11:17 +00:00
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-27 15:47:34 +00:00
|
|
|
} else if (strcmp(*argv, "-strokeWidth") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
const char *strokeWidthStr = *argv;
|
|
|
|
if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) {
|
2012-08-07 12:58:50 +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-08-07 12:58:50 +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;
|
|
|
|
}
|
2009-08-04 01:51:09 +00:00
|
|
|
} else if (strcmp(*argv, "-match") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
2011-10-31 16:33:52 +00:00
|
|
|
*fMatches.append() = *argv;
|
2009-08-04 01:51:09 +00:00
|
|
|
} else {
|
2012-08-07 12:58:50 +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;
|
|
|
|
}
|
|
|
|
} else if (strcmp(*argv, "-config") == 0) {
|
|
|
|
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-08-07 12:58:50 +00:00
|
|
|
logger.logError("missing arg for -config\n");
|
|
|
|
help();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else if (strcmp(*argv, "-logFile") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
if (!logger.SetLogFile(*argv)) {
|
|
|
|
SkString str;
|
|
|
|
str.printf("Could not open %s for writing.", *argv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
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-08-07 12:58:50 +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) {
|
|
|
|
// if no config is specified by user, we add them all.
|
|
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
|
|
|
|
*configs.append() = i;
|
|
|
|
}
|
|
|
|
}
|
2012-08-07 12:58:50 +00:00
|
|
|
|
2011-04-04 14:31:36 +00:00
|
|
|
// report our current settings
|
|
|
|
{
|
|
|
|
SkString str;
|
2012-07-02 20:48:51 +00:00
|
|
|
str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d "
|
|
|
|
"deferred=%d logperiter=%d",
|
2012-07-20 23:03:42 +00:00
|
|
|
forceAlpha, forceAA, forceFilter, benchMode == kDeferred_benchModes,
|
|
|
|
logPerIter);
|
2011-06-15 17:25:46 +00:00
|
|
|
str.appendf(" rotate=%d scale=%d clip=%d",
|
|
|
|
doRotate, doScale, doClip);
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
SkGLContext* timerCtx = NULL;
|
2011-06-15 17:25:46 +00:00
|
|
|
//Don't do GL when fixed.
|
2012-08-02 14:03:32 +00:00
|
|
|
#if !defined(SK_SCALAR_IS_FIXED) && SK_SUPPORT_GPU
|
2011-10-28 14:59:07 +00:00
|
|
|
int contextWidth = 1024;
|
|
|
|
int contextHeight = 1024;
|
|
|
|
determine_gpu_context_size(defineDict, &contextWidth, &contextHeight);
|
2011-12-13 16:49:49 +00:00
|
|
|
SkAutoTUnref<SkGLContext> realGLCtx(new SkNativeGLContext);
|
|
|
|
SkAutoTUnref<SkGLContext> nullGLCtx(new SkNullGLContext);
|
2012-03-19 14:42:13 +00:00
|
|
|
SkAutoTUnref<SkGLContext> debugGLCtx(new SkDebugGLContext);
|
2011-12-13 16:49:49 +00:00
|
|
|
gRealGLHelper.init(realGLCtx.get(), contextWidth, contextHeight);
|
|
|
|
gNullGLHelper.init(nullGLCtx.get(), contextWidth, contextHeight);
|
2012-03-19 14:42:13 +00:00
|
|
|
gDebugGLHelper.init(debugGLCtx.get(), contextWidth, contextHeight);
|
2012-03-28 16:19:11 +00:00
|
|
|
#if SK_ANGLE
|
2012-08-02 14:03:32 +00:00
|
|
|
SkAutoTUnref<SkGLContext> angleGLCtx(new SkANGLEGLContext);
|
2012-03-28 16:19:11 +00:00
|
|
|
gANGLEGLHelper.init(angleGLCtx.get(), contextWidth, contextHeight);
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
|
|
|
timerCtx = gRealGLHelper.glContext();
|
|
|
|
#endif // !defined(SK_SCALAR_IS_FIXED) && SK_SUPPORT_GPU
|
2011-10-27 20:44:19 +00:00
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
BenchTimer timer = BenchTimer(timerCtx);
|
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;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2011-05-18 18:37:07 +00:00
|
|
|
|
2009-08-04 01:51:09 +00:00
|
|
|
// only run benchmarks if their name contains matchStr
|
2011-10-31 16:33:52 +00:00
|
|
|
if (skip_name(fMatches, bench->getName())) {
|
2009-08-04 01:51:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-05-18 18:37:07 +00:00
|
|
|
|
2009-08-04 18:17:15 +00:00
|
|
|
{
|
|
|
|
SkString str;
|
2011-04-11 13:12:51 +00:00
|
|
|
str.printf("running bench [%d %d] %28s", dim.fX, dim.fY,
|
2010-02-22 19:50:13 +00:00
|
|
|
bench->getName());
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logProgress(str);
|
2009-08-04 18:17:15 +00:00
|
|
|
}
|
2011-05-18 18:37:07 +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];
|
|
|
|
|
|
|
|
outConfig = gConfigs[configIndex].fConfig;
|
|
|
|
configName = gConfigs[configIndex].fName;
|
|
|
|
backend = gConfigs[configIndex].fBackend;
|
|
|
|
glHelper = gConfigs[configIndex].fGLHelper;
|
2011-12-13 16:49:49 +00:00
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-12-13 16:49:49 +00:00
|
|
|
if (kGPU_Backend == backend &&
|
|
|
|
(NULL == glHelper || !glHelper->isValid())) {
|
2011-05-17 02:25:05 +00:00
|
|
|
continue;
|
2009-01-19 20:08:35 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-12-13 16:49:49 +00:00
|
|
|
SkDevice* device = make_device(outConfig, dim, backend, glHelper);
|
2012-07-20 23:03:42 +00:00
|
|
|
SkCanvas* canvas = NULL;
|
|
|
|
SkPicture pictureRecordFrom;
|
|
|
|
SkPicture pictureRecordTo;
|
|
|
|
switch(benchMode) {
|
|
|
|
case kDeferred_benchModes:
|
|
|
|
canvas = new SkDeferredCanvas(device);
|
|
|
|
break;
|
|
|
|
case kRecord_benchModes:
|
|
|
|
canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY);
|
|
|
|
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);
|
|
|
|
bench->draw(tempCanvas);
|
|
|
|
pictureRecordFrom.endRecording();
|
|
|
|
canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY);
|
|
|
|
canvas->ref();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kNormal_benchModes:
|
|
|
|
canvas = new SkCanvas(device);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
2012-04-16 19:11:17 +00:00
|
|
|
}
|
2011-05-17 02:25:05 +00:00
|
|
|
device->unref();
|
2012-04-16 19:11:17 +00:00
|
|
|
SkAutoUnref canvasUnref(canvas);
|
|
|
|
|
2009-01-21 03:15:13 +00:00
|
|
|
if (doClip) {
|
2012-04-16 19:11:17 +00:00
|
|
|
performClip(canvas, dim.fX, dim.fY);
|
2009-01-21 03:15:13 +00:00
|
|
|
}
|
2009-08-04 01:51:09 +00:00
|
|
|
if (doScale) {
|
2012-04-16 19:11:17 +00:00
|
|
|
performScale(canvas, dim.fX, dim.fY);
|
2009-08-04 01:51:09 +00:00
|
|
|
}
|
2009-01-21 03:15:13 +00:00
|
|
|
if (doRotate) {
|
2012-04-16 19:11:17 +00:00
|
|
|
performRotate(canvas, dim.fX, dim.fY);
|
2009-01-21 03:15:13 +00:00
|
|
|
}
|
2011-12-13 16:49:49 +00:00
|
|
|
|
2012-07-02 20:48:51 +00:00
|
|
|
// warm up caches if needed
|
2010-12-20 18:34:17 +00:00
|
|
|
if (repeatDraw > 1) {
|
2012-04-16 19:11:17 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
2012-07-20 23:03:42 +00:00
|
|
|
if (benchMode == kPictureRecord_benchModes) {
|
|
|
|
pictureRecordFrom.draw(canvas);
|
|
|
|
} else {
|
|
|
|
bench->draw(canvas);
|
|
|
|
}
|
2012-04-16 19:11:17 +00:00
|
|
|
canvas->flush();
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-12-13 16:49:49 +00:00
|
|
|
if (glHelper) {
|
|
|
|
glHelper->grContext()->flush();
|
|
|
|
SK_GL(*glHelper->glContext(), Finish());
|
2011-05-18 18:37:07 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2010-12-20 18:34:17 +00:00
|
|
|
}
|
2012-07-02 20:48:51 +00:00
|
|
|
|
|
|
|
// record timer values for each repeat, and their sum
|
|
|
|
SkString fWallStr(" msecs = ");
|
|
|
|
SkString fCpuStr(" cmsecs = ");
|
|
|
|
SkString fGpuStr(" gmsecs = ");
|
|
|
|
double fWallSum = 0.0;
|
|
|
|
double fCpuSum = 0.0;
|
|
|
|
double fGpuSum = 0.0;
|
2009-01-19 20:08:35 +00:00
|
|
|
for (int i = 0; i < repeatDraw; i++) {
|
2012-07-20 23:03:42 +00:00
|
|
|
if ((benchMode == kRecord_benchModes
|
|
|
|
|| benchMode == kPictureRecord_benchModes)) {
|
|
|
|
// This will clear the recorded commands so that they do not
|
|
|
|
// acculmulate.
|
|
|
|
canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY);
|
|
|
|
}
|
|
|
|
|
2012-07-02 20:48:51 +00:00
|
|
|
timer.start();
|
2012-04-16 19:11:17 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
2012-07-20 23:03:42 +00:00
|
|
|
if (benchMode == kPictureRecord_benchModes) {
|
|
|
|
pictureRecordFrom.draw(canvas);
|
|
|
|
} else {
|
|
|
|
bench->draw(canvas);
|
|
|
|
}
|
2012-04-16 19:11:17 +00:00
|
|
|
canvas->flush();
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-12-13 16:49:49 +00:00
|
|
|
if (glHelper) {
|
|
|
|
glHelper->grContext()->flush();
|
2011-07-14 19:03:58 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2012-07-02 20:48:51 +00:00
|
|
|
timer.end();
|
|
|
|
|
|
|
|
if (i == repeatDraw - 1) {
|
|
|
|
// no comma after the last value
|
2012-07-20 23:03:42 +00:00
|
|
|
fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall);
|
|
|
|
fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu);
|
|
|
|
fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu);
|
2012-07-02 20:48:51 +00:00
|
|
|
} else {
|
2012-07-20 23:03:42 +00:00
|
|
|
fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall);
|
|
|
|
fWallStr.appendf(",");
|
|
|
|
fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu);
|
|
|
|
fCpuStr.appendf(",");
|
|
|
|
fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu);
|
|
|
|
fGpuStr.appendf(",");
|
2012-07-02 20:48:51 +00:00
|
|
|
}
|
|
|
|
fWallSum += timer.fWall;
|
|
|
|
fCpuSum += timer.fCpu;
|
|
|
|
fGpuSum += timer.fGpu;
|
2011-07-14 19:03:58 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-12-13 16:49:49 +00:00
|
|
|
if (glHelper) {
|
|
|
|
SK_GL(*glHelper->glContext(), Finish());
|
2011-10-19 20:56:30 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2009-01-19 20:08:35 +00:00
|
|
|
if (repeatDraw > 1) {
|
2012-07-02 20:48:51 +00:00
|
|
|
// output each repeat (no average) if logPerIter is set,
|
|
|
|
// otherwise output only the average
|
|
|
|
if (!logPerIter) {
|
2012-07-20 23:03:42 +00:00
|
|
|
fWallStr.set(" msecs = ");
|
|
|
|
fWallStr.appendf(normalTimeFormat.c_str(), fWallSum / repeatDraw);
|
|
|
|
fCpuStr.set(" cmsecs = ");
|
|
|
|
fCpuStr.appendf(normalTimeFormat.c_str(), fCpuSum / repeatDraw);
|
|
|
|
fGpuStr.set(" gmsecs = ");
|
|
|
|
fGpuStr.appendf(normalTimeFormat.c_str(), fGpuSum / repeatDraw);
|
2012-07-02 20:48:51 +00:00
|
|
|
}
|
2009-08-04 18:17:15 +00:00
|
|
|
SkString str;
|
2011-06-07 19:16:02 +00:00
|
|
|
str.printf(" %4s:", configName);
|
|
|
|
if (timerWall) {
|
2012-07-02 20:48:51 +00:00
|
|
|
str += fWallStr;
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
if (timerCpu) {
|
2012-07-02 20:48:51 +00:00
|
|
|
str += fCpuStr;
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
2012-07-02 20:48:51 +00:00
|
|
|
if (timerGpu && glHelper && fGpuSum > 0) {
|
|
|
|
str += fGpuStr;
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logProgress(str);
|
2009-01-19 20:08:35 +00:00
|
|
|
}
|
2009-01-21 03:15:13 +00:00
|
|
|
if (outDir.size() > 0) {
|
2011-05-17 02:25:05 +00:00
|
|
|
saveFile(bench->getName(), configName, outDir.c_str(),
|
|
|
|
device->accessBitmap(false));
|
2009-01-21 03:15:13 +00:00
|
|
|
}
|
2009-01-19 20:08:35 +00:00
|
|
|
}
|
2012-08-07 12:58:50 +00:00
|
|
|
logger.logProgress(SkString("\n"));
|
2009-01-05 03:34:50 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-03-19 14:42:13 +00:00
|
|
|
// need to clean up here rather than post-main to allow leak detection to work
|
|
|
|
gDebugGLHelper.cleanup();
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2009-01-05 03:34:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|