зеркало из https://github.com/mozilla/moz-skia.git
DM: add pdf
BUG=skia:2598 R=halcanary@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/312873002
This commit is contained in:
Родитель
9c4ff80d9b
Коммит
30bf3e2ffc
17
dm/DM.cpp
17
dm/DM.cpp
|
@ -14,6 +14,7 @@
|
||||||
#include "DMCpuGMTask.h"
|
#include "DMCpuGMTask.h"
|
||||||
#include "DMGpuGMTask.h"
|
#include "DMGpuGMTask.h"
|
||||||
#include "DMGpuSupport.h"
|
#include "DMGpuSupport.h"
|
||||||
|
#include "DMPDFTask.h"
|
||||||
#include "DMReporter.h"
|
#include "DMReporter.h"
|
||||||
#include "DMSKPTask.h"
|
#include "DMSKPTask.h"
|
||||||
#include "DMTask.h"
|
#include "DMTask.h"
|
||||||
|
@ -21,6 +22,13 @@
|
||||||
#include "DMTestTask.h"
|
#include "DMTestTask.h"
|
||||||
#include "DMWriteTask.h"
|
#include "DMWriteTask.h"
|
||||||
|
|
||||||
|
#ifdef SK_BUILD_POPPLER
|
||||||
|
# include "SkPDFRasterizer.h"
|
||||||
|
# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
|
||||||
|
#else
|
||||||
|
# define RASTERIZE_PDF_PROC NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
using skiagm::GM;
|
using skiagm::GM;
|
||||||
|
@ -49,9 +57,11 @@ DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
|
||||||
"^ and $ requires an exact match\n"
|
"^ and $ requires an exact match\n"
|
||||||
"If a GM does not match any list entry,\n"
|
"If a GM does not match any list entry,\n"
|
||||||
"it is skipped unless some list entry starts with ~");
|
"it is skipped unless some list entry starts with ~");
|
||||||
DEFINE_string(config, "565 8888 gpu nonrendering",
|
DEFINE_string(config, "565 8888 pdf gpu nonrendering",
|
||||||
"Options: 565 8888 gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 gpunull gpudebug angle mesa");
|
"Options: 565 8888 pdf gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 "
|
||||||
DEFINE_bool(dryRun, false, "Just print the tests that would be run, without actually running them.");
|
"gpunull gpudebug angle mesa");
|
||||||
|
DEFINE_bool(dryRun, false,
|
||||||
|
"Just print the tests that would be run, without actually running them.");
|
||||||
DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
|
DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
|
||||||
DEFINE_string(skps, "", "Directory to read skps from.");
|
DEFINE_string(skps, "", "Directory to read skps from.");
|
||||||
|
|
||||||
|
@ -111,6 +121,7 @@ static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
|
||||||
START("gpudebug", GpuGMTask, debug, 0);
|
START("gpudebug", GpuGMTask, debug, 0);
|
||||||
START("angle", GpuGMTask, angle, 0);
|
START("angle", GpuGMTask, angle, 0);
|
||||||
START("mesa", GpuGMTask, mesa, 0);
|
START("mesa", GpuGMTask, mesa, 0);
|
||||||
|
START("pdf", PDFTask, RASTERIZE_PDF_PROC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef START
|
#undef START
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DMPDFRasterizeTask.h"
|
||||||
|
#include "DMExpectationsTask.h"
|
||||||
|
#include "DMUtil.h"
|
||||||
|
#include "DMWriteTask.h"
|
||||||
|
#include "SkBitmap.h"
|
||||||
|
#include "SkCanvas.h"
|
||||||
|
#include "SkStream.h"
|
||||||
|
|
||||||
|
namespace DM {
|
||||||
|
|
||||||
|
PDFRasterizeTask::PDFRasterizeTask(const Task& parent,
|
||||||
|
SkData* pdf,
|
||||||
|
const Expectations& expectations,
|
||||||
|
RasterizePdfProc proc)
|
||||||
|
: CpuTask(parent)
|
||||||
|
, fName(UnderJoin(parent.name().c_str(), "rasterize"))
|
||||||
|
, fPdf(SkRef(pdf))
|
||||||
|
, fExpectations(expectations)
|
||||||
|
, fRasterize(proc) {}
|
||||||
|
|
||||||
|
void PDFRasterizeTask::draw() {
|
||||||
|
SkMemoryStream pdfStream(fPdf.get());
|
||||||
|
SkBitmap bitmap;
|
||||||
|
|
||||||
|
if (!fRasterize(&pdfStream, &bitmap)) {
|
||||||
|
this->fail();
|
||||||
|
}
|
||||||
|
if (!fExpectations.check(*this, bitmap)) {
|
||||||
|
this->fail();
|
||||||
|
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace DM
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DMPDFRasterizeTask_DEFINED
|
||||||
|
#define DMPDFRasterizeTask_DEFINED
|
||||||
|
|
||||||
|
#include "DMExpectations.h"
|
||||||
|
#include "DMTask.h"
|
||||||
|
#include "SkBitmap.h"
|
||||||
|
#include "SkData.h"
|
||||||
|
#include "SkStream.h"
|
||||||
|
#include "SkString.h"
|
||||||
|
#include "SkTemplates.h"
|
||||||
|
|
||||||
|
namespace DM {
|
||||||
|
|
||||||
|
typedef bool (*RasterizePdfProc)(SkStream* pdf, SkBitmap* output);
|
||||||
|
|
||||||
|
class PDFRasterizeTask : public CpuTask {
|
||||||
|
public:
|
||||||
|
PDFRasterizeTask(const Task& parent,
|
||||||
|
SkData* pdf,
|
||||||
|
const Expectations&,
|
||||||
|
RasterizePdfProc);
|
||||||
|
|
||||||
|
virtual void draw() SK_OVERRIDE;
|
||||||
|
virtual bool shouldSkip() const SK_OVERRIDE { return NULL == fRasterize; }
|
||||||
|
virtual SkString name() const SK_OVERRIDE { return fName; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const SkString fName;
|
||||||
|
SkAutoTUnref<SkData> fPdf;
|
||||||
|
const Expectations& fExpectations;
|
||||||
|
RasterizePdfProc fRasterize;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace DM
|
||||||
|
|
||||||
|
#endif // DMPDFRasterizeTask_DEFINED
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DMPDFTask.h"
|
||||||
|
#include "DMExpectationsTask.h"
|
||||||
|
#include "DMPDFRasterizeTask.h"
|
||||||
|
#include "DMUtil.h"
|
||||||
|
#include "DMWriteTask.h"
|
||||||
|
#include "SkCommandLineFlags.h"
|
||||||
|
#include "SkDocument.h"
|
||||||
|
|
||||||
|
DEFINE_bool(pdf, true, "PDF backend master switch.");
|
||||||
|
|
||||||
|
namespace DM {
|
||||||
|
|
||||||
|
PDFTask::PDFTask(const char* suffix,
|
||||||
|
Reporter* reporter,
|
||||||
|
TaskRunner* taskRunner,
|
||||||
|
const Expectations& expectations,
|
||||||
|
skiagm::GMRegistry::Factory factory,
|
||||||
|
RasterizePdfProc rasterizePdfProc)
|
||||||
|
: CpuTask(reporter, taskRunner)
|
||||||
|
, fGM(factory(NULL))
|
||||||
|
, fName(UnderJoin(fGM->getName(), suffix))
|
||||||
|
, fExpectations(expectations)
|
||||||
|
, fRasterize(rasterizePdfProc) {}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class SinglePagePDF {
|
||||||
|
public:
|
||||||
|
SinglePagePDF(SkScalar width, SkScalar height)
|
||||||
|
: fDocument(SkDocument::CreatePDF(&fWriteStream))
|
||||||
|
, fCanvas(fDocument->beginPage(width, height)) {}
|
||||||
|
|
||||||
|
SkCanvas* canvas() { return fCanvas; }
|
||||||
|
|
||||||
|
SkData* end() {
|
||||||
|
fCanvas->flush();
|
||||||
|
fDocument->endPage();
|
||||||
|
fDocument->close();
|
||||||
|
return fWriteStream.copyToData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SkDynamicMemoryWStream fWriteStream;
|
||||||
|
SkAutoTUnref<SkDocument> fDocument;
|
||||||
|
SkCanvas* fCanvas;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void PDFTask::draw() {
|
||||||
|
SinglePagePDF pdf(fGM->width(), fGM->height());
|
||||||
|
//TODO(mtklein): GM doesn't do this. Why not?
|
||||||
|
//pdf.canvas()->concat(fGM->getInitialTransform());
|
||||||
|
fGM->draw(pdf.canvas());
|
||||||
|
|
||||||
|
SkAutoTUnref<SkData> pdfData(pdf.end());
|
||||||
|
SkASSERT(pdfData.get());
|
||||||
|
|
||||||
|
if (!(fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag)) {
|
||||||
|
this->spawnChild(SkNEW_ARGS(PDFRasterizeTask,
|
||||||
|
(*this, pdfData.get(), fExpectations, fRasterize)));
|
||||||
|
}
|
||||||
|
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf")));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PDFTask::shouldSkip() const {
|
||||||
|
if (!FLAGS_pdf) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace DM
|
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef DMPDFTask_DEFINED
|
||||||
|
#define DMPDFTask_DEFINED
|
||||||
|
|
||||||
|
#include "DMPDFRasterizeTask.h"
|
||||||
|
#include "DMExpectations.h"
|
||||||
|
#include "DMTask.h"
|
||||||
|
#include "SkBitmap.h"
|
||||||
|
#include "SkString.h"
|
||||||
|
#include "SkTemplates.h"
|
||||||
|
#include "gm.h"
|
||||||
|
|
||||||
|
namespace DM {
|
||||||
|
|
||||||
|
// This task renders a GM using Skia's PDF backend.
|
||||||
|
// If rasterizePdfProc is non-NULL, it will spawn a PDFRasterizeTask.
|
||||||
|
class PDFTask : public CpuTask {
|
||||||
|
public:
|
||||||
|
PDFTask(const char* suffix,
|
||||||
|
Reporter*,
|
||||||
|
TaskRunner*,
|
||||||
|
const Expectations&,
|
||||||
|
skiagm::GMRegistry::Factory,
|
||||||
|
RasterizePdfProc);
|
||||||
|
|
||||||
|
virtual void draw() SK_OVERRIDE;
|
||||||
|
|
||||||
|
virtual bool shouldSkip() const SK_OVERRIDE;
|
||||||
|
|
||||||
|
virtual SkString name() const SK_OVERRIDE { return fName; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
SkAutoTDelete<skiagm::GM> fGM;
|
||||||
|
const SkString fName;
|
||||||
|
const Expectations& fExpectations;
|
||||||
|
RasterizePdfProc fRasterize;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace DM
|
||||||
|
|
||||||
|
#endif // DMPDFTask_DEFINED
|
|
@ -28,14 +28,26 @@ static int split_suffixes(int N, const char* name, SkTArray<SkString>* out) {
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteTask::WriteTask(const Task& parent, SkBitmap bitmap)
|
inline static SkString find_gm_name(const Task& parent, SkTArray<SkString>* suffixList) {
|
||||||
: CpuTask(parent), fBitmap(bitmap) {
|
|
||||||
const int suffixes = parent.depth() + 1;
|
const int suffixes = parent.depth() + 1;
|
||||||
const SkString& name = parent.name();
|
const SkString& name = parent.name();
|
||||||
const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffixes);
|
const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), suffixList);
|
||||||
fGmName.set(name.c_str(), name.size()-totalSuffixLength);
|
return SkString(name.c_str(), name.size() - totalSuffixLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WriteTask::WriteTask(const Task& parent, SkBitmap bitmap)
|
||||||
|
: CpuTask(parent)
|
||||||
|
, fGmName(find_gm_name(parent, &fSuffixes))
|
||||||
|
, fBitmap(bitmap)
|
||||||
|
, fData(NULL)
|
||||||
|
, fExtension(".png") {}
|
||||||
|
|
||||||
|
WriteTask::WriteTask(const Task& parent, SkData *data, const char* ext)
|
||||||
|
: CpuTask(parent)
|
||||||
|
, fGmName(find_gm_name(parent, &fSuffixes))
|
||||||
|
, fData(SkRef(data))
|
||||||
|
, fExtension(ext) {}
|
||||||
|
|
||||||
void WriteTask::makeDirOrFail(SkString dir) {
|
void WriteTask::makeDirOrFail(SkString dir) {
|
||||||
if (!sk_mkdir(dir.c_str())) {
|
if (!sk_mkdir(dir.c_str())) {
|
||||||
this->fail();
|
this->fail();
|
||||||
|
@ -103,6 +115,16 @@ struct PngAndRaw {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Does not take ownership of data.
|
||||||
|
bool save_data_to_file(const SkData* data, const char* path) {
|
||||||
|
SkFILEWStream stream(path);
|
||||||
|
if (!stream.isValid() || !stream.write(data->data(), data->size())) {
|
||||||
|
SkDebugf("Can't write %s.\n", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void WriteTask::draw() {
|
void WriteTask::draw() {
|
||||||
|
@ -112,9 +134,13 @@ void WriteTask::draw() {
|
||||||
dir = SkOSPath::SkPathJoin(dir.c_str(), fSuffixes[i].c_str());
|
dir = SkOSPath::SkPathJoin(dir.c_str(), fSuffixes[i].c_str());
|
||||||
this->makeDirOrFail(dir);
|
this->makeDirOrFail(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkString path = SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str());
|
SkString path = SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str());
|
||||||
path.append(".png");
|
path.append(fExtension);
|
||||||
if (!PngAndRaw::Encode(fBitmap, path.c_str())) {
|
|
||||||
|
const bool ok = fData.get() ? save_data_to_file(fData, path.c_str())
|
||||||
|
: PngAndRaw::Encode(fBitmap, path.c_str());
|
||||||
|
if (!ok) {
|
||||||
this->fail();
|
this->fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,12 @@ namespace DM {
|
||||||
class WriteTask : public CpuTask {
|
class WriteTask : public CpuTask {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WriteTask(const Task& parent, // WriteTask must be a child Task. Pass its parent here.
|
WriteTask(const Task& parent, // WriteTask must be a child task.
|
||||||
SkBitmap bitmap); // Bitmap to write.
|
SkBitmap bitmap); // Bitmap to encode to PNG and write to disk.
|
||||||
|
|
||||||
|
WriteTask(const Task& parent, // WriteTask must be a child task.
|
||||||
|
SkData *data, // Pre-encoded data to write to disk.
|
||||||
|
const char* ext); // File extension.
|
||||||
|
|
||||||
virtual void draw() SK_OVERRIDE;
|
virtual void draw() SK_OVERRIDE;
|
||||||
virtual bool shouldSkip() const SK_OVERRIDE;
|
virtual bool shouldSkip() const SK_OVERRIDE;
|
||||||
|
@ -34,8 +38,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SkTArray<SkString> fSuffixes;
|
SkTArray<SkString> fSuffixes;
|
||||||
SkString fGmName;
|
const SkString fGmName;
|
||||||
const SkBitmap fBitmap;
|
const SkBitmap fBitmap;
|
||||||
|
SkAutoTUnref<SkData> fData;
|
||||||
|
const char* fExtension;
|
||||||
|
|
||||||
void makeDirOrFail(SkString dir);
|
void makeDirOrFail(SkString dir);
|
||||||
};
|
};
|
||||||
|
|
11
dm/README
11
dm/README
|
@ -1,13 +1,4 @@
|
||||||
DM is like GM, but multithreaded. It doesn't do everything GM does yet.
|
DM is like GM, but multithreaded. It doesn't do everything GM does.
|
||||||
|
|
||||||
Current approximate list of missing features:
|
|
||||||
--config pdf
|
|
||||||
--mismatchPath
|
|
||||||
--missingExpectationsPath
|
|
||||||
--writePicturePath
|
|
||||||
|
|
||||||
--deferred
|
|
||||||
|
|
||||||
|
|
||||||
DM's design is based around Tasks and a TaskRunner.
|
DM's design is based around Tasks and a TaskRunner.
|
||||||
|
|
||||||
|
|
17
gyp/dm.gyp
17
gyp/dm.gyp
|
@ -32,13 +32,15 @@
|
||||||
'../dm/DMCpuGMTask.cpp',
|
'../dm/DMCpuGMTask.cpp',
|
||||||
'../dm/DMExpectationsTask.cpp',
|
'../dm/DMExpectationsTask.cpp',
|
||||||
'../dm/DMGpuGMTask.cpp',
|
'../dm/DMGpuGMTask.cpp',
|
||||||
|
'../dm/DMPDFRasterizeTask.cpp',
|
||||||
|
'../dm/DMPDFTask.cpp',
|
||||||
'../dm/DMPipeTask.cpp',
|
'../dm/DMPipeTask.cpp',
|
||||||
'../dm/DMQuiltTask.cpp',
|
'../dm/DMQuiltTask.cpp',
|
||||||
'../dm/DMRecordTask.cpp',
|
'../dm/DMRecordTask.cpp',
|
||||||
'../dm/DMReplayTask.cpp',
|
'../dm/DMReplayTask.cpp',
|
||||||
'../dm/DMReporter.cpp',
|
'../dm/DMReporter.cpp',
|
||||||
'../dm/DMSerializeTask.cpp',
|
|
||||||
'../dm/DMSKPTask.cpp',
|
'../dm/DMSKPTask.cpp',
|
||||||
|
'../dm/DMSerializeTask.cpp',
|
||||||
'../dm/DMTask.cpp',
|
'../dm/DMTask.cpp',
|
||||||
'../dm/DMTaskRunner.cpp',
|
'../dm/DMTaskRunner.cpp',
|
||||||
'../dm/DMTestTask.cpp',
|
'../dm/DMTestTask.cpp',
|
||||||
|
@ -60,14 +62,17 @@
|
||||||
'record.gyp:*',
|
'record.gyp:*',
|
||||||
],
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['skia_android_framework',
|
['skia_android_framework', {
|
||||||
{
|
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'-lskia',
|
|
||||||
'-lcutils',
|
'-lcutils',
|
||||||
|
'-lskia',
|
||||||
],
|
],
|
||||||
},
|
}],
|
||||||
],
|
['skia_poppler_enabled', {
|
||||||
|
'sources': [ '../src/utils/SkPDFRasterizer.cpp' ],
|
||||||
|
'defines': [ 'SK_BUILD_POPPLER' ],
|
||||||
|
'dependencies': [ 'poppler.gyp:*' ],
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче