-replay tests are only run if forward rendering succeeded.

-serialize tests are only run if previous test (either -replay or forward
rendering) succeeded.
The results of -replay and -serialize are compared against the output of
forward rendering.



git-svn-id: http://skia.googlecode.com/svn/trunk@1626 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
tomhudson@google.com 2011-06-17 13:11:45 +00:00
parent e97f0856a8
commit cae6b3f1e8

View File

@ -132,25 +132,32 @@ static bool compare(const SkBitmap& target, const SkBitmap& base,
target.copyTo(&copy, SkBitmap::kARGB_8888_Config); target.copyTo(&copy, SkBitmap::kARGB_8888_Config);
bm = © bm = ©
} }
SkBitmap baseCopy;
const SkBitmap* bp = &base;
if (base.config() != SkBitmap::kARGB_8888_Config) {
base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config);
bp = &baseCopy;
}
force_all_opaque(*bm); force_all_opaque(*bm);
force_all_opaque(*bp);
const int w = bm->width(); const int w = bm->width();
const int h = bm->height(); const int h = bm->height();
if (w != base.width() || h != base.height()) { if (w != bp->width() || h != bp->height()) {
SkDebugf( SkDebugf(
"---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n", "---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n",
renderModeDescriptor, name.c_str(), renderModeDescriptor, name.c_str(),
base.width(), base.height(), w, h); bp->width(), bp->height(), w, h);
return false; return false;
} }
SkAutoLockPixels bmLock(*bm); SkAutoLockPixels bmLock(*bm);
SkAutoLockPixels baseLock(base); SkAutoLockPixels baseLock(*bp);
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
SkPMColor c0 = *base.getAddr32(x, y); SkPMColor c0 = *bp->getAddr32(x, y);
SkPMColor c1 = *bm->getAddr32(x, y); SkPMColor c1 = *bm->getAddr32(x, y);
if (c0 != c1) { if (c0 != c1) {
SkDebugf( SkDebugf(
@ -160,7 +167,7 @@ static bool compare(const SkBitmap& target, const SkBitmap& base,
if (diff) { if (diff) {
diff->setConfig(SkBitmap::kARGB_8888_Config, w, h); diff->setConfig(SkBitmap::kARGB_8888_Config, w, h);
diff->allocPixels(); diff->allocPixels();
compute_diff(*bm, base, diff); compute_diff(*bm, *bp, diff);
} }
return false; return false;
} }
@ -205,10 +212,10 @@ static void setup_bitmap(const ConfigData& gRec, SkISize& size,
// halt. // halt.
static bool generate_image(GM* gm, const ConfigData& gRec, static bool generate_image(GM* gm, const ConfigData& gRec,
GrContext* context, GrContext* context,
SkBitmap& bitmap) { SkBitmap* bitmap) {
SkISize size (gm->getISize()); SkISize size (gm->getISize());
setup_bitmap(gRec, size, &bitmap); setup_bitmap(gRec, size, bitmap);
SkCanvas canvas(bitmap); SkCanvas canvas(*bitmap);
if (gRec.fBackend == kRaster_Backend) { if (gRec.fBackend == kRaster_Backend) {
gm->draw(&canvas); gm->draw(&canvas);
@ -216,16 +223,15 @@ static bool generate_image(GM* gm, const ConfigData& gRec,
if (NULL == context) { if (NULL == context) {
return false; return false;
} }
// not a real object, so don't unref it // not a real object, so don't unref it
GrRenderTarget* rt = SkGpuDevice::Current3DApiRenderTarget(); GrRenderTarget* rt = SkGpuDevice::Current3DApiRenderTarget();
SkGpuCanvas gc(context, rt); SkGpuCanvas gc(context, rt);
gc.setDevice(new SkGpuDevice(context, rt))->unref(); gc.setDevice(new SkGpuDevice(context, rt))->unref();
gm->draw(&gc); gm->draw(&gc);
// the device is as large as the current rendertarget, so we explicitly // the device is as large as the current rendertarget, so we explicitly
// only readback the amount we expect (in size) // only readback the amount we expect (in size)
gc.readPixels(SkIRect::MakeSize(size), &bitmap); // overwrite our previous allocation // overwrite our previous allocation
gc.readPixels(SkIRect::MakeSize(size), bitmap);
} }
return true; return true;
} }
@ -276,6 +282,22 @@ static bool write_reference_image(const ConfigData& gRec,
return success; return success;
} }
static bool compare_to_reference_image(const SkString& name,
SkBitmap &bitmap,
const SkBitmap& comparisonBitmap,
const char diffPath [],
const char renderModeDescriptor []) {
bool success;
SkBitmap diffBitmap;
success = compare(bitmap, comparisonBitmap, name, renderModeDescriptor,
diffPath ? &diffBitmap : NULL);
if (!success && diffPath) {
SkString diffName = make_filename(diffPath, "", name, ".diff.png");
write_bitmap(diffName, diffBitmap);
}
return success;
}
static bool compare_to_reference_image(const char readPath [], static bool compare_to_reference_image(const char readPath [],
const SkString& name, const SkString& name,
SkBitmap &bitmap, SkBitmap &bitmap,
@ -287,14 +309,9 @@ static bool compare_to_reference_image(const char readPath [],
SkBitmap::kARGB_8888_Config, SkBitmap::kARGB_8888_Config,
SkImageDecoder::kDecodePixels_Mode, NULL); SkImageDecoder::kDecodePixels_Mode, NULL);
if (success) { if (success) {
SkBitmap diffBitmap; success = compare_to_reference_image(name, bitmap,
success = compare(bitmap, orig, name, renderModeDescriptor, orig, diffPath,
diffPath ? &diffBitmap : NULL); renderModeDescriptor);
if (!success && diffPath) {
SkString diffName = make_filename(diffPath, "", name, ".diff.png");
fprintf(stderr, "Writing %s\n", diffName.c_str());
write_bitmap(diffName, diffBitmap);
}
} else { } else {
fprintf(stderr, "FAILED to read %s\n", path.c_str()); fprintf(stderr, "FAILED to read %s\n", path.c_str());
} }
@ -308,7 +325,8 @@ static bool handle_test_results(GM* gm,
const char diffPath [], const char diffPath [],
const char renderModeDescriptor [], const char renderModeDescriptor [],
SkBitmap& bitmap, SkBitmap& bitmap,
SkDynamicMemoryWStream* pdf) { SkDynamicMemoryWStream* pdf,
const SkBitmap* comparisonBitmap) {
SkString name = make_name(gm->shortName(), gRec.fName); SkString name = make_name(gm->shortName(), gRec.fName);
if (writePath) { if (writePath) {
@ -318,6 +336,10 @@ static bool handle_test_results(GM* gm,
} else if (readPath && gRec.fBackend != kPDF_Backend) { } else if (readPath && gRec.fBackend != kPDF_Backend) {
return compare_to_reference_image(readPath, name, bitmap, return compare_to_reference_image(readPath, name, bitmap,
diffPath, renderModeDescriptor); diffPath, renderModeDescriptor);
} else if (comparisonBitmap) {
return compare_to_reference_image(name, bitmap,
*comparisonBitmap, diffPath,
renderModeDescriptor);
} }
return true; return true;
} }
@ -362,8 +384,8 @@ static bool test_drawing(GM* gm,
const char writePath [], const char writePath [],
const char readPath [], const char readPath [],
const char diffPath [], const char diffPath [],
GrContext* context) { GrContext* context,
SkBitmap bitmap; SkBitmap* bitmap) {
SkDynamicMemoryWStream pdf; SkDynamicMemoryWStream pdf;
if (gRec.fBackend == kRaster_Backend || if (gRec.fBackend == kRaster_Backend ||
@ -379,11 +401,12 @@ static bool test_drawing(GM* gm,
generate_pdf(gm, pdf); generate_pdf(gm, pdf);
} }
return handle_test_results(gm, gRec, writePath, readPath, diffPath, return handle_test_results(gm, gRec, writePath, readPath, diffPath,
"", bitmap, &pdf); "", *bitmap, &pdf, NULL);
} }
static bool test_picture_playback(GM* gm, static bool test_picture_playback(GM* gm,
const ConfigData& gRec, const ConfigData& gRec,
const SkBitmap& comparisonBitmap,
const char readPath [], const char readPath [],
const char diffPath []) { const char diffPath []) {
SkPicture* pict = generate_new_picture(gm); SkPicture* pict = generate_new_picture(gm);
@ -392,14 +415,15 @@ static bool test_picture_playback(GM* gm,
if (kRaster_Backend == gRec.fBackend) { if (kRaster_Backend == gRec.fBackend) {
SkBitmap bitmap; SkBitmap bitmap;
generate_image_from_picture(gm, gRec, pict, &bitmap); generate_image_from_picture(gm, gRec, pict, &bitmap);
return handle_test_results(gm, gRec, NULL, readPath, diffPath, return handle_test_results(gm, gRec, NULL, NULL, diffPath,
"-replay", bitmap, NULL); "-replay", bitmap, NULL, &comparisonBitmap);
} }
return true; return true;
} }
static bool test_picture_serialization(GM* gm, static bool test_picture_serialization(GM* gm,
const ConfigData& gRec, const ConfigData& gRec,
const SkBitmap& comparisonBitmap,
const char readPath [], const char readPath [],
const char diffPath []) { const char diffPath []) {
SkPicture* pict = generate_new_picture(gm); SkPicture* pict = generate_new_picture(gm);
@ -410,8 +434,8 @@ static bool test_picture_serialization(GM* gm,
if (kRaster_Backend == gRec.fBackend) { if (kRaster_Backend == gRec.fBackend) {
SkBitmap bitmap; SkBitmap bitmap;
generate_image_from_picture(gm, gRec, repict, &bitmap); generate_image_from_picture(gm, gRec, repict, &bitmap);
return handle_test_results(gm, gRec, NULL, readPath, diffPath, return handle_test_results(gm, gRec, NULL, NULL, diffPath,
"-serialize", bitmap, NULL); "-serialize", bitmap, NULL, &comparisonBitmap);
} }
return true; return true;
} }
@ -511,21 +535,26 @@ int main(int argc, char * const argv[]) {
SkISize size = gm->getISize(); SkISize size = gm->getISize();
SkDebugf("drawing... %s [%d %d]\n", gm->shortName(), SkDebugf("drawing... %s [%d %d]\n", gm->shortName(),
size.width(), size.height()); size.width(), size.height());
SkBitmap forwardRenderedBitmap;
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
bool testSuccess = test_drawing(gm, gRec[i], bool testSuccess = test_drawing(gm, gRec[i],
writePath, readPath, diffPath, context); writePath, readPath, diffPath, context,
&forwardRenderedBitmap);
overallSuccess &= testSuccess; overallSuccess &= testSuccess;
if (doReplay && testSuccess) { if (doReplay && testSuccess) {
testSuccess = test_picture_playback(gm, gRec[i], testSuccess = test_picture_playback(gm, gRec[i],
forwardRenderedBitmap,
readPath, diffPath); readPath, diffPath);
overallSuccess &= testSuccess; overallSuccess &= testSuccess;
} }
if (doSerialize && testSuccess) { if (doSerialize && testSuccess) {
overallSuccess &= test_picture_serialization(gm, gRec[i], testSuccess &= test_picture_serialization(gm, gRec[i],
forwardRenderedBitmap,
readPath, diffPath); readPath, diffPath);
overallSuccess &= testSuccess;
} }
} }
SkDELETE(gm); SkDELETE(gm);