2012-08-14 13:36:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkDeferredCanvas.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
class DeferredCanvasBench : public SkBenchmark {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
DeferredCanvasBench(const char name[]) {
|
2012-08-14 13:36:26 +00:00
|
|
|
fName.printf("deferred_canvas_%s", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CANVAS_WIDTH = 200,
|
|
|
|
CANVAS_HEIGHT = 200,
|
|
|
|
};
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) {
|
2014-02-04 15:34:10 +00:00
|
|
|
#if 0 // what specifically are we interested in timing here?
|
2013-08-29 11:54:56 +00:00
|
|
|
SkBaseDevice *device = canvas->getDevice()->createCompatibleDevice(
|
2012-09-17 11:52:48 +00:00
|
|
|
SkBitmap::kARGB_8888_Config, CANVAS_WIDTH, CANVAS_HEIGHT, false);
|
|
|
|
|
2013-08-09 14:24:59 +00:00
|
|
|
SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(device));
|
2012-09-17 11:52:48 +00:00
|
|
|
device->unref();
|
2012-08-14 13:36:26 +00:00
|
|
|
|
|
|
|
initDeferredCanvas(deferredCanvas);
|
2013-12-03 18:17:16 +00:00
|
|
|
drawInDeferredCanvas(loops, deferredCanvas);
|
2012-08-14 13:36:26 +00:00
|
|
|
finalizeDeferredCanvas(deferredCanvas);
|
2013-05-28 17:39:08 +00:00
|
|
|
deferredCanvas->flush();
|
2014-02-04 15:34:10 +00:00
|
|
|
#endif
|
2012-08-14 13:36:26 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 17:39:08 +00:00
|
|
|
virtual void initDeferredCanvas(SkDeferredCanvas* canvas) = 0;
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void drawInDeferredCanvas(const int loops, SkDeferredCanvas* canvas) = 0;
|
2013-05-28 17:39:08 +00:00
|
|
|
virtual void finalizeDeferredCanvas(SkDeferredCanvas* canvas) = 0;
|
2012-08-14 13:36:26 +00:00
|
|
|
|
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SimpleNotificationClient : public SkDeferredCanvas::NotificationClient {
|
|
|
|
public:
|
|
|
|
SimpleNotificationClient() : fDummy(false) {}
|
|
|
|
|
|
|
|
//bogus virtual implementations that just do something small
|
|
|
|
virtual void prepareForDraw() SK_OVERRIDE {fDummy = true;}
|
|
|
|
virtual void storageAllocatedForRecordingChanged(size_t) SK_OVERRIDE {fDummy = false;}
|
|
|
|
virtual void flushedDrawCommands() SK_OVERRIDE {fDummy = !fDummy;}
|
|
|
|
private:
|
|
|
|
bool fDummy;
|
2013-02-07 21:02:23 +00:00
|
|
|
|
|
|
|
typedef SkDeferredCanvas::NotificationClient INHERITED;
|
2012-08-14 13:36:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Test that records very simple draw operations.
|
|
|
|
// This benchmark aims to capture performance fluctuations in the recording
|
|
|
|
// overhead of SkDeferredCanvas
|
|
|
|
class DeferredRecordBench : public DeferredCanvasBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
DeferredRecordBench()
|
|
|
|
: INHERITED("record") {
|
2012-08-14 13:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2013-05-28 17:39:08 +00:00
|
|
|
virtual void initDeferredCanvas(SkDeferredCanvas* canvas) SK_OVERRIDE {
|
|
|
|
canvas->setNotificationClient(&fNotificationClient);
|
2012-08-14 13:36:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void drawInDeferredCanvas(const int loops, SkDeferredCanvas* canvas) SK_OVERRIDE {
|
2012-08-14 13:36:26 +00:00
|
|
|
SkRect rect;
|
|
|
|
rect.setXYWH(0, 0, 10, 10);
|
|
|
|
SkPaint paint;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2014-04-18 14:19:31 +00:00
|
|
|
canvas->save();
|
2013-05-28 17:39:08 +00:00
|
|
|
canvas->translate(SkIntToScalar(i * 27 % CANVAS_WIDTH), SkIntToScalar(i * 13 % CANVAS_HEIGHT));
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->restore();
|
2012-08-14 13:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 17:39:08 +00:00
|
|
|
virtual void finalizeDeferredCanvas(SkDeferredCanvas* canvas) SK_OVERRIDE {
|
|
|
|
canvas->clear(0x0);
|
|
|
|
canvas->setNotificationClient(NULL);
|
2012-08-14 13:36:26 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-08-14 13:36:26 +00:00
|
|
|
private:
|
|
|
|
typedef DeferredCanvasBench INHERITED;
|
2012-08-20 14:25:04 +00:00
|
|
|
SimpleNotificationClient fNotificationClient;
|
2012-08-14 13:36:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new DeferredRecordBench(); )
|