| Index: dm/DMGpuTask.cpp
|
| diff --git a/dm/DMGpuTask.cpp b/dm/DMGpuTask.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..534fdb9a8905dc0c167d5b65343e15d705b7fdee
|
| --- /dev/null
|
| +++ b/dm/DMGpuTask.cpp
|
| @@ -0,0 +1,63 @@
|
| +#include "DMGpuTask.h"
|
| +
|
| +#include "DMComparisonTask.h"
|
| +#include "DMUtil.h"
|
| +#include "SkCommandLineFlags.h"
|
| +#include "SkGpuDevice.h"
|
| +#include "SkTLS.h"
|
| +
|
| +namespace DM {
|
| +
|
| +GpuTask::GpuTask(const char* name,
|
| + Reporter* reporter,
|
| + TaskRunner* taskRunner,
|
| + const skiagm::ExpectationsSource& expectations,
|
| + skiagm::GMRegistry::Factory gmFactory,
|
| + SkBitmap::Config config,
|
| + GrContextFactory::GLContextType contextType,
|
| + int sampleCount)
|
| + : Task(reporter, taskRunner)
|
| + , fGM(gmFactory(NULL))
|
| + , fName(underJoin(fGM->shortName(), name))
|
| + , fExpectations(expectations.get(png(fName).c_str()))
|
| + , fConfig(config)
|
| + , fContextType(contextType)
|
| + , fSampleCount(sampleCount)
|
| + {}
|
| +
|
| +GrContextFactory* GpuTask::GetGrFactory() {
|
| + return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&NewGrContextFactory,
|
| + &DeleteGrContextFactory));
|
| +}
|
| +
|
| +void* GpuTask::NewGrContextFactory() {
|
| + return SkNEW(GrContextFactory);
|
| +}
|
| +
|
| +void GpuTask::DeleteGrContextFactory(void* factory) {
|
| + return SkDELETE((GrContextFactory*) factory);
|
| +}
|
| +
|
| +void GpuTask::draw() {
|
| + GrContext* gr = GetGrFactory()->get(fContextType); // Will be owned by device.
|
| + SkGpuDevice device(gr, fConfig, fGM->width(), fGM->height(), fSampleCount);
|
| + SkCanvas canvas(&device);
|
| +
|
| + canvas.concat(fGM->getInitialTransform());
|
| + fGM->draw(&canvas);
|
| + canvas.flush();
|
| +
|
| + SkBitmap bitmap;
|
| + bitmap.setConfig(fConfig, fGM->width(), fGM->height());
|
| + canvas.readPixels(&bitmap, 0, 0);
|
| +
|
| + // We offload checksum comparison to the main CPU threadpool.
|
| + // This cuts run time by about 30%.
|
| + this->spawnChild(SkNEW_ARGS(ComparisonTask, (*this, fExpectations, bitmap)));
|
| +}
|
| +
|
| +bool GpuTask::shouldSkip() const {
|
| + return fGM->getFlags() & skiagm::GM::kSkipGPU_Flag;
|
| +}
|
| +
|
| +} // namespace DM
|
|
|