skia2/dm/DMUtil.cpp
commit-bot@chromium.org 192cbf67b2 DM: add --serialize
Plus:
  - minor ReplayTask refactoring to share code with SerializeTask
  - move --replay to ReplayTask and --serialize to SerializeTask like WriteTask
  - when --writePath is given, write failures for Replay and Serialize tasks
  - function names have fewer blatant Skia style violations

BUG=
R=bsalomon@google.com

Author: mtklein@google.com

Review URL: https://codereview.chromium.org/32613003

git-svn-id: http://skia.googlecode.com/svn/trunk@11890 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-21 18:40:25 +00:00

56 lines
1.6 KiB
C++

#include "DMUtil.h"
#include "SkPicture.h"
namespace DM {
SkString UnderJoin(const char* a, const char* b) {
SkString s;
s.appendf("%s_%s", a, b);
return s;
}
SkString Png(SkString s) {
s.appendf(".png");
return s;
}
bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap bitmap) {
if (expectations.ignoreFailure() || expectations.empty()) {
return true;
}
const skiagm::GmResultDigest digest(bitmap);
return expectations.match(digest);
}
void RecordPicture(skiagm::GM* gm, SkPicture* picture) {
SkCanvas* canvas = picture->beginRecording(SkScalarCeilToInt(gm->width()),
SkScalarCeilToInt(gm->height()),
0 /*flags*/);
canvas->concat(gm->getInitialTransform());
gm->draw(canvas);
canvas->flush();
picture->endRecording();
}
void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap) {
bitmap->setConfig(config, SkScalarCeilToInt(gm->width()), SkScalarCeilToInt(gm->height()));
bitmap->allocPixels();
bitmap->eraseColor(0x00000000);
}
void DrawPicture(SkPicture* picture, SkBitmap* bitmap) {
SkASSERT(picture != NULL);
SkASSERT(bitmap != NULL);
SkCanvas canvas(*bitmap);
canvas.drawPicture(*picture);
canvas.flush();
}
bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) {
const SkAutoLockPixels lockA(a), lockB(b);
return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(), b.getSize());
}
} // namespace DM