2014-11-13 16:06:40 +00:00
|
|
|
#include "CrashHandler.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "DMJsonWriter.h"
|
|
|
|
#include "DMSrcSink.h"
|
|
|
|
#include "OverwriteLine.h"
|
|
|
|
#include "ProcStats.h"
|
|
|
|
#include "SkBBHFactory.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"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkMD5.h"
|
Start to rework DM JSON handling.
DM's striking off into its own JSON world. This gets strawman implementations
in place for writing and reading a JSON file mapping test name to hashes.
For what it's worth, I basically want to change _all_ these pieces,
- MD5 is slow and we can replace it with something faster,
- JSON schema needs room to grow more data,
- it'd be nice to hash once instead of twice when reading and writing,
- this code wants lots of refactoring,
but this gives us a starting platform to work on these bits at our leisure.
E.x. file for now:
mtklein@mtklein ~/skia (dm)> cat good/dm.json
{
"3x3bitmaprect_565" : "fc70d985fbfbe70e3a3c9dc626d4f5bc",
"3x3bitmaprect_8888" : "df1591dde35907399734ea19feb76663",
"3x3bitmaprect_gpu" : "df1591dde35907399734ea19feb76663",
"aaclip_565" : "1862798689b838a7ab0dc0652b9ace3a",
"aaclip_8888" : "47bb314329f0ce243f1d83fd583decb7",
"aaclip_gpu" : "75f72412d0ef4815770202d297246e7d",
...
BUG=skia:
R=jcgregorio@google.com, stephana@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/546873002
2014-09-08 15:05:18 +00:00
|
|
|
#include "SkOSFile.h"
|
SkThreadPool ~~> SkTaskGroup
SkTaskGroup is like SkThreadPool except the threads stay in
one global pool. Each SkTaskGroup itself is tiny (4 bytes)
and its wait() method applies only to tasks add()ed to that
instance, not the whole thread pool.
This means we don't need to bring up new thread pools when
tests themselves want to use multithreading (e.g. pathops,
quilt). We just create a new SkTaskGroup and wait for that
to complete. This should be more efficient, and allow us
to expand where we use threads to really latency sensitive
places. E.g. we can probably now use these in nanobench
for CPU .skp rendering.
Now that all threads are sharing the same pool, I think we
can remove most of the custom mechanism pathops tests use
to control threading. They'll just ride on the global pool
with all other tests now.
This (temporarily?) removes the GPU multithreading feature
from DM, which we don't use.
On my desktop, DM runs a little faster (57s -> 55s) in
Debug, and a lot faster in Release (36s -> 24s). The bots
show speedups of similar proportions, cutting more than a
minute off the N4/Release and Win7/Debug runtimes.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/9c7207b5dc71dc5a96a2eb107d401133333d5b6f
R=caryclark@google.com, bsalomon@google.com, bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531653002
2014-09-03 22:34:37 +00:00
|
|
|
#include "SkTaskGroup.h"
|
2014-02-26 16:31:22 +00:00
|
|
|
#include "Test.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "Timer.h"
|
2014-06-03 20:57:14 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
DEFINE_bool(tests, true, "Run tests?");
|
|
|
|
DEFINE_string(images, "resources", "Images to decode.");
|
2015-01-15 21:58:56 +00:00
|
|
|
DEFINE_string(src, "gm skp image subset", "Source types to test.");
|
2015-01-15 18:56:12 +00:00
|
|
|
DEFINE_bool(nameByHash, false,
|
|
|
|
"If true, write to FLAGS_writePath[0]/<hash>.png instead of "
|
|
|
|
"to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png");
|
|
|
|
DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
|
|
|
|
DEFINE_string(matrix, "1 0 0 0 1 0 0 0 1",
|
|
|
|
"Matrix to apply when using 'matrix' in config.");
|
2015-01-15 20:46:02 +00:00
|
|
|
DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2015-01-15 21:44:22 +00:00
|
|
|
DEFINE_string(blacklist, "",
|
|
|
|
"Space-separated config/src/name triples to blacklist. '_' matches anything. E.g. \n"
|
|
|
|
"'--blacklist gpu skp _' will blacklist all SKPs drawn into the gpu config.\n"
|
|
|
|
"'--blacklist gpu skp _ 8888 gm aarects' will also blacklist the aarects GM on 8888.");
|
|
|
|
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
using namespace DM;
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2014-06-30 13:36:31 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
|
|
|
|
static SkTArray<SkString> gFailures;
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
static void fail(ImplicitString err) {
|
|
|
|
SkAutoMutexAcquire lock(gFailuresMutex);
|
|
|
|
SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
|
|
|
|
gFailures.push_back(err);
|
|
|
|
}
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
static int32_t gPending = 0; // Atomic.
|
|
|
|
|
|
|
|
static void done(double ms, ImplicitString config, ImplicitString src, ImplicitString name) {
|
|
|
|
SkDebugf("%s(%4dMB %5d) %s\t%s %s %s ", FLAGS_verbose ? "\n" : kSkOverwriteLine
|
|
|
|
, sk_tools::getMaxResidentSetSizeMB()
|
|
|
|
, sk_atomic_dec(&gPending)-1
|
|
|
|
, HumanizeMs(ms).c_str()
|
|
|
|
, config.c_str()
|
|
|
|
, src.c_str()
|
|
|
|
, name.c_str());
|
2015-01-10 19:18:04 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Tagged : public SkAutoTDelete<T> { const char* tag; };
|
|
|
|
|
|
|
|
static const bool kMemcpyOK = true;
|
|
|
|
|
|
|
|
static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
|
|
|
|
static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
|
|
|
|
|
|
|
|
static void push_src(const char* tag, Src* s) {
|
|
|
|
SkAutoTDelete<Src> src(s);
|
|
|
|
if (FLAGS_src.contains(tag) &&
|
|
|
|
!SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
|
|
|
|
Tagged<Src>& s = gSrcs.push_back();
|
|
|
|
s.reset(src.detach());
|
|
|
|
s.tag = tag;
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
static void gather_srcs() {
|
|
|
|
for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
|
|
|
|
push_src("gm", new GMSrc(r->factory()));
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
if (!FLAGS_skps.isEmpty()) {
|
|
|
|
SkOSFile::Iter it(FLAGS_skps[0], "skp");
|
|
|
|
for (SkString file; it.next(&file); ) {
|
|
|
|
push_src("skp", new SKPSrc(SkOSPath::Join(FLAGS_skps[0], file.c_str())));
|
2014-02-28 20:31:31 +00:00
|
|
|
}
|
2014-02-26 16:31:22 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
if (!FLAGS_images.isEmpty()) {
|
|
|
|
const char* exts[] = {
|
|
|
|
"bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
|
|
|
|
"BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
|
|
|
|
SkOSFile::Iter it(FLAGS_images[0], exts[i]);
|
|
|
|
for (SkString file; it.next(&file); ) {
|
|
|
|
SkString path = SkOSPath::Join(FLAGS_images[0], file.c_str());
|
|
|
|
push_src("image", new ImageSrc(path)); // Decode entire image.
|
|
|
|
push_src("subset", new ImageSrc(path, 5)); // Decode 5 random subsets.
|
|
|
|
}
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-15 16:30:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
static GrGLStandard get_gpu_api() {
|
|
|
|
if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
|
|
|
|
if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
|
|
|
|
return kNone_GrGLStandard;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void push_sink(const char* tag, Sink* s) {
|
|
|
|
SkAutoTDelete<Sink> sink(s);
|
|
|
|
if (!FLAGS_config.contains(tag)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Try a noop Src as a canary. If it fails, skip this sink.
|
|
|
|
struct : public Src {
|
|
|
|
Error draw(SkCanvas*) const SK_OVERRIDE { return ""; }
|
|
|
|
SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); }
|
|
|
|
Name name() const SK_OVERRIDE { return "noop"; }
|
|
|
|
} noop;
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkDynamicMemoryWStream stream;
|
|
|
|
Error err = sink->draw(noop, &bitmap, &stream);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
SkDebugf("Skipping %s: %s\n", tag, err.c_str());
|
2015-01-15 16:30:25 +00:00
|
|
|
return;
|
2014-07-28 14:21:24 +00:00
|
|
|
}
|
2015-01-15 16:30:25 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
Tagged<Sink>& ts = gSinks.push_back();
|
|
|
|
ts.reset(sink.detach());
|
|
|
|
ts.tag = tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool gpu_supported() {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
return FLAGS_gpu;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static Sink* create_sink(const char* tag) {
|
|
|
|
#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
|
|
|
|
if (gpu_supported()) {
|
2015-01-15 20:46:02 +00:00
|
|
|
typedef GrContextFactory Gr;
|
2015-01-15 18:56:12 +00:00
|
|
|
const GrGLStandard api = get_gpu_api();
|
2015-01-15 20:46:02 +00:00
|
|
|
SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
|
|
|
|
SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
|
|
|
|
SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
|
|
|
|
SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
|
|
|
|
SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
|
|
|
|
SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
|
|
|
|
SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
|
|
|
|
SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
|
2015-01-15 18:56:12 +00:00
|
|
|
#if SK_ANGLE
|
2015-01-15 20:46:02 +00:00
|
|
|
SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
|
2015-01-15 18:56:12 +00:00
|
|
|
#endif
|
|
|
|
#if SK_MESA
|
2015-01-15 20:46:02 +00:00
|
|
|
SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
|
2015-01-15 18:56:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAGS_cpu) {
|
|
|
|
SINK("565", RasterSink, kRGB_565_SkColorType);
|
|
|
|
SINK("8888", RasterSink, kN32_SkColorType);
|
|
|
|
// TODO(mtklein): reenable once skiagold can handle .pdf uploads.
|
|
|
|
//SINK("pdf", PDFSink);
|
|
|
|
}
|
|
|
|
#undef SINK
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Sink* create_via(const char* tag, Sink* wrapped) {
|
|
|
|
#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
|
|
|
|
VIA("serialize", ViaSerialization, wrapped);
|
|
|
|
|
|
|
|
VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
|
|
|
|
VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
|
|
|
|
|
|
|
|
const int xp = SkGPipeWriter::kCrossProcess_Flag,
|
|
|
|
sa = xp | SkGPipeWriter::kSharedAddressSpace_Flag;
|
|
|
|
VIA("pipe", ViaPipe, 0, wrapped);
|
|
|
|
VIA("pipe_xp", ViaPipe, xp, wrapped);
|
|
|
|
VIA("pipe_sa", ViaPipe, sa, wrapped);
|
|
|
|
|
|
|
|
if (FLAGS_matrix.count() == 9) {
|
|
|
|
SkMatrix m;
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
m[i] = (SkScalar)atof(FLAGS_matrix[i]);
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
VIA("matrix", ViaMatrix, m, wrapped);
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
#undef VIA
|
|
|
|
return NULL;
|
2014-07-28 14:21:24 +00:00
|
|
|
}
|
2014-05-14 17:55:32 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
static void gather_sinks() {
|
|
|
|
for (int i = 0; i < FLAGS_config.count(); i++) {
|
|
|
|
const char* config = FLAGS_config[i];
|
|
|
|
SkTArray<SkString> parts;
|
|
|
|
SkStrSplit(config, "-", &parts);
|
|
|
|
|
|
|
|
Sink* sink = NULL;
|
|
|
|
for (int i = parts.count(); i-- > 0;) {
|
|
|
|
const char* part = parts[i].c_str();
|
|
|
|
Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
|
|
|
|
if (next == NULL) {
|
|
|
|
SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
|
|
|
|
delete sink;
|
|
|
|
sink = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sink = next;
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
if (sink) {
|
|
|
|
push_sink(config, sink);
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2014-05-14 17:55:32 +00:00
|
|
|
}
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2014-05-14 17:55:32 +00:00
|
|
|
|
2015-01-15 21:44:22 +00:00
|
|
|
static bool match(const char* needle, const char* haystack) {
|
|
|
|
return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) {
|
|
|
|
for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) {
|
|
|
|
if (match(FLAGS_blacklist[i+0], sink) &&
|
|
|
|
match(FLAGS_blacklist[i+1], src) &&
|
|
|
|
match(FLAGS_blacklist[i+2], name)) {
|
|
|
|
return SkStringPrintf("%s %s %s",
|
|
|
|
FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
// The finest-grained unit of work we can run: draw a single Src into a single Sink,
|
|
|
|
// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
|
|
|
|
struct Task {
|
|
|
|
Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
|
|
|
|
const Tagged<Src>& src;
|
|
|
|
const Tagged<Sink>& sink;
|
|
|
|
|
|
|
|
static void Run(Task* task) {
|
2015-01-15 21:44:22 +00:00
|
|
|
SkString name = task->src->name();
|
|
|
|
SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str());
|
2015-01-15 18:56:12 +00:00
|
|
|
WallTimer timer;
|
|
|
|
timer.start();
|
2015-01-15 21:44:22 +00:00
|
|
|
if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
|
2015-01-15 18:56:12 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
SkDynamicMemoryWStream stream;
|
|
|
|
Error err = task->sink->draw(*task->src, &bitmap, &stream);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
fail(SkStringPrintf("%s %s %s: %s",
|
|
|
|
task->sink.tag,
|
|
|
|
task->src.tag,
|
2015-01-15 21:44:22 +00:00
|
|
|
name.c_str(),
|
2015-01-15 18:56:12 +00:00
|
|
|
err.c_str()));
|
|
|
|
}
|
|
|
|
if (!FLAGS_writePath.isEmpty()) {
|
|
|
|
const char* ext = task->sink->fileExtension();
|
|
|
|
if (stream.bytesWritten() == 0) {
|
|
|
|
SkMemoryStream pixels(bitmap.getPixels(), bitmap.getSize());
|
|
|
|
WriteToDisk(*task, &pixels, bitmap.getSize(), &bitmap, ext);
|
|
|
|
} else {
|
|
|
|
SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
|
|
|
|
WriteToDisk(*task, data, data->getLength(), NULL, ext);
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
timer.end();
|
2015-01-15 21:44:22 +00:00
|
|
|
if (!whyBlacklisted.isEmpty()) {
|
|
|
|
name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str());
|
|
|
|
}
|
|
|
|
done(timer.fWall, task->sink.tag, task->src.tag, name);
|
2014-12-13 00:41:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
static void WriteToDisk(const Task& task,
|
|
|
|
SkStream* data, size_t len,
|
|
|
|
const SkBitmap* bitmap,
|
|
|
|
const char* ext) {
|
|
|
|
SkMD5 hash;
|
|
|
|
hash.writeStream(data, len);
|
|
|
|
SkMD5::Digest digest;
|
|
|
|
hash.finish(digest);
|
|
|
|
|
|
|
|
JsonWriter::BitmapResult result;
|
|
|
|
result.name = task.src->name();
|
|
|
|
result.config = task.sink.tag;
|
|
|
|
result.sourceType = task.src.tag;
|
|
|
|
result.ext = ext;
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
result.md5.appendf("%02x", digest.data[i]);
|
|
|
|
}
|
|
|
|
JsonWriter::AddBitmapResult(result);
|
2015-01-15 16:30:25 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
const char* dir = FLAGS_writePath[0];
|
|
|
|
if (0 == strcmp(dir, "@")) { // Needed for iOS.
|
|
|
|
dir = FLAGS_resourcePath[0];
|
|
|
|
}
|
|
|
|
sk_mkdir(dir);
|
|
|
|
|
|
|
|
SkString path;
|
|
|
|
if (FLAGS_nameByHash) {
|
|
|
|
path = SkOSPath::Join(dir, result.md5.c_str());
|
|
|
|
path.append(".");
|
|
|
|
path.append(ext);
|
|
|
|
if (sk_exists(path.c_str())) {
|
|
|
|
return; // Content-addressed. If it exists already, we're done.
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
path = SkOSPath::Join(dir, task.sink.tag);
|
|
|
|
sk_mkdir(path.c_str());
|
|
|
|
path = SkOSPath::Join(path.c_str(), task.src.tag);
|
|
|
|
sk_mkdir(path.c_str());
|
|
|
|
path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
|
|
|
|
path.append(".");
|
|
|
|
path.append(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkFILEWStream file(path.c_str());
|
|
|
|
if (!file.isValid()) {
|
|
|
|
fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->rewind();
|
|
|
|
if (bitmap) {
|
|
|
|
// We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
|
|
|
|
SkBitmap converted;
|
|
|
|
if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
|
|
|
|
if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
|
|
|
|
fail("Can't convert A8 to 8888.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bitmap = &converted;
|
|
|
|
}
|
|
|
|
if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
|
|
|
|
fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!file.writeStream(data, len)) {
|
|
|
|
fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
};
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
// Run all tasks in the same enclave serially on the same thread.
|
|
|
|
// They can't possibly run concurrently with each other.
|
|
|
|
static void run_enclave(SkTArray<Task>* tasks) {
|
|
|
|
for (int i = 0; i < tasks->count(); i++) {
|
|
|
|
Task::Run(tasks->begin() + i);
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
|
|
|
|
|
|
|
|
static struct : public skiatest::Reporter {
|
|
|
|
void onReportFailed(const skiatest::Failure& failure) SK_OVERRIDE {
|
|
|
|
SkString s;
|
|
|
|
failure.getFailureString(&s);
|
|
|
|
fail(s);
|
|
|
|
JsonWriter::AddTestFailure(failure);
|
|
|
|
}
|
|
|
|
bool allowExtendedTest() const SK_OVERRIDE { return FLAGS_pathOpsExtended; }
|
|
|
|
bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; }
|
|
|
|
} gTestReporter;
|
|
|
|
|
2015-01-15 20:46:02 +00:00
|
|
|
static SkTArray<SkAutoTDelete<skiatest::Test>, kMemcpyOK> gCPUTests, gGPUTests;
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
static void gather_tests() {
|
|
|
|
if (!FLAGS_tests) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
|
|
|
|
SkAutoTDelete<skiatest::Test> test(r->factory()(NULL));
|
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-15 20:46:02 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
test->setReporter(&gTestReporter);
|
2015-01-15 20:46:02 +00:00
|
|
|
if (test->isGPUTest() && gpu_supported()) {
|
|
|
|
gGPUTests.push_back().reset(test.detach());
|
|
|
|
} else if (!test->isGPUTest() && FLAGS_cpu) {
|
|
|
|
gCPUTests.push_back().reset(test.detach());
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
2014-06-30 13:36:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
static void run_test(SkAutoTDelete<skiatest::Test>* t) {
|
|
|
|
WallTimer timer;
|
|
|
|
timer.start();
|
|
|
|
skiatest::Test* test = t->get();
|
|
|
|
if (!FLAGS_dryRun) {
|
2015-01-15 20:46:02 +00:00
|
|
|
test->setGrContextFactory(GetThreadLocalGrContextFactory());
|
2015-01-15 18:56:12 +00:00
|
|
|
test->run();
|
|
|
|
if (!test->passed()) {
|
|
|
|
fail(SkStringPrintf("test %s failed", test->getName()));
|
2014-02-26 23:01:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
timer.end();
|
|
|
|
done(timer.fWall, "unit", "test", test->getName());
|
2015-01-15 18:15:02 +00:00
|
|
|
}
|
2014-02-26 23:01:57 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-01-15 18:15:02 +00:00
|
|
|
int dm_main();
|
|
|
|
int dm_main() {
|
|
|
|
SetupCrashHandler();
|
|
|
|
SkAutoGraphics ag;
|
|
|
|
SkTaskGroup::Enabler enabled(FLAGS_threads);
|
2015-01-15 16:30:25 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
gather_srcs();
|
|
|
|
gather_sinks();
|
|
|
|
gather_tests();
|
|
|
|
|
2015-01-15 20:46:02 +00:00
|
|
|
gPending = gSrcs.count() * gSinks.count() + gCPUTests.count() + gGPUTests.count();
|
2015-01-15 18:56:12 +00:00
|
|
|
SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
|
2015-01-15 20:46:02 +00:00
|
|
|
gSrcs.count(), gSinks.count(), gCPUTests.count() + gGPUTests.count(), gPending);
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
// We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
|
|
|
|
// but Sinks that identify as part of a particular enclave run serially on a single thread.
|
2015-01-15 20:46:02 +00:00
|
|
|
// CPU tests run on any thread. GPU tests depend on --gpu_threading.
|
2015-01-15 18:56:12 +00:00
|
|
|
SkTArray<Task> enclaves[kNumEnclaves];
|
|
|
|
for (int j = 0; j < gSinks.count(); j++) {
|
|
|
|
SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
|
|
|
|
for (int i = 0; i < gSrcs.count(); i++) {
|
|
|
|
tasks.push_back(Task(gSrcs[i], gSinks[j]));
|
|
|
|
}
|
2014-02-26 23:01:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
SK_COMPILE_ASSERT(kAnyThread_Enclave == 0, AnyThreadZero);
|
|
|
|
SkTaskGroup tg;
|
|
|
|
tg.batch( Task::Run, enclaves[0].begin(), enclaves[0].count());
|
|
|
|
tg.batch(run_enclave, enclaves+1, kNumEnclaves-1);
|
2015-01-15 20:46:02 +00:00
|
|
|
tg.batch( run_test, gCPUTests.begin(), gCPUTests.count());
|
|
|
|
if (FLAGS_gpu_threading) {
|
|
|
|
tg.batch(run_test, gGPUTests.begin(), gGPUTests.count());
|
2015-01-15 22:20:41 +00:00
|
|
|
#if !defined(SK_BUILD_FOR_WIN32)
|
2015-01-15 20:46:02 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < gGPUTests.count(); i++) {
|
|
|
|
run_test(&gGPUTests[i]);
|
|
|
|
}
|
2015-01-15 22:20:41 +00:00
|
|
|
#endif
|
2015-01-15 20:46:02 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
tg.wait();
|
|
|
|
// At this point we're back in single-threaded land.
|
2013-10-16 13:02:15 +00:00
|
|
|
|
2015-01-15 22:20:41 +00:00
|
|
|
// This is not ideal for parallelism, but Windows seems crash-prone if we run
|
|
|
|
// these GPU tests in parallel with any GPU Src/Sink work. Everyone else seems fine.
|
|
|
|
#if defined(SK_BUILD_FOR_WIN32)
|
|
|
|
for (int i = 0; i < gGPUTests.count(); i++) {
|
|
|
|
run_test(&gGPUTests[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SkDebugf("\n");
|
2015-01-15 18:56:12 +00:00
|
|
|
JsonWriter::DumpJson();
|
2014-12-13 00:41:12 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
if (gFailures.count() > 0) {
|
|
|
|
SkDebugf("Failures:\n");
|
|
|
|
for (int i = 0; i < gFailures.count(); i++) {
|
|
|
|
SkDebugf("\t%s", gFailures[i].c_str());
|
|
|
|
}
|
|
|
|
SkDebugf("%d failures\n", gFailures.count());
|
|
|
|
return 1;
|
2014-12-13 00:41:12 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
if (gPending > 0) {
|
|
|
|
SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
|
|
|
|
return 1;
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
return 0;
|
2013-10-16 13:02:15 +00:00
|
|
|
}
|
2014-11-13 16:06:40 +00:00
|
|
|
|
|
|
|
#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
return dm_main();
|
|
|
|
}
|
|
|
|
#endif
|