aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMBenchTask.cpp
blob: bcedb96f25e43b0d6854e9c1972ac2eda3f23bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "DMBenchTask.h"
#include "DMUtil.h"
#include "SkSurface.h"

namespace DM {

static SkString bench_name(const char* name, const char* config) {
    SkString result("bench ");
    result.appendf("%s_%s", name, config);
    return result;
}

NonRenderingBenchTask::NonRenderingBenchTask(const char* config,
                                             Reporter* reporter,
                                             TaskRunner* tasks,
                                             BenchRegistry::Factory factory)
    : CpuTask(reporter, tasks)
    , fBench(factory(NULL))
    , fName(bench_name(fBench->getName(), config)) {}

CpuBenchTask::CpuBenchTask(const char* config,
                           Reporter* reporter,
                           TaskRunner* tasks,
                           BenchRegistry::Factory factory,
                           SkColorType colorType)
    : CpuTask(reporter, tasks)
    , fBench(factory(NULL))
    , fName(bench_name(fBench->getName(), config))
    , fColorType(colorType) {}

GpuBenchTask::GpuBenchTask(const char* config,
                           Reporter* reporter,
                           TaskRunner* tasks,
                           BenchRegistry::Factory factory,
                           GrContextFactory::GLContextType contextType,
                           int sampleCount)
    : GpuTask(reporter, tasks)
    , fBench(factory(NULL))
    , fName(bench_name(fBench->getName(), config))
    , fContextType(contextType)
    , fSampleCount(sampleCount) {}

bool NonRenderingBenchTask::shouldSkip() const {
    return !fBench->isSuitableFor(SkBenchmark::kNonRendering_Backend);
}

bool CpuBenchTask::shouldSkip() const {
    return !fBench->isSuitableFor(SkBenchmark::kRaster_Backend);
}

bool GpuBenchTask::shouldSkip() const {
    return kGPUDisabled || !fBench->isSuitableFor(SkBenchmark::kGPU_Backend);
}

static void draw_raster(SkBenchmark* bench, SkColorType colorType) {
    SkBitmap bitmap;
    SetupBitmap(colorType, bench, &bitmap);
    SkCanvas canvas(bitmap);

    bench->preDraw();
    bench->draw(1, &canvas);
    bench->postDraw();
}

void NonRenderingBenchTask::draw() {
    draw_raster(fBench.get(), kN32_SkColorType);
}

void CpuBenchTask::draw() {
    draw_raster(fBench.get(), fColorType);
}

void GpuBenchTask::draw(GrContextFactory* grFactory) {
    SkImageInfo info = SkImageInfo::Make(fBench->getSize().x(),
                                         fBench->getSize().y(),
                                         kN32_SkColorType,
                                         kPremul_SkAlphaType);
    SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, info, fSampleCount));

    fBench->preDraw();
    fBench->draw(1, surface->getCanvas());
    fBench->postDraw();
}

}  // namespace DM