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, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 36 | GrGLStandard gpuAPI, |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 37 | int sampleCount) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 38 | : GpuTask(reporter, tasks) |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 39 | , fBench(factory(NULL)) |
| 40 | , fName(bench_name(fBench->getName(), config)) |
| 41 | , fContextType(contextType) |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 42 | , fGpuAPI(gpuAPI) |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 43 | , fSampleCount(sampleCount) {} |
| 44 | |
| 45 | bool NonRenderingBenchTask::shouldSkip() const { |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 46 | return !fBench->isSuitableFor(Benchmark::kNonRendering_Backend); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | bool CpuBenchTask::shouldSkip() const { |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 50 | return !fBench->isSuitableFor(Benchmark::kRaster_Backend); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | bool GpuBenchTask::shouldSkip() const { |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 54 | return kGPUDisabled || !fBench->isSuitableFor(Benchmark::kGPU_Backend); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 55 | } |
| 56 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 57 | static void draw_raster(Benchmark* bench, SkColorType colorType) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 58 | SkBitmap bitmap; |
commit-bot@chromium.org | 2664207 | 2014-05-15 17:33:31 +0000 | [diff] [blame] | 59 | AllocatePixels(colorType, bench->getSize().x(), bench->getSize().y(), &bitmap); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 60 | SkCanvas canvas(bitmap); |
| 61 | |
| 62 | bench->preDraw(); |
| 63 | bench->draw(1, &canvas); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void NonRenderingBenchTask::draw() { |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 67 | draw_raster(fBench.get(), kN32_SkColorType); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void CpuBenchTask::draw() { |
| 71 | draw_raster(fBench.get(), fColorType); |
| 72 | } |
| 73 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 74 | void GpuBenchTask::draw(GrContextFactory* grFactory) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 75 | SkImageInfo info = SkImageInfo::Make(fBench->getSize().x(), |
| 76 | fBench->getSize().y(), |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 77 | kN32_SkColorType, |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 78 | kPremul_SkAlphaType); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 79 | SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuAPI, info, |
| 80 | fSampleCount)); |
| 81 | if (!surface) { |
| 82 | this->fail("Could not create context for the config and the api."); |
| 83 | return; |
| 84 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 85 | fBench->preDraw(); |
| 86 | fBench->draw(1, surface->getCanvas()); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | } // namespace DM |