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

Side by Side Diff: bench/SKPBench.cpp

Issue 1541983002: Add tileSKP option to nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix scales Created 4 years, 11 months 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') | no next file » | 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" 10 #include "SkMultiPictureDraw.h"
11 #include "SkSurface.h" 11 #include "SkSurface.h"
12 12
13 #if SK_SUPPORT_GPU 13 #if SK_SUPPORT_GPU
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #endif 15 #endif
16 16
17 #include <stdlib.h>
18
19 DEFINE_bool(tileSKP, true, "Tile skp benches?");
20
17 // These CPU tile sizes are not good per se, but they are similar to what Chrome uses. 21 // These CPU tile sizes are not good per se, but they are similar to what Chrome uses.
18 DEFINE_int32(CPUbenchTileW, 256, "Tile width used for CPU SKP playback."); 22 DEFINE_int32(CPUbenchTileW, 256, "Tile width used for CPU SKP playback.");
19 DEFINE_int32(CPUbenchTileH, 256, "Tile height used for CPU SKP playback."); 23 DEFINE_int32(CPUbenchTileH, 256, "Tile height used for CPU SKP playback.");
20 24
21 DEFINE_int32(GPUbenchTileW, 1600, "Tile width used for GPU SKP playback."); 25 DEFINE_int32(GPUbenchTileW, 1600, "Tile width used for GPU SKP playback.");
22 DEFINE_int32(GPUbenchTileH, 512, "Tile height used for GPU SKP playback."); 26 DEFINE_int32(GPUbenchTileH, 512, "Tile height used for GPU SKP playback.");
23 27
24 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale, 28 SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale,
25 bool useMultiPictureDraw, bool doLooping) 29 bool useMultiPictureDraw, bool doLooping)
26 : fPic(SkRef(pic)) 30 : fPic(SkRef(pic))
27 , fClip(clip) 31 , fClip(clip)
28 , fScale(scale) 32 , fScale(scale)
29 , fName(name) 33 , fName(name)
30 , fUseMultiPictureDraw(useMultiPictureDraw) 34 , fUseMultiPictureDraw(useMultiPictureDraw)
31 , fDoLooping(doLooping) { 35 , fDoLooping(doLooping) {
32 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for perf.skia.org traces. 36 fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for perf.skia.org traces.
33 if (useMultiPictureDraw) { 37 if (useMultiPictureDraw) {
38 if (!FLAGS_tileSKP) {
39 SkDebugf("Tried to use SkMultiPictureDraw with a non-tiled SKP. Abor ting. "
40 "(Please use --mpd false.)");
41 exit(-1);
42 }
34 fUniqueName.append("_mpd"); 43 fUniqueName.append("_mpd");
35 } 44 }
36 } 45 }
37 46
38 SKPBench::~SKPBench() { 47 SKPBench::~SKPBench() {
39 for (int i = 0; i < fSurfaces.count(); ++i) { 48 for (int i = 0; i < fSurfaces.count(); ++i) {
40 fSurfaces[i]->unref(); 49 fSurfaces[i]->unref();
41 } 50 }
42 } 51 }
43 52
44 const char* SKPBench::onGetName() { 53 const char* SKPBench::onGetName() {
45 return fName.c_str(); 54 return fName.c_str();
46 } 55 }
47 56
48 const char* SKPBench::onGetUniqueName() { 57 const char* SKPBench::onGetUniqueName() {
49 return fUniqueName.c_str(); 58 return fUniqueName.c_str();
50 } 59 }
51 60
52 void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) { 61 void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
62 if (!FLAGS_tileSKP) {
63 return;
64 }
65
53 SkIRect bounds; 66 SkIRect bounds;
54 SkAssertResult(canvas->getClipDeviceBounds(&bounds)); 67 SkAssertResult(canvas->getClipDeviceBounds(&bounds));
55 68
56 const bool gpu = canvas->getGrContext() != nullptr; 69 const bool gpu = canvas->getGrContext() != nullptr;
57 int tileW = gpu ? FLAGS_GPUbenchTileW : FLAGS_CPUbenchTileW, 70 int tileW = gpu ? FLAGS_GPUbenchTileW : FLAGS_CPUbenchTileW,
58 tileH = gpu ? FLAGS_GPUbenchTileH : FLAGS_CPUbenchTileH; 71 tileH = gpu ? FLAGS_GPUbenchTileH : FLAGS_CPUbenchTileH;
59 72
60 tileW = SkTMin(tileW, bounds.width()); 73 tileW = SkTMin(tileW, bounds.width());
61 tileH = SkTMin(tileH, bounds.height()); 74 tileH = SkTMin(tileH, bounds.height());
62 75
(...skipping 17 matching lines...) Expand all
80 clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect. fTop)); 93 clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect. fTop));
81 fSurfaces.top()->getCanvas()->clipRect(clip); 94 fSurfaces.top()->getCanvas()->clipRect(clip);
82 95
83 fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix()); 96 fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix());
84 fSurfaces.top()->getCanvas()->scale(fScale, fScale); 97 fSurfaces.top()->getCanvas()->scale(fScale, fScale);
85 } 98 }
86 } 99 }
87 } 100 }
88 101
89 void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) { 102 void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) {
103 if (!FLAGS_tileSKP) {
104 return;
105 }
106
90 // Draw the last set of tiles into the master canvas in case we're 107 // Draw the last set of tiles into the master canvas in case we're
91 // saving the images 108 // saving the images
92 for (int i = 0; i < fTileRects.count(); ++i) { 109 for (int i = 0; i < fTileRects.count(); ++i) {
93 SkAutoTUnref<SkImage> image(fSurfaces[i]->newImageSnapshot()); 110 SkAutoTUnref<SkImage> image(fSurfaces[i]->newImageSnapshot());
94 canvas->drawImage(image, 111 canvas->drawImage(image,
95 SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTil eRects[i].fTop)); 112 SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTil eRects[i].fTop));
96 SkSafeSetNull(fSurfaces[i]); 113 SkSafeSetNull(fSurfaces[i]);
97 } 114 }
98 115
99 fSurfaces.rewind(); 116 fSurfaces.rewind();
100 fTileRects.rewind(); 117 fTileRects.rewind();
101 } 118 }
102 119
103 bool SKPBench::isSuitableFor(Backend backend) { 120 bool SKPBench::isSuitableFor(Backend backend) {
104 return backend != kNonRendering_Backend; 121 return backend != kNonRendering_Backend;
105 } 122 }
106 123
107 SkIPoint SKPBench::onGetSize() { 124 SkIPoint SKPBench::onGetSize() {
108 return SkIPoint::Make(fClip.width(), fClip.height()); 125 return SkIPoint::Make(fClip.width(), fClip.height());
109 } 126 }
110 127
111 void SKPBench::onDraw(int loops, SkCanvas* canvas) { 128 void SKPBench::onDraw(int loops, SkCanvas* canvas) {
112 SkASSERT(fDoLooping || 1 == loops); 129 SkASSERT(fDoLooping || 1 == loops);
113 if (fUseMultiPictureDraw) { 130 while (1) {
114 for (int i = 0; i < loops; i++) { 131 if (!FLAGS_tileSKP) {
132 this->drawPicture(canvas);
133 } else if (fUseMultiPictureDraw) {
115 this->drawMPDPicture(); 134 this->drawMPDPicture();
135 } else {
136 this->drawPictureTiled();
116 } 137 }
117 } else { 138 if (0 == --loops) {
118 for (int i = 0; i < loops; i++) { 139 break;
119 this->drawPicture();
120 } 140 }
141 #if SK_SUPPORT_GPU
142 // Ensure the GrContext doesn't batch across draw loops.
143 if (GrContext* context = canvas->getGrContext()) {
144 context->flush();
145 }
146 #endif
121 } 147 }
122 #if SK_SUPPORT_GPU 148 }
123 // Ensure the GrContext doesn't batch across draw loops. 149
124 if (GrContext* context = canvas->getGrContext()) { 150 void SKPBench::drawPicture(SkCanvas* canvas) {
125 context->flush(); 151 canvas->save();
126 } 152 canvas->scale(fScale, fScale);
127 #endif 153 canvas->drawPicture(fPic);
154 canvas->restore();
128 } 155 }
129 156
130 void SKPBench::drawMPDPicture() { 157 void SKPBench::drawMPDPicture() {
131 SkMultiPictureDraw mpd; 158 SkMultiPictureDraw mpd;
132 159
133 for (int j = 0; j < fTileRects.count(); ++j) { 160 for (int j = 0; j < fTileRects.count(); ++j) {
134 SkMatrix trans; 161 SkMatrix trans;
135 trans.setTranslate(-fTileRects[j].fLeft/fScale, 162 trans.setTranslate(-fTileRects[j].fLeft/fScale,
136 -fTileRects[j].fTop/fScale); 163 -fTileRects[j].fTop/fScale);
137 mpd.add(fSurfaces[j]->getCanvas(), fPic, &trans); 164 mpd.add(fSurfaces[j]->getCanvas(), fPic, &trans);
138 } 165 }
139 166
140 mpd.draw(); 167 mpd.draw();
141 168
142 for (int j = 0; j < fTileRects.count(); ++j) { 169 for (int j = 0; j < fTileRects.count(); ++j) {
143 fSurfaces[j]->getCanvas()->flush(); 170 fSurfaces[j]->getCanvas()->flush();
144 } 171 }
145 } 172 }
146 173
147 void SKPBench::drawPicture() { 174 void SKPBench::drawPictureTiled() {
148 for (int j = 0; j < fTileRects.count(); ++j) { 175 for (int j = 0; j < fTileRects.count(); ++j) {
149 const SkMatrix trans = SkMatrix::MakeTrans(-fTileRects[j].fLeft / fScale , 176 const SkMatrix trans = SkMatrix::MakeTrans(-fTileRects[j].fLeft / fScale ,
150 -fTileRects[j].fTop / fScale) ; 177 -fTileRects[j].fTop / fScale) ;
151 fSurfaces[j]->getCanvas()->drawPicture(fPic, &trans, nullptr); 178 fSurfaces[j]->getCanvas()->drawPicture(fPic, &trans, nullptr);
152 } 179 }
153 180
154 for (int j = 0; j < fTileRects.count(); ++j) { 181 for (int j = 0; j < fTileRects.count(); ++j) {
155 fSurfaces[j]->getCanvas()->flush(); 182 fSurfaces[j]->getCanvas()->flush();
156 } 183 }
157 } 184 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 context->freeGpuResources(); 216 context->freeGpuResources();
190 context->resetContext(); 217 context->resetContext();
191 context->getGpu()->resetShaderCacheForTesting(); 218 context->getGpu()->resetShaderCacheForTesting();
192 draw_pic_for_stats(canvas, context, fPic, keys, values, "first_frame"); 219 draw_pic_for_stats(canvas, context, fPic, keys, values, "first_frame");
193 220
194 // draw second frame 221 // draw second frame
195 draw_pic_for_stats(canvas, context, fPic, keys, values, "second_frame"); 222 draw_pic_for_stats(canvas, context, fPic, keys, values, "second_frame");
196 223
197 #endif 224 #endif
198 } 225 }
OLDNEW
« no previous file with comments | « bench/SKPBench.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698