2014-02-26 23:01:57 +00:00
|
|
|
#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)
|
2014-02-28 20:31:31 +00:00
|
|
|
: CpuTask(reporter, tasks)
|
2014-02-26 23:01:57 +00:00
|
|
|
, fBench(factory(NULL))
|
|
|
|
, fName(bench_name(fBench->getName(), config)) {}
|
|
|
|
|
|
|
|
CpuBenchTask::CpuBenchTask(const char* config,
|
|
|
|
Reporter* reporter,
|
|
|
|
TaskRunner* tasks,
|
|
|
|
BenchRegistry::Factory factory,
|
|
|
|
SkColorType colorType)
|
2014-02-28 20:31:31 +00:00
|
|
|
: CpuTask(reporter, tasks)
|
2014-02-26 23:01:57 +00:00
|
|
|
, 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)
|
2014-02-28 20:31:31 +00:00
|
|
|
: GpuTask(reporter, tasks)
|
2014-02-26 23:01:57 +00:00
|
|
|
, 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 {
|
2014-03-26 21:26:15 +00:00
|
|
|
return kGPUDisabled || !fBench->isSuitableFor(SkBenchmark::kGPU_Backend);
|
2014-02-26 23:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2014-04-11 13:47:30 +00:00
|
|
|
draw_raster(fBench.get(), kPMColor_SkColorType);
|
2014-02-26 23:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CpuBenchTask::draw() {
|
|
|
|
draw_raster(fBench.get(), fColorType);
|
|
|
|
}
|
|
|
|
|
2014-02-28 20:31:31 +00:00
|
|
|
void GpuBenchTask::draw(GrContextFactory* grFactory) {
|
2014-02-26 23:01:57 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(fBench->getSize().x(),
|
|
|
|
fBench->getSize().y(),
|
2014-04-11 13:47:30 +00:00
|
|
|
kPMColor_SkColorType,
|
2014-02-26 23:01:57 +00:00
|
|
|
kPremul_SkAlphaType);
|
2014-03-26 21:26:15 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, info, fSampleCount));
|
2014-02-26 23:01:57 +00:00
|
|
|
|
|
|
|
fBench->preDraw();
|
|
|
|
fBench->draw(1, surface->getCanvas());
|
|
|
|
fBench->postDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DM
|