commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1 | #include "DMBenchTask.h" |
| 2 | #include "DMUtil.h" |
| 3 | #include "SkSurface.h" |
| 4 | |
| 5 | namespace DM { |
| 6 | |
| 7 | static SkString bench_name(const char* name, const char* config) { |
| 8 | SkString result("bench "); |
| 9 | result.appendf("%s_%s", name, config); |
| 10 | return result; |
| 11 | } |
| 12 | |
| 13 | NonRenderingBenchTask::NonRenderingBenchTask(const char* config, |
| 14 | Reporter* reporter, |
| 15 | TaskRunner* tasks, |
| 16 | BenchRegistry::Factory factory) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 17 | : CpuTask(reporter, tasks) |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 18 | , fBench(factory(NULL)) |
| 19 | , fName(bench_name(fBench->getName(), config)) {} |
| 20 | |
| 21 | CpuBenchTask::CpuBenchTask(const char* config, |
| 22 | Reporter* reporter, |
| 23 | TaskRunner* tasks, |
| 24 | BenchRegistry::Factory factory, |
| 25 | SkColorType colorType) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 26 | : CpuTask(reporter, tasks) |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 27 | , fBench(factory(NULL)) |
| 28 | , fName(bench_name(fBench->getName(), config)) |
| 29 | , fColorType(colorType) {} |
| 30 | |
| 31 | GpuBenchTask::GpuBenchTask(const char* config, |
| 32 | Reporter* reporter, |
| 33 | TaskRunner* tasks, |
| 34 | BenchRegistry::Factory factory, |
| 35 | GrContextFactory::GLContextType contextType, |
| 36 | int sampleCount) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 37 | : GpuTask(reporter, tasks) |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 38 | , fBench(factory(NULL)) |
| 39 | , fName(bench_name(fBench->getName(), config)) |
| 40 | , fContextType(contextType) |
| 41 | , fSampleCount(sampleCount) {} |
| 42 | |
| 43 | bool NonRenderingBenchTask::shouldSkip() const { |
| 44 | return !fBench->isSuitableFor(SkBenchmark::kNonRendering_Backend); |
| 45 | } |
| 46 | |
| 47 | bool CpuBenchTask::shouldSkip() const { |
| 48 | return !fBench->isSuitableFor(SkBenchmark::kRaster_Backend); |
| 49 | } |
| 50 | |
| 51 | bool GpuBenchTask::shouldSkip() const { |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 52 | return kGPUDisabled || !fBench->isSuitableFor(SkBenchmark::kGPU_Backend); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static void draw_raster(SkBenchmark* bench, SkColorType colorType) { |
| 56 | SkBitmap bitmap; |
| 57 | SetupBitmap(colorType, bench, &bitmap); |
| 58 | SkCanvas canvas(bitmap); |
| 59 | |
| 60 | bench->preDraw(); |
| 61 | bench->draw(1, &canvas); |
| 62 | bench->postDraw(); |
| 63 | } |
| 64 | |
| 65 | void NonRenderingBenchTask::draw() { |
| 66 | draw_raster(fBench.get(), kPMColor_SkColorType); |
| 67 | } |
| 68 | |
| 69 | void CpuBenchTask::draw() { |
| 70 | draw_raster(fBench.get(), fColorType); |
| 71 | } |
| 72 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 73 | void GpuBenchTask::draw(GrContextFactory* grFactory) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 74 | SkImageInfo info = SkImageInfo::Make(fBench->getSize().x(), |
| 75 | fBench->getSize().y(), |
| 76 | kPMColor_SkColorType, |
| 77 | kPremul_SkAlphaType); |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 78 | SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, info, fSampleCount)); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 79 | |
| 80 | fBench->preDraw(); |
| 81 | fBench->draw(1, surface->getCanvas()); |
| 82 | fBench->postDraw(); |
| 83 | } |
| 84 | |
| 85 | } // namespace DM |