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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 886233004: Print gpu/cache stats from DM. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: minor Created 5 years, 10 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
OLDNEW
1 #include "DMSrcSink.h" 1 #include "DMSrcSink.h"
2 #include "SamplePipeControllers.h" 2 #include "SamplePipeControllers.h"
3 #include "SkCommonFlags.h" 3 #include "SkCommonFlags.h"
4 #include "SkDocument.h" 4 #include "SkDocument.h"
5 #include "SkMultiPictureDraw.h" 5 #include "SkMultiPictureDraw.h"
6 #include "SkOSFile.h" 6 #include "SkOSFile.h"
7 #include "SkPictureRecorder.h" 7 #include "SkPictureRecorder.h"
8 #include "SkRandom.h" 8 #include "SkRandom.h"
9 #include "SkStream.h" 9 #include "SkStream.h"
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 : fContextType(ct) 138 : fContextType(ct)
139 , fGpuAPI(api) 139 , fGpuAPI(api)
140 , fSampleCount(samples) 140 , fSampleCount(samples)
141 , fUseDFText(dfText) 141 , fUseDFText(dfText)
142 , fThreaded(threaded) {} 142 , fThreaded(threaded) {}
143 143
144 int GPUSink::enclave() const { 144 int GPUSink::enclave() const {
145 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave; 145 return fThreaded ? kAnyThread_Enclave : kGPU_Enclave;
146 } 146 }
147 147
148 Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { 148 DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu sink runs? Requires verbose.");
mtklein 2015/02/02 16:23:17 Seems like --gpuStats is plenty enough to control
149
150 Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*) const {
149 GrContextFactory factory; 151 GrContextFactory factory;
150 const SkISize size = src.size(); 152 const SkISize size = src.size();
151 const SkImageInfo info = 153 const SkImageInfo info =
152 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul _SkAlphaType); 154 SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul _SkAlphaType);
153 SkAutoTUnref<SkSurface> surface( 155 SkAutoTUnref<SkSurface> surface(
154 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f UseDFText)); 156 NewGpuSurface(&factory, fContextType, fGpuAPI, info, fSampleCount, f UseDFText));
155 if (!surface) { 157 if (!surface) {
156 return "Could not create a surface."; 158 return "Could not create a surface.";
157 } 159 }
158 SkCanvas* canvas = surface->getCanvas(); 160 SkCanvas* canvas = surface->getCanvas();
159 Error err = src.draw(canvas); 161 Error err = src.draw(canvas);
160 if (!err.isEmpty()) { 162 if (!err.isEmpty()) {
161 return err; 163 return err;
162 } 164 }
163 canvas->flush(); 165 canvas->flush();
166 if (FLAGS_gpuStats) {
167 canvas->getGrContext()->dumpCacheStats(&fVerboseLog);
168 canvas->getGrContext()->dumpGpuStats(&fVerboseLog);
169 }
164 dst->allocPixels(info); 170 dst->allocPixels(info);
165 canvas->readPixels(dst, 0,0); 171 canvas->readPixels(dst, 0,0);
166 if (FLAGS_abandonGpuContext) { 172 if (FLAGS_abandonGpuContext) {
167 factory.abandonContexts(); 173 factory.abandonContexts();
168 } 174 }
169 return ""; 175 return "";
170 } 176 }
171 177
172 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 178 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
173 179
174 PDFSink::PDFSink() {} 180 PDFSink::PDFSink() {}
175 181
176 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst) const { 182 Error PDFSink::onDraw(const Src& src, SkBitmap*, SkWStream* dst) const {
177 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages. 183 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages.
178 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); 184 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
179 185
180 int width = src.size().width(), 186 int width = src.size().width(),
181 height = src.size().height(); 187 height = src.size().height();
182 188
183 const int kLetterWidth = 612, // 8.5 * 72 189 const int kLetterWidth = 612, // 8.5 * 72
184 kLetterHeight = 792; // 11 * 72 190 kLetterHeight = 792; // 11 * 72
185 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), 191 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
186 SkIntToScalar(kLetterHeight)); 192 SkIntToScalar(kLetterHeight));
(...skipping 18 matching lines...) Expand all
205 } 211 }
206 doc->close(); 212 doc->close();
207 dst->flush(); 213 dst->flush();
208 return ""; 214 return "";
209 } 215 }
210 216
211 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 217 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
212 218
213 SKPSink::SKPSink() {} 219 SKPSink::SKPSink() {}
214 220
215 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst) const { 221 Error SKPSink::onDraw(const Src& src, SkBitmap*, SkWStream* dst) const {
216 SkSize size; 222 SkSize size;
217 size = src.size(); 223 size = src.size();
218 SkPictureRecorder recorder; 224 SkPictureRecorder recorder;
219 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 225 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
220 if (!err.isEmpty()) { 226 if (!err.isEmpty()) {
221 return err; 227 return err;
222 } 228 }
223 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); 229 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
224 pic->serialize(dst); 230 pic->serialize(dst);
225 return ""; 231 return "";
226 } 232 }
227 233
228 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
229 235
230 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {} 236 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {}
231 237
232 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { 238 Error RasterSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*) const {
233 const SkISize size = src.size(); 239 const SkISize size = src.size();
234 // If there's an appropriate alpha type for this color type, use it, otherwi se use premul. 240 // If there's an appropriate alpha type for this color type, use it, otherwi se use premul.
235 SkAlphaType alphaType = kPremul_SkAlphaType; 241 SkAlphaType alphaType = kPremul_SkAlphaType;
236 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); 242 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
237 243
238 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType)); 244 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType));
239 dst->eraseColor(SK_ColorTRANSPARENT); 245 dst->eraseColor(SK_ColorTRANSPARENT);
240 SkCanvas canvas(*dst); 246 SkCanvas canvas(*dst);
241 return src.draw(&canvas); 247 return src.draw(&canvas);
242 } 248 }
243 249
244 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 250 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
245 251
246 ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {} 252 ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {}
247 253
248 Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream) const { 254 Error ViaMatrix::onDraw(const Src& src, SkBitmap* bitmap, SkWStream* stream) con st {
249 // We turn our arguments into a Src, then draw that Src into our Sink to fil l bitmap or stream. 255 // We turn our arguments into a Src, then draw that Src into our Sink to fil l bitmap or stream.
250 struct ProxySrc : public Src { 256 struct ProxySrc : public Src {
251 const Src& fSrc; 257 const Src& fSrc;
252 SkMatrix fMatrix; 258 SkMatrix fMatrix;
253 ProxySrc(const Src& src, SkMatrix matrix) : fSrc(src), fMatrix(matrix) { } 259 ProxySrc(const Src& src, SkMatrix matrix) : fSrc(src), fMatrix(matrix) { }
254 260
255 Error draw(SkCanvas* canvas) const SK_OVERRIDE { 261 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
256 canvas->concat(fMatrix); 262 canvas->concat(fMatrix);
257 return fSrc.draw(canvas); 263 return fSrc.draw(canvas);
258 } 264 }
259 SkISize size() const SK_OVERRIDE { return fSrc.size(); } 265 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
260 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 266 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
261 } proxy(src, fMatrix); 267 } proxy(src, fMatrix);
262 return fSink->draw(proxy, bitmap, stream); 268 return fSink->draw(proxy, bitmap, stream);
263 } 269 }
264 270
265 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 271 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
266 272
267 ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {} 273 ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {}
268 274
269 Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream) const { 275 Error ViaPipe::onDraw(const Src& src, SkBitmap* bitmap, SkWStream* stream) const {
270 // We turn ourselves into another Src that draws our argument into bitmap/st ream via pipe. 276 // We turn ourselves into another Src that draws our argument into bitmap/st ream via pipe.
271 struct ProxySrc : public Src { 277 struct ProxySrc : public Src {
272 const Src& fSrc; 278 const Src& fSrc;
273 ProxySrc(const Src& src) : fSrc(src) {} 279 ProxySrc(const Src& src) : fSrc(src) {}
274 280
275 Error draw(SkCanvas* canvas) const SK_OVERRIDE { 281 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
276 SkISize size = this->size(); 282 SkISize size = this->size();
277 PipeController controller(canvas, &SkImageDecoder::DecodeMemory); 283 PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
278 SkGPipeWriter pipe; 284 SkGPipeWriter pipe;
279 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which does n't use any flags. 285 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which does n't use any flags.
280 return fSrc.draw(pipe.startRecording(&controller, kFlags, size.width (), size.height())); 286 return fSrc.draw(pipe.startRecording(&controller, kFlags, size.width (), size.height()));
281 } 287 }
282 SkISize size() const SK_OVERRIDE { return fSrc.size(); } 288 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
283 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 289 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
284 } proxy(src); 290 } proxy(src);
285 return fSink->draw(proxy, bitmap, stream); 291 return fSink->draw(proxy, bitmap, stream);
286 } 292 }
287 293
288 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 294 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
289 295
290 ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {} 296 ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {}
291 297
292 Error ViaSerialization::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream ) const { 298 Error ViaSerialization::onDraw(const Src& src, SkBitmap* bitmap, SkWStream* stre am) const {
293 // Record our Src into a picture. 299 // Record our Src into a picture.
294 SkSize size; 300 SkSize size;
295 size = src.size(); 301 size = src.size();
296 SkPictureRecorder recorder; 302 SkPictureRecorder recorder;
297 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 303 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
298 if (!err.isEmpty()) { 304 if (!err.isEmpty()) {
299 return err; 305 return err;
300 } 306 }
301 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); 307 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
302 308
(...skipping 20 matching lines...) Expand all
323 } 329 }
324 330
325 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 331 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
326 332
327 ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink) 333 ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
328 : fW(w) 334 : fW(w)
329 , fH(h) 335 , fH(h)
330 , fFactory(factory) 336 , fFactory(factory)
331 , fSink(sink) {} 337 , fSink(sink) {}
332 338
333 Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream) const { 339 Error ViaTiles::onDraw(const Src& src, SkBitmap* bitmap, SkWStream* stream) cons t {
334 // Record our Src into a picture. 340 // Record our Src into a picture.
335 SkSize size; 341 SkSize size;
336 size = src.size(); 342 size = src.size();
337 SkPictureRecorder recorder; 343 SkPictureRecorder recorder;
338 Error err = src.draw(recorder.beginRecording(size.width(), size.height(), fF actory.get())); 344 Error err = src.draw(recorder.beginRecording(size.width(), size.height(), fF actory.get()));
339 if (!err.isEmpty()) { 345 if (!err.isEmpty()) {
340 return err; 346 return err;
341 } 347 }
342 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); 348 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
343 349
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 surfaces.unrefAll(); 388 surfaces.unrefAll();
383 return ""; 389 return "";
384 } 390 }
385 SkISize size() const SK_OVERRIDE { return fSize; } 391 SkISize size() const SK_OVERRIDE { return fSize; }
386 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 392 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
387 } proxy(fW, fH, pic, src.size()); 393 } proxy(fW, fH, pic, src.size());
388 return fSink->draw(proxy, bitmap, stream); 394 return fSink->draw(proxy, bitmap, stream);
389 } 395 }
390 396
391 } // namespace DM 397 } // namespace DM
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698