2013-10-16 13:02:15 +00:00
|
|
|
// Main binary for DM.
|
|
|
|
// For a high-level overview, please see dm/README.
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "CrashHandler.h"
|
2014-07-22 17:15:34 +00:00
|
|
|
#include "SkCommonFlags.h"
|
2013-10-16 13:02:15 +00:00
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkGraphics.h"
|
2014-05-14 17:55:32 +00:00
|
|
|
#include "SkPicture.h"
|
2013-12-02 13:50:38 +00:00
|
|
|
#include "SkString.h"
|
2014-02-26 16:31:22 +00:00
|
|
|
#include "Test.h"
|
2013-10-16 13:02:15 +00:00
|
|
|
#include "gm.h"
|
|
|
|
|
2014-02-28 20:31:31 +00:00
|
|
|
#include "DMCpuGMTask.h"
|
|
|
|
#include "DMGpuGMTask.h"
|
2014-03-26 21:26:15 +00:00
|
|
|
#include "DMGpuSupport.h"
|
2014-06-03 20:57:14 +00:00
|
|
|
#include "DMPDFTask.h"
|
2013-10-16 13:02:15 +00:00
|
|
|
#include "DMReporter.h"
|
2014-05-14 17:55:32 +00:00
|
|
|
#include "DMSKPTask.h"
|
2013-10-16 13:02:15 +00:00
|
|
|
#include "DMTask.h"
|
|
|
|
#include "DMTaskRunner.h"
|
2014-02-26 16:31:22 +00:00
|
|
|
#include "DMTestTask.h"
|
Add support for reading a directory of images with --expectations (-r).
DM writes out its images in a hierarchy that's a little different than GM,
so this can't read GM's output. But it can read its own, written with -w.
Example usage:
$ out/Release/dm -w /tmp/baseline
$ out/Release/dm -r /tmp/baseline -w /tmp/new
(and optionally)
$ mkdir /tmp/diff; out/Release/skdiff /tmp/baseline /tmp/new /tmp/diff
GM's IndividualImageExpectationsSource and Expectations are a little too eager
about decoding and hashing the expected images, so I took the opportunity to
add DM::Expectations that mostly replaces skiagm::ExpectationsSource and
skiagm::Expectations in DM. It mainly exists to move the image decoding and
comparison off the main thread, which would otherwise be a major speed
bottleneck.
I tried to use skiagm code where possible. One notable place where I differed
is in this new feature. When -r is a directory of images, DM does no hashing.
It considerably faster to read the expected file into an SkBitmap and do a
byte-for-byte comparison than to hash the two bitmaps and check those.
The example usage above isn't quite working 100% yet. Expectations on some GMs
fail, even with no binary change. I haven't pinned down whether this is due to
- a bug in DM
- flaky GMs
- unthreadsafe GMs
- flaky image decoding
- unthreadsafe image decoding
- something else
but I intend to. Leon, Derek and I have suspected PNG decoding isn't
threadsafe, but are as yet unable to prove it.
I also seem to be able to cause malloc to fail on my laptop if I run too many
configs at once, though I never seem to be using more than ~1G of RAM. Will
track that down too.
BUG=
R=reed@google.com, bsalomon@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/108963002
git-svn-id: http://skia.googlecode.com/svn/trunk@12596 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-10 14:53:16 +00:00
|
|
|
#include "DMWriteTask.h"
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2014-06-03 20:57:14 +00:00
|
|
|
#ifdef SK_BUILD_POPPLER
|
|
|
|
# include "SkPDFRasterizer.h"
|
|
|
|
# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
|
|
|
|
#else
|
|
|
|
# define RASTERIZE_PDF_PROC NULL
|
|
|
|
#endif
|
|
|
|
|
2014-05-16 18:11:51 +00:00
|
|
|
#include <ctype.h>
|
2013-10-16 13:02:15 +00:00
|
|
|
|
|
|
|
using skiagm::GM;
|
|
|
|
using skiagm::GMRegistry;
|
2014-02-26 16:31:22 +00:00
|
|
|
using skiatest::Test;
|
|
|
|
using skiatest::TestRegistry;
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2014-06-30 13:36:31 +00:00
|
|
|
static const char kGpuAPINameGL[] = "gl";
|
|
|
|
static const char kGpuAPINameGLES[] = "gles";
|
|
|
|
|
2014-02-28 20:31:31 +00:00
|
|
|
DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
|
Add support for reading a directory of images with --expectations (-r).
DM writes out its images in a hierarchy that's a little different than GM,
so this can't read GM's output. But it can read its own, written with -w.
Example usage:
$ out/Release/dm -w /tmp/baseline
$ out/Release/dm -r /tmp/baseline -w /tmp/new
(and optionally)
$ mkdir /tmp/diff; out/Release/skdiff /tmp/baseline /tmp/new /tmp/diff
GM's IndividualImageExpectationsSource and Expectations are a little too eager
about decoding and hashing the expected images, so I took the opportunity to
add DM::Expectations that mostly replaces skiagm::ExpectationsSource and
skiagm::Expectations in DM. It mainly exists to move the image decoding and
comparison off the main thread, which would otherwise be a major speed
bottleneck.
I tried to use skiagm code where possible. One notable place where I differed
is in this new feature. When -r is a directory of images, DM does no hashing.
It considerably faster to read the expected file into an SkBitmap and do a
byte-for-byte comparison than to hash the two bitmaps and check those.
The example usage above isn't quite working 100% yet. Expectations on some GMs
fail, even with no binary change. I haven't pinned down whether this is due to
- a bug in DM
- flaky GMs
- unthreadsafe GMs
- flaky image decoding
- unthreadsafe image decoding
- something else
but I intend to. Leon, Derek and I have suspected PNG decoding isn't
threadsafe, but are as yet unable to prove it.
I also seem to be able to cause malloc to fail on my laptop if I run too many
configs at once, though I never seem to be using more than ~1G of RAM. Will
track that down too.
BUG=
R=reed@google.com, bsalomon@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/108963002
git-svn-id: http://skia.googlecode.com/svn/trunk@12596 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-10 14:53:16 +00:00
|
|
|
DEFINE_string2(expectations, r, "",
|
|
|
|
"If a directory, compare generated images against images under this path. "
|
2014-05-16 18:11:51 +00:00
|
|
|
"If a file, compare generated images against JSON expectations at this path."
|
|
|
|
);
|
2014-07-22 17:15:34 +00:00
|
|
|
|
2014-05-14 17:55:32 +00:00
|
|
|
DEFINE_string(skps, "", "Directory to read skps from.");
|
2014-02-26 16:31:22 +00:00
|
|
|
|
|
|
|
DEFINE_bool(gms, true, "Run GMs?");
|
|
|
|
DEFINE_bool(tests, true, "Run tests?");
|
2013-10-16 13:02:15 +00:00
|
|
|
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
|
|
|
// "FooBar" -> "foobar". Obviously, ASCII only.
|
|
|
|
static SkString lowercase(SkString s) {
|
|
|
|
for (size_t i = 0; i < s.size(); i++) {
|
|
|
|
s[i] = tolower(s[i]);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-02-26 23:01:57 +00:00
|
|
|
static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
|
2014-03-12 14:46:31 +00:00
|
|
|
static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
|
2014-02-26 23:01:57 +00:00
|
|
|
static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
|
|
|
|
static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
|
|
|
|
static const GrContextFactory::GLContextType angle =
|
|
|
|
#if SK_ANGLE
|
|
|
|
GrContextFactory::kANGLE_GLContextType;
|
|
|
|
#else
|
|
|
|
native;
|
|
|
|
#endif
|
|
|
|
static const GrContextFactory::GLContextType mesa =
|
|
|
|
#if SK_MESA
|
2014-05-02 14:43:12 +00:00
|
|
|
GrContextFactory::kMESA_GLContextType;
|
2014-02-26 23:01:57 +00:00
|
|
|
#else
|
|
|
|
native;
|
|
|
|
#endif
|
|
|
|
|
2014-02-26 16:31:22 +00:00
|
|
|
static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
|
|
|
|
const SkTArray<SkString>& configs,
|
2014-06-30 13:36:31 +00:00
|
|
|
GrGLStandard gpuAPI,
|
2014-02-26 16:31:22 +00:00
|
|
|
const DM::Expectations& expectations,
|
|
|
|
DM::Reporter* reporter,
|
|
|
|
DM::TaskRunner* tasks) {
|
2014-06-06 16:28:43 +00:00
|
|
|
#define START(name, type, ...) \
|
|
|
|
if (lowercase(configs[j]).equals(name)) { \
|
|
|
|
tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \
|
2014-02-26 23:01:57 +00:00
|
|
|
}
|
2013-10-16 13:02:15 +00:00
|
|
|
for (int i = 0; i < gms.count(); i++) {
|
2014-02-26 23:01:57 +00:00
|
|
|
for (int j = 0; j < configs.count(); j++) {
|
2014-06-30 13:36:31 +00:00
|
|
|
|
2014-06-06 16:28:43 +00:00
|
|
|
START("565", CpuGMTask, expectations, kRGB_565_SkColorType);
|
|
|
|
START("8888", CpuGMTask, expectations, kN32_SkColorType);
|
2014-06-30 13:36:31 +00:00
|
|
|
START("gpu", GpuGMTask, expectations, native, gpuAPI, 0);
|
|
|
|
START("msaa4", GpuGMTask, expectations, native, gpuAPI, 4);
|
|
|
|
START("msaa16", GpuGMTask, expectations, native, gpuAPI, 16);
|
|
|
|
START("nvprmsaa4", GpuGMTask, expectations, nvpr, gpuAPI, 4);
|
|
|
|
START("nvprmsaa16", GpuGMTask, expectations, nvpr, gpuAPI, 16);
|
|
|
|
START("gpunull", GpuGMTask, expectations, null, gpuAPI, 0);
|
|
|
|
START("gpudebug", GpuGMTask, expectations, debug, gpuAPI, 0);
|
|
|
|
START("angle", GpuGMTask, expectations, angle, gpuAPI, 0);
|
|
|
|
START("mesa", GpuGMTask, expectations, mesa, gpuAPI, 0);
|
2014-06-03 20:57:14 +00:00
|
|
|
START("pdf", PDFTask, RASTERIZE_PDF_PROC);
|
2014-02-26 23:01:57 +00:00
|
|
|
}
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
2014-02-26 23:01:57 +00:00
|
|
|
#undef START
|
|
|
|
}
|
|
|
|
|
2014-02-26 16:31:22 +00:00
|
|
|
static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
|
|
|
|
DM::Reporter* reporter,
|
|
|
|
DM::TaskRunner* tasks) {
|
|
|
|
for (int i = 0; i < tests.count(); i++) {
|
2014-02-28 20:31:31 +00:00
|
|
|
SkAutoTDelete<Test> test(tests[i](NULL));
|
|
|
|
if (test->isGPUTest()) {
|
|
|
|
tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
|
|
|
|
} else {
|
|
|
|
tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
|
|
|
|
}
|
2014-02-26 16:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 17:55:32 +00:00
|
|
|
static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
|
|
|
|
if (FLAGS_skps.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkOSFile::Iter it(FLAGS_skps[0], ".skp");
|
|
|
|
SkString filename;
|
|
|
|
while (it.next(&filename)) {
|
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
|
|
|
|
|
|
|
|
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str()));
|
|
|
|
if (stream.get() == NULL) {
|
|
|
|
SkDebugf("Could not read %s.\n", path.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
|
|
|
|
if (pic.get() == NULL) {
|
|
|
|
SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:34:44 +00:00
|
|
|
tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
|
|
|
|
tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename,
|
2014-06-06 16:28:43 +00:00
|
|
|
RASTERIZE_PDF_PROC)));
|
2014-05-14 17:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 20:14:48 +00:00
|
|
|
static void report_failures(const SkTArray<SkString>& failures) {
|
2013-10-16 13:02:15 +00:00
|
|
|
if (failures.count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDebugf("Failures:\n");
|
|
|
|
for (int i = 0; i < failures.count(); i++) {
|
|
|
|
SkDebugf(" %s\n", failures[i].c_str());
|
|
|
|
}
|
2014-05-29 20:14:48 +00:00
|
|
|
SkDebugf("%d failures.\n", failures.count());
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 13:36:31 +00:00
|
|
|
static GrGLStandard get_gl_standard() {
|
|
|
|
if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
|
|
|
|
return kGL_GrGLStandard;
|
|
|
|
}
|
|
|
|
if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
|
|
|
|
return kGLES_GrGLStandard;
|
|
|
|
}
|
|
|
|
return kNone_GrGLStandard;
|
|
|
|
}
|
|
|
|
|
2014-02-26 23:01:57 +00:00
|
|
|
template <typename T, typename Registry>
|
|
|
|
static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
|
|
|
|
for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
|
|
|
|
SkAutoTDelete<T> forName(reg->factory()(NULL));
|
|
|
|
if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
|
|
|
|
*out->append() = reg->factory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 17:15:34 +00:00
|
|
|
int dm_main();
|
|
|
|
int dm_main() {
|
2014-06-18 18:44:15 +00:00
|
|
|
SetupCrashHandler();
|
2014-05-29 20:14:48 +00:00
|
|
|
SkAutoGraphics ag;
|
2014-05-30 17:23:31 +00:00
|
|
|
|
|
|
|
if (FLAGS_dryRun) {
|
|
|
|
FLAGS_verbose = true;
|
|
|
|
}
|
2014-02-26 16:31:22 +00:00
|
|
|
#if SK_ENABLE_INST_COUNT
|
|
|
|
gPrintInstCount = FLAGS_leaks;
|
|
|
|
#endif
|
2014-02-25 19:32:15 +00:00
|
|
|
|
2014-02-26 16:31:22 +00:00
|
|
|
SkTArray<SkString> configs;
|
2014-02-26 23:01:57 +00:00
|
|
|
for (int i = 0; i < FLAGS_config.count(); i++) {
|
|
|
|
SkStrSplit(FLAGS_config[i], ", ", &configs);
|
|
|
|
}
|
|
|
|
|
2014-06-30 13:36:31 +00:00
|
|
|
GrGLStandard gpuAPI = get_gl_standard();
|
|
|
|
|
2014-02-25 20:02:09 +00:00
|
|
|
SkTDArray<GMRegistry::Factory> gms;
|
2014-02-26 16:31:22 +00:00
|
|
|
SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
|
|
|
|
if (FLAGS_gms) {
|
2014-02-26 23:01:57 +00:00
|
|
|
append_matching_factories<GM>(GMRegistry::Head(), &gms);
|
2014-02-26 16:31:22 +00:00
|
|
|
|
|
|
|
if (FLAGS_expectations.count() > 0) {
|
|
|
|
const char* path = FLAGS_expectations[0];
|
|
|
|
if (sk_isdir(path)) {
|
|
|
|
expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
|
|
|
|
} else {
|
|
|
|
expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
|
|
|
|
}
|
2013-10-25 15:02:57 +00:00
|
|
|
}
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 16:31:22 +00:00
|
|
|
SkTDArray<TestRegistry::Factory> tests;
|
|
|
|
if (FLAGS_tests) {
|
2014-02-26 23:01:57 +00:00
|
|
|
append_matching_factories<Test>(TestRegistry::Head(), &tests);
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 21:29:53 +00:00
|
|
|
SkDebugf("%d GMs x %d configs, %d tests\n",
|
|
|
|
gms.count(), configs.count(), tests.count());
|
2013-10-16 13:02:15 +00:00
|
|
|
DM::Reporter reporter;
|
2014-02-28 20:31:31 +00:00
|
|
|
DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
|
2014-06-30 13:36:31 +00:00
|
|
|
kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks);
|
2014-02-26 16:31:22 +00:00
|
|
|
kick_off_tests(tests, &reporter, &tasks);
|
2014-05-14 17:55:32 +00:00
|
|
|
kick_off_skps(&reporter, &tasks);
|
2013-10-16 13:02:15 +00:00
|
|
|
tasks.wait();
|
|
|
|
|
|
|
|
SkDebugf("\n");
|
|
|
|
|
2014-05-29 20:14:48 +00:00
|
|
|
SkTArray<SkString> failures;
|
|
|
|
reporter.getFailures(&failures);
|
|
|
|
report_failures(failures);
|
|
|
|
return failures.count() > 0;
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
2013-10-16 18:21:03 +00:00
|
|
|
|
|
|
|
#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
|
|
|
|
int main(int argc, char** argv) {
|
2014-07-22 17:15:34 +00:00
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
return dm_main();
|
2013-10-16 18:21:03 +00:00
|
|
|
}
|
|
|
|
#endif
|