2013-10-18 20:52:44 +00:00
|
|
|
#include "DMWriteTask.h"
|
|
|
|
|
|
|
|
#include "DMUtil.h"
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkImageEncoder.h"
|
2013-12-02 13:36:22 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2013-10-18 20:52:44 +00:00
|
|
|
|
|
|
|
DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs.");
|
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
2013-12-02 13:36:22 +00:00
|
|
|
WriteTask::WriteTask(const Task& parent, SkBitmap bitmap)
|
|
|
|
: Task(parent)
|
|
|
|
, fBitmap(bitmap) {
|
|
|
|
// Split parent's name <gmName>_<config> into gmName and config.
|
|
|
|
const char* parentName = parent.name().c_str();
|
|
|
|
const char* fromLastUnderscore = strrchr(parentName, '_');
|
|
|
|
const ptrdiff_t gmNameLength = fromLastUnderscore - parentName;
|
2013-10-18 20:52:44 +00:00
|
|
|
|
2013-12-02 13:36:22 +00:00
|
|
|
fConfig.set(fromLastUnderscore+1);
|
|
|
|
fGmName.set(parentName, gmNameLength);
|
2013-10-18 20:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteTask::draw() {
|
2013-12-02 13:36:22 +00:00
|
|
|
const char* root = FLAGS_writePath[0];
|
|
|
|
const SkString dir = SkOSPath::SkPathJoin(root, fConfig.c_str());
|
|
|
|
if (!sk_mkdir(root) ||
|
|
|
|
!sk_mkdir(dir.c_str()) ||
|
|
|
|
!SkImageEncoder::EncodeFile(Png(SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str())).c_str(),
|
2013-10-18 20:52:44 +00:00
|
|
|
fBitmap,
|
|
|
|
SkImageEncoder::kPNG_Type,
|
2013-12-02 13:36:22 +00:00
|
|
|
100/*quality*/))
|
|
|
|
{
|
2013-10-18 20:52:44 +00:00
|
|
|
this->fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString WriteTask::name() const {
|
2013-12-02 13:36:22 +00:00
|
|
|
return SkStringPrintf("writing %s/%s.png", fConfig.c_str(), fGmName.c_str());
|
2013-10-18 20:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WriteTask::shouldSkip() const {
|
|
|
|
return FLAGS_writePath.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DM
|