blob: 6cf69ffc1c9c2b8a550ae39ad8260b99606f92e8 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMGpuTask.h"
2
3#include "DMComparisonTask.h"
4#include "DMUtil.h"
5#include "SkCommandLineFlags.h"
6#include "SkGpuDevice.h"
7#include "SkTLS.h"
8
9namespace DM {
10
11GpuTask::GpuTask(const char* name,
12 Reporter* reporter,
13 TaskRunner* taskRunner,
14 const skiagm::ExpectationsSource& expectations,
15 skiagm::GMRegistry::Factory gmFactory,
16 SkBitmap::Config config,
17 GrContextFactory::GLContextType contextType,
18 int sampleCount)
19 : Task(reporter, taskRunner)
20 , fGM(gmFactory(NULL))
21 , fName(underJoin(fGM->shortName(), name))
22 , fExpectations(expectations.get(png(fName).c_str()))
23 , fConfig(config)
24 , fContextType(contextType)
25 , fSampleCount(sampleCount)
26 {}
27
28static void* new_gr_context_factory() {
29 return SkNEW(GrContextFactory);
30}
31
32static void delete_gr_context_factory(void* factory) {
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000033 SkDELETE((GrContextFactory*) factory);
mtklein@google.comd36522d2013-10-16 13:02:15 +000034}
35
36static GrContextFactory* get_gr_factory() {
37 return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory,
38 &delete_gr_context_factory));
39}
40
41void GpuTask::draw() {
42 GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by device.
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000043 SkGpuDevice device(gr,
44 fConfig,
45 SkScalarCeilToInt(fGM->width()),
46 SkScalarCeilToInt(fGM->height()),
47 fSampleCount);
mtklein@google.comd36522d2013-10-16 13:02:15 +000048 SkCanvas canvas(&device);
49
50 canvas.concat(fGM->getInitialTransform());
51 fGM->draw(&canvas);
52 canvas.flush();
53
54 SkBitmap bitmap;
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000055 bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
mtklein@google.comd36522d2013-10-16 13:02:15 +000056 canvas.readPixels(&bitmap, 0, 0);
57
58 // We offload checksum comparison to the main CPU threadpool.
59 // This cuts run time by about 30%.
60 this->spawnChild(SkNEW_ARGS(ComparisonTask, (*this, fExpectations, bitmap)));
61}
62
63bool GpuTask::shouldSkip() const {
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000064 return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
mtklein@google.comd36522d2013-10-16 13:02:15 +000065}
66
67} // namespace DM