skia2/dm/DMGpuTask.cpp
mtklein@google.com ee21a3e395 DM: some refactoring
- rename ComparisonTask to ChecksumTask
  - have ChecksumTask handle all the checksum-checking
  - turn on all extra modes by default
  - simplify progress output to a countdown

BUG=
R=bsalomon@google.com

Review URL: https://codereview.chromium.org/88543002

git-svn-id: http://skia.googlecode.com/svn/trunk@12398 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-11-26 18:52:31 +00:00

72 lines
2.1 KiB
C++

#include "DMGpuTask.h"
#include "DMChecksumTask.h"
#include "DMUtil.h"
#include "DMWriteTask.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)
{}
static void* new_gr_context_factory() {
return SkNEW(GrContextFactory);
}
static void delete_gr_context_factory(void* factory) {
SkDELETE((GrContextFactory*) factory);
}
static GrContextFactory* get_gr_factory() {
return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory,
&delete_gr_context_factory));
}
void GpuTask::draw() {
GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by device.
SkGpuDevice device(gr,
fConfig,
SkScalarCeilToInt(fGM->width()),
SkScalarCeilToInt(fGM->height()),
fSampleCount);
SkCanvas canvas(&device);
canvas.concat(fGM->getInitialTransform());
fGM->draw(&canvas);
canvas.flush();
SkBitmap bitmap;
bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
canvas.readPixels(&bitmap, 0, 0);
#if GR_CACHE_STATS
gr->printCacheStats();
#endif
this->spawnChild(SkNEW_ARGS(ChecksumTask, (*this, fExpectations, bitmap)));
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
}
bool GpuTask::shouldSkip() const {
return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
}
} // namespace DM