OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2012 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 */ | |
7 #include "Benchmark.h" | |
8 #include "SkDeferredCanvas.h" | |
9 #include "SkDevice.h" | |
10 #include "SkString.h" | |
11 | |
12 class DeferredCanvasBench : public Benchmark { | |
13 public: | |
14 DeferredCanvasBench(const char name[]) { | |
15 fName.printf("deferred_canvas_%s", name); | |
16 } | |
17 | |
18 enum { | |
19 CANVAS_WIDTH = 200, | |
20 CANVAS_HEIGHT = 200, | |
21 }; | |
22 protected: | |
23 virtual const char* onGetName() { | |
24 return fName.c_str(); | |
25 } | |
26 | |
27 virtual void onDraw(const int loops, SkCanvas* canvas) { | |
28 #if 0 // what specifically are we interested in timing here? | |
29 SkBaseDevice *device = canvas->getDevice()->createCompatibleDevice( | |
30 SkBitmap::kARGB_8888_Config, CANVAS_WIDTH, CANVAS_HEIGHT, false); | |
31 | |
32 SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(d
evice)); | |
33 device->unref(); | |
34 | |
35 initDeferredCanvas(deferredCanvas); | |
36 drawInDeferredCanvas(loops, deferredCanvas); | |
37 finalizeDeferredCanvas(deferredCanvas); | |
38 deferredCanvas->flush(); | |
39 #endif | |
40 } | |
41 | |
42 virtual void initDeferredCanvas(SkDeferredCanvas* canvas) = 0; | |
43 virtual void drawInDeferredCanvas(const int loops, SkDeferredCanvas* canvas)
= 0; | |
44 virtual void finalizeDeferredCanvas(SkDeferredCanvas* canvas) = 0; | |
45 | |
46 SkString fName; | |
47 | |
48 private: | |
49 typedef Benchmark INHERITED; | |
50 }; | |
51 | |
52 class SimpleNotificationClient : public SkDeferredCanvas::NotificationClient { | |
53 public: | |
54 SimpleNotificationClient() : fDummy(false) {} | |
55 | |
56 //bogus virtual implementations that just do something small | |
57 virtual void prepareForDraw() SK_OVERRIDE {fDummy = true;} | |
58 virtual void storageAllocatedForRecordingChanged(size_t) SK_OVERRIDE {fDummy
= false;} | |
59 virtual void flushedDrawCommands() SK_OVERRIDE {fDummy = !fDummy;} | |
60 private: | |
61 bool fDummy; | |
62 | |
63 typedef SkDeferredCanvas::NotificationClient INHERITED; | |
64 }; | |
65 | |
66 // Test that records very simple draw operations. | |
67 // This benchmark aims to capture performance fluctuations in the recording | |
68 // overhead of SkDeferredCanvas | |
69 class DeferredRecordBench : public DeferredCanvasBench { | |
70 public: | |
71 DeferredRecordBench() | |
72 : INHERITED("record") { | |
73 } | |
74 | |
75 protected: | |
76 | |
77 virtual void initDeferredCanvas(SkDeferredCanvas* canvas) SK_OVERRIDE { | |
78 canvas->setNotificationClient(&fNotificationClient); | |
79 } | |
80 | |
81 virtual void drawInDeferredCanvas(const int loops, SkDeferredCanvas* canvas)
SK_OVERRIDE { | |
82 SkRect rect; | |
83 rect.setXYWH(0, 0, 10, 10); | |
84 SkPaint paint; | |
85 for (int i = 0; i < loops; i++) { | |
86 canvas->save(); | |
87 canvas->translate(SkIntToScalar(i * 27 % CANVAS_WIDTH), SkIntToScala
r(i * 13 % CANVAS_HEIGHT)); | |
88 canvas->drawRect(rect, paint); | |
89 canvas->restore(); | |
90 } | |
91 } | |
92 | |
93 virtual void finalizeDeferredCanvas(SkDeferredCanvas* canvas) SK_OVERRIDE { | |
94 canvas->clear(0x0); | |
95 canvas->setNotificationClient(NULL); | |
96 } | |
97 | |
98 private: | |
99 typedef DeferredCanvasBench INHERITED; | |
100 SimpleNotificationClient fNotificationClient; | |
101 }; | |
102 | |
103 | |
104 /////////////////////////////////////////////////////////////////////////////// | |
105 | |
106 DEF_BENCH( return new DeferredRecordBench(); ) | |
OLD | NEW |