Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: bench/SKPBench.cpp

Issue 731973005: Add MultiPictureDraw to nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Disable multithreading in nanobench Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SKPBench.h" 8 #include "SKPBench.h"
9 #include "SkCommandLineFlags.h" 9 #include "SkCommandLineFlags.h"
10 #include "SkMultiPictureDraw.h"
11 #include "SkSurface.h"
10 12
11 DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback."); 13 DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback.");
12 14
13 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale) 15 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale,
16 bool useMultiPictureDraw)
14 : fPic(SkRef(pic)) 17 : fPic(SkRef(pic))
15 , fClip(clip) 18 , fClip(clip)
16 , fScale(scale) 19 , fScale(scale)
17 , fName(name) { 20 , fName(name)
21 , fUseMultiPictureDraw(useMultiPictureDraw) {
18 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for skiaperf.com traces. 22 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for skiaperf.com traces.
23 if (useMultiPictureDraw) {
24 fUniqueName.append("_mpd");
25 }
26 }
27
28 SKPBench::~SKPBench() {
29 for (int i = 0; i < fSurfaces.count(); ++i) {
30 fSurfaces[i]->unref();
31 }
19 } 32 }
20 33
21 const char* SKPBench::onGetName() { 34 const char* SKPBench::onGetName() {
22 return fName.c_str(); 35 return fName.c_str();
23 } 36 }
24 37
25 const char* SKPBench::onGetUniqueName() { 38 const char* SKPBench::onGetUniqueName() {
26 return fUniqueName.c_str(); 39 return fUniqueName.c_str();
27 } 40 }
28 41
42 void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
43 if (!fUseMultiPictureDraw) {
44 return;
45 }
46
47 SkIRect bounds;
48 SkAssertResult(canvas->getClipDeviceBounds(&bounds));
49
50 int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(FLAGS_benchTi le));
51 int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(FLAGS_benchTi le));
52
53 fSurfaces.setReserve(xTiles * yTiles);
54 fTileRects.setReserve(xTiles * yTiles);
55
56 SkImageInfo ii = canvas->imageInfo().makeWH(FLAGS_benchTile, FLAGS_benchTile );
57
58 for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) {
59 for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTile) {
60 *fTileRects.append() = SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAG S_benchTile);
61 *fSurfaces.push() = canvas->newSurface(ii);
62 fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix());
63 fSurfaces.top()->getCanvas()->scale(fScale, fScale);
64 }
65 }
66 }
67
68 void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) {
69 if (!fUseMultiPictureDraw) {
70 return;
71 }
72
73 // Draw the last set of tiles into the master canvas in case we're
74 // saving the images
75 for (int i = 0; i < fTileRects.count(); ++i) {
76 canvas->drawImage(fSurfaces[i]->newImageSnapshot(),
77 SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTil eRects[i].fTop));
78 SkSafeSetNull(fSurfaces[i]);
79 }
80
81 fSurfaces.rewind();
82 fTileRects.rewind();
83 }
84
29 bool SKPBench::isSuitableFor(Backend backend) { 85 bool SKPBench::isSuitableFor(Backend backend) {
30 return backend != kNonRendering_Backend; 86 return backend != kNonRendering_Backend;
31 } 87 }
32 88
33 SkIPoint SKPBench::onGetSize() { 89 SkIPoint SKPBench::onGetSize() {
34 return SkIPoint::Make(fClip.width(), fClip.height()); 90 return SkIPoint::Make(fClip.width(), fClip.height());
35 } 91 }
36 92
37 void SKPBench::onDraw(const int loops, SkCanvas* canvas) { 93 void SKPBench::onDraw(const int loops, SkCanvas* canvas) {
38 SkIRect bounds; 94 if (fUseMultiPictureDraw) {
39 SkAssertResult(canvas->getClipDeviceBounds(&bounds)); 95 for (int i = 0; i < loops; i++) {
96 SkMultiPictureDraw mpd;
40 97
41 SkAutoCanvasRestore overall(canvas, true/*save now*/); 98 for (int i = 0; i < fTileRects.count(); ++i) {
42 canvas->scale(fScale, fScale); 99 SkMatrix trans;
100 trans.setTranslate(-fTileRects[i].fLeft/fScale,
101 -fTileRects[i].fTop/fScale);
102 mpd.add(fSurfaces[i]->getCanvas(), fPic, &trans);
103 }
43 104
44 for (int i = 0; i < loops; i++) { 105 mpd.draw();
45 for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) { 106
46 for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTile) { 107 for (int i = 0; i < fTileRects.count(); ++i) {
47 SkAutoCanvasRestore perTile(canvas, true/*save now*/); 108 fSurfaces[i]->getCanvas()->flush();
48 canvas->clipRect(SkRect::Make(
49 SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAGS_bench Tile)));
50 fPic->playback(canvas);
51 } 109 }
52 } 110 }
53 canvas->flush(); 111 } else {
112 SkIRect bounds;
113 SkAssertResult(canvas->getClipDeviceBounds(&bounds));
114
115 SkAutoCanvasRestore overall(canvas, true/*save now*/);
116 canvas->scale(fScale, fScale);
117
118 for (int i = 0; i < loops; i++) {
119 for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) {
120 for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTi le) {
121 SkAutoCanvasRestore perTile(canvas, true/*save now*/);
122 canvas->clipRect(SkRect::Make(
123 SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAGS_b enchTile)));
124 fPic->playback(canvas);
125 }
126 }
127
128 canvas->flush();
129 }
54 } 130 }
55 } 131 }
OLDNEW
« no previous file with comments | « bench/SKPBench.h ('k') | bench/nanobench.cpp » ('j') | bench/nanobench.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698