OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "BenchTimer.h" | 8 #include "BenchTimer.h" |
9 #include "ResultsWriter.h" | 9 #include "ResultsWriter.h" |
10 #include "SkBenchLogger.h" | 10 #include "SkBenchLogger.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 SkString filename; | 115 SkString filename; |
116 make_filename(name, &filename); | 116 make_filename(name, &filename); |
117 filename.appendf("_%s.png", config); | 117 filename.appendf("_%s.png", config); |
118 SkString path = SkOSPath::SkPathJoin(dir, filename.c_str()); | 118 SkString path = SkOSPath::SkPathJoin(dir, filename.c_str()); |
119 ::remove(path.c_str()); | 119 ::remove(path.c_str()); |
120 | 120 |
121 SkFILEWStream stream(path.c_str()); | 121 SkFILEWStream stream(path.c_str()); |
122 stream.write(data->data(), data->size()); | 122 stream.write(data->data(), data->size()); |
123 } | 123 } |
124 | 124 |
125 static void performClip(SkCanvas* canvas, int w, int h) { | 125 static void perform_clip(SkCanvas* canvas, int w, int h) { |
126 SkRect r; | 126 SkRect r; |
127 | 127 |
128 r.set(SkIntToScalar(10), SkIntToScalar(10), | 128 r.set(SkIntToScalar(10), SkIntToScalar(10), |
129 SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); | 129 SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); |
130 canvas->clipRect(r, SkRegion::kIntersect_Op); | 130 canvas->clipRect(r, SkRegion::kIntersect_Op); |
131 | 131 |
132 r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), | 132 r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), |
133 SkIntToScalar(w-10), SkIntToScalar(h-10)); | 133 SkIntToScalar(w-10), SkIntToScalar(h-10)); |
134 canvas->clipRect(r, SkRegion::kXOR_Op); | 134 canvas->clipRect(r, SkRegion::kXOR_Op); |
135 } | 135 } |
136 | 136 |
137 static void performRotate(SkCanvas* canvas, int w, int h) { | 137 static void perform_rotate(SkCanvas* canvas, int w, int h) { |
138 const SkScalar x = SkIntToScalar(w) / 2; | 138 const SkScalar x = SkIntToScalar(w) / 2; |
139 const SkScalar y = SkIntToScalar(h) / 2; | 139 const SkScalar y = SkIntToScalar(h) / 2; |
140 | 140 |
141 canvas->translate(x, y); | 141 canvas->translate(x, y); |
142 canvas->rotate(SkIntToScalar(35)); | 142 canvas->rotate(SkIntToScalar(35)); |
143 canvas->translate(-x, -y); | 143 canvas->translate(-x, -y); |
144 } | 144 } |
145 | 145 |
146 static void performScale(SkCanvas* canvas, int w, int h) { | 146 static void perform_scale(SkCanvas* canvas, int w, int h) { |
147 const SkScalar x = SkIntToScalar(w) / 2; | 147 const SkScalar x = SkIntToScalar(w) / 2; |
148 const SkScalar y = SkIntToScalar(h) / 2; | 148 const SkScalar y = SkIntToScalar(h) / 2; |
149 | 149 |
150 canvas->translate(x, y); | 150 canvas->translate(x, y); |
151 // just enough so we can't take the sprite case | 151 // just enough so we can't take the sprite case |
152 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); | 152 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
153 canvas->translate(-x, -y); | 153 canvas->translate(-x, -y); |
154 } | 154 } |
155 | 155 |
156 static SkSurface* make_surface(SkColorType colorType, const SkIPoint& size, | 156 static SkSurface* make_surface(SkColorType colorType, const SkIPoint& size, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 if (SkBenchmark::kGPU_Backend == config.backend) { | 473 if (SkBenchmark::kGPU_Backend == config.backend) { |
474 context = gContextFactory.get(config.contextType); | 474 context = gContextFactory.get(config.contextType); |
475 if (NULL == context) { | 475 if (NULL == context) { |
476 continue; | 476 continue; |
477 } | 477 } |
478 glContext = gContextFactory.getGLContext(config.contextType); | 478 glContext = gContextFactory.getGLContext(config.contextType); |
479 } | 479 } |
480 #endif | 480 #endif |
481 | 481 |
482 SkAutoTUnref<SkCanvas> canvas; | 482 SkAutoTUnref<SkCanvas> canvas; |
483 SkPicture recordFrom, recordTo; | 483 SkAutoTUnref<SkPicture> recordFrom; |
| 484 SkPictureRecorder recorderTo; |
484 const SkIPoint dim = bench->getSize(); | 485 const SkIPoint dim = bench->getSize(); |
485 | 486 |
486 const SkPicture::RecordingFlags kRecordFlags = | 487 const SkPicture::RecordingFlags kRecordFlags = |
487 SkPicture::kUsePathBoundsForClip_RecordingFlag; | 488 SkPicture::kUsePathBoundsForClip_RecordingFlag; |
488 | 489 |
489 SkAutoTUnref<SkSurface> surface; | 490 SkAutoTUnref<SkSurface> surface; |
490 if (SkBenchmark::kNonRendering_Backend != config.backend) { | 491 if (SkBenchmark::kNonRendering_Backend != config.backend) { |
491 surface.reset(make_surface(config.fColorType, | 492 surface.reset(make_surface(config.fColorType, |
492 dim, | 493 dim, |
493 config.backend, | 494 config.backend, |
494 config.sampleCount, | 495 config.sampleCount, |
495 context)); | 496 context)); |
496 if (!surface.get()) { | 497 if (!surface.get()) { |
497 logger.logError(SkStringPrintf( | 498 logger.logError(SkStringPrintf( |
498 "Device creation failure for config %s. Will skip.\n", c
onfig.name)); | 499 "Device creation failure for config %s. Will skip.\n", c
onfig.name)); |
499 continue; | 500 continue; |
500 } | 501 } |
501 | 502 |
502 switch(benchMode) { | 503 switch(benchMode) { |
503 case kDeferredSilent_BenchMode: | 504 case kDeferredSilent_BenchMode: |
504 case kDeferred_BenchMode: | 505 case kDeferred_BenchMode: |
505 canvas.reset(SkDeferredCanvas::Create(surface.get())); | 506 canvas.reset(SkDeferredCanvas::Create(surface.get())); |
506 break; | 507 break; |
507 case kRecord_BenchMode: | 508 case kRecord_BenchMode: |
508 canvas.reset(SkRef(recordTo.beginRecording(dim.fX, dim.f
Y, kRecordFlags))); | 509 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim
.fY, kRecordFlags))); |
509 break; | 510 break; |
510 case kPictureRecord_BenchMode: | 511 case kPictureRecord_BenchMode: { |
511 bench->draw(1, recordFrom.beginRecording(dim.fX, dim.fY,
kRecordFlags)); | 512 SkPictureRecorder recorderFrom; |
512 recordFrom.endRecording(); | 513 bench->draw(1, recorderFrom.beginRecording(dim.fX, dim.f
Y, kRecordFlags)); |
513 canvas.reset(SkRef(recordTo.beginRecording(dim.fX, dim.f
Y, kRecordFlags))); | 514 recordFrom.reset(recorderFrom.endRecording()); |
| 515 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim
.fY, kRecordFlags))); |
514 break; | 516 break; |
| 517 } |
515 case kNormal_BenchMode: | 518 case kNormal_BenchMode: |
516 canvas.reset(SkRef(surface->getCanvas())); | 519 canvas.reset(SkRef(surface->getCanvas())); |
517 break; | 520 break; |
518 default: | 521 default: |
519 SkASSERT(false); | 522 SkASSERT(false); |
520 } | 523 } |
521 } | 524 } |
522 | 525 |
523 if (NULL != canvas) { | 526 if (NULL != canvas) { |
524 canvas->clear(SK_ColorWHITE); | 527 canvas->clear(SK_ColorWHITE); |
525 if (FLAGS_clip) { performClip(canvas, dim.fX, dim.fY); } | 528 if (FLAGS_clip) { |
526 if (FLAGS_scale) { performScale(canvas, dim.fX, dim.fY); } | 529 perform_clip(canvas, dim.fX, dim.fY); |
527 if (FLAGS_rotate) { performRotate(canvas, dim.fX, dim.fY); } | 530 } |
| 531 if (FLAGS_scale) { |
| 532 perform_scale(canvas, dim.fX, dim.fY); |
| 533 } |
| 534 if (FLAGS_rotate) { |
| 535 perform_rotate(canvas, dim.fX, dim.fY); |
| 536 } |
528 } | 537 } |
529 | 538 |
530 if (!loggedBenchName) { | 539 if (!loggedBenchName) { |
531 loggedBenchName = true; | 540 loggedBenchName = true; |
532 writer.bench(bench->getName(), dim.fX, dim.fY); | 541 writer.bench(bench->getName(), dim.fX, dim.fY); |
533 } | 542 } |
534 | 543 |
535 #if SK_SUPPORT_GPU | 544 #if SK_SUPPORT_GPU |
536 SkGLContextHelper* contextHelper = NULL; | 545 SkGLContextHelper* contextHelper = NULL; |
537 if (SkBenchmark::kGPU_Backend == config.backend) { | 546 if (SkBenchmark::kGPU_Backend == config.backend) { |
(...skipping 24 matching lines...) Expand all Loading... |
562 // you've got a computer clocked at several THz or have
a broken benchmark. ;) | 571 // you've got a computer clocked at several THz or have
a broken benchmark. ;) |
563 // "1B ought to be enough for anybody." | 572 // "1B ought to be enough for anybody." |
564 logger.logError(SkStringPrintf( | 573 logger.logError(SkStringPrintf( |
565 "\nCan't get %s %s to converge in %dms (%d loops)", | 574 "\nCan't get %s %s to converge in %dms (%d loops)", |
566 bench->getName(), config.name, FLAGS_maxMs, loopsPe
rIter)); | 575 bench->getName(), config.name, FLAGS_maxMs, loopsPe
rIter)); |
567 break; | 576 break; |
568 } | 577 } |
569 | 578 |
570 if ((benchMode == kRecord_BenchMode || benchMode == kPicture
Record_BenchMode)) { | 579 if ((benchMode == kRecord_BenchMode || benchMode == kPicture
Record_BenchMode)) { |
571 // Clear the recorded commands so that they do not accum
ulate. | 580 // Clear the recorded commands so that they do not accum
ulate. |
572 canvas.reset(SkRef(recordTo.beginRecording(dim.fX, dim.f
Y, kRecordFlags))); | 581 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim
.fY, kRecordFlags))); |
573 } | 582 } |
574 | 583 |
575 timer.start(); | 584 timer.start(); |
576 // Inner loop that allows us to break the run into smaller | 585 // Inner loop that allows us to break the run into smaller |
577 // chunks (e.g. frames). This is especially useful for the G
PU | 586 // chunks (e.g. frames). This is especially useful for the G
PU |
578 // as we can flush and/or swap buffers to keep the GPU from | 587 // as we can flush and/or swap buffers to keep the GPU from |
579 // queuing up too much work. | 588 // queuing up too much work. |
580 for (int loopCount = loopsPerIter; loopCount > 0; ) { | 589 for (int loopCount = loopsPerIter; loopCount > 0; ) { |
581 // Save and restore around each call to draw() to guaran
tee a pristine canvas. | 590 // Save and restore around each call to draw() to guaran
tee a pristine canvas. |
582 SkAutoCanvasRestore saveRestore(canvas, true/*also save*
/); | 591 SkAutoCanvasRestore saveRestore(canvas, true/*also save*
/); |
583 | 592 |
584 int loops; | 593 int loops; |
585 if (frameIntervalComputed && loopCount > loopsPerFrame)
{ | 594 if (frameIntervalComputed && loopCount > loopsPerFrame)
{ |
586 loops = loopsPerFrame; | 595 loops = loopsPerFrame; |
587 loopCount -= loopsPerFrame; | 596 loopCount -= loopsPerFrame; |
588 } else { | 597 } else { |
589 loops = loopCount; | 598 loops = loopCount; |
590 loopCount = 0; | 599 loopCount = 0; |
591 } | 600 } |
592 | 601 |
593 if (benchMode == kPictureRecord_BenchMode) { | 602 if (benchMode == kPictureRecord_BenchMode) { |
594 recordFrom.draw(canvas); | 603 recordFrom->draw(canvas); |
595 } else { | 604 } else { |
596 bench->draw(loops, canvas); | 605 bench->draw(loops, canvas); |
597 } | 606 } |
598 | 607 |
599 if (kDeferredSilent_BenchMode == benchMode) { | 608 if (kDeferredSilent_BenchMode == benchMode) { |
600 static_cast<SkDeferredCanvas*>(canvas.get())->silent
Flush(); | 609 static_cast<SkDeferredCanvas*>(canvas.get())->silent
Flush(); |
601 } else if (NULL != canvas) { | 610 } else if (NULL != canvas) { |
602 canvas->flush(); | 611 canvas->flush(); |
603 } | 612 } |
604 | 613 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 gContextFactory.destroyContexts(); | 693 gContextFactory.destroyContexts(); |
685 #endif | 694 #endif |
686 return 0; | 695 return 0; |
687 } | 696 } |
688 | 697 |
689 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 698 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
690 int main(int argc, char * const argv[]) { | 699 int main(int argc, char * const argv[]) { |
691 return tool_main(argc, (char**) argv); | 700 return tool_main(argc, (char**) argv); |
692 } | 701 } |
693 #endif | 702 #endif |
OLD | NEW |