OLD | NEW |
| (Empty) |
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) | |
17 : CpuTask(reporter, tasks) | |
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) | |
26 : CpuTask(reporter, tasks) | |
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 GrGLStandard gpuAPI, | |
37 int sampleCount) | |
38 : GpuTask(reporter, tasks) | |
39 , fBench(factory(NULL)) | |
40 , fName(bench_name(fBench->getName(), config)) | |
41 , fContextType(contextType) | |
42 , fGpuAPI(gpuAPI) | |
43 , fSampleCount(sampleCount) {} | |
44 | |
45 bool NonRenderingBenchTask::shouldSkip() const { | |
46 return !fBench->isSuitableFor(Benchmark::kNonRendering_Backend); | |
47 } | |
48 | |
49 bool CpuBenchTask::shouldSkip() const { | |
50 return !fBench->isSuitableFor(Benchmark::kRaster_Backend); | |
51 } | |
52 | |
53 bool GpuBenchTask::shouldSkip() const { | |
54 return kGPUDisabled || !fBench->isSuitableFor(Benchmark::kGPU_Backend); | |
55 } | |
56 | |
57 static void draw_raster(Benchmark* bench, SkColorType colorType) { | |
58 SkBitmap bitmap; | |
59 AllocatePixels(colorType, bench->getSize().x(), bench->getSize().y(), &bitma
p); | |
60 SkCanvas canvas(bitmap); | |
61 | |
62 bench->preDraw(); | |
63 bench->draw(1, &canvas); | |
64 } | |
65 | |
66 void NonRenderingBenchTask::draw() { | |
67 draw_raster(fBench.get(), kN32_SkColorType); | |
68 } | |
69 | |
70 void CpuBenchTask::draw() { | |
71 draw_raster(fBench.get(), fColorType); | |
72 } | |
73 | |
74 void GpuBenchTask::draw(GrContextFactory* grFactory) { | |
75 SkImageInfo info = SkImageInfo::Make(fBench->getSize().x(), | |
76 fBench->getSize().y(), | |
77 kN32_SkColorType, | |
78 kPremul_SkAlphaType); | |
79 SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuA
PI, info, | |
80 fSampleCount)); | |
81 if (!surface) { | |
82 this->fail("Could not create context for the config and the api."); | |
83 return; | |
84 } | |
85 fBench->preDraw(); | |
86 fBench->draw(1, surface->getCanvas()); | |
87 } | |
88 | |
89 } // namespace DM | |
OLD | NEW |