1 #include "DMBenchTask.h"
2 #include "DMUtil.h"
3 #include "SkSurface.h"
4
5 namespace DM {
6
bench_name(const char * name,const char * config)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
NonRenderingBenchTask(const char * config,Reporter * reporter,TaskRunner * tasks,BenchRegistry::Factory factory)13 NonRenderingBenchTask::NonRenderingBenchTask(const char* config,
14 Reporter* reporter,
15 TaskRunner* tasks,
16 BenchRegistry::Factory factory)
17 : CpuTask(reporter, tasks)
18 , fBench(factory(NULL))
19 , fName(bench_name(fBench->getName(), config)) {}
20
CpuBenchTask(const char * config,Reporter * reporter,TaskRunner * tasks,BenchRegistry::Factory factory,SkColorType colorType)21 CpuBenchTask::CpuBenchTask(const char* config,
22 Reporter* reporter,
23 TaskRunner* tasks,
24 BenchRegistry::Factory factory,
25 SkColorType colorType)
26 : CpuTask(reporter, tasks)
27 , fBench(factory(NULL))
28 , fName(bench_name(fBench->getName(), config))
29 , fColorType(colorType) {}
30
GpuBenchTask(const char * config,Reporter * reporter,TaskRunner * tasks,BenchRegistry::Factory factory,GrContextFactory::GLContextType contextType,int sampleCount)31 GpuBenchTask::GpuBenchTask(const char* config,
32 Reporter* reporter,
33 TaskRunner* tasks,
34 BenchRegistry::Factory factory,
35 GrContextFactory::GLContextType contextType,
36 int sampleCount)
37 : GpuTask(reporter, tasks)
38 , fBench(factory(NULL))
39 , fName(bench_name(fBench->getName(), config))
40 , fContextType(contextType)
41 , fSampleCount(sampleCount) {}
42
shouldSkip() const43 bool NonRenderingBenchTask::shouldSkip() const {
44 return !fBench->isSuitableFor(Benchmark::kNonRendering_Backend);
45 }
46
shouldSkip() const47 bool CpuBenchTask::shouldSkip() const {
48 return !fBench->isSuitableFor(Benchmark::kRaster_Backend);
49 }
50
shouldSkip() const51 bool GpuBenchTask::shouldSkip() const {
52 return kGPUDisabled || !fBench->isSuitableFor(Benchmark::kGPU_Backend);
53 }
54
draw_raster(Benchmark * bench,SkColorType colorType)55 static void draw_raster(Benchmark* bench, SkColorType colorType) {
56 SkBitmap bitmap;
57 AllocatePixels(colorType, bench->getSize().x(), bench->getSize().y(), &bitmap);
58 SkCanvas canvas(bitmap);
59
60 bench->preDraw();
61 bench->draw(1, &canvas);
62 }
63
draw()64 void NonRenderingBenchTask::draw() {
65 draw_raster(fBench.get(), kN32_SkColorType);
66 }
67
draw()68 void CpuBenchTask::draw() {
69 draw_raster(fBench.get(), fColorType);
70 }
71
draw(GrContextFactory * grFactory)72 void GpuBenchTask::draw(GrContextFactory* grFactory) {
73 SkImageInfo info = SkImageInfo::Make(fBench->getSize().x(),
74 fBench->getSize().y(),
75 kN32_SkColorType,
76 kPremul_SkAlphaType);
77 SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, info, fSampleCount));
78
79 fBench->preDraw();
80 fBench->draw(1, surface->getCanvas());
81 }
82
83 } // namespace DM
84