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

Side by Side Diff: bench/SKPBench.cpp

Issue 750583002: Revert of Add MultiPictureDraw to nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « bench/SKPBench.h ('k') | bench/nanobench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
12 10
13 DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback."); 11 DEFINE_int32(benchTile, 256, "Tile dimension used for SKP playback.");
14 12
15 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale, 13 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale)
16 bool useMultiPictureDraw)
17 : fPic(SkRef(pic)) 14 : fPic(SkRef(pic))
18 , fClip(clip) 15 , fClip(clip)
19 , fScale(scale) 16 , fScale(scale)
20 , fName(name) 17 , fName(name) {
21 , fUseMultiPictureDraw(useMultiPictureDraw) {
22 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for skiaperf.com traces. 18 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 }
32 } 19 }
33 20
34 const char* SKPBench::onGetName() { 21 const char* SKPBench::onGetName() {
35 return fName.c_str(); 22 return fName.c_str();
36 } 23 }
37 24
38 const char* SKPBench::onGetUniqueName() { 25 const char* SKPBench::onGetUniqueName() {
39 return fUniqueName.c_str(); 26 return fUniqueName.c_str();
40 } 27 }
41 28
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
85 bool SKPBench::isSuitableFor(Backend backend) { 29 bool SKPBench::isSuitableFor(Backend backend) {
86 return backend != kNonRendering_Backend; 30 return backend != kNonRendering_Backend;
87 } 31 }
88 32
89 SkIPoint SKPBench::onGetSize() { 33 SkIPoint SKPBench::onGetSize() {
90 return SkIPoint::Make(fClip.width(), fClip.height()); 34 return SkIPoint::Make(fClip.width(), fClip.height());
91 } 35 }
92 36
93 void SKPBench::onDraw(const int loops, SkCanvas* canvas) { 37 void SKPBench::onDraw(const int loops, SkCanvas* canvas) {
94 if (fUseMultiPictureDraw) { 38 SkIRect bounds;
95 for (int i = 0; i < loops; i++) { 39 SkAssertResult(canvas->getClipDeviceBounds(&bounds));
96 SkMultiPictureDraw mpd;
97 40
98 for (int i = 0; i < fTileRects.count(); ++i) { 41 SkAutoCanvasRestore overall(canvas, true/*save now*/);
99 SkMatrix trans; 42 canvas->scale(fScale, fScale);
100 trans.setTranslate(-fTileRects[i].fLeft/fScale,
101 -fTileRects[i].fTop/fScale);
102 mpd.add(fSurfaces[i]->getCanvas(), fPic, &trans);
103 }
104 43
105 mpd.draw(); 44 for (int i = 0; i < loops; i++) {
106 45 for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) {
107 for (int i = 0; i < fTileRects.count(); ++i) { 46 for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTile) {
108 fSurfaces[i]->getCanvas()->flush(); 47 SkAutoCanvasRestore perTile(canvas, true/*save now*/);
48 canvas->clipRect(SkRect::Make(
49 SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAGS_bench Tile)));
50 fPic->playback(canvas);
109 } 51 }
110 } 52 }
111 } else { 53 canvas->flush();
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 }
130 } 54 }
131 } 55 }
OLDNEW
« no previous file with comments | « bench/SKPBench.h ('k') | bench/nanobench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698