skia2/dm/DMGpuTask.cpp
commit-bot@chromium.org 0dc5bd149a Let DM run unit tests.
- refactor GYPs and a few flags
  - make GPU tests grab a thread-local GrContextFactory when needed as we do in DM for GMs
  - add a few more UI features to make DM more like tests

I believe this makes the program 'tests' obsolete.

It should be somewhat faster to run the two sets together than running the old binaries serially:
  - serial: tests 20s (3m18s CPU), dm 21s (3m01s CPU)
  - together: 27s (6m21s CPU)

Next up is to incorporate benches.  I'm only planning there on a single-pass sanity check, so that won't obsolete the program 'bench' just yet.

Tested: out/Debug/tests && out/Debug/dm && echo ok
BUG=skia:

Committed: http://code.google.com/p/skia/source/detail?r=13586

R=reed@google.com, bsalomon@google.com, mtklein@google.com, tfarina@chromium.org

Author: mtklein@chromium.org

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13592 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-26 16:31:22 +00:00

60 lines
1.8 KiB
C++

#include "DMGpuTask.h"
#include "DMExpectationsTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"
#include "SkCommandLineFlags.h"
#include "SkSurface.h"
#include "SkTLS.h"
namespace DM {
GpuTask::GpuTask(const char* name,
Reporter* reporter,
TaskRunner* taskRunner,
const Expectations& expectations,
skiagm::GMRegistry::Factory gmFactory,
SkColorType colorType,
GrContextFactory::GLContextType contextType,
int sampleCount)
: Task(reporter, taskRunner)
, fTaskRunner(taskRunner)
, fGM(gmFactory(NULL))
, fName(UnderJoin(fGM->shortName(), name))
, fExpectations(expectations)
, fColorType(colorType)
, fContextType(contextType)
, fSampleCount(sampleCount)
{}
void GpuTask::draw() {
SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
SkScalarCeilToInt(fGM->height()),
fColorType,
kPremul_SkAlphaType);
GrContext* gr = fTaskRunner->getGrContextFactory()->get(fContextType); // Owned by surface.
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(gr, info, fSampleCount));
SkCanvas* canvas = surface->getCanvas();
canvas->concat(fGM->getInitialTransform());
fGM->draw(canvas);
canvas->flush();
SkBitmap bitmap;
bitmap.setConfig(info);
canvas->readPixels(&bitmap, 0, 0);
#if GR_CACHE_STATS
gr->printCacheStats();
#endif
this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)));
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
}
bool GpuTask::shouldSkip() const {
return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
}
} // namespace DM