2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-08-19 17:22:05 +00:00
|
|
|
|
2011-10-10 13:19:10 +00:00
|
|
|
#include "gm.h"
|
2012-02-14 14:53:59 +00:00
|
|
|
#include "system_preferences.h"
|
2012-04-19 19:15:35 +00:00
|
|
|
#include "GrContextFactory.h"
|
2011-08-19 17:22:05 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2009-07-08 02:54:47 +00:00
|
|
|
#include "SkColorPriv.h"
|
2011-06-24 19:12:12 +00:00
|
|
|
#include "SkData.h"
|
2012-01-18 16:21:08 +00:00
|
|
|
#include "SkDeferredCanvas.h"
|
2011-08-19 17:22:05 +00:00
|
|
|
#include "SkDevice.h"
|
2012-06-04 17:17:36 +00:00
|
|
|
#include "SkGPipe.h"
|
2011-08-19 17:22:05 +00:00
|
|
|
#include "SkGpuCanvas.h"
|
|
|
|
#include "SkGpuDevice.h"
|
2009-06-21 00:49:18 +00:00
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkImageEncoder.h"
|
2011-04-25 15:49:53 +00:00
|
|
|
#include "SkPicture.h"
|
2012-06-05 19:35:09 +00:00
|
|
|
#include "SkRefCnt.h"
|
2012-06-06 21:07:10 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SamplePipeControllers.h"
|
2010-12-20 19:46:07 +00:00
|
|
|
|
2011-12-30 16:02:53 +00:00
|
|
|
static bool gForceBWtext;
|
|
|
|
|
2011-11-08 14:59:38 +00:00
|
|
|
extern bool gSkSuppressFontCachePurgeSpew;
|
|
|
|
|
2010-12-20 19:46:07 +00:00
|
|
|
#ifdef SK_SUPPORT_PDF
|
2011-04-25 15:49:53 +00:00
|
|
|
#include "SkPDFDevice.h"
|
|
|
|
#include "SkPDFDocument.h"
|
2010-12-20 19:46:07 +00:00
|
|
|
#endif
|
2009-06-10 15:38:48 +00:00
|
|
|
|
2012-01-18 20:11:13 +00:00
|
|
|
// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
|
|
|
|
// stop writing out XPS-format image baselines in gm.
|
|
|
|
#undef SK_SUPPORT_XPS
|
2011-10-10 13:19:10 +00:00
|
|
|
#ifdef SK_SUPPORT_XPS
|
|
|
|
#include "SkXPSDevice.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-29 12:54:46 +00:00
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
|
|
|
#include "SkCGUtils.h"
|
2011-06-29 19:42:58 +00:00
|
|
|
#define CAN_IMAGE_PDF 1
|
2011-06-29 12:54:46 +00:00
|
|
|
#else
|
2011-06-29 19:42:58 +00:00
|
|
|
#define CAN_IMAGE_PDF 0
|
2011-06-29 12:54:46 +00:00
|
|
|
#endif
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
typedef int ErrorBitfield;
|
|
|
|
const static ErrorBitfield ERROR_NONE = 0x00;
|
|
|
|
const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01;
|
|
|
|
const static ErrorBitfield ERROR_PIXEL_MISMATCH = 0x02;
|
|
|
|
const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04;
|
|
|
|
const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08;
|
|
|
|
const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10;
|
|
|
|
|
2012-05-17 15:28:20 +00:00
|
|
|
// If true, emit a messange when we can't find a reference image to compare
|
|
|
|
static bool gNotifyMissingReadReference;
|
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
using namespace skiagm;
|
|
|
|
|
|
|
|
class Iter {
|
|
|
|
public:
|
|
|
|
Iter() {
|
2011-06-13 21:55:32 +00:00
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
2009-06-20 02:38:16 +00:00
|
|
|
fReg = GMRegistry::Head();
|
2009-06-10 15:38:48 +00:00
|
|
|
}
|
2011-01-18 21:05:42 +00:00
|
|
|
|
2009-06-20 02:38:16 +00:00
|
|
|
GM* next() {
|
2009-06-10 15:38:48 +00:00
|
|
|
if (fReg) {
|
2009-06-20 02:38:16 +00:00
|
|
|
GMRegistry::Factory fact = fReg->factory();
|
2009-06-10 15:38:48 +00:00
|
|
|
fReg = fReg->next();
|
2009-06-20 02:38:16 +00:00
|
|
|
return fact(0);
|
2009-06-10 15:38:48 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-18 21:05:42 +00:00
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
static int Count() {
|
2009-06-20 02:38:16 +00:00
|
|
|
const GMRegistry* reg = GMRegistry::Head();
|
2009-06-10 15:38:48 +00:00
|
|
|
int count = 0;
|
|
|
|
while (reg) {
|
|
|
|
count += 1;
|
|
|
|
reg = reg->next();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2011-01-18 21:05:42 +00:00
|
|
|
|
2009-06-10 15:38:48 +00:00
|
|
|
private:
|
|
|
|
const GMRegistry* fReg;
|
|
|
|
};
|
|
|
|
|
2009-06-21 00:49:18 +00:00
|
|
|
static SkString make_name(const char shortName[], const char configName[]) {
|
|
|
|
SkString name(shortName);
|
|
|
|
name.appendf("_%s", configName);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
static SkString make_filename(const char path[],
|
|
|
|
const char pathSuffix[],
|
|
|
|
const SkString& name,
|
|
|
|
const char suffix[]) {
|
2009-06-21 00:49:18 +00:00
|
|
|
SkString filename(path);
|
2011-04-25 15:49:53 +00:00
|
|
|
if (filename.endsWith("/")) {
|
|
|
|
filename.remove(filename.size() - 1, 1);
|
2009-06-10 15:38:48 +00:00
|
|
|
}
|
2011-04-25 15:49:53 +00:00
|
|
|
filename.append(pathSuffix);
|
|
|
|
filename.append("/");
|
2010-12-20 19:46:07 +00:00
|
|
|
filename.appendf("%s.%s", name.c_str(), suffix);
|
2009-06-21 00:49:18 +00:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2009-07-08 02:54:47 +00:00
|
|
|
/* since PNG insists on unpremultiplying our alpha, we take no precision chances
|
|
|
|
and force all pixels to be 100% opaque, otherwise on compare we may not get
|
|
|
|
a perfect match.
|
|
|
|
*/
|
|
|
|
static void force_all_opaque(const SkBitmap& bitmap) {
|
|
|
|
SkAutoLockPixels lock(bitmap);
|
|
|
|
for (int y = 0; y < bitmap.height(); y++) {
|
|
|
|
for (int x = 0; x < bitmap.width(); x++) {
|
|
|
|
*bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
|
|
|
|
SkBitmap copy;
|
|
|
|
bitmap.copyTo(©, SkBitmap::kARGB_8888_Config);
|
|
|
|
force_all_opaque(copy);
|
|
|
|
return SkImageEncoder::EncodeFile(path.c_str(), copy,
|
|
|
|
SkImageEncoder::kPNG_Type, 100);
|
|
|
|
}
|
|
|
|
|
2010-12-20 21:10:29 +00:00
|
|
|
static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) {
|
2011-04-25 15:49:53 +00:00
|
|
|
int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
|
|
|
|
int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
|
|
|
|
int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
|
|
|
|
return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db));
|
2010-12-20 21:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void compute_diff(const SkBitmap& target, const SkBitmap& base,
|
2011-04-25 15:49:53 +00:00
|
|
|
SkBitmap* diff) {
|
|
|
|
SkAutoLockPixels alp(*diff);
|
2010-12-20 21:10:29 +00:00
|
|
|
|
|
|
|
const int w = target.width();
|
|
|
|
const int h = target.height();
|
|
|
|
for (int y = 0; y < h; y++) {
|
|
|
|
for (int x = 0; x < w; x++) {
|
|
|
|
SkPMColor c0 = *base.getAddr32(x, y);
|
|
|
|
SkPMColor c1 = *target.getAddr32(x, y);
|
2011-04-25 15:49:53 +00:00
|
|
|
SkPMColor d = 0;
|
|
|
|
if (c0 != c1) {
|
|
|
|
d = compute_diff_pmcolor(c0, c1);
|
|
|
|
}
|
|
|
|
*diff->getAddr32(x, y) = d;
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 21:10:29 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield compare(const SkBitmap& target, const SkBitmap& base,
|
|
|
|
const SkString& name,
|
|
|
|
const char* renderModeDescriptor,
|
|
|
|
SkBitmap* diff) {
|
2009-07-08 02:54:47 +00:00
|
|
|
SkBitmap copy;
|
|
|
|
const SkBitmap* bm = ⌖
|
|
|
|
if (target.config() != SkBitmap::kARGB_8888_Config) {
|
|
|
|
target.copyTo(©, SkBitmap::kARGB_8888_Config);
|
|
|
|
bm = ©
|
|
|
|
}
|
2011-06-17 13:11:45 +00:00
|
|
|
SkBitmap baseCopy;
|
|
|
|
const SkBitmap* bp = &base;
|
|
|
|
if (base.config() != SkBitmap::kARGB_8888_Config) {
|
|
|
|
base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config);
|
|
|
|
bp = &baseCopy;
|
|
|
|
}
|
2009-07-08 02:54:47 +00:00
|
|
|
|
|
|
|
force_all_opaque(*bm);
|
2011-06-17 13:11:45 +00:00
|
|
|
force_all_opaque(*bp);
|
2009-07-08 02:54:47 +00:00
|
|
|
|
|
|
|
const int w = bm->width();
|
|
|
|
const int h = bm->height();
|
2011-06-17 13:11:45 +00:00
|
|
|
if (w != bp->width() || h != bp->height()) {
|
2011-06-09 20:30:03 +00:00
|
|
|
SkDebugf(
|
|
|
|
"---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n",
|
|
|
|
renderModeDescriptor, name.c_str(),
|
2011-06-17 13:11:45 +00:00
|
|
|
bp->width(), bp->height(), w, h);
|
2011-12-28 19:31:01 +00:00
|
|
|
return ERROR_DIMENSION_MISMATCH;
|
2009-07-08 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoLockPixels bmLock(*bm);
|
2011-06-17 13:11:45 +00:00
|
|
|
SkAutoLockPixels baseLock(*bp);
|
2009-07-08 02:54:47 +00:00
|
|
|
|
|
|
|
for (int y = 0; y < h; y++) {
|
|
|
|
for (int x = 0; x < w; x++) {
|
2011-06-17 13:11:45 +00:00
|
|
|
SkPMColor c0 = *bp->getAddr32(x, y);
|
2009-07-08 02:54:47 +00:00
|
|
|
SkPMColor c1 = *bm->getAddr32(x, y);
|
|
|
|
if (c0 != c1) {
|
2011-06-09 20:30:03 +00:00
|
|
|
SkDebugf(
|
|
|
|
"----- %s pixel mismatch for %s at [%d %d] base 0x%08X current 0x%08X\n",
|
|
|
|
renderModeDescriptor, name.c_str(), x, y, c0, c1);
|
2010-12-20 21:10:29 +00:00
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
if (diff) {
|
|
|
|
diff->setConfig(SkBitmap::kARGB_8888_Config, w, h);
|
|
|
|
diff->allocPixels();
|
2011-06-17 13:11:45 +00:00
|
|
|
compute_diff(*bm, *bp, diff);
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2011-12-28 19:31:01 +00:00
|
|
|
return ERROR_PIXEL_MISMATCH;
|
2009-07-08 02:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 21:10:29 +00:00
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
// they're equal
|
2011-12-28 19:31:01 +00:00
|
|
|
return ERROR_NONE;
|
2009-06-21 00:49:18 +00:00
|
|
|
}
|
2009-06-10 15:38:48 +00:00
|
|
|
|
2011-10-10 13:19:10 +00:00
|
|
|
static bool write_document(const SkString& path,
|
|
|
|
const SkDynamicMemoryWStream& document) {
|
2011-02-03 23:00:40 +00:00
|
|
|
SkFILEWStream stream(path.c_str());
|
2011-10-10 13:19:10 +00:00
|
|
|
SkAutoDataUnref data(document.copyToData());
|
2011-06-24 19:12:12 +00:00
|
|
|
return stream.writeData(data.get());
|
2010-12-20 19:46:07 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 23:00:40 +00:00
|
|
|
enum Backend {
|
|
|
|
kRaster_Backend,
|
|
|
|
kGPU_Backend,
|
|
|
|
kPDF_Backend,
|
2011-10-10 13:19:10 +00:00
|
|
|
kXPS_Backend,
|
2011-02-03 23:00:40 +00:00
|
|
|
};
|
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
enum ConfigFlags {
|
|
|
|
kNone_ConfigFlag = 0x0,
|
|
|
|
/* Write GM images if a write path is provided. */
|
|
|
|
kWrite_ConfigFlag = 0x1,
|
|
|
|
/* Read comparison GM images if a read path is provided. */
|
|
|
|
kRead_ConfigFlag = 0x2,
|
|
|
|
kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
|
|
|
|
};
|
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
struct ConfigData {
|
2012-04-19 19:15:35 +00:00
|
|
|
SkBitmap::Config fConfig;
|
|
|
|
Backend fBackend;
|
|
|
|
GrContextFactory::GLContextType fGLContextType; // GPU backend only
|
|
|
|
int fSampleCnt; // GPU backend only
|
|
|
|
ConfigFlags fFlags;
|
|
|
|
const char* fName;
|
2011-04-25 15:49:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns true if processing should continue, false to skip the
|
|
|
|
/// remainder of this config for this GM.
|
|
|
|
//@todo thudson 22 April 2011 - could refactor this to take in
|
|
|
|
// a factory to generate the context, always call readPixels()
|
|
|
|
// (logically a noop for rasters, if wasted time), and thus collapse the
|
|
|
|
// GPU special case and also let this be used for SkPicture testing.
|
|
|
|
static void setup_bitmap(const ConfigData& gRec, SkISize& size,
|
|
|
|
SkBitmap* bitmap) {
|
|
|
|
bitmap->setConfig(gRec.fConfig, size.width(), size.height());
|
|
|
|
bitmap->allocPixels();
|
|
|
|
bitmap->eraseColor(0);
|
|
|
|
}
|
|
|
|
|
2011-12-30 16:02:53 +00:00
|
|
|
#include "SkDrawFilter.h"
|
|
|
|
class BWTextDrawFilter : public SkDrawFilter {
|
|
|
|
public:
|
|
|
|
virtual void filter(SkPaint*, Type) SK_OVERRIDE;
|
|
|
|
};
|
|
|
|
void BWTextDrawFilter::filter(SkPaint* p, Type t) {
|
|
|
|
if (kText_Type == t) {
|
|
|
|
p->setAntiAlias(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void installFilter(SkCanvas* canvas) {
|
|
|
|
if (gForceBWtext) {
|
|
|
|
canvas->setDrawFilter(new BWTextDrawFilter)->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 17:34:30 +00:00
|
|
|
static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF = false) {
|
2012-06-04 20:00:01 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
2012-03-21 17:34:30 +00:00
|
|
|
if (!isPDF) {
|
2012-06-04 20:00:01 +00:00
|
|
|
canvas->concat(gm->getInitialTransform());
|
2012-03-21 17:34:30 +00:00
|
|
|
}
|
2011-12-30 16:02:53 +00:00
|
|
|
installFilter(canvas);
|
|
|
|
gm->draw(canvas);
|
|
|
|
canvas->setDrawFilter(NULL);
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec,
|
|
|
|
GrContext* context,
|
|
|
|
GrRenderTarget* rt,
|
2012-01-18 16:21:08 +00:00
|
|
|
SkBitmap* bitmap,
|
|
|
|
bool deferred) {
|
2011-04-25 15:49:53 +00:00
|
|
|
SkISize size (gm->getISize());
|
2011-06-17 13:11:45 +00:00
|
|
|
setup_bitmap(gRec, size, bitmap);
|
2011-04-25 15:49:53 +00:00
|
|
|
|
|
|
|
if (gRec.fBackend == kRaster_Backend) {
|
2012-01-18 16:21:08 +00:00
|
|
|
SkCanvas* canvas;
|
|
|
|
if (deferred) {
|
|
|
|
canvas = new SkDeferredCanvas;
|
|
|
|
canvas->setDevice(new SkDevice(*bitmap))->unref();
|
|
|
|
} else {
|
|
|
|
canvas = new SkCanvas(*bitmap);
|
|
|
|
}
|
|
|
|
SkAutoUnref canvasUnref(canvas);
|
|
|
|
invokeGM(gm, canvas);
|
2012-01-30 14:53:22 +00:00
|
|
|
canvas->flush();
|
2011-04-25 15:49:53 +00:00
|
|
|
} else { // GPU
|
|
|
|
if (NULL == context) {
|
2011-12-28 19:31:01 +00:00
|
|
|
return ERROR_NO_GPU_CONTEXT;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2012-01-18 16:21:08 +00:00
|
|
|
SkCanvas* gc;
|
|
|
|
if (deferred) {
|
|
|
|
gc = new SkDeferredCanvas;
|
|
|
|
} else {
|
|
|
|
gc = new SkGpuCanvas(context, rt);
|
|
|
|
}
|
|
|
|
SkAutoUnref gcUnref(gc);
|
|
|
|
gc->setDevice(new SkGpuDevice(context, rt))->unref();
|
|
|
|
invokeGM(gm, gc);
|
2011-06-16 19:10:39 +00:00
|
|
|
// the device is as large as the current rendertarget, so we explicitly
|
|
|
|
// only readback the amount we expect (in size)
|
2011-06-17 13:11:45 +00:00
|
|
|
// overwrite our previous allocation
|
2011-11-02 19:57:21 +00:00
|
|
|
bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
|
|
|
|
size.fHeight);
|
2012-01-18 16:21:08 +00:00
|
|
|
gc->readPixels(bitmap, 0, 0);
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2011-12-28 19:31:01 +00:00
|
|
|
return ERROR_NONE;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
|
|
|
|
SkPicture* pict, SkBitmap* bitmap) {
|
|
|
|
SkISize size = gm->getISize();
|
|
|
|
setup_bitmap(gRec, size, bitmap);
|
|
|
|
SkCanvas canvas(*bitmap);
|
2011-12-30 16:02:53 +00:00
|
|
|
installFilter(&canvas);
|
2011-04-25 15:49:53 +00:00
|
|
|
canvas.drawPicture(*pict);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
|
|
|
|
#ifdef SK_SUPPORT_PDF
|
2012-03-21 17:34:30 +00:00
|
|
|
SkMatrix initialTransform = gm->getInitialTransform();
|
|
|
|
SkISize pageSize = gm->getISize();
|
|
|
|
SkPDFDevice* dev = NULL;
|
|
|
|
if (initialTransform.isIdentity()) {
|
|
|
|
dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
|
|
|
|
} else {
|
|
|
|
SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
|
|
|
|
SkIntToScalar(pageSize.height()));
|
|
|
|
initialTransform.mapRect(&content);
|
|
|
|
content.intersect(0, 0, SkIntToScalar(pageSize.width()),
|
|
|
|
SkIntToScalar(pageSize.height()));
|
|
|
|
SkISize contentSize =
|
|
|
|
SkISize::Make(SkScalarRoundToInt(content.width()),
|
|
|
|
SkScalarRoundToInt(content.height()));
|
|
|
|
dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
|
|
|
|
}
|
2011-04-25 15:49:53 +00:00
|
|
|
SkAutoUnref aur(dev);
|
|
|
|
|
|
|
|
SkCanvas c(dev);
|
2012-03-21 17:34:30 +00:00
|
|
|
invokeGM(gm, &c, true);
|
2011-04-25 15:49:53 +00:00
|
|
|
|
|
|
|
SkPDFDocument doc;
|
|
|
|
doc.appendPage(dev);
|
|
|
|
doc.emitPDF(&pdf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-10 13:19:10 +00:00
|
|
|
static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
|
|
|
|
#ifdef SK_SUPPORT_XPS
|
|
|
|
SkISize size = gm->getISize();
|
|
|
|
|
|
|
|
SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height()));
|
2012-01-05 16:56:29 +00:00
|
|
|
static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
|
|
|
|
static const SkScalar upm = 72 * inchesPerMeter;
|
|
|
|
SkVector unitsPerMeter = SkPoint::Make(upm, upm);
|
|
|
|
static const SkScalar ppm = 200 * inchesPerMeter;
|
|
|
|
SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
|
2011-10-10 13:19:10 +00:00
|
|
|
|
|
|
|
SkXPSDevice* dev = new SkXPSDevice();
|
|
|
|
SkAutoUnref aur(dev);
|
|
|
|
|
|
|
|
SkCanvas c(dev);
|
|
|
|
dev->beginPortfolio(&xps);
|
|
|
|
dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
|
2011-12-30 16:02:53 +00:00
|
|
|
invokeGM(gm, &c);
|
2011-10-10 13:19:10 +00:00
|
|
|
dev->endSheet();
|
|
|
|
dev->endPortfolio();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield write_reference_image(const ConfigData& gRec,
|
|
|
|
const char writePath [],
|
|
|
|
const char renderModeDescriptor [],
|
|
|
|
const SkString& name,
|
|
|
|
SkBitmap& bitmap,
|
|
|
|
SkDynamicMemoryWStream* document) {
|
2011-04-25 15:49:53 +00:00
|
|
|
SkString path;
|
|
|
|
bool success = false;
|
2011-10-10 13:19:10 +00:00
|
|
|
if (gRec.fBackend == kRaster_Backend ||
|
|
|
|
gRec.fBackend == kGPU_Backend ||
|
|
|
|
(gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
|
|
|
|
|
2011-06-09 20:30:03 +00:00
|
|
|
path = make_filename(writePath, renderModeDescriptor, name, "png");
|
2011-04-25 15:49:53 +00:00
|
|
|
success = write_bitmap(path, bitmap);
|
2011-06-29 12:54:46 +00:00
|
|
|
}
|
|
|
|
if (kPDF_Backend == gRec.fBackend) {
|
2011-06-09 20:30:03 +00:00
|
|
|
path = make_filename(writePath, renderModeDescriptor, name, "pdf");
|
2011-10-10 13:19:10 +00:00
|
|
|
success = write_document(path, *document);
|
|
|
|
}
|
|
|
|
if (kXPS_Backend == gRec.fBackend) {
|
|
|
|
path = make_filename(writePath, renderModeDescriptor, name, "xps");
|
|
|
|
success = write_document(path, *document);
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2011-12-28 19:31:01 +00:00
|
|
|
if (success) {
|
|
|
|
return ERROR_NONE;
|
|
|
|
} else {
|
2011-04-25 15:49:53 +00:00
|
|
|
fprintf(stderr, "FAILED to write %s\n", path.c_str());
|
2011-12-28 19:31:01 +00:00
|
|
|
return ERROR_WRITING_REFERENCE_IMAGE;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield compare_to_reference_image(const SkString& name,
|
|
|
|
SkBitmap &bitmap,
|
|
|
|
const SkBitmap& comparisonBitmap,
|
|
|
|
const char diffPath [],
|
|
|
|
const char renderModeDescriptor []) {
|
|
|
|
ErrorBitfield errors;
|
2011-06-17 13:11:45 +00:00
|
|
|
SkBitmap diffBitmap;
|
2011-12-28 19:31:01 +00:00
|
|
|
errors = compare(bitmap, comparisonBitmap, name, renderModeDescriptor,
|
|
|
|
diffPath ? &diffBitmap : NULL);
|
2012-04-09 20:20:10 +00:00
|
|
|
if ((ERROR_NONE != errors) && diffPath) {
|
|
|
|
// write out the generated image
|
|
|
|
SkString genName = make_filename(diffPath, "", name, "png");
|
|
|
|
if (!write_bitmap(genName, bitmap)) {
|
2011-12-28 19:31:01 +00:00
|
|
|
errors |= ERROR_WRITING_REFERENCE_IMAGE;
|
|
|
|
}
|
2011-06-17 13:11:45 +00:00
|
|
|
}
|
2011-12-28 19:31:01 +00:00
|
|
|
return errors;
|
2011-06-17 13:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield compare_to_reference_image(const char readPath [],
|
|
|
|
const SkString& name,
|
|
|
|
SkBitmap &bitmap,
|
|
|
|
const char diffPath [],
|
|
|
|
const char renderModeDescriptor []) {
|
2011-04-25 15:49:53 +00:00
|
|
|
SkString path = make_filename(readPath, "", name, "png");
|
|
|
|
SkBitmap orig;
|
2011-12-28 19:31:01 +00:00
|
|
|
if (SkImageDecoder::DecodeFile(path.c_str(), &orig,
|
|
|
|
SkBitmap::kARGB_8888_Config,
|
|
|
|
SkImageDecoder::kDecodePixels_Mode, NULL)) {
|
|
|
|
return compare_to_reference_image(name, bitmap,
|
|
|
|
orig, diffPath,
|
|
|
|
renderModeDescriptor);
|
2011-04-25 15:49:53 +00:00
|
|
|
} else {
|
2012-05-17 15:28:20 +00:00
|
|
|
if (gNotifyMissingReadReference) {
|
|
|
|
fprintf(stderr, "FAILED to read %s\n", path.c_str());
|
|
|
|
}
|
2011-12-28 19:31:01 +00:00
|
|
|
return ERROR_READING_REFERENCE_IMAGE;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield handle_test_results(GM* gm,
|
|
|
|
const ConfigData& gRec,
|
|
|
|
const char writePath [],
|
|
|
|
const char readPath [],
|
|
|
|
const char diffPath [],
|
|
|
|
const char renderModeDescriptor [],
|
|
|
|
SkBitmap& bitmap,
|
|
|
|
SkDynamicMemoryWStream* pdf,
|
|
|
|
const SkBitmap* comparisonBitmap) {
|
2011-04-25 15:49:53 +00:00
|
|
|
SkString name = make_name(gm->shortName(), gRec.fName);
|
2012-04-18 13:36:54 +00:00
|
|
|
ErrorBitfield retval = ERROR_NONE;
|
2011-04-25 15:49:53 +00:00
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
if (readPath && (gRec.fFlags & kRead_ConfigFlag)) {
|
2012-04-18 13:36:54 +00:00
|
|
|
retval |= compare_to_reference_image(readPath, name, bitmap,
|
|
|
|
diffPath, renderModeDescriptor);
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2012-04-19 19:15:35 +00:00
|
|
|
if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
|
2012-04-18 13:36:54 +00:00
|
|
|
retval |= write_reference_image(gRec, writePath, renderModeDescriptor,
|
|
|
|
name, bitmap, pdf);
|
|
|
|
}
|
|
|
|
if (comparisonBitmap) {
|
|
|
|
retval |= compare_to_reference_image(name, bitmap,
|
|
|
|
*comparisonBitmap, diffPath,
|
|
|
|
renderModeDescriptor);
|
|
|
|
}
|
|
|
|
return retval;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SkPicture* generate_new_picture(GM* gm) {
|
|
|
|
// Pictures are refcounted so must be on heap
|
|
|
|
SkPicture* pict = new SkPicture;
|
|
|
|
SkCanvas* cv = pict->beginRecording(1000, 1000);
|
2011-12-30 16:02:53 +00:00
|
|
|
invokeGM(gm, cv);
|
2011-04-25 15:49:53 +00:00
|
|
|
pict->endRecording();
|
|
|
|
|
|
|
|
return pict;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkPicture* stream_to_new_picture(const SkPicture& src) {
|
|
|
|
|
|
|
|
// To do in-memory commiunications with a stream, we need to:
|
|
|
|
// * create a dynamic memory stream
|
|
|
|
// * copy it into a buffer
|
|
|
|
// * create a read stream from it
|
|
|
|
// ?!?!
|
|
|
|
|
|
|
|
SkDynamicMemoryWStream storage;
|
|
|
|
src.serialize(&storage);
|
|
|
|
|
|
|
|
int streamSize = storage.getOffset();
|
|
|
|
SkAutoMalloc dstStorage(streamSize);
|
|
|
|
void* dst = dstStorage.get();
|
|
|
|
//char* dst = new char [streamSize];
|
|
|
|
//@todo thudson 22 April 2011 when can we safely delete [] dst?
|
|
|
|
storage.copyTo(dst);
|
|
|
|
SkMemoryStream pictReadback(dst, streamSize);
|
|
|
|
SkPicture* retval = new SkPicture (&pictReadback);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test: draw into a bitmap or pdf.
|
|
|
|
// Depending on flags, possibly compare to an expected image
|
|
|
|
// and possibly output a diff image if it fails to match.
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield test_drawing(GM* gm,
|
|
|
|
const ConfigData& gRec,
|
|
|
|
const char writePath [],
|
|
|
|
const char readPath [],
|
|
|
|
const char diffPath [],
|
|
|
|
GrContext* context,
|
|
|
|
GrRenderTarget* rt,
|
|
|
|
SkBitmap* bitmap) {
|
2011-10-10 13:19:10 +00:00
|
|
|
SkDynamicMemoryWStream document;
|
2011-04-25 15:49:53 +00:00
|
|
|
|
|
|
|
if (gRec.fBackend == kRaster_Backend ||
|
2011-08-19 17:22:05 +00:00
|
|
|
gRec.fBackend == kGPU_Backend) {
|
2011-12-28 19:31:01 +00:00
|
|
|
// Early exit if we can't generate the image.
|
2012-01-18 16:21:08 +00:00
|
|
|
ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap,
|
|
|
|
false);
|
2011-12-28 19:31:01 +00:00
|
|
|
if (ERROR_NONE != errors) {
|
|
|
|
return errors;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2011-06-29 12:54:46 +00:00
|
|
|
} else if (gRec.fBackend == kPDF_Backend) {
|
2011-10-10 13:19:10 +00:00
|
|
|
generate_pdf(gm, document);
|
2011-06-29 12:54:46 +00:00
|
|
|
#if CAN_IMAGE_PDF
|
2011-10-10 13:47:06 +00:00
|
|
|
SkAutoDataUnref data(document.copyToData());
|
2011-06-29 12:54:46 +00:00
|
|
|
SkMemoryStream stream(data.data(), data.size());
|
|
|
|
SkPDFDocumentToBitmap(&stream, bitmap);
|
|
|
|
#endif
|
2011-10-10 13:19:10 +00:00
|
|
|
} else if (gRec.fBackend == kXPS_Backend) {
|
|
|
|
generate_xps(gm, document);
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2011-04-26 20:22:57 +00:00
|
|
|
return handle_test_results(gm, gRec, writePath, readPath, diffPath,
|
2011-10-10 13:19:10 +00:00
|
|
|
"", *bitmap, &document, NULL);
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 16:21:08 +00:00
|
|
|
static ErrorBitfield test_deferred_drawing(GM* gm,
|
|
|
|
const ConfigData& gRec,
|
|
|
|
const SkBitmap& comparisonBitmap,
|
|
|
|
const char diffPath [],
|
|
|
|
GrContext* context,
|
|
|
|
GrRenderTarget* rt) {
|
|
|
|
SkDynamicMemoryWStream document;
|
|
|
|
|
|
|
|
if (gRec.fBackend == kRaster_Backend ||
|
|
|
|
gRec.fBackend == kGPU_Backend) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
// Early exit if we can't generate the image, but this is
|
|
|
|
// expected in some cases, so don't report a test failure.
|
|
|
|
if (!generate_image(gm, gRec, context, rt, &bitmap, true)) {
|
|
|
|
return ERROR_NONE;
|
|
|
|
}
|
|
|
|
return handle_test_results(gm, gRec, NULL, NULL, diffPath,
|
|
|
|
"-deferred", bitmap, NULL, &comparisonBitmap);
|
|
|
|
}
|
|
|
|
return ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield test_picture_playback(GM* gm,
|
|
|
|
const ConfigData& gRec,
|
|
|
|
const SkBitmap& comparisonBitmap,
|
|
|
|
const char readPath [],
|
|
|
|
const char diffPath []) {
|
2011-04-25 15:49:53 +00:00
|
|
|
SkPicture* pict = generate_new_picture(gm);
|
|
|
|
SkAutoUnref aur(pict);
|
|
|
|
|
|
|
|
if (kRaster_Backend == gRec.fBackend) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
generate_image_from_picture(gm, gRec, pict, &bitmap);
|
2011-06-17 13:11:45 +00:00
|
|
|
return handle_test_results(gm, gRec, NULL, NULL, diffPath,
|
|
|
|
"-replay", bitmap, NULL, &comparisonBitmap);
|
2011-12-28 19:31:01 +00:00
|
|
|
} else {
|
|
|
|
return ERROR_NONE;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
static ErrorBitfield test_picture_serialization(GM* gm,
|
|
|
|
const ConfigData& gRec,
|
|
|
|
const SkBitmap& comparisonBitmap,
|
|
|
|
const char readPath [],
|
|
|
|
const char diffPath []) {
|
2011-04-25 15:49:53 +00:00
|
|
|
SkPicture* pict = generate_new_picture(gm);
|
|
|
|
SkAutoUnref aurp(pict);
|
|
|
|
SkPicture* repict = stream_to_new_picture(*pict);
|
|
|
|
SkAutoUnref aurr(repict);
|
|
|
|
|
|
|
|
if (kRaster_Backend == gRec.fBackend) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
generate_image_from_picture(gm, gRec, repict, &bitmap);
|
2011-06-17 13:11:45 +00:00
|
|
|
return handle_test_results(gm, gRec, NULL, NULL, diffPath,
|
|
|
|
"-serialize", bitmap, NULL, &comparisonBitmap);
|
2011-12-28 19:31:01 +00:00
|
|
|
} else {
|
|
|
|
return ERROR_NONE;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 17:17:36 +00:00
|
|
|
static ErrorBitfield test_pipe_playback(GM* gm,
|
|
|
|
const ConfigData& gRec,
|
|
|
|
const SkBitmap& comparisonBitmap,
|
|
|
|
const char readPath [],
|
|
|
|
const char diffPath []) {
|
|
|
|
if (kRaster_Backend != gRec.fBackend) {
|
|
|
|
return ERROR_NONE;
|
|
|
|
}
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkISize size = gm->getISize();
|
|
|
|
setup_bitmap(gRec, size, &bitmap);
|
|
|
|
SkCanvas canvas(bitmap);
|
|
|
|
PipeController pipeController(&canvas);
|
|
|
|
SkGPipeWriter writer;
|
|
|
|
SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
|
|
|
|
SkGPipeWriter::kCrossProcess_Flag);
|
|
|
|
invokeGM(gm, pipeCanvas);
|
|
|
|
writer.endRecording();
|
|
|
|
return handle_test_results(gm, gRec, NULL, NULL, diffPath,
|
|
|
|
"-pipe", bitmap, NULL, &comparisonBitmap);
|
|
|
|
}
|
|
|
|
|
2012-06-06 21:07:10 +00:00
|
|
|
static ErrorBitfield test_tiled_pipe_playback(GM* gm,
|
|
|
|
const ConfigData& gRec,
|
|
|
|
const SkBitmap& comparisonBitmap,
|
|
|
|
const char readPath [],
|
|
|
|
const char diffPath []) {
|
|
|
|
if (kRaster_Backend != gRec.fBackend) {
|
|
|
|
return ERROR_NONE;
|
|
|
|
}
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkISize size = gm->getISize();
|
|
|
|
setup_bitmap(gRec, size, &bitmap);
|
|
|
|
TiledPipeController pipeController(bitmap);
|
|
|
|
SkGPipeWriter writer;
|
|
|
|
SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
|
|
|
|
SkGPipeWriter::kCrossProcess_Flag);
|
|
|
|
invokeGM(gm, pipeCanvas);
|
|
|
|
writer.endRecording();
|
|
|
|
return handle_test_results(gm, gRec, NULL, NULL, diffPath,
|
|
|
|
"-tiled pipe", bitmap, NULL, &comparisonBitmap);
|
|
|
|
}
|
|
|
|
|
2012-06-02 14:50:13 +00:00
|
|
|
static void write_picture_serialization(GM* gm, const ConfigData& rec,
|
|
|
|
const char writePicturePath[]) {
|
|
|
|
// only do this once, so we pick raster
|
|
|
|
if (kRaster_Backend == rec.fBackend &&
|
|
|
|
SkBitmap::kARGB_8888_Config == rec.fConfig) {
|
|
|
|
|
|
|
|
SkAutoTUnref<SkPicture> pict(generate_new_picture(gm));
|
|
|
|
|
|
|
|
const char* pictureSuffix = "skp";
|
|
|
|
SkString path = make_filename(writePicturePath, "",
|
|
|
|
SkString(gm->shortName()), pictureSuffix);
|
|
|
|
|
|
|
|
SkFILEWStream stream(path.c_str());
|
|
|
|
pict->serialize(&stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
static const GrContextFactory::GLContextType kDontCare_GLContextType =
|
|
|
|
GrContextFactory::kNative_GLContextType;
|
|
|
|
|
|
|
|
// If the platform does not support writing PNGs of PDFs then there will be no
|
|
|
|
// comparison images to read. However, we can always write the .pdf files
|
|
|
|
static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag :
|
|
|
|
kWrite_ConfigFlag;
|
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
static const ConfigData gRec[] = {
|
2012-04-19 19:15:35 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" },
|
|
|
|
{ SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" },
|
|
|
|
{ SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565" },
|
2011-06-20 13:21:24 +00:00
|
|
|
#ifdef SK_SCALAR_IS_FLOAT
|
2012-04-19 19:15:35 +00:00
|
|
|
{ SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu" },
|
|
|
|
{ SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16" },
|
|
|
|
/* The debug context does not generate images */
|
|
|
|
{ SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "debug" },
|
|
|
|
#ifdef SK_ANGLE
|
|
|
|
{ SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" },
|
|
|
|
{ SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16" },
|
|
|
|
#endif
|
|
|
|
#ifdef SK_MESA
|
|
|
|
{ SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa" },
|
|
|
|
#endif
|
2011-02-03 23:00:40 +00:00
|
|
|
#endif
|
2011-10-10 13:19:10 +00:00
|
|
|
#ifdef SK_SUPPORT_XPS
|
2012-04-19 19:15:35 +00:00
|
|
|
/* At present we have no way of comparing XPS files (either natively or by converting to PNG). */
|
|
|
|
{ SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps" },
|
|
|
|
#endif
|
|
|
|
#ifdef SK_SUPPORT_PDF
|
|
|
|
{ SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" },
|
2011-10-10 13:19:10 +00:00
|
|
|
#endif
|
2009-06-10 15:38:48 +00:00
|
|
|
};
|
|
|
|
|
2012-06-07 17:39:48 +00:00
|
|
|
static void usage(const char * argv0) {
|
|
|
|
SkDebugf("%s\n", argv0);
|
|
|
|
SkDebugf(" [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n");
|
|
|
|
SkDebugf(" [-config ");
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
|
|
if (i > 0) {
|
|
|
|
SkDebugf("|");
|
|
|
|
}
|
|
|
|
SkDebugf(gRec[i].fName);
|
|
|
|
}
|
|
|
|
SkDebugf(" ]\n");
|
2012-06-15 12:53:04 +00:00
|
|
|
SkDebugf(" [--noreplay] [--pipe] [--noserialize] [--forceBWtext] [--nopdf] \n"
|
2012-06-07 17:39:48 +00:00
|
|
|
" [--tiledPipe] \n"
|
|
|
|
" [--nodeferred] [--match substring] [--notexturecache]\n"
|
|
|
|
" [-h|--help]\n"
|
|
|
|
);
|
|
|
|
SkDebugf(" writePath: directory to write rendered images in.\n");
|
|
|
|
SkDebugf(
|
|
|
|
" readPath: directory to read reference images from;\n"
|
|
|
|
" reports if any pixels mismatch between reference and new images\n");
|
|
|
|
SkDebugf(" diffPath: directory to write difference images in.\n");
|
|
|
|
SkDebugf(" resourcePath: directory that stores image resources.\n");
|
|
|
|
SkDebugf(" --noreplay: do not exercise SkPicture replay.\n");
|
|
|
|
SkDebugf(" --pipe: Exercise SkGPipe replay.\n");
|
|
|
|
SkDebugf(" --tiledPipe: Exercise tiled SkGPipe replay.\n");
|
|
|
|
SkDebugf(
|
2012-06-15 12:53:04 +00:00
|
|
|
" --noserialize: do not exercise SkPicture serialization & deserialization.\n");
|
2012-06-07 17:39:48 +00:00
|
|
|
SkDebugf(" --forceBWtext: disable text anti-aliasing.\n");
|
|
|
|
SkDebugf(" --nopdf: skip the pdf rendering test pass.\n");
|
|
|
|
SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n");
|
|
|
|
SkDebugf(" --match foo: will only run tests that substring match foo.\n");
|
|
|
|
SkDebugf(" --notexturecache: disable the gpu texture cache.\n");
|
|
|
|
SkDebugf(" -h|--help : Show this help message. \n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int findConfig(const char config[]) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
|
|
|
|
if (!strcmp(config, gRec[i].fName)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-31 16:30:04 +00:00
|
|
|
static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
|
|
|
|
if (0 == array.count()) {
|
|
|
|
// no names, so don't skip anything
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < array.count(); ++i) {
|
|
|
|
if (strstr(name, array[i])) {
|
|
|
|
// found the name, so don't skip
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-18 15:25:04 +00:00
|
|
|
namespace skiagm {
|
2012-04-19 19:15:35 +00:00
|
|
|
SkAutoTUnref<GrContext> gGrContext;
|
|
|
|
/**
|
|
|
|
* Sets the global GrContext, accessible by indivual GMs
|
|
|
|
*/
|
2012-06-06 12:10:45 +00:00
|
|
|
static void SetGr(GrContext* grContext) {
|
2012-04-19 19:15:35 +00:00
|
|
|
SkSafeRef(grContext);
|
|
|
|
gGrContext.reset(grContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the global GrContext, can be called by GM tests.
|
|
|
|
*/
|
2012-06-06 12:10:45 +00:00
|
|
|
GrContext* GetGr();
|
2011-07-18 15:25:04 +00:00
|
|
|
GrContext* GetGr() {
|
2012-04-19 19:15:35 +00:00
|
|
|
return gGrContext.get();
|
2011-07-18 15:25:04 +00:00
|
|
|
}
|
2012-04-19 19:15:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the global GrContext and then resets it to its previous value at
|
|
|
|
* destruction.
|
|
|
|
*/
|
|
|
|
class AutoResetGr : SkNoncopyable {
|
|
|
|
public:
|
|
|
|
AutoResetGr() : fOld(NULL) {}
|
|
|
|
void set(GrContext* context) {
|
|
|
|
SkASSERT(NULL == fOld);
|
|
|
|
fOld = GetGr();
|
|
|
|
SkSafeRef(fOld);
|
|
|
|
SetGr(context);
|
|
|
|
}
|
|
|
|
~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); }
|
|
|
|
private:
|
|
|
|
GrContext* fOld;
|
|
|
|
};
|
2011-07-18 15:25:04 +00:00
|
|
|
}
|
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
int main(int argc, char * const argv[]) {
|
2012-06-05 19:35:09 +00:00
|
|
|
SkGraphics::Init();
|
2011-11-08 14:59:38 +00:00
|
|
|
// we don't need to see this during a run
|
|
|
|
gSkSuppressFontCachePurgeSpew = true;
|
2011-01-18 21:05:42 +00:00
|
|
|
|
2012-02-14 14:53:59 +00:00
|
|
|
setSystemPreferences();
|
|
|
|
|
2009-06-21 00:49:18 +00:00
|
|
|
const char* writePath = NULL; // if non-null, where we write the originals
|
2012-06-02 14:50:13 +00:00
|
|
|
const char* writePicturePath = NULL; // if non-null, where we write serialized pictures
|
2009-06-21 00:49:18 +00:00
|
|
|
const char* readPath = NULL; // if non-null, were we read from to compare
|
2011-04-25 15:49:53 +00:00
|
|
|
const char* diffPath = NULL; // if non-null, where we write our diffs (from compare)
|
2012-03-20 17:40:58 +00:00
|
|
|
const char* resourcePath = NULL;// if non-null, where we read from for image resources
|
2009-06-21 00:49:18 +00:00
|
|
|
|
2011-10-31 16:30:04 +00:00
|
|
|
SkTDArray<const char*> fMatches;
|
2012-01-31 18:35:30 +00:00
|
|
|
|
2011-09-19 19:01:38 +00:00
|
|
|
bool doPDF = true;
|
2011-05-26 15:57:56 +00:00
|
|
|
bool doReplay = true;
|
2012-06-04 17:45:54 +00:00
|
|
|
bool doPipe = false;
|
2012-06-06 21:07:10 +00:00
|
|
|
bool doTiledPipe = false;
|
2012-06-15 12:53:04 +00:00
|
|
|
bool doSerialize = true;
|
2012-01-18 16:21:08 +00:00
|
|
|
bool doDeferred = true;
|
2012-01-31 18:35:30 +00:00
|
|
|
bool disableTextureCache = false;
|
2012-06-07 17:39:48 +00:00
|
|
|
SkTDArray<size_t> configs;
|
|
|
|
bool userConfig = false;
|
2012-01-31 18:35:30 +00:00
|
|
|
|
2012-05-17 15:28:20 +00:00
|
|
|
gNotifyMissingReadReference = true;
|
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
const char* const commandName = argv[0];
|
2009-06-21 00:49:18 +00:00
|
|
|
char* const* stop = argv + argc;
|
|
|
|
for (++argv; argv < stop; ++argv) {
|
|
|
|
if (strcmp(*argv, "-w") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
writePath = *argv;
|
|
|
|
}
|
2012-06-02 14:50:13 +00:00
|
|
|
} else if (strcmp(*argv, "-wp") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
writePicturePath = *argv;
|
|
|
|
}
|
2009-06-21 00:49:18 +00:00
|
|
|
} else if (strcmp(*argv, "-r") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
readPath = *argv;
|
|
|
|
}
|
2010-12-20 21:10:29 +00:00
|
|
|
} else if (strcmp(*argv, "-d") == 0) {
|
2011-04-25 15:49:53 +00:00
|
|
|
argv++;
|
2010-12-20 21:10:29 +00:00
|
|
|
if (argv < stop && **argv) {
|
|
|
|
diffPath = *argv;
|
|
|
|
}
|
2012-03-20 17:40:58 +00:00
|
|
|
} else if (strcmp(*argv, "-i") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
resourcePath = *argv;
|
|
|
|
}
|
2011-12-30 16:02:53 +00:00
|
|
|
} else if (strcmp(*argv, "--forceBWtext") == 0) {
|
|
|
|
gForceBWtext = true;
|
2012-06-04 17:45:54 +00:00
|
|
|
} else if (strcmp(*argv, "--pipe") == 0) {
|
|
|
|
doPipe = true;
|
2012-06-06 21:07:10 +00:00
|
|
|
} else if (strcmp(*argv, "--tiledPipe") == 0) {
|
|
|
|
doTiledPipe = true;
|
2011-05-26 15:57:56 +00:00
|
|
|
} else if (strcmp(*argv, "--noreplay") == 0) {
|
|
|
|
doReplay = false;
|
2011-09-19 19:01:38 +00:00
|
|
|
} else if (strcmp(*argv, "--nopdf") == 0) {
|
|
|
|
doPDF = false;
|
2012-01-18 16:21:08 +00:00
|
|
|
} else if (strcmp(*argv, "--nodeferred") == 0) {
|
|
|
|
doDeferred = false;
|
2012-05-17 15:28:20 +00:00
|
|
|
} else if (strcmp(*argv, "--disable-missing-warning") == 0) {
|
|
|
|
gNotifyMissingReadReference = false;
|
|
|
|
} else if (strcmp(*argv, "--enable-missing-warning") == 0) {
|
|
|
|
gNotifyMissingReadReference = true;
|
2012-06-15 12:53:04 +00:00
|
|
|
} else if (strcmp(*argv, "--noserialize") == 0) {
|
|
|
|
doSerialize = false;
|
2011-04-25 19:20:54 +00:00
|
|
|
} else if (strcmp(*argv, "--serialize") == 0) {
|
2012-06-15 12:53:04 +00:00
|
|
|
//@todo borenet - Remove unused "--serialize" flag
|
2011-07-25 14:28:57 +00:00
|
|
|
} else if (strcmp(*argv, "--match") == 0) {
|
|
|
|
++argv;
|
|
|
|
if (argv < stop && **argv) {
|
2011-10-31 16:30:04 +00:00
|
|
|
// just record the ptr, no need for a deep copy
|
|
|
|
*fMatches.append() = *argv;
|
2011-07-25 14:28:57 +00:00
|
|
|
}
|
2012-01-31 18:35:30 +00:00
|
|
|
} else if (strcmp(*argv, "--notexturecache") == 0) {
|
2012-03-20 17:40:58 +00:00
|
|
|
disableTextureCache = true;
|
2012-06-07 17:39:48 +00:00
|
|
|
} else if (strcmp(*argv, "-config") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop) {
|
|
|
|
int index = findConfig(*argv);
|
|
|
|
if (index >= 0) {
|
|
|
|
*configs.append() = index;
|
|
|
|
userConfig = true;
|
|
|
|
} else {
|
|
|
|
SkString str;
|
|
|
|
str.printf("unrecognized config %s\n", *argv);
|
|
|
|
SkDebugf(str.c_str());
|
|
|
|
usage(commandName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SkDebugf("missing arg for -config\n");
|
|
|
|
usage(commandName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) {
|
|
|
|
usage(commandName);
|
|
|
|
return -1;
|
2011-04-25 15:49:53 +00:00
|
|
|
} else {
|
2012-03-20 17:40:58 +00:00
|
|
|
usage(commandName);
|
|
|
|
return -1;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argv != stop) {
|
2012-03-20 17:40:58 +00:00
|
|
|
usage(commandName);
|
|
|
|
return -1;
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2010-12-23 15:00:45 +00:00
|
|
|
|
2012-06-07 17:39:48 +00:00
|
|
|
if (!userConfig) {
|
|
|
|
// if no config is specified by user, we add them all.
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
|
|
*configs.append() = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
GM::SetResourcePath(resourcePath);
|
|
|
|
|
2012-06-05 19:35:09 +00:00
|
|
|
GrContextFactory* grFactory = new GrContextFactory;
|
2010-12-23 15:00:45 +00:00
|
|
|
|
2010-12-14 17:46:14 +00:00
|
|
|
if (readPath) {
|
|
|
|
fprintf(stderr, "reading from %s\n", readPath);
|
2012-04-18 13:36:54 +00:00
|
|
|
}
|
|
|
|
if (writePath) {
|
2010-12-14 17:46:14 +00:00
|
|
|
fprintf(stderr, "writing to %s\n", writePath);
|
|
|
|
}
|
2012-06-02 14:50:13 +00:00
|
|
|
if (writePicturePath) {
|
|
|
|
fprintf(stderr, "writing pictures to %s\n", writePicturePath);
|
|
|
|
}
|
2012-03-20 17:40:58 +00:00
|
|
|
if (resourcePath) {
|
|
|
|
fprintf(stderr, "reading resources from %s\n", resourcePath);
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
// Accumulate success of all tests.
|
|
|
|
int testsRun = 0;
|
|
|
|
int testsPassed = 0;
|
|
|
|
int testsFailed = 0;
|
|
|
|
int testsMissingReferenceImages = 0;
|
|
|
|
|
2012-01-31 18:35:30 +00:00
|
|
|
if (disableTextureCache) {
|
|
|
|
skiagm::GetGr()->setTextureCacheLimits(0, 0);
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
Iter iter;
|
|
|
|
GM* gm;
|
2009-06-10 15:38:48 +00:00
|
|
|
while ((gm = iter.next()) != NULL) {
|
2011-07-25 14:28:57 +00:00
|
|
|
const char* shortName = gm->shortName();
|
2011-10-31 16:30:04 +00:00
|
|
|
if (skip_name(fMatches, shortName)) {
|
2011-07-25 14:28:57 +00:00
|
|
|
SkDELETE(gm);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-04-25 15:49:53 +00:00
|
|
|
SkISize size = gm->getISize();
|
2011-07-25 14:28:57 +00:00
|
|
|
SkDebugf("drawing... %s [%d %d]\n", shortName,
|
2009-06-21 00:49:18 +00:00
|
|
|
size.width(), size.height());
|
2011-06-17 13:11:45 +00:00
|
|
|
SkBitmap forwardRenderedBitmap;
|
2009-06-21 00:49:18 +00:00
|
|
|
|
2012-06-07 17:39:48 +00:00
|
|
|
for (int i = 0; i < configs.count(); i++) {
|
|
|
|
ConfigData config = gRec[configs[i]];
|
2012-04-19 19:15:35 +00:00
|
|
|
SkAutoTUnref<GrRenderTarget> rt;
|
|
|
|
AutoResetGr autogr;
|
2012-06-07 17:39:48 +00:00
|
|
|
if (kGPU_Backend == config.fBackend) {
|
|
|
|
GrContext* gr = grFactory->get(config.fGLContextType);
|
2012-04-19 19:15:35 +00:00
|
|
|
if (!gr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a render target to back the device
|
|
|
|
GrTextureDesc desc;
|
|
|
|
desc.fConfig = kSkia8888_PM_GrPixelConfig;
|
|
|
|
desc.fFlags = kRenderTarget_GrTextureFlagBit;
|
|
|
|
desc.fWidth = gm->getISize().width();
|
|
|
|
desc.fHeight = gm->getISize().height();
|
2012-06-07 17:39:48 +00:00
|
|
|
desc.fSampleCnt = config.fSampleCnt;
|
2012-04-19 19:15:35 +00:00
|
|
|
GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0);
|
|
|
|
if (!tex) {
|
2012-04-20 19:08:44 +00:00
|
|
|
continue;
|
2012-04-19 19:15:35 +00:00
|
|
|
}
|
|
|
|
rt.reset(tex->asRenderTarget());
|
|
|
|
rt.get()->ref();
|
|
|
|
tex->unref();
|
|
|
|
|
|
|
|
autogr.set(gr);
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
// Skip any tests that we don't even need to try.
|
2011-11-30 16:57:21 +00:00
|
|
|
uint32_t gmFlags = gm->getFlags();
|
2012-06-07 17:39:48 +00:00
|
|
|
if ((kPDF_Backend == config.fBackend) &&
|
2011-09-19 19:31:04 +00:00
|
|
|
(!doPDF || (gmFlags & GM::kSkipPDF_Flag)))
|
|
|
|
{
|
2011-09-19 19:01:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
// Now we know that we want to run this test and record its
|
|
|
|
// success or failure.
|
|
|
|
ErrorBitfield testErrors = ERROR_NONE;
|
2011-04-25 15:49:53 +00:00
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
if ((ERROR_NONE == testErrors) &&
|
2012-06-07 17:39:48 +00:00
|
|
|
(kGPU_Backend == config.fBackend) &&
|
2011-12-28 19:31:01 +00:00
|
|
|
(NULL == rt.get())) {
|
|
|
|
fprintf(stderr, "Could not create render target for gpu.\n");
|
|
|
|
testErrors |= ERROR_NO_GPU_CONTEXT;
|
2011-04-25 19:20:54 +00:00
|
|
|
}
|
2011-04-25 15:49:53 +00:00
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
if (ERROR_NONE == testErrors) {
|
2012-06-07 17:39:48 +00:00
|
|
|
testErrors |= test_drawing(gm, config,
|
2011-12-28 19:31:01 +00:00
|
|
|
writePath, readPath, diffPath,
|
2012-04-19 19:15:35 +00:00
|
|
|
GetGr(),
|
2011-12-28 19:31:01 +00:00
|
|
|
rt.get(), &forwardRenderedBitmap);
|
|
|
|
}
|
|
|
|
|
2012-01-18 16:21:08 +00:00
|
|
|
if (doDeferred && !testErrors &&
|
2012-06-07 17:39:48 +00:00
|
|
|
(kGPU_Backend == config.fBackend ||
|
|
|
|
kRaster_Backend == config.fBackend)) {
|
|
|
|
testErrors |= test_deferred_drawing(gm, config,
|
2012-03-20 17:40:58 +00:00
|
|
|
forwardRenderedBitmap,
|
2012-04-19 19:15:35 +00:00
|
|
|
diffPath, GetGr(), rt.get());
|
2012-01-18 16:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
if ((ERROR_NONE == testErrors) && doReplay &&
|
|
|
|
!(gmFlags & GM::kSkipPicture_Flag)) {
|
2012-06-07 17:39:48 +00:00
|
|
|
testErrors |= test_picture_playback(gm, config,
|
2011-12-28 19:31:01 +00:00
|
|
|
forwardRenderedBitmap,
|
|
|
|
readPath, diffPath);
|
|
|
|
}
|
|
|
|
|
2012-06-04 17:17:36 +00:00
|
|
|
if ((ERROR_NONE == testErrors) && doPipe &&
|
|
|
|
!(gmFlags & GM::kSkipPipe_Flag)) {
|
2012-06-07 17:39:48 +00:00
|
|
|
testErrors |= test_pipe_playback(gm, config,
|
2012-06-04 17:17:36 +00:00
|
|
|
forwardRenderedBitmap,
|
|
|
|
readPath, diffPath);
|
|
|
|
}
|
|
|
|
|
2012-06-06 21:07:10 +00:00
|
|
|
if ((ERROR_NONE == testErrors) && doTiledPipe &&
|
|
|
|
!(gmFlags & GM::kSkipPipe_Flag)) {
|
2012-06-07 17:39:48 +00:00
|
|
|
testErrors |= test_tiled_pipe_playback(gm, config,
|
2012-06-06 21:07:10 +00:00
|
|
|
forwardRenderedBitmap,
|
|
|
|
readPath, diffPath);
|
|
|
|
}
|
|
|
|
|
2012-03-23 19:00:34 +00:00
|
|
|
if ((ERROR_NONE == testErrors) && doSerialize &&
|
|
|
|
!(gmFlags & GM::kSkipPicture_Flag)) {
|
2012-06-07 17:39:48 +00:00
|
|
|
testErrors |= test_picture_serialization(gm, config,
|
2011-12-28 19:31:01 +00:00
|
|
|
forwardRenderedBitmap,
|
|
|
|
readPath, diffPath);
|
|
|
|
}
|
2012-06-02 14:50:13 +00:00
|
|
|
|
|
|
|
if (!(gmFlags & GM::kSkipPicture_Flag) && writePicturePath) {
|
2012-06-07 17:39:48 +00:00
|
|
|
write_picture_serialization(gm, config, writePicturePath);
|
2012-06-02 14:50:13 +00:00
|
|
|
}
|
2011-12-28 19:31:01 +00:00
|
|
|
|
|
|
|
// Update overall results.
|
|
|
|
// We only tabulate the particular error types that we currently
|
|
|
|
// care about (e.g., missing reference images). Later on, if we
|
|
|
|
// want to also tabulate pixel mismatches vs dimension mistmatches
|
|
|
|
// (or whatever else), we can do so.
|
|
|
|
testsRun++;
|
|
|
|
if (ERROR_NONE == testErrors) {
|
|
|
|
testsPassed++;
|
|
|
|
} else if (ERROR_READING_REFERENCE_IMAGE & testErrors) {
|
|
|
|
testsMissingReferenceImages++;
|
|
|
|
} else {
|
|
|
|
testsFailed++;
|
2011-04-25 19:20:54 +00:00
|
|
|
}
|
2011-04-25 15:49:53 +00:00
|
|
|
}
|
2009-06-10 15:38:48 +00:00
|
|
|
SkDELETE(gm);
|
|
|
|
}
|
2011-12-28 19:31:01 +00:00
|
|
|
printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n",
|
|
|
|
testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
|
2012-03-21 17:57:55 +00:00
|
|
|
|
2012-06-05 19:35:09 +00:00
|
|
|
delete grFactory;
|
|
|
|
SkGraphics::Term();
|
|
|
|
|
2012-06-13 18:54:08 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
SkRefCnt::CheckInstanceCount();
|
|
|
|
#endif
|
2012-06-05 19:35:09 +00:00
|
|
|
|
2011-12-28 19:31:01 +00:00
|
|
|
return (0 == testsFailed) ? 0 : -1;
|
2009-06-10 15:38:48 +00:00
|
|
|
}
|